audio decompression in realtime?

GFA, ASM, STOS, ...

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

audio decompression in realtime?

Postby Zamuel_a » Tue Apr 01, 2008 3:12 pm

Is it possible with some audio decompression in realtime for audio samples? Had been nice to have that in a game, but it has to be rather fast then and compress the sample to some amount. If its only to 80-90% its not worth it.
Is there else some way to rather fast decompress a audiosample, not in realtime, so it just saves space on the disc, but can be decompressed rather fast anyway.
ST / STFM / STE / Mega STE / Falcon / TT030
Zamuel_a
Captain Atari
Captain Atari
 
Posts: 238
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: audio decompression in realtime?

Postby Zorro 2 » Tue Apr 01, 2008 3:31 pm

Only Cybernetics do that ! (hum... I think)

There are a little production only for Atari STE : Flexi Glass

The official website : http://cyber.savina.net/
User avatar
Zorro 2
Moderator
Moderator
 
Posts: 1887
Joined: Tue May 21, 2002 12:44 pm

Re: audio decompression in realtime?

Postby bod/STAX » Tue Apr 01, 2008 5:43 pm

It's possible.

I think Gunstick/ULM did it in his parallax distorter screen in the Dark Side of the Spoon demo using delta-compression.
So let it be written, So let it be done. I'm sent here by the chosen one.
User avatar
bod/STAX
Captain Atari
Captain Atari
 
Posts: 259
Joined: Wed Nov 24, 2004 8:13 pm
Location: Halesowen, West Midlands, England

Re: audio decompression in realtime?

Postby Zamuel_a » Tue Apr 01, 2008 10:51 pm

Ok, I did some testings with delta compression. From what I know delta compression is made by you take one sample and you calculate the difference from the previous so if you have 3 samples in a row with the same value you get a delta value of 0 and if you have 2,4,6,8 you get a delta value of 2,2,2. I tried that and could only compress a sample to about 10% perhaps. I had to resample to 7 bits to, so I could have one bit telling me if I had more than one sample with the same delta value, or else I had to (in worst case) spend 2 bytes for every byte of sample. If I just did a compare between the samples and grouped samples of same value, run length encoding I think it's called. I could actually compress more than with the delta technic, atleast with the test sample I had, so I don't know really how to do it to gain anything much.
ST / STFM / STE / Mega STE / Falcon / TT030
Zamuel_a
Captain Atari
Captain Atari
 
Posts: 238
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: audio decompression in realtime?

Postby earx » Wed Apr 02, 2008 8:06 am

zamuel: you're doing lossless compression. lossy crunches much harder with the risk of making it sound like shit. it all depends on the predictor and amount of quantisation. google for ADPCM.

predictor = guess for the next sample. often this is just taking the current sample. but there are loads of smart choices for specific cases.

quantisation = this basically is the precision of the amplitude. you can quantise to 4 bits to cover a range of 16, but also a range of 32 (taking steps of two)

there are smart ways like Sony's soundchips in the PSX (VAG compression, a bit inefficient on 68000) or a cheaper one of which i forgot the name.
i tried a VAG derivative on the Falcon's DSP and it rocks.
User avatar
earx
Captain Atari
Captain Atari
 
Posts: 351
Joined: Wed Aug 27, 2003 7:09 am

Re: audio decompression in realtime?

Postby Nyh » Wed Apr 02, 2008 10:54 am

Zamuel_a wrote:Is it possible with some audio decompression in realtime for audio samples? Had been nice to have that in a game, but it has to be rather fast then and compress the sample to some amount. If its only to 80-90% its not worth it.
Is there else some way to rather fast decompress a audiosample, not in realtime, so it just saves space on the disc, but can be decompressed rather fast anyway.

The ARJ M7 depacker can depack samples at a rate of about 64 kB/s on a normal ST. In most cases you can improve the compression ratio by delta encoding the sample before packing and add the values before playing.

The trick with ARJ is good for lossless compression. To get better compression ratios you can do a lossy compression. Use something like mu-law encoding. If you make it table driven it can be pretty fast. When you encode at nibble level you can use the sequence: -128, -64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64. With two 256 byte tables you can decode the upper and lower nibble without any shifting. If the quality is not good enough you can add some bits. The decoder becomes a bit more tricky and time consuming as you have to decode a bit stream.

Hans Wessels
User avatar
Nyh
Atari God
Atari God
 
Posts: 1226
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: audio decompression in realtime?

Postby earx » Wed Apr 02, 2008 11:31 am

MrNi: LZ coding is as good as useless on more-or-less noisy data. Huffman or another entropy coder do help. I tried a pure Huffman codec and zip and the differences were (logically) negligible.
User avatar
earx
Captain Atari
Captain Atari
 
Posts: 351
Joined: Wed Aug 27, 2003 7:09 am

Re: audio decompression in realtime?

Postby Nyh » Thu Apr 03, 2008 9:20 am

earx wrote:MrNi: LZ coding is as good as useless on more-or-less noisy data. Huffman or another entropy coder do help. I tried a pure Huffman codec and zip and the differences were (logically) negligible.

That is correct. The compression ratio on samples of an LZ coder is not impressive. The test file I used left 80% of the original. That is why I advised to use a delta encoder before using an ARJ. Even then you will not get impressive results. But on loss less compression it is about as good as it gets with the standard tools available on the ST.

Hans Wessels
User avatar
Nyh
Atari God
Atari God
 
Posts: 1226
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: audio decompression in realtime?

Postby unseenmenace » Thu Apr 03, 2008 7:07 pm

I don't know exactly what it is or if its any good to you but theres something labelled as "Sample Packer" on Medway Boys menu 74
UNSEEN MENACE
Several STFM's, 4MB STE, 2MB TT with 1.2GB Hard Drive and 14MB Falcon with 540MB Hard Drive,
Lynx 2 and Jaguar with JagCD
Member of GamebaseST and AtariLegend team
Check out my website at http://unseenmenace.110mb.com
User avatar
unseenmenace
Atari God
Atari God
 
Posts: 1926
Joined: Tue Sep 21, 2004 9:33 pm
Location: Broadstairs, Kent, UK

Re: audio decompression in realtime?

Postby Gunstick » Wed Apr 09, 2008 2:12 pm

bod/STAX wrote:It's possible.

I think Gunstick/ULM did it in his parallax distorter screen in the Dark Side of the Spoon demo using delta-compression.


oh? someone mentioned ULM?

*raising from the digital grave*

Yes, I think there has been no screen in ULM history featuring digisound which was not compressed. Packing twice the sound in the same space is just too appealing.
And you DON'T HEAR the difference! At least not on an YM.

Most amazing is that it is possible to play compressed sound faster than uncompressed.
For more infos on dominotable check this thread viewtopic.php?f=1&t=4357&p=32070&#p32070 also read some posts above that about why a table on 2, 4, 8, ...128 is better than any other way to do it.

Georges
PS: that entire thread is worth a read for the technophiles.
Gunstick
Captain Atari
Captain Atari
 
Posts: 205
Joined: Thu Jun 20, 2002 6:49 pm
Location: Luxembourg

Re: audio decompression in realtime?

Postby atari_mark » Tue Apr 15, 2008 12:35 pm

Boris of POV did something like this on our Invisible Man demo and the Ivor Biggun demo. The source code may be on the POV CD but I can't check at the moment because I am at work. Boris' routine was a bit difference one that only worked on some samples, we could play a sample and load/depack on the fly in the background.

Mark
Mac Sys Data/Persistence Of Vision

Instructions said to install Windows 2000 or better so I installed Fedora.
User avatar
atari_mark
Captain Atari
Captain Atari
 
Posts: 165
Joined: Thu Oct 10, 2002 12:30 pm
Location: Wigan, England

Re: audio decompression in realtime?

Postby Zamuel_a » Mon May 04, 2009 3:56 pm

I tried to do some testings with compression like Gunstick did on the parallax distorter screen with the information here http://www.atari-forum.com/viewtopic.php?f=1&t=4357&p=32070&#p32070
But I can't get it to work. I made a test sequence of data and then compress it to 4 bits and then back with the table 1,2,4,8... technic but I can't get it to work. It looks ok at the beginning of the sequence but then the errors get higher until it gets useless.

First I created two tables:

Code: Select all
BYTE delta_conversion_table[256];
char delta_table[16] = {0,1,2,4,8,16,32,64,127,-64,-32,-16,-8,-4,-2,-1};

void createDeltaTable()
{
int i,j=-128;

   for (i=0; i<255; i++,j++)
   {
      if (j==0) delta_conversion_table[i] = 0;
      if (j==1) delta_conversion_table[i] = 1;
      if (j>=2 && j<=3) delta_conversion_table[i] = 2;
      if (j>=4 && j<=6) delta_conversion_table[i] = 3;
      if (j>=7 && j<=12) delta_conversion_table[i] = 4;
      if (j>=13 && j<=24) delta_conversion_table[i] = 5;
      if (j>=25 && j<=48) delta_conversion_table[i] = 6;
      if (j>=49 && j<=96) delta_conversion_table[i] = 7;
      if (j>=97 && j<=127) delta_conversion_table[i] = 8;
      if (j>=-128 && j<=-97) delta_conversion_table[i] = 8;
      if (j>=-96 && j<=-49) delta_conversion_table[i] = 9;
      if (j>=-48 && j<=-25) delta_conversion_table[i] = 10;
      if (j>=-24 && j<=-13) delta_conversion_table[i] = 11;
      if (j>=-12 && j<=-7) delta_conversion_table[i] = 12;
      if (j>=-6 && j<=-4) delta_conversion_table[i] = 13;
      if (j>=-3 && j<=-2) delta_conversion_table[i] = 14;
      if (j==-1) delta_conversion_table[i] = 15;
   }
}



After that I calculate the delta values like this:

Code: Select all
void calcDelta()
{
int   i;
BYTE   previous = 0;
BYTE   delta;
BYTE   c;

   for (i=0; i<buffer_length; i++)
   {
      c = buffer[i];
      delta =c - previous;
      delta_buffer[i] = delta_conversion_table[(BYTE)(delta+128)];
      previous = c;
   }
}


"buffer" is a unsigned char buffer with the data to compress

And to decompress it I do this:

Code: Select all
void decompress()
{
int   i;
BYTE   index;
char   value;
char   old_value=0;
BYTE   sample;

   for (i=0; i<buffer_length; i++)
   {
      index = delta_buffer[i];
      value = delta_table[index];
      sample = old_value+value;
      old_value = sample;
      buffer[i] = sample;
   }
}


I can't see any errors. I have tried most char/unsigned char combination if it's a overflow problem with negativ and positiv numbers, but this is what gives something close to a result. I might have missunderstod the whole thing of how to do it?

I made a testtable:
1 10 14 150 4 216 59 24 200 18

and then I decoded it I got:
1 9 13 140 11 235 106 74 10 74

So it looks ok at first, but then halfway in it gets all wrong.
ST / STFM / STE / Mega STE / Falcon / TT030
Zamuel_a
Captain Atari
Captain Atari
 
Posts: 238
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: audio decompression in realtime?

Postby Nyh » Tue May 05, 2009 8:25 am

Zamuel_a wrote:So it looks ok at first, but then halfway in it gets all wrong.

I didn't do a thourough analisis of your code but I think you go wrong here in the void calcDelta() function.

I would say:
Code: Select all
void calcDelta()
{
  int   i;
  BYTE   previous = 0;
  BYTE   delta;
  BYTE   c;

     for (i=0; i<buffer_length; i++)
     {
        c = buffer[i];
        delta =c - previous;
        delta_buffer[i] = delta_conversion_table[(BYTE)(delta+128)];
        previous += delta_buffer[i];
     }
}

With this code you are working with the calculated value to determine the next delta, as you do in your decompressor. With your code the errors keep adding up until there is no correlation left between input and output.

Hans Wessels
User avatar
Nyh
Atari God
Atari God
 
Posts: 1226
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: audio decompression in realtime?

Postby Zamuel_a » Tue May 05, 2009 3:15 pm

Thanks! It actually works now!
I had to replace that last line to:
previous += delta_table[delta_buffer[i]];
since the delta_buffer just keeps index numbers and not the real values. But then I changed it to that I actually got something out that sounded more or less like the sample I converted. There are some "clicks" here and there in the sample, but I guess that could be
ST / STFM / STE / Mega STE / Falcon / TT030
Zamuel_a
Captain Atari
Captain Atari
 
Posts: 238
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: audio decompression in realtime?

Postby Zamuel_a » Tue May 05, 2009 3:17 pm

because of some error I still got in the code.
It sounds much better than then I tried to resample to 6 bits, but now it's only 4!
ST / STFM / STE / Mega STE / Falcon / TT030
Zamuel_a
Captain Atari
Captain Atari
 
Posts: 238
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: audio decompression in realtime?

Postby Gunstick » Tue May 05, 2009 7:00 pm

I did not read all your code. What you have to do is, calculate delta, then get the 4 bit value nearest this delta, then add that value to the current sample to get the next theoretical sample (you "previous").
This is the same as letting running the decompressor at the same time with the compressor so that the compressor creates the waveform as close as possible to the original.
And don't forget that 254+4=2 which makes loud samples sound great.
Gunstick
Captain Atari
Captain Atari
 
Posts: 205
Joined: Thu Jun 20, 2002 6:49 pm
Location: Luxembourg


Return to Coding

Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests