Blitter sound routine

GFA, ASM, STOS, ...

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

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

Re: Using blitter for sound mixing

Postby npomarede » Thu May 17, 2018 10:08 am

Hi
yes, that's the idea :)

working with a larger buffer (triple or even more) is a good alternative too, because you don't have to change the number of generated sample per VBL, you just have to stop generating samples at one point when the buffer is too much "in advance" (this is similar to how Hatari internaly generate emulated sound samples for the OS, using a circular 16 KB buffer, with one pointer to write new data and one pointer to read data and push them to the OS).
A larger buffer will create a small latency (2 VBL in your case with triple buffer), but that's unnoticeable in the case of a demo.

User avatar
troed
Atari God
Atari God
Posts: 1436
Joined: Mon Apr 30, 2012 6:20 pm
Location: Sweden

Re: Using blitter for sound mixing

Postby troed » Thu May 17, 2018 1:34 pm

STE base clock is either 8.02 or 8.05 (NTSC models) though.

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

Re: Using blitter for sound mixing

Postby metalages » Thu May 17, 2018 2:38 pm

Does this mean something around 50.23 VBL per sec => 996.73 DMA sound samples per sec ?

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

Re: Using blitter for sound mixing

Postby metalages » Mon May 21, 2018 6:13 pm

Ok I have something working with de-sync looping-dma and replay routine using 4 buffers.
So no more click indeed.

Drawbacks with this approach are :
- there is a small desync in replay / rythm when I catch up. Can be accpetable as it does not happen so often.
- it would be difficult with this approach to sync STe balance control with score

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

Re: Using blitter for sound mixing

Postby metalages » Tue May 22, 2018 9:26 pm

Ok. In order to avoid these problems I went for something like you have proposed in a first time Nicolas :
- DMA in loop mode
- 3 buffers
- chain assignments of dma start / end adresses on buffers (1, 2, 3, 1, 2, 3...) at a point later where I am sure new adresses have been acquired by dma
- monitor read cursor to determine if I need to render a 1000 or 1002 samples on the next frame
- and tune dma end address accordingly

I have something working in C under Hatari. No click, no lag...
Need to port this in ASM now ;)

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

Re: Using blitter for sound mixing

Postby npomarede » Tue May 22, 2018 9:36 pm

Great ! Hopefully, doing the same in ASM should not be a problem now that you have the logic right in C :)

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

Re: Using blitter for sound mixing

Postby dhedberg » Tue May 22, 2018 9:38 pm

Pretty awesome! Please make something with this! Too good to just be put on the shelf!
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo MORE.

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

Re: Using blitter for sound mixing

Postby metalages » Sat May 26, 2018 9:31 pm

Ok it now works in C and ASM perfectly on Hatari :)
Need to check on real hardware now...

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

Re: Using blitter for sound mixing

Postby metalages » Sat Jun 02, 2018 9:15 pm

I have tested on STe. Here is the result :

https://youtu.be/ehSvjL8RLo4

It works the same way than in Hatari => nearly no click, but I have the feeling that even with DMA in loop mode,
I have some clicks when running at display time instead of start of VBL (not really a problem as I do not see the point to run it during display)

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

Re: Using blitter for sound mixing

Postby metalages » Sat Jun 02, 2018 9:34 pm

... and sources + binary released here

https://github.com/gibs75/demOS

User avatar
CiH
Atari God
Atari God
Posts: 1128
Joined: Wed Feb 11, 2004 4:34 pm
Location: Middle Earth (Npton) UK
Contact:

Re: Using blitter for sound mixing

Postby CiH » Sun Jun 03, 2018 6:52 pm

Pretty awesome! I second Daniel. This is too good to be left here.
"Where teh feck is teh Hash key on this Mac?!"

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

Re: Using blitter for sound mixing

Postby metalages » Sun Jun 03, 2018 7:06 pm

Code and binaries are on github :)

So it is available for musicians and coders (ask me if you need help)

I think at some point I will find time to make a musik disk if some musicians are interested to collaborate but I am currently quite busy :(

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

Re: Using blitter for sound mixing

Postby metalages » Tue Jun 05, 2018 8:32 pm

New release of BLSplay and BLSconvert with support of STe balance (microwire) like described into doc

https://github.com/gibs75/demOS

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

Re: Using blitter for sound mixing

Postby metalages » Thu Jun 07, 2018 7:39 pm

BLSplay v1.2.0 submitted => speed up init samples process (was really slow)

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

Re: Using blitter for sound mixing

Postby metalages » Tue Jun 19, 2018 8:01 pm

new commit : https://github.com/gibs75/demOS

BLSplay 1.4.0
- add support for delay sample effect (0xEDx)
- on PC : closing the window closes the player
- little optimizations in ASM
- split ASM source (inits / play)
- update unit tests
- update doc

BLSconvert 1.1.0
- add support for delay sample effect (0xEDx)

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

Re: Blitter sound routine

Postby metalages » Mon Jun 25, 2018 9:19 pm

new commit : https://github.com/gibs75/demOS

BLSconvert 1.1.1
- fix convertion when different samples have same transposed size

BLSplay 1.5.0
- display v=* when voices are off (optimized)
- little optimization in ASM version

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

Re: Blitter sound routine

Postby dhedberg » Mon Jun 25, 2018 9:30 pm

Looks like it's keeping you busy! Any hope for a remote entry at Sommarhack? :wink:
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo MORE.

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

Re: Blitter sound routine

Postby metalages » Mon Jun 25, 2018 9:43 pm

Yep, using it brings me to some necessary adjustements ;)
Too short unfortunately for Sommarhack.
But some design for a musik disk is currently growing in my mind ;)

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

Re: Blitter sound routine

Postby dhedberg » Tue Jun 26, 2018 6:06 am

That sounds great as well! Looking forward to get my hands on that music disk! :D
Daniel, New Beat - http://newbeat.atari.org. Like demos? Have a look at our new Falcon030 demo MORE.

MarkP
Atarian
Atarian
Posts: 5
Joined: Tue Jul 31, 2018 10:22 pm

Re: Blitter sound routine

Postby MarkP » Wed Aug 01, 2018 1:05 am

Awesome new 2018 concept ... needs to be bumped up regularly :-)

...sort of annoyed even that I just thought of a very similar thing yesterday whilst idly flipping past some blitter infos and realising it need not necessarily be used for graphics but could also be an answer to the STe's audio shortcomings vs the Amoeba, ie no hardware multichannel mixing and only four hardwired replay rates with both channels locked to the same rate as each other, so the CPU ends up doing the heavy lifting for live resampling instrument patches and downmixing them into the RAM buffer... even though those are both things the Blitter is built to do much faster and more efficiently (and in 2D to boot, not just the 1D needed for audio), and nominally in parallel with other processing (OK, it steals CPU cycles, but there's no need to use timer interrupts that waste time pushing and popping the stack, or cycle-count your way through multiplexing audio routines with your other code; you just throw values into its registers and then allow for the slowdown it causes to your other processes).

But that was 6+ months after Metalages also had the same thought, it turns out, and I had no idea if it could actually work, or do so whilst being tuneful or sounding any good. Plus I don't have an STe and can't code, so pretty glad to see someone else who can actually do the work thought of it first :-)

Just in case it's relevant - and I know I've just written this in another thread anyway - if you're still chasing stubborn timing issues on different machines, have you accounted for the DMA system having its own clock that's not related to the main system clock? As in it runs an entirely separate crystal, but one that's close enough to the CPU/bus clock that it can deceive you into thinking that they're locked together? So the relationship is different depending on whether your machine is PAL or NTSC (and maybe also different in the MSTe/TT vs the regular STe), and could even vary machine to machine, hour to hour as different parts of the board warm up to different temperatures and pull the frequencies up or down slightly. It might therefore be worth not bothering with a fixed ratio and instead making a quick measurement of DMA vs system speed ratio each time the program is loaded... It'd help with using the routine alongside a YM replayer as well for ~9 channels of simultaneous output (3 squares, noise, envelope and/or timer, and 4 channels of DMA) whilst keeping them fully in tune and in time with each other. As well as ironing out those insidious clicks.

(Also, for killing that kind of transient - have you considered turning on/adjusting the low-pass filters, and using the microwire EQ to recover some of the treble otherwise lost by doing so? Removing spurious clicks and other types of high frequency interference, including the aliasing artefacts caused by the simplistic nearest-neighbour stretch that's all we can practically do at the data level in a single-digit-MHz computer, is essentially what they're there for in the first place, same as in the Amiga and SNES...)

What frequency is that btw? The full 50kHz? It certainly sounds wideband enough to be more than 25... So if you're able to do 4 channels of 50kHz in 10~16% of a frame... would 8 channels be doable, in 20~32%? Maybe even more? Though as we only have 2x 8-bit DACs to output through, rather than 4 of them, or being able to chain two per speaker into virtual 14-bit, the quality might start to suffer and things might start to disappear into the noise floor even at 8ch. Seeing as we have so much time left over (with the actual output stage at this point being "free", as it happens in what would otherwise been video cycles if not for blanking), perhaps we can do some further hardware mixing, put three virtual channels through each of the physical DMA channels, and another three through the YM using the usual sample replay routines (...which might also be blitter-augmentable, including for wanging values into the YM registers?) for 9 fairly clear digital channels (3 left, 3 right, 3 centre... though the choice ends up being between the centre ones being somewhat louder than the others, or rather noisier... cheers Atari) as an alternative to 6 digital + the more standard PSG output?

...maybe even stretch it right out, produce a fourth digital stream, and send it to a Covox plugged into the printer port, and through a modded monitor cable to feed its output back down the "audio in" line (...or produce spatial stereo in opposition to the YM's flat mono by splitting it and connecting the two outputs respectively in-phase with Left and reverse-phase with Right... or even doing a version of the internal "stereo YM" mod to decouple the PSG from the normal output, running it to a separate single RCA, and using a couple of 2-into-1 RCA splitter/joiners to put YM-whatever on the left channel, covox on the right...), and having 2 to 4 logical channels running through each of the physical Covox, YM-digital and two DMA channels, for 8/12/16 total and not too much noise... and still some CPU time left over to do non-audio things.

(Could they even then be used to extend the effective sampling depth, much like chaining Amiga channels, if the Covox output - ultimately coming from the YM's IO port after all - might be similarly louder than the DMA as the YM is... so the two channels working their way through the YM could work as the MSBs, truncated wherever the YM's effective noise floor is, and the DMAs working as the LSBs? Should be possible to get at least 12-bit effective resolution with a bit of careful tuning, which in most listening environments will sound rather closer to 16-bit than to 8-bit... Also, can the actual DMA controller - rather than the Shifter's DMA capability - be used to stuff bytes into the YM parallel IO instead of the CPU or blitter having to do it? Or is it not sufficiently programmable to make that at all useful? ... Heck, is there enough flexibility in the ASCI port to hook a simple 8-bit DAC into that as well and provide 4 proper 8-bit PCM channels, or even 2 proper 16-bit ones if its output and that of the Covox can either be amplified to make their LSBs 2x the level of the DMAs' MSBs, or their MSBs 1/2x the level of the DMAs' LSBs? ... actually, could probably skip the YM internal mod, and just split the Covox output into two 4-bit channels which could be either the most or least significant bits of a 12-bit system, and the PSG can be left to work as a pure synth, or fall back to being a centre-channel-only 5-to-6-ish bit PCM source)

Aaaaaaaaaaaaaaaaaah so many possibilities still.
And that's without even thinking about the possibility of building something that can connect to the video port and sample the first and/or last 16 pixels of a heavily overscanned line to turn into audio somehow... one word per line makes for two more 8-bit channels at ~31.5kHz after all, and that's something that can be very definitely blitted. Though the palette would be an issue (as would clocking) as ideally we'd want the 16-level greyscale or colours that downconverted to similar somehow.

(though the historic answer of course was just to build something that connected to the cartridge port and directly turned the low 16 address bits into analogue audio levels for the left or right channel depending on which CS line was driven high and when, maybe with its own clock and FIFO...)

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

Re: Blitter sound routine

Postby metalages » Wed Aug 01, 2018 9:43 pm

Hi Mark,

Thanks for the great feedback :) It will take time for me to analyze all this ;)

Some elements to begin :

About the DMA timing I have received great advices from Nicolas Pomarede.
Currently the routine expects the DMA to play between 2000 and 2004 samples per 20 ms frame and adapt dynamically to catch up by re-assigning the play adresses on the fly while the DMA plays in loop mode.

The DMA runs at 50khz but the 4 voices are computed at 25khz and interlaced (instead of added as the blitter is good at interlacing but bad at adding).
It creates interlacing artifacts around 25khz that are out of audio spectrum, but if we want to interlace more voices like 6 voices for example, it means we will get these artifacts around 16.6 khz. I have not even tried but I guess the result will be unacceptable. This means we are stuck on 4 voices for the DMA voices with this technic. But I am pretty sure using the YM in the same time would be really great :)

Currently I have not played with the Microwire EQ but it is possible to set it as the routine does not touch it.
I have only wired the balance to be able to assign left / right levels from the .mod score to offer a possible alternative to the constraining volume effect by bit shiftting.

I need more time to analyze your other ideas :)

User avatar
arcx
Atariator
Atariator
Posts: 23
Joined: Tue Jan 19, 2016 12:13 am

Re: Blitter sound routine

Postby arcx » Thu Aug 02, 2018 12:24 pm

Wow,cool idea,although some limitations to it obviously.

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

Re: Blitter sound routine

Postby metalages » Thu Aug 02, 2018 8:53 pm

Thanx :)

My first goal with this routine was to have a sound routine :
- using STe DMA sound
- that do not take too much CPU time in order to be used in a demo or a game. Currently it fits into the upper border (50hz) which is really convenient...
- that can fits some minutes of musik on a floppy, which is hard to achieve with a streaming approach (even with a clever sequence)
- that do not take too much RAM to allow your whole application fitting in 1mb (remains challenging with BLSnd when you create your .mod ...)

My first ideas were focussed on providing sound throught DMA PCM in an acceptable amount of CPU / storage space, no really like Mark propose : having a maximum of sound replays in the same time. But this another possibilty that can be considered...
The first obvious one would be to have regular YM chiptune capabilities in the same time like I was planning to have with my first two voices prototype in 2016.

What appears with my first tries composing a dedicated .mod is that :
- it is do-able :)
- using YM in the same time would be a good complement as it has very different constraints. In particular it would provide a way to have portamienti into the tune that BLSnd is unable to provide...

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2407
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Blitter sound routine

Postby charles » Thu Aug 02, 2018 9:15 pm

metalages what exactily are u replaying ,,im a midi guy so samples are familiar but not very clear on what your doing with sound ...are u playing a whole file as a song , or do u have music data sequencing samples ?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

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

Re: Blitter sound routine

Postby metalages » Thu Aug 02, 2018 9:28 pm

It uses a format that is close to Amiga .MOD format (reason why I currently use regular soundtrackers to edit songs).
In this file format you have both a samples table and then score data.
Score data is composed of a list of patterns that tells which sample to play on which key, which effect to apply...

My BLS format contains some pre-computed values to make the replay routine inits simpler but it basically contains the same kind of stuffs that you can find in a regular .MOD file (many MOD format descriptions are available on the net, for instance http://www.textfiles.com/programming/FO ... d-form.txt)


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 0 guests