CVSD Compressed audio example

Announce (tech) demos or games releases

Moderator: Mask of Destiny

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sun Jul 12, 2009 9:10 pm

Chilly Willy wrote:Oh, a quick peek at that shows it's 3:1 compression (4 bytes for 12 samples). I'm gonna go work on an encoder and see what is sounds like. 8)

Odd coinky-dink, but it's quite similar to my 2 bit CVSD, except you explicitly state a delta, use not instead of negate, and use delta instead of delta*2.
I do think things won't sound too great, at least not by looking into some WAVs... but how it works out in reality is something I know nothing about and perhaps the result is actually GOOD :D
And you can negate if you want, NOT is not much different from negation :P

I made this for 8bit input and output, but nothing stops you from using it for 16bit data, but it won't be too optimal for 16bit stuff since the maximal change in signal is +255 / -255 per sample... so 16bit perfect square waves will not be as perfect later :lol:

E-mail works for me, I check mail too many times a day... IM is nice for chats, and that is what I was hoping for...


Anyway, I wish you good luck :)
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Jul 12, 2009 10:40 pm

Just about time for dinner here.

Here's demo 4. This uses the ADPCM that TmEE described earlier... with a couple changes.

Decoding the stream as bytes made the DC drift too much for my tastes. 16 bit didn't drift, and fit my existing code better. However, if I just leave the delta as +/-255, then you can't react to changes as fast, so now the first byte is shifted a byte to form the 16 bit delta. Because we're doing strict 16 bit math (not 32 bit ints) on the Z80, I restrict DELTA to 0 to 127. I also use negate instead of NOT. Otherwise, it's just how the scrap paper said. :D

While my other routines will take data on any boundary, this compression scheme requires the data to be on block boundaries, so it must be four byte aligned.

I must say I'm really pleased with the result - this method is quite suitable for music. Just listen to the rom - this is once more Sonic CD, tracks 3, 6, 9, 12, and 18. At 3:1, it takes more space, but if you have it, this is a good way to store music that must be digital.

musicdemo4.7z

The compressor takes a 16 bit signed 22050 Hz raw sample stream and outputs the compressed bin (no header). The decompressor takes the bin and outputs an 8 bit unsigned 22050 Hz raw stream.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Mon Jul 13, 2009 7:26 am

Wow, this sounds MUCH better than I thought it would :D
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Jul 13, 2009 3:04 pm

TmEE co.(TM) wrote:Wow, this sounds MUCH better than I thought it would :D
I was surprised at how good it sounds, too. I was surprised even more by how well my simple little encoder worked. That was the thing I was worried about the most. Especially picking the delta for a block - I just started with an average delta thinking I didn't want it too big or too small. I thought for sure picking delta would turn out to be harder than that. :lol:

Even more surprising was the timing on my Z80 code was perfect the very first time. I didn't have to adjust it at all. I usually time some music (knowing how long it SHOULD be) and then add enough NOPs to compensate... didn't need to add or sub any this time. :)

mic_
Very interested
Posts: 265
Joined: Tue Aug 12, 2008 12:26 pm
Location: Sweden
Contact:

Post by mic_ » Tue Jul 14, 2009 8:17 am

Seems to me like the case where you'd want to use sampled music the most is in the case of song/speech, so that's where the quality matters the most. The music in the demo (the Sonic tracks) all sound like they could've been done fairly accurately using FM synthesis (I only listened to the beginning of each track, so maybe they contain some totally un-FM-synth'able stuff later on).

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Jul 14, 2009 3:40 pm

A couple of the Sonic CD tracks contain some choral elements in them. Otherwise, yes, they're just plain FM style songs. Those aren't what I recommend compression be used on, merely what I used in the demo. An example of where you WOULD use it would be like the Genesis Harry Potter game, where clips of the movie score are used with truly dreadful compression. Sounds like they're using my old 16:1 compressor. :lol:

BinaryCreature
Newbie
Posts: 7
Joined: Thu Jul 22, 2010 3:38 am

Compressed Speech

Post by BinaryCreature » Thu Jul 22, 2010 4:40 am

Tested your demo on a JXD 1000 (Sunplus PMP8000-powered, using its Megadrive emulator.)

The audio plays back very well, considering the extraordinary compression ratio. 24 minutes crammed into a 4 megabyte rom is amazing.

I am interested in using your code in a slideshow (picture + speech) demo.
Basically loop through a series of bitmaps (or tile art), playing a speech clip upon each bitmap displayed.

A more advanced application (possible in the future) would be an interactive adventure book, with sound effects and more.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Jul 22, 2010 5:38 am

That's fine - feel free. Remember that I did a number of revisions to the code through the thread that did different compression levels, and better compressors. So be sure to check them all out and find the one that suits your purposes most closely. If you have any questions fitting the code in your program, just ask.

Basic summary of demos:
Demo 1 = 8:1 compression (rather noisy)
Demo 2 = 4:1 compression (good for sfx, iffy for music)
Demo 3 = 8:1 compression w better compressor (suitable for sfx)
Demo 4 = 3:1 compression - Tiido's compression format (good for music)

BinaryCreature
Newbie
Posts: 7
Joined: Thu Jul 22, 2010 3:38 am

Post by BinaryCreature » Thu Jul 22, 2010 7:16 am

Chilly Willy wrote:That's fine - feel free. Remember that I did a number of revisions to the code through the thread that did different compression levels, and better compressors. So be sure to check them all out and find the one that suits your purposes most closely. If you have any questions fitting the code in your program, just ask.
Thanks. The Demo 4 seems best for what I'm doing (speech).
I notice that, to make the demo, it requires zasm to assemble the file z80_tadpcm.s80

Any idea where I might find zasm, or a suitable alternative ?
Thanks.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Jul 22, 2010 8:07 am


BinaryCreature
Newbie
Posts: 7
Joined: Thu Jul 22, 2010 3:38 am

Post by BinaryCreature » Thu Jul 22, 2010 8:57 am

Chilly Willy wrote:I'm using 3.0.18 from here: http://k1.dyndns.org/Develop/projects/z ... ributions/
Thanks. Got anything that works on Windows ? I do prefer Linux but stuck in the MS matrix for a while.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Jul 22, 2010 9:14 am

Well, you could either try compiling it with cygwin or mingw, or try converting the code to as.

http://john.ccac.rwth-aachen.de:8000/as/

BinaryCreature
Newbie
Posts: 7
Joined: Thu Jul 22, 2010 3:38 am

Post by BinaryCreature » Thu Jul 22, 2010 10:28 am

Chilly Willy wrote:Well, you could either try compiling it with cygwin or mingw, or try converting the code to as.

http://john.ccac.rwth-aachen.de:8000/as/
Thanks. I'll have another look at it when I get sufficient free time.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jul 23, 2010 1:04 am

I almost forgot about this - Shiru posted a link for this Z80 assembler:
http://sjasmplus.sourceforge.net/

EDIT: If you compile this yourself for linux, you need to make an edit... open the sjasm/sjdefs.h file and look at line 71-73.

Code: Select all

#ifdef WIN32
#include <stdlib.h>
#endif
Change that to

Code: Select all

#include <stdlib.h>
or you'll get errors when compiling.

BinaryCreature
Newbie
Posts: 7
Joined: Thu Jul 22, 2010 3:38 am

Post by BinaryCreature » Fri Jul 23, 2010 2:01 am

Chilly Willy wrote:I almost forgot about this - Shiru posted a link for this Z80 assembler:
http://sjasmplus.sourceforge.net/
Trying to assemble z80_tadpcm.s80 using sjasmplus.exe :

Code: Select all

C:\megadrive\musicdemo4>sjasmplus z80_tadpcm.s80
SjASMPlus Z80 Cross-Assembler v1.07 RC7 (build 02-04-2008)
Pass 1 complete (0 errors)
z80_tadpcm.s80(1): error: Invalid labelname: #target
z80_tadpcm.s80(1): error: Unrecognized instruction: bin
z80_tadpcm.s80(2): error: Invalid labelname: #code
z80_tadpcm.s80(2): error: Unrecognized instruction: $0000, $2000
z80_tadpcm.s80(2): error: Unexpected: $0000, $2000
z80_tadpcm.s80(486): error: Invalid labelname: #end
Pass 2 complete (6 errors)
z80_tadpcm.s80(1): error: Invalid labelname: #target
z80_tadpcm.s80(1): error: Unrecognized instruction: bin
z80_tadpcm.s80(2): error: Invalid labelname: #code
z80_tadpcm.s80(2): error: Unrecognized instruction: $0000, $2000
z80_tadpcm.s80(2): error: Unexpected: $0000, $2000
z80_tadpcm.s80(486): error: Invalid labelname: #end
Pass 3 complete
Errors: 12, warnings: 0, compiled: 487 lines, work time: 0.015 seconds

Post Reply