Log In  

Hey y'all, I'm gonna use this thread as my rubber ducky while I flail around figuring stuff out. Hopefully someone here has insight or I am missing something simple and solvable...

Cart #yajoziyoro-0 | 2021-02-11 | Code ▽ | Embed ▽ | No License
1

I've been trying to create the audio atmosphere where button being held down (x) turns on an otherwise muted music track. In theory this seemed easy. I feel like I am always one step away from a graceful solution, but keep making a mess.

I have created the function squeak(voil) that goes through the music memory and peeks and pokes its way to mute and unmute (aka voil) the particular channel on key press. This only works for the NEXT pattern however and not for the current pattern playing.

Alright, well, since I'm doing the peeking, I know the sfx that is supposed to be playing on the heretofore muted channel. I can just run an sfx call, offset by stat(20)—and then when the music call rolls over to the next pattern, the newly unmuted channel will just take over and everything will loop fine from that point on forever, but the music tag doesn't take over from the sfx.

Here's the action bits; mus_cycle(n) is the rudimentary state machine that is toggled on click. Full cart above.

function squeak(voil)
 printh("-------------------- "..(voil and "voil up" or "voil down"))
 -- printh(stat(24))
 local c=0
 local mus_trac,catchup=stat(24),0
 for mem=0x3102,0x31ff,4 do
  local v=peek(mem)
  local track = voil and band(v,0b111111) or bor(v,0b1000000)
  poke(mem, track)
  -- printh("poked "..mem.."     "..track)

  if(c==mus_trac) catchup=band(track,0b111111)
  c+=1
 end
 if voil then

  sfx(catchup,3,stat(20))
  -- printh(stat(19).." voil")
  printh(catchup.." "..stat(23).." / "..stat(26).." voil")
 else

  sfx(-1,3)
  sfx(-1,2)
  -- sfx(21,-2)
  -- printh(stat(19).." no voil")
  printh(catchup.." "..stat(23).." / "..stat(26).." no voil")
 end
 -- music(stat(24),0,stat(26))
 -- printh(stat(19))
end

mus_action=1
-- 1=nothing playing, 2=play nothing
-- 3=squeaky playing, 4=play squeaky
function mus_cycle(n)
 local boops={
  function()  end,
  function()
   squeak(false)
   mus_action=1
  end,
  function()  end,
  function()
   squeak(true)
   mus_action=3
  end
 }
 boops[n]()
end
  • Why is the music+sfx tune catchup solution tripping all over itself?
  • It feels like it works (loops form sfx to music) THE FIRST TIME, but then runs out of numbers or something?
  • Am I running out of channels and not realizing it? There should be a whole empty channel? I tried letting the engine decide where to play what and I tried explicitly nailing things down.

  • If I could have the music track start from a particular NOTE that would be great, but I can't and if I restart the music, I lose the rhythm.
  • I dunno what to make of stat(26), the values it is returning are weird.
  • I've been meaning to cache the mute/voil versions of the music and memcpy them into place as needed. Would that solve the issue however?
  • I really want to avoid having to manually serve one of the music channels through some kind of timer if I can get away with it...
  • But ugh how do people traditionally solve this kind of problem?
P#87392 2021-02-11 02:52 ( Edited 2021-02-11 02:55)

Alright, so I came up with something. I stripped all the game and left just the music action in the cart below.

Feel free to use it if it works for ya!

Cart #giwuwiridi-0 | 2021-02-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

  • the music plays on its own with the 3rd channel muted
  • the function that mutes the channel, feeds all the sfx on that channel into an array
  • on btn(X) the sfx() starts playing the current note of the current pattern's 3rd sfx
    • while btn(X), on the very next note of the 3rd sfx, i call the sfx() on the same clip again (to make sure the timing is tight, as a note could last any number of frames, and this ensures it always lines up even if it crops the starting note)
    • if the btn(x) is still pressed down when the current sfx runs out, it calls the next one
  • whenever btn(x) is released 3rd channel is muted again

It works fine.

Moral of this story is: commit to a single solution, rather than drive self daffy whack-a-mole-ing shortcomings of earlier partial solutions, no matter how crisp they seem in theory.

XOXO

P#87822 2021-02-18 01:05 ( Edited 2021-02-18 01:09)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 10:20:23 | 0.010s | Q:18