English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 27 May 2010, 18:30   #1
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
Lossless audio compression.

Hi,

I'm looking for a reasonably good, lossless way to compress 16 bit stereo (28Khz) audio. I know there are things like FLAC, but I need something that will allow decompression without a high cpu load on a 50Mhz '030. Anyone know of anything useful? If it's not possible, then just forget it, but if there is any chance it's doable, then I'd like to hear some ideas.

Any suggestions are appreciated
Thorham is online now  
Old 27 May 2010, 19:13   #2
Genju
Registered User
 
Genju's Avatar
 
Join Date: Mar 2005
Location: Germany
Age: 43
Posts: 73
FLAC is the lossless codec with the least complexity (and hence CPU usage) out there. Unless you want to create your own (which is probably bound to fail, considering that coding an efficient lossless audio codec is everything but trivial), you should either try FLAC or forget about the idea.
Genju is offline  
Old 27 May 2010, 19:40   #3
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,682
Hm, why say that Genju? I haven't seen any proofs that there is no better compression algorithm for lossless audio than FLAC. Certainly it's easy to make alternatives yourself that have a lighter CPU load.

If it's for Amiga I would try something inside the sampleplayer interrupt itself, to replace the 'fetching from buffer', a replacement for the buffer handler. If the algorithm is simple enough, you'd only have to be a sample ahead instead of temporarily buffering it in memory.

Delta conversion and RLE is the simplest I can think of that has any effect.
Photon is online now  
Old 27 May 2010, 19:44   #4
Genju
Registered User
 
Genju's Avatar
 
Join Date: Mar 2005
Location: Germany
Age: 43
Posts: 73
Quote:
Originally Posted by Photon View Post
Hm, why say that Genju? I haven't seen any proofs that there is no better compression algorithm for lossless audio than FLAC. Certainly it's easy to make alternatives yourself that have a lighter CPU load.
FLAC is already the best trade-off between compression ratio and complexity. Sure, you can try simple huffman compression, but you won't save more than 15-20% of the original size then. FLAC uses stuff like joint-stereo and inter-channel correlations and you can't go any lower with the complexity unless you want to end up with something that doesn't compress audio better than zip would.
Genju is offline  
Old 27 May 2010, 21:44   #5
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
Quote:
Originally Posted by Genju View Post
FLAC is the lossless codec with the least complexity (and hence CPU usage) out there. Unless you want to create your own (which is probably bound to fail, considering that coding an efficient lossless audio codec is everything but trivial)
Sorry, but FLAC is too heavy (which is unfortunate because it's good) Meynaf is already doing a FLAC decoder on his 50Mhz '030, and I think it uses around 90% cpu time, and his decoder is well optimized. That's the last thing I've heard from him if I'm remembering it correct (which may not be the case ). I'm looking for something that's effective (doesn't have to be as effective as FLAC), and relatively fast.
Quote:
Originally Posted by Genju View Post
you should either try FLAC or forget about the idea.
I don't think it's a good idea to forget about it so soon
Quote:
Originally Posted by Photon View Post
Certainly it's easy to make alternatives yourself that have a lighter CPU load.
Have to agree with that
Quote:
Originally Posted by Genju View Post
If it's for Amiga I would try something inside the sampleplayer interrupt itself, to replace the 'fetching from buffer', a replacement for the buffer handler. If the algorithm is simple enough, you'd only have to be a sample ahead instead of temporarily buffering it in memory.
It's just for music replaying, isn't a simple buffer easier?
Quote:
Originally Posted by Genju View Post
Delta conversion and RLE is the simplest I can think of that has any effect.
Yep, sounds good. With deltas the number of bits drop, and you can easily RLE the sign for each delta (tested on the peecee). Seems promising

Any more suggestions?
Thorham is online now  
Old 27 May 2010, 22:51   #6
Zetr0
Ya' like it Retr0?
 
Zetr0's Avatar
 
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
@Thornam

whats your target CPU for this project?

If you are looking at something 020'ish or lower - then huffman/delta RLE with a resizable buffer (pending on target) might be the only choice.

What are you hoping to achieve in terms of running CPU load / audio quality (bits) and compression ratio?

As a thought you could use a a parser that removes/clips non-audible sounds from the audio file first and then encodes / compresses the audio file... although this is a lossy approach it will likey prove a better compressor with only nominal non-audible loss.

Last edited by Zetr0; 27 May 2010 at 22:58.
Zetr0 is offline  
Old 27 May 2010, 22:54   #7
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,865
Quote:
Originally Posted by Zetr0 View Post
@Thornam

what your target CPU for this project?
Quote:
Originally Posted by Thorham View Post
but I need something that will allow decompression without a high cpu load on a 50Mhz '030.
StingRay is offline  
Old 27 May 2010, 23:03   #8
Zetr0
Ya' like it Retr0?
 
Zetr0's Avatar
 
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
LOL, thanks StingRay!


But I rekon you just hacked that in there didin't you... come on admit it.... It wasnt there before you l33t coder you!!!!


/Zetr0 nips out to check the google cache

"i'l catch you one of these days y'know...!!" lol!!


okay, so the target machine has a maximum of 9MIPS processing, so say we use only half of that 4.5MIPS...

for a Delta/RLE compressed 16 bit stereo audio file?
Zetr0 is offline  
Old 27 May 2010, 23:16   #9
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
Quote:
Originally Posted by Zetr0 View Post
whats your target CPU for this project?
In the end a 28Mhz '020 (Blizzard?) should be able to handle it, although I'm using a '030 at 50Mhz. Basically as low as possible.
Quote:
Originally Posted by Zetr0 View Post
If you are looking at something 020'ish or lower - then huffman/delta RLE with a resizable buffer (pending on target) might be the only choice.
Something like that might already be good enough anyway.
Quote:
Originally Posted by Zetr0 View Post
What are you hoping to achieve in terms of running CPU load / audio quality (bits) and compression ratio?
Audio: 14bit 28Khz stereo (current wavs are still 16bit, though).
Cpu load: As low as possible

For the compression ratio I want to fit 1.67 Giga bytes onto one CD. The music is looped (game music) and the rips I have actually include the looping as repeating data, this can be cut off, and looped in the software. This will get rid of quite some data, so the compression ratio doesn't have to be the best possible.
Quote:
Originally Posted by Zetr0 View Post
As a thought you could use a a parser that removes/clips non-audible sounds from the audio file first and then encodes / compresses the audio file... although this is a lossy approach it will likey prove a better compressor with only nominal non-audible loss.
Although you're right, the rips are lossless and the downsampling (done with Sox) is already lossy. If it's not possible to fit all the music on one CD, then this will be an interesting alternative

Last edited by Thorham; 27 May 2010 at 23:27.
Thorham is online now  
Old 28 May 2010, 00:14   #10
Zetr0
Ya' like it Retr0?
 
Zetr0's Avatar
 
Join Date: Jul 2005
Location: United Kingdom
Age: 49
Posts: 9,768
@Thornham,

It sounds like a fun project, I enjoyed playing with delta's and some shuffle key techniques at Uni, ahh fun times =)

So, lets see a standard CD being 700MB, storing 1.67GB might be a little on the hard side to achive, (thats 60%+ compression rate)

Although I suspect that that these looped tracks a half the problem, how much data have you got without the loops?
Zetr0 is offline  
Old 28 May 2010, 00:49   #11
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
Quote:
Originally Posted by Zetr0 View Post
Although I suspect that that these looped tracks a half the problem, how much data have you got without the loops?
I don't know, and I would have to listen to most of the 93 tracks to get the loop times, although the original wavs are from a tracked source (PSF) so the loops might be detectable with a simple freebasic program.
Thorham is online now  
Old 28 May 2010, 17:56   #12
absence
Registered User
 
Join Date: Mar 2009
Location: moon
Posts: 373
Quote:
Originally Posted by Thorham View Post
For the compression ratio I want to fit 1.67 Giga bytes onto one CD. The music is looped (game music) and the rips I have actually include the looping as repeating data, this can be cut off, and looped in the software. This will get rid of quite some data, so the compression ratio doesn't have to be the best possible.
Good thing, as fitting 1.67 GB of data on a cd can be a tall order even for FLAC. How large is the uncompressed data when looping in software? If the repeating data is large enough, compression may not even be necessary. (Edit: Sorry, I was too quick and didn't notice you had already answered this question.)

If audio quality isn't a top priority, you can also improve the compression ratio of lossless algorithms by avoiding dithering and noise shaping when converting from 16 to 14 bits. The result is "uglier" quantisation noise (distortion instead of hissing), but it may not be noticable.

Also, does it really have to be lossless? I don't know if simpler frequency based codecs like MP2 or Musepack (both sound good at high bitrates) are too heavy for the target CPU, but there's also stuff like ADPCM, which was used extensively as a streaming music format on the previous generation of game consoles.
absence is offline  
Old 29 May 2010, 05:15   #13
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
ADPCM sounds reasonably well, is cheap to decompress, and gives you 4:1 compression ratio for 16bit samples. You should be able to replay 28khz stereo for 10-20% CPU on a 28mhz 030.

I've published a decompressor here: http://code.google.com/p/unitedstatesofamiga/
Kalms is offline  
Old 29 May 2010, 07:54   #14
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
Quote:
Originally Posted by absence View Post
Good thing, as fitting 1.67 GB of data on a cd can be a tall order even for FLAC. How large is the uncompressed data when looping in software? If the repeating data is large enough, compression may not even be necessary. (Edit: Sorry, I was too quick and didn't notice you had already answered this question.)
It's probably less than half of data.
Quote:
Originally Posted by absence View Post
If audio quality isn't a top priority, you can also improve the compression ratio of lossless algorithms by avoiding dithering and noise shaping when converting from 16 to 14 bits. The result is "uglier" quantisation noise (distortion instead of hissing), but it may not be noticable.
Sound quality has maximum priority

The data is still all 16 bit, because Sox, which I used for the high quality down sampling from 48Khz, doesn't seem to like dithering from 16 bit to 14 bit. I tried to do this, because it might have increased the sound quality.

Getting rid of the two unneeded bits will reduce the data to 1.47 Gigs, whis is better than 1.67 Gigs, and it shouldn't even be audible (or even improve the audio somehat!), because when replaying on the Amiga, I think bits 6 and 7 will overlap with bits 8 and 9.
Quote:
Originally Posted by absence View Post
Also, does it really have to be lossless? I don't know if simpler frequency based codecs like MP2 or Musepack (both sound good at high bitrates) are too heavy for the target CPU, but there's also stuff like ADPCM, which was used extensively as a streaming music format on the previous generation of game consoles.
Lossyness is only acceptable if there's truely no other way. Lossy encoding is therefore a last resort.
Quote:
Originally Posted by Kalms View Post
ADPCM sounds reasonably well, is cheap to decompress, and gives you 4:1 compression ratio for 16bit samples. You should be able to replay 28khz stereo for 10-20% CPU on a 28mhz 030.

I've published a decompressor here: http://code.google.com/p/unitedstatesofamiga/
Thanks for the code However, from 'reasonably well' and the 4:1 compression I take it that ADPCM is lossy. Lossy is certainly interesting, but only if there's no other way.

Last edited by Thorham; 31 May 2010 at 14:50.
Thorham is online now  
Old 31 May 2010, 15:01   #15
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,856
I've been playing around with this for a while and I'm able to compress to about 75%, without any Huffman or RLE encoding (those will be added if necessary). Anyone know how to improve it? Here's what I'm doing now:

1. Calculate mid/side: mid=(left+right)/2 side=mid-left (may look strange, but these steps can be reversed without any loss)
2. Calculate difference between previous sample and current.
3. Store difference sign separately and convert difference to distance.
4. Store the distances with a very simple variable length code (add two extra bits to let the decoder know a distance value is 4, 8, 12 or 16 bits large).

This is of course a very simple method that can easily be expanded. Any ideas?
Thorham is online now  
Old 16 January 2015, 01:30   #16
algorithm
 
Posts: n/a
Do you really need lossless? If so, have you considered applying a haar wavelet to the audio. It may sound complex, but it is not. it is merely the average of each byte pair followed by the difference which recreates the byte pair. This is iterated until you have an average followed by the fluctuations. Then pack via the Huffman, lz methods.

Near lossless can be achieved at guaranteed 2:1 ratio with barely any audial loss via VQ encoding byte pairs. Read up on vector quantization. 256 "optimum" byte pairs are created (512 byte table) and each byte lookup converts to a byte pair. Very fast decode.
 
Old 16 January 2015, 06:16   #17
Nekoniaow
Banned
 
Join Date: Dec 2014
Location: Montreal
Posts: 129
Quote:
Originally Posted by Thorham View Post
I've been playing around with this for a while and I'm able to compress to about 75%, without any Huffman or RLE encoding (those will be added if necessary). Anyone know how to improve it? Here's what I'm doing now:

1. Calculate mid/side: mid=(left+right)/2 side=mid-left (may look strange, but these steps can be reversed without any loss)
2. Calculate difference between previous sample and current.
3. Store difference sign separately and convert difference to distance.
4. Store the distances with a very simple variable length code (add two extra bits to let the decoder know a distance value is 4, 8, 12 or 16 bits large).

This is of course a very simple method that can easily be expanded. Any ideas?
By 75% do you mean a 4:1 compression ratio or 4:3? I understood 4:3 but I'd rather be sure.
(The best codecs barely reach 50% so 4:3 it is. )

Also why do you store the sign bit separately? If you Huffman encode the values then it does not matter that they contain a sign bit and on the contrary it seems very unlikely that you will be able to separately compress the series of sign bits efficiently given their likely random nature.

Last edited by Nekoniaow; 16 January 2015 at 06:48.
Nekoniaow is offline  
Old 19 January 2015, 22:51   #18
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
this is interesting...

what i have done recently is to use a Lanczos filter to interpolate between the even bytes, then take the difference between the interpolated odd bytes and the real data. Store the even bytes and odd byte error separately, the odd bytes will be relatively small for "nice" sample data and will compress easily with any off-the-shelf packing algorithm or a custom LZ variant.
Mrs Beanbag is offline  
Old 20 January 2015, 00:25   #19
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,682
Heh, thread necromancing Since 2010 I did Nibbler, which is good at sample data and it can uniquely do 28kHz 4 channels in real time... bit of work to convert it to 4x interleaved streaming but if mono is ok it should be doable to just pop bytes out to a buffer, with time to spare. (This on 68000 now. Forever and for always. )

In lossless 8-bit audio, you're looking at 25-50% for sample data, unless you do something special. Delta+pure Huffman seems promising, why not, if you can stream it fast enough.

Lossy is where size gets interesting, basically though I think on 68000, considering you might lose the DMA advantage and 8-bit sounds bad enough as it is it's a bit wasting resources unless you can do something interesting with it like modulation, speech synth or whatever cos you get parameters to play with.
Photon is online now  
Old 20 January 2015, 00:48   #20
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 854
Can someone humour me with something I have been wondering for a while:
If you compress a sample with a lossy algorithm, what kind of compression could you get out of a delta between the original and the decompressed lossy data?

I.e. lossy compressed data plus compressed delta data - is it possible to get some better compression?
NorthWay is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Compression Methods For... Lonewolf10 Coders. General 16 16 June 2013 17:31
Best Audio Config in Winuae for a Creative X-Fi Audio Card shaf support.WinUAE 2 14 June 2012 16:27
Compression Suggestions h0ffman Coders. General 2 31 December 2010 12:19
ProTracker Module Compression h0ffman support.Other 12 24 September 2010 19:57

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:18.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10761 seconds with 13 queries