Sample rate in Tutorial: Looping audio using..AudioSampleBuffer class


#1

I’ve been playing with the Looping audio tutorial as a basis for the application I’m writing, and I’ve noticed that it doesn’t take into account different sample rates. Could someone suggest how I could implement that? It seems like just changing the buffer size would do the trick, but I’m not seeing how to easily do that. I tried:
AudioDeviceManager::AudioDeviceSetup setup;
deviceManager.getAudioDeviceSetup(setup);
setup.sampleRate = fileSampleRate;
setup.outputChannels=fileNumChannels;
setup.useDefaultOutputChannels=false;
deviceManager.setAudioDeviceSetup(setup,true);

But it didn’t seem to do anything.

                                >>>Steve<<<

#2

Hi Steve,

It would be a little more involved. You could resample the buffer in the getNextAudioBlock() function. You could do this by calculating the ratio of the device sample rate and the file sample rate. This would then allow you to scan through the buffer at the right speed but you wouldn’t be able to simply copy the data in blocks of samples. You 'd need to perform some interpolation on the samples too.

Martin


#3

Thanks for the reply, Martin! So there’s no way to do something like: Change buffer size on the device, or change the sample rate of the device, or even using the resamplingAudioSource class to do it?

      >>>Steve<<<

#4

I guess you could change the sample rate of the device if that supports the sample rate of the file. But that’s not a very practical way of proceeding!

The main point of the tutorial is to show how to do the raw sample reading from a file (then to introduce some multithread handling code in the subsequent advanced tutorial). For most purposes you’re better off using audio sources, which handle this stuff for you.

I’m sure you’ve seen this one? https://www.juce.com/doc/tutorial_playing_sound_files

And this one that draws the waveform too: https://www.juce.com/doc/tutorial_audio_thumbnail