[iOS]Looping Recorderの基礎(Audio Unit (4)) | Cocoa練習帳

[iOS]Looping Recorderの基礎(Audio Unit (4))

Remote IO UnitのRemote Inputで得られるデータについて、調べてみた。




マイク等をつないでいない、素の状態の入力と出力のチャンネル数は、Audio Session Serveiceで得る事ができる。




AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 nChannels = 0;
UInt32 size = sizeof(nChannels);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputNumberChannels,
                        &size,
                        &nChannels);
NSLog(@"Input nChannels:%u", (unsigned int)nChannels);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputNumberChannels,
                        &size,
                        &nChannels);
NSLog(@"Output nChannels:%u", (unsigned int)nChannels);



シミュレータの結果は、以下のとおり。




2012-04-03 06:22:05.331 DemoAudio[8706:10703] Input nChannels:2
2012-04-03 06:22:05.332 DemoAudio[8706:10703] Output nChannels:2



入力も出力も2チャンネル。ステレオのようだ。実機での結果は、以下のとおり。




2012-04-03 06:31:17.136 DemoAudio[7496:707] Input nChannels:17072444
2012-04-03 06:31:17.142 DemoAudio[7496:707] Output nChannels:2



あれ、入力のチャンネル数がおかしい。


シミュレータと実機では得られる入力データが異なった。前回説明したが、シミュレータでは以下のとおり。




2012-04-01 01:45:33.482 DemoAudio[7045:10703] -[AudioUnitViewController record:]
2012-04-01 01:45:34.925 DemoAudio[7045:17503] MyAURenderCallack, inNumberFrames:512
2012-04-01 01:45:34.926 DemoAudio[7045:17503] ioData: mNumberBuffers(1)
2012-04-01 01:45:34.928 DemoAudio[7045:17503] ioData->mBuffers[0]: mNumberChannels(2), mDataByteSize(2048)



実機では、こうなった。




2012-04-03 06:43:20.907 DemoAudio[7496:707] -[AudioUnitViewController record:]
2012-04-03 06:43:21.316 DemoAudio[7496:4203] MyAURenderCallack, inNumberFrames:1024
2012-04-03 06:43:21.319 DemoAudio[7496:4203] ioData: mNumberBuffers(2)
2012-04-03 06:43:21.329 DemoAudio[7496:4203] ioData->mBuffers[0]: mNumberChannels(1), mDataByteSize(4096)
2012-04-03 06:43:21.333 DemoAudio[7496:4203] ioData->mBuffers[1]: mNumberChannels(1), mDataByteSize(4096)



どちらも2チャンネルで、シミュレータはインターリーブ、実機は非インターリーブのようにみえる。




ソースコード
GitHubからどうぞ。

https://github.com/murakami/DemoAudio - GitHub


関連情報
Cocoa Life KOF2011特別編 - Facebook

Cocoa勉強会 関西の会誌。

iPhone Core Audioプログラミング(永野 哲久 著)

とれも参考にさせていただきました。