Audio Glitches when playing a midi file with audio sample on device

,

Hi,
I'm trying to play a midi file where the notes are created from one .wav audio sample.
I have something working, but on the device, some audio glitches are audible (They are hardly noticable in the simulator).
I'm not sure if it is a bug or if I'm doing something wrong, but it seems that this problem appeared recently (or it is just that I never noticed it in the simulator).

Here is attached a sample code (and an attached project file).

local snd = playdate.sound

local music = snd.sequence.new("sounds/music.mid")
local sample = snd.sample.new("sounds/note")
local ntracks = music:getTrackCount()
for i=1,ntracks do
    local track = music:getTrackAtIndex(i)
    local instrument = snd.instrument.new()
    for i=1,track:getPolyphony() do
        instrument:addVoice(snd.synth.new(sample))
    end
    track:setInstrument(instrument)
end
music:play()
function playdate.update()
end

Source.zip (283.2 KB)

This is not exactly what I do in my app, but it seems to reproduce the problem.

Do you have any idea where these audio glitches come from?

1 Like

As a dev who doesn't have hardware yet, this scares me. I'm pretty invested in midi.

This seems related to this issue I posted a while ago:

Unfortunately I still haven't found a solution.

1 Like

I also do goToStep in my app (not in this sample code).
And the audio glitch is so weird !
It looks like the audio data is coming from some internal audio waveform.

Here is attached the recorded audio on the playdate (when performing goToStep) , with the strange glitches after the plain notes.

With your post and mine, the sdk team have a lot of info (even sample projects) to reproduce and analyse the problem.
Some feedback would be welcome.

1 Like

This was a regression that popped up in 1.12.1, causing sample-based synths to play past the end of the sample data. I've fixed that, and also a separate issue with goToStep() sometimes going to the step before the requested step, if you've noticed anything odd there.

We're working our way through the 1.13 MR queue now, hope to have a beta out soon and a release not too much later!

2 Likes

Great !
Thank you for the feedback and for the fix :slight_smile:

I should have mentioned a simple workaround: Switching to a mono sample avoids the overrun bug. I was also going to say you could use getSubsample() to make a new sample from the data that's half the length, so that when it plays twice as long it actually ends at the right spot, but there's another bug (fixed for 1.13) where sample synths can't play subsamples. :confused:

1 Like

This workaround is something I can use right now !
Thank you.

1 Like