Play raw uncompressed sound with AudioQueue, no sound

冷暖自知 提交于 2019-12-11 01:08:51

问题


I use three buffers with one queue, to play ADPCM data over network. The data is decoded from my app, and the decoded data (uncompressed pcm data) is verified correctly by playing from Audacity. However, I cannot hear any sound when playing from my app using AudioQueue. All AudioQueue API return values are noErr (0). I've been trying to follow AudioQueue does not output any sound by allocating three buffers . It didn't work for me! Somebody knows how to reveal more AudioQueue logs so I could catch the fault point or is there any problem from my code? Thanks!



    ...
    aq->mDataFormat.mSampleRate = format->nSamplesPerSec; // 44100
    aq->mDataFormat.mChannelsPerFrame = format->nChannels; // 1
    aq->mDataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
                                   kAudioFormatFlagIsPacked;
    aq->mDataFormat.mFramesPerPacket = 1;
    aq->mDataFormat.mBitsPerChannel = 16;
    aq->mDataFormat.mFormatID = kAudioFormatLinearPCM;

    ...

    // Fill data before starting                                                                                                                        
    for (i = 0; i bufferByteSize >= size) {
            aq->mBuffers[i]->mAudioDataByteSize =
                size - (kNumberBuffers - 1 - i) * chunkSize;
            memcpy(aq->mBuffers[i]->mAudioData,
                   src + aq->mBuffers[i]->mAudioDataByteSize,
                   aq->mBuffers[i]->mAudioDataByteSize);
            status = AudioQueueEnqueueBuffer(aq->mQueue, aq->mBuffers[i], 0, NULL);
            printf("%s: %d/%d bytes to enqueue - %d\n", __func__,
                   aq->mBuffers[i]->mAudioDataByteSize, size, status);
            size -= aq->mBuffers[i]->mAudioDataByteSize;
            src += aq->mBuffers[i]->mAudioDataByteSize;
        } else {
            aq->mBuffers[i]->mAudioDataByteSize = aq->bufferByteSize;
            memcpy(aq->mBuffers[i]->mAudioData, src, aq->bufferByteSize);
            status = AudioQueueEnqueueBuffer(aq->mQueue, aq->mBuffers[i], 0, NULL);
            printf("%s: enqueue a full buffer[%d]\n - %d\n", __func__, i, status);
                size -= aq->bufferByteSize;
                src += aq->bufferByteSize;
            }
        }
    }


    ...
    status = AudioQueueSetParameter(aq->mQueue, kAudioQueueParam_Volume, 1.0);
    printf("%s: set AudioQueue volume %d\n", __func__, status);
    status = AudioQueueStart(aq->mQueue, NULL);
    printf("%s: start AudioQueue [%d] %d\n", __func__, aq->bufferByteSize, status);

来源:https://stackoverflow.com/questions/9451508/play-raw-uncompressed-sound-with-audioqueue-no-sound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!