简体   繁体   中英

Using ALSA's function snd_pcm_writei can I free the sample buffer right away?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM