diff options
author | David Winter <david.winter@analog.com> | 2021-09-28 13:42:54 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-10-21 10:59:16 -0400 |
commit | db01027fd99c882cf8b3a7dad854606499778e3b (patch) | |
tree | 2b2acc3584dc36668ef3fb2493598e7abf7abd3c /gr-audio/lib/osx/osx_source.cc | |
parent | 61709059f2e40a04ada73785812f19a5fc89cb8a (diff) |
global: Replace stdio logging with logger
This commit replaces many uses of std::c{out,err} and printf with the
appropriate GR_LOG_* directives.
Signed-off-by: David Winter <david.winter@analog.com>
Diffstat (limited to 'gr-audio/lib/osx/osx_source.cc')
-rw-r--r-- | gr-audio/lib/osx/osx_source.cc | 230 |
1 files changed, 126 insertions, 104 deletions
diff --git a/gr-audio/lib/osx/osx_source.cc b/gr-audio/lib/osx/osx_source.cc index 468d65e8f3..94048a7ca5 100644 --- a/gr-audio/lib/osx/osx_source.cc +++ b/gr-audio/lib/osx/osx_source.cc @@ -221,7 +221,8 @@ void osx_source::setup() (d_output_sample_rate < 50000.0 ? 50000 : (UInt32)d_output_sample_rate); #if _OSX_AU_DEBUG_ - std::cerr << "source(): max # samples = " << d_buffer_sample_count << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("source(): max # samples = %d") % d_buffer_sample_count); #endif // create the default AudioUnit for input @@ -331,10 +332,9 @@ void osx_source::setup() err, "Get Device Input Stream Format (before) failed", "audio_osx_source::setup"); #if _OSX_AU_DEBUG_ - std::cerr << std::endl - << "---- Device Stream Format (before) ----" << std::endl - << d_asbd_device << std::endl - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("\n---- Device Stream Format (before) ----\n%s\n") % + d_asbd_device); #endif // try to set the device (input) side of the audio device to the @@ -365,10 +365,9 @@ void osx_source::setup() err, "Get Device Input Stream Format (after) failed", "audio_osx_source::setup"); #if _OSX_AU_DEBUG_ - std::cerr << std::endl - << "---- Device Stream Format (after) ----" << std::endl - << d_asbd_device << std::endl - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("\n---- Device Stream Format (after) ----\n%s\n") % + d_asbd_device); #endif d_device_sample_rate = d_asbd_device.mSampleRate; @@ -388,9 +387,9 @@ void osx_source::setup() "audio_osx_source::setup"); #if _OSX_AU_DEBUG_ - std::cerr << "---- Client Stream Format (Before) ----" << std::endl - << d_asbd_client << std::endl - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("---- Client Stream Format (Before) ----\n%s\n") % + d_asbd_client); #endif // Set the format of all the AUs to the @@ -437,9 +436,9 @@ void osx_source::setup() err, "Get Device Output Stream Format (after) failed", "audio_osx_source::setup"); #if _OSX_AU_DEBUG_ - std::cerr << "---- Client Stream Format (After) ----" << std::endl - << d_asbd_client << std::endl - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("---- Client Stream Format (After) ----\n%s\n") % + d_asbd_client); #endif d_pass_through = (d_asbd_client.mSampleRate == d_output_sample_rate); @@ -646,26 +645,27 @@ void osx_source::setup() check_error_and_throw(err, "AudioUnitInitialize", "audio_osx_source::check_channels"); #if _OSX_AU_DEBUG_ - std::cerr << std::endl - << "audio_osx_source Parameters:" << std::endl - << " Device Sample Rate is " << d_device_sample_rate << std::endl - << " Client Sample Rate is " - << (d_pass_through ? d_output_sample_rate : d_device_sample_rate) - << std::endl - << " User Sample Rate is " << d_output_sample_rate << std::endl - << " Do Passthrough is " << (d_pass_through ? "true" : "false") - << std::endl - << " Max Sample Count is " << d_buffer_sample_count << std::endl - << " # Device Channels is " << d_n_dev_channels << std::endl - << " Device Buffer Size in Frames = " << d_device_buffer_size_frames - << std::endl - << " Lead Size in Frames = " << d_lead_size_frames << std::endl - << " Trail Size in Frames = " << d_trail_size_frames << std::endl - << " Input Buffer Size in Frames = " << d_input_buffer_size_frames - << std::endl - << " Output Buffer Size in Frames = " << d_output_buffer_size_frames - << std::endl - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format(R"EOF( +audio_osx_source Parameters: + Device Sample Rate is %d + Client Sample Rate is %d + User Sample Rate is %d + Do Passthrough is %s + Max Sample Count is %d + # Device Channels is %d + Device Buffer Size in Frames = %d + Lead Size in Frames = %d + Trail Size in Frames = %d + Input Buffer Size in Frames = %d + Output Buffer Size in Frames = %d +)EOF") % d_device_sample_rate % + (d_pass_through ? d_output_sample_rate : d_device_sample_rate) % + d_output_sample_rate % (d_pass_through ? "true" : "false") % + d_buffer_sample_count % d_n_dev_channels % + d_device_buffer_size_frames % d_lead_size_frames % + d_trail_size_frames % d_input_buffer_size_frames % + d_output_buffer_size_frames); #endif } @@ -682,8 +682,9 @@ void osx_source::alloc_audio_buffer_list(AudioBufferList** t_abl, int counter = n_channels; #if _OSX_AU_DEBUG_ - std::cerr << "alloc_audio_buffer_list: (#chan, #bytes) == (" << n_channels << ", " - << input_buffer_size_bytes << ")" << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("alloc_audio_buffer_list: (#chan, #bytes) == (%d, %d)") % + n_channels % input_buffer_size_bytes); #endif while (--counter >= 0) { @@ -731,15 +732,17 @@ bool osx_source::is_running() bool osx_source::start() { #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::start: Starting." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::start: Starting.") % + ((void*)(pthread_self()))); #endif if ((!is_running()) && d_input_au) { #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) - << " : audio_osx_source::start: Starting Audio Unit." << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::start: Starting Audio Unit.") % + ((void*)(pthread_self()))); #endif // reset buffers before starting @@ -760,8 +763,10 @@ bool osx_source::start() } #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::start: Returning." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::start: Returning.") % + (void*)(pthread_self())); + #endif return (true); @@ -770,14 +775,16 @@ bool osx_source::start() bool osx_source::stop() { #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::stop: Starting." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::stop: Starting.") % + ((void*)(pthread_self()))); #endif if (is_running()) { #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) - << " : audio_osx_source::stop: stopping audio unit." << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::stop: stopping audio unit.") % + ((void*)(pthread_self()))); #endif // stop the audio unit @@ -793,8 +800,9 @@ bool osx_source::stop() } #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::stop: Returning." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::stop: Returning.") % + ((void*)(pthread_self()))); #endif return (true); @@ -803,8 +811,9 @@ bool osx_source::stop() void osx_source::teardown() { #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::teardown: Starting." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::teardown: Starting.") % + ((void*)(pthread_self()))); #endif OSStatus err = noErr; @@ -928,8 +937,9 @@ void osx_source::teardown() d_using_default_device = false; #if _OSX_AU_DEBUG_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::teardown: Returning." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::teardown: Returning.") % + ((void*)(pthread_self()))); #endif } @@ -961,7 +971,9 @@ bool osx_source::check_topology(int ninputs, int noutputs) d_n_user_channels = noutputs; #if _OSX_AU_DEBUG_ - std::cerr << "chk_topo: Actual # user output channels = " << noutputs << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("chk_topo: Actual # user output channels = %d") % + noutputs); #endif return (true); @@ -972,8 +984,9 @@ int osx_source::work(int noutput_items, gr_vector_void_star& output_items) { #if _OSX_AU_DEBUG_RENDER_ - std::cerr << ((void*)(pthread_self())) << " : audio_osx_source::work: Starting." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("%s : audio_osx_source::work: Starting.") % + ((void*)(pthread_self()))); #endif if (d_do_reset) { if (d_hardware_changed) { @@ -1000,13 +1013,13 @@ int osx_source::work(int noutput_items, } else { #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: doing reset." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: doing reset."); #endif GR_LOG_WARN(d_logger, - boost::format("\n\nThe default input audio device has " - "changed; resetting audio.\nThere may " - "be a sound glitch while resetting.\n")); + "\n\nThe default input audio device has " + "changed; resetting audio.\nThere may " + "be a sound glitch while resetting.\n"); // for any changes, just tear down the current // configuration, then set it up again using the user's @@ -1017,14 +1030,15 @@ int osx_source::work(int noutput_items, gr::thread::scoped_lock l(d_internal); #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: mutex locked." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: mutex locked."); #endif setup(); start(); #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: returning after reset." << std::endl; + GR_LOG_DEBUG(d_debug_logger, + "audio_osx_source::work: returning after reset."); #endif return (0); } @@ -1033,12 +1047,11 @@ int osx_source::work(int noutput_items, gr::thread::scoped_lock l(d_internal); #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: mutex locked." << std::endl; -#endif + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: mutex locked."); -#if _OSX_AU_DEBUG_RENDER_ - std::cerr << "work1: SC = " << d_queue_sample_count << ", #OI = " << noutput_items - << ", #Chan = " << output_items.size() << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("work1: SC=%d, #OI=%d, #Chan=%d") % d_queue_sample_count % + noutput_items % output_items.size()); #endif // set the actual # of output items to the 'desired' amount then @@ -1058,13 +1071,13 @@ int osx_source::work(int noutput_items, // release control so-as to allow data to be retrieved; // block until there is data to return #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: waiting." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: waiting."); #endif d_waiting_for_data = true; d_cond_data.wait(l); d_waiting_for_data = false; #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: done waiting." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: done waiting."); #endif // the condition's 'notify' was called; acquire control to // keep thread safe @@ -1073,9 +1086,8 @@ int osx_source::work(int noutput_items, // up the next time this method is called. if (d_do_reset) { #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: " - "returning for reset." - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + "audio_osx_source::work: returning for reset."); #endif return (0); } @@ -1083,9 +1095,9 @@ int osx_source::work(int noutput_items, } else { // no data & not blocking; return nothing #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: no data " - "& not blocking; returning 0." - << std::endl; + GR_LOG_DEBUG( + d_debug_logger, + "audio_osx_source::work: no data & not blocking; returning 0."); #endif return (0); } @@ -1096,8 +1108,9 @@ int osx_source::work(int noutput_items, } #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: copying " << actual_noutput_items - << " items per channel" << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("audio_osx_source::work: copying %d items per channel") % + actual_noutput_items); #endif // number of channels @@ -1128,12 +1141,12 @@ int osx_source::work(int noutput_items, d_queue_sample_count -= actual_noutput_items; #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "work2: SC = " << d_queue_sample_count - << ", act#OI = " << actual_noutput_items << std::endl - << "Returning." << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("work2: SC = %d, act#OI = %d\nReturning.") % + d_queue_sample_count % actual_noutput_items); #endif #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::work: returning." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::work: returning."); #endif return (actual_noutput_items); @@ -1158,9 +1171,9 @@ OSStatus osx_source::converter_callback(AudioConverterRef in_audio_converter, This->d_n_actual_input_frames = (*io_number_data_packets); #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cc1: io#DP = " << (*io_number_data_packets) - << ", TIBSB = " << total_input_buffer_size_bytes << ", #C = " << counter - << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("cc1: io#DP = %d, TIBSB = %d, #C = %d") % + (*io_number_data_packets) % total_input_buffer_size_bytes % counter); #endif while (--counter >= 0) { @@ -1171,7 +1184,7 @@ OSStatus osx_source::converter_callback(AudioConverterRef in_audio_converter, } #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cc2: Returning." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "cc2: Returning."); #endif return (noErr); @@ -1185,26 +1198,30 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, AudioBufferList* io_data) { #if _OSX_AU_DEBUG_RENDER_ - std::cerr << ((void*)(pthread_self())) - << " : audio_osx_source::au_input_callback: Starting." << std::endl; + // GR_LOG_DEBUG(This->d_debug_logger, boost::format("%s : + // audio_osx_source::au_input_callback: Starting." ) + // % ((void*)(pthread_self()))); #endif osx_source* This = reinterpret_cast<osx_source*>(in_ref_con); gr::thread::scoped_lock l(This->d_internal); gr::logger_ptr d_logger = This->d_logger; + gr::logger_ptr d_debug_logger = This->d_debug_logger; #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "audio_osx_source::au_input_callback: mutex locked." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "audio_osx_source::au_input_callback: mutex locked."); #endif OSStatus err = noErr; #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb0: in#Fr = " << in_number_frames << ", inBus# = " << in_bus_number - << ", idD = " << ((void*)io_data) - << ", d_ib = " << ((void*)(This->d_input_buffer)) - << ", d_ib#c = " << This->d_input_buffer->mNumberBuffers - << ", SC = " << This->d_queue_sample_count << std::endl; + GR_LOG_DEBUG( + d_debug_logger, + boost::format( + "cb0: in#Fr = %d, inBus# = %d, idD = %d, d_ib = %d, d_ib#c = %d, SC = %d") % + in_number_frames % in_bus_number % ((void*)io_data) % + ((void*)(This->d_input_buffer)) % This->d_input_buffer->mNumberBuffers % + This->d_queue_sample_count); #endif if (This->d_do_reset) { @@ -1279,8 +1296,9 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, #endif #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb1: avail: #IF = " << available_input_frames - << ", #OF = " << available_output_frames << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("cb1: avail: #IF = %d, #OF = %d") % + available_input_frames % available_output_frames); #endif actual_output_frames = available_output_frames; @@ -1303,11 +1321,14 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, // output frames #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb2: actual: #IF = " << This->d_n_actual_input_frames - << ", #OF = " << actual_output_frames << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("cb2: actual: #IF = %d, #OF = %d") % + This->d_n_actual_input_frames % actual_output_frames); + if (This->d_n_actual_input_frames != available_input_frames) - std::cerr << "cb2.1: avail#IF = " << available_input_frames - << ", actual#IF = " << This->d_n_actual_input_frames << std::endl; + GR_LOG_WARN(d_debug_logger, + boost::format("cb2.1: (avail#IF = %d) != (actual#IF = %d)") % + available_input_frames % This->d_n_actual_input_frames); #endif } @@ -1320,7 +1341,7 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, float* in_buffer = (float*)This->d_output_buffer->mBuffers[counter].mData; #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb3: enqueuing audio data." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "cb3: enqueuing audio data."); #endif int l_res = This->d_buffers[counter]->enqueue(in_buffer, actual_output_frames); @@ -1341,9 +1362,10 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, } #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb4: #OI = " << actual_output_frames - << ", #Cnt = " << This->d_queue_sample_count - << ", mSC = " << This->d_buffer_sample_count << std::endl; + GR_LOG_DEBUG(d_debug_logger, + boost::format("cb4: #OI = %d, #Cnt = %d, mSC = %d") % + actual_output_frames % This->d_queue_sample_count % + This->d_buffer_sample_count); #endif // signal that data is available, if appropriate @@ -1353,7 +1375,7 @@ OSStatus osx_source::au_input_callback(void* in_ref_con, } #if _OSX_AU_DEBUG_RENDER_ - std::cerr << "cb5: returning." << std::endl; + GR_LOG_DEBUG(d_debug_logger, "cb5: returning."); #endif return (err); |