Pd.sound.fileplayer plays music with wrong speed if specific track been loaded before

Windows SDK 2.5.0.
After I load an specific track, any next tracks that will be loaded, will have incorrect speed. But, if you never load that specific track, all other tracks will have correct speed.

(Music tracks attachment) Can't upload it here, so here is google drive.

Sounds confusing, but let's see on real example:

There is 3 tracks. BG1.wav, BG2.wav and Intro.wav.

If we NEVER load Intro.wav to pd.sound.fileplayer, BG1.wav and BG2.wav will be played correctly. But if ever Intro.wav been played, BG1.wav and BG2.wav will have incorrect speed.

Small helping hand code for you to handle it same way I do:

SoundManager = {}
SoundManager.MusicVolume = 1

local lastmusicloaded = ""

function SoundManager:PlayMusic(name, smooth)
    if smooth == nil then
        smooth = true
    end
    local justplayfromstart = false
    if lastmusicloaded == name then
        if musicplayer ~= nil then
            if not musicplayer:isPlaying() then
                justplayfromstart = true
            else
                return
            end
        end
    end
    if musicplayer == nil then
        musicplayer = pd.sound.fileplayer.new("music/"..name)
    else
        musicplayer:stop()
        if not justplayfromstart then
            musicplayer:load("music/"..name)
        end
    end
    if smooth then
        musicplayer:setVolume(0)
        musicplayer:setVolume(SoundManager.MusicVolume, SoundManager.MusicVolume, 3)
    else
        musicplayer:setVolume(SoundManager.MusicVolume)
    end
    
    musicplayer:play(0)
    lastmusicloaded = name
end

Steps to reproduce:

  1. SoundManager:PlayMusic("Intro")
  2. SoundManager:PlayMusic("BG1")
  3. BG1 - playing with incorrect speed.

Expected:

If you load SoundManager:PlayMusic("BG1") and never exectute SoundManager:PlayMusic("Intro") BG1 will sounds normal, I expect to Intro.wav never cased any next problems with later played tracks.

P.S.

It only happends if music share same instance, in my case when new track need to be loaded, I am utilize previously allocated fileplayer, musicplayer:load("music/"..name) if instead we going to allocate new instance for each next track, like so musicplayer = pd.sound.fileplayer.new("music/"..name) there will not be a problem with this.

2 Likes

I have this exact same issue. Reusing a fileplayer ond load() a new track will cause the 2nd track to use the internal audio rate of the first track.

Was there ever a fix for this?
It seems wasteful to new up a new player each time, but maybe that's how it was intended to be used?

I confirmed that as long as I author all waves at the same khz then the problem does not manifest. This has been my solution for the moment.