mirror of
https://github.com/azahar-emu/soundtouch
synced 2025-11-08 16:10:10 +01:00
Fixed buffer overflow bug in BPMDetect.cpp & changed version to 1.4.1
This commit is contained in:
parent
15a7e7be2a
commit
28aaff6c99
@ -18,7 +18,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body class="normal">
|
<body class="normal">
|
||||||
<hr>
|
<hr>
|
||||||
<h1>SoundTouch audio processing library v1.4.0
|
<h1>SoundTouch audio processing library v1.4.1
|
||||||
</h1>
|
</h1>
|
||||||
<p class="normal">SoundTouch library Copyright (c) Olli
|
<p class="normal">SoundTouch library Copyright (c) Olli
|
||||||
Parviainen 2002-2009 </p>
|
Parviainen 2002-2009 </p>
|
||||||
@ -538,6 +538,13 @@ estimates the BPM rate:</p>
|
|||||||
<h2>5. Change History</h2>
|
<h2>5. Change History</h2>
|
||||||
<h3>5.1. SoundTouch library Change History </h3>
|
<h3>5.1. SoundTouch library Change History </h3>
|
||||||
|
|
||||||
|
<p><strong>1.4.1:</strong></p>
|
||||||
|
<ul>
|
||||||
|
<li>Fixed a buffer overflow bug in BPM detect algorithm routines if processing
|
||||||
|
more than 2048 samples at one call </li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
<p><strong>1.4.0:</strong></p>
|
<p><strong>1.4.0:</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Improved sound quality by automatic calculation of time stretch algorithm
|
<li>Improved sound quality by automatic calculation of time stretch algorithm
|
||||||
|
|||||||
@ -79,10 +79,10 @@ namespace soundtouch
|
|||||||
{
|
{
|
||||||
|
|
||||||
/// Soundtouch library version string
|
/// Soundtouch library version string
|
||||||
#define SOUNDTOUCH_VERSION "1.4.0"
|
#define SOUNDTOUCH_VERSION "1.4.1"
|
||||||
|
|
||||||
/// SoundTouch library version id
|
/// SoundTouch library version id
|
||||||
#define SOUNDTOUCH_VERSION_ID (10400)
|
#define SOUNDTOUCH_VERSION_ID (10401)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Available setting IDs for the 'setSetting' & 'get_setting' functions:
|
// Available setting IDs for the 'setSetting' & 'get_setting' functions:
|
||||||
|
|||||||
@ -229,6 +229,7 @@ static void detectBPM(WavInFile *inFile, RunParameters *params)
|
|||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
nChannels = inFile->getNumChannels();
|
nChannels = inFile->getNumChannels();
|
||||||
|
assert(BUFF_SIZE % nChannels == 0);
|
||||||
|
|
||||||
// Process the 'inFile' in small blocks, repeat until whole file has
|
// Process the 'inFile' in small blocks, repeat until whole file has
|
||||||
// been processed
|
// been processed
|
||||||
|
|||||||
@ -115,7 +115,8 @@ BPMDetect::~BPMDetect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// low-pass filter & decimate to about 500 Hz. return number of outputted samples.
|
/// convert to mono, low-pass filter & decimate to about 500 Hz.
|
||||||
|
/// return number of outputted samples.
|
||||||
///
|
///
|
||||||
/// Decimation is used to remove the unnecessary frequencies and thus to reduce
|
/// Decimation is used to remove the unnecessary frequencies and thus to reduce
|
||||||
/// the amount of data needed to be processed as calculating autocorrelation
|
/// the amount of data needed to be processed as calculating autocorrelation
|
||||||
@ -134,13 +135,20 @@ int BPMDetect::decimate(SAMPLETYPE *dest, const SAMPLETYPE *src, int numsamples)
|
|||||||
outcount = 0;
|
outcount = 0;
|
||||||
for (count = 0; count < numsamples; count ++)
|
for (count = 0; count < numsamples; count ++)
|
||||||
{
|
{
|
||||||
decimateSum += src[count];
|
int j;
|
||||||
|
|
||||||
|
// convert to mono and accumulate
|
||||||
|
for (j = 0; j < channels; j ++)
|
||||||
|
{
|
||||||
|
decimateSum += src[j];
|
||||||
|
}
|
||||||
|
src += j;
|
||||||
|
|
||||||
decimateCount ++;
|
decimateCount ++;
|
||||||
if (decimateCount >= decimateBy)
|
if (decimateCount >= decimateBy)
|
||||||
{
|
{
|
||||||
// Store every Nth sample only
|
// Store every Nth sample only
|
||||||
out = (LONG_SAMPLETYPE)(decimateSum / decimateBy);
|
out = (LONG_SAMPLETYPE)(decimateSum / (decimateBy * channels));
|
||||||
decimateSum = 0;
|
decimateSum = 0;
|
||||||
decimateCount = 0;
|
decimateCount = 0;
|
||||||
#ifdef INTEGER_SAMPLES
|
#ifdef INTEGER_SAMPLES
|
||||||
@ -231,27 +239,27 @@ void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BPMDetect::inputSamples(SAMPLETYPE *samples, int numSamples)
|
void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
|
||||||
{
|
{
|
||||||
SAMPLETYPE decimated[DECIMATED_BLOCK_SAMPLES];
|
SAMPLETYPE decimated[DECIMATED_BLOCK_SAMPLES];
|
||||||
|
|
||||||
// convert from stereo to mono if necessary
|
// iterate so that max INPUT_BLOCK_SAMPLES processed per iteration
|
||||||
if (channels == 2)
|
while (numSamples > 0)
|
||||||
{
|
{
|
||||||
int i;
|
int block;
|
||||||
|
int decSamples;
|
||||||
|
|
||||||
for (i = 0; i < numSamples; i ++)
|
block = (numSamples > INPUT_BLOCK_SAMPLES) ? INPUT_BLOCK_SAMPLES : numSamples;
|
||||||
{
|
|
||||||
samples[i] = (samples[i * 2] + samples[i * 2 + 1]) / 2;
|
// decimate. note that converts to mono at the same time
|
||||||
}
|
decSamples = decimate(decimated, samples, block);
|
||||||
|
samples += block * channels;
|
||||||
|
numSamples -= block;
|
||||||
|
|
||||||
|
// envelope new samples and add them to buffer
|
||||||
|
calcEnvelope(decimated, decSamples);
|
||||||
|
buffer->putSamples(decimated, decSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decimate
|
|
||||||
numSamples = decimate(decimated, samples, numSamples);
|
|
||||||
|
|
||||||
// envelope new samples and add them to buffer
|
|
||||||
calcEnvelope(decimated, numSamples);
|
|
||||||
buffer->putSamples(decimated, numSamples);
|
|
||||||
|
|
||||||
// when the buffer has enought samples for processing...
|
// when the buffer has enought samples for processing...
|
||||||
if ((int)buffer->numSamples() > windowLen)
|
if ((int)buffer->numSamples() > windowLen)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user