Skip to content

Conversation

@jetrotal
Copy link
Contributor

Very dirty implementation of play music from timestamp.

TPC Syntax:

@msg.choice {
    .case "MEMORIZE + TIMESTAMP" {
        @comment "memorize bgm"
        @cmd 11530, "", [0, 10] // [tick_variabletype, tick_variablevalue]
        
    }
    .case "PLAY MEMORIZED W TIMESTAMP" {
        @bgm.stop
        @comment "play memorized bgm"
        @cmd 11540, "", [0, 10] // [tick_variabletype, tick_variablevalue]
        
    }
    .cancel bl {
        
    }
}

I runs correctly with wav files.

MIDI seems to have a glitch: Every time The music resets, the latest tick from the music is understood as 0:

  • first time playing a midi: 0 is 0
  • if I reset the song at 9s: 9 is the new 0.
  • If I reset the song again: 18s is the new 0.

(Oh boy, I can see this becoming another feature to never be aproved)

@Ghabry
Copy link
Member

Ghabry commented Sep 22, 2025

I like the idea but not the implementation 😅 . This pitch adjustments looks very fragile and does solve the problem at the wrong layer: The audio decoder itself should do the seeking/telling though this directly increases the complexity by a lot which also explains why nobody added this before:

When you look in audio_decoder_base you can see the functions Seek and Tell these are for the stream position in bytes which is not useful for telling about where the stream is in terms of time.

But something similar could be added like SeekMilliseconds and TellMilliseconds which seeks / gets the position in milliseconds (higher precision than the seconds from MidiTicks).

In audio_decoder_base.cpp add a stub like for the normal seek/tell. Then e.g. implement it just for the DrWavDecoder and play a WAV file for doing the testing.

Also add suitable functions BGM_SeekMilliseconds/TellMilliseconds to audio.h and audio_generic.h.

@jetrotal
Copy link
Contributor Author

My first thought was to base this on the tick metrics the engine uses as a variable option, since the engine has it coded already and can be useful if someone tries something different, like dynamic music changes with musical changes.

That's why I chose that part of the code. It's a shame midi gets the tick value in such broken way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants