[haiku-commits] haiku: hrev48460 - in src: add-ons/media/media-add-ons/mixer tests/add-ons/media/media-add-ons/mixer

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 8 Dec 2014 19:39:31 +0100 (CET)

hrev48460 adds 2 changesets to branch 'master'
old head: 258fbe371b6ca5b43c73a698470fe96fceda2672
new head: d23c4131888e026b1366cb3e4f3331b4850fd3e3
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=d23c413+%5E258fbe3

----------------------------------------------------------------------------

dab42bf: MixerToy: do an initialisation run on the mixer
  
  The Interpolating mixer has internal state which must be setup by a
  previous frame (we assume 0 for the first frame). Since we work on
  exactly a period of the wave here, sending the same data twice works as
  it should.

d23c413: Interpolating resampler: un-break it.
  
  The interpolation was performed only on the samples in a buffer,
  without "linking" with the previous one. This can't work.
  * Remember the last sample from a buffer to be able to use it when
  interpolating the first samples of the next one
  * Adjust the kernel to properly loop over all samples in the buffer
  
  Fixes #9438.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 16 insertions(+), 7 deletions(-)
src/add-ons/media/media-add-ons/mixer/Interpolate.cpp | 15 +++++++++------
src/add-ons/media/media-add-ons/mixer/Interpolate.h   |  2 +-
src/tests/add-ons/media/media-add-ons/mixer/main.cpp  |  6 ++++++

############################################################################

Commit:      dab42bf05b6f701f35564bd8f1cde771e97f78f1
URL:         http://cgit.haiku-os.org/haiku/commit/?id=dab42bf
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Dec  8 17:51:47 2014 UTC

MixerToy: do an initialisation run on the mixer

The Interpolating mixer has internal state which must be setup by a
previous frame (we assume 0 for the first frame). Since we work on
exactly a period of the wave here, sending the same data twice works as
it should.

----------------------------------------------------------------------------

diff --git a/src/tests/add-ons/media/media-add-ons/mixer/main.cpp 
b/src/tests/add-ons/media/media-add-ons/mixer/main.cpp
index 3caf843..b30edb4 100644
--- a/src/tests/add-ons/media/media-add-ons/mixer/main.cpp
+++ b/src/tests/add-ons/media/media-add-ons/mixer/main.cpp
@@ -266,6 +266,12 @@ MainWindow::MessageReceived(BMessage* message)
                                Interpolate 
sampler(media_raw_audio_format::B_AUDIO_FLOAT,
                                        media_raw_audio_format::B_AUDIO_FLOAT);
 
+                               // First call initializes the "old sample" in 
the interpolator.
+                               // Since we do the interpolation on exactly one 
period of the
+                               // sound wave, this works.
+                               sampler.Resample(fWaveView->waves[1].Raw(), 
sizeof(float), irate,
+                                       fWaveView->waves[2].Raw(), 
sizeof(float), orate, 1);
+
                                sampler.Resample(fWaveView->waves[1].Raw(), 
sizeof(float), irate,
                                        fWaveView->waves[2].Raw(), 
sizeof(float), orate, 1);
                        } else {

############################################################################

Revision:    hrev48460
Commit:      d23c4131888e026b1366cb3e4f3331b4850fd3e3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d23c413
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Dec  8 18:07:45 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/9438

Interpolating resampler: un-break it.

The interpolation was performed only on the samples in a buffer,
without "linking" with the previous one. This can't work.
* Remember the last sample from a buffer to be able to use it when
interpolating the first samples of the next one
* Adjust the kernel to properly loop over all samples in the buffer

Fixes #9438.

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/media-add-ons/mixer/Interpolate.cpp 
b/src/add-ons/media/media-add-ons/mixer/Interpolate.cpp
index de4ab75..17bbbb2 100644
--- a/src/add-ons/media/media-add-ons/mixer/Interpolate.cpp
+++ b/src/add-ons/media/media-add-ons/mixer/Interpolate.cpp
@@ -43,13 +43,14 @@ kernel(Resampler* object, const void *_src, int32 
srcSampleOffset,
                return;
        }
 
-       register float delta = float(srcSampleCount - 1) / 
float(destSampleCount - 1);
+       register float delta = float(srcSampleCount) / float(destSampleCount);
        register float current = 0.0f;
+       float oldSample = ((Interpolate*)object)->fOldSample;
 
-       #define SRC(n) *(const inType*)(src + n * srcSampleOffset)
+       #define SRC *(const inType*)(src)
 
-       while (--count) {
-               float tmp = (gain * (SRC(0) + (SRC(1) - SRC(0)) * current) + 
offset);
+       while (count--) {
+               float tmp = (gain * (oldSample + (SRC - oldSample) * current) + 
offset);
                if (tmp < min) tmp = min;
                if (tmp > max) tmp = max;
                *(outType *)dest = (outType)tmp;
@@ -59,17 +60,19 @@ kernel(Resampler* object, const void *_src, int32 
srcSampleOffset,
                if (current >= 1.0f) {
                        double ipart;
                        current = modf(current, &ipart);
+                       oldSample = SRC;
                        src += srcSampleOffset * (int)ipart;
                }
        }
 
-       *(outType*)dest = (outType)(SRC(0) * gain + offset);
+       ((Interpolate*)object)->fOldSample = oldSample;
 }
 
 
 Interpolate::Interpolate(uint32 src_format, uint32 dst_format)
        :
-       Resampler()
+       Resampler(),
+       fOldSample(0)
 {
        if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) {
                switch (src_format) {
diff --git a/src/add-ons/media/media-add-ons/mixer/Interpolate.h 
b/src/add-ons/media/media-add-ons/mixer/Interpolate.h
index 2d08632..fb4dddb 100644
--- a/src/add-ons/media/media-add-ons/mixer/Interpolate.h
+++ b/src/add-ons/media/media-add-ons/mixer/Interpolate.h
@@ -13,8 +13,8 @@ class Interpolate: public Resampler {
 public:
                                                        Interpolate(uint32 
sourceFormat,
                                                                uint32 
destFormat);
-private:
 
+                       float                   fOldSample;
 };
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev48460 - in src: add-ons/media/media-add-ons/mixer tests/add-ons/media/media-add-ons/mixer - pulkomandy