如何使用 AudioQueue 从特定位置启动音频文件?
我分析了iPhone开发论坛的“SpeakHere”示例代码。
有一个启动 AudioQueue 的代码如下。
AudioTimeStamp ats = {0};
AudioQueueStart(mQueue, &ats);
但我不知道如何启动文件中间。
我用包括负值在内的各种值更改了 AudioTimeStamp。但它不起作用。
请让我知道您的好意见。谢谢。
I have analyzed "SpeakHere" sample code of iPhone dev forum.
There is a code for starting AudioQueue as following..
AudioTimeStamp ats = {0};
AudioQueueStart(mQueue, &ats);
But I have no idea that how to start middle of file.
I changed AudioTimeStamp with various values include negative. But it does not works.
Please let me know your great opinion. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AudioQueueStart
不是可以帮助您执行此操作的函数。时间就像一个延迟,如果你传递NULL那么这意味着队列将尽快启动。您必须传递要播放的帧并将其排入队列,以计算您必须知道文件具有的帧数以及要播放的(相对)位置。
这些是如何在 SpeakHere 中进行制作的说明
在新的(基于 objc++ 的)SpeakHere
中在 AQPlayer.h 中添加一个私有实例变量:
和一个公共方法:
在 AQPlayer.mm 中的
AQPlayer::SetupNewQueue()
在mIsInitialized = true;
之前添加:现在您必须使用它(例如,在 SpeakHereControler.mm 中添加它并将其链接到 UISlider):
为什么它有效:
为队列提供数据的播放回调函数 AudioQueueOutputCallback带有新数据包,在新的 SpeakHere 中是:
void AQPlayer::AQBufferCallback( , , )
调用AudioFileReadPackets
来读取文件的特定部分并将其排入队列。对于该任务,使用了 mCurrentPacket,这就是我们刚刚在上述方法中调整的内容,因此您想要播放的部分被读取、排队并最终播放:)Just for historical reasons :)
在旧的(基于objc)SpeakHere
中的AudioPlayer.h中添加一个实例变量:
AudioPlayer.m里面
- (void) openPlaybackFile: (CFURLRef) soundFile
添加:
然后向 AudioPlayer.h 和 .m 添加一个方法
现在您必须使用它(例如在 AudioViewController 中添加此方法并将其链接到 UISlider):
当值为 0 时,您将从头开始播放,0.5 从中间开始播放,等等
希望这有帮助。
AudioQueueStart
is not the function that will help you to do that. The time there is like a delay, if you pass NULL then it means that the queue will start ASAP.You have to pass the frame you want to play and enqueue it, to calculate that you have to know the number of frames your file has and the (relative) position you want to play.
These are instructions how to make it in SpeakHere
In the new (objc++ based) SpeakHere
In AQPlayer.h add a private instance variable:
and a public method:
In AQPlayer.mm inside
AQPlayer::SetupNewQueue()
beforemIsInitialized = true;
add:Now you have to use it (In SpeakHereControler.mm add this and link it to a UISlider for example):
Why this works:
The playback callback function AudioQueueOutputCallback that feeds the queue with new packets and which in the new SpeakHere is:
void AQPlayer::AQBufferCallback( , , )
callsAudioFileReadPackets
to read and enqueue a certain part of a file. For that taskmCurrentPacket
is used and that is what we just adjusted in above methods, hence the part you wanted to play is read, enqueued and finally played :)Just for historical reasons :)
In the old (objc based) SpeakHere
In AudioPlayer.h add an instance variable:
AudioPlayer.m inside
- (void) openPlaybackFile: (CFURLRef) soundFile
add:
Then add a method to AudioPlayer.h and .m
Now you have to use it (In AudioViewController add this and link it to a UISlider for example):
When value is 0 you will play from the beggining, 0.5 from the middle, etc.
Hope this helps.