9697f9a50c01 — Chris Cannam 3 years ago
Add getEffectiveRatio
4 files changed, 46 insertions(+), 4 deletions(-)

M bqresample/Resampler.h
M src/BQResampler.cpp
M src/BQResampler.h
M src/Resampler.cpp
M bqresample/Resampler.h +17 -3
@@ 60,9 60,6 @@ public:
          * Performance hint indicating whether the ratio is expected
          * to change regularly or not. If not, more work may happen on
          * ratio changes to reduce work when ratio is unchanged.
-         *!!! doc: more likely to avoid allocations?
-         *!!! doc: do we actually change output on ratio changes if
-         * we're expecting them? (e.g. smoothing)
          */
         Dynamism dynamism; 
 

          
@@ 161,8 158,25 @@ public:
                             double ratio,
                             bool final = false);
 
+    /**
+     * Return the channel count provided on construction.
+     */
     int getChannelCount() const;
 
+    /**
+     * Return the ratio that will be actually used when the given
+     * ratio is requested. For example, if the resampler internally
+     * uses a rational approximation of the given ratio, this will
+     * return the closest double to that approximation. Not all
+     * implementations support this; an implementation that does not
+     * will just return the given ratio.
+     */
+    double getEffectiveRatio(double ratio) const;
+    
+    /**
+     * Reset the internal processing state so that the next call
+     * behaves as if the resampler had just been constructed.
+     */
     void reset();
 
     class Impl;

          
M src/BQResampler.cpp +9 -0
@@ 230,6 230,15 @@ BQResampler::resampleInterleaved(float *
     return o / m_channels;
 }
 
+double
+BQResampler::getEffectiveRatio(double ratio) const {
+    if (m_initialised && ratio == m_s->parameters.ratio) {
+        return m_s->parameters.effective;
+    } else {
+        return pick_params(ratio).effective;
+    }
+}
+    
 int
 BQResampler::gcd(int a, int b) const
 {

          
M src/BQResampler.h +2 -0
@@ 72,6 72,8 @@ public:
                             const float *const in, int incount,
                             double ratio, bool final);
 
+    double getEffectiveRatio(double ratio) const;
+    
     void reset();
 
 private:

          
M src/Resampler.cpp +18 -1
@@ 109,6 109,7 @@ public:
                                     bool final) = 0;
 
     virtual int getChannelCount() const = 0;
+    virtual double getEffectiveRatio(double ratio) const = 0;
 
     virtual void reset() = 0;
 };

          
@@ 140,6 141,7 @@ public:
                             bool final = false);
 
     int getChannelCount() const { return m_channels; }
+    double getEffectiveRatio(double ratio) const { return ratio; }
 
     void reset();
 

          
@@ 571,6 573,7 @@ public:
                             bool final = false);
 
     int getChannelCount() const { return m_channels; }
+    double getEffectiveRatio(double ratio) const { return ratio; }
 
     void reset();
 

          
@@ 795,6 798,7 @@ public:
                             bool final);
 
     int getChannelCount() const { return m_channels; }
+    double getEffectiveRatio(double ratio) const { return ratio; }
 
     void reset();
 

          
@@ 980,7 984,13 @@ public:
                             double ratio,
                             bool final = false);
 
-    int getChannelCount() const { return m_channels; }
+    int getChannelCount() const {
+        return m_channels;
+    }
+
+    double getEffectiveRatio(double ratio) const {
+        return m_resampler->getEffectiveRatio(ratio);
+    }
 
     void reset();
 

          
@@ 1131,6 1141,7 @@ public:
                             bool final = false);
 
     int getChannelCount() const { return m_channels; }
+    double getEffectiveRatio(double ratio) const { return ratio; }
 
     void reset();
 

          
@@ 1555,6 1566,12 @@ Resampler::getChannelCount() const
     return d->getChannelCount();
 }
 
+double
+Resampler::getEffectiveRatio(double ratio) const
+{
+    return d->getEffectiveRatio(ratio);
+}
+
 void
 Resampler::reset()
 {