在 AudioFileOpenURL 之后附加音频时出现问题

发布于 2024-12-06 16:13:30 字数 1996 浏览 0 评论 0原文

在向音频数据添加额外录音后,我在播放音频数据时遇到问题。以下是事件的一般顺序,不会返回任何错误:

AudioQueueNewInput       // Start audio queue
AudioFileCreateWithURL   // Create audio file
AudioFileSetProperty     // Set magic cookie

AudioQueueAllocateBuffer // Allocate buffers
AudioQueueEnqueueBuffer  // Prime buffer
AudioQueueStart          // Start the audio queue

// Record some audio in the audio queue callback...
AudioQueueWritePackets
AudioQueueEnqueueBuffer

AudioQueueStop           // Stop the queue
AudioQueueFlush          // Flush remaining buffers in the queue
AudioFileSetProperty     // Set magic cookie again (needed for some formats?)
AudioQueueDispose        // Dispose queue
AudioFileClose           // Close the file

我可以启动和停止队列以附加记录,并且效果很好。音频完美附加,我可以按预期播放。当我重新打开文件并尝试附加时,问题就出现了:

AudioQueueNewInput       // Start audio queue
AudioFileOpenURL         // Re-open audio file
AudioFileGetProperty     // Get packet count and resume recording at last packet
AudioFileOptimize        // "Optimize" the file for appending
AudioFileSetProperty     // Set magic cookie

AudioQueueAllocateBuffer // Allocate buffers
AudioQueueEnqueueBuffer  // Prime buffer
AudioQueueStart          // Start the audio queue

// Record some audio in the audio queue callback...
AudioQueueWritePackets
AudioQueueEnqueueBuffer

AudioQueueStop           // Stop the queue
AudioQueueFlush          // Flush remaining buffers in the queue

我小心地从最后一个音频包恢复录制,实际上,数据正在附加到文件中,因为我可以看到文件大小增长。但是,当我播放该文件时,我听不到附加的音频。它会播放原始音频,但在我期望听到附加音频之前就停止了。

我尝试了不同的组合来移动 AudioFileOptimize 并重置 magic cookie 但无济于事。

我使用的音频格式如下:

static const AudioStreamBasicDescription kMyAudioFormat = {
    .mFormatID = kAudioFormatAppleIMA4,
    .mSampleRate = 44100.0,
    .mChannelsPerFrame = 2,
    .mBitsPerChannel = 0,
    .mBytesPerPacket = 68,
    .mBytesPerFrame = 0,
    .mFramesPerPacket = 64,
    .mFormatFlags = 0
};

这是怎么回事?为什么我重新打开AudioFileID后附加的音频无法播放?

I'm having a problem playing back audio data after appending extra recording to it. Here's the general sequence of events, which don't return any errors:

AudioQueueNewInput       // Start audio queue
AudioFileCreateWithURL   // Create audio file
AudioFileSetProperty     // Set magic cookie

AudioQueueAllocateBuffer // Allocate buffers
AudioQueueEnqueueBuffer  // Prime buffer
AudioQueueStart          // Start the audio queue

// Record some audio in the audio queue callback...
AudioQueueWritePackets
AudioQueueEnqueueBuffer

AudioQueueStop           // Stop the queue
AudioQueueFlush          // Flush remaining buffers in the queue
AudioFileSetProperty     // Set magic cookie again (needed for some formats?)
AudioQueueDispose        // Dispose queue
AudioFileClose           // Close the file

I can start and stop the queue to append recording and it works great. The audio appends perfectly and I can play back as I expect. The problem comes when I re-open the file, and try to append:

AudioQueueNewInput       // Start audio queue
AudioFileOpenURL         // Re-open audio file
AudioFileGetProperty     // Get packet count and resume recording at last packet
AudioFileOptimize        // "Optimize" the file for appending
AudioFileSetProperty     // Set magic cookie

AudioQueueAllocateBuffer // Allocate buffers
AudioQueueEnqueueBuffer  // Prime buffer
AudioQueueStart          // Start the audio queue

// Record some audio in the audio queue callback...
AudioQueueWritePackets
AudioQueueEnqueueBuffer

AudioQueueStop           // Stop the queue
AudioQueueFlush          // Flush remaining buffers in the queue

I take care to resume recording from the last packet of audio, and indeed, data is being appended to the file because I can see the file size grow. However, when I play back the file, I do not hear the appended audio. It plays back the original audio, but stops before I expect to hear the additional audio.

I've tried different combinations moving around AudioFileOptimize and resetting the magic cookie to no avail.

The audio format I'm using is as follows:

static const AudioStreamBasicDescription kMyAudioFormat = {
    .mFormatID = kAudioFormatAppleIMA4,
    .mSampleRate = 44100.0,
    .mChannelsPerFrame = 2,
    .mBitsPerChannel = 0,
    .mBytesPerPacket = 68,
    .mBytesPerFrame = 0,
    .mFramesPerPacket = 64,
    .mFormatFlags = 0
};

What is going on here? Why won't the appended audio play back after I re-open the AudioFileID?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-12-13 16:13:30

需要调用AudioFileClose。有关详细信息,请参阅:http://lists.apple.com/档案/Coreaudio-api/2011/Oct/msg00014.html

Needed to call AudioFileClose. For more info see: http://lists.apple.com/archives/Coreaudio-api/2011/Oct/msg00014.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文