diff options
author | Josh Blum | 2011-03-09 00:52:55 -0800 |
---|---|---|
committer | Josh Blum | 2011-03-09 00:52:55 -0800 |
commit | 77da72f511647d458b62ffefaa94662b78d7f7d3 (patch) | |
tree | c66ecde5ec4418b9262c985c8ace4e5ae658a14c /gr-audio/lib | |
parent | b9b5318101d596b8f06cf5640ddceb90bdb9235c (diff) | |
download | gnuradio-77da72f511647d458b62ffefaa94662b78d7f7d3.tar.gz gnuradio-77da72f511647d458b62ffefaa94662b78d7f7d3.tar.bz2 gnuradio-77da72f511647d458b62ffefaa94662b78d7f7d3.zip |
audio: added audio factory registry and top level includes
Diffstat (limited to 'gr-audio/lib')
-rw-r--r-- | gr-audio/lib/Makefile.am | 18 | ||||
-rw-r--r-- | gr-audio/lib/gr_audio_registry.cc | 57 | ||||
-rw-r--r-- | gr-audio/lib/gr_audio_registry.h | 39 |
3 files changed, 114 insertions, 0 deletions
diff --git a/gr-audio/lib/Makefile.am b/gr-audio/lib/Makefile.am index d5b319c36..8e5915ba2 100644 --- a/gr-audio/lib/Makefile.am +++ b/gr-audio/lib/Makefile.am @@ -20,3 +20,21 @@ # include $(top_srcdir)/Makefile.common + +AM_CPPFLAGS = \ + $(STD_DEFINES_AND_INCLUDES) \ + $(WITH_INCLUDES) \ + -I$(abs_top_srcdir)/gr-audio/include \ + -Dgnuradio_audio_EXPORTS + +lib_LTLIBRARIES = libgnuradio-audio.la + +libgnuradio_audio_la_SOURCES = \ + gr_audio_registry.cc + +libgnuradio_audio_la_LIBADD = \ + $(GNURADIO_CORE_LA) + +libgnuradio_audio_la_LDFLAGS = $(LTVERSIONFLAGS) + +noinst_HEADERS = gr_audio_registry.h diff --git a/gr-audio/lib/gr_audio_registry.cc b/gr-audio/lib/gr_audio_registry.cc new file mode 100644 index 000000000..e40d1ff0f --- /dev/null +++ b/gr-audio/lib/gr_audio_registry.cc @@ -0,0 +1,57 @@ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "gr_audio_registry.h" +#include <stdexcept> +#include <vector> + +static std::vector<gr_audio_registry_entry> &get_registry(void){ + static std::vector<gr_audio_registry_entry> _registry; + return _registry; +} + +void gr_audio_register(const gr_audio_registry_entry &entry){ + get_registry().push_back(entry); +} + +gr_audio_source::sptr gr_make_audio_source( + int sampling_rate, + const std::string device_name, + bool ok_to_block +){ + if (get_registry().empty()){ + throw std::runtime_error("no available audio factories"); + } + //TODO we may prefer to use a specific entry in the registry + return get_registry().front().source(sampling_rate, device_name, ok_to_block); +} + +gr_audio_sink::sptr gr_make_audio_sink( + int sampling_rate, + const std::string device_name, + bool ok_to_block +){ + if (get_registry().empty()){ + throw std::runtime_error("no available audio factories"); + } + //TODO we may prefer to use a specific entry in the registry + return get_registry().front().sink(sampling_rate, device_name, ok_to_block); +} diff --git a/gr-audio/lib/gr_audio_registry.h b/gr-audio/lib/gr_audio_registry.h new file mode 100644 index 000000000..4b43a408b --- /dev/null +++ b/gr-audio/lib/gr_audio_registry.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_AUDIO_REGISTRY_H +#define INCLUDED_GR_AUDIO_REGISTRY_H + +#include <gr_audio_sink.h> +#include <gr_audio_source.h> +#include <string> + +struct gr_audio_registry_entry{ + typedef gr_audio_source::sptr(*source_factory_t)(int, const std::string &, bool); + typedef gr_audio_sink::sptr(*sink_factory_t)(int, const std::string &, bool); + std::string name; + source_factory_t source; + sink_factory_t sink; +}; + +void gr_audio_register(const gr_audio_registry_entry &entry); + +#endif /* INCLUDED_GR_AUDIO_REGISTRY_H */ |