You know what would be handy?
sfx n [channel [offset] [end]]
where [end] is the last note to be played. I'm in a spot right now where I'm needing extra space for music, and it would be very useful if I could cram more than one sound effect into a single slot.
More control over music in general would be great. I wanted to do something for a game I did where I had two tracks and swap between them dynamically without missing a beat but there's no real way to do it with the current API. Or at least no way to do it in the amount of time I had for the game jam.
hrm.. that is a nice idea. Apart from space saving, it would also allow things like varying sound effects like explosions by playing them from random offsets.
Unfortunately I can't break the API right now (PocketCHIP PICO-8 needs to work out of the box with BBS carts), but am wish-listing things like this for a potential API-breaking update in the future.
Judging by your gifs on twitter, there aren't many tokens to spare either, but the best alternative I could suggest is to memcpy sound data into an SFX each time you want to play. Here's a demo that stuffs 8 8-note sounds into 2 SFX:
It costs 5 tokens to copy the SFX data into user memory space during _init():
-- copy the first 2 SFX to 0x4300. (Each one is 68 bytes) memcpy(0x4300,0x3200,136) |
And 26 tokens to play them:
function tinysfx(i) -- clear the sfx to play memset(0x3200,0,64) -- copy 8 notes from the desired sfx memcpy(0x3200, band(i,0xfc)+ -- skip spd etc 0x4300+i*16, 16) sfx(0) end |
Each SFX starting at 0x3200 is 68 bytes long: 32*2 for notes and 4 bytes for SPD & LOOP. The band() is to jump over the 4 byte gaps. If you already have note data stored somewhere in the cart data as one continuous block, you could skip the initial memcpy() and do it in 14 tokens total:
function tsfx(i) memcpy(0x3200,0x4300+i,16) sfx(0) end |
While we are already on that topic. I would love to be able, to directly move values into the audio-buffer.
To make techniques like that possible:
https://www.youtube.com/watch?v=tCRPUv8V22o
For now I'll try to poke stuff around like you showed in this example.
Hm.. one neat detail could be, that the code must be evaluated in audio-frequency speed. That would make some "special facility" necessary. Something like a "shader for sound". =)
an optional frequency offset would go a long way towards sound effect variety!
for now I'll be trying with peeks and pokes...
[Please log in to post a comment]