19 AudioResampler::AudioResampler(
int numChannels)
22 resample_source = NULL;
25 new_num_of_samples = 0;
28 resampled_buffer = NULL;
35 resample_source =
new juce::ResamplingAudioSource(buffer_source,
false, numChannels);
39 resampled_buffer->clear();
42 resample_callback_buffer.buffer = resampled_buffer;
43 resample_callback_buffer.numSamples = 1;
44 resample_callback_buffer.startSample = 0;
48 AudioResampler::~AudioResampler()
54 delete resample_source;
56 delete resampled_buffer;
64 if (new_sample_rate <= 0)
65 new_sample_rate = 44100;
68 source_ratio = sample_rate / new_sample_rate;
71 SetBuffer(new_buffer, source_ratio);
79 buffer_source->setBuffer(buffer);
83 dest_ratio = 1.0 / ratio;
84 num_of_samples = buffer->getNumSamples();
85 new_num_of_samples = round(num_of_samples * dest_ratio);
88 resample_source->setResamplingRatio(source_ratio);
94 resample_source->prepareToPlay(num_of_samples + 10, 0);
99 resampled_buffer->setSize(buffer->getNumChannels(), new_num_of_samples,
true,
true,
true);
100 resample_callback_buffer.numSamples = new_num_of_samples;
101 resample_callback_buffer.startSample = 0;
102 resample_callback_buffer.clearActiveBufferRegion();
109 resample_source->getNextAudioBlock(resample_callback_buffer);
112 return resampled_buffer;