gpt4 book ai didi

ios - 应用程序启动时录制 Callback() 时间歇性崩溃

转载 作者:行者123 更新时间:2023-11-29 04:59:04 29 4
gpt4 key购买 nike

我的 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) {

我正在 setup() 中使用 ofSoundStreamSetup(0, 1, this, 44100, 256, 4); 进行音频设置。

在模拟器中,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 ()

然后线程11 AURemoteIO::IOThread:程序收到信号:“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;
}

最佳答案

阅读堆栈跟踪并转到它告诉您的地方。

#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

在该文件的我的副本中,该代码如下所示:

  void
_M_dispose(const _Alloc& __a)
{
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
if (__builtin_expect(this != &_S_empty_rep(), false))
#endif
if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
-1) <= 0)
//Line 238:
_M_destroy(__a);
} // XXX MT

查看文件中的其他位置,basic_string 的析构函数调用该方法来释放字符串的私有(private)存储 (_M_rep())。

对于 Objective-C 对象,像这样的崩溃通常表明对象本身(在本例中为字符串)被废弃,通常是由于过度释放它。但我不知道这对 C++ 对象有多适用; C++ 与 Objective-C 中很多事情的工作方式都不同。

如果您向我们展示 recordingCallback 的代码,并确保包含该文件的第 143 行(再次,请参阅堆栈跟踪以了解我指向此处的原因),我们可能会告诉您更多信息。

关于ios - 应用程序启动时录制 Callback() 时间歇性崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7354964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com