diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2020-04-11 00:46:24 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-04-13 15:55:41 +0200 |
commit | 337b99e78fddb4589ebbc793d7f4784daa4314d8 (patch) | |
tree | 1f0003755f7a13056ce2600475298a4dbcaa6ef0 /gr-audio/lib/portaudio/portaudio_source.cc | |
parent | 0f88db1ef0569bf6fcd5e9c843da38d487a6f54b (diff) |
audio: replace stderr logging by calls to GR's logging facilties
This is a bit special, in that audio systems tend to have their own ways
of going wrong, and there's platform-specific development debugging
infrastructure in there, which I intentionally did not touch.
I did touch a few commented lines of code in the intention of, if you
enable that line of logging, it should be consistent with the rest.
There's copious amounts of untouched stderr-logging in `#if 0`-disabled
code in OSX's infrastructure.
Diffstat (limited to 'gr-audio/lib/portaudio/portaudio_source.cc')
-rw-r--r-- | gr-audio/lib/portaudio/portaudio_source.cc | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/gr-audio/lib/portaudio/portaudio_source.cc b/gr-audio/lib/portaudio/portaudio_source.cc index 7f5b2aeb15..f742549f6b 100644 --- a/gr-audio/lib/portaudio/portaudio_source.cc +++ b/gr-audio/lib/portaudio/portaudio_source.cc @@ -58,11 +58,10 @@ void portaudio_source::create_ringbuffer(void) int bufsize_samples = d_portaudio_buffer_size_frames * d_input_parameters.channelCount; - if (d_verbose) { - fprintf(stderr, - "ring buffer size = %d frames\n", - N_BUFFERS * bufsize_samples / d_input_parameters.channelCount); - } + if (d_verbose) + GR_LOG_INFO(d_debug_logger, + boost::format("ring buffer size = %d frames") % + (N_BUFFERS * bufsize_samples / d_input_parameters.channelCount)); // FYI, the buffer indices are in units of samples. d_writer = gr::make_buffer(N_BUFFERS * bufsize_samples, sizeof(sample_t)); @@ -113,8 +112,10 @@ int portaudio_source_callback(const void* inputBuffer, self->d_noverruns++; ssize_t r = ::write(2, "aO", 2); // FIXME change to non-blocking call if (r == -1) { - perror("audio_portaudio_source::portaudio_source_callback write error to " - "stderr."); + gr::logger_ptr logger, debug_logger; + gr::configure_default_loggers( + logger, debug_logger, "portaudio_source_callback"); + GR_LOG_ERROR(logger, boost::format("write error: %s") % strerror(errno)); } self->d_ringbuffer_ready = false; @@ -143,8 +144,6 @@ portaudio_source::portaudio_source(int sampling_rate, d_noverruns(0) { memset(&d_input_parameters, 0, sizeof(d_input_parameters)); - // if(LOGGING) - // d_log = gri_logger::singleton(); PaError err; int i, numDevices; @@ -169,33 +168,30 @@ portaudio_source::portaudio_source(int sampling_rate, // FIXME Get smarter about picking something device = Pa_GetDefaultInputDevice(); deviceInfo = Pa_GetDeviceInfo(device); - fprintf(stderr, - "%s is the chosen device using %s as the host\n", - deviceInfo->name, - Pa_GetHostApiInfo(deviceInfo->hostApi)->name); + GR_LOG_ERROR(d_logger, + boost::format("%s is the chosen device using %s as the host") % + deviceInfo->name % Pa_GetHostApiInfo(deviceInfo->hostApi)->name); } else { bool found = false; - + GR_LOG_INFO(d_debug_logger, "Test Devices"); for (i = 0; i < numDevices; i++) { deviceInfo = Pa_GetDeviceInfo(i); - fprintf(stderr, "Testing device name: %s", deviceInfo->name); + GR_LOG_INFO(d_debug_logger, + boost::format("Testing device name: %s...") % deviceInfo->name); if (deviceInfo->maxInputChannels <= 0) { - fprintf(stderr, "\n"); continue; } if (strstr(deviceInfo->name, d_device_name.c_str())) { - fprintf(stderr, " Chosen!\n"); + GR_LOG_INFO(d_debug_logger, " Chosen!"); device = i; - fprintf(stderr, - "%s using %s as the host\n", - d_device_name.c_str(), - Pa_GetHostApiInfo(deviceInfo->hostApi)->name), - fflush(stderr); + GR_LOG_INFO(d_debug_logger, + boost::format("%s using %s as the host") % + d_device_name.c_str() % + Pa_GetHostApiInfo(deviceInfo->hostApi)->name); found = true; deviceInfo = Pa_GetDeviceInfo(device); i = numDevices; // force loop exit - } else - fprintf(stderr, "\n"), fflush(stderr); + } } if (!found) { @@ -236,11 +232,9 @@ bool portaudio_source::check_topology(int ninputs, int noutputs) #if 1 d_portaudio_buffer_size_frames = (int)(0.0213333333 * d_sampling_rate + 0.5); // Force 512 frame buffers at 48000 - fprintf(stderr, - "Latency = %8.5f, requested sampling_rate = %g\n", // Force latency - // to 21.3333333.. ms - 0.0213333333, - (double)d_sampling_rate); + GR_LOG_ERROR(d_logger, + boost::format("Latency = %8.5f, requested sampling_rate = %g") % + 0.0213333333 % (double)d_sampling_rate); #endif err = Pa_OpenStream(&d_stream, &d_input_parameters, @@ -257,15 +251,16 @@ bool portaudio_source::check_topology(int ninputs, int noutputs) } #if 0 - const PaStreamInfo *psi = Pa_GetStreamInfo(d_stream); + const PaStreamInfo *psi = Pa_GetStreamInfo(d_stream); - d_portaudio_buffer_size_frames = (int)(d_input_parameters.suggestedLatency * psi->sampleRate); - fprintf(stderr, "Latency = %7.4f, psi->sampleRate = %g\n", - d_input_parameters.suggestedLatency, psi->sampleRate); + d_portaudio_buffer_size_frames = (int)(d_input_parameters.suggestedLatency * psi->sampleRate); + GR_LOG_ERROR(d_logger, + boost::format("Latency = %7.4f, psi->sampleRate = %g") % + d_input_parameters.suggestedLatency % psi->sampleRate); #endif - - fprintf( - stderr, "d_portaudio_buffer_size_frames = %d\n", d_portaudio_buffer_size_frames); + GR_LOG_ERROR(d_logger, + boost::format("d_portaudio_buffer_size_frames = %d") % + d_portaudio_buffer_size_frames); assert(d_portaudio_buffer_size_frames != 0); @@ -360,11 +355,9 @@ int portaudio_source::work(int noutput_items, void portaudio_source::output_error_msg(const char* msg, int err) { - fprintf(stderr, - "audio_portaudio_source[%s]: %s: %s\n", - d_device_name.c_str(), - msg, - Pa_GetErrorText(err)); + GR_LOG_ERROR(d_logger, + boost::format("%s: %s %s") % d_device_name.c_str() % msg % + Pa_GetErrorText(err)); } void portaudio_source::bail(const char* msg, int err) |