The upcoming Pico-8 0.2.6 release will introduce wavetable synthesis via "waveform instruments". Any of this may change before release so I will try to update it as I discover new info about the feature. The waveform instruments are stored in the same sfx indices as regular instruments (0-7) and use a similar encoding scheme to regular sfx:
Bytes 0-63
The first 64 bytes of the sfx contain one signed 8-bit sample per byte. Pico-8 uses signed 16-bit numbers, so signed 8-bit values from -128 to -1 are represented as 128 to 255, while 0 to 127 are represented normally. Signed 8-bit values outside the -96 to 96 range will appear cropped in the visual editor, although it does appear to be possible to draw values in the full range by dragging the mouse cursor beyond the border.
Regarding PCM playback, Pico-8's tracker updates at about 120.4918Hz, and at 64 signed 8-bit samples per cycle, the sample rate would be about 7711.4752Hz. However, because the closest playback frequencies available are A#-0 (A#-2 in standard pitch notation @ 116.54Hz) or B-0 (B-2 in standard pitch notation @ 123.47Hz), it appears that smooth PCM playback will not be possible by stringing waveform instruments together, as waveforms would not have the chance to play exactly one oscillation per tick; instead being slightly cropped or slightly looped (and then cropped). This will result in clipping/distortion, and weird tuning artifacts.
Byte 64
Used for editor mode and sfx filters. This byte serves the same purpose as regular sfx and the filters introduced in 0.2.2 can be used with waveform instruments.
Byte 65
If the lowest bit is set (1), the "bass" option will be activated and the instrument will be transposed down one octave. I assume this is similar to poking byte 0x5f40.
Byte 66
If the highest bit is set (128), the sfx will be activated as a waveform instrument.
Byte 67
Unused
This looks really cool! I'm excited to hear what people can come up with using custom instruments. Do you know if these will be able to be modified at runtime and/or will we be able to employ custom waveform instruments on-the-fly with control codes?
This is going to be a game changer for SFX and Music on PICO-8!
@kozm0naut Yeah, u can just write to RAM per above specs. I'm unclear atm about how Pico-8's internal mixer is handling this data but since it's raw audio, it's best to be safe and say that u should be very careful with what u write to not damage the user's speakers or ears.
[Please log in to post a comment]