Log In  

Cart #impossible-1 | 2021-03-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Impossible Mission R.T.

Discovered #pico8's secret 5512Hz 8-bit digital audio out API.

Created a homage to this legendary 80's masterpiece to celebrate.

Thanks zep!

P#88937 2021-03-13 22:14



P#88939 2021-03-13 22:28

There have been so many amazing carts made for PICO-8. Yet somehow you have proven that we haven't scratched the surface of greatness until now. Absolutely incredible.

P#88944 2021-03-14 00:14

excellent finding!

P#88952 2021-03-14 08:10

I had made a cart privately a while back demonstrating the possibility of a wavetable/PCM software mixing engine taking a small fraction of the PICO-8's CPU budget, which could've possibly allowed MOD playback with samples outputted from the GPIO pins. With some updates, I can now finally hear what it's actually generating!

I was darn hoping there would be a way to play samples from RAM, but I never even thought it would be done through a serial channel. And I never bothered to look for undocumented serial channels!

Cart #sb06_soft_synth-0 | 2021-03-14 | Code ▽ | Embed ▽ | No License

Also, I came across a PICO-8 bug where the mute shortcut (CTRL+M) or the mute button on the BBS player doesn't mute the undocumented PCM DMA channel, but otherwise does mute the normal PSG audio. I don't know if it should use either the music or SFX volume in the config, but I'm assuming it would be used for short voice clips so the latter would be a good choice. But no less, can this bug be fixed @zep?

P#88955 2021-03-14 09:10 ( Edited 2021-03-14 09:23)
:: zep

Very nicely done @carlc27843. And I can't imagine a more fitting demo cart ~~ it's perfect!

@StinkerB06 thanks, will fix that for 0.2.2d. (PICO-8 only observes the global volume setting, so it will be straightforward).

P#88960 2021-03-14 13:35

Thanks @zep, and very nice demo @StinkerB06!

I can't wait to see what other procedural audio the PICO-8 community comes up with.

The first person to create PICO-8-SID will be awarded a gold star personally delivered through the internet from me. ;)

P#88968 2021-03-14 17:00

This is so cool! I was actually just thinking the other day about whether I could wire PICO-8 up to some Javascript to play samples on cue; this would be a way to do that without the external gubbins.

...now I'm wishing I knew how to do, like, speech synthesis, because it'd be awesome to have a library for converting X-SAMPA phonetic transcription into PICO-8 serial audio.

P#88971 2021-03-14 19:46
:: Megus

I was sure that sample playback is possible! Now we can create synths!

P#88979 2021-03-14 22:35

how did you go about encoding audio into a string?

P#88984 2021-03-15 01:06

@tesselode that's a really good question. I have a custom build system but the audio conversion part boils down to:

  1. use ffmpeg (https://ffmpeg.org/) to convert to 5512hz sample rate and single channel, and output an ogg, e.g.
    ffmpeg -i inputpath -ar 5512 -ac 1 outputpath.ogg
  2. use stb_vorbis.c (https://github.com/nothings/stb/blob/master/stb_vorbis.c) stb_vorbis_decode_filename() to load the file into 16-bit samples
  3. for each sample do sample_p8 = (uint8_t)((sample_16>>8)+128)
  4. encode the sample bytes into a pico8 string and insert it in the code

The last step required some care:

  • 0 needs to be encoded as \0 {92,48} unless it is followed by a digit (48 through 57) in which case it needs to be encoded as \000 {92,48,48,48}
  • 10 needs to be encoded as \n {92,10}
  • 13 needs to be encoded as \r {92,13}
  • 92 needs to be encoded as \\ {92,92}
  • if you use ' as your quote character then 39 needs to be encoded as \' {92,39}
  • if you use " as your quote character then 34 needs to be encoded as \" {92,34}
  • otherwise the encoded byte can be the input byte
  • surround the encoded bytes with your favorite quote character

I kept bumping into the compressed code size limit and ended up storing 16128 bytes of audio data in rom. The pk function in the cart reads memory into a string using s..=chr(peek(a))

Oh and because of the limited rom/code size I reduced the sample bitcount. A couple of the clips use 5 bits per sample, and the C64 clips use 4 bits per sample. They are expanded to 8 bits at runtime in the updatemix function.

The cart explains but I should mention for searchability: use serial(0x808,address,length) to write your 8-bit samples to the audio output buffer. Use stat(108) to read how many bytes remain buffered for output. I believe at most 2048 bytes can be buffered.

P#88989 2021-03-15 02:59

another interesting aspect is how did you find? poking around? reverse engineering of pico code?

again, thanks for the finding, it puts my Another World/Out of this World port back on track!

P#88993 2021-03-15 08:16
:: dw817

Impressive ! Now if @zep will just let us convert WAVs, we'll be all set.

P#89005 2021-03-15 16:05

@freds72 I think he was just poking around for look for undocumented serial channels, and when he did a write to channel 0x808, he heard a loud noise, assuming he was triggering some hidden audio capabilities.

P#89006 2021-03-15 16:49

@dw817 by my calculation, with the 32k cart size limit, you can't store very much raw audio directly - like, 32k uncompressed only buys you about six seconds. I think a lot of using serial audio samples is going to be about implementing the right compression tools, and I don't see how zep can know what the standard will be in advance.

P#89009 2021-03-15 17:22 ( Edited 2021-03-15 17:23)

@freds72/ @StinkerB06 I was noodling with serial channels 0x804 (stdin) and 0x805 (stdout) trying to get realtime messaging with an external app working (to replace the DLL injected mqtt library I had been using but which was becoming a bear to maintain with zep's prolific updates). I thought I noticed that stdout was only being flushed at 30hz even though I had a 60hz cart so I decided to peek behind the curtain a little...

When I saw what was going on with 0x808 I felt like a kid who noticed the biggest most brightly wrapped present ever behind the tree on christmas morning. Couldn't believe my eyes so I wrote some data to 0x808 - static had never sounded so sweet, knowing that the PICO-8 community would be able to do some amazing carts with the channel. I immediately dropped everything to unwrap that gift and share it with my friends.

You'd think that present would be sufficient, but @zep put a pretty bow on it too. Channel 0x808 just like the famous Roland TR-808 drum machine from the early 80's. Stat 0x6c for the six-cee sounds everyone will be making with it!

I don't think @zep minds if we peek behind the curtain every now and then. If I ever stumble across more undocumented features I plan to only reveal them with entertaining carts that make good use of them.

P#89007 2021-03-15 18:06

indeed right on time for this side project of mine!

P#89015 2021-03-15 18:35

I was wondering why you didn't convert straight to unsigned char pcm:

ffmpeg -i input.wav -ac 1 -ar 5512 -acodec pcm_8 -f data output.u8

seems straightforward? well, never got it to work. ¯\_(ツ)_/¯


sox.exe input.wav -c 1 -r 5512 out.u8

works a treat!

P#89032 2021-03-16 00:24

@zep It also appears that using extcmd"audio_rec" to capture the audio output doesn't capture the PCM channel. Will that get fixed too?

P#89051 2021-03-16 14:51

@ultrabrite I couldn't find the correct incantation to get ffmpeg to the conversion directly to pcm u8 either. Great to know that sox does it, thanks for the tip.

P#89054 2021-03-16 17:16

This is Awesome! I can't believe I just got rick rolled in pico-8, looking forward to seeing the first pico-8 based DAW someday.

P#89056 2021-03-16 17:23

Excellent discovery ! So it is the also the open gate to Viznut ByteBeat ... :)

It is a bit crunchy in webplayer

Cart #bytebeat-3 | 2021-03-16 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

In Pico8, it sounds slightly better

P#89068 2021-03-16 21:02 ( Edited 2021-03-16 22:00)

I can’t believe I got RickRolled

P#89100 2021-03-17 14:22

Absolutely amazing! 100/10!! Best game I have EVER played!!!

P#89161 2021-03-18 10:35

...you know what this means, right?

We've gotta get the Software Automatic Mouth in Pico-8. We Gotta

P#89757 2021-03-30 16:38

How do you do that, furthermore how can I do that? Is there an application for doing that?

P#91372 2021-05-02 00:18

I wonder if, using a similar method to this, the entire Never Gonna Give You Up song could be emulated in PICO-8

P#91376 2021-05-02 00:26

[Under spam review]

P#91532 2021-05-05 14:40

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-05-09 14:39:12 | 0.099s | Q:75