Virtual PCM channels [Prog8]

For posting library code and examples.
Post Reply
badmai
Posts: 31
Joined: Tue May 16, 2023 2:32 am

Virtual PCM channels [Prog8]

Post by badmai »

tldr; example shows how to have 4 virtual pcm channels without mixing samples

This is just a quick proof of concept, and is NOT OPTIMIZED (yet)

Since we only have 1 pcm channel, how to mix multiple pcm sound effects?

first thought was to just combine the samples, clip, fill buffer w/e
a lot of compute!

then I got the idea of virtual channels...
take the max 48828.125 Hz
so with 48828.125 Hz we can have 4 x 12207 Hz samples playing

theory is 48828.125 Hz / max virtual channels, I picked 4 so all samples are 12207 Hz

This is my first test using the idea of virtual channels...seems to work well :)

Try It Now!


*I hope to make it compatible with zsmkit
Attachments
VPCM.ZIP
(26.26 KiB) Downloaded 192 times
User avatar
ahenry3068
Posts: 1144
Joined: Tue Apr 04, 2023 9:57 pm

Re: Virtual PCM channels [Prog8]

Post by ahenry3068 »

badmai wrote: Sat Mar 30, 2024 2:22 am
*I hope to make it compatible with zsmkit

A. You will have to create a "ZCM" header for the data. Put that at the Start of a Bank.
(This will have to describe the "combined" data. The "hardware" format of PCM Data you are actually feeding to the VERA)

(You'll have to study code found here https://github.com/ZeroByteOrg/zsound)



B. Put the PCM Data in BRAM after the header as if you had BLOADED a ZCM.
(ZSMKit's PCM support revolves around this file format. You'll have to simulate loading one of these files).

C. Call zcm_set_mem assigning a ZCM Number

D. Repeat A, B, & C for a 2nd Buffer. (You'll only need a 2nd buffer if you want continuous Audio)

E. zcm_play (ZCM Number 1)


LOOP
Check VERA FIFO. As soon as Empty call ZCM Play on the 2nd Buffer (for continuous Audio)

Reload Audio DATA. Repeat ZCM Play. You'll only need to repeat the Header construction and zcm_set_mem if you want to change the "Hardware" Audio Data format, or change Buffer location.

I'm using this in BASIC for my Audio Book to tell when the FIFO is empty.

DEF FN FIFO.EMPTY(I)=(PEEK($9F3B) AND $40)<>0 IF FN FIFO.EMPTY(0) THEN GOSUB PlayNextBuffer.

I is just a dummy argument as a DEF FN in BASIC requires 1 argument.
User avatar
ahenry3068
Posts: 1144
Joined: Tue Apr 04, 2023 9:57 pm

Re: Virtual PCM channels [Prog8]

Post by ahenry3068 »

You can also put the combined PCM audio in a ZSM file as an instrument. But for the above Program flow I was thinking doing it Real Time. To go into a ZSM file it has to done at Compose time not Playtime. The ZCM Header format is simple enough to construct Real Time. Not so for a ZSM file. ( I think it's unfortunate that the file extension's chosen are so close, ZCM and ZSM are very different internally, There's been a few times I've seen people mixing them up. The parts of ZSMKit that support them both are SEPARATE Routines.
badmai
Posts: 31
Joined: Tue May 16, 2023 2:32 am

Re: Virtual PCM channels [Prog8]

Post by badmai »

Yeah, when I say "*I hope to make it compatible with zsmkit"
just not step on it's toes so to speak, no plans to use it's PCM playback system or specific files

zsm playback is great, but pcm is limited, and talking to MooingLemur this is a "niche" application, which I understand

I'm just trying to implement a simple multi pcm playback system, which works for me AND compatible with zsmkit

currently adding a "streaming pcm" to the kit, which would conflict with the streaming zsm playback

IDK this release has nothing to do zsmkit, thought it was interesting how 4 channels could be played in 1 without mixing the samples ;)

I'll update if people are interested (post), otherwise it's for my personal projects.
User avatar
desertfish
Posts: 1098
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Virtual PCM channels [Prog8]

Post by desertfish »

I like your approach. Simple, to the point, and quite an interesting idea!
mortarm
Posts: 302
Joined: Tue May 16, 2023 6:21 pm

Re: Virtual PCM channels [Prog8]

Post by mortarm »

I'm interested in anything audio related, so I say go for it.
badmai
Posts: 31
Joined: Tue May 16, 2023 2:32 am

Re: Virtual PCM channels [Prog8]

Post by badmai »

ok, it does what I want now...

Streams a ZSM file with 4 Virtual PCM channels...
or
Streams a PCM file with 3 Virtual PCM channels...

*note installed a custom keyboard handler so you can press multiple keys to trigger sounds


Try It Now!






.
Attachments
audio_test.zip
(2.41 MiB) Downloaded 55 times
User avatar
desertfish
Posts: 1098
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Virtual PCM channels [Prog8]

Post by desertfish »

Bomb The Bass ZSM 8-)
Post Reply