i building audio app playback , stop features. function playaudio() playback, stopaudio() stop. expected file format wav. the main implementation of playaudio() below: playaudio() { ... ... int err = snd_pcm_open(&handle, "default", snd_pcm_stream_playback, 0); if ( err < 0 ) { printf("scm open failed: %s\n", snd_strerror(err)); exit(err); } while ( 0 < numofframes) { ... ... ssize_t frames = snd_pcm_writei(handle, &buffer[0], periodsize); ... ... } snd_pcm_drain(handle); snd_pcm_close(handle); } stopaudio() { snd_pcm_drop( m_handle ); } while audio playing back, program blocked @ line of snd_pcm_drain(handle); until playback completion. during period, expect stop audio play. action click stop button on ui , call snd_pcm_drop( m_handle ) finally. voice stopped, programm running still staying @ line of snd_pcm_drain(handle) untils several seconds later...
Comments
Post a Comment