(spoiler: turns out I was scribbling over memory I shouldn't have been ... including the RNG state)
I think I've discovered a strange issue with rnd()
and mouse position:
Here, I'm just playing a snare hit over and over again. The snare is created by mixing a sine wave with noise, where the noise is generated by rnd()
. (With separate envelopes applied to each component.) Notice that every time the mouse exits the top of the screen, the character of the sound changes, becoming more tonal.
I am virtually certain this is because rnd()
is doing something strange. If I modify my audio chunk synthesis function (runs ~1x/frame, generating ~100 samples) to put srand(any_constant_value)
at the beginning, I'll get the tonal effect every time. If I instead put this at the beginning:
seed=0 function audio_dochunk() srand(seed) seed+=1 |
... then I never get the tonal effect, which is the result I would expect. I have confirmed that this does not happen when the mouse exits the screen in any other direction.
I've attached the cart for reference. Not sure if this'll work on the web - I'm seeing this on a Mac.
(Also, web PCM is always wonky for me, and drag controls here turn on mouse capture, which also appears to not work on BBS embeds? So knobs etc. won't work unless you download and run locally.)
I don't think it has so much to do with the mouse as when the mouse leaves the window, you have lost focus and there is a new timing involved for not being focused, @luchak.
For instance here I have changed my configuration for Pico-8.
-foreground_sleep_ms 1 -background_sleep_ms 1000
Try running it direct from Pico-8 and if it sounds differently, use the same sleep_ms
for both and see if it still changes sound when you lose focus.
You're probably overwriting the RNG area in the pico8 memory in your memcpy, as you're writing to 0x6000+off, and off may be negative if the mouse is exiting the screen upwards.
@thisismypassword Oh, nice, yeah, that's almost definitely it, it didn't occur to me that RNG state would be in cart-accessible Pico-8 memory, and I'm definitely not careful about scribbling over things near 0x6000. Whoops. Thank you!
edit: yeah, that was it.
[Please log in to post a comment]