Skip to content

Commit

Permalink
Add ratio limiter to AudioStream
Browse files Browse the repository at this point in the history
If an out-of-bound stretching ratio is about to be used,
(e.g. because of a tempo changing glitch), limit the
stretching ratio to sane values. This will workaround
#7.
  • Loading branch information
Windfisch committed Sep 13, 2013
1 parent fa9a7ee commit f50bbbe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions muse2/muse/audiostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace std;

#ifdef RUBBERBAND_SUPPORT
using namespace RubberBand;
#define RATIO_LIMIT 5
#endif

namespace MusECore {
Expand Down Expand Up @@ -138,6 +139,16 @@ void AudioStream::seek(unsigned int frame, XTick xtick)
#ifdef RUBBERBAND_SUPPORT
void AudioStream::set_stretch_ratio(double ratio)
{
if (ratio > RATIO_LIMIT)
{
printf("AudioStream::set_stretch_ratio: limiting upwards!\n");
ratio=RATIO_LIMIT;
}
if (ratio < 1.0/RATIO_LIMIT)
{
printf("AudioStream::set_stretch_ratio: limiting downwards!\n");
ratio=1.0/RATIO_LIMIT;
}
effective_stretch_ratio = ratio * output_sampling_rate / input_sampling_rate;
stretcher->setTimeRatio(effective_stretch_ratio);
}
Expand Down

0 comments on commit f50bbbe

Please sign in to comment.