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

AVAudioEngineでリアルタイムレンダリング

 AVAudioEngineでリアルタイムレンダリング

iOSDC Japan 2020

Yuki Yasoshima

September 20, 2020
Tweet

More Decks by Yuki Yasoshima

Other Decks in Programming

Transcript

  1. "7"VEJP4PVSDF/PEF ΦʔσΟΦΛग़ྗ͢ΔσʔλΛ౉͢ 4PVSDF/PEF 0VUQVU/PEF "7"VEJP&OHJOF 3FOEFS #MPDL @interface AVAudioSourceNode :

    AVAudioNode <AVAudioMixing> - (instancetype)initWithRenderBlock:(AVAudioSourceNodeRenderBlock)block; - (instancetype)initWithFormat:(AVAudioFormat *)format renderBlock:(AVAudioSourceNodeRenderBlock)block; @end
  2. "7"VEJP4JOL/PEF ΦʔσΟΦͷೖྗ͞ΕͨσʔλΛड͚औΔ *OQVU/PEF 4JOL/PEF "7"VEJP&OHJOF 3FDFJWFS #MPDL @interface AVAudioSinkNode :

    AVAudioNode - (instancetype)initWithReceiverBlock:(AVAudioSinkNodeReceiverBlock)block; @end
  3. ෳ਺ͷ஋ΛΞτϛοΫʹ͢Δ ڞ༻ମͰTUEBUPNJDͷܕͱTUSVDUΛม׵ union Value { void *v; struct { float

    const level; float const peak; }; }; static_assert(sizeof(Value) == sizeof(void *), "");
  4. ෳ਺ͷ஋ΛΞτϛοΫʹ͢Δ ڞ༻ମͰTUEBUPNJDͷܕͱTUSVDUΛม׵ std::atomic<void *> atomicValue; // atomicͷ஋ʹηοτ͢Δ Value setValue{.level =

    0.0f, .peak = 0.0f}; atomicValue = setValue.v; // atomicͷ஋͔Βήοτ͢Δ Value getValue{.v = atomicValue};
  5. ͭͷεϨου͔Βಉ͡σʔλΛѻ͏ %FGFSSFEͷαϯϓϧ αΠϯ೾ੜ੒εϨου 8SJUJOH 3FBEJOH ΞτϛοΫͳϑϥά 8SJUJOHͳΒ αΠϯ೾Λॻ͖ࠐΜͰ 3FBEJOHʹ͢Δ 3FBEJOHͳΒ

    ग़ྗόοϑΝʹ σʔλΛಡΈࠐΜͰ ࠷ޙ·ͰߦͬͨΒ 8SJUJOHʹ͢Δ ڞ༗͢Δσʔλ ͭ ඵؒͷ ΦʔσΟΦσʔλ ग़ྗεϨου