1bit sound library extended

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

1bit sound library extended

Post by stefano »

I recently sorted out the bit-banging sound library for z88dk, bringing it at the level I intended to reach when I set it up, about 20 years ago :D
Luckily the core skeleton was already present, and Dominic took really care of it so the task of extending it to all the targets is even easier than in the past !

The news are related to a new white noise generator, a bit_play variant (called synth_play) able to do phase shifting effects, a bigger sound effect library and an interesting number of fixes and improvements, some specific for the ZX81 ;)
( also the EACA EG2000 and the Commodore 128 were fixed, but probably nobody in this forum will care very much :D )

The poor little ZX81 can't do miracles, but it has been cleaned quite a lot.
Few more bugs were removed to fix the Commodore 128 and the EACA EG2000.

sndtest.c could be a nice one to try (and edit.. there are more examples buried in the comments, e.g. a sequence of bit_frequency() calls, which will produce the exact tones of the chromatic scale, an helicopter effect based on the sin() function, etc).

Just wait tomorrow to get an updated nightly build, or get the sources right now from github.

The ZX80 and ZX81 users to hear it on EightyOne must press F4. Be aware that the ZX81 is built around just A SINGLE BIT OUTPUT, the noise is normal, and.. yes, on the small zeddies also the garbled video is normal :D
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

Yet another extension, a pattern driven buzzer.
buzz_play() is good for bass parts. Should be useful to create interesting sound effects as well, and useful for C driven effects.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

Simple way to get a custom sound:
patch_beep(10000,20,"BUZZZZZZ!!!!!!!!!");


..the text will be "played" as a repeated sound pattern ;)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

Sound fx comparison:

for (p=10;p<150;p++)
bit_beep(p,p);

for (p=10;p<150;p++)
patch_beep(p,p,"BUZZ");

.."BUZZZZZZ!!!!!!!!!" will play differently ;)

For byte encoded patterns change "BUZZ" to "\x5e\x5f", mind the zero termination in case you wish to edit the sound pattern directly with your code.

White noise generator:

for (p=5;p<40;p++) {
bit_noise(p,p);
}


Combining the bit banging engines:

for (p=1;p<80;p++) {
bit_noise(5,10000-p*30);
patch_beep(p*4,100-p,"0x5E");
}

for (p=1;p<60;p++) {
bit_noise(p,p);
patch_beep(p*4,100-p,"0x5E");
}


Altering the sound pattern on the fly:

int p;
char buzz[]="x\0";

for (p=1;p<99;p++) {
buzz[0]=rand();
patch_beep(p*4,100-p,buzz);
}
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

new in sound.h:


/* Sound patches for buzzer_play. */
/* Some of them can be long and should be put in a static variable */
#define BUZZ_BASS "\x01\xF0"
#define BUZZ_BASS2 "\x0F\x80"
#define BUZZ_BASS3 "\x3F\x04"
#define BUZZ_JAMBASS "\xFF\x80"
#define BUZZ_TREMBASS "\x0F\x1E\x0F\x80"
#define BUZZ_LOW "\x5C\x5C"
#define BUZZ_MID "\xCF"
#define BUZZ_MID2 "\x02"
#define BUZZ_HIGH "\x22"
#define BUZZ_RESONATE "\x22\x22"
#define BUZZ_RESONATE2 "\xAA\xBA"

/* Example on how to 'SQUELCH' the sound tail in complex sound patches:
// wah wah buzzer
char wahwah_buzzer[]={0xcF,0xcF,0xcF,0xcF,0xcF,0xcF,0xcF,0xcF,0xcF,0x0F,0x0F,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0};
// buzzer hit
char buzzer_hit[]={0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,2,2,2,2,2,2,2,2,2,0xcF,0xcF,0xcF,0xcF,0x5C,0x5C,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0};
*/
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

New function available, playzb4() reproduces a 4 bit encoded wave data block, the data rate is around 8khz (4 Kb per second).
The best results are achieved with the Commodore 128 and the Bondwell 12/24 targets, nevertheless it is surprisingly nice also on a 3.5 mhz CPU banging a bit pattern on a single wire.
I left an optional source file in the 'games' folder. It is slightly less accurate but 130 bytes smaller.
You can check the result yourself on your favourite target, the demo file is in examples/sound/bit4.c
derekfountain
Member
Posts: 121
Joined: Mon Mar 26, 2018 1:49 pm

Re: 1bit sound library extended

Post by derekfountain »

I got it to build me a Spectrum version with this:

Code: Select all

zcc +zx -vn -compiler sdcc -startup=31 bit4.c -o bit4 -create-app
"dur dur dee dut dee dur!"

Mind you, 8KB... :)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

Lol , now I discovered there are no tools to easily get that audio format, but some ancient software from Covox and some obscure stuff from the Commodore world.
I've been tuning that player more times today, now we have 2 options with a difference of 130 bytes in size, the smaller being totally ROMable and with a slightly worse sound.
A very small improvement on the ROMable version can be achieved by unrolling the loop, but those three options together wouldn't have had much sense.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

I think that very short samples could be used in the games. The more accurate routine takes a little bit of time in pre-masking the patterns, I wonder if that delay is visible, in my tests doesn't seem so.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

I altered the demonstration program splitting the samples to check how long the sample preparation takes.
I'd say it is not a problem at all, and as a bonus result now the new version plays a slightly longer tune in less than 8K.
fraespre
Member
Posts: 56
Joined: Mon Aug 19, 2019 8:08 pm

Re: 1bit sound library extended

Post by fraespre »

Hi,

When I try to compile this examples using this command:
zcc +zx -v -clib=sdcc_iy -SO3 clicktest.c -o clicktest -create-app

I find strange errors like:

Code: Select all

C:\mio\soft\dev\z80\wrks\zxspectrum\zx_tap\sound\clicktest.c:15: warning 112: function 'patch_beep' implicit declaration
C:\mio\soft\dev\z80\wrks\zxspectrum\zx_tap\sound\clicktest.c:30: warning 112: function 'bit_noise' implicit declaration
C:\mio\soft\dev\z80\wrks\zxspectrum\zx_tap\sound\clicktest.c:15: error 101: too many parameters
C:\mio\soft\dev\z80\wrks\zxspectrum\zx_tap\sound\clicktest.c:30: error 101: too many parameters
Why are these instructions not available in sdcc_iy ?
or am I doing something wrong ?

Thanks in advance,
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

you're right, atm I put it on the classic lib side only
fraespre
Member
Posts: 56
Joined: Mon Aug 19, 2019 8:08 pm

Re: 1bit sound library extended

Post by fraespre »

I can see the unique instruction of this style that already exists in the new library is "bit_synth", but it's quite different to the others (noise and patch_beeper).

/* 1 BIT SYNTH - Polyphony and multitimbric effects */
bit_synth(int duration, int frequency1, int frequency2, int frequency3, int frequency4)

/* "period": the higher value, the lower the simulated white noise frequency cutoff ! */
bit_noise(int duration, int period)
/* "period": the higher value, the lower tone ! pattern: the "on/off" pattern defining the sound patch, zero terminated */
patch_beep(int duration, int period, void *pattern)

Patch_beep seems an evolution of th bit_noise. I guess that you can do the same but easier.
However bit_synth is oriented to polyhony music instead noise generation.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

There should be also a "bit_buzz" thing.. and few bit_fx() added.
Alvin put his own effort on evolving the same library on the newlib, surely they need to be merged.
examples/sndtest.c should now show how all this new stuff works
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: 1bit sound library extended

Post by stefano »

functions improved, check bit4.c on your favourite target.
Post Reply