diff --git a/modules/juce_audio_utils/players/juce_SoundPlayer.cpp b/modules/juce_audio_utils/players/juce_SoundPlayer.cpp index a6e79e7713..1623eba09c 100644 --- a/modules/juce_audio_utils/players/juce_SoundPlayer.cpp +++ b/modules/juce_audio_utils/players/juce_SoundPlayer.cpp @@ -28,9 +28,9 @@ // This is an AudioTransportSource which will own it's assigned source struct AudioSourceOwningTransportSource : public AudioTransportSource { - AudioSourceOwningTransportSource (PositionableAudioSource* s) : source (s) + AudioSourceOwningTransportSource (PositionableAudioSource* s, double sampleRate) : source (s) { - AudioTransportSource::setSource (s); + AudioTransportSource::setSource (s, 0, nullptr, sampleRate); } ~AudioSourceOwningTransportSource() @@ -180,7 +180,7 @@ void SoundPlayer::play (const void* resourceData, size_t resourceSize) void SoundPlayer::play (AudioFormatReader* reader, bool deleteWhenFinished) { if (reader != nullptr) - play (new AudioFormatReaderSource (reader, deleteWhenFinished), true); + play (new AudioFormatReaderSource (reader, deleteWhenFinished), true, reader->sampleRate); } void SoundPlayer::play (AudioSampleBuffer* buffer, bool deleteWhenFinished, bool playOnAllOutputChannels) @@ -189,7 +189,7 @@ void SoundPlayer::play (AudioSampleBuffer* buffer, bool deleteWhenFinished, bool play (new AudioSampleBufferSource (buffer, deleteWhenFinished, playOnAllOutputChannels), true); } -void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFinished) +void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFinished, double fileSampleRate) { if (audioSource != nullptr) { @@ -199,12 +199,12 @@ void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFin { if (deleteWhenFinished) { - transport = new AudioSourceOwningTransportSource (audioSource); + transport = new AudioSourceOwningTransportSource (audioSource, fileSampleRate); } else { transport = new AudioTransportSource(); - transport->setSource (audioSource); + transport->setSource (audioSource, 0, nullptr, fileSampleRate); deleteWhenFinished = true; } } diff --git a/modules/juce_audio_utils/players/juce_SoundPlayer.h b/modules/juce_audio_utils/players/juce_SoundPlayer.h index e3ccc1dc5d..b436c6316e 100644 --- a/modules/juce_audio_utils/players/juce_SoundPlayer.h +++ b/modules/juce_audio_utils/players/juce_SoundPlayer.h @@ -77,8 +77,12 @@ public: @param deleteWhenFinished If this is true then the audio source will be deleted once the device manager has finished playing. + @param sampleRateOfSource The sample rate of the source. If this is zero, JUCE + will assume that the sample rate is the same as the + audio output device. */ - void play (PositionableAudioSource* audioSource, bool deleteWhenFinished = false); + void play (PositionableAudioSource* audioSource, bool deleteWhenFinished = false, + double sampleRateOfSource = 0.0); /** Plays the sound from an audio sample buffer.