|
From: Lasse Kärkkäi. <tr...@us...> - 2009-10-10 08:44:16
|
Module: performous
Branch: master
Commit: dd85fff3cb17562468ec3711e3e54d5a9b078c4b
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Oct 10 11:42:00 2009 +0300
Made libda and libplugin++ shared libraries to make them easier to use.
Be sure to remove all installed libplugin++.a and libda.a files.
Fixed libda capture example and wrote stand-alone CMakeLists.txt for it.
Linkage visibility fixes (I believe this could actually work on Windows now).
---
libs/libda/examples/CMakeLists.txt | 7 ++++
libs/libda/examples/capture.cpp | 45 ++++++++++++++++-------------
libs/libda/include/libda/audio.hpp | 7 ++--
libs/libda/src/CMakeLists.txt | 2 +-
libs/plugin++/CMakeLists.txt | 5 ++-
libs/plugin++/include/plugin++/dll.hpp | 5 ++-
libs/plugin++/include/plugin++/loader.hpp | 2 +-
libs/plugin++/src/dll-posix.cpp | 2 +
libs/plugin++/src/dll-windows.cpp | 2 +
9 files changed, 48 insertions(+), 29 deletions(-)
diff --git a/libs/libda/examples/CMakeLists.txt b/libs/libda/examples/CMakeLists.txt
new file mode 100644
index 0000000..fe6d273
--- /dev/null
+++ b/libs/libda/examples/CMakeLists.txt
@@ -0,0 +1,7 @@
+project("Libda examples" CXX)
+cmake_minimum_required(VERSION 2.4)
+
+add_executable(da_capture capture.cpp)
+target_link_libraries(da_capture da)
+install(TARGETS da_capture DESTINATION bin)
+
diff --git a/libs/libda/examples/capture.cpp b/libs/libda/examples/capture.cpp
index 4643240..4848061 100644
--- a/libs/libda/examples/capture.cpp
+++ b/libs/libda/examples/capture.cpp
@@ -1,3 +1,4 @@
+#include <boost/format.hpp>
#include <libda/audio.hpp>
#include <fstream>
#include <iomanip>
@@ -19,48 +20,52 @@ class FileOut {
<< channels << " -r" << rate << " " << filename << std::endl;
}
/** Callback function **/
- void operator()(audio::pcm_data& data, audio::settings const& s) {
+ bool operator()(da::pcm_data& data) {
channels = data.channels;
- rate = s.rate;
+ rate = data.rate;
// std::cout << data.frames << " frames received" << std::endl;
for (std::size_t fr = 0; fr < data.frames; ++fr) {
for (std::size_t ch = 0; ch < data.channels; ++ch) {
- audio::sample_t s = data(fr, ch);
+ da::sample_t s = data(fr, ch);
file.write(reinterpret_cast<char*>(&s), sizeof(s));
}
}
frames += data.frames;
+ return true;
}
};
int main(int argc, char** argv) {
// Print the list of devices
{
- std::vector<std::string> dev = audio::record::devices();
- std::cout << "Available audio devices: ";
- std::copy(dev.begin(), dev.end(), std::ostream_iterator<std::string>(std::cout, " "));
- std::cout << std::endl;
+ std::vector<da::devinfo> l = da::record::devices();
+ std::cout << "Capture devices available:" << std::endl;
+ for (da::record::devlist_t::const_iterator it = l.begin(); it != l.end(); ++it) {
+ std::cout << boost::format(" %1% %|10t|%2%\n") % it->name() % it->desc();
+ }
}
// Create output file
FileOut fileout("testout.raw");
// Construct settings
- audio::settings rs(argc > 1 ? argv[1] : "");
- rs.callback = boost::ref(fileout);
- rs.channels = 2;
- rs.rate = 48000;
- rs.frames = 1024;
- rs.debug = &std::cerr;
- {
+ da::settings rs(argc > 1 ? argv[1] : "");
+ rs.set_callback(boost::ref(fileout))
+ .set_channels(2)
+ .set_rate(48000)
+ .set_frames(1024)
+ .set_debug(std::cerr);
+ da::initialize dainit; // Load da plugins
+ try {
// Start recording (may modify settings)
- audio::record r(rs);
- std::cout << "# Device: " << rs.device << ":" << rs.subdev << std::endl;
- std::cout << "# Sampling rate: " << rs.rate << std::endl;
- std::cout << "# Channels: " << rs.channels << std::endl;
- std::cout << "# Frames per block: " << rs.frames << std::endl;
+ da::record r(rs);
+ std::cout << "# Device: " << rs.device() << ":" << rs.subdev() << std::endl;
+ std::cout << "# Sampling rate: " << rs.rate() << std::endl;
+ std::cout << "# Channels: " << rs.channels() << std::endl;
+ std::cout << "# Frames per block: " << rs.frames() << std::endl;
std::cout << "PRESS ENTER TO STOP" << std::endl;
std::cin.get();
// Stop recording (r goes out of scope)
+ } catch (std::exception& e) {
+ std::cout << "Unable to record: " << e.what() << std::endl;
}
- std::cout << "EXITING" << std::endl;
}
diff --git a/libs/libda/include/libda/audio.hpp b/libs/libda/include/libda/audio.hpp
index 2fa7187..9c2a0cf 100644
--- a/libs/libda/include/libda/audio.hpp
+++ b/libs/libda/include/libda/audio.hpp
@@ -15,6 +15,7 @@ Link with libda when you use this.
#include "sample.hpp"
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
+#include <plugin++/dllhelper.hpp>
#include <cmath>
#include <cstddef>
#include <iosfwd>
@@ -31,7 +32,7 @@ namespace da {
* so that you can create multiple da::initialize objects.
* Do not, however, destroy the object while audio devices are still in use!
**/
- class initialize {
+ class DLL_PUBLIC initialize {
init_impl* m_impl;
public:
initialize();
@@ -143,7 +144,7 @@ namespace da {
bool special() const { return !m_name.empty() && m_name[0] == '~'; }
};
- class record {
+ class DLL_PUBLIC record {
public:
typedef std::vector<devinfo> devlist_t;
static devlist_t devices();
@@ -154,7 +155,7 @@ namespace da {
dev* m_handle;
};
- class playback {
+ class DLL_PUBLIC playback {
public:
typedef std::vector<devinfo> devlist_t;
static devlist_t devices();
diff --git a/libs/libda/src/CMakeLists.txt b/libs/libda/src/CMakeLists.txt
index fc6ea31..549dcb6 100644
--- a/libs/libda/src/CMakeLists.txt
+++ b/libs/libda/src/CMakeLists.txt
@@ -10,6 +10,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif(CMAKE_COMPILER_IS_GNUCXX)
include_directories(${Boost_INCLUDE_DIRS})
-add_library(da audio.cpp)
+add_library(da SHARED audio.cpp)
target_link_libraries(da plugin++ ${Boost_LIBRARIES})
install(TARGETS da DESTINATION lib${LIB_SUFFIX})
diff --git a/libs/plugin++/CMakeLists.txt b/libs/plugin++/CMakeLists.txt
index f2837f2..f460392 100644
--- a/libs/plugin++/CMakeLists.txt
+++ b/libs/plugin++/CMakeLists.txt
@@ -9,9 +9,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif(CMAKE_COMPILER_IS_GNUCXX)
if (WIN32)
- add_library(plugin++ STATIC src/dll-windows.cpp)
+ add_library(plugin++ SHARED src/dll-windows.cpp)
else (WIN32)
- add_library(plugin++ STATIC src/dll-posix.cpp)
+ add_library(plugin++ SHARED src/dll-posix.cpp)
+ target_link_libraries(plugin++ dl)
endif (WIN32)
install(TARGETS plugin++ DESTINATION lib${LIB_SUFFIX})
diff --git a/libs/plugin++/include/plugin++/dll.hpp b/libs/plugin++/include/plugin++/dll.hpp
index 19100f5..ed4a7b6 100644
--- a/libs/plugin++/include/plugin++/dll.hpp
+++ b/libs/plugin++/include/plugin++/dll.hpp
@@ -1,11 +1,12 @@
#ifndef DLL_HPP_INCLUDED
#define DLL_HPP_INCLUDED
+#include "dllhelper.hpp"
#include <string>
namespace plugin {
- /** @short RAII wrapper to load and unload dynamic library **/
- class dll {
+ /** @short RAII wrapper to load and unload dynamic library **/
+ class DLL_PUBLIC dll {
void* lib;
public:
dll(std::string const& filename);
diff --git a/libs/plugin++/include/plugin++/loader.hpp b/libs/plugin++/include/plugin++/loader.hpp
index 5ad0e69..373688a 100644
--- a/libs/plugin++/include/plugin++/loader.hpp
+++ b/libs/plugin++/include/plugin++/loader.hpp
@@ -13,7 +13,7 @@
namespace plugin {
namespace fs = boost::filesystem;
- /** @short A helper for loading all matching libraries in a folder. **/
+ /** @short A helper for loading all matching libraries in a folder. **/
class loader {
boost::ptr_vector<dll> dlls;
void parse(std::set<fs::path>& paths, char const* var, fs::path const& folder = fs::path()) {
diff --git a/libs/plugin++/src/dll-posix.cpp b/libs/plugin++/src/dll-posix.cpp
index 1f71043..41d88e4 100644
--- a/libs/plugin++/src/dll-posix.cpp
+++ b/libs/plugin++/src/dll-posix.cpp
@@ -1,4 +1,6 @@
+#define BUILDING_DLL
#include <plugin++/dll.hpp>
+#undef BUILDING_DLL
#include <dlfcn.h>
#include <stdexcept>
diff --git a/libs/plugin++/src/dll-windows.cpp b/libs/plugin++/src/dll-windows.cpp
index ecbe37b..a514ff7 100644
--- a/libs/plugin++/src/dll-windows.cpp
+++ b/libs/plugin++/src/dll-windows.cpp
@@ -1,4 +1,6 @@
+#define BUILDING_DLL
#include <plugin++/dll.hpp>
+#undef BUILDING_DLL
#include <windows.h>
#include <stdexcept>
|