summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilippo Giunchedi <filippo@esaurito.net>2009-11-14 13:44:09 (GMT)
committer Filippo Giunchedi <filippo@esaurito.net>2009-11-14 14:21:53 (GMT)
commit86f27e300f43a263f622ca5edcae2f89ecf7ee6e (patch)
treef4ba6c167c6e4dcbf6500207e74e76083ea4eb9a
parent9f761a0edd9d0d02f75fe5b0e5e4162ef208bc84 (diff)
make portaudio and jack separated via #ifdef
probably the best option would be to make two subclasses of SoundDevice and use those in jmixer... oh well
-rw-r--r--configure.ac26
-rw-r--r--src/dev_sound.cpp63
-rw-r--r--src/dev_sound.h19
3 files changed, 87 insertions, 21 deletions
diff --git a/configure.ac b/configure.ac
index a7b6697..8b9f1f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -289,9 +289,27 @@ AC_SUBST(GUI_CFLAGS)
dnl ==============================================================
dnl Choose external portaudio library
dnl =========================================
-PKG_CHECK_MODULES(PORTAUDIO, portaudio-2.0, [:],
- AC_MSG_ERROR([*** portaudio 19 not found!]))
+AC_ARG_ENABLE(portaudio,
+ AS_HELP_STRING([--enable-portaudio],
+ [compile with portaudio support (yes)]),
+ [enable_portaudio=$enableval],
+ [enable_portaudio=yes])
+
+if test x$enable_portaudio = xyes; then
+ PKG_CHECK_MODULES(PORTAUDIO, portaudio-2.0, [have_portaudio=yes],
+ [have_portaudio=no])
+ if test x$have_portaudio = xyes; then
+ AC_DEFINE(HAVE_PORTAUDIO, 1, [Have portaudio library])
+ fi
+fi
+if test x$have_portaudio = xno && test x$have_jack = xno; then
+ AC_MSG_ERROR([*** portaudio nor jack found!])
+fi
+
+if test x$have_portaudio = xyes && test x$have_jack = xyes; then
+ AC_MSG_ERROR([*** both portaudio and jack are enabled, disable one])
+fi
dnl ==============================================================
dnl shout lib
@@ -425,6 +443,10 @@ if test "${have_jack}" = "yes"; then
echo ":: Linking libJack for connecting to the Jack audio daemon"
fi
+if test "${have_portaudio}" = "yes"; then
+ echo ":: Linking portaudio for soundcard output"
+fi
+
if test "$have_lame" = "yes"; then
echo ":: Linking Lame libraries for MP3 encoding"
fi
diff --git a/src/dev_sound.cpp b/src/dev_sound.cpp
index 47119bb..6c2e210 100644
--- a/src/dev_sound.cpp
+++ b/src/dev_sound.cpp
@@ -29,13 +29,9 @@
#define PA_SAMPLE_TYPE paFloat32
#define PA_SAMPLES_PER_FRAME 2
-#define PA_NUM_SECONDS 5
#define FRAMES_PER_BUFFER (64)
#define PA_PIPE_SIZE MIX_CHUNK*sizeof(PA_SAMPLE_TYPE)*64
-#define INPUT_DEVICE Pa_GetDefaultInputDeviceID()
-#define OUTPUT_DEVICE Pa_GetDefaultOutputDeviceID()
-
#ifdef HAVE_JACK
int dev_jack_process(jack_nframes_t nframes, void *arg) {
@@ -73,6 +69,7 @@ void dev_jack_shutdown(void *arg) {
SoundDevice::SoundDevice() {
+#ifdef HAVE_PORTAUDIO
memset(&input_device,0,sizeof(input_device));
memset(&output_device,0,sizeof(output_device));
pa_dev.input = &input_device;
@@ -83,15 +80,19 @@ SoundDevice::SoundDevice() {
output_device.pipe->set_block(true,false);
input_device.pipe->set_output_type("copy_float_to_int16");
output_device.pipe->set_input_type("copy_int16_to_float");
+#endif
+#ifdef HAVE_JACK
jack = false;
jack_in = false;
jack_out = false;
+#endif
}
SoundDevice::~SoundDevice() {
close();
}
+#ifdef HAVE_PORTAUDIO
static int pa_process( const void *inputBuffer, void *outputBuffer,
long unsigned int framesPerBuffer, const PaStreamCallbackTimeInfo *outTime,
PaStreamCallbackFlags flags, void *userData )
@@ -141,14 +142,21 @@ long len = framesPerBuffer * (PA_SAMPLES_PER_FRAME*sizeof(PA_SAMPLE_TYPE));
}
return 0;
}
+#endif
bool SoundDevice::input(bool state) {
bool res = false;
- if(jack) return true;
- if(!res) res = pa_open(state,PaInput);
+#ifdef HAVE_JACK
+ if(jack) res = true;
+#endif
+#ifdef HAVE_PORTAUDIO
+ res = pa_open(state, PaInput);
+#endif
+
return res;
}
+#ifdef HAVE_PORTAUDIO
PaError SoundDevice::pa_real_open(int mode) {
PaStream *stream;
input_device.input_params.device = input_device.id;
@@ -255,11 +263,16 @@ bool SoundDevice::pa_open(bool state,int mode) {
}
return true;
}
+#endif // HAVE_PORTAUDIO
bool SoundDevice::output(bool state) {
- bool res = false;
- if(jack) return true;
- if(!res) res = pa_open(state,PaOutput);
+ bool res;
+#ifdef HAVE_JACK
+ if(jack) res = true;
+#endif
+#ifdef HAVE_PORTAUDIO
+ res = pa_open(state, PaOutput);
+#endif
return res;
}
@@ -310,6 +323,7 @@ bool SoundDevice::open(bool read, bool write) {
}
void SoundDevice::close() {
+#ifdef HAVE_PORTAUDIO
if((pa_mode&PaInput) == PaInput) {
if((pa_mode&PaOutput) == PaOutput) {
pa_mode = PaOutput;
@@ -338,21 +352,27 @@ void SoundDevice::close() {
else pa_mode = PaNull;
}
//delete output_device.pipe;
+#endif
}
int SoundDevice::read(void *buf, int len) {
// len is in samples: 4*2 32bit stereo
int res = -1;
+#ifdef HAVE_JACK
if(jack) {
res = jack_in_pipe->read(len*2,buf);
- } else if(input_device.stream) { // portaudio
+ }
+#endif
+#ifdef HAVE_PORTAUDIO
+ if(input_device.stream) {
// takes number of left and right frames (stereo / 2)
res = input_device.pipe->read(len*2,buf);
- }
+ }
+#endif
return res;
}
@@ -360,28 +380,41 @@ int SoundDevice::write(void *buf, int len) {
// len is in samples, for bytes must *2 (16bit)
int res = -1;
+#ifdef HAVE_JACK
if(jack) { // jack audio daemon
res = jack_out_pipe->write(len*2,buf);
- } else if(output_device.stream) { // portaudio
- res = output_device.pipe->write(len,buf);
+ }
+#endif
+#ifdef HAVE_PORTAUDIO
+ if(output_device.stream) { // portaudio
+ res = output_device.pipe->write(len,buf);
//func("dspout available pipe space: %d \n",output_device.pipe->space());
}
+#endif
return res;
}
void SoundDevice::flush_output() {
+#ifdef HAVE_JACK
if(jack)
jack_out_pipe->flush();
- else if(output_device.stream) { // portaudio
+#endif
+#ifdef HAVE_PORTAUDIO
+ if(output_device.stream) { // portaudio
output_device.pipe->flush();
}
+#endif
}
void SoundDevice::flush_input() {
+#ifdef HAVE_JACK
if(jack)
jack_in_pipe->flush();
- else if(input_device.stream) {
+#endif
+#ifdef HAVE_PORTAUDIO
+ if(input_device.stream) {
input_device.pipe->flush();
}
+#endif
}
diff --git a/src/dev_sound.h b/src/dev_sound.h
index 5efe638..88c2e7f 100644
--- a/src/dev_sound.h
+++ b/src/dev_sound.h
@@ -7,10 +7,13 @@
#include <jack/jack.h>
#endif
+#ifdef HAVE_PORTAUDIO
#include <portaudio.h>
+#endif
#include <pipe.h>
+#ifdef HAVE_PORTAUDIO
typedef struct {
PaDeviceIndex id;
PaStream *stream;
@@ -25,6 +28,7 @@ typedef struct {
PaDevInfo *output;
} PaDevices;
///< the PortAudio device descriptor , this struct just group some data used by PortAudio framework
+#endif
class SoundDevice {
public:
@@ -56,17 +60,24 @@ class SoundDevice {
void flush_input();
void flush_output();
+#ifdef HAVE_JACK
bool jack;
bool jack_in;
bool jack_out;
+#endif
+#ifdef HAVE_PORTAUDIO
/* TODO - should be private */
PaDevInfo input_device; ///< portaudio input device
PaDevInfo output_device; ///< portaudio output device
+#endif
+
+
private:
+#ifdef HAVE_PORTAUDIO
bool pa_open(bool state,int mode);
PaError pa_real_open(int mode);
-
+
PaError err;
PaDevices pa_dev;
@@ -74,10 +85,11 @@ class SoundDevice {
#define PaNull 0
#define PaInput 1
#define PaOutput 2
+#endif
+#ifdef HAVE_JACK
Pipe *jack_in_pipe;
Pipe *jack_out_pipe;
-#ifdef HAVE_JACK
jack_client_t *jack_client;
jack_port_t *jack_in_port;
jack_port_t *jack_out_port;
@@ -86,7 +98,6 @@ class SoundDevice {
size_t jack_sample_size;
int jack_samplerate;
#endif
-
};
-#endif
+#endif // __DEV_SOUND_H__