From 8c2b9dac59a4f26007749a092cc36288d314e503 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Mon, 24 Aug 2015 20:31:47 +1000 Subject: [PATCH] Rename several methods in PortAudioIO class return ErrorCode's and handle them where necessary --- libs/backends/portaudio/portaudio_backend.cc | 20 +++++------ libs/backends/portaudio/portaudio_io.cc | 35 +++++++++++--------- libs/backends/portaudio/portaudio_io.h | 12 +++---- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index 882fb47487..ddbf9d422b 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -458,10 +458,10 @@ PortAudioBackend::_start (bool for_latency_measurement) PortAudioIO::ErrorCode err; - err = _pcmio->pcm_setup(name_to_id(_input_audio_device), - name_to_id(_output_audio_device), - _samplerate, - _samples_per_period); + err = _pcmio->open_blocking_stream(name_to_id(_input_audio_device), + name_to_id(_output_audio_device), + _samplerate, + _samples_per_period); switch (err) { case PortAudioIO::NoError: @@ -558,7 +558,7 @@ PortAudioBackend::_start (bool for_latency_measurement) if (timeout == 0 || !_active) { DEBUG_AUDIO("Failed to start main audio thread\n"); - _pcmio->pcm_stop(); + _pcmio->close_stream(); _run = false; unregister_ports(); _active = false; @@ -1387,8 +1387,8 @@ PortAudioBackend::main_process_thread () manager.registration_callback(); manager.graph_order_callback(); - if (_pcmio->pcm_start()) { - _pcmio->pcm_stop (); + if (_pcmio->start_stream() != PortAudioIO::NoError) { + _pcmio->close_stream (); _active = false; engine.halted_callback(get_error_string(AudioDeviceIOError).c_str()); } @@ -1496,7 +1496,7 @@ PortAudioBackend::main_process_thread () /* call engine process callback */ if (engine.process_callback (_samples_per_period)) { - _pcmio->pcm_stop (); + _pcmio->close_stream (); _active = false; return 0; } @@ -1559,7 +1559,7 @@ PortAudioBackend::main_process_thread () // TODO clear midi or stop midi recv when entering fwheelin' if (engine.process_callback (_samples_per_period)) { - _pcmio->pcm_stop (); + _pcmio->close_stream(); _active = false; return 0; } @@ -1604,7 +1604,7 @@ PortAudioBackend::main_process_thread () } } - _pcmio->pcm_stop (); + _pcmio->close_stream(); _active = false; if (_run) { engine.halted_callback(get_error_string(AudioDeviceIOError).c_str()); diff --git a/libs/backends/portaudio/portaudio_io.cc b/libs/backends/portaudio/portaudio_io.cc index 18eae36fd9..4e7013f060 100644 --- a/libs/backends/portaudio/portaudio_io.cc +++ b/libs/backends/portaudio/portaudio_io.cc @@ -56,7 +56,7 @@ PortAudioIO::PortAudioIO () PortAudioIO::~PortAudioIO () { - pcm_stop(); + close_stream(); pa_deinitialize (); clear_device_lists (); @@ -548,11 +548,15 @@ PortAudioIO::reset_stream_dependents () _cur_output_latency = 0; } -void -PortAudioIO::pcm_stop () +PortAudioIO::ErrorCode +PortAudioIO::close_stream() { - if (_stream) { - Pa_CloseStream (_stream); + if (!_stream) return NoError; + + PaError err = Pa_CloseStream (_stream); + + if (err != paNoError) { + return StreamCloseError; } _stream = NULL; @@ -560,17 +564,18 @@ PortAudioIO::pcm_stop () free (_input_buffer); _input_buffer = NULL; free (_output_buffer); _output_buffer = NULL; + return NoError; } -int -PortAudioIO::pcm_start() +PortAudioIO::ErrorCode +PortAudioIO::start_stream() { PaError err = Pa_StartStream (_stream); if (err != paNoError) { - return -1; + return StreamStartError; } - return 0; + return NoError; } bool @@ -730,10 +735,10 @@ PortAudioIO::pre_stream_open(int device_input, } PortAudioIO::ErrorCode -PortAudioIO::pcm_setup(int device_input, - int device_output, - double sample_rate, - uint32_t samples_per_period) +PortAudioIO::open_blocking_stream(int device_input, + int device_output, + double sample_rate, + uint32_t samples_per_period) { PaStreamParameters inputParam; PaStreamParameters outputParam; @@ -761,12 +766,12 @@ PortAudioIO::pcm_setup(int device_input, if (!set_sample_rate_and_latency_from_stream()) { DEBUG_AUDIO ("PortAudio failed to query stream information.\n"); - pcm_stop(); + close_stream(); return StreamOpenError; } if (!allocate_buffers_for_blocking_api(samples_per_period)) { - pcm_stop(); + close_stream(); return StreamOpenError; } return NoError; diff --git a/libs/backends/portaudio/portaudio_io.h b/libs/backends/portaudio/portaudio_io.h index 7b54f676fe..e98f15451e 100644 --- a/libs/backends/portaudio/portaudio_io.h +++ b/libs/backends/portaudio/portaudio_io.h @@ -83,13 +83,13 @@ public: std::string control_app_name (int device_id) const; void launch_control_app (int device_id); - void pcm_stop (void); - int pcm_start (void); + ErrorCode open_blocking_stream(int device_input, + int device_output, + double sample_rate, + uint32_t samples_per_period); + ErrorCode start_stream(void); - ErrorCode pcm_setup(int device_input, - int device_output, - double sample_rate, - uint32_t samples_per_period); + ErrorCode close_stream(void); uint32_t n_playback_channels (void) const { return _playback_channels; } uint32_t n_capture_channels (void) const { return _capture_channels; }