From bea950eae9aeeae35f30e13fcdc625832c595f74 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Tue, 10 Jul 2007 20:10:47 +0000 Subject: [PATCH] adds the option to finish file B while mixing in git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@400 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/announcement/Announcement.cpp | 2 +- apps/examples/mixin_announce/mix_announce.py | 2 +- apps/ivr/IvrAudioMixIn.cpp | 5 +++-- core/AmAudioMixIn.cpp | 18 +++++++++++++----- core/AmAudioMixIn.h | 5 ++++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/announcement/Announcement.cpp b/apps/announcement/Announcement.cpp index e7cd7c0b..5386ccbf 100644 --- a/apps/announcement/Announcement.cpp +++ b/apps/announcement/Announcement.cpp @@ -128,7 +128,7 @@ void AnnouncementDialog::startSession(){ throw string("AnnouncementDialog::onSessionStart: Cannot open file\n"); } - AmAudioMixIn* s = new AmAudioMixIn(&wav_file, f, 4, 0.0); + AmAudioMixIn* s = new AmAudioMixIn(&wav_file, f, 4, 0.1, true); setOutput(s); } diff --git a/apps/examples/mixin_announce/mix_announce.py b/apps/examples/mixin_announce/mix_announce.py index 1d4bec13..dc30c76f 100644 --- a/apps/examples/mixin_announce/mix_announce.py +++ b/apps/examples/mixin_announce/mix_announce.py @@ -17,7 +17,7 @@ class IvrDialog(IvrDialogBase): self.beep.open(config['beep'], ivr.AUDIO_READ) self.mixin = IvrAudioMixIn() - self.mixin.init(self.announcement, self.beep, 3, 0.6) + self.mixin.init(self.announcement, self.beep, 3, 0.6, True) self.enqueue(self.mixin, None) def onEmptyQueue(self): diff --git a/apps/ivr/IvrAudioMixIn.cpp b/apps/ivr/IvrAudioMixIn.cpp index 79f988ea..17a812ca 100644 --- a/apps/ivr/IvrAudioMixIn.cpp +++ b/apps/ivr/IvrAudioMixIn.cpp @@ -35,10 +35,11 @@ static PyObject* IvrAudioMixIn_init(IvrAudioMixIn* self, PyObject* args) AmAudioFile* b = NULL; int s; double l; + int finish = 0; PyObject *o_a, *o_b; - if(!PyArg_ParseTuple(args,"OOid", &o_a, &o_b, &s, &l)) + if(!PyArg_ParseTuple(args,"OOid|i", &o_a, &o_b, &s, &l, &finish)) return NULL; if (o_a == Py_None) { @@ -68,7 +69,7 @@ static PyObject* IvrAudioMixIn_init(IvrAudioMixIn* self, PyObject* args) delete self->mix; } - self->mix = new AmAudioMixIn(a, b, s, l); + self->mix = new AmAudioMixIn(a, b, s, l, finish); Py_INCREF(Py_None); return Py_None; diff --git a/core/AmAudioMixIn.cpp b/core/AmAudioMixIn.cpp index 14a5d74a..83a126b3 100644 --- a/core/AmAudioMixIn.cpp +++ b/core/AmAudioMixIn.cpp @@ -29,8 +29,11 @@ #include "SampleArray.h" AmAudioMixIn::AmAudioMixIn(AmAudio* A, AmAudioFile* B, - unsigned int s, double l) - : A(A),B(B), s(s), l(l), mixing(false), next_start_ts_i(false) + unsigned int s, double l, + bool finish_b_while_mixing) + : A(A),B(B), s(s), l(l), + mixing(false), next_start_ts_i(false), + finish_b_while_mixing(finish_b_while_mixing) { } AmAudioMixIn::~AmAudioMixIn() { } @@ -68,7 +71,7 @@ int AmAudioMixIn::get(unsigned int user_ts, unsigned char* buffer, // get audio from A int len = A->get(user_ts, (unsigned char*)mix_buf, nb_samples); - if (len<0) { // A finished + if ((len<0) && !finish_b_while_mixing) { // A finished return len; } for (int i=0;i0) + len_from_a=(unsigned int)res; + + if (nb_samples<<1 != len_from_a) + memset((void*)&pdest[len_from_a>>1], 0, + nb_samples<<1 - len_from_a); // add audio from B len = B->get(user_ts, (unsigned char*)mix_buf, nb_samples); diff --git a/core/AmAudioMixIn.h b/core/AmAudioMixIn.h index 5805fb1c..7f33dc20 100644 --- a/core/AmAudioMixIn.h +++ b/core/AmAudioMixIn.h @@ -50,6 +50,7 @@ class AmAudioMixIn : public AmAudio { AmAudioFile* B; unsigned int s; double l; + bool finish_b_while_mixing; bool mixing; @@ -58,9 +59,11 @@ class AmAudioMixIn : public AmAudio { short mix_buf[MAX_BUF_SAMPLES]; // 240 + public: AmAudioMixIn(AmAudio* A, AmAudioFile* B, - unsigned int s, double l); + unsigned int s, double l, + bool finish_b_while_mixing = false); ~AmAudioMixIn(); protected: // not used