Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Last active January 19, 2026 17:55
Show Gist options
  • Select an option

  • Save Xenakios/c9aebbb170c7a651d8ce16d553028639 to your computer and use it in GitHub Desktop.

Select an option

Save Xenakios/c9aebbb170c7a651d8ce16d553028639 to your computer and use it in GitHub Desktop.
inline void test_clipsource()
{
juce::AudioFormatManager mana;
mana.registerBasicFormats();
auto reader =
mana.createReaderFor(juce::File(R"(C:\MusicAudio\sourcesamples\ukulele\uku01.wav)"));
double outsr = 96000.0;
auto readersrc = std::make_unique<juce::AudioFormatReaderSource>(reader, true);
auto src = std::make_unique<ClipAudioSourceModel>(std::move(readersrc), juce::String("foo"),
0.0, 0.0, 1.0, mana);
juce::WavAudioFormat wavf;
juce::File outputfile{R"(C:\MusicAudio\sourcesamples\ukulele\tstest.wav)"};
if (outputfile.existsAsFile())
outputfile.deleteFile();
auto ostream = outputfile.createOutputStream();
auto writer = wavf.createWriterFor(ostream.release(), outsr, reader->numChannels, 32, {}, 0);
int bufsize = 256;
juce::AudioBuffer<float> procBuf{(int)reader->numChannels, bufsize};
procBuf.clear();
int outlen = reader->lengthInSamples / reader->sampleRate * outsr;
int counter = 0;
src->prepareToPlay(bufsize, outsr);
src->setStretchRatio(0.5);
while (counter < outlen)
{
juce::AudioSourceChannelInfo info;
info.buffer = &procBuf;
info.startSample = 0;
info.numSamples = bufsize;
src->getNextAudioBlock(info);
writer->writeFromAudioSampleBuffer(procBuf, 0, bufsize);
counter += bufsize;
}
delete writer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment