Log In  

A cart a bit different than the usual coming from me. I recently discovered about the hidden PCM channel and I just had to play with.

So I'm experimenting with both sample playback and PSG (Programmable Sound Generators) to both learn and see if we can make the most of the PCM channel and -why not- in the distant future, have a 5-channel tracker?

So here, we've got one cart that shows smooth playback of various samples and at the end a sawtooth PSG.

Cart #eyn_smplsndbx-0 | 2021-05-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
10

To generate the samples, I use two steps:

  • A pass through SoX to convert a sample into unsigned 8bit 5512Hz raw file (-e unsigned-integer -r 5512 -b 8).
  • A quick use of a Python script to convert the sample into a pastable string (I suggest you to convert it into chars once inside Pico-8). I'm sorry I can't post the snippet here yet, it somehow breaks the BBS' upload process.

I commented in the cart a basic low-pass filter inside the sawtooth PSG. It seems pretty costly to generate it on the fly. Maybe it'd be wise to precompute filtered waveforms like LSDj does.

A few notes on my findings

  • The playback is way better on Desktop than on a browser. I'm sorry in advance for the noise or the volume.
  • I got the best playback results with a packet size of 512 bytes.
  • Just playing samples from a string doesn't cost a lot. It'd be even lighter if you would blit the string in the RAM to just memcpy away.
  • It seems that a tick of length 8 in a SFX vaguely matches 366 PCM samples. Vaguely because I still have desync issues after a while. I wish I can find the proper packet size balance so we could not have to deal with desyncs.

Update : moved to SFX. I probably won't touch the cart anymore.

P#91665 2021-05-07 22:36 ( Edited 2021-09-13 11:49)

> It seems that a tick of length 8 in a SFX vaguely matches 366 PCM samples. Vaguely because I still have desync issues after a while. I wish I can find the proper packet size balance so we could not have to deal with desyncs.

Huh - my past experiments implied that 1 PICO-8 music tick is 183 samples at 22050 Hz, so a tick of length 8 in an SFX should be exactly 366 PCM samples at 5512.5 Hz.

Does it drift out of sync steadily? I know 183/22050 is approximately 1/120.5, so absent lag the 60 fps clock for screen update slips out of sync with the music cart at a rate of about one part in 240 - if it's, like, one second per four minutes, that would line up.

P#91717 2021-05-09 20:40

Those samples are pretty crisp! If you haven't seen this cart yet, it might be helpful for what you're doing here with PSG. It emulates an old audio chip and blends 3 tracks into the PCM channel, for tone/volume/noise without any active Pico-8 audio channels at all: https://www.lexaloffle.com/bbs/?pid=90136

The desync might be a bug due to internal use of two separate audio playback streams, which lag separately. I think PCM was only ever intended for sound effects and voice clips, so it probably isn't blended with the music stream in a way that they'd stay synced up forever. Could maybe resync both as each new song is queued up, though.

P#91721 2021-05-09 21:46
1

Here's the cart I used to test the synchronization:

Cart #eyn_ticksync-0 | 2021-05-09 | Code ▽ | Embed ▽ | No License
1

The number of loops is computed from the number of samples played, not the number of patterns. Should I update it with both counters?

Edit : after somewhat 96-98 loops, it starts to desync.
Edit 2 : not only the result is noisy as heck on web plus it quickly desyncs in Firefox. Didn't have to wait more than 3 loops.

> Those samples are pretty crisp!

Thanks! I had to deal with sample conversion in the past and I have a few friends that are well versed in the topic, can't deny it helped! Also it's raw 8bit at "native" sample rate, can't do cleaner than that haha (also my cart size hurts)!

> Does it drift out of sync steadily?
Not after a few patterns, I haven't counted them but after at least more than 10 sfx loops, it starts to drift enough so you can hear phasing.

> If you haven't seen this cart yet, it might be helpful for what you're doing here with PSG.

Actually that's the one that made me discover that feature! I'm more interested as using the PCM as a new channel rather than softmix into it.

> Could maybe resync both as each new song is queued up, though.

I'm looking into the stuff to make a music tracker. I know I'll have a lot of headaches just to track the channels independently, so I guess that's another thing to add to the list.

P#91722 2021-05-09 21:54 ( Edited 2021-05-09 22:13)

> Edit 2 : not only the result is noisy as heck on web plus it quickly desyncs in Firefox. Didn't have to wait more than 3 loops.

Huh - could it be related to lag somehow? Does it desync when frames are dropped? I think browser PICO-8 is laggier than desktop PICO-8.

P#91730 2021-05-10 02:56

On Chrome that new cart stays synced for longer, but if you pause it and then resume it's completely desynced, by what seems like a random amount. This seems to confirm that it's two separate streams internally (one for PCM, one for the main 4 audio channels), and these desync issues might be unavoidable because of that.

I'd recommend posting that cart in bugs or feature requests, and seeing if zep is willing to manually mix the two audio streams before playback in one output stream, so they always stay in sync with each other. I don't think there's any other way to do this blended tracker + PSG idea purely inside Pico-8, unfortunately. But since a lot of people are using PCM to make music right now, this might be an easy feature to sell.

P#91736 2021-05-10 05:31 ( Edited 2021-05-10 05:32)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 19:28:48 | 0.011s | Q:24