bit_fx does not produce asynchronous sounds :-(

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Fabrizio
Member
Posts: 86
Joined: Tue Jul 11, 2017 9:28 pm

bit_fx does not produce asynchronous sounds :-(

Post by Fabrizio »

Hi

bit_fx is cool but it seems to me that it is not very usable for in-game sounds because it blocks the CPU.
Maybe I am not using it correctly.
Is there a way to have these sound work asynchonously?

I thought I could use them for my game as I have done for other targets (e.g., Oric 1/Atmos).

If this is not yet possible, it would be cool to have asynchronous sound effects in the future.

Fabrizio
Timmy
Well known member
Posts: 186
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

The Spectrum (at least, the normal model) does not have asynchronous sounds. Only Synchronous sounds are available. Unless you give every player a free hardware sound card, of course. ^_^ There is no way to make sound asynchronously, not now and not in the future.

It's possible to emulate it using synchronous sounds, and the game will lose about 75% of its game speed if you* do that, and you will have to use assembly.

Doesn't mean many games have sound effects in game, but 99% of that is synchronous mode.

For you, I'd say: It's probably easier to just make a silent game if all you want is portability.

(I just ported a Spectrum game to MSX and I had to rewrite the whole sound system too, but for me that's normal.)

P.S. If you seriously expect that all the machines you port your games on must have asynchronous sounds, then you better port to 16 bit machines instead. ^_^
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

beepfx is another one to check out:
https://github.com/z88dk/z88dk/blob/mas ... S/beepfx.c

As Timmy says, the beeper is driven by the cpu so it's not possible to generate sound independently of the cpu. Usually the sound effects are brief so that playing them doesn't interfere with gameplay.

If you want independent audio, you have to target the 128k spectrum model which has the AY chip. Or you could assume the 128k is there, playing effects so that 128k spectrums would hear them and 48ks would not. But it's more normal to play brief sound effects via beeper.
Timmy
Well known member
Posts: 186
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Alvin, I do wonder if the 128k effects could be considered as "easy to code". I was converting the beeps in the 48k version to the AY on the MSX, and I find the only thing I can do there is to play the AY, wait a frame or two, and then stop the AY.

It's less "fire and forget" than I would have thought (if I don't want to use the interrupt that is), or am I missing something obvious?

(sorry for being a bit offtopic)
Fabrizio
Member
Posts: 86
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

Thanks guys!

@Timmy, I know that the beeper is CPU driven but I was hoping to get an interrupt-driven asynchronous solution.
I guess it is possible because I found something like that for the Oric 1/Atmos but maybe too complex and not worthwhile.

I will use short sounds in order not to block the game too long.
Timmy
Well known member
Posts: 186
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Well, the Oric 1/Atmos has a sound chip called 8912 (or AY, or PSG, depends on who talks about it), which most Spectrums don't have. It's easy enough to have an interrupt solution for that chip on that computer, yes.

Unfortunately 1) the regular Spectrum doesn't have that chip, and 2) setting up an interrupt on the Spectrum is a lot of complex work and costs a lot of memory, and 3) even with an interrupt solution you'd lose a lot of processor time because you'd have to give the CPU a lot of time to drive the beeper.

Therefore it's not recommended.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Timmy wrote:Alvin, I do wonder if the 128k effects could be considered as "easy to code". I was converting the beeps in the 48k version to the AY on the MSX, and I find the only thing I can do there is to play the AY, wait a frame or two, and then stop the AY.

It's less "fire and forget" than I would have thought (if I don't want to use the interrupt that is), or am I missing something obvious?
There is AYfx which is a sound effects player for the AY.

Video: https://www.youtube.com/watch?v=XI6aW2QSUXw
Package: https://shiru.untergrund.net/files/ayfxedit.zip

It's a similar idea to beepfx which is written by the same author.

AYfx has not been incorporated into z88dk yet but you should be able to include it without too much hassle.

There's also WYZ player which does AY music and apparently sound effects but I don't know too much about it yet.
https://github.com/z88dk/z88dk/issues/184

Setting up an interrupt routine in z88dk is fairly easy; you just have to make sure you've set aside memory for the interrupt table and jump. See the setupint function in:
https://github.com/z88dk/z88dk/blob/mas ... /src/int.c
Fabrizio
Member
Posts: 86
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

Thanks a lot guys!
My (not so) little game is starting to look and sound good in its Spectrum version.

For the moment the 128K sound effects are not a high priority. I need short enough sound effects for my game.

So far I have only managed to get the Spectrum target to work decently but I still need to improve the sound and the animations.

I hope I will make similar progress on the ZX81, CPC, MSX and VG 5000 targets!
Hopefully some of the other targets have some sound support (maybe the MSX).
Timmy
Well known member
Posts: 186
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

@Alvin, thanks for the info.

I might write my own, too.
Fabrizio
Member
Posts: 86
Joined: Tue Jul 11, 2017 9:28 pm

Post by Fabrizio »

If I use bit_fx, I get reproducible crashes in my game at certain places.
zcc +zx -startup=1 -clib=sdcc_iy -vn -DSPECTRUM_32COL -D__SPECTRUM__ -create-app -o ...

In my code:
...
CLEAR_SCREEN();
sleep(1);
PING_SOUND(); /*= bit_fx(bitfx_19); */
printExtraLife();
sleep(1);
++lives;
...

Remark 1: No crashes if bit_fx is avoided (remove PING_SOUND above solves the crashes)

Remark 2: No crashes in the rest of the code with neither of the compilers in Z88DK nor CC65

Remark 3: My game is no longer using malloc. The crash is independent because it occurs even in the version of my game where I still used malloc.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Post Reply