Ooops
September 21, 2021, 11:46:15

Author Topic: Creating ZX SOUND  (Read 6271 times)

Online iWasAdam

  • Hero Member
  • *****
  • Posts: 2450
Re: Creating ZX SOUND
« Reply #90 on: July 16, 2021, 18:51:30 »
Quote
I am getting this message sometimes. RINGBUFFER: Prevent "Buffer Overrun! Wait for 20 msec"
Ive already tried ajusting the 40Khz down to 22,100Hz but then emulation runs very slow and laggy.
Im going to try and not use the CheckBufferOverRun() Function and see what effect that has.

That would suggest something is wrong with the ring buffer. Plus also the code itself might be doing something funky.

As an example a general ringbuffer should support up to 32 channels at the same time with no slowdown!

if you look at the spectrum, the sound is just a simple square wave.

The speed of your system should have no bearing as you should be syncing into the reatime clock and working out timing from there.

if you are looking at the AY chip then you will need to do some serious research into FM synthesis.

Another thing to think about is separating the sound system from the main code in it's own thread system. That way it wont ever slow things down unless you are doing something very odd...

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #91 on: July 16, 2021, 21:22:06 »
Okay!  ???

Trying Bandicam to upload a video Currently ???

For 'Fook Sake' Don't Laugh. I feel like a 52 year old Kid trying to bash the "ROUND PEG" into the Star "HOLE"  ::) Things used to be so easy!

Nearly there. :-\ This is a 'Hobby'

Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: Creating ZX SOUND
« Reply #92 on: July 17, 2021, 00:16:42 »
Quote
I am getting this message sometimes. RINGBUFFER: Prevent "Buffer Overrun! Wait for 20 msec"
Ive already tried ajusting the 40Khz down to 22,100Hz but then emulation runs very slow and laggy.
Im going to try and not use the CheckBufferOverRun() Function and see what effect that has.

That would suggest something is wrong with the ring buffer. Plus also the code itself might be doing something funky.

As an example a general ringbuffer should support up to 32 channels at the same time with no slowdown!

if you look at the spectrum, the sound is just a simple square wave.

The speed of your system should have no bearing as you should be syncing into the reatime clock and working out timing from there.

if you are looking at the AY chip then you will need to do some serious research into FM synthesis.

Another thing to think about is separating the sound system from the main code in it's own thread system. That way it wont ever slow things down unless you are doing something very odd...


That would suggest something is wrong with the ring buffer.

@Adam

could you please read the complete topics before you fire your comments with no context to the theme?

The FreeAudioRingbuffer feeds the Audio-Device with the (user's) given HERTZ, CHANNELS and FORMAT. If then a user fires the double amout of datas every ringbuffer gets to the point of overrun. My FreeaudioRingBuffer reports this at the state of 80% to the DEBUG window to inform the user that the source datas are fired to fast. And it waits for 20msec until the buffer is again free enough to receive the additional datas.

Baggey wants to simulate with the FreeAudioRingbuffer an old Spectrum Hardware. On the old hardware the timing was always perfect, because the hardware speed was a given limitation. If he now fires the same datas on a modern computer, then they reach 10 to 100 times faster the "soundchip". So, when he now received the message "buffer overrun" this means that his simulator timing is faster than the original vintage timing was.

His problem is not that the FreeAudioRingbuffer slows down! He does not send 32 channels but one!!!! My FreeaudioRingbuffer is 100% able to handle 32 channels with 96kHz and 4byte-FLOATs.

But he sends SF_MONO8 with 40kHz and this means only 40000  bytes per second should be sended to the RingBuffer and not 400.000 each second!!!
So he receives the helpful message "Please send slower! This are to many for the rate you decided!"

Quote
if you look at the spectrum, the sound is just a simple square wave
What do you think we are doing here? We send only SQUARE WAVES. But in the tricky way of the 70th.

Quote
...Another thing to think about is separating the sound system from the main code in it's own thread system.
What do you think we are doing here? FreeAudioRingBuffer is in it's own thread system.

Sometimes READING would help!
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #93 on: July 24, 2021, 14:16:06 »
So Finaly a post of SpecBlitz playing "Jet Set Willy".

Cant get Full screen video up  ??? This isnt really a showcase im still trying to get Sounds to work! And further mods todo to the SpecBlitz Emulator.

There are holes in the in game tune and when an effect of jump, collect item or being Killed. Video is about 4 Mins but ive tried to capture every sound effect that should or dosent happen  ;D

Im getting buffer Overrun at the mo will try code for more precise TCycles latter  ;)



I will indue corse get some more vids up with other game sounds trying to demonstrate where sounds are or arent working.

Kind Regards Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #94 on: July 24, 2021, 14:56:07 »
MidiMaster has a new Version of the RingBuffer Version 1.2

https://www.syntaxbomb.com/worklogs/done!-a-new-audio-out-approach-in-blitzmax-freeaudio-ringbuffer/msg347049187/#msg347049187

I Shall try this new code in SpecBlitz to see if it will iron out writing to fast to the Ring Buffer.

Hopefully we may hear Sound's that are being misssed by my incorrect timing or Buffer overrun's  ;D

Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #95 on: July 24, 2021, 16:50:14 »
Here's a Link to Highway Encounter about 4 mins



I think all sounds in this game are being Sounded but i think there are small holes in the sound. This could be due to my Timing not quite right.

Not Running RingBuffer 1.2 yet and if i need to make my Timing more acurate thats a lot of CODE to alter  :o

Noticed theres a write to 16384 which isnt aloud when watching back video! Could be a another Bug ive just found  :-X

Kind Regards Baggey
« Last Edit: July 24, 2021, 17:00:26 by Baggey »
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: Creating ZX SOUND
« Reply #96 on: July 25, 2021, 10:00:02 »
There are holes in the in game tune and when an effect of jump, collect item or being Killed. Video is about 4 Mins but ive tried to capture every sound effect that should or dosent happen  ;D

Im getting buffer Overrun at the mo will try code for more precise TCycles latter  ;)



In your audio example you can hear both possible situations with the RingBuffer. And you can als ohear how comfortable the Overrun message works.

As long as the Ringbuffer fires the Overrund-Message the sounds are perfect. This is because the Ringbuffer takes command about the corrrect timing. Your app fires the datas to fast and the fingbuffer interrupts your app and forces it to send a optimal timing. So in this situation your timing control fails and the app is sending to often packets.

The second possible situation is that your app sends datas too slow. Now the number of datas reaching the ringbuffer are to low. you can hear this in the "stuttering". This is caused by little pauses where the buffer has no more data to process and it reacts with SILENCE.

There a some possible solutions or reasons for this:

1. The buffer works to fast. Set the HERTZ lower and the buffer expects less datas.

2. The sender sends to slow. Try to send the packets more often.

3. The processor speed simulation is not perfect.
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #97 on: August 01, 2021, 07:10:03 »
So, Yes it's sort of a showcase but it's more about the seemingly endless task of getting Sound to WORK!

Yesterday ive altered and tweeked the Maincode and Z80 timing control of SpecBlitz. Using Manic Miner as the Example, as that is what i started with.

My game Code is Running silky smooth now without any tearing to Willy and the Baddy on screen he jumps around and there seems to be no Throteling or slowing of the game play!

Using the Latest RingBufferClass with TCycles set at 3500 per milli second and a ring buffer of 44100Hz see Output window as i change the Tcycles in realtime slightly.

Flash routine is now out of sync but it's irelavent to the main code controling the sound data being sent! I'll change this latter. Oh HALT emulation will need adjusting too but it's not used in Manic Miner.

First Video is ManicMiner running on FUSE and me Running SpecBlitz at 44100Hz at 3500TCycles per second. Fuse Title Music seems fast and the in Game Jig seems fast too. Compared to SpecBlitz Sound. In game sounds of jumping, Diying and item collecting work as you'd expect! But Silence for quick snipets of jumping, Diying and item collecting?
I think thou, the in game play are very similair. Video is Roughly 2.5mins



So, Here's the thing ive now created a video changing SpecBlitz to 9600Hz at 3500TCycles per second. Music sound seems very Laggy now but in game sounds like dying, Jumping and item collecting are trying to work. Video is Roughly 1.0min



I Really have no idea what is happening  :-[ The silence at 44100hz seems like i should be sending data Quicker. As im not getting Buffer Overun. And at the lower 9600Hz scale it seems like im not sending it quick enough either. But in Game Emulation seems silcky smooth now :D


Sound seems to be a tough cookie to get right!? So Anyone got an idea as to what might be happening?


Id like to move on with Future Changes to come :-
     Creating 128K emulation
     An automatic file loader
     And Finally get the AY Chip going  :o

Oh i want to create a coding window with a cross between Basic and Machinecode ie a Special Assembler so SpecBlitz can be coded in Native Machine code but using A Basic like Syntax. The idea i think will get people coding in Machine code but using an understandable Basic Syntax.

Oh, Onemore. All programs will be able to be saved and run and instantly available again if there is a CRASH!  8)

However it seems like One is not quite hitting the sweet spot in my timing maybe  :-\

Kind Regards Baggey "up the CREEK without a PADDLE" when it comes to SOUND  :))




« Last Edit: August 01, 2021, 07:11:51 by Baggey »
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Online iWasAdam

  • Hero Member
  • *****
  • Posts: 2450
Re: Creating ZX SOUND
« Reply #98 on: August 01, 2021, 07:41:34 »
ignoring the sound...

Can you set a base cpu frequency (fast, slow, exact, etc) and get the games to run at the required speed?

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #99 on: August 01, 2021, 07:56:04 »
ignoring the sound...

Can you set a base cpu frequency (fast, slow, exact, etc) and get the games to run at the required speed?

yes, i can. In the first video in the Output window i changed the Tcycles from 3500 to 3506 and back down to 3500 again in realtime. The in game emulation as a result runs faster or slower but smoothly.

Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Online iWasAdam

  • Hero Member
  • *****
  • Posts: 2450
Re: Creating ZX SOUND
« Reply #100 on: August 01, 2021, 08:06:18 »
ok, so your actual z80 code is fine and all the ula etc is being dealt with. brilliant.

next question - sound - lets just assume I know nothing about how it is currently being done.
Q. With the sound. I am assuming you are sending data to a black box (Yep I know it's some form of ring buffer), in some form of square wave?

And when you activate the black box - that's when it slows down?


Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #101 on: August 01, 2021, 08:42:29 »
ok, so your actual z80 code is fine and all the ula etc is being dealt with. brilliant.

To the best off my Knowledge the Z80 code is working as it should or it would'nt be Emulating the game. So things like Flags, video Interupts, Keyboard interupts and Machine Interupts etc are functioning. I believe i am runing at a Base Frequency as you call it of 3500TCycles per milli second As close as.

next question - sound - lets just assume I know nothing about how it is currently being done.
Q. With the sound. I am assuming you are sending data to a black box (Yep I know it's some form of ring buffer), in some form of square wave?

I am sending one Byte of information. When ever the Emulator interpret's an OUT r,(254) instruction. ie, this port concern's the Mic,Ear and border value. i strip the information by anding with 24. I then have the Mic bit and the EAR bit. The value being sent to the Ring buffer is one byte value of 50 or 200 depending of wether the Piezo/Speaker Moving to ON or setteling to OFF. So to speak.

For Example :-
Code: BlitzMax
  1. Select (value & 24)
  2.                 Case 0  ' OFF
  3.                       RingBuffer.SendONE 50
  4.                 Case 8  ' EAR Socket ON ... ie PIEZO
  5.                       RingBuffer.SendONE 200
  6.                 Case 16 ' MIC Socket ON
  7.                       RingBuffer.SendONE 50
  8.                 Case 24 ' EAR and MIC SOCKET ON ... Should Amplify Sound Slightly ... ie, Louder Volume
  9.                       RingBuffer.SendONE 200
  10.                 'Default
  11.                       'RingBuffer.SendONE 50
  12. End Select

And when you activate the black box - that's when it slows down?

Im not sure about the final part!  :-[

Kin Regards Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: Creating ZX SOUND
« Reply #102 on: August 01, 2021, 08:42:50 »
At a first step the game speed has to be correct. If this is perfect you now can find out the best HERTZ for the ringbuffer. You  should find the same HERTZ the vintage speaker port worked with.
In this former times the speakers did not work with a common Hertz like 44100, but they used the computer's clock rate or a division of it. So we can only guess.

A sign, that you are using the correct HERTZ is the pitch of the music. It should also today on modern computers sound with exact the same pitch as it was on the vintage computers.

A too high HERTZ results in stuttering, a too low HERTZ will cause "BUFFER OVERRUN" messages. You can find out the best HERTZ by using the middle of your MINIMUM and MAXIMUM test HERTZ. So I suggest now to use (44100+9600)/2 = 26000 for a next experiment.

If you get STUTTERING you take 26000 as new MAXIMUM. So next eperiment is with (26000+9600)/2 =18000 Hertz

If you get BUFFER OVERRUN you take 26000 as new MINIMUM. So next eperiment is with (44100+26000)/2 =35000 Hertz

Better you test this with in-game-music instead of short sounds.
« Last Edit: August 01, 2021, 08:45:12 by Midimaster »
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Baggey

  • Full Member
  • ***
  • Posts: 175
Re: Creating ZX SOUND
« Reply #103 on: August 01, 2021, 08:58:35 »
Okay,

So it's like trying to find a UNITY point. Sweet Spot. if i had a scope or analyser maybe i could see the Frequency of the FUSE sound?

However, I shall try this division idea of 2. Moving closer to a frequency of compromise i suppose?

I have some Schematics of the Zx spectrum ill see where the Clk Cycles get divided. May be looking to deep but i suppose there's some sort of feed from a clock source feeding the PIEZO through an NPN, PNP or OP-AMP by a clk pulse. Being turned on by the OUT r,(254) letting through a clk pulse :o

Thanks to all in advise and helping!

Kind Regards Baggey
Currently Running a PC that just Aint fast enough!?
ZX Spectrum 48k, NEXT, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip.

Jesus was only famous because of his DAD.

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 363
    • Midimaster Music Education Software
Re: Creating ZX SOUND
« Reply #104 on: August 01, 2021, 09:05:48 »
I checked the sound pitch in your videos with AUDACITY and found out, that 44.100 is still to low

The factor of pitch between the song in FUSE and your test with 44.100 is 1.45. This would mean that 44100*1.45 = 63.945.

So I would suggest a test with 64.000 HERTZ next

But this would cause more STUTTERING. It looks like the port 254 received the double amout of data on the vintage computers.

So please do a second test with 32.000 Hertz. I guess the pitch (and the song speed) will be to low, but the STUTTERING will be away and there are still no BUFFER OVERRUN messages.


If this is a hit, it would mean, that they did something with the speaker we still do not know. Or the game speed is not 3500 but higher.


Only one DELAY?

Did you now remove all DELAY commands except the one in AddCycles()?
« Last Edit: August 01, 2021, 09:08:39 by Midimaster »
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal