0

コア プロットを使用して、マイクに入力されるオーディオの波形を描画しています。それはうまく機能しますが、いつかこのエラーが発生します:malloc:*オブジェクト0x175a1550のエラー:解放されているポインターが割り当てられていません*デバッグするためにmalloc_error_breakにブレークポイントを設定します。コアプロット配列がクリアされているときに、時折発生します (1 分後、10 分後、1 時間後...状況によります!)。

-(void)refreshScope: (NSTimer*)theTimer;
{
    if ([[audio dataForScope] count] == 500)
    {
        [self performSelectorOnMainThread:@selector(reloadDataOnMainThread) withObject:nil waitUntilDone:YES];
        [[audio dataForScope] removeAllObjects]; // HERE !!!!
    }
}

-(void) reloadDataOnMainThread
{
    [audioScope reloadData];
}

dataForScope 配列 (変更可能) は、コードの audio クラスの alloc/init です。オーディオ バッファの整数で埋められます。私はさまざまなことを試しましたが、何もうまくいかないようです。私はいつも同じエラーが発生します ありがとうございました。

編集 :

-(void)processAudio:(AudioBufferList *)bufferList{
    AudioBuffer sourceBuffer = bufferList->mBuffers[0];

    memcpy(tempBuffer.mData, bufferList->mBuffers[0].mData, bufferList->mBuffers[0].mDataByteSize);

    int16_t* samples = (int16_t*)(tempBuffer.mData);

    @autoreleasepool
    {
        for ( int i = 0; i < tempBuffer.mDataByteSize / 2; ++i )
        {
            if(i % 5 == 0)
            {
                if ([dataForScope count] == 500)
                {
                    scopeIndex = 0;
                }

                else
                {
                    float scopeTime = scopeIndex * 1000.0 / SampleRate;
                    id xScope = [NSNumber numberWithFloat: scopeTime];
                    id yScope = [NSNumber numberWithInt: samples[i]/100];
                    [dataForScope addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xScope, @"xScope", yScope, @"yScope", nil]];
                }

                scopeIndex = scopeIndex + 1;
            }
        }

    }
4

1 に答える 1