[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src engine/AudioChannel.h engine/Audio...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src engine/AudioChannel.h engine/Audio... |
Date: |
Mon, 18 Feb 2008 08:17:32 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 08/02/18 08:17:32
Modified files:
src/engine : AudioChannel.h AudioDevice.cpp AudioDevice.h
CMakeLists.txt
src/traverso : CMakeLists.txt
Added files:
src/engine : PulseAudioDriver.cpp PulseAudioDriver.h
Log message:
* added skeleton PulseAudioDriver. far from working! Anyone who feels
the need to make it work, please, go ahead :)
N.B. latest pulseaudio release works with the AlsaDriver, so there
isn't really any urgent need for native pa support.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/AudioChannel.h?cvsroot=traverso&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/AudioDevice.cpp?cvsroot=traverso&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/AudioDevice.h?cvsroot=traverso&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/CMakeLists.txt?cvsroot=traverso&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/PulseAudioDriver.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/PulseAudioDriver.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/CMakeLists.txt?cvsroot=traverso&r1=1.11&r2=1.12
Patches:
Index: engine/AudioChannel.h
===================================================================
RCS file: /sources/traverso/traverso/src/engine/AudioChannel.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- engine/AudioChannel.h 19 Mar 2007 11:18:57 -0000 1.6
+++ engine/AudioChannel.h 18 Feb 2008 08:17:30 -0000 1.7
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: AudioChannel.h,v 1.6 2007/03/19 11:18:57 r_sijrier Exp $
+$Id: AudioChannel.h,v 1.7 2008/02/18 08:17:30 r_sijrier Exp $
*/
#ifndef AUDIOCHANNEL_H
@@ -95,6 +95,7 @@
friend class JackDriver;
friend class AlsaDriver;
friend class PADriver;
+ friend class PulseAudioDriver;
friend class Driver;
int has_data()
Index: engine/AudioDevice.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/engine/AudioDevice.cpp,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- engine/AudioDevice.cpp 21 Jan 2008 17:20:41 -0000 1.52
+++ engine/AudioDevice.cpp 18 Feb 2008 08:17:30 -0000 1.53
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: AudioDevice.cpp,v 1.52 2008/01/21 17:20:41 r_sijrier Exp $
+$Id: AudioDevice.cpp,v 1.53 2008/02/18 08:17:30 r_sijrier Exp $
*/
#include "AudioDevice.h"
@@ -36,6 +36,11 @@
#include "PADriver.h"
#endif
+#if defined (PULSEAUDIO_SUPPORT)
+#include "PulseAudioDriver.h"
+#endif
+
+
#include "Driver.h"
#include "Client.h"
#include "AudioChannel.h"
@@ -161,6 +166,10 @@
availableDrivers << "PortAudio";
#endif
+#if defined (PULSEAUDIO_SUPPORT)
+ availableDrivers << "PulseAudio";
+#endif
+
availableDrivers << "Null Driver";
// tsar is a singleton, so initialization is done on first tsar() call
@@ -389,7 +398,7 @@
}
#endif
- if (driverType == "PortAudio") {
+ if (driverType == "PortAudio"|| (driverType == "PulseAudio") ) {
if (driver->start() == -1) {
// PortAudio driver failed to start, fallback to Null
Driver:
set_parameters(rate, bufferSize, "Null Driver");
@@ -447,6 +456,20 @@
}
#endif
+#if defined (PULSEAUDIO_SUPPORT)
+ if (driverType == "PulseAudio") {
+ driver = new PulseAudioDriver(this, m_rate, m_bufferSize);
+ if (driver->setup(capture, playback, cardDevice) < 0) {
+ message(tr("Audiodevice: Failed to create the
PulseAudio Driver"), WARNING);
+ delete driver;
+ driver = 0;
+ return -1;
+ }
+ m_driverType = driverType;
+ return 1;
+ }
+#endif
+
if (driverType == "Null Driver") {
printf("Creating Null Driver...\n");
driver = new Driver(this, m_rate, m_bufferSize);
Index: engine/AudioDevice.h
===================================================================
RCS file: /sources/traverso/traverso/src/engine/AudioDevice.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- engine/AudioDevice.h 15 Jan 2008 19:51:49 -0000 1.28
+++ engine/AudioDevice.h 18 Feb 2008 08:17:31 -0000 1.29
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2005-2006 Remon Sijrier
+Copyright (C) 2005-2008 Remon Sijrier
This file is part of Traverso
@@ -17,7 +17,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: AudioDevice.h,v 1.28 2008/01/15 19:51:49 r_sijrier Exp $
*/
#ifndef AUDIODEVICE_H
@@ -141,6 +140,7 @@
friend class AlsaDriver;
friend class PADriver;
friend class Driver;
+ friend class PulseAudioDriver;
friend class AudioDeviceThread;
Index: engine/CMakeLists.txt
===================================================================
RCS file: /sources/traverso/traverso/src/engine/CMakeLists.txt,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- engine/CMakeLists.txt 7 Nov 2007 20:28:21 -0000 1.4
+++ engine/CMakeLists.txt 18 Feb 2008 08:17:31 -0000 1.5
@@ -43,6 +43,13 @@
)
ENDIF(HAVE_PORTAUDIO)
+IF(HAVE_PULSEAUDIO)
+ SET(TRAVERSO_ENGINE_SOURCES
+ PulseAudioDriver.cpp
+ ${TRAVERSO_ENGINE_SOURCES}
+ )
+ENDIF(HAVE_PULSEAUDIO)
+
SET(TRAVERSO_ENGINE_LIBRARY "traversoaudiobackend")
QT4_WRAP_CPP(TRAVERSO_ENGINE_MOC_SOURCES ${TRAVERSO_ENGINE_MOC_CLASSES})
Index: traverso/CMakeLists.txt
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/CMakeLists.txt,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- traverso/CMakeLists.txt 15 Feb 2008 20:14:19 -0000 1.11
+++ traverso/CMakeLists.txt 18 Feb 2008 08:17:32 -0000 1.12
@@ -253,7 +253,7 @@
IF(HAVE_PULSEAUDIO)
TARGET_LINK_LIBRARIES(traverso
- pulse-simple
+ pulse
)
ENDIF(HAVE_PULSEAUDIO)
Index: engine/PulseAudioDriver.cpp
===================================================================
RCS file: engine/PulseAudioDriver.cpp
diff -N engine/PulseAudioDriver.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ engine/PulseAudioDriver.cpp 18 Feb 2008 08:17:31 -0000 1.1
@@ -0,0 +1,195 @@
+/*
+ Copyright (C) 2008 Remon Sijrier
+
+ This file is part of Traverso
+
+ Traverso 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "PulseAudioDriver.h"
+
+#include <pulse/error.h>
+
+#include "AudioDevice.h"
+#include "AudioChannel.h"
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+PulseAudioDriver::PulseAudioDriver( AudioDevice * dev , int rate, nframes_t
bufferSize)
+ : Driver(dev, rate, bufferSize)
+{
+ read = MakeDelegate(this, &PulseAudioDriver::_read);
+ write = MakeDelegate(this, &PulseAudioDriver::_write);
+ run_cycle = RunCycleCallback(this, &PulseAudioDriver::_run_cycle);
+
+ mainloop = NULL;
+ context = NULL;
+ stream = NULL;
+ mainloop_api = NULL;
+ volume = PA_VOLUME_NORM;
+ channel_map_set = 0;
+}
+
+PulseAudioDriver::~PulseAudioDriver( )
+{
+ PENTER;
+ if (stream)
+ pa_stream_unref(stream);
+
+ if (context)
+ pa_context_unref(context);
+
+ if (mainloop) {
+ pa_signal_done();
+ pa_mainloop_free(mainloop);
+ }
+}
+
+int PulseAudioDriver::_read( nframes_t nframes )
+{
+ return 1;
+}
+
+int PulseAudioDriver::_write( nframes_t nframes )
+{
+ return 1;
+}
+
+int PulseAudioDriver::setup(bool capture, bool playback, const QString& )
+{
+ PENTER;
+
+ sample_spec.rate = frame_rate;
+ sample_spec.channels = 2;
+ sample_spec.format = PA_SAMPLE_FLOAT32NE;
+
+ assert(pa_sample_spec_valid(&sample_spec));
+
+ if (channel_map_set && channel_map.channels != sample_spec.channels) {
+ fprintf(stderr, "Channel map doesn't match file.\n");
+ return -1;
+ }
+
+ /* Set up a new main loop */
+ if (!(mainloop = pa_mainloop_new())) {
+ fprintf(stderr, "pa_mainloop_new() failed.\n");
+ return -1;
+ }
+
+ mainloop_api = pa_mainloop_get_api(mainloop);
+
+ int r = pa_signal_init(mainloop_api);
+ assert(r == 0);
+
+ /* Create a new connection context */
+ if (!(context = pa_context_new(mainloop_api, "Traverso"))) {
+ fprintf(stderr, "pa_context_new() failed.\n");
+ return -1;
+ }
+
+ pa_context_set_state_callback(context, context_state_callback, this);
+
+ /* Connect the context */
+ pa_context_connect(context, "", (pa_context_flags_t)0, NULL);
+
+ int ret;
+ /* Run the main loop */
+// if (pa_mainloop_run(mainloop, &ret) < 0) {
+// fprintf(stderr, "pa_mainloop_run() failed.\n");
+// return -1;
+// }
+
+
+ AudioChannel* audiochannel;
+ int port_flags;
+ char buf[32];
+
+ // TODO use the found maxchannel count for the playback stream, instead
of assuming 2 !!
+ for (int chn = 0; chn < 2; chn++) {
+
+ snprintf (buf, sizeof(buf) - 1, "playback_%d", chn+1);
+
+ audiochannel = device->register_playback_channel(buf, "32 bit
float audio", port_flags, frames_per_cycle, chn);
+ audiochannel->set_latency( frames_per_cycle +
capture_frame_latency );
+ playbackChannels.append(audiochannel);
+ }
+
+ // TODO use the found maxchannel count for the capture stream, instead
of assuming 0 !!
+ for (int chn = 0; chn < 2; chn++) {
+
+ snprintf (buf, sizeof(buf) - 1, "capture_%d", chn+1);
+
+ audiochannel = device->register_capture_channel(buf, "32 bit
float audio", port_flags, frames_per_cycle, chn);
+ audiochannel->set_latency( frames_per_cycle +
capture_frame_latency );
+ captureChannels.append(audiochannel);
+ }
+
+ return 1;
+}
+
+int PulseAudioDriver::attach( )
+{
+ PENTER;
+ return 1;
+}
+
+int PulseAudioDriver::start( )
+{
+ PENTER;
+ return 1;
+}
+
+int PulseAudioDriver::stop( )
+{
+ PENTER;
+ return 1;
+}
+
+int PulseAudioDriver::process_callback (nframes_t nframes)
+{
+ device->run_cycle( nframes, 0.0);
+ return 0;
+}
+
+QString PulseAudioDriver::get_device_name()
+{
+ return "Pulse";
+}
+
+QString PulseAudioDriver::get_device_longname()
+{
+ return "Pulse";
+}
+
+int PulseAudioDriver::_run_cycle()
+{
+ return device->run_cycle(frames_per_cycle, 0);
+}
+
+void PulseAudioDriver::context_state_callback(pa_context * c, void * userdata)
+{
+}
+
+void PulseAudioDriver::stream_state_callback(pa_stream * s, void * userdata)
+{
+}
+
+void PulseAudioDriver::stream_write_callback(pa_stream * s, size_t length,
void * userdata)
+{
+}
+
Index: engine/PulseAudioDriver.h
===================================================================
RCS file: engine/PulseAudioDriver.h
diff -N engine/PulseAudioDriver.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ engine/PulseAudioDriver.h 18 Feb 2008 08:17:31 -0000 1.1
@@ -0,0 +1,72 @@
+/*
+ Copyright (C) 2008 Remon Sijrier
+
+ This file is part of Traverso
+
+ Traverso 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 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef PULSE_AUDIO_DRIVER_H
+#define PULSE_AUDIO_DRIVER_H
+
+#include "Driver.h"
+#include "defines.h"
+#include <pulse/pulseaudio.h>
+
+class PulseAudioDriver : public Driver
+{
+public:
+ PulseAudioDriver(AudioDevice* dev, int rate, nframes_t bufferSize);
+ ~PulseAudioDriver();
+
+ int process_callback (nframes_t nframes);
+ int _read(nframes_t nframes);
+ int _write(nframes_t nframes);
+ int _run_cycle();
+ int setup(bool capture=true, bool playback=true, const QString&
cardDevice="hw:0");
+ int attach();
+ int start();
+ int stop();
+
+ QString get_device_name();
+ QString get_device_longname();
+
+ float get_cpu_load();
+
+ void update_config();
+
+private:
+ /** PulseAudio playback stream object */
+ pa_mainloop* mainloop;
+ pa_context *context;
+ pa_stream *stream;
+ pa_mainloop_api *mainloop_api;
+ pa_volume_t volume;
+ pa_sample_spec sample_spec;
+ pa_channel_map channel_map;
+ int channel_map_set;
+
+ static void context_state_callback(pa_context *c, void *userdata);
+ static void stream_state_callback(pa_stream *s, void *userdata);
+ static void stream_write_callback(pa_stream *s, size_t length, void
*userdata);
+};
+
+
+#endif
+
+//eof
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src engine/AudioChannel.h engine/Audio...,
Remon Sijrier <=