Page 5 of 7

Kernal & BASIC sound API for the ROM - ideas?

Posted: Mon Dec 19, 2022 7:49 pm
by ZeroByte

BASIC and PCM aren't a good match for each other.


  1. PCM takes up gobs of space... would consume large swaths of ROM real-estate, and would also be crappy (of necessity).


  2. PCM requires lots of shepherding by the CPU, which BASIC is not really suited to doing, except in cases where


    1. the entire sample fits into the FIFO and can thus be just dumped in and ignored


    2. The BASIC command to play a PCM clip larger than 4k takes hold of the program until the entire clip plays.




Also, remember that these extensions to BASIC aren't really going to be super useful as background music player functionality. BASIC really doesn't do that. You really need to have some kind of IRQ-driven code that is loaded somewhere in memory and sent commands from BASIC. I've written a very simplified interface to the Zsound music player that does this. It's mostly a proof-of-concept / demo of how to do such a thing with Zsound. It doesn't do anything that's required of such a thing to be truly viable, such as modify MEMTOP - so doing a lot in BASIC with the existing module would actually overwrite the code with BASIC variables at some point.

Thus, having a "drum kit" in ROM is really not going to be the useful thing that it would seem to be.

BASIC is ultimately a sort of "cradle" where programming is more easily picked up from scratch, but then you quickly outgrow it, unless you just wanna show off by doing things in BASIC that others thought impossible, or else the task at hand is really not depending much on performance or timing, so who cares what it's written in? (record album organizer, anyone?)



The objective here is to make playing little ditties, and audible prompts into something much more immediately accessible for novices, not to be a real sound API.

 


Kernal & BASIC sound API for the ROM - ideas?

Posted: Mon Dec 19, 2022 7:53 pm
by ZeroByte

There have already been a couple of lightweight sound engines designed for BASIC extension posted here on the site, come to think of it...


Kernal & BASIC sound API for the ROM - ideas?

Posted: Mon Dec 19, 2022 10:42 pm
by neutrino

How large is the X16 audio FIFO ? is it VERA doing the sample shuffling directly to the D/A ?

 


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 12:17 am
by TomXP411


On 12/19/2022 at 2:42 PM, neutrino said:




How large is the X16 audio FIFO ? is it VERA doing the sample shuffling directly to the D/A ?



From the manual: "High quality PCM audio playback from an 4kB FIFO buffer featuring up to 48kHz 16-bit stereo sound."

Since you can VLOAD the data directly into VERA, that's probably as much support as you can expect from BASIC in support of PCM audio. 

 


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 3:58 am
by neutrino

So with VLOAD and some.. VPLAY? PCM support in Basic should be doable?

 


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 4:43 am
by Jestin

We've started prototyping @ZeroByte's proposed kernal routines and BASIC statements for FM sound, and here's a quick demo of early versions of `FMINST` and `FMNOTE`:

https://youtu.be/iVPJGHNNFL8

These two statements alone would get us a Commander X16 where new users could start making sounds and music with fairly low effort.  This is the sort of example that can go at the beginning of the user guide chapter on sound.


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 5:51 am
by BruceMcF

Excellent.

One thing about FM chips is that, even with consumer keyboards based on FM chips, even for those people who went beyond using predefined instrument patches, the first steps were often putting in a patch that someone else had found created a cool sounding instrument. The connection between the various settings and the resulting sound can be a lot less easily understood than with a PSG style chip.


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 1:27 pm
by neutrino

@Jestin Sounds like some instruments in passages of Jean-Michel Jarre ?

Seems promising.

Btw, What are the options for connecting a MIDI keyboard to the X16 ?

 


Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 3:43 pm
by Edmond D


On 12/19/2022 at 8:43 PM, Jestin said:




We've started prototyping @ZeroByte's proposed kernal routines and BASIC statements for FM sound, and here's a quick demo of early versions of `FMINST` and `FMNOTE`:



https://youtu.be/iVPJGHNNFL8



These two statements alone would get us a Commander X16 where new users could start making sounds and music with fairly low effort. 



Thanks for the demo of the prototypes. The two BASIC commands give hope to both new users and to those who are severely musically challenged (like myself.)

I'll never be the next Mozart or Jarre, but if implemented I have a fighting chance of getting some sound in my X16 code.




Kernal & BASIC sound API for the ROM - ideas?

Posted: Tue Dec 20, 2022 6:23 pm
by Ed Minchau


On 12/19/2022 at 5:17 PM, TomXP411 said:




Since you can VLOAD the data directly into VERA, that's probably as much support as you can expect from BASIC in support of PCM audio. 



 



I don't think you can do that. Sure, you can VLOAD into VRAM,  but PCM audio has its own register. Right now, best we can do is load into RAM and then push one byte at a time into the PCMAudio register. 

For my video demos I've been breaking up the audio files into separate 1/10th of a second clips, about 2574 bytes each (can't recall the exact numbers off the top of my head). That's more than enough time for a snare, kick, or high hat (or tom, probably not enough time for a cymbal).

For about 10kb of ROM we could have samples of various drum sounds. The problem then becomes combining two or more PCM sounds that happen at the same time. Perhaps an 8 bit sample could be enough for various drum sounds, to make the necessary math faster.