summaryrefslogtreecommitdiff
path: root/gr-audio/lib/osx/osx_sink.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-audio/lib/osx/osx_sink.cc')
-rw-r--r--gr-audio/lib/osx/osx_sink.cc189
1 files changed, 111 insertions, 78 deletions
diff --git a/gr-audio/lib/osx/osx_sink.cc b/gr-audio/lib/osx/osx_sink.cc
index ef0da038db..2a0fa66934 100644
--- a/gr-audio/lib/osx/osx_sink.cc
+++ b/gr-audio/lib/osx/osx_sink.cc
@@ -16,6 +16,7 @@
#include "osx_sink.h"
#include <gnuradio/io_signature.h>
+#include <gnuradio/logger.h>
#include <gnuradio/prefs.h>
#include <stdexcept>
@@ -88,7 +89,7 @@ void osx_sink::setup()
if (all_names[0].compare(d_desired_name) != 0) {
// yes: log the full device name
- GR_LOG_INFO(d_logger,
+ GR_LOG_INFO(d_debug_logger,
boost::format("Using output audio device '%s'.") %
all_names[0]);
}
@@ -105,15 +106,18 @@ void osx_sink::setup()
osx::find_audio_devices("", false, NULL, &all_names);
- std::string err_str("\n\nA unique output audio device name "
+ std::string err_str("A unique output audio device name "
"matching the string '");
err_str += d_desired_name;
- err_str += "' was not found.\n\n";
+ err_str += "' was not found.";
err_str += "The current known output audio device name";
err_str += ((all_names.size() > 1) ? "s are" : " is");
- err_str += ":\n";
+ err_str += ": ";
for (UInt32 nn = 0; nn < all_names.size(); ++nn) {
- err_str += " " + all_names[nn] + "\n";
+ err_str += all_names[nn];
+ if (nn != all_names - 1) {
+ err_str += ", ";
+ }
}
GR_LOG_ERROR(d_logger, boost::format(err_str));
throw std::runtime_error("audio_osx_sink::setup");
@@ -161,14 +165,13 @@ void osx_sink::setup()
} else {
- GR_LOG_INFO(d_logger,
- boost::format("\n\nUsing output audio device '%s'.\n ... "
- "which is the current default output audio"
- " device.\n Changing the default output"
- " audio device in the System Preferences"
- " will \n result in changing it here, too "
- "(with an internal reconfiguration).\n") %
- std::string(c_name_buf));
+ GR_LOG_INFO(
+ d_debug_logger,
+ boost::format(
+ "Using current default output audio device '%s'. Changing the "
+ "default audio device in the System Preferences will result in "
+ "changing it here, too (with an internal reconfiguration).") %
+ std::string(c_name_buf));
}
d_selected_name = c_name_buf;
@@ -198,9 +201,10 @@ void osx_sink::setup()
(d_input_sample_rate < 50000.0 ? 50000 : (UInt32)d_input_sample_rate);
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self()))
- << " : audio_osx_sink: max # samples = " << d_buffer_size_samples
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self()))
+ << " : audio_osx_sink: max # samples = " << d_buffer_size_samples;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
// create the default AudioUnit for output:
@@ -223,7 +227,7 @@ void osx_sink::setup()
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
if (!comp) {
- GR_LOG_FATAL(d_logger, boost::format("AudioComponentFindNext Failed"));
+ GR_LOG_FATAL(d_logger, "AudioComponentFindNext Failed");
throw std::runtime_error("audio_osx_sink::setup");
}
err = AudioComponentInstanceNew(comp, &d_output_au);
@@ -234,7 +238,7 @@ void osx_sink::setup()
Component comp = FindNextComponent(NULL, &desc);
if (comp == NULL) {
- GR_LOG_FATAL(d_logger, boost::format("FindNextComponent Failed"));
+ GR_LOG_FATAL(d_logger, "FindNextComponent Failed");
throw std::runtime_error("audio_osx_sink::setup");
}
err = OpenAComponent(comp, &d_output_au);
@@ -385,18 +389,20 @@ void osx_sink::setup()
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink Parameters:" << std::endl
- << " Sample Rate is " << d_input_sample_rate << std::endl
- << " Max # samples to store per channel is " << d_buffer_size_samples
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink Parameters: Sample Rate is "
+ << d_input_sample_rate << " Max # samples to store per channel is "
+ << d_buffer_size_samples;
+ GR_LOG_INFO(debug_logger, msg.str());
#endif
}
void osx_sink::teardown()
{
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::teardown: starting"
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : starting";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
OSStatus err = noErr;
@@ -463,8 +469,10 @@ void osx_sink::teardown()
d_output_ad_id = 0;
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::teardown: finished"
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::teardown: finished";
+ ;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
}
@@ -516,8 +524,10 @@ bool osx_sink::check_topology(int ninputs, int noutputs)
d_n_user_channels = ninputs;
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::check_topology: "
- << "Actual # user input channels = " << d_n_user_channels << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::check_topology: "
+ << "Actual # user input channels = " << d_n_user_channels;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
return (true);
@@ -607,8 +617,9 @@ bool osx_sink::start()
if (!is_running() && d_output_au) {
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self()))
- << " : audio_osx_sink::start: starting Output AudioUnit." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " start: starting Output AudioUnit.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
// check channels, (re)allocate and reset buffers if/as necessary
@@ -623,8 +634,9 @@ bool osx_sink::start()
#if _OSX_AU_DEBUG_
else {
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::start: "
- << "already running." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " start: already running.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
}
#endif
@@ -636,15 +648,18 @@ bool osx_sink::stop()
if (is_running()) {
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::stop: "
- << "stopping Output AudioUnit." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " stop: "
+ << "stopping Output AudioUnit.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
// if waiting in ::work, signal to wake up
if (d_waiting_for_data) {
#if _OSX_AU_DEBUG_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::stop: "
- << "signaling waiting condition" << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " stop: signaling waiting condition";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
d_cond_data.notify_one();
}
@@ -668,8 +683,9 @@ bool osx_sink::stop()
}
#if _OSX_AU_DEBUG_
else {
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::stop: "
- << "already stopped." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " stop: already stopped.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
}
#endif
@@ -683,9 +699,11 @@ int osx_sink::work(int noutput_items,
#if _OSX_AU_DEBUG_RENDER_
{
gr::thread::scoped_lock l(d_internal);
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "Starting: #OI = " << noutput_items
- << ", reset = " << (d_do_reset ? "true" : "false") << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
+ << "Starting: #OI = " << noutput_items
+ << ", reset = " << (d_do_reset ? "true" : "false");
+ GR_LOG_INFO(d_debug_logger, msg.str());
}
#endif
if (d_do_reset) {
@@ -703,7 +721,7 @@ int osx_sink::work(int noutput_items,
GR_LOG_FATAL(d_logger,
boost::format("The selected output audio device ('%s') "
- "is no longer available.\n") %
+ "is no longer available.") %
d_selected_name);
return (gr::block::WORK_DONE);
}
@@ -715,15 +733,17 @@ int osx_sink::work(int noutput_items,
#if _OSX_AU_DEBUG_RENDER_
{
gr::thread::scoped_lock l(d_internal);
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "doing reset." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
+ << "doing reset.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
}
#endif
GR_LOG_WARN(d_logger,
- boost::format("\n\nThe default output audio device has "
- "changed; resetting audio.\nThere may "
- "be a sound glitch while resetting.\n"));
+ "The default output audio device has "
+ "changed; resetting audio. There may "
+ "be a sound glitch while resetting.");
// for any changes, just tear down the current
// configuration, then set it up again using the user's
@@ -737,8 +757,9 @@ int osx_sink::work(int noutput_items,
start();
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink: "
- << "returning 0 after reset." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " returning 0 after reset.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
return (0);
}
@@ -764,10 +785,11 @@ int osx_sink::work(int noutput_items,
}
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "qSC = " << d_queue_sample_count << ", lMC = " << l_max_count
- << ", dBSC = " << d_buffer_size_samples << ", #OI = " << noutput_items
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
+ << "qSC = " << d_queue_sample_count << ", lMC = " << l_max_count
+ << ", dBSC = " << d_buffer_size_samples << ", #OI = " << noutput_items;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
if (d_queue_sample_count > l_max_count) {
@@ -783,15 +805,19 @@ int osx_sink::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 << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "waiting." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " work: "
+ << "waiting.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
d_waiting_for_data = true;
d_cond_data.wait(l);
d_waiting_for_data = false;
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "done waiting." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " work: "
+ << "done waiting";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
// the condition's 'notify' was called; acquire control to
// keep thread safe
@@ -800,8 +826,10 @@ int osx_sink::work(int noutput_items,
// up the next time this method is called.
if (d_do_reset) {
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "returning 0 for reset." << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " work: "
+ << "returning 0 for reset.";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
return (0);
}
@@ -847,10 +875,11 @@ int osx_sink::work(int noutput_items,
}
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::work: "
- << "returning: #OI = " << noutput_items
- << ", qSC = " << d_queue_sample_count << ", bSS = " << d_buffer_size_samples
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " work: "
+ << "returning: #OI = " << noutput_items << ", qSC = " << d_queue_sample_count
+ << ", bSS = " << d_buffer_size_samples;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
return (noutput_items);
@@ -873,10 +902,11 @@ OSStatus osx_sink::au_output_callback(void* in_ref_con,
gr::thread::scoped_lock l(This->d_internal);
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::au_output_callback: "
- << "starting: qSC = " << This->d_queue_sample_count
- << ", in#F = " << in_number_frames << ", in#C = " << This->d_n_user_channels
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " : audio_osx_sink::au_output_callback: "
+ << "starting: qSC = " << This->d_queue_sample_count
+ << ", in#F = " << in_number_frames << ", in#C = " << This->d_n_user_channels;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
if (This->d_queue_sample_count < in_number_frames) {
@@ -898,11 +928,12 @@ OSStatus osx_sink::au_output_callback(void* in_ref_con,
int rv = This->d_buffers[nn]->dequeue(out_buffer, &t_n_output_items);
if ((rv != 1) || (t_n_output_items != in_number_frames)) {
-
- std::cerr << "audio_osx_sink::au_output_callback: "
- << "number of available items changing "
- << "unexpectedly (should never happen): was "
- << in_number_frames << " now " << t_n_output_items << std::endl;
+ std::ostringstream msg;
+ msg << "audio_osx_sink::au_output_callback: "
+ << "number of available items changing "
+ << "unexpectedly (should never happen): was " << in_number_frames
+ << " now " << t_n_output_items;
+ GR_LOG_ERROR(d_logger, msg.str());
err = kAudioUnitErr_TooManyFramesToProcess;
}
}
@@ -914,17 +945,19 @@ OSStatus osx_sink::au_output_callback(void* in_ref_con,
if (This->d_waiting_for_data) {
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self()))
- << " : audio_osx_sink::au_output_callback: "
- << "signaling waiting condition" << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " au_output_callback: "
+ << "signaling waiting condition";
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
This->d_cond_data.notify_one();
}
#if _OSX_AU_DEBUG_RENDER_
- std::cerr << ((void*)(pthread_self())) << " : audio_osx_sink::au_output_callback: "
- << "returning: qSC = " << This->d_queue_sample_count << ", err = " << err
- << std::endl;
+ std::ostringstream msg;
+ msg << ((void*)(pthread_self())) << " au_output_callback: "
+ << "returning: qSC = " << This->d_queue_sample_count << ", err = " << err;
+ GR_LOG_INFO(d_debug_logger, msg.str());
#endif
return (err);