Page 3 of 3

New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Thu Apr 01, 2021 7:21 pm
by rje

So I've been thinking about an API that wraps your code and makes it configurable via the X16's ABI pseudo-registers.

I haven't thought deeply enough about it, so it might be ridiculous/overkill, but here's what I'm thinking of doing:


  • R1a. voice

    R1b. waveform


  • R2 a + b. frequency (16 bits)


  • R3a. pulse width


  • R4a. channel

    R4b. volume


  • (R5a. attack)

    R5b. decay


  • (R6. sustain & release)


Then two API calls:

$9000 (or wherever): SSND - sets up and plays a voice, using all of the pseudo-registers above.

$9003 (or wherever): PLAY - plays a previously set-up voice, using the first three pseudo-registers.

Obviously it's not designed for playing music.  But maybe it would be useful for configuring the voices initially (generally useful for sound effects in other words).  I know you've addressed the music angle in your other library on your blog.

 

Presumably, the API calls would copy the register values into memory.  The voice, waveform, frequency, pulse width, channel, and volume would go into VERA. ADSR would take up 64 bytes (4 bytes per voice) in somewhere convenient in main RAM (maybe $200?).

 


New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Fri Apr 02, 2021 5:36 am
by ZeroByte

Here's a demo of YM music I did in BASIC a while back.  STARDUST.PRG

The logic for the bass line is kind of convoluted - I just put all possible notes in different voices and just play the different notes in the progression on the different voices. That freed the music data up to be dead simple. It's raw OCT+KC register values ($28+voice#), or it's $FF which is a rest. There's something in the code about $FE but I didn't use it, and now I don't know what the point of those was.

The demo plays the "stardust" song from Lazy Jones (C64 game) - also known by sports fans as "Zombie Nation" or "that o O OH OHH OH!" song they play before kickoffs. Zombie Nation (a techno musician) made that version and called it something like kernelkraft9000...

If I were to re-think this for "general use" I would re-order the bytes written to the voices in the "load patches" subroutine to loop through the registers in order of YM address, and not group them by Operator - that way, a patch could be easily stored as 26 bytes to be written out to: $20, $38, $40, $48, $50, $58, $60, $68 .. etc ... $F0, $F8  (add channel number to each of these reg values to use the patch for whichver voice, so voice 4 would be $24, $3C, $44, $4C, etc)

I'm thinking about making an instrument browser in basic because I have a giant truckload of OPM instrument packs from SEGA games - I'd want to de-dup them and somehow name them in a sane fashion, but then have an X16 program that would just loop some simple sequences on a voice and let you select them one by one and listen to them. Deflemask --sux-- for browsing instruments, ESPECIALLY from VOPM files.


Re: New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Thu Jun 22, 2023 11:15 am
by mobluse
I cannot get EFFECTS.PRG or EFFECTSHI.PRG to work in x16emu R43, but they work in R42. In R43 they crash the program and they hang or you get into the debugger/monitor. At least EFFECTS.PRG doesn't work in the web emulator R43. I use EFFECTS.PRG in Aritm. You can use Aritm if you remove the lines with SYS: 2405 and 3620. I plan to replace EFFECTS.PRG with PSG sound effects in BASIC. It would be interesting to know why EFFECTS.PRG crashes in R43.

Aritm is here and you can try it in the web emulator, but it crashes when you GOTO 3620 i.e. when you make an error, because then it should play the explode sound:
viewtopic.php?p=26672#p26672

I did also test it with EFFECTS.PRG downloaded from here, with the same result:
https://github.com/Dooshco/X16/blob/master/EFFECTS.PRG

Re: New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Fri Jun 23, 2023 8:39 pm
by DusanStrakl
mobluse wrote: Thu Jun 22, 2023 11:15 am I cannot get EFFECTS.PRG or EFFECTSHI.PRG to work in x16emu R43, but they work in R42. In R43 they crash the program and they hang or you get into the debugger/monitor. At least EFFECTS.PRG doesn't work in the web emulator R43. I use EFFECTS.PRG in Aritm. You can use Aritm if you remove the lines with SYS: 2405 and 3620. I plan to replace EFFECTS.PRG with PSG sound effects in BASIC. It would be interesting to know why EFFECTS.PRG crashes in R43.

Aritm is here and you can try it in the web emulator, but it crashes when you GOTO 3620 i.e. when you make an error, because then it should play the explode sound:
viewtopic.php?p=26672#p26672

I did also test it with EFFECTS.PRG downloaded from here, with the same result:
https://github.com/Dooshco/X16/blob/master/EFFECTS.PRG
Hi mobluse,

I just tried it on Emulator with R43 rom and it works fine for me.

Make sure you downloaded it correctly (it should have 361 bytes) and then try to load it outside of any program to eliminate any kind of external interference first by:

LOAD"EFFECT.PRG",8,0,$400

SYS$400
SYS$403
SYS$406
SYS$409

should give you PING, SHOOT, ZAP and EXPLODE effects (I modeled that after the named BASIC commands on ORIC).

Re: New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Fri Jun 23, 2023 11:06 pm
by mobluse
This worked, except EFFECTS.PRG is misspelled.

According to the instructions one should load it using:

Code: Select all

IF PEEK($400)=0 THEN LOAD”EFFECTS.PRG”,8,1,$0400
? PEEK($400) prints different numbers each time you start now, and therefore it doesn't get loaded. R43 randomizes RAM and you assume it's zeroed from start.

The R43 emulator breaks existing programs based on the assumption that RAM is zeroed from start. You should change the instructions for loading to e.g.

Code: Select all

IF PEEK($400)<>76 THEN LOAD”EFFECTS.PRG”,8,1,$0400
My old program always works if you start the emulator using:

Code: Select all

./x16emu -zeroram -prg ARITM-X16.PRG
but that is not how the web emulator starts. All programs that load EFFECTS.PRG according to the instructions will be broken by R43.

Re: New community dev tool uploaded: Simplest Sound Effects Library for BASIC programs

Posted: Sat Jun 24, 2023 2:04 am
by DusanStrakl
mobluse wrote: Fri Jun 23, 2023 11:06 pm This worked, except EFFECTS.PRG is misspelled.

According to the instructions one should load it using:

Code: Select all

IF PEEK($400)=0 THEN LOAD”EFFECTS.PRG”,8,1,$0400
? PEEK($400) prints different numbers each time you start now, and therefore it doesn't get loaded. R43 randomizes RAM and you assume it's zeroed from start.

The R43 emulator breaks existing programs based on the assumption that RAM is zeroed from start. You should change the instructions for loading to e.g.

Code: Select all

IF PEEK($400)<>76 THEN LOAD”EFFECTS.PRG”,8,1,$0400
My old program always works if you start the emulator using:

Code: Select all

./x16emu -zeroram -prg ARITM-X16.PRG
but that is not how the web emulator starts. All programs that load EFFECTS.PRG according to the instructions will be broken by R43.
Yes you are correct. I had the same problem when testing Crazy Boulders on R43 and had to change it to:

IF PEEK($315)<>4 THEN LOAD"EFFECTS.PRG",8,1,$0400

Above works because the library changes the default IRQ pointer and after first use the high byte becomes $04. This should work unless the IRQ pointer location gets changed in future versions of ROM.