私の iOS アプリ (openFrameworks を使用) は、次の行での起動時に 30 ~ 40% の確率でクラッシュします。
if(soundInputPtr!=NULL) soundInputPtr->audioIn(tempBuffer, ioData->mBuffers[i].mDataByteSize/2, 1);
これは、より大きな関数の中にありますofxiPhoneSoundStream.m
static OSStatus recordingCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
ofSoundStreamSetup(0, 1, this, 44100, 256, 4);
でオーディオ設定を行っていますsetup()
。
シミュレーターでは、このクラッシュは 100% の確率で発生します。(a)何が起こっているのか、または(b)それをデバッグする方法はありますか?
更新: スタック トレース:
Thread 11 AURemoteIO::IOThread, Queue : (null)
#0 0x00008ff2 in Gameplay::listen() at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/include/c++/4.2.1/bits/basic_string.h:238
#1 0x003178bc in recordingCallback(void*, unsigned long*, AudioTimeStamp const*, unsigned long, unsigned long, AudioBufferList*) at /Developer/of_007_iphone/libs/openFrameworks/sound/ofxiPhoneSoundStream.mm:143
#2 0x019447e4 in AUIOHelper::NotifyInputAvailable(AudioTimeStamp const&, unsigned long, AudioBufferList const&) ()
#3 0x0192baf1 in AURemoteIO::PerformIO(unsigned int, unsigned int, XAudioTimeStamp const&, XAudioTimeStamp const&, int&) ()
#4 0x0192bbc1 in AURIOCallbackReceiver_PerformIO ()
#5 0x0191b3bf in _XPerformIO ()
#6 0x01861c11 in mshMIGPerform ()
#7 0x018e4180 in MSHMIGDispatchMessage ()
#8 0x019297ba in AURemoteIO::IOThread::Run() ()
#9 0x0192e8e1 in AURemoteIO::IOThread::Entry(void*) ()
#10 0x01836972 in CAPThread::Entry(CAPThread*) ()
#11 0x97bf7259 in _pthread_start ()
#12 0x97bf70de in thread_start ()
その後Thread 11 AURemoteIO::IOThread: Program received signal: "EXC_BAD_ACCESS"
要求に応じて、recordingCallback()
:
static OSStatus recordingCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
AudioBufferList list;
// redundant
list.mNumberBuffers = 1;
list.mBuffers[0].mData = sampleBuffer;
list.mBuffers[0].mDataByteSize = 2 * inNumberFrames;
list.mBuffers[0].mNumberChannels = 1;
ioData = &list;
//printf("No buffers: %d, buffer length: %d bus number: %d\n", ioData->mNumberBuffers, ioData->mBuffers[0].mDataByteSize, inBusNumber);
// Then:
// Obtain recorded samples
OSStatus status = AudioUnitRender(audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
checkStatus(status);
if(status!=noErr) return status;
if(ioData->mNumberBuffers>0) {
int i = 0;
short int *buffer = (short int *) list.mBuffers[i].mData;
for(int j = 0; j < ioData->mBuffers[i].mDataByteSize/2; j++) {
// go through each sample and turn it into a float
tempBuffer[j] = (float)buffer[j]/32767.f;
}
done = true;
// THIS LINE IS LINE 143
if(soundInputPtr!=NULL) soundInputPtr->audioIn(tempBuffer, ioData->mBuffers[i].mDataByteSize/2, 1);
}
return noErr;
}
上記でマークされた 143 行目も、次のようになります。if(soundInputPtr!=NULL) soundInputPtr->audioIn(tempBuffer, ioData->mBuffers[i].mDataByteSize/2, 1);
追加した:
Gameplay::listen()
は単なる最大/最小トラッカーです。以前はもっと多くのことを行っていましたが、これらの機能を に移動したほうがよいことに気付きましたaudioRecieved()
。実際、この関数を呼び出すコードは他にありません。
void Gameplay::listen() {
// track extremes for XML purpose
if (pitchAvg > move.highestPitch) move.highestPitch = pitchAvg;
if ((pitchAvg < move.lowestPitch) && pitchAvg != 0) move.lowestPitch = pitchAvg;
if (ampAvg > move.loudestVol) move.loudestVol = ampAvg;
if ((ampAvg < move.softestVol) && ampAvg > 0.15) move.softestVol = ampAvg;
}