Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今日から分かる Android Audioの全て

今日から分かる Android Audioの全て

Shumpei Urabe

October 26, 2020
Tweet

More Decks by Shumpei Urabe

Other Decks in Programming

Transcript

  1. InputStreamΛ४උ͢Δ void AAudio_IO::setupInputStream( AAudioStreamBuilder* builder ) { AAudioStreamBuilder_setDeviceId ( builder,

    _inputDeviceId ); AAudioStreamBuilder_setSampleRate ( builder, _sampleRate ); AAudioStreamBuilder_setChannelCount( builder, _inputChannelCount ); AAudioStreamBuilder_setFormat ( builder, _sampleFormat ); AAudioStreamBuilder_setSharingMode ( builder, AAUDIO_SHARING_MODE_EXCLUSIVE ); AAudioStreamBuilder_setPerformanceMode( builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY ); AAudioStreamBuilder_setDirection ( builder, AAUDIO_DIRECTION_INPUT ); AAudioStreamBuilder_setErrorCallback ( builder, ::errorCallback, this ); }
  2. outputStreamΛ४උ͢Δ void AAudio_IO::setupOutputStream( AAudioStreamBuilder* builder ) { AAudioStreamBuilder_setDeviceId ( builder,

    _outputDeviceId ); AAudioStreamBuilder_setFormat ( builder, _sampleFormat ); AAudioStreamBuilder_setChannelCount( builder, _outputChannelCount ); AAudioStreamBuilder_setSharingMode ( builder, AAUDIO_SHARING_MODE_EXCLUSIVE ); AAudioStreamBuilder_setPerformanceMode( builder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY ); AAudioStreamBuilder_setDirection ( builder, AAUDIO_DIRECTION_OUTPUT ); AAudioStreamBuilder_setDataCallback ( builder, ::dataCallback, this ); AAudioStreamBuilder_setErrorCallback ( builder, ::errorCallback, this ); }
  3. inputStreamΛ࡞Δ void AAudio_IO::createInputStream() { AAudioStreamBuilder* builder = createStreamBuilder(); setupInputStream( builder

    ); aaudio_result_t result = static_cast<aaudio_result_t>(AAudioStreamBuilder_openStream( builder, &_inputStream )); AAudioStreamBuilder_delete( builder ); }
  4. outputStreamΛ࡞Δ void AAudio_IO::createOutputStream() { AAudioStreamBuilder* builder = createStreamBuilder(); setupOutputStream( builder

    ); aaudio_result_t result = static_cast<aaudio_result_t>(AAudioStreamBuilder_openStream( builder, &_outputStream )); if ( result == AAUDIO_OK && _outputStream != nullptr ) { _sampleRate = AAudioStream_getSampleRate( _outputStream ); _framesPerBurst = AAudioStream_getFramesPerBurst( _outputStream ); AudioEngineProps::SAMPLE_RATE = _sampleRate; updateBufferSizeInFrames( AAudioStream_setBufferSizeInFrames( _outputStream, _framesPerBurst )); _underrunCountOutputStream = AAudioStream_getXRunCount( _outputStream ); } else { return; } AAudioStreamBuilder_delete( builder ); }
  5. streamΛ։࢝ɾఀࢭ͢Δ void AAudio_IO::startStream( AAudioStream* stream ) { aaudio_result_t result =

    static_cast<aaudio_result_t>(AAudioStream_requestStart( stream )); if ( result != AAUDIO_OK ) { return; } } void AAudio_IO::stopStream( AAudioStream* stream ) { if ( stream == nullptr ) { return; } aaudio_result_t result = static_cast<aaudio_result_t>(AAudioStream_requestStop( stream )); }
  6. inline void optimizeThreadPerformance( const std::vector<int>& cpuIds ) { cpu_set_t mask;

    pid_t current_thread_id = gettid(); cpu_set_t cpu_set; CPU_ZERO( &cpu_set ); if ( cpuIds.empty() ) { int current_cpu_id = sched_getcpu(); CPU_SET( current_cpu_id, &cpu_set ); } else { for ( size_t i = 0; i < cpuIds.size(); i++ ) { int cpu_id = cpuIds.at( i ); CPU_SET( cpu_id, &cpu_set ); } } } CPUΞϑΟχςΟΛεϨουʹઃఆ͢Δ w ΞϑΟχςΟΛઃఆ͢Δ͜ͱͰɺ$16ύϑΥʔ ϚϯεΛۃݶ·Ͱ޲্ͤ͞Δ͜ͱ͕Ͱ͖Δ w ϓϩηεɾεϨου͸04ʹΑͬͯͲΕ͔ͷ $16ίΞ্Ͱ࣮ߦ͞ΕΔɻ$16ΞϑΟχςΟΛ ઃఆ͢Δ͜ͱͰɺͦͷ࣮ߦ͞ΕΔ$16ίΞΛ೚ ҙʹ੍ݶɾࢦఆ͢Δ͜ͱ͕Ͱ͖Δɻ