Log In  

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.

P#38037 2017-03-04 14:22 ( Edited 2017-05-08 17:11)

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.

P#38094 2017-03-08 03:10 ( Edited 2017-03-08 08:10)
1

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:

Cart #38114 | 2017-03-09 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

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
P#38115 2017-03-09 01:50 ( Edited 2017-03-09 06:56)

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.

P#40173 2017-05-04 08:31 ( Edited 2017-05-04 12:31)

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". =)

P#40174 2017-05-04 08:51 ( Edited 2017-05-04 12:51)

an optional frequency offset would go a long way towards sound effect variety!
for now I'll be trying with peeks and pokes...

P#40325 2017-05-08 13:11 ( Edited 2017-05-08 17:11)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 12:56:12 | 0.010s | Q:22