41 #ifndef filmstro_audiobasics_OutputSourcePlayer_h
42 #define filmstro_audiobasics_OutputSourcePlayer_h
57 : internalSampleRate (sampleRate),
58 deviceSampleRate (0.0),
59 numChannels (channels),
60 outputDevice (nullptr)
70 const juce::ScopedLock sl (readLock);
71 juce::AudioSourcePlayer::setSource (newSource);
78 float **outputChannelData,
int totalNumOutputChannels,
79 int numSamples)
override
81 if (getCurrentSource()) {
82 const juce::ScopedLock sl (readLock);
84 if (outputDevice !=
nullptr) {
85 if (fabs (deviceSampleRate - outputDevice->getCurrentSampleRate ()) > 1.0) {
86 deviceSampleRate = outputDevice->getCurrentSampleRate();
87 resampler->setResamplingRatio (deviceSampleRate != 0 ?
88 internalSampleRate / deviceSampleRate :
90 resampler->flushBuffers ();
93 juce::AudioBuffer<float> buffer (outputChannelData,
94 totalNumOutputChannels,
96 juce::AudioSourceChannelInfo bufferToFill (&buffer, 0, numSamples);
97 resampler->getNextAudioBlock (bufferToFill);
100 juce::AudioSourcePlayer::audioDeviceIOCallback (inputChannelData,
101 totalNumInputChannels,
103 totalNumOutputChannels,
113 outputDevice = device;
114 resampler =
new juce::ResamplingAudioSource (getCurrentSource(),
false);
115 resampler->prepareToPlay (device->getCurrentBufferSizeSamples(),
116 device->getCurrentSampleRate());
117 juce::AudioSourcePlayer::audioDeviceAboutToStart (device);
125 juce::AudioSourcePlayer::audioDeviceStopped();
127 outputDevice =
nullptr;
133 double internalSampleRate;
135 double deviceSampleRate;
139 juce::AudioIODevice* outputDevice;
141 juce::ScopedPointer<juce::ResamplingAudioSource> resampler;
143 juce::CriticalSection readLock;
void setSource(juce::AudioSource *newSource)
Set or replace the source of the AudioSourcePlayer.
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:68
void audioDeviceStopped() override
Callback when the AudioIODevice just stopped using the AudioDeviceIOCallback.
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:123
void audioDeviceAboutToStart(juce::AudioIODevice *device) override
callback when the device wants to start using the AudioDeviceIOCallback
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:111
void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples) override
Callback from the AudioIODevice.
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:77
This class provides an AudioSourcePlayer, which will adapt its resampler whenever the device changes ...
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:48
OutputSourcePlayer(double sampleRate, int channels=2)
Constructs an OutputSourcePlayer.
Definition: filmstro_audiohelpers_OutputSourcePlayer.h:56