在 iOS 中写入随机值 AudioBuffer 时无法听到 'noise'

Not able to hear 'noise' when writing random values AudioBuffer in iOS

我正在使用 EZAudio 并尝试将我的软件生成的一些样本写入此库 https://github.com/syedhali/EZAudio 提供的 AudioBuffer,如示例 "Playback By Manual Override".

所示

我的代码是这样的...

// Completely override the output callback function
- (void)
                 output:(EZOutput *)output
callbackWithActionFlags:(AudioUnitRenderActionFlags *)ioActionFlags
            inTimeStamp:(const AudioTimeStamp *)inTimeStamp
            inBusNumber:(UInt32)inBusNumber
         inNumberFrames:(UInt32)inNumberFrames
                 ioData:(AudioBufferList *)ioData {
    //grab latest sample from sample queue
    if (currentAudioPiece == nil || currentAudioPiece.duration >= currentAudioPieceIndex) {
        self.currentAudioPiece = sampleQueue.dequeue;
    }
    AudioBuffer audioBuffer = ioData->mBuffers[0];


    if (true) {
        for (int i = 0; i < audioBuffer.mDataByteSize; i++) {
            uint8_t rofl[2048];
            arc4random_buf(&rofl, 2048);
            audioBuffer.mData = rofl;
        }

        return;
    }

    //... more code that I'll debug later...'

基本上我无法进行健全性检查,以确保随机播放的一堆内存应该会产生一些噪音。我认为问题出在 "audioBuffer.mData = rofl;"。我对在 void* 中使用内存感到很困惑。

jn_pdx是正确的,你需要copy/fillmData而不是重新赋值。

- (void)
                 output:(EZOutput *)output
callbackWithActionFlags:(AudioUnitRenderActionFlags *)ioActionFlags
            inTimeStamp:(const AudioTimeStamp *)inTimeStamp
            inBusNumber:(UInt32)inBusNumber
         inNumberFrames:(UInt32)inNumberFrames
                 ioData:(AudioBufferList *)ioData {
    //grab latest sample from sample queue
    if (currentAudioPiece == nil || currentAudioPiece.duration >= currentAudioPieceIndex) {
        self.currentAudioPiece = sampleQueue.dequeue;
    }
    AudioBuffer audioBuffer = ioData->mBuffers[0];


    if (true) {
        arc4random_buf(audioBuffer.mData, audioBuffer.mDataByteSize);

        return;
    }