Amiga.org

The "Not Quite Amiga but still computer related category" => Amiga Emulation => Topic started by: bloodline on March 24, 2012, 10:11:59 AM

Title: Paula Audio Emulation AudioUnit
Post by: bloodline on March 24, 2012, 10:11:59 AM
Some time ago (2006 I think) Karlos and I were discussing the nonlinear nature of the Amiga's audio DACs and how that might colour the audio reproduction of samples.

Put simply the Amiga's audio DAC should take a number (henceforth known as a sample) and then produce an electrical voltage that is proportional to that number. Although the Amiga uses signed 8bit numbers, and positive and negative polarities the following simplified example should make it a little clearer:

A DAC can output any value between 0 and 5 volts, the Amiga has an 8bit audio DAC with means the output is divided into 256 discrete values, thus:

   0 -> 0.0000 volts
   1 -> 0.0195 volts
...
128 ->2.5000 volts
...
234 -> 4.5703 volts
...
255 -> 5.0000 volts

You get the idea...

And by altering the voltage a few thousand times every second, the Amiga can reproduce an audio signal.

But as mentioned above, the Amiga's DACs are nonlinear meaning they don't produce exactly the voltage one would expect... This is probably due to design limitations, engineering considerations and manufacturing defects, however it contributes to what makes the Amiga's audio output rather distinctive.

After some work, with Karlos's help, I managed to build a calibration table which listed the difference between the expected output value and the real output value which I wanted to use to colour an audio signal.

Now when playing an 8bit audio recording on 16bit hardware (i.e. modern audio hardware), each sample is simply multiplied by 256 to give the 16bit value... but I used my calibration table to give the value that real Amiga hardware would produce rather than what should have been produced.

For example:

The 8bit sample of 120 (Signed) would give a 16bit sample of 30720, but a real Amiga would have a value of 30816... simple :)

Ok, I have worked on and off on this idea for a few years, and last weekend I had a bit of free time and built a static converter to take an 8bit audio sample and then output a 16bit sample with the Amiga audio "distortion", to really see how much of a difference it makes:

First the original 8bit sample (depending upon your audio hardware this should sound the same as the linear upscaled 16bit version):
http://www.troubled-mind.co.uk/paula/ergo8.aiff (http://www.troubled-mind.co.uk/paula/ergo8.aiff)

Now the Linear upscaled 16bit version (using simple mathematical conversion)
http://www.troubled-mind.co.uk/paula/ergo16.aiff (http://www.troubled-mind.co.uk/paula/ergo16.aiff)

Now the Amiga distortion emulation 16bit version:
http://www.troubled-mind.co.uk/paula/ergopaula.aiff (http://www.troubled-mind.co.uk/paula/ergopaula.aiff)

If I'm really honest I can't tell the difference between them, I'm not sure that it was worth the effort... some feedback would be most welcome :)
Title: Re: Paula Audio Emulation AudioUnit
Post by: ChaosLord on March 24, 2012, 10:20:03 AM
I was always under the impression that the nonlinearity depended on which volume level you were playing the sample.  I have no idea how that idea got into my head. :)

I always thought it was the 64 volume levels that were nonlinear, not the -128 to +127 sample bytes.

I donno... Just throwing ideas around :)
Title: Re: Paula Audio Emulation AudioUnit
Post by: minator on March 24, 2012, 12:52:43 PM
Quote from: bloodline;685048
If I'm really honest I can't tell the difference between them, I'm not sure that it was worth the effort... some feedback would be most welcome :)


The non-linearity will produce a wave shaping effect.  I'm guessing it'll might be quite subtle.

Test it with something like a sine wave.  If it's adding many harmonics you'll notice it then.

I'd imagine the fact it's 8 bit and especially the variable sample rate would make a rather bigger difference.
Title: Re: Paula Audio Emulation AudioUnit
Post by: Jpan1 on March 24, 2012, 01:21:48 PM
I think human audio capabilities reach up to 20,000khz so I wonder if the difference can really be noticed when listening, although, mathematical there is a difference in audio...but it's hard to distinguish, especially if audio has been re-sampled in emulation. I have problems with timing in emulated audio, that is, when making tracker songs, emulation does not seem so accurate or 'punchy' as it would do if it were played on a real Amiga. I was always impressed by the Aura sound card, and I had the 12bit playback version, which played mono samples, with an audible difference, yet, getting that to play alongside 8-bit sample, proved to be more difficult...which was a shame because I'd anticipated that my basic 4 channel would be for the drum and bass riffs and the extra 12-bit channel would allow for ambient string samples to be played at the same time.
Title: Re: Paula Audio Emulation AudioUnit
Post by: cicero790 on March 24, 2012, 02:14:35 PM
Thanks for explaining that Bloodline. I think I'm getting it for the first time. :biglaugh:
I don't know if my ears play a trix on me but the “nom” in “ergonomically” seems to have a slighter more volume as in solid substance to it, in the linear upscaled 16bit. Just in the bridge between “o” and “m”.  Isn't there something happening there in the lower register?
Title: Re: Paula Audio Emulation AudioUnit
Post by: itix on March 24, 2012, 04:00:01 PM
Quote from: Jpan1;685074
I think human audio capabilities reach up to 20,000khz so I wonder if the difference can really be noticed when listening, although, mathematical there is a difference in audio...but it's hard to distinguish, especially if audio has been re-sampled in emulation. I have problems with timing in emulated audio, that is, when making tracker songs, emulation does not seem so accurate or 'punchy' as it would do if it were played on a real Amiga.


There are delays in replayer routines you dont really notice but when played in faster Amiga you notice it sounds slightly different. It is very subtle but it is there.
Title: Re: Paula Audio Emulation AudioUnit
Post by: TheBilgeRat on March 24, 2012, 04:24:59 PM
Quote from: bloodline;685048
Some time ago (2006 I think) Karlos and I were discussing the nonlinear nature of the Amiga's audio DACs and how that might colour the audio reproduction of samples.

Put simply the Amiga's audio DAC should take a number (henceforth known as a sample) and then produce an electrical voltage that is proportional to that number. Although the Amiga uses signed 8bit numbers, and positive and negative polarities the following simplified example should make it a little clearer:

A DAC can output any value between 0 and 5 volts, the Amiga has an 8bit audio DAC with means the output is divided into 256 discrete values, thus:

   0 -> 0.0000 volts
   1 -> 0.0195 volts
...
128 ->2.5000 volts
...
234 -> 4.5703 volts
...
255 -> 5.0000 volts

You get the idea...

And by altering the voltage a few thousand times every second, the Amiga can reproduce an audio signal.

But as mentioned above, the Amiga's DACs are nonlinear meaning they don't produce exactly the voltage one would expect... This is probably due to design limitations, engineering considerations and manufacturing defects, however it contributes to what makes the Amiga's audio output rather distinctive.

After some work, with Karlos's help, I managed to build a calibration table which listed the difference between the expected output value and the real output value which I wanted to use to colour an audio signal.

Now when playing an 8bit audio recording on 16bit hardware (i.e. modern audio hardware), each sample is simply multiplied by 256 to give the 16bit value... but I used my calibration table to give the value that real Amiga hardware would produce rather than what should have been produced.

For example:

The 8bit sample of 120 (Signed) would give a 16bit sample of 30720, but a real Amiga would have a value of 30816... simple :)

Ok, I have worked on and off on this idea for a few years, and last weekend I had a bit of free time and built a static converter to take an 8bit audio sample and then output a 16bit sample with the Amiga audio "distortion", to really see how much of a difference it makes:

First the original 8bit sample (depending upon your audio hardware this should sound the same as the linear upscaled 16bit version):
http://www.troubled-mind.co.uk/paula/ergo8.aiff (http://www.troubled-mind.co.uk/paula/ergo8.aiff)

Now the Linear upscaled 16bit version (using simple mathematical conversion)
http://www.troubled-mind.co.uk/paula/ergo16.aiff (http://www.troubled-mind.co.uk/paula/ergo16.aiff)

Now the Amiga distortion emulation 16bit version:
http://www.troubled-mind.co.uk/paula/ergopaula.aiff (http://www.troubled-mind.co.uk/paula/ergopaula.aiff)

If I'm really honest I can't tell the difference between them, I'm not sure that it was worth the effort... some feedback would be most welcome :)


Pish Tosh - Science is worth it!  You may not tell a difference, but I bet there's some audiophile out there who possibly could.  The oscilloscope never lies at any rate :D

Very cool writeup!
Title: Re: Paula Audio Emulation AudioUnit
Post by: bloodline on March 24, 2012, 05:32:25 PM
:) thanks for your comments guys!

I'm thinking that the nonlinear nature is effectively dithering the sample... Which "should" improve the quality of a poor quality sample. I chose the "Ergonomically..." Audio as it is a classic well known 8bit sample from a 1991 Amiga game and it was easy enough to rip it.

My next test will be to record a clean 16bit audio at 44100, then down scale it using the best algorithms my expensive audio software can do, into 8bit 15040Hz and then run it through my static converter and see I we can hear the difference :)
Title: Re: Paula Audio Emulation AudioUnit
Post by: paul1981 on March 24, 2012, 06:44:52 PM
I always thought that the Amiga's distinctive sound was because of it's poor quality basic DAC with no oversampling/interpolation like what a real audio DAC should have (such as any CD player or sound card).
I'm not knocking Paula, I like it as well, but I just assumed that was the reason.

Even with well calibrated 14-bit output (Cybersound), at 44.1 KHz, the top end is still noticeably grainy (truthful to real CD quality if you like), and I'm guessing it's simply to do with total lack of oversampling/interpolation. The audio filter built into the Amiga can clean the distortion up to some extent.
Title: Re: Paula Audio Emulation AudioUnit
Post by: Thorham on March 24, 2012, 07:26:06 PM
Quote from: bloodline;685048
the Amiga has an 8bit audio DAC
No, it has a 14 bit dac.
Title: Re: Paula Audio Emulation AudioUnit
Post by: bbond007 on March 24, 2012, 10:35:53 PM
Quote from: paul1981;685112
I always thought that the Amiga's distinctive sound was because of it's poor quality basic DAC with no oversampling/interpolation like what a real audio DAC should have (such as any CD player or sound card).
I'm not knocking Paula, I like it as well, but I just assumed that was the reason.


To me Paula sounded a lot better than the Sand Blaster and Sand Blaster Pro, as I recall having those boards. I even had the original "Game Blaster" for a which which was like having 12 of the stock PC speakers going at once.

I wonder if this Paula audio emulation technology could be used to give FPGA based Amigas more accurate sound?
Title: Re: Paula Audio Emulation AudioUnit
Post by: Karlos on March 24, 2012, 11:10:46 PM
Quote from: bloodline;685048
If I'm really honest I can't tell the difference between them, I'm not sure that it was worth the effort... some feedback would be most welcome :)


Didn't we also conclude that aliasing played a big part in the colouring of Paula's audio?

I found that for certain bright sounds, like cymbals, there were quite noticeable effects as you approached the regular PAL 27kHz playback limit, specifically a bit like the old aphex corp's "aural exciter" effect.
Title: Re: Paula Audio Emulation AudioUnit
Post by: gertsy on March 24, 2012, 11:30:48 PM
Quote from: Karlos;685140
Didn't we also conclude that aliasing played a big part in the colouring of Paula's audio?

I found that for certain bright sounds, like cymbals, there were quite noticeable effects as you approached the regular PAL 27kHz playback limit, specifically a bit like the old aphex corp's "aural exciter" effect.


The mild "cymbal like" distortion on the "fff" in the word "Terrific" has the legacy 8bit signature all-over it.  Well according to my cloth ears anyway.  
I can't tell the difference.  I'm guessing with your loud music history you suffer the same disability Bloodline.
Title: Re: Paula Audio Emulation AudioUnit
Post by: ChaosLord on March 25, 2012, 02:56:48 AM
Quote from: Bloodline
the Amiga has an 8bit audio DAC
Quote from: Thorham;685118
No, it has a 14 bit dac.

Thorham is correct.  The Amiga has at least a 14 bit DAC.  It might even have a 16-bit DAC where 2 of the bits are permanently unusable.
Title: Re: Paula Audio Emulation AudioUnit
Post by: bloodline on March 25, 2012, 09:54:33 AM
Quote from: ChaosLord;685181
Thorham is correct.  The Amiga has at least a 14 bit DAC.  It might even have a 16-bit DAC where 2 of the bits are permanently unusable.
Not really, you can't count the 6 volume bits when talking about audio reproduction. The Amiga's audio chip is fed with 8bit signed integer values and at full volume, the DAC is an 8bit DAC... So those extra 6bits are simply altering the maximum output value, the resolution of the input remains 8bit.

Ok, if you are prepared to lose an audio channel, then you can modulate the volume in time with the audio sample and get 14bits... But that is a special case and not part of what I'm trying to do :)
Title: Re: Paula Audio Emulation AudioUnit
Post by: bloodline on March 25, 2012, 10:00:23 AM
Quote from: Karlos;685140
Didn't we also conclude that aliasing played a big part in the colouring of Paula's audio?

I found that for certain bright sounds, like cymbals, there were quite noticeable effects as you approached the regular PAL 27kHz playback limit, specifically a bit like the old aphex corp's "aural exciter" effect.
Indeed, once I get the resolution issues sorted (An idea hit me last night at the pub with some friends)... I will look at how to recreate the effect of the amiga sample rates...
Title: Re: Paula Audio Emulation AudioUnit
Post by: ChaosLord on March 25, 2012, 01:47:13 PM
Amiga has a 14-bit (or more) DAC.

You are confusing the sample size with the DAC size.  The samples are sadly, only 8-bits, but they happily get 6 bits of volume control added to them for a total of 14 bits that the DAC outputs.

If the DAC was only 8-bits then the volume control registers would have no effect and all Amiga mods would sound like crap.
Title: Re: Paula Audio Emulation AudioUnit
Post by: Karlos on March 25, 2012, 02:42:33 PM
Quote from: ChaosLord;685284
Amiga has a 14-bit (or more) DAC..


You are talking cross purposes. Bloodline isn't trying to reproduce 14-bit replay, he's trying to reproduce how 8-bit audio sounds when it's played back through the DAC at a given volume.

The output precision of Paula itself is not what is being modelled here, it's the response behaviour.

Paula is very non-linear. For a fixed channel volume, the output does not vary linearly as a function of the input 8-bit sample. Likewise, the output does not vary linearly as a function of channel volume for a fixed input 8-bit sample value.

Finally, these variances themselves change from one Paula to another.

The guy (sorry, the name escapes me just now) that wrote the original 14-bit Cybersound driver that was later assimilated into AHI was well aware of this. He developed a calibration tool that relies on the user manually eliminating a simple square wave (IIRC) across a spread of input values by adjusting a set of scaling factors. The idea was that for each input value, you had to adjust the scaling factor until the square wave was as inaudible as possible.

It was my original suggestion to Bloodline that the resulting calibration table should contain the necessary data (likely requiring some inversion) for his proposed application.

We then went on to discuss other factors affecting the audio. On the digital side, there is sample aliasing and on the analogue side, the frequency response (always kinda bassy to my ear) of the op-amps that boost the output from the DAC and, of course, the low pass filter (if enabled).
Title: Re: Paula Audio Emulation AudioUnit
Post by: Bif on March 26, 2012, 06:17:52 AM
Cool research. If you want to be serious about knowing if the changes you make are truly audible and not a placebo effect you should be performing ABX tests: http://wiki.hydrogenaudio.org/index.php?title=ABX

It may sound silly if you have never been exposed to it but the brain plays surprising tricks on you, especially when you start to think of audio with warm nostalgic feelings - you perceive it that way even if it isn't.

In what you have done so far you can try to ABX the non-linear vs. linear response to see if you can confidently hear a difference.

If you get Paula better emulated via crude resampling/etc. then you probably want to ABX against what you do in software and an actual recording of the Paula, ensuring they are level matched and time aligned. Heck if you can get that close you could just start to compare the recorded audio files directly to check for bit differences to see how close you are.

I'm not a Paula guru, but I would also suspect it is the crude and noisy/aliasing resampling + 8-bit that provides most of the distinctiveness of the output you hear, not so much the non-linearity.
Title: Re: Paula Audio Emulation AudioUnit
Post by: Thorham on April 29, 2012, 11:59:49 AM
Quote from: TheBilgeRat;685089
You may not tell a difference, but I bet there's some audiophile out there who possibly could.
With 8 bit samples at maximum volume, no, but with 14 bit playback, the soft parts of a sample will sound noisy.

Quote from: bloodline;685248
Not really, you can't count the 6 volume bits when talking about audio reproduction. The Amiga's audio chip is fed with 8 bit signed integer values and at full volume, the DAC is an 8 bit DAC... So those extra 6 bits are simply altering the maximum output value, the resolution of the input remains 8 bit.
No, the 6 volume bits are part of the DAC. 8 bits are used for the sample, 6 bits are used for the volume.

Quote from: Karlos;685293
You are talking cross purposes. Bloodline isn't trying to reproduce 14-bit replay, he's trying to reproduce how 8-bit audio sounds when it's played back through the DAC at a given volume.
Which means it's perfectly relevant that Paula is 14 bit, given that 6 bits are used to control volume. Especially in MODs that use different volumes all the time, this may be important.

Generally speaking these non-linearities will result in some noise, and probably nothing more. The only thing that's special about the Paula is the ridiculous speed at which it can operate when using the CPU to feed it with data.