Author: sayer
Date: 2009-05-10 22:31:45 +0200 (Sun, 10 May 2009)
New Revision: 1377
Modified:
branches/wb/core/AmAudio.cpp
branches/wb/core/AmAudio.h
branches/wb/core/AmBufferedAudio.cpp
branches/wb/core/AmRtpAudio.cpp
Log:
split up downMix/upMix into rate and channels. This way AmAudio's can make a
hack for stereo: overwrite AmAudio::get with a version that return n channels
interleaved (need to know the codec's channels to set that up of course)
Modified: branches/wb/core/AmAudio.cpp
===================================================================
--- branches/wb/core/AmAudio.cpp 2009-05-09 23:51:12 UTC (rev 1376)
+++ branches/wb/core/AmAudio.cpp 2009-05-10 20:31:45 UTC (rev 1377)
@@ -63,7 +63,7 @@
unsigned int AmAudioFormat::calcBytesToRead(unsigned int needed_samples) const
{
if (codec && codec->samples2bytes)
- return codec->samples2bytes(h_codec, needed_samples) * channels; // FIXME:
channels, system_channels
+ return codec->samples2bytes(h_codec, needed_samples) * channels;
WARN("Cannot convert samples to bytes\n");
return needed_samples * channels;
@@ -228,8 +228,10 @@
}
/* into internal format */
- size = downMix(size);
+ size = downMixChannels(size);
+ size = downMixRate(size);
+
if(size>0)
memcpy(buffer,(unsigned char*)samples,size);
@@ -250,7 +252,7 @@
memcpy((unsigned char*)samples,buffer,size);
/* from internal format */
- size = upMix(size);
+ size = upMixRate(size);
int s = encode(size);
if (s<=0)
@@ -339,32 +341,38 @@
return s;
}
-unsigned int AmAudio::downMix(unsigned int size)
+unsigned int AmAudio::downMixRate(unsigned int size)
{
unsigned int s = size;
-
- if (fmt->channels == 2) {
- stereo2mono(samples.back_buffer(),(unsigned char*)samples,s);
- samples.swap();
- }
#ifdef USE_LIBSAMPLERATE
if (fmt->rate != SYSTEM_SAMPLERATE) {
- s = resample(src_state_in, (double)SYSTEM_SAMPLERATE / (double)fmt->rate,
size);
+ s = resample(src_state_in, (double)SYSTEM_SAMPLERATE / (double)fmt->rate,
s);
}
#endif
return s;
}
-unsigned int AmAudio::upMix(unsigned int size)
+unsigned int AmAudio::downMixChannels(unsigned int size) {
+ unsigned int s = size;
+
+ if (fmt->channels == 2) {
+ stereo2mono(samples.back_buffer(),(unsigned char*)samples,s);
+ samples.swap();
+ }
+
+ return s;
+}
+
+unsigned int AmAudio::upMixRate(unsigned int size)
{
unsigned int s = size;
// todo: system_channels, convert from/to stereo ?
#ifdef USE_LIBSAMPLERATE
if (fmt->rate != SYSTEM_SAMPLERATE) {
- s = resample(src_state_out, (double)fmt->rate / (double)SYSTEM_SAMPLERATE,
size);
+ s = resample(src_state_out, (double)fmt->rate / (double)SYSTEM_SAMPLERATE,
s);
}
#endif
Modified: branches/wb/core/AmAudio.h
===================================================================
--- branches/wb/core/AmAudio.h 2009-05-09 23:51:12 UTC (rev 1376)
+++ branches/wb/core/AmAudio.h 2009-05-10 20:31:45 UTC (rev 1377)
@@ -234,17 +234,23 @@
int encode(unsigned int size);
/**
- * Converts to internal format(-> mono, SYSTEM_SAMPLERATE)
+ * Converts to internal format(-> SYSTEM_SAMPLERATE)
* @return new size in bytes
*/
- unsigned int downMix(unsigned int size);
+ unsigned int downMixRate(unsigned int size);
/**
- * Converts from internal format (<- mono, SYSTEM_SAMPLERATE)
+ * Converts from internal format (<- SYSTEM_SAMPLERATE)
* @return new size in bytes
*/
- unsigned int upMix(unsigned int size);
+ unsigned int upMixRate(unsigned int size);
+ /**
+ * Converts to internal channels count (-> mono)
+ * @return new size in bytes
+ */
+ unsigned int downMixChannels(unsigned int size);
+
#ifdef USE_LIBSAMPLERATE
/** resampler helper function */
unsigned int resample(src_state* m_src_state, double factor, unsigned int
size);
Modified: branches/wb/core/AmBufferedAudio.cpp
===================================================================
--- branches/wb/core/AmBufferedAudio.cpp 2009-05-09 23:51:12 UTC (rev
1376)
+++ branches/wb/core/AmBufferedAudio.cpp 2009-05-10 20:31:45 UTC (rev
1377)
@@ -133,8 +133,11 @@
}
// DBG("decode returned %i\n",size);
- size = downMix(size);
+ size = downMixChannels(size);
+ size = downMixRate(size);
+
+
if(size>0) {
memcpy(&output_buffer[w],(unsigned char*)samples,size);
w+=size;
Modified: branches/wb/core/AmRtpAudio.cpp
===================================================================
--- branches/wb/core/AmRtpAudio.cpp 2009-05-09 23:51:12 UTC (rev 1376)
+++ branches/wb/core/AmRtpAudio.cpp 2009-05-10 20:31:45 UTC (rev 1377)
@@ -246,7 +246,9 @@
}
/* into internal format */
- size = downMix(size);
+ size = downMixChannels(size);
+
+ size = downMixRate(size);
// rtp_ts = SYSTEM_SAMPLERATE * rtp_ts / fmt->rate;
if (fmt->rate && fmt->rate != SYSTEM_SAMPLERATE) {
@@ -277,7 +279,8 @@
return size;
// /* convert here for sampling in internal format after playout buffer */
- // size = downMix(size);
+ // size = downMixChannels(size);
+ // size = downMixRate(size);
// if (size < 0)
// return size;
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev