JohnEarnest / Octo

A Chip8 IDE
MIT License
664 stars 53 forks source link

Yet Another Proposal: Stereo Audio with Multi-Voice Support (Sweet and Simple Design) #162

Closed Bandock closed 2 years ago

Bandock commented 2 years ago

Me and @Kouzeru recently had discussions about stereo audio recently (as originally, I was planning a different solution for that, but feedback led to a great solution) as well as multi-voice (which you already know from an older issue).

I would like to present three new instructions (which I first implemented in my HyperCHIP-64 extension and also implemented in @Kouzeru's Octo fork) that enable such capabilities.

The first one is the volume instruction FX3B, which allows finer control (utilizing 8-bit volume control supplied by a register, similar to how the pitch instruction works). This actually is important for multi-voice support as additive synthesis is generally involved here when using 1-bit samples. This leads up to the next instruction, the voice instruction FN3C. Currently, I put a limit of 4 in my implementation (@Kouzeru has done the same). This is not a mask, but instead a literal value (ranging from 0 to 15). To make this particular feature work, additional sound timers are required. Fortunately, this instruction automatically selects the right timer when you set the buzzer and you can adjust the pitch just for that voice. ;)

Now comes the tasty instruction that enables stereo audio. This one is the channel instruction FN3D. Functionality wise, it operates much like XO-CHIP's plane instruction, except it's for audio. Drawing inspiration from that instruction and also from Yamaha's OPL3 chip (found on numerous sound cards in the past), this is essentially a channel mask instruction. Channel masks are handled per voice (meaning, you can control the output to different speaker channels for each voice using this instruction). Right now, the first bit is used to handle the left channel and the second bit is used to handle the right channel. The other two could enable quadraphonic support, but not necessary at the moment.

@Kouzeru recently made a very awesome demo, showing off these capabilities. The link is right here: https://kouzeru.github.io/Octo/index.html?key=Cn39wl5y (Utilizes both multi-voice and stereo audio support)

If you ever want to implement these instructions into Octo and XO-CHIP one day, I think these would be a perfect match:

voice N # FN3C
channel N # FN3D, remember, this sets the mask for the currently selected voice
volume VX # FX3B, sets the volume for the currently selected voice
volume := VX # Possible alternative syntax if you prefer

Let me know what you think of this proposal.