Using blitter for sound mixing

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Cyprian
Atari God
Atari God
Posts: 1469
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Using blitter for sound mixing

Postby Cyprian » Fri Mar 30, 2018 2:00 pm

metalages can you pls update your blog? http://cyber.savina.net/sound.htm
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Aranym / Steem / Saint
http://260ste.appspot.com/

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Fri Mar 30, 2018 2:08 pm

charles wrote:any chance youll adapt midi as the file format ?
have loaded spl/wav triggered via midi notes ..?
I guess like gadjits seq one and other commercial tracker/sequeners for Atari?


Video fixed here...
https://youtu.be/Xc0zv4YFitI

The routine has very strong constraints.
But as I use a converter, I suppose the converter can be adapted to other formats ?

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Fri Mar 30, 2018 2:08 pm

Cyprian wrote:metalages can you pls update your blog? http://cyber.savina.net/sound.htm


I will take time for that ;)

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Mon Apr 02, 2018 9:37 am

Cyprian wrote:metalages can you pls update your blog? http://cyber.savina.net/sound.htm


I have added some details on the page...

http://cyber.savina.net/sound.htm
http://cyber.savina.net

User avatar
Cyprian
Atari God
Atari God
Posts: 1469
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Using blitter for sound mixing

Postby Cyprian » Mon Apr 02, 2018 11:15 pm

metalages wrote:
Cyprian wrote:metalages can you pls update your blog? http://cyber.savina.net/sound.htm


I have added some details on the page...

http://cyber.savina.net/sound.htm
http://cyber.savina.net

many thanks
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Aranym / Steem / Saint
http://260ste.appspot.com/

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Tue Apr 03, 2018 9:26 pm

I have uploaded a preview of the documentation here http://cyber.savina.net/sound/BLITSnd.pdf
with a lot of details in there ;)

joska
Hardware Guru
Hardware Guru
Posts: 3926
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Using blitter for sound mixing

Postby joska » Wed Apr 04, 2018 10:27 am

This is very interesting stuff. I have been experimenting with something similar myself, but not nearly as advanced as this. Like you I generate new samples for each used note for each sample, but I don't use the blitter for mixing. I stopped since it occured to me that it would be too complex (or use too much RAM) to support volume- and frequency-slides, and some of the mods I really wanted to use needed those effects.
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Wed Apr 04, 2018 9:16 pm

Frequency slide is the main constraint in my opinion. Volume is neither precise (a bit more when possible to play with LMC).
I think there is still room to make cool stuffs but this routine is very constraining indeed.
What would be great : being able to use YM in the same time => it would offer portamiento, and volume slide on the chip voices.
But this needs a dedicated editing tool and it is a big (huge) work :| (and I am a total newb with YM)

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Tue May 08, 2018 9:05 pm

I have no time to make a screen with it for the moment...
I have uploaded a first version of the sound routine using blitter on my github.

Docs are here : https://github.com/gibs75/demOS/blob/ma ... /README.md
Sources here : https://github.com/gibs75/demOS

User avatar
dhedberg
Atari Super Hero
Atari Super Hero
Posts: 659
Joined: Mon Aug 30, 2010 8:36 am
Contact:

Re: Using blitter for sound mixing

Postby dhedberg » Tue May 08, 2018 10:25 pm

If you find the time, maybe a remote entry for the demo competition at Sommarhack?
http://dhs.nu/sommarhack/2018/
Last edited by dhedberg on Wed May 09, 2018 8:36 pm, edited 1 time in total.
Daniel, New Beat - http://newbeat.atari.org

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Wed May 09, 2018 7:34 pm

Seems difficult but we will see ;)

I have just pushed a change.
Strangely in Hatari when running the update routine from VBL start, there is no click.
If I wait first display line, clicks appear => I have added BACKSPACE allows to toggle the sync in player.
Running from first display line is just for benchmarking using raster lines...

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Thu May 10, 2018 3:27 pm

Hi
not really related to the "click" issue, but looking at the code on github, it seems you inverted the meaning of "waitfordisplay" : if waitfordsiplay is true, you call BLSupdate(), else (waitfordisplay is false), you wait for display to start by checking that video counter increases. To match current code, the 'if' should be "if (!g_player.waitfordisplay)".
So, does it mean there's a click if BLSupdate() is called immediately or if it's called when video counter starts (around HBL 63) ?
Just to be sure we use the same references.
On real STE, there's no click at all in both cases ?

Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Thu May 10, 2018 4:49 pm

Yep indeed. I have inverted the condition to have the display synched by default when running without renaming the variable.
My fault :$ Clicks happen when starting on line 63.

I have to try on real STe but not tested yet as it is in a cupboard.

BLSPLAY.TTP is available at the root.
I have tested with QUICKIE.BLS file (need to convert the MOD file) =)> I will upload it.
It is very clear on the bassline.

Jerome

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Thu May 10, 2018 4:53 pm

QUICKIE.BLS and _QUICKIE.BLS uploaded on git...

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Sun May 13, 2018 12:02 pm

Hi
I tried quickie.bls on my STe, and I don't hear any difference when toggling wait for display, sound remains similar.

But this doesn't mean it's correct, it's just hard to spot sound quality issue on my old crt monitor, especially because the click are easier to notice on the bassline, but the other 3 voices playing at the same time makes it hard to really listen to bassline.

Could you make a version of blsplay where it's possible to toggle each voice on/off with keys 1/2/3/4 for example ?
Or maybe a version of the module that only play voice A (bassline) and nothing on the other voices ?

Also, what is the difference between QUICKIE.BLS and _QUICKIE.BLS ? They seems to sound the same ?

Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Sun May 13, 2018 6:33 pm

Sorry I did not find the time to test on my STe.
On the current version of BLSplay, you can toggle voices on / off with keys 5 to 8 (not the numpad)
Clicks were very clear in Hatari on bassline (voice 1).

QUICKIE.BLS and _QUICKIE.BLS are the same module but two voices have been inverted on _QUICKIE.BLS.
It shows clearly that the performance increase a lot with _QUICKIE.BLS if two voices Left+Right of the same word in the sound buffer interlacing are inactive in the same time (not the case when not inverted).

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Mon May 14, 2018 12:05 pm

metalages wrote:Sorry I did not find the time to test on my STe.
On the current version of BLSplay, you can toggle voices on / off with keys 5 to 8 (not the numpad)

I tried 1 to 4, but didn't think to try 5 to 8 :)
With only voice A playing, the result is the same in both cases (wait for display on or off).
The clicks are not the same as on Hatari, but still the sample has some kind very small noises, like listening to an old vinyl disk. I don't know if it's due to the sample processing you do to use the blitter, maybe it alters the quality a little ?
Clicks were very clear in Hatari on bassline (voice 1).

I saw a possible rounding problem when updating the sound buffer in Hatari when you do a stop/start of the dma sound to set the new start/end addresses for the sample buffer.
It can cause Hatari to read too much from the audio dma fifo, and in the case where dma sound is stopped, it will read from an empty fifo and output some "0" bytes as a fallback in the sound buffer.
These 2 "0" bytes will create the clicks.
This part of dma audio emulation is tricky, because audio fifo is normally filled when display is OFF (when entering right border). For performance reason, Hatari fills the fifo a little later at the end of the hbl, but this can create some un-accurate cases like this one.
This bug will occur not because you're on HBL 63 when waiting for display, but also depending on the position on line 63 when doing a stop/start for audio dma.
After waiting for display to start on line 63, you could try to add a variable number of NOP so that the audio stop/start happens at a different position, this might remove the click. but I have no idea of the number of NOP, you could try 20, 100 or more, but no guarantee :(

Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Mon May 14, 2018 9:10 pm

Thank you for your tests and detailled answer :)

I have tried to figure out where the clicks can come from.

I have the feeling that some appear when the sample is retriggered at each new note (sample is retriggered without any smoothing).
On Facebook, Troed has also talked about usual clicks on STe hardware around 2.6khz and it seems my clicks are in this kind of range.
Also maybe the 50khz / 25khz interlacing technique is a bit agressive for the D/A converters ?

About the sync, currently I wait the beginning of the display on the left by waiting the low video counter starting to change.
I will try different combinations, maybe it would it be better if I wait end of the line display on the right ?
What you said about the fact normal behaviour is to fill FIFO when display is off => does it mean that on a real STe, doing overscan also change when dma sound operates ?

I am not aware of exact details of the hardware behaviour on a real STe but I was believing DMA sound output level was remaining in the same state when stopped - not going back to 0 ? (I do not remember where I read this on internet)

Documentation I have found on the dma sound is not very detailled on how it behaves on the end buffer limit.
Does it loads the data corresponding to the end adr ? Even this simple thing is not very clear. Also how does it work when switched off while reading...

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Mon May 14, 2018 9:57 pm

metalages wrote:Thank you for your tests and detailled answer :)

I have tried to figure out where the clicks can come from.

I have the feeling that some appear when the sample is retriggered at each new note (sample is retriggered without any smoothing).
On Facebook, Troed has also talked about usual clicks on STe hardware around 2.6khz and it seems my clicks are in this kind of range.
Also maybe the 50khz / 25khz interlacing technique is a bit agressive for the D/A converters ?

I'm not sure it's a D/A conversion issue, either it's a loss of quality when samples are preprocessed to be used for your blitter mixing, or it's a small artefact when doing the stop/start to switch audio buffer every VBL (see below)
About the sync, currently I wait the beginning of the display on the left by waiting the low video counter starting to change.
I will try different combinations, maybe it would it be better if I wait end of the line display on the right ?

I don't think there's a rule for this, it's more about luck to find a spot where Hatari will not round to an extra unnecessary sample.
Once you sync to display on line 63, maybe do sthg like this :

Code: Select all

  move.w ExtraPause,d0
.wait2
  dbf d0,.wait2

And maybe assign 2 keys to increase/decrease ExtraPause from 0 to 3000 for example. You might find a value where the clicks are removed under Hatari.
But that's just an ugly workaround if you want to call your replay from somewhere else than the start of the vbl.
What you said about the fact normal behaviour is to fill FIFO when display is off => does it mean that on a real STe, doing overscan also change when dma sound operates ?

Yes, that's what I suspect. I didn"t measure it yet in overscan on a real STe, but with a custom program I was already able to see that dma audio counter increased just when display is off when borders are not removed, so my guess is that dma audio accesses happen as soon as the mmu don't send data to the video shifter. Note that overscan will change when the fifo is fillled, but it doesn't change when sampled are played, it's just that samples are not "played" from RAM, but in fact they're played from the small fifo (which itself is filled from RAM)
I am not aware of exact details of the hardware behaviour on a real STe but I was believing DMA sound output level was remaining in the same state when stopped - not going back to 0 ? (I do not remember where I read this on internet)

Documentation I have found on the dma sound is not very detailled on how it behaves on the end buffer limit.
Does it loads the data corresponding to the end adr ? Even this simple thing is not very clear. Also how does it work when switched off while reading...

I'm not sure if level remains the same (ie the last byte read from the fifo) when dma is off or if it's 0. Hatari assumes 0, but I didn't measure it. In your cases, maybe playing the last byte could solve the click bug in Hatari, I will try this as a possible workaround.

Bytes at end addr are not read, so only bytes >= start addr and < end addr are played.
Also, instead of setting a new sample buffer by doing
- stop dma
- set start/end addr
- start dma

You could do :
- set dma to play in loop mode
- set start/end addr for buffer1
- before reaching the end of buffer1 (for example after 1/2 VBL) set the new start/end addr for buffer2
This way buffer2 will play seamlessly when end of buffer1 is reached. On next VBL, do the opposite and buffer1 plays at the end of buffer2.
This works because the dma audio buffers the start/end addresses once in play mode, so any new start/end addresses you write will not be taken into account until end of the current sample is reached.
With this, you don't have to stop/start dma audio, even briefly, so transition between switching audio buffer will not be hearable (this is also possible with the stop/start method, but you need very precise timing to do the stop just after the last byte of the sample was read)

Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Tue May 15, 2018 9:05 pm

Whaou a lot of valuable quality info in there, tx :)

About quality of pre-transpose + blitter mixing, there is a way to check : if you run BLSplay in test mode (add -test to command line),it will dump the generated sample into a file instead of playing with DMA sound.
This file will be generated into .\_logs\ASM\ or .\_logs\C\ or .\_logs\PC\ according to the build configuration (ST asm, ST C, PC)
This raw sample file can be imported in Audacity for inspection (import => raw => 4ch / 8 bit signed PCM / 25khz)
In Audacity I ear clicks on voice 3 & 4 that happen when volume change while a sample is playing => there is a big drop in sample envelop volume in this case. Bassline is rather clean (except a very low constant sampling noise (or maybe interpolation :))).
(https://github.com/gibs75/demOS/blob/ma ... ITSnd_3.md)

Ok, I will try to add some extra waiting to solve the problem of the player in Hatari.
Seems the easiest way to work around this.

About using loop mode instead of play once : for sure it would be cleaner technically speaking but I am not a fan of requiring a second step to run the routine during the VBL because this routine allows to have full remaining time for graphic effects, or blitting without sharing bus, or stable interupts, or sync code... which is an advantage compared to SID voice or sync buzzer technics. In particular the routine exec fits completly into the upper border and is not far from fitting into the lower border. Really a pitty having the DMA sound not completely synched with VBL :(

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Tue May 15, 2018 10:40 pm

metalages wrote:About using loop mode instead of play once : for sure it would be cleaner technically speaking but I am not a fan of requiring a second step to run the routine during the VBL because this routine allows to have full remaining time for graphic effects, or blitting without sharing bus, or stable interupts, or sync code... which is an advantage compared to SID voice or sync buzzer technics. In particular the routine exec fits completly into the upper border and is not far from fitting into the lower border. Really a pitty having the DMA sound not completely synched with VBL :(

Waiting 1/2 VBL in my previous post was just a (bad) example, in fact you should be able to write new start/end values just after starting audio dma. Once audio dma is started it latches the values of start/end, so you can write new ones.
If you don't want to slow your routine, you can do this in you blsupdate called from VBL :
- only on the 1st call : write buffer1 start/end, start dma audio and write buffer2 start/end.
- for all other vbl, just write the other buffer start/end address.
This would give :
- VBL0 : set buffer1, start dma audio, set buffer2
- VBL1 : set buffer1
- VBL2 : set buffer2
- VBL3 : set buffer1
and so on...

Of course, you need to have a very precise number of samples to play each VBL, because over time it' s possible the point where each sample loops will slightly drift (but that would be the same problem when you use the start/stop method to be sure the new sample is started exactly when the previous one ends (and not 1 byte too soon or too late). That's because depending on the dma audio freq then number of bytes to play each vbl might not be an integer.

Nicolas

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Wed May 16, 2018 1:13 pm

metalages wrote:About quality of pre-transpose + blitter mixing, there is a way to check : if you run BLSplay in test mode (add -test to command line),it will dump the generated sample into a file instead of playing with DMA sound.
This file will be generated into .\_logs\ASM\ or .\_logs\C\ or .\_logs\PC\ according to the build configuration (ST asm, ST C, PC)
This raw sample file can be imported in Audacity for inspection (import => raw => 4ch / 8 bit signed PCM / 25khz)
In Audacity I ear clicks on voice 3 & 4 that happen when volume change while a sample is playing => there is a big drop in sample envelop volume in this case. Bassline is rather clean (except a very low constant sampling noise (or maybe interpolation :))).


I tried the '-test' option (btw, maybe you could create _logs and asm directories if they don't exist ?) and listened to the result under Audacity.
When just listening to voice A / bassline, I don't hear the kind of "vinyl cracks" I had on my STe. So even if this cracks are rather light, it might be due to the way used to switch between sound buffers 1 and 2 on each VBL, maybe indicating that the exact number of bytes per buffer is not always played.
Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Wed May 16, 2018 8:58 pm

I can try this way, but my problem in this case is : if I do not always generate 1000 samples (per channel) per frame, I am not sure everything will divide so well in different cases...

Maybe another way is to use a triple buffer and have only one constant DMA looping on these three buffers.
Then control which sub part of the 3 to fill according to the currently playing address.

In reality, in average DMA sound expects 50066 / 50 = 1001.32 samples if I am not wrong ?
Maybe I can trick by computing 1000 samples and duplicating one or two samples at the end when needed ?

User avatar
npomarede
Atari God
Atari God
Posts: 1233
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Using blitter for sound mixing

Postby npomarede » Wed May 16, 2018 9:25 pm

Well, that's the problem when you want to play continuous samples with dma audio : you can't base your numbers on 50 VBL, because in fact a PAL STF/STE has 50.0527 VBL per second :)

Here's why : base cpu clock is 8021247 Hz and we know one VBL is always 160256 cycles when shifter is set to 50 Hz. If you divide 8021247 by 160256, you get 50,0527, not 50.0

Which means that 1 VBL of DMA audio at 50066 is is fact ~1000.2657 samples, not 1001.32 (this was the cause of a long standing issue I had in Hatari some years ago when emulating "More or less zero" by DHS, because after a while video and sound were not in sync anymore if I assumed 50 VBL per sec instead of 50.05).

As you can't play a fractional number of sample each VBL, this means you must have a kind of "adjusting" buffer to play every VBL ; sometime you play 1000 samples and sometimes 1001, to keep the error as low as possible.
You can do this by keeping a total of the integer number of samples played since the start and compare it to the theoretical total (ie 1000.2657 * vbl_number) (you can think of this as some kind of bresenham algo to minimize rouding error).

Here, we can consider that 1000.2657 is in fact 1000 + 1/4. So every 4 VBL you must play a total of 4001 samples. In the case of your replay, this means you must play 3 buffers of 1000 bytes then 1 buffer of 1001 bytes.
Of course, your replay could generate 1002 samples every VBL for convenience, but you must play only 1000 or 1001 of them (and then you need to watch how your buffer grow, because after a while you will have more samples than needed for 1 VBL if you play only 1000 or 1001 of the 1002 you compute every time)

This might sound unnecessary tricky, but if you want a really accurate audio quality without any "drift" over time, having a variable len buffer seems the easier way to me (other solution would be to monitor current dma audio address to do a stop/start at the exact end position, but this is not very useful in a demo context where we don't want a replay to take so much time).

Nicolas

User avatar
metalages
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 101
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Using blitter for sound mixing

Postby metalages » Thu May 17, 2018 9:36 am

Excellent. Things get really more clear about how STe operates with your explanations :)
(also get things more clear in my mind ;))

I think I will try something like :
- triple buffer with constant DMA looping on the 3 buffers
- monitor the current play address to decide where to generate (or not) the sound buffer
- always generate 1000 samples + 1 duplication (per channel)

=> so generation will be progressively more and more in advance on the DMA replay
=> means at one point we will have to not generate the buffer during a frame to catch up (why we need a triple buffer) => one frame every 4000 vbl if I well understood
=> I have to check that 1 duplication do not generate a sensible de-phasis


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 2 guests