small updates

This commit is contained in:
WolverinDEV
2019-11-09 23:06:20 +01:00
parent 2d9deaa1a4
commit fc02c7008d
5 changed files with 61 additions and 42 deletions
@@ -68,7 +68,6 @@ bool AudioInput::open_device(std::string& error, PaDeviceIndex index) {
parameters.device = this->_current_device_index;
parameters.sampleFormat = paFloat32;
parameters.suggestedLatency = this->_current_device->defaultLowOutputLatency;
auto err = Pa_OpenStream(
&this->input_stream,
&parameters,
@@ -78,8 +77,10 @@ bool AudioInput::open_device(std::string& error, PaDeviceIndex index) {
paClipOff,
&AudioInput::_audio_callback,
this);
if(err != paNoError) {
error = "Pa_OpenStream returned " + to_string(err);
this->input_stream = nullptr;
error = to_string(err) + "/" + Pa_GetErrorText(err);
return false;
}
@@ -111,18 +112,22 @@ bool AudioInput::recording() {
void AudioInput::stop() {
lock_guard lock(this->input_stream_lock);
if(this->input_stream) {
Pa_AbortStream(this->input_stream);
if(Pa_IsStreamActive(this->input_stream))
Pa_StopStream(this->input_stream);
}
}
void AudioInput::close_device() {
lock_guard lock(this->input_stream_lock);
if(this->input_stream) {
/* TODO: Test for errors */
Pa_AbortStream(this->input_stream);
Pa_CloseStream(this->input_stream);
if(Pa_IsStreamActive(this->input_stream))
Pa_StopStream(this->input_stream);
auto error = Pa_CloseStream(this->input_stream);
if(error != paNoError)
log_error(category::audio, tr("Failed to close PA stream: {}"), error);
this->input_stream = nullptr;
this_thread::sleep_for(chrono::seconds{1});
}
}
@@ -254,7 +254,7 @@ bool AudioOutput::open_device(std::string& error, PaDeviceIndex index) {
auto err = Pa_OpenStream(&output_stream, nullptr, &output_parameters, (double) this->_sample_rate, paFramesPerBufferUnspecified, paClipOff, &AudioOutput::_audio_callback, this);
if(err != paNoError) {
error = "Pa_OpenStream returned " + to_string(err);
error = to_string(err) + "/" + Pa_GetErrorText(err);
return false;
}