Click Here
home features news forums classifieds faqs links search
6071 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
18 crawler(s) on-line.
 127 guest(s) on-line.
 0 member(s) on-line.



You are an anonymous user.
Register Now!
 NutsAboutAmiga:  17 mins ago
 zipper:  17 mins ago
 clint:  53 mins ago
 RickSkid:  1 hr 3 mins ago
 bhabbott:  1 hr 9 mins ago
 BigD:  1 hr 11 mins ago
 Diane:  1 hr 14 mins ago
 VooDoo:  1 hr 17 mins ago
 A1200:  1 hr 21 mins ago
 pixie:  1 hr 34 mins ago

/  Forum Index
   /  Amiga Development
      /  For Saimo - Gain adjusted Paula audio
Register To Post

PosterThread
Karlos 
For Saimo - Gain adjusted Paula audio
Posted on 2-Aug-2018 18:48:18
#1 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Saimo,

Following on from our interesting discussion regarding audio tricks on Paula, I created a very crude prototype of the companded 8-bit format. There is an encoder and decoder pair, the latter simulates how one may expect Paula replay the 8-bit normalised audio using amplitude modulation for overall frame gain.

It converts the 16-bit audio to 14 bit and analyses the 14 bit data for the maximum absolute values etc. Decoding converts back 16 bit for file output purposes. It doesn't do any gain interpolation between frames and it also assumes that the effect of the volume control register is linear with respect to the reconstruction. The latter may not be true, but that could be corrected for using a lookup table.

Aside from a few clipping bugs which may be due to some off by one error somewhere, the results seem quite promising. The reconstructed audio is audibly much better than basic 8 bit to my ear.

https://github.com/0xABADCAFE/paula-hdr

Beware, this was hacked together on an x86 box so the raw 16-bit files are little endian.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
klx300r 
Re: For Saimo - Gain adjusted Paula audio
Posted on 2-Aug-2018 20:52:06
#2 ]
Elite Member
Joined: 4-Mar-2008
Posts: 3833
From: Toronto, Canada

@Karlos

thanks

_________________
____________________________
c64-2sids, A1000, A1200T-060@50(finally working!),A4000-CSMKIII
! My Master Miggies- Amiga 1000 & AmigaOne X1000 !
mancave-ramblings
X1000 I BELIEVE

 Status: Offline
Profile     Report this post  
saimo 
Re: For Saimo - Gain adjusted Paula audio
Posted on 2-Aug-2018 21:50:48
#3 ]
Elite Member
Joined: 11-Mar-2003
Posts: 2450
From: Unknown

@Karlos

Kudos for immediately turning the idea into actual code - and, of course, also for the contribution to the Amiga world!
Now, please don't be offended, but I'm a bit crazy: as soon as I see alien code and makefiles, I get sick. I'm no computer geek. It infuriates me even just configuring a modem. No kidding. There's a reason why, despite a degree, I've always been looking for a job unrelated to computer science (and, given the situation Italy is in now, I've been unemployed for 2 years now) (Looong story, so I'll end it here.)
I encourage you to keep on working on it, and I wish you to succeed! I'll be glad to hear the results.

_________________
RETREAM - retro dreams for Amiga, Commodore 64 and PC

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 2-Aug-2018 23:02:27
#4 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@saimo

Don't get too carried away its just a proof of concept at a purely code level. There are a few things to do before this can be used as a for real.

First of all I need to dig out a working Amiga and confirm how the volume register affects the actual attenuation of a full range 8-bit sample. My idea here is to create a full range square wave sample and play it in a single channel, dropping the volume from 64 to 1 over some time interval. This can be done trivially in a tracker, capturing the direct output on a nice linear ADC and taking measurements from the waveform.

I'm expecting this to be reasonably linear, but even if it isn't, the function can be extracted from that data.

The second thing is to experiment with actual Paula amplitude modulation, which I've never done. I hope that volume changes applied via modulation are instantaneous and affect the sample pair in the carrier channel as DAC, but it's possible there is some latency here that could complicate things. That can be determined with some synthetic tests and again capturing the output.

Assuming there is no latency then the third step is to write a playback system that can decode this format into sample and volume buffers for AM playback.

I'm interested to take it further, for example applying delta compression to the 8-bit sample data and experiment with longer frame sizes, gain interpolation and actual error estimation based encoding of the frames. It may be that the approach has potential for use cases like your game audio.

If that works then... I guess I'll go back to my 15 bit display emulation idea lol..

Last edited by Karlos on 02-Aug-2018 at 11:30 PM.
Last edited by Karlos on 02-Aug-2018 at 11:28 PM.
Last edited by Karlos on 02-Aug-2018 at 11:24 PM.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 17:17:18
#5 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

I've fixed the clipping bugs in the encoder and the quality is now extremely good. I've added a tool to estimate the RMS error for the entire file and I currently get an error value of 28.77 out of 3036672 samples compared. That is, the average difference between the source 16-bit sample and decoded sample is about 29. That is hugely better than I expected.

The original 16-bit sample used is a volume maximised recording of a drumkit from my tone gen. This was chosen because it has a lot of sounds that cover the full volume range of 16-bit, has noisy ans tuned examples and also has a lot of fast transients. Things which should tax a frame based encoding scheme like this.

I've included the actual source audio, encoded output and decoded output from that.

According to the Amiga Hardware reference docs, the volume control should be linear with respect to the output voltage.

The question now is, can I get Paula to play it?

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
wawa 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 17:56:47
#6 ]
Elite Member
Joined: 21-Jan-2008
Posts: 6259
From: Unknown

@saimo
hey, that makefile contains three lines and three object files:)

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 17:59:41
#7 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@wawa

Let's be honest, it's not a make file. It's a shell script to compile 3 single source executables.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 20:25:56
#8 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

While trying to better understand how Paula's volume control works in order to determine if AM will be instantaneous or have lag, I came across this old thread on EAB

http://eab.abime.net/showthread.php?t=63227

I didn't realise it worked this way, it's truly fascinating. The volume output for each 8 bit DAC is controlled by Pulse Width Modulation, effectively turning the DAC output on and off for some duty cycle (actually between the sample value and zero). The 3.58MHz clock drives a counter that wraps at 63 back to zero, e.g. it completes a full count of 0-63 at a rate of 56kHz. The DAC output is turned on when the AUDxVOL value is greater than the counter. So at volume 64, it's always on, at volume 0 it's never on. At volume 32 it's on for half the duty cycle. This explains why the volume levels are quite linear while the DAC themselves aren't. The fact you can't hear some horrendous high pitched noise from this is probably that the switching rate is basically too high and even the tiniest capacitance in the analogue side would result in some averaging between the on and off state. The latter is just a guess on my part.

This means that under regular PAL modes at 28kHz every instantaneous sample output is subdivided into 128 intervals where the DAC is either on or off depending on the counter versus volume.

This strongly implies there will be no appreciable latencies when doing connected channel amplitude modulation on Paula.

Last edited by Karlos on 03-Aug-2018 at 09:32 PM.
Last edited by Karlos on 03-Aug-2018 at 08:56 PM.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
kolla 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 22:37:56
#9 ]
Elite Member
Joined: 20-Aug-2003
Posts: 2859
From: Trondheim, Norway

@Karlos

Quote:

The fact you can't hear some horrendous high pitched noise from this is probably that the switching rate is basically too high and even the tiniest capacitance in the analogue side would result in some averaging between the on and off state.


Or we're just getting old...

Getting rid of the horrendous high pitched noise was what the CyberSound/14Bit_Calibration tool was all about.

_________________
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 3-Aug-2018 23:17:13
#10 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@kolla

I thought that was just about compensating for non linearities in the DAC so that the summing works better. I don't think the PWM mechanism itself is involved beyond controlling the channel volume.

I'm quite intrigued to find out how feasible my AM approach will be on real HW. Certainly the basic simulation seems to work OK.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Hypex 
Re: For Saimo - Gain adjusted Paula audio
Posted on 4-Aug-2018 8:12:03
#11 ]
Elite Member
Joined: 6-May-2007
Posts: 11180
From: Greensborough, Australia

@Karlos

Quote:
First of all I need to dig out a working Amiga and confirm how the volume register affects the actual attenuation of a full range 8-bit sample. My idea here is to create a full range square wave sample and play it in a single channel, dropping the volume from 64 to 1 over some time interval. This can be done trivially in a tracker, capturing the direct output on a nice linear ADC and taking measurements from the waveform.


Without a real Amiga setup to go the easiest can be programming in UAE with a pre-existing developer environment. I have this on OS4 somewhere. And on all the UAEs I setup up on my laptops over the years I tended to always copy my old A1200 development setup too. Then, once you have something working under emulation, set it up on the real thing.

I wonder if a track introduces latency or if it happens in the hardware itself? Years ago I was experimenting with noise cancellation. I used ProTracker to play two different samples on each stereo pair. One sample was rotated 180 degrees opposite to the other. Mathematically I just negated it. A soft mixer would cancel it out.

What I found was that a sound was still produced. Even though it should have cancelled it out completely. This led me to believe noise cancellation may not be possible. But I didn't know exactly how the hardware mixer worked. And I still don't. So I don't know if there is some delay before samples are mixed on the hardware. I didn't measure the output, just used my ears.

And after all this time I'm still wondering how the hardware actually mixed those channels.

More so, from what I gleamed from above, is that it looks the samples are turned on or off for volume control. This would suggest 14-bit playback isn't possible at all, at least not in the digital sense. And that 8-bit samples are switched on or off. Thus still being 8 bit.

But, can it be used in other ways? To play samples like SACD does? SACD differs from PCM. PCM uses whole values to represent point on the waveform. But by comparison, SACD uses a fast serial 1-bit PCM stream. Yes, each "sample" is only one bit wide. But the sample frequency is much higher to compensate. So it samples at 2.8224 mhz in one bit. Hard to imagine 1 bit samples would work at all. My point is, could Paula be programmed to duplicate this? Given the rate of 3.58Mhz, it would require some advanced coding, but would need AM mode to come close. SACD is 24-bit quality but not stored as such.

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 4-Aug-2018 8:47:13
#12 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Hypex

I'm skipping the volume question for now as I think it has been answered. The channel volume is implemented by PWM and is therefore entirely digital. I'm inclined to think the analogue output goes through some sort of reconstruction filter (not the low pass controllable one) that converts this high frequency chopped up signal into a more continuous voltage.

I will need to confirm that a real Paula chip has no latency when doing volume modulation for my idea to work, but even if it has a latency, as long as it is systematic and predictable it should be possible to work around it.

If the AM route works, if I were to separate the volume and PCM data it means that I could set the modulation channel to a lower period than the PCM one as we only set the volume every N PCM sample pairs (1 volume value per every 16 pcm samples in my test case). This would mean I don't have to fill the modulation channels DMA buffer with duplicate copies which would be needed if it were playing at the same period as the PCM channel. Fewer chip ram writes is always a good thing.

My observation on the data is that the volume data changes in much the same way as the PCM data (no surprise, it's derived from it) and would compress reasonably well with a delta encoding and some lossless compression. The 8-bit PCM data is also compressible using a range of lossy or lossless techniques.*

As it stands, without any such tricks, the reconstructed audio sounds great even though its currently only 8.5 bits per sample in effect.

*this is in contrast to trying to compress 14 bit audio as 8 bit and the lower 6 bits separately where the latter is just too random without doing some form of delta encoding on the original data first.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
saimo 
Re: For Saimo - Gain adjusted Paula audio
Posted on 4-Aug-2018 9:10:31
#13 ]
Elite Member
Joined: 11-Mar-2003
Posts: 2450
From: Unknown

@Karlos

Quote:
I've fixed the clipping bugs in the encoder and the quality is now extremely good. I've added a tool to estimate the RMS error for the entire file and I currently get an error value of 28.77 out of 3036672 samples compared. That is, the average difference between the source 16-bit sample and decoded sample is about 29. That is hugely better than I expected.

Excellent!

_________________
RETREAM - retro dreams for Amiga, Commodore 64 and PC

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 4-Aug-2018 10:32:09
#14 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Hypex

Yes, from what I understand, the DAC are genuinely 8 bit, so true 14-bit replay is impossible. However, it doesn't detract from the actual technique of playing 14 bit by using 2 channels that are being played in sync. In fact, the biggest problem with to existing technique is that the DAC themselves do not linearly convert digital level to voltage, whereas the effect of the volume control is rather linear since the analogue voltage output at any given digital sample point is the time averaged value you would get passing the PWM output through any sort of capacitance or reconstruction filter.

What this means is that, without calibrating for the nonlinearity of the DAC, the 14 bit technique is imperfect, linearly summing the nonlinear analogue output of two DAC. I believe this is what the calibration tool for cybersound was designed to correct.

My approach will have a similar problem in that we are applying linear gain to a nonlinear DAC output. However, as it doesn't rely on summing the output of two channels and the volume envelope affects all 8-bit samples in each frame equally, it probably won't need calibration.

A key difference between this approach and 14 bit replay is that this is inherently lossy. We simply don't store any PCM data better than 8-bit. However, the step size per PCM sample depends on the volume level and therefore the biggest quantization errors (compared to the original 16-bit) are in the loudest frames and therefore not as perceptible. This error per sample falls as the envelope does and thus so does the quantisation noise in quieter frames.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Hypex 
Re: For Saimo - Gain adjusted Paula audio
Posted on 28-Aug-2018 14:44:30
#15 ]
Elite Member
Joined: 6-May-2007
Posts: 11180
From: Greensborough, Australia

@Karlos

Quote:
The channel volume is implemented by PWM and is therefore entirely digital. I'm inclined to think the analogue output goes through some sort of reconstruction filter (not the low pass controllable one) that converts this high frequency chopped up signal into a more continuous voltage.


According to this article it does go through two analog lowpass filters. The LED one (I assume you are referring to) and another it doesn't give much info on:
https://amitopia.com/amiga-was-already-capable-of-14bit-playback-in-1985

What's also interesting I find is that PWM is the basis of SACD encoding.

Quote:
I will need to confirm that a real Paula chip has no latency when doing volume modulation for my idea to work, but even if it has a latency, as long as it is systematic and predictable it should be possible to work around it.


Yes this is what I wonder from my own realtime mixing test. It would also relate to how the audio is mixed. For example if there is some sort of multiplexer involved on each sample timing pulse. If there is some sort of delay between sample output from each channel then it would affect volume modulation the same way. But hopefully not by much to make any discernible difference.

Quote:
This would mean I don't have to fill the modulation channels DMA buffer with duplicate copies which would be needed if it were playing at the same period as the PCM channel. Fewer chip ram writes is always a good thing.


Yes that's a good point. You also conserve with the sample buffer.

Quote:
My observation on the data is that the volume data changes in much the same way as the PCM data (no surprise, it's derived from it) and would compress reasonably well with a delta encoding and some lossless compression. The 8-bit PCM data is also compressible using a range of lossy or lossless techniques.*


I wonder. Why lossy? Hasn't mp3 already destroyed music quality as it is? The Amiga output is of a lower hifi quality as it is. As a comparison I converted some modules into 128Kbps mp3s thinking the lower sample rate quality and resolution would compare well. They sounded crap.

Given your high and low byte streams are at different rates it may make sense, to use the words of saimo, to store them on different byteplanes and compress them seperately.

Quote:
As it stands, without any such tricks, the reconstructed audio sounds great even though its currently only 8.5 bits per sample in effect.


That's good. One thing I wonder, given your 16 step volume envelope, if this affects sample rate? Though 16 is a good number for a computer it likely wouldn't divide into the sample rate, unless it was a multiple of 16.

Quote:
In fact, the biggest problem with to existing technique is that the DAC themselves do not linearly convert digital level to voltage, whereas the effect of the volume control is rather linear since the analogue voltage output at any given digital sample point is the time averaged value you would get passing the PWM output through any sort of capacitance or reconstruction filter.


Given the squarewave interleaving nature of PWM, I've also wondered if a mixing trick can be constructed by interleaving sample data. It would work best on same rate samples. And for each channel added the max rate would halve. So for example instead of adding two samples to mix they instead would be interleaved in stream and sample rate doubled. But i imagine with the samples comtorting the output like that it may just make it noisy.

Quote:
I believe this is what the calibration tool for cybersound was designed to correct.


I found out that not all Amigas have the channels in LRRL order. Some have have them in RLLR order. Well according to AHI, which defaults to the RLLR order. This was he only difference I was aware of. Though I also used CyberSound.

Quote:
However, the step size per PCM sample depends on the volume level and therefore the biggest quantization errors (compared to the original 16-bit) are in the loudest frames and therefore not as perceptible. This error per sample falls as the envelope does and thus so does the quantisation noise in quieter frames.


And also, as I pointed out, any difference in sample rates.

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 28-Aug-2018 22:32:42
#16 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Hypex

Just a short reply for now as I have my hands full. I haven't had time to write a legit Paula playback but have experimented with the encoder and decoder a bit. I have recently dropped all 14 bit pre conversion as it is totally unnecessary in this model.

The latest iteration of the code is on the same github link posted earlier. The current plan is to encode blocks of frames to allow it to be a streaming format. There is a c++ encoder that allows you to specify the frame and block sizes but there's no corresponding decoder yet.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Karlos 
Re: For Saimo - Gain adjusted Paula audio
Posted on 29-Aug-2018 8:56:14
#17 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4394
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Hypex

Just some extra detail. The 16 step was chosen as an experimental starting point. For the maximum sample replay of 28kHz (not sure about dblpal specifics here), the maximum rate we can adjust the volume is only 14kHz since both channels read 1 word each at that period.

However for lower sample rates, given that the modulator period is independent, it might be that you could replay a 1:1 sample/volume stream, though it's unclear if that would really be an improvement over 14 bit.

When I started this, what I was really interested in was if Paula could be a better 8-bit player rather than a poor 16-bit one, by using this whole channel modulation facility. This led me to the notion of an 8-bit format with additional gain envelope. It seemed natural that in this scheme the envelope rate should be less than the sample rate.

The encoder that I am working on takes 2 parameters. Frame length and block length. The frame length is the number of samples (must be even) in a single frame that will be analysed to get a single gain value for normalisation. The block parameter says how many frames will go together into a single decodable chunk. The default is 16:16, so we get a chunk of 256 samples and 16 gain samples. The intent is that this will form a single replay unit for a streaming format.

If you checkout the source, the original raw audio, and simulated decode are in there (44kHz mono 16-bit little endian) and you can see for yourself how well it copes at 1 envelope point per 16 pcm samples.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle