使用 ALSA 的函数 snd_pcm_writei 可以立即释放样本缓冲区吗?
使用ALSA播放音频,调用snd__pcm__writei后,可以立即释放声音样本缓冲区还是需要等到声音播放完毕才能释放样本缓冲区?
例如:
unsigned short *buffer;
buffer = malloc(size of sample to play);
...load data into buffer...
snd_pcm_writei (playback_handle, buffer, size of sample)
free(buffer)
Using ALSA to play audio, after calling snd__pcm__writei, can I free the sound sample buffer right away or do I need to wait until the sound is finished playing before I can free the sample buffer?
For example:
unsigned short *buffer;
buffer = malloc(size of sample to play);
...load data into buffer...
snd_pcm_writei (playback_handle, buffer, size of sample)
free(buffer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的找出方法是从缓冲区末尾开始向后写入,看看是否影响音频播放。如果你这样做了,那么你肯定无法释放缓冲区。如果没有什么区别,那么您可以安全地释放缓冲区,因为声卡不会从该特定的内存块中读取数据。
Easiest way to find out would be to start writing backwards from the end of the buffer and see if you affect the audio playback. If you do then you definitely can't free the buffer. If it makes no difference then you can safely free the buffer as the sound card is not reading from that particular block of memory.