Log In  

I want to do some advanced things with the music state, like dynamically change the way playback works. I assume this is possible, but I wasn't able to find detail on the way the music state is mapped out in memory. Does anyone have any details on this?

Specifically I'd like to query the song position (the sequence number and the current pattern position), and update the loop points.

Thanks.

P#15847 2015-10-25 21:56 ( Edited 2015-10-26 05:48)

You can update the loop points for a sample during playback. For example, create a sound in slot 0 with an ascending note pattern all the way across (or whatever), create a music pattern in slot 0 with sound 0 in a channel, then:

function _init()
  music(0)
end

function _update()
  loopbegin = peek(0x3242)
  loopend = peek(0x3243)
  if (btnp(0)) loopend -= 1
  if (btnp(1)) loopend += 1
  poke(0x3243, loopend)
end

function _draw()
  cls()
  print(loopend, 0, 0)
end

I don't know about querying or modifying the current playback position beyond calling music() to start a new pattern.

For future reference:

Song data is stored between 0x3100 and 0x31ff, with four bytes for each of 64 patterns. The lower 6 bits of each byte is a sfx number between 0 and 63 (0x3f). If a channel is disabled for the pattern, the 7th bit is set and the lower bits are just the channel number (0x41, 0x42, 0x43, 0x44 for each of the respective channels). The highest (8th) bit represents a flag for the pattern: channel 1's high bit is "stop at end of pattern," channel 2's high bit is "end pattern loop," and channel 3's high bit is "begin pattern loop" (the three toggle buttons in the music UI).

Sfx data is stored between 0x3200 and 0x42ff, with 68 bytes for each of 64 sounds. The first 64 bytes each represent one of up to 32 notes, two bytes per note, with this layout:

w2-w1-pppppp _-eee-vvv-w3

eee: effect (0-7)
vvv: volume (0-7)
w3w2w1: waveform (0-7)
pppppp: pitch (0-63)

The last four bytes for the sound represent the editor mode (pitch vs. note editor), the note duration (in 1/128ths of a second), the loop range start, and the loop range end. My example above changes the loop end of sound 0 by poking a new value in 0x3243.

P#15850 2015-10-25 23:17 ( Edited 2015-10-26 03:17)

Ah perfect, thanks.

It was the start/end pattern loop points I want to toggle, so I can control transitions by turning off the endpoint to move to the next sequence, or by turning off the start point to go back. It's tricky without being able to query the position though. Maybe I'll just keep a running total of the frames and work out the relation to speed. Seems to be something like speed * 4 frames per quarter note.

The other info won't go to waste etiher. I made some silly (in hindsight) assumptions about the layout and was going to waste a lot of time scratching my head.

Thanks again!

P#15855 2015-10-26 01:48 ( Edited 2015-10-26 05:48)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 23:58:58 | 0.006s | Q:13