mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
SoundPlayer: Added support for automatic sample rate conversion when playing audio from AudioFormatReaders
This commit is contained in:
parent
b653e838d0
commit
38f9e951bb
2 changed files with 11 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue