From 80d60a1736ff82e65fd7634cd415779c47bc13ed Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 24 Sep 2014 08:46:35 +0200 Subject: Virtualise backend and prepare for pulseaudio. --- configure.ac | 10 +++++ src/Makefile.am | 12 +++-- src/audiobackend-alsa.cc | 111 ++++++++++++++++++++++++++++++++++++++++++++++ src/audiobackend-alsa.h | 48 ++++++++++++++++++++ src/audiobackend-pulse.cc | 73 ++++++++++++++++++++++++++++++ src/audiobackend-pulse.h | 48 ++++++++++++++++++++ src/audiobackend.cc | 29 ++++++++++++ src/audiobackend.h | 44 ++++++++++++++++++ src/audioinput.cc | 72 ------------------------------ src/audioinput.h | 44 ------------------ src/audioinputhandler.cc | 9 ++-- src/audioinputhandler.h | 4 +- src/config.ini | 5 ++- src/mainwindow.cc | 4 +- src/mainwindow.h | 2 +- src/simplertp.cc | 35 +++++++++++++-- src/soundplayer.cc | 20 +-------- 17 files changed, 416 insertions(+), 154 deletions(-) create mode 100644 src/audiobackend-alsa.cc create mode 100644 src/audiobackend-alsa.h create mode 100644 src/audiobackend-pulse.cc create mode 100644 src/audiobackend-pulse.h create mode 100644 src/audiobackend.cc create mode 100644 src/audiobackend.h delete mode 100644 src/audioinput.cc delete mode 100644 src/audioinput.h diff --git a/configure.ac b/configure.ac index 2374032..48ef55d 100644 --- a/configure.ac +++ b/configure.ac @@ -55,6 +55,16 @@ dnl Check for opus dnl ====================== PKG_CHECK_MODULES(OPUS, opus >= 1.0.2) +dnl ====================== +dnl Check for libpulse +dnl ====================== +AC_ARG_WITH(pulse, [ --with-pulse Build with pulse support]) +if test x$with_pulse == xyes; then + PKG_CHECK_MODULES(PULSE, pulse >= 1.0.0) + AC_MSG_WARN([*** Building with libpulse support!]) + CXXFLAGS="$CXXFLAGS -DWITH_PULSE" +fi + dnl ====================== dnl Check for Jpeg library dnl ====================== diff --git a/src/Makefile.am b/src/Makefile.am index 5dcf5cf..0ad31cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,13 +21,15 @@ simplertp_SOURCES = \ opusdecoder.cc \ samplecache.cc \ frame.cc \ - audioinput.cc \ audioinputhandler.cc \ audiooutputhandler.cc \ soundplayer.cc \ outputstreamer.cc \ inputstreamer.cc \ - videowidget.cc + videowidget.cc \ + audiobackend.cc \ + audiobackend-alsa.cc \ + audiobackend-pulse.cc simplertp_genkey_LDADD = simplertp_genkey_CXXFLAGS = @@ -42,13 +44,15 @@ EXTRA_DIST = \ opusdecoder.h \ samplecache.h \ frame.h \ - audioinput.h \ audioinputhandler.h \ audiooutputhandler.h \ soundplayer.h \ outputstreamer.h \ inputstreamer.h \ - videowidget.h + videowidget.h \ + audiobackend.h \ + audiobackend-alsa.h \ + audiobackend-pulse.h simplertp_MOC = $(shell ../tools/MocList cc ) diff --git a/src/audiobackend-alsa.cc b/src/audiobackend-alsa.cc new file mode 100644 index 0000000..b4401ca --- /dev/null +++ b/src/audiobackend-alsa.cc @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend-alsa.cc + * + * Wed Sep 24 07:47:43 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "audiobackend-alsa.h" + +#include + +#include "mediaconfig.h" + +AudioBackendAlsa::AudioBackendAlsa(const char *device) +{ + // + // LibAO: + // + ao_initialize(); + + ao_sample_format sf; + memset(&sf, 0, sizeof(sf)); + sf.bits = 16; + sf.rate = SAMPLERATE; + sf.channels = 1; + sf.byte_format = AO_FMT_NATIVE; + + dev = ao_open_live(ao_default_driver_id(), &sf, 0); + + // + // LibAudioIn: + // + int err; + ai = ai_init(&err, device, "", SAMPLERATE, 1); + if(ai == NULL || err) { + printf("ai_init: %d (device: %s)\n", err, device); + exit(1); + return; + } + + int srate = ai_get_samplerate(&err, ai); + if(err) printf("ai_get_samplerate: %d\n", err); + if(srate != SAMPLERATE) { + printf("Samplerate: %d\n", srate); + } +} + +AudioBackendAlsa::~AudioBackendAlsa() +{ + // + // LibAO: + // + ao_close(dev); + ao_shutdown(); + + // + // LibAudioIn: + // + if(ai == NULL) { + printf("ai_err: no handle\n"); + return; + } + + int err; + ai_close(&err, ai); + if(err) printf("ai_err: %d\n", err); +} + +int AudioBackendAlsa::read(char *pcm, size_t maxsize) +{ + // + // LibAudioIn: + // + if(ai == NULL) { + printf("ai_err: no handle\n"); + return 0; + } + + int err; + int ret = ai_read(&err, ai, pcm, maxsize); + if(err) printf("ai_read: %d\n", err); + return ret; +} + +int AudioBackendAlsa::write(const char *pcm, size_t size) +{ + // + // LibAO: + // + ao_play(dev, (char *)pcm, size); + return 0; +} diff --git a/src/audiobackend-alsa.h b/src/audiobackend-alsa.h new file mode 100644 index 0000000..4a79a5d --- /dev/null +++ b/src/audiobackend-alsa.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend-alsa.h + * + * Wed Sep 24 07:47:43 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __SIMPLERTP_AUDIOBACKEND_ALSA_H__ +#define __SIMPLERTP_AUDIOBACKEND_ALSA_H__ + +#include "audiobackend.h" + +#include +#include + +class AudioBackendAlsa : public AudioBackend { +public: + AudioBackendAlsa(const char *device); + ~AudioBackendAlsa(); + + int read(char *pcm, size_t maxsize); + int write(const char *pcm, size_t size); + +private: + struct ai_t *ai; + ao_device *dev; +}; + +#endif/*__SIMPLERTP_AUDIOBACKEND_ALSA_H__*/ diff --git a/src/audiobackend-pulse.cc b/src/audiobackend-pulse.cc new file mode 100644 index 0000000..57d1a5c --- /dev/null +++ b/src/audiobackend-pulse.cc @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend-pulse.cc + * + * Wed Sep 24 07:47:47 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "audiobackend-pulse.h" + +#ifdef WITH_PULSE + +/* +Input example: +http://freedesktop.org/software/pulseaudio/doxygen/pacat-simple_8c-example.html + +Output example: +http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html +*/ + +#include "mediaconfig.h" + +AudioBackendPulse::AudioBackendPulse(const char *device) +{ + // Initialise pulse here + + //s = pa_simple_new(...); +} + +AudioBackendPulse::~AudioBackendPulse() +{ + // Shut down pulse here + + //pa_simple_free(s); +} + +int AudioBackendPulse::read(char *pcm, size_t maxsize) +{ + // read maximum 'maxsize' bytes into pcm and return number of bytes read. + + //pa_simple_read(...) + + return 0; +} + +int AudioBackendPulse::write(const char *pcm, size_t size) +{ + // write pcm to pulse + + //pa_simple_write(...) + + return 0; +} + +#endif/*WITH_PULSE*/ diff --git a/src/audiobackend-pulse.h b/src/audiobackend-pulse.h new file mode 100644 index 0000000..7dc2be8 --- /dev/null +++ b/src/audiobackend-pulse.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend-pulse.h + * + * Wed Sep 24 07:47:47 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __SIMPLERTP_AUDIOBACKEND-PULSE_H__ +#define __SIMPLERTP_AUDIOBACKEND-PULSE_H__ + +#ifdef WITH_PULSE + +#include + +class AudioBackendPulse : public AudioBackend { +public: + AudioBackendPulse(const char *device); + ~AudioBackendPulse(); + + int read(char *pcm, size_t maxsize); + int write(const char *pcm, size_t size); + +private: + pa_simple *s; +}; + +#endif/*WITH_PULSE*/ + +#endif/*__SIMPLERTP_AUDIOBACKEND-PULSE_H__*/ diff --git a/src/audiobackend.cc b/src/audiobackend.cc new file mode 100644 index 0000000..fb0057f --- /dev/null +++ b/src/audiobackend.cc @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend.cc + * + * Wed Sep 24 08:01:03 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "audiobackend.h" + +AudioBackend *g_audiobackend = NULL; diff --git a/src/audiobackend.h b/src/audiobackend.h new file mode 100644 index 0000000..4c3232d --- /dev/null +++ b/src/audiobackend.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiobackend.h + * + * Wed Sep 24 07:46:35 CEST 2014 + * Copyright 2014 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of SimpleRTP. + * + * SimpleRTP 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. + * + * SimpleRTP 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 SimpleRTP; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __SIMPLERTP_AUDIOBACKEND_H__ +#define __SIMPLERTP_AUDIOBACKEND_H__ + +#include + +class AudioBackend { +public: + AudioBackend() {} + virtual ~AudioBackend() {} + + virtual int read(char *pcm, size_t maxsize) = 0; + virtual int write(const char *pcm, size_t size) = 0; +}; + +// Declared in audiobackend.cc +extern AudioBackend *g_audiobackend; + +#endif/*__SIMPLERTP_AUDIOBACKEND_H__*/ diff --git a/src/audioinput.cc b/src/audioinput.cc deleted file mode 100644 index e0b4970..0000000 --- a/src/audioinput.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * audioinput.cc - * - * Fri Sep 19 19:44:11 CEST 2014 - * Copyright 2014 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of SimpleRTP. - * - * SimpleRTP 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. - * - * SimpleRTP 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 SimpleRTP; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "audioinput.h" - -#include - -#include "mediaconfig.h" - -AudioInput::AudioInput(const char *device) -{ - int err; - ai = ai_init(&err, device, "", SAMPLERATE, 1); - if(ai == NULL || err) { - printf("ai_init: %d\n", err); - return; - } - - int srate = ai_get_samplerate(&err, ai); - if(err) printf("ai_get_samplerate: %d\n", err); - if(srate != SAMPLERATE) { - printf("Samplerate: %d\n", srate); - } -} - -AudioInput::~AudioInput() -{ - if(ai == NULL) { - printf("ai_err: no handle\n"); - return; - } - - int err; - ai_close(&err, ai); - if(err) printf("ai_err: %d\n", err); -} - -int AudioInput::getSamples(void *pcm, size_t size) -{ - if(ai == NULL) { - printf("ai_err: no handle\n"); - return 0; - } - - int err; - int ret = ai_read(&err, ai, pcm, size); - if(err) printf("ai_read: %d\n", err); - return ret; -} diff --git a/src/audioinput.h b/src/audioinput.h deleted file mode 100644 index 50e5f34..0000000 --- a/src/audioinput.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * audioinput.h - * - * Fri Sep 19 19:44:11 CEST 2014 - * Copyright 2014 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of SimpleRTP. - * - * SimpleRTP 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. - * - * SimpleRTP 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 SimpleRTP; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#ifndef __SIMPLERTP_AUDIOINPUT_H__ -#define __SIMPLERTP_AUDIOINPUT_H__ - -#include -#include - -class AudioInput { -public: - AudioInput(const char *device); - ~AudioInput(); - - int getSamples(void *pcm, size_t size); - -private: - struct ai_t *ai; -}; - -#endif/*__SIMPLERTP_AUDIOINPUT_H__*/ diff --git a/src/audioinputhandler.cc b/src/audioinputhandler.cc index 95517f6..2961289 100644 --- a/src/audioinputhandler.cc +++ b/src/audioinputhandler.cc @@ -28,13 +28,14 @@ #include -AudioInputHandler::AudioInputHandler(QString device) - : ai(device.toStdString().c_str()) +#include "audiobackend.h" + +AudioInputHandler::AudioInputHandler() { qRegisterMetaType("framelist_t"); // Only start if we actually have an audio interface - if(device != "") start(); + if(g_audiobackend != NULL) start(); } AudioInputHandler::~AudioInputHandler() @@ -49,7 +50,7 @@ void AudioInputHandler::run() running = true; while(running) { - int sz = ai.getSamples(pcm, sizeof(pcm)); + int sz = g_audiobackend->read(pcm, sizeof(pcm)); //printf("sz: %d\n", sz); if(sz > 0) { framelist_t fl = oe.encode(pcm, sz); diff --git a/src/audioinputhandler.h b/src/audioinputhandler.h index dbf43e7..86ed99b 100644 --- a/src/audioinputhandler.h +++ b/src/audioinputhandler.h @@ -30,13 +30,12 @@ #include #include -#include "audioinput.h" #include "opusencoder.h" class AudioInputHandler : public QThread { Q_OBJECT public: - AudioInputHandler(QString device); + AudioInputHandler(); ~AudioInputHandler(); void run(); @@ -45,7 +44,6 @@ signals: void newAudio(framelist_t list); private: - AudioInput ai; OpusEncoder oe; volatile bool running; diff --git a/src/config.ini b/src/config.ini index 67893e6..d669668 100644 --- a/src/config.ini +++ b/src/config.ini @@ -3,8 +3,9 @@ # [hardware] -v4ldev="/dev/video0" -adev="hw:1,0" +audiobackend="alsa" +audiodevice="hw:2,0" +v4ldevice="/dev/video0" [crypto] key="123456789012345678901234567890123456789012345678901234567890" diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 81ea65c..30b6151 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -30,10 +30,10 @@ #include -MainWindow::MainWindow(QString v4ldev, QString adev, +MainWindow::MainWindow(QString v4ldev, OutputStreamer &os, QList &isl) - : v4l(v4ldev), aih(adev), ostreamer(os), islist(isl) + : v4l(v4ldev), ostreamer(os), islist(isl) { /* // Self view: connect(&v4l, SIGNAL(newImage(Frame)), diff --git a/src/mainwindow.h b/src/mainwindow.h index d8329bb..4235b0a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,7 +43,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QString v4ldev, QString adev, + MainWindow(QString v4ldev, OutputStreamer &ostreamer, QList &islist); diff --git a/src/simplertp.cc b/src/simplertp.cc index 7d1dec1..3db28ce 100644 --- a/src/simplertp.cc +++ b/src/simplertp.cc @@ -31,13 +31,21 @@ #include "mainwindow.h" +#include "audiobackend.h" +#include "audiobackend-alsa.h" +#ifdef WITH_PULSE +#include "audiobackend-pulse.h" +#endif/*WITH_PULSE*/ + int main(int argc, char *argv[]) { +/* int pulse = system("pidof pulseaudio &> /dev/null"); if(WEXITSTATUS(pulse) == 0) { printf("Pulse audio is running - simplertp wont work...\n"); return 1; } +*/ QApplication app(argc, argv); @@ -48,11 +56,25 @@ int main(int argc, char *argv[]) QSettings settings(argv[1], QSettings::IniFormat); - settings.beginGroup("hardware"); - QString v4ldev = settings.value("v4ldev", "/dev/video0").toString(); - QString adev = settings.value("adev", "hw:0,0").toString(); + settings.beginGroup("hardware"); + QString audiobackend = settings.value("audiobackend", "alsa").toString(); + QString audiodevice = settings.value("audiodevice", "hw:0,0").toString(); + QString v4ldevice = settings.value("v4ldevice", "/dev/video0").toString(); settings.endGroup(); + if(audiobackend == "alsa") { + g_audiobackend = new AudioBackendAlsa(audiodevice.toStdString().c_str()); + } else +#ifdef WITH_PULSE + if(audiobackend == "pulse") { + g_audiobackend = new AudioBackendPulse(audiodevice.toStdString().c_str()); + } else +#endif/*WITH_PULSE*/ + { + printf("Unknown audiobackend: %s\n", audiobackend.toStdString().c_str()); + } + + settings.beginGroup("crypto"); QString key = settings.value("key").toString(); unsigned int ssrc = settings.value("ssrc").toUInt(); @@ -84,7 +106,7 @@ int main(int argc, char *argv[]) } settings.endGroup(); - MainWindow wnd(v4ldev, adev, os, islist); + MainWindow wnd(v4ldevice, os, islist); wnd.show(); int ret = app.exec(); @@ -95,5 +117,10 @@ int main(int argc, char *argv[]) i++; } + if(g_audiobackend) { + delete g_audiobackend; + g_audiobackend = NULL; + } + return ret; } diff --git a/src/soundplayer.cc b/src/soundplayer.cc index 42196d4..aa05358 100644 --- a/src/soundplayer.cc +++ b/src/soundplayer.cc @@ -27,9 +27,7 @@ */ #include "soundplayer.h" -#include - -#include "mediaconfig.h" +#include "audiobackend.h" #define BUFSZ 512 @@ -49,17 +47,6 @@ SoundPlayer::~SoundPlayer() void SoundPlayer::run() { - ao_initialize(); - - ao_sample_format sf; - memset(&sf, 0, sizeof(sf)); - sf.bits = 16; - sf.rate = SAMPLERATE; - sf.channels = 1; - sf.byte_format = AO_FMT_NATIVE; - - ao_device *dev = ao_open_live(ao_default_driver_id(), &sf, 0); - running = true; short s[BUFSZ]; @@ -71,11 +58,8 @@ void SoundPlayer::run() pread++; } - ao_play(dev, (char *)s, sizeof(s)); + g_audiobackend->write((const char *)s, sizeof(s)); } - - ao_close(dev); - ao_shutdown(); } void SoundPlayer::playSamples(int peer, const char *pcm, size_t size) -- cgit v1.2.3