CPCWiki forum

General Category => Emulators => Topic started by: cpcitor on 22:21, 03 November 21

Title: Sound emulation survey
Post by: cpcitor on 22:21, 03 November 21
Hi! This is a survey to gather some information about behaviors of emulators with regard to sound.

Can you run the BASIC commands below on real CPCs and emulators and tell what you hear?
It's even better if you can post captures of the output.

The first is only to sanity check your setup and make sure you hear a 440Hz basic tone.
The second is the one I'm interested in.

sound 2,284,50,15 : sound 2,6,50,15

Here are my samples:

* cpcec or cpcec-plus (Linux): 1 second 440Hz tone, then one second of a different, higher pitch, tone. Attached sound_2_284_50_15_sound_2_6_50_15_cpcec.wav.bin
* caprice32 (Linux): 1 second 440Hz tone, then one second of a different, higher pitch, tone. But different!
* floooh's chips test of the tiny8bits emulator libraries:  1 second 440Hz tone, then one second of a different, higher pitch, tone. But different again! (You can try it live on https://floooh.github.io/tiny8bit/cpc.html?type=cpc464 )
* real CPC... I let you try this one.

You might be wondering why I'm asking this.

If you think you can guess why I'm asking this, your guess is welcome.

Captures from emulators and real CPCs are the most welcome of all.

It's best with attached samples. Since the forum rejects wav files, simply rename to .wav.bin and it passed.
Title: Re: Sound emulation survey
Post by: roudoudou on 22:37, 03 November 21
the crappy high pitch sound is due to aliasing/rounded index for replay

i asked Megachur to let his emulator run at higher replay rate (up to 192KHz) and it solve easily most the high frequencies replay (still not perfect but really better)
a solution for high frequencies replay at 44Khz or 48Khz may be to use sinus instead of squares and let shanon do the rest
Title: Re: Sound emulation survey
Post by: cpcitor on 12:57, 04 November 21
Quote from: roudoudou on 22:37, 03 November 21
the crappy high pitch sound is due to aliasing/rounded index for replay

i asked Megachur to let his emulator run at higher replay rate (up to 192KHz) and it solve easily most the high frequencies replay (still not perfect but really better)
a solution for high frequencies replay at 44Khz or 48Khz may be to use sinus instead of squares and let shanon do the rest

You're right, this is aliasing.

Still, that's not all.

Shannon does not say to replace the square with a sine, and there's no need to deviate from the chip behavior like this.

Is there any emulator out there that has a different result?
Title: Re: Sound emulation survey
Post by: eto on 14:42, 04 November 21
Quote from: cpcitor on 22:21, 03 November 21You might be wondering why I'm asking this.

Indeed - and knowing it might make help to motivate people to attach cables and record it ;-)
Title: Re: Sound emulation survey
Post by: roudoudou on 15:40, 04 November 21
Quote from: cpcitor on 12:57, 04 November 21
Shannon does not say to replace the square with a sine, and there's no need to deviate from the chip behavior like this.
I never said that  :o
What i mean is using a sinus will keep the high frequencies clean. It's impossible with a square signal and a restitution frequency non multiple of the generator one

Moreover, the AY high frequencies looks like sinus signal because it can't do a clean square so fast  ;D

Title: Re: Sound emulation survey
Post by: cpcitor on 16:27, 04 November 21
Reason the the survey

Quote from: eto on 14:42, 04 November 21
Indeed - and knowing it might make help to motivate people to attach cables and record it ;-)

Okay, @eto (https://www.cpcwiki.eu/forum/index.php?action=profile;u=3625), thanks for asking. I'm considering some advanced signal processing tricks to play unusual audio on the CPC.

For an introduction of the neighboring concept, see https://en.wikipedia.org/wiki/Noise_shaping . In plain English, sending specifically crafted signals at high speed can overcome the hardware limitations in some sense.  For a crazy example not in audio but in the radio frequency range, see https://bellard.org/dvbt/ . This one is out of league, anyway.

To come back to CPC level: it's about using the phenomenon alluded to by roudoudou to our advantage: very high frequency output from the AY chip is somehow dampened.

My firsts experiments suggested that (some? nearly all?) emulators will not emulate that properly.

It would feel somehow strange to make some high quality sound output that blows everyone's mind when plyaing on a real CPC, yet happen to sound like crap on nearly all emulators.  :doh:

Hence the survey.   :)




Please try this on your emulator

I attached a screenshot of an updated listing, will give much more interesting results.

[attach=1,msg208863]

And results on cpcec, caprice32, chips are attached:
[attach=2,msg208863]
[attach=4,msg208863]
[attach=5,msg208863]

Please run the listing on your emulators, record the output and post it.

For a real CPC, recording with any device (e.g. smartphone) and sending a MP4 etc will be enough.

How to record a program with Audacity

Linux users with pulseaudio: run audacity, enable monitoring, run pavucontrol and in "Recording" tab, set ALSA plug-in[audacity]: ALSA Capture from "Monitor of [name of your sound card]".

[attach=3,msg208863]

Windows users see: https://manual.audacityteam.org/man/tutorial_recording_computer_playback_on_windows.html

Title: Re: Sound emulation survey
Post by: eto on 17:24, 04 November 21
Sounds interesting. I can provide a few samples if there is no hurry. Probably over the weekend. I have a few real machines (6128 plus, 6128, 464) where I can sample the output.
Title: Re: Sound emulation survey
Post by: andycadley on 18:16, 04 November 21
If it works on real hard, you should totally do it even if it sounds like crap on an emulator.


Stuff like this is what pushes the envelope of emulator development. Such as Chromatrons Attack on the Speccy, which relies on weird quirks in the PAL signal to generate an image. Initially didn't look right on emulators at all, but a few of the more advanced ones can now pull it off and, as a result, can do a better job of rendering all software.
Title: Re: Sound emulation survey
Post by: Aeliss on 18:37, 04 November 21
Here a sample on Arnold https://www.cjoint.com/c/KKerLtQRdga
Some sound part are totaly missing
Title: Re: Sound emulation survey
Post by: cpcitor on 18:58, 04 November 21
Quote from: Aeliss on 18:37, 04 November 21
Here a sample on Arnold https://www.cjoint.com/c/KKerLtQRdga
Some sound part are totaly missing

Excellent! Thanks! This is the best output so far.

Is it Arnold Emu by Kevin Thacker?
Which version of Arnold is it?
Title: Re: Sound emulation survey
Post by: cpcitor on 19:04, 04 November 21
Quote from: andycadley on 18:16, 04 November 21
If it works on real hard, you should totally do it even if it sounds like crap on an emulator.

Thanks! You're right.

It was written about the demo 8088mph for the original IBM PC of 1981 "Yes, this demo breaks all emulators"
https://www.youtube.com/watch?v=gdb3AQ14iVc

Quote from: andycadley on 18:16, 04 November 21
Stuff like this is what pushes the envelope of emulator development. Such as Chromatrons Attack on the Speccy, which relies on weird quirks in the PAL signal to generate an image. Initially didn't look right on emulators at all, but a few of the more advanced ones can now pull it off and, as a result, can do a better job of rendering all software.

Ah, yes, the trick of using composite output, like it was done on the PC https://int10h.org/blog/2015/04/cga-in-1024-colors-new-mode-illustrated/ and so often on the Apple 2, that Apple 2 computers fitted with a RGB output emulated it.

Thanks, I did not know it could be done on the Spectrum, too.
Title: Spectrum images (Re: Sound emulation survey)
Post by: cpcitor on 12:58, 05 November 21
Here are spectrum images of the emulators tested so far.

In theory one should see a hyperbolic-step shape of the first harmonic and second harmonic and nothing else.

Lots of orange bars (or worse, yellow) in the 0-1000Hz range (bottom of chart) means you hear false tones, at various heights. All 4 have it except Arnold.

Chips: high density of red all over. Plus some vertical artifacts at ~3.5 seconds, ~5.6s, ~7.9s, ~8.05s, ~9.8s.
[attach=1,msg208887]

Cpcec: red all over. Cheating at period 1-5 by outputting nothing. At 5 there should be a yellow line at 12500Hz.
[attach=2,msg208887]

Caprice32: blue and red "spots" all over. Better than cpcec. Cheating at period 1-4 by outputting nothing. The yellow curves are at least visually standing out somehow.
[attach=3,msg208887]

Arnold: some noise, but the cleanest spectrum so far. You can see the hyperbolic shape of the first harmonic (yellow curve) and second harmonic (orange curve on top right). Spurious frequencies are much weaker and only at high frequency (2.5+ kHz).
[attach=4,msg208887]

Open to other measurements, thanks!
Title: Re: Sound emulation survey
Post by: roudoudou on 15:18, 05 November 21
Here is captures of CPCEmu_Power Linux
http://www.roudoudou.com/export/cpc/temp/cpcemu_power_44Khz.wav (emulator and recording @44KHz)

http://www.roudoudou.com/export/cpc/temp/cpcemu_power_192_to_44Khz.wav (emulator @192Khz output + record @44KHz)
http://www.roudoudou.com/export/cpc/temp/cpcemu_power_192Khz.wav (emulator and recording @192KHz)
Title: Re: Sound emulation survey
Post by: eto on 15:21, 05 November 21
Schneider 6128 - early and late model
Amstrad 6128 plus
RetroVm - 2.0 beta 1 r7
https://www.dropbox.com/s/c094rb9yuquznex/soundtest.zip (https://www.dropbox.com/s/c094rb9yuquznex/soundtest.zip)
Title: Re: Spectrum images (Re: Sound emulation survey)
Post by: Bryce on 16:12, 05 November 21
Quote from: cpcitor on 12:58, 05 November 21
Arnold: some noise, but the cleanest spectrum so far. You can see the hyperbolic shape of the first harmonic (yellow curve) and second harmonic (orange curve on top right). Spurious frequencies are much weaker and only at high frequency (2.5+ kHz).
 

Open to other measurements, thanks!

Just for correctness. The orange curve is the third harmonic not the second: 1st = Fundamental frequency (f), 2nd harmonic = 2f, 3rd harmonic =3f and so on.

Bryce.
Title: Re: Sound emulation survey
Post by: cpcitor on 23:25, 05 November 21
Quote from: roudoudou on 15:18, 05 November 21
Here is captures of CPCEmu_Power Linux
http://www.roudoudou.com/export/cpc/temp/cpcemu_power_44Khz.wav (emulator and recording @44KHz)

http://www.roudoudou.com/export/cpc/temp/cpcemu_power_192_to_44Khz.wav (emulator @192Khz output + record @44KHz)
http://www.roudoudou.com/export/cpc/temp/cpcemu_power_192Khz.wav (emulator and recording @192KHz)

Can you describe the recording setup a bit better?

Hearing them, I find them between cpcec and caprice32, closer to caprice32. Visually they look closer to cpcec.  :-\

Here are the spectrums (spectra?) in same order:

[attach=1,msg208903]
[attach=2,msg208903]
[attach=3,msg208903]
Title: Re: Sound emulation survey
Post by: cpcitor on 23:30, 05 November 21
Quote from: eto on 15:21, 05 November 21
Schneider 6128 - early and late model
Amstrad 6128 plus
RetroVm - 2.0 beta 1 r7
https://www.dropbox.com/s/c094rb9yuquznex/soundtest.zip (https://www.dropbox.com/s/c094rb9yuquznex/soundtest.zip)

Ah, a real beep from a real, CPC! That's refreshing to hear!
No spurious frequencies, as expected.

Oh, RetroVm is really good!
I reproduced it here, and it performs proper low-pass filtering! Youhoo! Congratulations to authors of RetroVirtualMachine!

Here are the spectrums (spectra?) in same order:

[attach=1]  [attach=2]  [attach=3]  [attach=4]

Quote from: Bryce on 16:12, 05 November 21
Just for correctness. The orange curve is the third harmonic not the second: 1st = Fundamental frequency (f), 2nd harmonic = 2f, 3rd harmonic =3f and so on.

Bryce.


Oh, you're right, I was misusing the terminology.
It's the second non-null in a theoretically perfect square wave, but since it's a 3f it's the third harmonic.
Thanks @Bryce (https://www.cpcwiki.eu/forum/index.php?action=profile;u=225).

Oh, errrm, it was a mistake on purpose. To check if you were listening.  ;)

Title: Re: Sound emulation survey
Post by: roudoudou on 23:39, 05 November 21
Quote from: cpcitor on 23:25, 05 November 21
Can you describe the recording setup a bit better?
Hearing them, I find them between cpcec and caprice32, closer to caprice32. Visually they look closer to cpcec.  :-\
i simply run the emulator and record with arecord (PulseAudio PCM utilisant ALSA)
note that the last WAV is mono and should be cleaner that the second one
(https://i.postimg.cc/gcCgrmCd/kkk192.png)
Title: Re: Sound emulation survey
Post by: BSC on 00:06, 06 November 21
Quote from: cpcitor on 16:27, 04 November 21I'm considering some advanced signal processing tricks to play unusual audio on the CPC.

Great topic, looking forward to hearing your tricks at play. Also thanks for the additional links, I am always happy to learn more about (the endless realms of) digital audio.
Title: Re: Sound emulation survey
Post by: cpcitor on 14:31, 06 November 21
Quote from: BSC on 00:06, 06 November 21
Great topic, looking forward to hearing your tricks at play. Also thanks for the additional links, I am always happy to learn more about (the endless realms of) digital audio.

Don't hold your breath, though. :-)

This is the video that got me inspired in believing that maybe something is possible https://wiki.xiph.org/Videos/Digital_Show_and_Tell (or go straight to the video https://www.xiph.org/video/vid2.shtml ).

A number of obstacles exist between the idea of something and an implementation within the constraints of the CPC.

I don't promise anything. You can pretend there's no hope, to avoid any disappointment.

And if the only gain of this thread is that mainstream emulators "align to the top", that is get a sound much closer to a real CPC sound, it's already worth it. :-)

In the meantime you can enjoy this tune https://www.youtube.com/watch?v=qgjRwBQzJss apparently playing on the YM2149 variant of the chip, on a Atari ST, a chip very similar to our AY8912 ( https://maidavale.org/blog/ay-ym-differences/ ). The CPC probably cannot do exactly this due to slower clocks, but I still think there are some things to explore.


Title: Re: Sound emulation survey
Post by: roudoudou on 09:25, 07 November 21
Quote from: cpcitor on 23:30, 05 November 21
Oh, RetroVm is really good!
I reproduced it here, and it performs proper low-pass filtering! Youhoo! Congratulations to authors of RetroVirtualMachine!
RetroVm has a very bad replay with SID sounds. This may be due to an overall bad emulation, but hey, as we dont know what is inside the emulator... can state about it  ;D
Title: Re: Sound emulation survey
Post by: cpcitor on 00:06, 08 November 21
Quote from: roudoudou on 09:25, 07 November 21
RetroVm has a very bad replay with SID sounds. This may be due to an overall bad emulation, but hey, as we dont know what is inside the emulator... can state about it  ;D

RetroVM can emulate a SID? And even so, this does not affect AY emulation, right?
That said, I agree it's closed source so it's evil  :o.

Anyway, capture from RetroVm and show waveform in e.g. audacity, it shows the Gibbs phenomenon that typically results from low pass filtering.
So, it sounds like low pass filtering, it looks like low pass filtering, and it is exactly what is needed, so ... it would be even better open-sourced. ;-)

[attach=1]

Title: Re: Sound emulation survey
Post by: megachur on 07:38, 08 November 21
Quote from: cpcitor on 14:31, 06 November 21
And if the only gain of this thread is that mainstream emulators "align to the top", that is get a sound much closer to a real CPC sound, it's already worth it. :-)

In the meantime you can enjoy this tune https://www.youtube.com/watch?v=qgjRwBQzJss (https://www.youtube.com/watch?v=qgjRwBQzJss) apparently playing on the YM2149 variant of the chip, on a Atari ST, a chip very similar to our AY8912 ( https://maidavale.org/blog/ay-ym-differences/ (https://maidavale.org/blog/ay-ym-differences/) ). The CPC probably cannot do exactly this due to slower clocks, but I still think there are some things to explore.
Firstly : Yes it's a good idea but what do you show with this analysis ? that some emulators are using filter and others not !? what do you use to record the sound of the real hardware on amstrad cpc !? using stereo cable and a very, very good sound card without filter ?

Secondly : this youtube video have very bad sound... and yes YM2149 (2Mhz) and AY8912-2 (1Mhz) are very similar.
see this source for the real hardware analysis done years before for mame emulator :https://github.com/mamedev/mame/blob/master/src/devices/sound/ay8910.cpp (https://github.com/mamedev/mame/blob/master/src/devices/sound/ay8910.cpp)

The conversion of atari st songs have allready done some year ago.... the first one have been done by Longshot if I remember correctly : see https://www.cpc-power.com/index.php?page=detail&num=7799 (https://www.cpc-power.com/index.php?page=detail&num=7799).
Most of them here : https://www.cpc-power.com/index.php?page=staff&lenom=Transfert%20Atari%20ST (https://www.cpc-power.com/index.php?page=staff&lenom=Transfert%20Atari%20ST)


It's simple : convert the 68000 code to z80 code then divide frequencies to have correct sound on 1Mhz AY !


Title: Re: Sound emulation survey
Post by: roudoudou on 08:02, 08 November 21
Quote from: cpcitor on 00:06, 08 November 21
RetroVM can emulate a SID? And even so, this does not affect AY emulation, right?
That said, I agree it's closed source so it's evil  :o .

Anyway, capture from RetroVm and show waveform in e.g. audacity, it shows the Gibbs phenomenon that typically results from low pass filtering.
So, it sounds like low pass filtering, it looks like low pass filtering, and it is exactly what is needed, so ... it would be even better open-sourced. ;-)


i'm talking about some SID sounds a CPC or a Plus can do* with FAST volume switching. Timing accuracy is more important than if you play a music with a 50Hz player routine. So yes, global emulation may change the sound replay ;)

*Like CRTC3 demo or KillMax demo

Title: Re: Sound emulation survey
Post by: cpcitor on 08:29, 08 November 21
Quote from: roudoudou on 08:02, 08 November 21
i'm talking about some SID sounds a CPC or a Plus can do* with FAST volume switching. Timing accuracy is more important than if you play a music with a 50Hz player routine. So yes, global emulation may change the sound replay ;)

Okay, RetroVm might have nice output smoothing but not respect timings, or compute too many oscillations assuming that AY registers did not change, which is not always true, will go unnoticed in most cases and totally destroy some effects. Is that what you meant?

Quote from: roudoudou on 08:02, 08 November 21
*Like CRTC3 demo or KillMax demo

Nice demos!
Title: Re: Sound emulation survey
Post by: cpcitor on 08:46, 08 November 21
Quote from: megachur on 07:38, 08 November 21
Firstly : Yes it's a good idea but what do you show with this analysis ? that some emulators are using filter and others not !? what do you use to record the sound of the real hardware on amstrad cpc !? using stereo cable and a very, very good sound card without filter ?

The goal in this thread is to find emulator(s) that remain faithful to the original machine even when changing AY registers extremely often.
That said, I just switched to using real CPCs because, well, I believe they behave exactly like real CPCs. No aliasing at all, no extraneous frequencies whatsoever, and I'm pretty certain other real CPCs will perform the same.  ;D

Quote from: megachur on 07:38, 08 November 21
Secondly : this youtube video have very bad sound...

What do you mean? How is it bad?

Quote from: megachur on 07:38, 08 November 21and yes YM2149 (2Mhz) and AY8912-2 (1Mhz) are very similar.
see this source for the real hardware analysis done years before for mame emulator :https://github.com/mamedev/mame/blob/master/src/devices/sound/ay8910.cpp (https://github.com/mamedev/mame/blob/master/src/devices/sound/ay8910.cpp)

Extremely interesting link. I had read that a complete chip analysis was performed years ago, this one states interesting facts. Things like "Careful studies of the chip output prove that the chip counts up from 0 until the counter becomes greater or equal to the period. This is an important difference when the program is rapidly changing the period to modulate the sound. This is worthwhile noting, since the datasheets say, that the chip counts down."

Quote from: megachur on 07:38, 08 November 21
The conversion of atari st songs have allready done some year ago.... the first one have been done by Longshot if I remember correctly : see https://www.cpc-power.com/index.php?page=detail&num=7799 (https://www.cpc-power.com/index.php?page=detail&num=7799).
Most of them here : https://www.cpc-power.com/index.php?page=staff&lenom=Transfert%20Atari%20ST (https://www.cpc-power.com/index.php?page=staff&lenom=Transfert%20Atari%20ST)

It's simple : convert the 68000 code to z80 code then divide frequencies to have correct sound on 1Mhz AY !

Well, if dividing periods does not cause too high approximation (small periods), and if the original player on the ST did not access the registers so fast that the CPC can't keep up. For music the approximation feels like it should be okay. For sampled speech, maybe not so well.
Title: (Re: Sound emulation survey)
Post by: cpcitor on 23:03, 08 November 21
This test:

for p=2 to 25 : sound 2,p,50,15 : next

can easily be overlooked but it is a demanding test. Passing it very well is not obvious. It only tests whether the "misalignment" between PSG frequency (125kHz base oscillator) and audio frequency output (typically 44.1kHz or 48kHz) are well handled. This is a signal processing issue, not an emulation issue.
Title: Re: Sound emulation survey
Post by: zhulien on 17:16, 10 November 21
The sound chip isn't the only way the CPC can make music.  You can also click the tape motor on and off fast on a 464.  I don't know if you can 'control it' but, has anyone tried to control the faint buzzing of the z80 you hear at night when you do certain tasks?


If a beeper on a spectrum can sound like this:   https://www.youtube.com/watch?v=L4LSHnMhFPU


What is the technical reason that 1 sound channel on the AY cannot simulate a spectrum's beeper as per above?


(Interesting technical page about how spectrums can achieve multichannel sound using a beeper
  https://www.gamejournal.it/the-sound-of-1-bit-technical-constraint-as-a-driver-for-musical-creativity-on-the-48k-sinclair-zx-spectrum/?fbclid=IwAR23eyQmlrxH1Th0DB7-hZaeSF0K1qOg7hBpUBeesxgVedXpd51pO_7q_BA )
Title: Re: Sound emulation survey
Post by: megachur on 17:53, 10 November 21
Quote from: cpcitor on 08:46, 08 November 21

What do you mean? How is it bad?

Just hear it on the real Atari ST and you will understand what I mean ! Even some Atari ST emulator feature no right 2Mhz YM emulation...

Also use a good stero audio headphone with correct or more than 20Hz-20KHz if you can hear it ;-) https://www.youtube.com/watch?v=WoPWyXsD81k (https://www.youtube.com/watch?v=WoPWyXsD81k)!
Title: Re: Sound emulation survey
Post by: BSC on 23:06, 10 November 21
Quote from: zhulien on 17:16, 10 November 21What is the technical reason that 1 sound channel on the AY cannot simulate a spectrum's beeper as per above?

I have done some experiments using the envelope generator, they are on soundcloud:

https://soundcloud.com/betasoftcologne/4bit-sweeping-demo

https://soundcloud.com/betasoftcologne/cocio-and-finsprit-6-channel-preview

I think there are a couple of reasons why the sound of the beeper engines can not (easily) be reproduced on a CPC using the AY:

1. Much slower access to the sound chips registers, yielding a lower max replay frequency
2. I believe the beeper, even though it is programmed in a digital way, i.e. only 0 or 1 is possible, does in fact work very much like an analog(ue) device, the hardware geeks here might be able to say if I am wrong or elaborate further, but I think if for example you toggle from 0 to 1, then hold for a very short amount of time before toggling back from 1 to 0, the beeper (which is a tiny speaker that is directly connected to port &fe) will not have fully moved to its maximum displacement, but only a fraction of that, depending on the amount of time 1 was active.

I was planning to make more experiments, like manipulating a single volume register directly instead of going through the envelope generator (that was done purely out of curiosity) or actually using the tape port (port &f5) which might result in more speccy-like, albeit really delicate, sounds.



Title: Re: Sound emulation survey
Post by: cpcitor on 10:22, 11 November 21
Quote from: zhulien on 17:16, 10 November 21
The sound chip isn't the only way the CPC can make music.  You can also click the tape motor on and off fast on a 464.  I don't know if you can 'control it' but, has anyone tried to control the faint buzzing of the z80 you hear at night when you do certain tasks?

A CPC can control the motor or tape output faster than the PSG. Not sure it can even make interesting sounds without damaging hardware long-term.

Quote from: zhulien on 17:16, 10 November 21
If a beeper on a spectrum can sound like this:   https://www.youtube.com/watch?v=L4LSHnMhFPU

Excellent use of the Spectrum hardware!

Quote from: zhulien on 17:16, 10 November 21
What is the technical reason that 1 sound channel on the AY cannot simulate a spectrum's beeper as per above?

You answer later, I answer to that below.

Quote from: zhulien on 17:16, 10 November 21
(Interesting technical page about how spectrums can achieve multichannel sound using a beeper
  https://www.gamejournal.it/the-sound-of-1-bit-technical-constraint-as-a-driver-for-musical-creativity-on-the-48k-sinclair-zx-spectrum )

Interesting article with many references. Thanks for posting.

Quote from: BSC on 23:06, 10 November 21
I think there are a couple of reasons why the sound of the beeper engines can not (easily) be reproduced on a CPC using the AY:

1. Much slower access to the sound chips registers, yielding a lower max replay frequency
2. I believe the beeper, even though it is programmed in a digital way, i.e. only 0 or 1 is possible, does in fact work very much like an analog(ue) device, the hardware geeks here might be able to say if I am wrong or elaborate further, but I think if for example you toggle from 0 to 1, then hold for a very short amount of time before toggling back from 1 to 0, the beeper (which is a tiny speaker that is directly connected to port &fe) will not have fully moved to its maximum displacement, but only a fraction of that, depending on the amount of time 1 was active.

I agree with 1. Also, when an effect requires changing multiple registers, the delay between those can produce unwanted sounds (or even silence) in the meantime. Delay is minuscule for usual music on the CPC, but can limit what effects are possible and the extent of those that remain possible.

Note sure I agree with 2 as an argument. First, is the beeper on the CPC very different from what can be plugged on a spectrum?

Let's admit the speaker will not reach maximum displacement, but so what ?
Let's rephrase.
The speaker provides sound by pushing or pulling air.
Effects of high speed bit flipping put the speaker closer to a not saturated but linear regime, where frequency domain analysis provides hints.
In other words, at high base frequency, the harmonics will get dampened, right.
At which frequency does this happen?
To get a hint, we'd like to guess the range of frequencies the speaker can provide. Easiest is to ask what frequencies are emitted, disregarding if those are harmonics or even the fundamental.
The answer is : above many kHz, as people report hearing sound from the CPC even with periods as small as 5.
This is why those musics on the spectrum sound scratchy, and on the CPC, too.

But all of this does not explain IMHO why the beeper engines can not be easily reproduced on the CPC.

I would rather say: with one bit-banging output, the Spectrum developers had no choice but to explore what happens when varying delays between highs and lows.

The CPC's AY chip can modulate while the Z80 does other work, but with less control (especially no PWM), and got people accustomed to that.

In some sense the CPC has some unexplored potential, yet how that can be combined feels a tough space to explore.

Quote from: BSC on 23:06, 10 November 21
I was planning to make more experiments, like manipulating a single volume register directly instead of going through the envelope generator (that was done purely out of curiosity) or actually using the tape port (port &f5) which might result in more speccy-like, albeit really delicate, sounds.

On a CPC you can control the tape signal output "very" quickly (Z80 OUT takes 'µs or 1/250000s on the CPC). About 5 times quicker than the fastest PSG access.

So, I recently had the idea of a "tape demo". You put a cassette in your CPC464, press "record", run the code, you hear a low volume music while tape records. Then you put the cassette in a regular player and it plays something "remarkable".
(If you're sad enough ;) to own a CPC 6128, you can plug a cable on the DIN and either connect that to you audio amplifier or to a tape recorder.)

Quote from: BSC on 23:06, 10 November 21
I have done some experiments using the envelope generator, they are on soundcloud:

https://soundcloud.com/betasoftcologne/4bit-sweeping-demo

https://soundcloud.com/betasoftcologne/cocio-and-finsprit-6-channel-preview

Interesting. Could you share what parameters are set and are changing in each section?
I can't even say if the sequence of sections repeat periodically or not.
Title: Re: Sound emulation survey
Post by: cpcitor on 10:29, 11 November 21
Quote from: megachur on 17:53, 10 November 21
Just hear it on the real Atari ST and you will understand what I mean ! Even some Atari ST emulator feature no right 2Mhz YM emulation...

I have no ST to try that.

I believe you gladly, about the limited emulation.

Best if you can be more specific, or provide a recording of the same tune.
Title: Re: Sound emulation survey
Post by: cpcitor on 12:56, 11 November 21
You will find below audio and spectrum recorded from a real CPC6128 by putting a smartphone microphone in front of the CPC speaker.

From a signal processing perspective it's bad to record like this because the signal is "dirty". In this case it allows to get hints about the speaker bandwidth.

I took care of recording in uncompressed wav format. My first try was with an app that compresses to m4a, and this resulted in subtle yet interesting 'holes' in the spectrum (this isn't related to retrocomputing, but I may share if some of you are interested).

To be fair, consumer grade audio recording equipment might not be a good idea for subtle sound analysis, so one should really watch out for strange things.

Analysis of diagram

Overall there is a pattern of continuous horizontal lines.
You can see that it continue after 13.27s, when no sound is emitted and the AY chip is at rest. Because it is continues the same all the time, it is not a consequence of the changing signals and so not aliasing of those frequencies. Since I was in a relatively quiet room but still in a city, it represents the sum of the city background noise plus the continuous background noise a CPC speaker emits.
I guess that the apparently changing strength of it reflects the automatic gain control of the sound recording.
Let's ignore it.

Let's jump to the sound at 12.5s, period 4095. It should have a visible fundamental at 125000/4095 = 30Hz, yet spectrum actually peaks at around 880Hz, and fades to the low frequencies. Nearly nothing below ~100Hz. This shows that the speaker does not let bass frequencies through. This could be analyzed further to establish a Bode diagram of the CPC speaker. Has someone done this already? @Targhan (https://www.cpcwiki.eu/forum/index.php?action=profile;u=110) how does the "Emulate CPC internal speaker" option in Arkos Tracker 2 work?

So, what else do we see? Fundamental frequency, very loud (lowest curve). Third harmonics as expected (third curve), and fifth (top right lonely bar), but also second and fourth harmonics (second and fourth curves).

No specific frequency at periods 2, 3 and 4.
Things go on smoothly until period 12 (6.2 seconds and before).

Something strange at period 13: there seem to be energy at frequencies below 300Hz, which does not happen at other times. Perhaps some artifact in the recording rig? Spurious frequencies at periods 14, 15 and 16 (6.5s to 8s).
Then relatively clean spectrum upwards.

So, overall we see how a real spectrum off a real CPC6128 speaker looks like.

Now, emulators that aim at accuracy should properly handle the conversion from the 125kHz-based AY to the app sampling frequency. I'm considering providing example code for one of the emulators, properly commented so as to be reusable by other emulators. Comments welcome.

Title: Re: Sound emulation survey
Post by: Aeliss on 16:55, 14 November 21
Quote from: cpcitor on 18:58, 04 November 21xcellent! Thanks! This is the best output so far.

Is it Arnold Emu by Kevin Thacker?
Which version of Arnold is it?

It's a modified version https://www.cpcwiki.eu/forum/emulators/another-version-of-arnold-emulator/ (https://www.cpcwiki.eu/forum/emulators/another-version-of-arnold-emulator/) but yes, the core is almost the same.
Title: Re: Sound emulation survey
Post by: BSC on 21:18, 14 December 21
Quote from: cpcitor on 10:29, 11 November 21
Note sure I agree with 2 as an argument. First, is the beeper on the CPC very different from what can be plugged on a spectrum?

Let's admit the speaker will not reach maximum displacement, but so what ? Let's rephrase.The speaker provides sound by pushing or pulling air.
Effects of high speed bit flipping put the speaker closer to a not saturated but linear regime, where frequency domain analysis provides hints.
In other words, at high base frequency, the harmonics will get dampened, right. At which frequency does this happen?
To get a hint, we'd like to guess the range of frequencies the speaker can provide. Easiest is to ask what frequencies are emitted, disregarding if those are harmonics or even the fundamental.
The answer is : above many kHz, as people report hearing sound from the CPC even with periods as small as 5.
This is why those musics on the spectrum sound scratchy, and on the CPC, too.
But all of this does not explain IMHO why the beeper engines can not be easily reproduced on the CPC.
I would rather say: with one bit-banging output, the Spectrum developers had no choice but to explore what happens when varying delays between highs and lows.
The CPC's AY chip can modulate while the Z80 does other work, but with less control (especially no PWM), and got people accustomed to that.
In some sense the CPC has some unexplored potential, yet how that can be combined feels a tough space to explore.

I am not sure if I follow you on what you wrote concerning frequencys and harmonics. Care to elaborate?

Anyway, there is no "beeper" in the CPC as is in the Spectrum. The beeper I was referring to is the envelope generator of the AY.
Then, of course, an external AY can be plugged to the olden Spectrums with only a beeper (16k and 48k versions), but in any case all spectrums have the beeper.
But I guess you already knew all that.

I agree with your sentiment on the explorations Spectrum delevopers had to do. But I also think that much more is possible than what I have shown in my demos.
I might continue my experiments soonish, as I could not really work on my CPC related stuff since last summer. But that's about to change.


Quote from: cpcitor on 10:29, 11 November 21
On a CPC you can control the tape signal output "very" quickly (Z80 OUT takes 'µs or 1/250000s on the CPC). About 5 times quicker than the fastest PSG access.

So, I recently had the idea of a "tape demo". You put a cassette in your CPC464, press "record", run the code, you hear a low volume music while tape records. Then you put the cassette in a regular player and it plays something "remarkable".
(If you're sad enough  to own a CPC 6128, you can plug a cable on the DIN and either connect that to you audio amplifier or to a tape recorder.)

Yes! I think the tape "beeper" is a good approximation of the Spectrum one. Have you already tried this approach?


Quote from: cpcitor on 10:29, 11 November 21
Interesting. Could you share what parameters are set and are changing in each section?
I can't even say if the sequence of sections repeat periodically or not.

Regarding this:

https://soundcloud.com/betasoftcologne/4bit-sweeping-demo

I think it consists of 4 virtual oscillators which trigger a re-start of the envelope generator shape every time one of the oscillators
"transitions" from low to high or vice versa. The envelope shapes vary throughout the track, every 3 seconds, but I don't recall
which exact shapes were used at what time, but all of them were of the non-repeating type. And the oscillators were only a few
hertz apart each, like 400, 403, 406 and 409, to get a lot of beating.

And regarding this one:

https://soundcloud.com/betasoftcologne/cocio-and-finsprit-6-channel-preview

This is basically the same as above, but with 4 oscillators for the bass and 2 for the lead and I think the frequency difference was
even smaller, like 1 Hz apart.
Title: Re: Sound emulation survey
Post by: cpcitor on 22:26, 14 December 21
Quote from: BSC on 21:18, 14 December 21
I am not sure if I follow you on what you wrote concerning frequencys and harmonics. Care to elaborate?

Probably yes, but not quickly, I'll have to re-read and think it again.

Quote from: BSC on 21:18, 14 December 21
Anyway, there is no "beeper" in the CPC as is in the Spectrum. The beeper I was referring to is the envelope generator of the AY.

The "beeper" I was referring to is the mechanical speaker:

Quote from: BSC
beeper (which is a tiny speaker that is directly connected to port &fe)

... and yes, on the CPC it's connected to the AY chip, not a I/O port close to the CPU.

Quote from: BSC
Yes! I think the tape "beeper" is a good approximation of the Spectrum one. Have you already tried this approach?

It's been only a thought experiment so far.
Notice that if you record on tape, the smoothing effect will come from the tape frequency response, which will be different from the speaker frequency response.

Quote from: BSC
Regarding this:

https://soundcloud.com/betasoftcologne/4bit-sweeping-demo

I think it consists of 4 virtual oscillators which trigger a re-start of the envelope generator shape every time one of the oscillators
"transitions" from low to high or vice versa. The envelope shapes vary throughout the track, every 3 seconds, but I don't recall
which exact shapes were used at what time, but all of them were of the non-repeating type. And the oscillators were only a few
hertz apart each, like 400, 403, 406 and 409, to get a lot of beating.

And regarding this one:

https://soundcloud.com/betasoftcologne/cocio-and-finsprit-6-channel-preview

This is basically the same as above, but with 4 oscillators for the bass and 2 for the lead and I think the frequency difference was
even smaller, like 1 Hz apart.

Thanks for the explanations. I'll have to take time to read and listen carefully.

Thank you for your feedback.
Powered by SMFPacks Menu Editor Mod