summaryrefslogtreecommitdiff
path: root/gr-audio/lib/alsa
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2014-08-13 16:06:19 -0400
committerTom Rondeau <tom@trondeau.com>2014-08-13 17:06:15 -0400
commit2fc6293932564fd9f84a31898aa11c0b9a3b44cc (patch)
tree08ab00c8881968bcb86dfae04682ddbbf6cab8ac /gr-audio/lib/alsa
parentf1c8ab4aff39340da87b82758263c11b4c9a6754 (diff)
audio: modified the audio registration system.
Instead of static functions and macros, this just uses simple ifdefs in the code to register new audio components if cmake found them. The code is more complicated for the developer, if we ever add a new audio machine. But this allows us to use gr-audio in statically linked cases.
Diffstat (limited to 'gr-audio/lib/alsa')
-rw-r--r--gr-audio/lib/alsa/alsa_sink.cc34
-rw-r--r--gr-audio/lib/alsa/alsa_source.cc29
2 files changed, 31 insertions, 32 deletions
diff --git a/gr-audio/lib/alsa/alsa_sink.cc b/gr-audio/lib/alsa/alsa_sink.cc
index a9224733aa..cfb247520f 100644
--- a/gr-audio/lib/alsa/alsa_sink.cc
+++ b/gr-audio/lib/alsa/alsa_sink.cc
@@ -36,15 +36,16 @@
namespace gr {
namespace audio {
- AUDIO_REGISTER_SINK(REG_PRIO_HIGH, alsa)(int sampling_rate,
- const std::string &device_name,
- bool ok_to_block)
+ sink::sptr
+ alsa_sink_fcn(int sampling_rate,
+ const std::string &device_name,
+ bool ok_to_block)
{
return sink::sptr
(new alsa_sink(sampling_rate, device_name, ok_to_block));
}
- static bool CHATTY_DEBUG = false;
+ static bool CHATTY_DEBUG = true;
static snd_pcm_format_t acceptable_formats[] = {
// these are in our preferred order...
@@ -111,8 +112,8 @@ namespace gr {
if(ok_to_block == false)
snd_pcm_nonblock(d_pcm_handle, !ok_to_block);
if(error < 0){
- fprintf(stderr, "audio_alsa_sink[%s]: %s\n",
- d_device_name.c_str(), snd_strerror(error));
+ GR_LOG_ERROR(d_logger, boost::format("[%1%]: %2%") \
+ % (d_device_name) % (snd_strerror(error)));
throw std::runtime_error("audio_alsa_sink");
}
@@ -171,9 +172,9 @@ namespace gr {
bail("failed to set rate near", error);
if(orig_sampling_rate != d_sampling_rate) {
- fprintf(stderr, "audio_alsa_sink[%s]: unable to support sampling rate %d\n",
- snd_pcm_name(d_pcm_handle), orig_sampling_rate);
- fprintf(stderr, " card requested %d instead.\n", d_sampling_rate);
+ GR_LOG_INFO(d_logger, boost::format("[%1%]: unable to support sampling rate %2%\n\tCard requested %3% instead.") \
+ % snd_pcm_name(d_pcm_handle) % orig_sampling_rate \
+ % d_sampling_rate);
}
/*
@@ -185,8 +186,6 @@ namespace gr {
unsigned int min_nperiods, max_nperiods;
snd_pcm_hw_params_get_periods_min(d_hw_params, &min_nperiods, &dir);
snd_pcm_hw_params_get_periods_max(d_hw_params, &max_nperiods, &dir);
- //fprintf(stderr, "alsa_sink: min_nperiods = %d, max_nperiods = %d\n",
- // min_nperiods, max_nperiods);
unsigned int orig_nperiods = d_nperiods;
d_nperiods = std::min (std::max (min_nperiods, d_nperiods), max_nperiods);
@@ -274,10 +273,11 @@ namespace gr {
d_buffer = new char[d_buffer_size_bytes];
- if(CHATTY_DEBUG)
- fprintf(stdout, "audio_alsa_sink[%s]: sample resolution = %d bits\n",
- snd_pcm_name(d_pcm_handle),
- snd_pcm_hw_params_get_sbits(d_hw_params));
+ if(CHATTY_DEBUG) {
+ GR_LOG_DEBUG(d_logger, boost::format("[%1%]: sample resolution = %d bits") \
+ % snd_pcm_name(d_pcm_handle) \
+ % snd_pcm_hw_params_get_sbits(d_hw_params));
+ }
switch(d_format) {
case SND_PCM_FORMAT_S16:
@@ -533,8 +533,8 @@ namespace gr {
void
alsa_sink::output_error_msg (const char *msg, int err)
{
- fprintf(stderr, "audio_alsa_sink[%s]: %s: %s\n",
- snd_pcm_name(d_pcm_handle), msg, snd_strerror(err));
+ GR_LOG_ERROR(d_logger, boost::format("[%1%]: %2%: %3%") \
+ % snd_pcm_name(d_pcm_handle) % msg % snd_strerror(err));
}
void
diff --git a/gr-audio/lib/alsa/alsa_source.cc b/gr-audio/lib/alsa/alsa_source.cc
index b6103c3c51..92a7bc549f 100644
--- a/gr-audio/lib/alsa/alsa_source.cc
+++ b/gr-audio/lib/alsa/alsa_source.cc
@@ -36,9 +36,10 @@
namespace gr {
namespace audio {
- AUDIO_REGISTER_SOURCE(REG_PRIO_HIGH, alsa)(int sampling_rate,
- const std::string &device_name,
- bool ok_to_block)
+ source::sptr
+ alsa_source_fcn(int sampling_rate,
+ const std::string &device_name,
+ bool ok_to_block)
{
return source::sptr
(new alsa_source(sampling_rate, device_name, ok_to_block));
@@ -106,8 +107,8 @@ namespace gr {
error = snd_pcm_open(&d_pcm_handle, d_device_name.c_str(),
SND_PCM_STREAM_CAPTURE, 0);
if(error < 0){
- fprintf(stderr, "audio_alsa_source[%s]: %s\n",
- d_device_name.c_str(), snd_strerror(error));
+ GR_LOG_ERROR(d_logger, boost::format("[%1%]: %2%") \
+ % (d_device_name) % (snd_strerror(error)));
throw std::runtime_error("audio_alsa_source");
}
@@ -168,9 +169,9 @@ namespace gr {
bail("failed to set rate near", error);
if(orig_sampling_rate != d_sampling_rate){
- fprintf(stderr, "audio_alsa_source[%s]: unable to support sampling rate %d\n",
- snd_pcm_name (d_pcm_handle), orig_sampling_rate);
- fprintf(stderr, " card requested %d instead.\n", d_sampling_rate);
+ GR_LOG_INFO(d_logger, boost::format("[%1%]: unable to support sampling rate %2%\n\tCard requested %3% instead.") \
+ % snd_pcm_name(d_pcm_handle) % orig_sampling_rate \
+ % d_sampling_rate);
}
/*
@@ -182,8 +183,6 @@ namespace gr {
unsigned int min_nperiods, max_nperiods;
snd_pcm_hw_params_get_periods_min(d_hw_params, &min_nperiods, &dir);
snd_pcm_hw_params_get_periods_max(d_hw_params, &max_nperiods, &dir);
- //fprintf (stderr, "alsa_source: min_nperiods = %d, max_nperiods = %d\n",
- // min_nperiods, max_nperiods);
unsigned int orig_nperiods = d_nperiods;
d_nperiods = std::min(std::max (min_nperiods, d_nperiods), max_nperiods);
@@ -253,9 +252,9 @@ namespace gr {
d_buffer = new char[d_buffer_size_bytes];
if(CHATTY_DEBUG) {
- fprintf(stdout, "audio_alsa_source[%s]: sample resolution = %d bits\n",
- snd_pcm_name(d_pcm_handle),
- snd_pcm_hw_params_get_sbits(d_hw_params));
+ GR_LOG_DEBUG(d_logger, boost::format("[%1%]: sample resolution = %d bits") \
+ % snd_pcm_name(d_pcm_handle) \
+ % snd_pcm_hw_params_get_sbits(d_hw_params));
}
switch(d_format) {
@@ -499,8 +498,8 @@ namespace gr {
void
alsa_source::output_error_msg(const char *msg, int err)
{
- fprintf(stderr, "audio_alsa_source[%s]: %s: %s\n",
- snd_pcm_name(d_pcm_handle), msg, snd_strerror (err));
+ GR_LOG_ERROR(d_logger, boost::format("[%1%]: %2%: %3%") \
+ % snd_pcm_name(d_pcm_handle) % msg % snd_strerror(err));
}
void