summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-11-28 16:07:32 (GMT)
committer jaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-11-28 16:07:32 (GMT)
commitcd23076fffe4f75acd23f8fd8e9ea751f51e2b66 (patch)
treee2d4bf7c4a52672387557ab149b14a4399e31a67
parentad113beb95a13d1cddcf2dcd35d282ce3f2a9ad8 (diff)
soundfile now correctly play'd
git-svn-id: svn://dyne.org/montevideo/ivysync@79 949728d9-16ea-0310-a75c-cbdf8430a4b8
-rw-r--r--branches/lydia/cmdline.cpp16
-rw-r--r--branches/lydia/sndfile_decoder.h1
-rw-r--r--branches/lydia/sound_decoder.cpp32
-rw-r--r--branches/lydia/sound_decoder.h24
-rw-r--r--branches/lydia/sound_device.cpp2
-rw-r--r--branches/lydia/sound_device.h1
6 files changed, 69 insertions, 7 deletions
diff --git a/branches/lydia/cmdline.cpp b/branches/lydia/cmdline.cpp
index 9687d8c..4a3051c 100644
--- a/branches/lydia/cmdline.cpp
+++ b/branches/lydia/cmdline.cpp
@@ -32,8 +32,12 @@
#include <errno.h>
#include <signal.h>
+
+
#include <decoder.h>
+#include <sndfile_decoder.h>
+
#include <sound_device.h>
#include <xmlrpc.h>
#include <gui.h>
@@ -59,7 +63,10 @@ Gui *gui = NULL;
XmlRpcServer *xmlrpc = NULL;
// sound device
-SoundDevice *snd = NULL;
+SoundDevice *snddev = NULL;
+
+// sound file
+MuseDecSndFile *sndfile = NULL;
// Threaded daemon
IvySyncDaemon *ivydaemon = NULL;
@@ -352,9 +359,12 @@ int main(int argc, char **argv) {
////////////////////////////////
/// Sound device
- snd = new SoundDevice();
+ snddev = new SoundDevice();
// open only for playback
- snd->open(false, true);
+ snddev->open(false, true);
+ sndfile = new MuseDecSndFile();
+ sndfile->load("/mnt/hd1/1/Lydia/pleistersound_def.wav");
+ sndfile->play_once(snddev);
////////////////////////////////
/////////////////////////////////
diff --git a/branches/lydia/sndfile_decoder.h b/branches/lydia/sndfile_decoder.h
index 68b08ad..76fbb1e 100644
--- a/branches/lydia/sndfile_decoder.h
+++ b/branches/lydia/sndfile_decoder.h
@@ -26,6 +26,7 @@
#define __IN_SND_H__
#include <sound_decoder.h>
+#include <linklist.h>
/* libsndfile inclusion */
#include <sndfile.h>
diff --git a/branches/lydia/sound_decoder.cpp b/branches/lydia/sound_decoder.cpp
index ab743cb..783d1b5 100644
--- a/branches/lydia/sound_decoder.cpp
+++ b/branches/lydia/sound_decoder.cpp
@@ -1,6 +1,7 @@
// "$Id: decoder.cpp 328 2004-02-13 16:58:16Z jaromil $"
+#include <sound_device.h>
#include <sound_decoder.h>
#include <utils.h>
@@ -9,11 +10,40 @@ MuseDec::MuseDec()
bitrate = samplerate = channels = frames = 0;
seekable = false; err = false; eos = false;
loaded = false;
+
+ device = NULL;
}
MuseDec::~MuseDec() { }
+bool MuseDec::play_once(SoundDevice *dev) {
+ seek(0.0);
+ eos = false;
+ device = dev;
+ launch();
+ return true;
+}
+
void MuseDec::run() {
- W("TODO: multi-threaded play of channels");
+ D("Sound file decoder thread launched");
+ IN_DATATYPE *buf;
+
+ if(!device) {
+ E("no device configured for decoder");
+ return;
+ }
+
+ while(!eos) {
+
+ buf = get_audio();
+
+ if(!buf) break;
+
+ device->write(buf, IN_CHUNK);
+
+ // device->flush_output();
+
+ }
+
return;
}
diff --git a/branches/lydia/sound_decoder.h b/branches/lydia/sound_decoder.h
index d930fc1..f0edfd2 100644
--- a/branches/lydia/sound_decoder.h
+++ b/branches/lydia/sound_decoder.h
@@ -22,8 +22,8 @@
@desc header file to be included by decoder implementations
*/
-#ifndef __DECODER_H__
-#define __DECODER_H__
+#ifndef __SOUND_DECODER_H__
+#define __SOUND_DECODER_H__
#include <inttypes.h>
@@ -68,6 +68,8 @@
@brief decoder parent abstraction class
*/
+class SoundDevice;
+
class MuseDec: public Thread {
public:
@@ -131,6 +133,22 @@ class MuseDec: public Thread {
@return pointer to decoded pcm buffer */
virtual IN_DATATYPE *get_audio() = 0; /* decode audio */
+
+
+ // =====================================================================
+ // DECODER PARENT FUNCTIONS
+
+ void run(); ///< thread runner
+
+ /**
+ Playback once the loaded file on a device, spawning a thread
+
+ @brief playback once the audio file
+ @return true on success, false otherwise */
+ bool play_once(SoundDevice *dev);
+
+ SoundDevice *device;
+
/**
* the following variables describe the audio returned by
* MuseDec::get_audio and must be setted up by the decoder implementation.
@@ -147,7 +165,7 @@ class MuseDec: public Thread {
bool err; ///< true when an error occurred during audio decoding
///////////////////////////////////////////////////////////
- void run(); ///< @TODO: multithreaded play of channels
+
};
diff --git a/branches/lydia/sound_device.cpp b/branches/lydia/sound_device.cpp
index 76ee5a4..20b4089 100644
--- a/branches/lydia/sound_device.cpp
+++ b/branches/lydia/sound_device.cpp
@@ -236,6 +236,8 @@ bool SoundDevice::open(bool read, bool write) {
return true;
}
+
+
void SoundDevice::close() {
if((pa_mode&PaInput) == PaInput) {
if((pa_mode&PaOutput) == PaOutput) {
diff --git a/branches/lydia/sound_device.h b/branches/lydia/sound_device.h
index 71e232a..3694d64 100644
--- a/branches/lydia/sound_device.h
+++ b/branches/lydia/sound_device.h
@@ -58,6 +58,7 @@ class SoundDevice {
PaError err;
PaDevices pa_dev;
+
int pa_mode; ///< a switch to represent portaudio mode currently using (for noaudio,input,output or both)
#define PaNull 0
#define PaInput 1