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/windows/windows_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/windows/windows_source.cc')
-rw-r--r-- | gr-audio/lib/windows/windows_source.cc | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/gr-audio/lib/windows/windows_source.cc b/gr-audio/lib/windows/windows_source.cc index 99435a9f44..465c62f028 100644 --- a/gr-audio/lib/windows/windows_source.cc +++ b/gr-audio/lib/windows/windows_source.cc @@ -90,10 +90,11 @@ windows_source::windows_source(int sampling_freq, const std::string device_name) (wave_format.wBitsPerSample / 8); // room for 16-bit audio on one channel. if (open_wavein_device() < 0) { - perror("audio_windows_source:open_wavein_device() failed\n"); + GR_LOG_ERROR(d_logger, + boost::format("open_wavein_device() failed %s" % strerror(errno))); throw std::runtime_error("audio_windows_source:open_wavein_device() failed"); - } else if (verbose) { - GR_LOG_INFO(d_logger, "Opened windows wavein device"); + } else { + GR_LOG_INFO(d_debug_logger, "Opened windows wavein device"); } lp_buffers = new LPWAVEHDR[nPeriods]; for (int i = 0; i < nPeriods; i++) { @@ -105,18 +106,21 @@ windows_source::windows_source(int sampling_freq, const std::string device_name) lp_buffer->lpData = new CHAR[d_buffer_size]; MMRESULT w_result = waveInPrepareHeader(d_h_wavein, lp_buffer, sizeof(WAVEHDR)); if (w_result != 0) { - perror("audio_windows_source: Failed to waveInPrepareHeader"); - throw std::runtime_error("audio_windows_source:open_wavein_device() failed"); + GR_LOG_ERROR( + d_logger, + boost::format("Failed to waveInPrepareHeader %s" % strerror(errno))); + throw std::runtime_error("open_wavein_device() failed"); } waveInAddBuffer(d_h_wavein, lp_buffer, sizeof(WAVEHDR)); } waveInStart(d_h_wavein); - if (verbose) + if (verbose) { GR_LOG_INFO( - d_logger, + d_debug_logger, boost::format( - "Initialized %1% %2%ms audio buffers, total memory used: %3$0.2fkB") % + "Initialized %1% %2% ms audio buffers, total memory used: %3$0.2f kiB") % (nPeriods) % (CHUNK_TIME * 1000) % ((d_buffer_size * nPeriods) / 1024.0)); + } } windows_source::~windows_source() @@ -226,8 +230,8 @@ UINT windows_source::find_device(std::string szDeviceName) if (num < num_devices) { result = num; } else { - GR_LOG_INFO(d_logger, - boost::format("Warning: waveIn deviceID %d was not found, " + GR_LOG_WARN(d_logger, + boost::format("waveIn deviceID %d was not found, " "defaulting to WAVE_MAPPER") % num); result = WAVE_MAPPER; @@ -238,19 +242,21 @@ UINT windows_source::find_device(std::string szDeviceName) for (UINT i = 0; i < num_devices; i++) { WAVEINCAPS woc; if (waveInGetDevCaps(i, &woc, sizeof(woc)) != MMSYSERR_NOERROR) { - perror("Error: Could not retrieve wave out device capabilities for " - "device"); + GR_LOG_ERROR(d_logger, + boost::format("Could not retrieve wave out device " + "capabilities for device %s" % + strerror(errno))); return -1; } if (woc.szPname == szDeviceName) { result = i; } if (verbose) - GR_LOG_INFO(d_logger, + GR_LOG_INFO(d_debug_logger, boost::format("WaveIn Device %d: %s") % i % woc.szPname); } if (result == -1) { - GR_LOG_INFO(d_logger, + GR_LOG_INFO(d_debug_logger, boost::format("Warning: waveIn device '%s' was not found, " "defaulting to WAVE_MAPPER") % szDeviceName); @@ -258,7 +264,9 @@ UINT windows_source::find_device(std::string szDeviceName) } } } else { - perror("Error: No WaveIn devices present or accessible"); + GR_LOG_ERROR(d_logger, + boost::format("No WaveIn devices present or accessible: %s" % + strerror(errno))); } return result; } @@ -284,16 +292,19 @@ int windows_source::open_wavein_device(void) // and stick with WAVE_MAPPER u_device_id = find_device(d_device_name); if (verbose) - GR_LOG_INFO(d_logger, boost::format("waveIn Device ID: %1%") % (u_device_id)); + GR_LOG_INFO(d_debug_logger, + boost::format("waveIn Device ID: %1%") % (u_device_id)); // Check if the sampling rate/bits/channels are good to go with the device. MMRESULT supported = is_format_supported(&wave_format, u_device_id); if (supported != MMSYSERR_NOERROR) { char err_msg[50]; waveInGetErrorText(supported, err_msg, 50); - GR_LOG_INFO(d_logger, boost::format("format error: %s") % err_msg); - perror("audio_windows_source: Requested audio format is not supported by device " - "driver"); + GR_LOG_INFO(d_debug_logger, boost::format("format error: %s") % err_msg); + GR_LOG_ERROR( + d_logger, + boost::format("Requested audio format is not supported by device driver: %s" % + strerror(errno))); return -1; } @@ -306,7 +317,9 @@ int windows_source::open_wavein_device(void) CALLBACK_FUNCTION | WAVE_ALLOWSYNC); if (result) { - perror("audio_windows_source: Failed to open waveform output device."); + GR_LOG_ERROR( + d_logger, + boost::format("Failed to open waveform output device: %s" % strerror(errno))); return -1; } return 0; @@ -318,7 +331,9 @@ static void CALLBACK read_wavein( // Ignore WIM_OPEN and WIM_CLOSE messages if (uMsg == WIM_DATA) { if (!dwInstance) { - perror("audio_windows_source: callback function missing buffer queue"); + GR_LOG_ERROR(d_logger, + boost::format("callback function missing buffer queue: %s" % + strerror(errno))); } LPWAVEHDR lp_wave_hdr = (LPWAVEHDR)dwParam1; // The new audio data boost::lockfree::spsc_queue<LPWAVEHDR>* q = |