Mixing 2 audios for STE DMA sound

All 680x0 related coding posts in this section please.

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

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Mixing 2 audios for STE DMA sound

Postby AtariZoll » Tue Jan 20, 2015 9:44 am

I'm thinking about doing same music mod (playing longer soundtracks) with Giana Sisters, as did with Xenon 2. There is lot of remixes, soundtracks DL-able.
Natural choice is STE, scrolling version done by Zamuel_a , because this will work only on STE and higher HW.
And as he made sound effects via DMA, while music is via PSG , we have to solve mixing of sound effects into music .
It will need some CPU time, but good thing is that will get rid from unbalanced PSG-DMA volume levels.
So, all sound will go via STE audio DMA.
I don't have any experience with this, just thinkered little:
Should do adding of 2 audio inputs, but it works not so simple with signed ones. To avoid overflow, should have 2 inputs at half amplitude . Fastest way would be to use unsigned inputs, at max value of $7F, then adding them, and after that doing signing.

Code: Select all

move.l #$80808080,d1

loop:
move.l  (a0)+,d0   * music buffer
add.l  (a1)+,d0   * effect buffer
add.l  d1,d0   * signing
move.l  d0,(a2)+   * Output buffer
...

Little faster, by adding sound effect directly to music buffer:
loop:
add.l (a1)+,(a0)
add.l d1,(a0)+
...


Anyone has experience with this ?
Zamuel_a - what think about idea, and do you want to work little on this - should do conversion of effect samples, as described above, + some other not so time consuming things.
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

User avatar
exxos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 4933
Joined: Fri Mar 28, 2003 8:36 pm
Location: England
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby exxos » Tue Jan 20, 2015 1:53 pm

I don't know about software solutions, So can't suggest much. Though it would be possible with hardware mods, though would need to route the PSG though its own volume control circuit, and route control to it into some register address in RAM. Or re-wire the LMC so you can use better audio inputs and outputs but still lot of hacks either way. Or just change volume of your music on SD card ;)
4MB STFM 1.44 FD- VELOCE+ 020 STE - Falcon 030 CT60 - Atari 2600 - Atari 7800 - Gigafile - SD Floppy Emulator - PeST - various clutter

http://www.exxoshost.co.uk/atari/ All my hardware guides - mods - games - STOS
http://www.exxoshost.co.uk/atari/last/storenew/ - All my hardware mods for sale - Please help support by making a purchase.
http://ataristeven.exxoshost.co.uk/Steem.htm Latest Steem Emulator

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Thu Jan 22, 2015 8:47 am

It is not at all about mixing PSG sound with DMA sound - what is solved now, I think. Doing all sound via STE audio DMA is the aim.
So, we do mixing in SW, because it is only way. Therefore this is here, in coding section. Somebody wake up Zamuel :)
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Mon Feb 16, 2015 8:35 am

First working version is done - see viewtopic.php?f=3&t=26360&start=300#p268291
But in meantime I thinkered little about how to make mixing fastest possible. With proper preshifting of 2 audio sources, which must have reduced volume - amplitude max $7F, we can do mixing in less steps. Goal is to get signed content with max amplitude of $FE for audio DMA .
Since samples in Giana are with 12517 Hz, I converted music on same too. But better would be with higher one. Then mixing with 2x, or 4x lover samplerate effects is still possible - just need to mix same byte 2 or 4x in row.
Another way, what requires not mixing via SW would be to use stereo, where music is on 1 channel, and effects on other. But that will eat 2x more space on disk - because 2 channels are interleaved in stereo mode.
So, there is still what to experiment :D
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Mixing 2 audios for STE DMA sound

Postby Zamuel_a » Mon Feb 16, 2015 7:54 pm

One way to mix sounds are to multiplex them. If you want a 25khz output, you set the playback rate to 50khz and let one sample use every even byte and the other sample use the odd bytes. This way, the samples are "added" together perfectly
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Mon Feb 16, 2015 9:10 pm

Zamuel_a wrote:One way to mix sounds are to multiplex them. If you want a 25khz output, you set the playback rate to 50khz and let one sample use every even byte and the other sample use the odd bytes. This way, the samples are "added" together perfectly

That's interesting way - but I'm not sure that audio quality will be really good. Need to test. And it has disadvantage that need double datarate for reading from disk, while effects may play only small % of time. If go double rate, I think that better is to go on music on 1 and effects on another channel.
After some thinking, I went on following: music mono at 25033 Hz, samples stay at 12517 Hz . Need to ensure that amplitude of each goes not over $3F and below $C0 - then can simply add them without distortion. And best result is when add bytewise - then no problems with overflow. Code looks like:

Code: Select all


* a2 - effect address
* a0 - music address - what follows in 1/25 sec approx.

mixL1      *  8 bytes
   move.b   (a2)+,d1
   add.b   d1,(a0)+
   add.b   d1,(a0)+

   move.b   (a2)+,d1
   add.b   d1,(a0)+
   add.b   d1,(a0)+

   move.b   (a2)+,d1
   add.b   d1,(a0)+
   add.b   d1,(a0)+

   move.b   (a2)+,d1
   add.b   d1,(a0)+
   add.b   d1,(a0)+
   
   dbf   d5,mixL1


With 25033 rate you need to mix 512 bytes in eery V-blank.

How it looks on Falcon:
http://youtu.be/h-2zFoLW1Pw
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Mixing 2 audios for STE DMA sound

Postby Zamuel_a » Mon Feb 16, 2015 9:18 pm

That's interesting way - but I'm not sure that audio quality will be really good.


I did some tests a few years ago with this. It was on PC to test the theory. I tried both this way and having 2 7 bit samples that I added together to get a maximum of 8 bit. The multiplexer sounded better since you still have full resolution.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Tue Feb 17, 2015 10:40 am

I tried that mixing way, and it is not that good. Samples just sound not good, and their volume is low too. Yes, you can keep music at 8 bit res. , but I want good effects too.
Third way would be to keep music at 8-bit, and halving it's amplitude only when sound effect is on, for mixing - but that way silences music self during effect, what I don't like. So, I will stay at 7-bits . Key is proper processing of music file - reducing it's dynamic , vie leveling, what is better than normalize.
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: Mixing 2 audios for STE DMA sound

Postby Zamuel_a » Tue Feb 17, 2015 4:53 pm

I tried that mixing way, and it is not that good. Samples just sound not good, and their volume is low too. Yes, you can keep music at 8 bit res. , but I want good effects too.


Sound volume will of course be 50% but the mixing should be good since it's "true analog mixing". But I have only tried it on PC so don't know how it sounds on the Atari.
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Tue Feb 17, 2015 6:23 pm

Hardly can agree with your "true analog mixing" . I would call it messy mixing. And I said that effects are what is silencer. Maybe because their lower samplerate. In any case, this is something what is bad in theory and in practice. This thread was just waste of time.
Next time try without "should be good" - we need "IS good" :lol:
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 769
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Mixing 2 audios for STE DMA sound

Postby mfro » Tue Feb 17, 2015 6:34 pm

I guess this will help you (although it's probably disappointing how much computation is necessary for the signed mix).

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Mixing 2 audios for STE DMA sound

Postby AtariZoll » Tue Feb 17, 2015 7:41 pm

That's interesting article. But in this case totally not usable - multiple is slow with MC68000 - using that normalization would take too much CPU time. And I actually don't want to normalize. More natural is simple adding two tones.

Here is code, for max amplitude music input - what will play with max. amplitude when no effect sound. If there is effect sound audio needs to be silenced to 50%, and mixed with already silenced to 50% effects - to save some CPU time.

Code: Select all

a0 - music address
a1 - effect address

move.b  #$80,d2
moveq   #$40,d3

loop
move.b (a0),d0   * -$80 - $7F   signed
sub.b  d2,d0    * unsigned  0-$FF
lsr.b   #1,d0   * unsigned    0-$7F
sub.b  d3,d0   * signed  -$40-$3F
add.b  (a1)+,d0    *  (a1) signed , range  -$40-$3F
move.b  d0,(a0)+
dbf  d7,loop



This is still enough fast, but I don't like that music will get silencer during effect, so rather go on music with 7 bits.

As best solution considering quality on STE I consider using left channel for music, and right for effects. But it will eat 2x more disk space, because interleaved L-R tracks, so we need to store silence on right track. Actually, with special IDE code we can write during load of audio track 1 zero after every loaded byte, but with ACSI it is not possible - DMA writes in order to RAM. IDE code will work much slower than by loading in order - about 250 KB/sec instead 1500 .
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 4 guests