From 74f59b78e447cecd1fb926354ecb7244dbfcc18f Mon Sep 17 00:00:00 2001
From: Stefan Sayer <stefan.sayer@googlemail.com>
Date: Wed, 10 Dec 2014 13:33:05 +0100
Subject: [PATCH 1/4] core:advanced_audio:mixin: allow generic AmAudio for
 mixin

---
 core/AmAudioMixIn.cpp | 24 ++++++++++++++++--------
 core/AmAudioMixIn.h   |  6 +++---
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/core/AmAudioMixIn.cpp b/core/AmAudioMixIn.cpp
index 4bfa782..7f35077 100644
--- a/core/AmAudioMixIn.cpp
+++ b/core/AmAudioMixIn.cpp
@@ -30,7 +30,7 @@
 #define IS_ONLY_ONCE       (flags & AUDIO_MIXIN_ONCE)
 #define IS_IMMEDIATE_START (flags & AUDIO_MIXIN_IMMEDIATE_START)
 
-AmAudioMixIn::AmAudioMixIn(AmAudio* A, AmAudioFile* B, 
+AmAudioMixIn::AmAudioMixIn(AmAudio* A, AmAudio* B, 
 			   unsigned int s, double l,
 			   unsigned int flags) 
   :   A(A),B(B), s(s), l(l), 
@@ -71,10 +71,14 @@ int AmAudioMixIn::get(unsigned long long system_ts, unsigned char* buffer,
       if (res <= 0) { // B empty
 	res = A->get(system_ts, buffer, output_sample_rate, nb_samples);
 	mixing = false;
-	if (IS_ONLY_ONCE)
+	if (IS_ONLY_ONCE) {
 	  B = NULL;
-	else
-	  B->rewind();
+	} else {
+	  AmAudioFile* B_file = dynamic_cast<AmAudioFile*>(B);
+	  if (NULL != B_file) {
+	    B_file->rewind();
+	  }
+	}
       }
       B_mut.unlock();
       return  res;
@@ -110,10 +114,14 @@ int AmAudioMixIn::get(unsigned long long system_ts, unsigned char* buffer,
       if (len<0) { // B finished
 	mixing = false;
 	
-	if (IS_ONLY_ONCE)
+	if (IS_ONLY_ONCE) {
 	  B = NULL;
-	else
-	  B->rewind();
+	} else {
+	  AmAudioFile* B_file = dynamic_cast<AmAudioFile*>(B);
+	  if (NULL != B_file) {
+	    B_file->rewind();
+	  }
+	}
       } else {
 	for (int i=0; i<(PCM16_B2S(len)); i++)  {
 	  pdest[i]+=(short)(((double)mix_buf[i])*l);
@@ -135,7 +143,7 @@ int AmAudioMixIn::put(unsigned long long system_ts, unsigned char* buffer,
   return -1;
 }
 
-void AmAudioMixIn::mixin(AmAudioFile* f) {
+void AmAudioMixIn::mixin(AmAudio* f) {
   B_mut.lock();
   B = f;
   mixing = next_start_ts_i = false; /* so that mix in will re-start */
diff --git a/core/AmAudioMixIn.h b/core/AmAudioMixIn.h
index 59b57d2..e8bfdb8 100644
--- a/core/AmAudioMixIn.h
+++ b/core/AmAudioMixIn.h
@@ -52,7 +52,7 @@
 
 class AmAudioMixIn : public AmAudio {
   AmAudio* A;
-  AmAudioFile* B;
+  AmAudio* B;
   unsigned int s;
   double l;
   int flags;
@@ -68,12 +68,12 @@ class AmAudioMixIn : public AmAudio {
 
 
  public:
-  AmAudioMixIn(AmAudio* A, AmAudioFile* B, 
+  AmAudioMixIn(AmAudio* A, AmAudio* B, 
 	       unsigned int s, double l, 
 	       unsigned int flags = 0);
   ~AmAudioMixIn();
 
-  void mixin(AmAudioFile* f);
+  void mixin(AmAudio* f);
 
  protected:
   // not used
-- 
1.9.3 (Apple Git-50)

