Browse Source

SoundPlayer: Added support for automatic sample rate conversion when playing audio from AudioFormatReaders

tags/2021-05-28
hogliux 8 years ago
parent
commit
38f9e951bb
2 changed files with 11 additions and 7 deletions
  1. +6
    -6
      modules/juce_audio_utils/players/juce_SoundPlayer.cpp
  2. +5
    -1
      modules/juce_audio_utils/players/juce_SoundPlayer.h

+ 6
- 6
modules/juce_audio_utils/players/juce_SoundPlayer.cpp View File

@@ -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;
}
}


+ 5
- 1
modules/juce_audio_utils/players/juce_SoundPlayer.h View File

@@ -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.


Loading…
Cancel
Save