Amiga.org

Amiga computer related discussion => General chat about Amiga topics => Topic started by: Amiga_Nut on August 09, 2010, 08:39:12 PM

Title: Amiga sound playback routine/format questions
Post by: Amiga_Nut on August 09, 2010, 08:39:12 PM
A couple of questions,

Firstly, is there a routine for Blitz Basic to playback 14bit audio via the channel muxxing hack of Paula? And if so does it strip out the extra data from a 16bit sample or do you have to create bespoke 14bit samples?

Secondly, as far as standard 8bit sample playback goes was there any kind of compression/decompression standard or do you have to read out the data uncompressed from memory due to lack of CPU time on OCS? (not expecting MP3 levels of compression! Just wondering if there is anything apart from depacking it from a compressed files to RAM as raw data before playback)

All questions are centred around a bog standard 7mhz OCS/ECS motherboard.

Cheers.
Title: Re: Amiga sound playback routine/format questions
Post by: bubblebobble on August 09, 2010, 08:50:49 PM
Not that I know of.

It's all easily possible with the includes (ADPCM4 Codec, AHI Playback), but not with a 7MHz nacked Amiga.

I wrote a 14bit Audio output routine once for BlitzBasic in inline ASM. But I dont know if I have it still somewere. If you know how to deal with the Paula Registers, 14bit playback is not so hard to do. I also think that the ADPCM4 Codec (4bit per sample) I wrote is fast enough for 7MHz (depends on the Samplerate of course), but I think it would be quite busy then.
Title: Re: Amiga sound playback routine/format questions
Post by: Amiga_Nut on August 09, 2010, 10:43:30 PM
Ahh right wasn't sure if Octamed does the 14bit trick on stock machines. And yes I was thinking Blitz calling a 68k ASM routine :)

At most an anim 5/7 may be playing at the same time, possibly just a static ham6 picture slideshow....not really decided as wasn't even sure it was possible.
Title: Re: Amiga sound playback routine/format questions
Post by: bloodline on August 09, 2010, 11:16:06 PM
14bit audio is quite easy.

Create two 8bit sample buffers the same length, load one with all the highbyte data of the 16bit sample and load the other with the lowbyte data. Set the volume of channel 0 to 1 and the volume of channel 3 to 64 then play both samples back at the same time with the highbyte data in the full volume channel and the lowbyte data in the volume 1 channel. That gives you your left 14bit channel.

Do the same for channels 1 and 2 for your right audio!
Title: Re: Amiga sound playback routine/format questions
Post by: amigaksi on August 10, 2010, 04:52:32 AM
Regarding 8-bit sample decompression, I did that on stock 7.16Mhz Amiga using lossless delta-modulation followed by Huffman encoding.  You can even use Arithmetic encoding to get around 3:1 lossless compression.  Currently, I am just uploading decompressed data from the floppy drive port (from PC) into a queue on Amiga end and I'm easily able to update the queue using 11.025Khz audio and have text/imagery also being uploaded at the same time.
Title: Re: Amiga sound playback routine/format questions
Post by: Britelite on August 10, 2010, 07:38:39 AM
My current IMA Adpcm decoder can play 16Khz/mono/16bit@14bit adpcm-files on a standard A500 straight from memory, and could probably play with even better samplerate with some 000-specific optimizations. Haven't tried streaming files from harddrive yet though.
Title: Re: Amiga sound playback routine/format questions
Post by: bubblebobble on August 10, 2010, 10:33:38 AM
@bloodline

You forgot to mention that the lower byte has to be shifted down 2 bits. This is where the 14bit comes into play. 64 is only 2^6. If they had made the volume control with a granulariy of 256 instead of 64, you could get 16bit playback.

Looseless goes not beyond 1:2 compression. But lossy ADPCM is cheaper to decode and at 8bit sounds pretty good (I cant hear a difference with HQ equipment). It still sounds acceptable at 4bit, but high frequencies get a little rough though.

We had this discussion once already:

PCM 16bit (http://www.hd-rec.de/Archive/FF10_PCM16.wav)
ADPCM 8bit (http://www.hd-rec.de/Archive/FF10_ADPCM8.wav)
ADPCM 4bit (http://www.hd-rec.de/Archive/FF10_ADPCM4.wav)
ADPCM 2bit (http://www.hd-rec.de/Archive/FF10_ADPCM2.wav)

Those are all plain .wav files, but have been encoded&decoded.
Title: Re: Amiga sound playback routine/format questions
Post by: bloodline on August 10, 2010, 10:51:12 AM
Quote from: bubblebobble;574149
@bloodline

You forgot to mention that the lower byte has to be shifted down 2 bits. This is where the 14bit comes into play. 64 is only 2^6. If they had made the volume control with a granulariy of 256 instead of 64, you could get 16bit playback.


Oops, yeah I forgot about that :)
Title: Re: Amiga sound playback routine/format questions
Post by: Piru on August 10, 2010, 11:02:57 AM
Quote from: bubblebobble;574149
@bloodline

You forgot to mention that the lower byte has to be shifted down 2 bits.

As Britelite pointed out at boozembly, plain shifting is slightly wrong though. If you want "perfect" scaling typically you'll use a lookup table.
Title: Re: Amiga sound playback routine/format questions
Post by: bubblebobble on August 10, 2010, 12:43:26 PM
Quote from: Piru;574151
As Britelite pointed out at boozembly, plain shifting is slightly wrong though. If you want "perfect" scaling typically you'll use a lookup table.

Sure, and if you want to do it really perfect, you do dithering.
But we are talking about a hack that adds two audio signals to resemble 14bit. Because the playback is far from beeing perfect/linear etc., the result is not perfect 14bit. I would say the noise from artefacts is somehow comparable with something like 12bit. So you do not really gain a lot from trying to be better than a simple shift, which is the fastest way to do it.
Title: Re: Amiga sound playback routine/format questions
Post by: amigaksi on August 10, 2010, 04:24:12 PM
Quote from: bubblebobble;574149
@bloodline

You forgot to mention that the lower byte has to be shifted down 2 bits. This is where the 14bit comes into play. 64 is only 2^6. If they had made the volume control with a granulariy of 256 instead of 64, you could get 16bit playback.

Looseless goes not beyond 1:2 compression. But lossy ADPCM is cheaper to decode and at 8bit sounds pretty good (I cant hear a difference with HQ equipment). It still sounds acceptable at 4bit, but high frequencies get a little rough though.

We had this discussion once already:

PCM 16bit (http://www.hd-rec.de/Archive/FF10_PCM16.wav)
ADPCM 8bit (http://www.hd-rec.de/Archive/FF10_ADPCM8.wav)
ADPCM 4bit (http://www.hd-rec.de/Archive/FF10_ADPCM4.wav)
ADPCM 2bit (http://www.hd-rec.de/Archive/FF10_ADPCM2.wav)

Those are all plain .wav files, but have been encoded&decoded.


I am not a fan of lossy algorithms including MPEG, JPEG, MP3, etc.  I rather know exactly what I'm losing every sample rather than some sort of probability distribution where some samples may lose a lot more bits than others.  It doesn't matter how it sounds to some particular person since that's subjective.  Yeah, I do get 3.3:1 compression in my Gita multimedia CD (available on my website).  I compressed 2GB of 11Khz 8-bit samples losslessly to 600MB so they fit on one CD along with images.  It depends on the algorithm and audio data and rate.  I can probably get higher compression at higher sampling rates since redundancies increase.  Some people think MP3 sounds just like uncompressed digital audio CDs, but objectively speaking, the uncompressed is higher quality.
Title: Re: Amiga sound playback routine/format questions
Post by: bubblebobble on August 10, 2010, 05:07:38 PM
> Yeah, I do get 3.3:1 compression in my Gita multimedia CD
This is probably due so relatively silent parts in the samples and/or the 8bit quantisation.
Try the same on some randrom music in 16bit. In average, you wont get better than 1:2 when you go loosless.
http://wiki.hydrogenaudio.org/index.php?title=Lossless_comparison

And Amiga_Nut needs something fast enough for a nacked A500 that should do some GFX in the meanwhile.
Title: Re: Amiga sound playback routine/format questions
Post by: Thorham on August 10, 2010, 05:38:46 PM
Quote from: bubblebobble;574163
But we are talking about a hack that adds two audio signals to resemble 14bit. Because the playback is far from beeing perfect/linear etc., the result is not perfect 14bit. I would say the noise from artefacts is somehow comparable with something like 12bit.
Paula 14 bit sound becomes quite a lot better when you use a proper calibration table and properly down sampled audio files. No calibration: lowered quality. No proper down sampling: lowered quality. Add these two together, and it won't sound very good.

Furthermore, it's not really a hack, because Paula is a 14 bit D/A converter ;)
Title: Re: Amiga sound playback routine/format questions
Post by: bubblebobble on August 10, 2010, 05:48:24 PM
If Paula is a 14bit DA Converter, what is the "calibration" for then?

As for th downsampling, this is another story, but can be done "offline". I used to do 44.1kHz with interrupt, but on a 68060.
With dithering I mean to reduce (or better mask, it is some kind of noise shaping) the audible quantisation noise. Just like dithering in images with low bit depth.
Title: Re: Amiga sound playback routine/format questions
Post by: amigaksi on August 11, 2010, 02:56:10 AM
Quote from: bubblebobble;574202
> Yeah, I do get 3.3:1 compression in my Gita multimedia CD
This is probably due so relatively silent parts in the samples and/or the 8bit quantisation.
Try the same on some randrom music in 16bit. In average, you wont get better than 1:2 when you go loosless.
http://wiki.hydrogenaudio.org/index.php?title=Lossless_comparison

And Amiga_Nut needs something fast enough for a nacked A500 that should do some GFX in the meanwhile.


Thanks for that link-- I didn't realize my link was also in that article: http://www.krishnasoft.com/sps.htm.  I never promoted my audio software but I guess someone did it for me.  I did say 8-bit in my post #5 and it does work on stock Amiga at 7.16Mhz as the decompressor is very fast (faster than playback rate).  All speech and even some music have silent parts; it's part of natural sentence structure.  But even the silence is noisy in my audio as it was digitized from cassettes and there's that "hiss" type of noise when someone pauses between words.
Title: Re: Amiga sound playback routine/format questions
Post by: amigaksi on August 11, 2010, 03:00:54 AM
Quote from: bubblebobble;574207
If Paula is a 14bit DA Converter, what is the "calibration" for then?

As for th downsampling, this is another story, but can be done "offline". I used to do 44.1kHz with interrupt, but on a 68060.
With dithering I mean to reduce (or better mask, it is some kind of noise shaping) the audible quantisation noise. Just like dithering in images with low bit depth.


I think the logic is that if it's not a linear 14-bit DAC then a table helps to map 16-bit data to the nonlinear 14-bits optimally rather than approximate with LSR.W #2,D0.
Title: Re: Amiga sound playback routine/format questions
Post by: Thorham on August 11, 2010, 10:41:13 AM
Quote from: bubblebobble;574207
If Paula is a 14bit DA Converter, what is the "calibration" for then?
Paula is 14 bit because both sample and volume data are handled by Paula.

The calibration part is only needed to compensate for the non-linearities in the audio hardware, probably the analog parts, but I'm not sure. Seems reasonable (all Paulas are the same?).