Pick more rational rational values
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
#include "Allocators.h"
|
#include "Allocators.h"
|
||||||
#include "VectorOps.h"
|
#include "VectorOps.h"
|
||||||
|
|
||||||
|
#include "mathmisc.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@@ -1220,18 +1222,22 @@ D_Speex::setRatio(double ratio)
|
|||||||
// Speex wants a ratio of two unsigned integers, not a single
|
// Speex wants a ratio of two unsigned integers, not a single
|
||||||
// float. Let's do that.
|
// float. Let's do that.
|
||||||
|
|
||||||
unsigned int big = 272408136U;
|
int max_denom = 96000;
|
||||||
unsigned int denom = 1, num = 1;
|
if (ratio > 1.0) {
|
||||||
|
max_denom = int(ceil(96000 / ratio));
|
||||||
if (ratio < 1.f) {
|
|
||||||
denom = big;
|
|
||||||
double dnum = double(big) * double(ratio);
|
|
||||||
num = (unsigned int)dnum;
|
|
||||||
} else if (ratio > 1.f) {
|
|
||||||
num = big;
|
|
||||||
double ddenom = double(big) / double(ratio);
|
|
||||||
denom = (unsigned int)ddenom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int inum, idenom;
|
||||||
|
pickNearestRational(ratio, max_denom, inum, idenom);
|
||||||
|
|
||||||
|
if (inum < 0 || idenom < 0) {
|
||||||
|
cerr << "Resampler::setRatio: Internal error: "
|
||||||
|
<< "numerator or denominator < 0 ("
|
||||||
|
<< inum << "/" << idenom << ")" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int num = inum, denom = idenom;
|
||||||
|
|
||||||
if (m_debugLevel > 1) {
|
if (m_debugLevel > 1) {
|
||||||
cerr << "D_Speex: Desired ratio " << ratio << ", requesting ratio "
|
cerr << "D_Speex: Desired ratio " << ratio << ", requesting ratio "
|
||||||
@@ -1246,8 +1252,12 @@ D_Speex::setRatio(double ratio)
|
|||||||
(m_resampler, denom, num, fromRate, toRate);
|
(m_resampler, denom, num, fromRate, toRate);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
cerr << "Resampler::Resampler: failed to set rate on Speex resampler"
|
cerr << "Resampler::Resampler: failed to set rate on Speex resampler"
|
||||||
<< endl;
|
<< " (with ratio = " << ratio << " [ratio-1 = " << ratio - 1.0
|
||||||
|
<< "], denom = " << denom
|
||||||
|
<< ", num = " << num << ", fromRate = " << fromRate
|
||||||
|
<< ", toRate = " << toRate << ", err = " << err
|
||||||
|
<< ")" << endl;
|
||||||
#ifndef NO_EXCEPTIONS
|
#ifndef NO_EXCEPTIONS
|
||||||
throw Resampler::ImplementationError;
|
throw Resampler::ImplementationError;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user