# HG changeset patch # User Mike Miller # Date 1423355924 18000 # Node ID b3363c531662b669569e798dcbec95cdd1da3bf9 # Parent cdf9c83b0e791c77ea2974b2bdd39e1a6b15d535 Stop audioplayer and audiorecorder when done or interrupted * audiodevinfo.cc (audioplayer::playblocking, audiorecorder::recordblocking): Use unwind_protect to stop stream. diff -r cdf9c83b0e79 -r b3363c531662 libinterp/dldfcn/audiodevinfo.cc --- a/libinterp/dldfcn/audiodevinfo.cc Sun Feb 01 19:20:40 2015 -0500 +++ b/libinterp/dldfcn/audiodevinfo.cc Sat Feb 07 19:38:44 2015 -0500 @@ -41,6 +41,7 @@ #include "ov-int32.h" #include "ov-struct.h" #include "parse.h" +#include "unwind-prot.h" #if defined (HAVE_PORTAUDIO) @@ -846,6 +847,12 @@ return paContinue; } +static void +safe_audioplayer_stop (audioplayer *player) +{ + player->stop (); +} + audioplayer::audioplayer (void) : octave_callback_function (0), id (-1), fs (0), nbits (16), channels (0), sample_number (0), @@ -1151,6 +1158,10 @@ start = get_sample_number (); end = get_end_sample (); + unwind_protect frame; + + frame.add_fcn (safe_audioplayer_stop, this); + for (unsigned int i = start; i < end; i += buffer_size) { OCTAVE_QUIT; @@ -1161,24 +1172,6 @@ err = Pa_WriteStream (stream, buffer, buffer_size); } - - err = Pa_StopStream (stream); - if (err != paNoError) - { - error ("audioplayer: failed to stop audio playback stream"); - return; - } - - err = Pa_CloseStream (stream); - if (err != paNoError) - { - error ("audioplayer: failed to close audio playback stream"); - return; - } - - stream = 0; - set_sample_number (0); - reset_end_sample (); } void @@ -1534,6 +1527,12 @@ return paContinue; } +static void +safe_audiorecorder_stop (audiorecorder *recorder) +{ + recorder->stop (); +} + audiorecorder::audiorecorder (void) : octave_callback_function (0), id (-1), fs (44100), nbits (16), channels (2), sample_number (0), @@ -1826,6 +1825,10 @@ unsigned int frames = seconds * get_fs (); + unwind_protect frame; + + frame.add_fcn (safe_audiorecorder_stop, this); + for (unsigned int i = 0; i < frames; i += buffer_size) { OCTAVE_QUIT;