Simple audio player, output at wrong rate, where/how to resample?


#1

Hi,

Sorry for the newbie question, but I haven't had any luck with existing forum q's, the API, or general web searching - - -

I'm putting together a simple audio player app (in Windows) to better learn JUCE, sort of folowing along the examples in the "Getting Started with JUCE book". The main difference is I'm trying to play an OggVorbis audio file...

So far I've got, and this seems pretty standard:

   AudoFormatManager + .ogg file ->

   AudioFormatReader ->

   AudioFormatReaderSource ->

   AudioTransportSource ->

   AudioSourcePlayer ->

   AudioDeviceManager

Hooray, it plays! But at the wrong speed, because my audio device only supports 48000Hz and the ogg file is 44100Hz, and it's being sped up by that ratio on playback.

My question is how/where to correct this? I can't insert a ResamplingAudioSource in the chain because it's not Positionable. An earlier forum topic gave the impression that the TransportSource might/ought to magically do the resampling, but it sure isn't.

What am I missing? Thanks for any help

- Martin Sz.

 


#2

The transport source definitely resamples correctly if it knows what rate it should be playing at. Maybe the audio device code is misbehaving and it thinks the rate is different.. Does the juce demo audio playback work?


#3

The only demo app I see for this is the AudioAppExample, which is a waveform generator. I hard-wired it to crank out 1000 Hz test tone and it is correct. But there's no audio file and no visible transport source so I don't know what to take away from this. Is there a different demo app that plays back an audio file?

 


#4

The big demo app has a subsection of audio demos, including a file player.


#5

Found it; and yes, that works. I'll spend time with that code and figure out the error in my ways

Thanks!

- - -

Addendum: my problem was in taking default values in AudioTransportSource::setSource, and not specifying the sample rate there.

I had been under the impression that the transport source might get the right sample rate magically via the audio format reader source param.

Working well now.


#6

Hey dude, I’m running into kind of the same issue you fixed. You don’t mind sharing which part of the Juce demo helped you solve the problem?