Advanced Audio Compression

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

Post Reply
Chilly Willy
Very interested
Posts: 2571
Joined: Fri Aug 17, 2007 9:33 pm

Advanced Audio Compression

Post by Chilly Willy » Sat Aug 06, 2011 8:38 pm

I've been playing with audio compression now for awhile. I've been looking at all sorts of compression formats, checking their speed vs compression vs quality. MP3 is not suitable for a number of reasons, a primary one being patent issue - right now, the U.S. is almost self-destructing over bad patents. A secondary issue is speed - I've yet to find an open source mp3 decoder that can do 16kHz mono on the 32X. Finally, even LAME can't encode mp3 at 24 to 32 kbps with a quality worth pursuing.

That led me to ogg-vorbis - no patent issues (knock on wood), sounds GOOD at 24 to 32 kbps, and has one of the fastest integer decoders out (Tremor). So I did some experiments - with just a few assembly optimizations I've got Tremor running fast enough for 22kHz mono on the 32X on real hardware. One issue I ran into concerned memory - my test app needs 128KB for Tremor to decode music (checked in 8KB increments from 64KB to 128KB); it also leaks memory bad enough that I have to reinit the heap between songs to keep it running.

So here's my latest Tremor test. Included is all source and the oggs that are used (22050 Hz mono 16 bit source encoded by the latest oggenc at 24 kbps VBR with an average bitrate of 30 to 33 kbps for most of the songs). This runs full speed in emulation AND on real hardware. The player starts playing automatically on startup and continues cycling through all the songs until you reset/power off. Press A for the previous song, or C for the next song.

TremorMonoTest32X-20110806.7z

As mentioned above, the codec leaks memory bad enough to require reseting the heap between songs, so I used MSYS - Simple Malloc & Free Functions - by malkia@digitald.com. Only, I might want to use MSYS on the Master SH2 as well for something... so I made two versions - MSYS for the Master SH2, and SSYS for the Slave SH2. They are functionally identical, but use different names on the calls along with static vars so that you don't run into cache coherency issues. So the Tremor codec in the archive above uses SSYS since it runs entirely on the Slave SH2.

memlibs-20110806.7z

All the above code uses my current toolchain. MSYS comes with makefiles for both the 32X and m68k, while SSYS just compiles for the 32X.

To make the test, cd to libssys and make clean, make, make install. Then cd to the test dir, cd to Tremor and make clean, make, make install. Then cd .. and make clean, make. You should then have oggtest.bin. This binary is included in the main archive above for folks who don't want to build this themselves.

As a comparison to my tests on CVSD ADPCM, mono 22kHz ogg-vorbis at 24 to 32 kbps is equivalent to 1 to 1.5 bits per sample ADPCM. If you compare the quality of the 30 kbps ogg samples, it sure sounds a lot better than my 1 or 2 bits per sample tests... better than the 3 bits per sample TADPCM as well. Now if I can get the memory usage down a bit and maybe a few more assembly optimizations...

User avatar
KanedaFr
Administrateur
Posts: 1114
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sat Aug 06, 2011 8:43 pm

what the name of the encoding used by Yamaha ?
yqf ? I remember good quality for small size.

also, on radio, I listen aac+ channel...

I don't know if it will be suitable for 32X (speed, memory...)

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

Post by Chilly Willy » Sat Aug 06, 2011 9:07 pm

KanedaFr wrote:what the name of the encoding used by Yamaha ?
yqf ? I remember good quality for small size.

also, on radio, I listen aac+ channel...

I don't know if it will be suitable for 32X (speed, memory...)
I have no idea about the Yamaha format - I'll have to look into it. Remember that I need open source integer decoding, and no patents would be nice, but not necessarily required.

AAC would probably be competitive for quality at the bit rates I'm using, but it's much more processor intensive. I had trouble getting AAC to decode at full speed on the N64! Anything less will not be suitable for AAC. AAC is also highly patented.

EDIT: The Yamaha format was TwinVQ (uses the .vqf extension). It's supposed to be about the same quality as an MP3 with 30% higher bit rate, so it might be suitable, quality wise. I'll have to look into decoding.

EDIT: Well, FFMPEG can decode it, but encoding would be an issue for folks. Also, this: http://wiki.hydrogenaudio.org/index.php?title=VQF

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

Post by Chilly Willy » Sun Aug 07, 2011 2:29 am

Here's the latest binary and sources: http://www.mediafire.com/download.php?9acgq3givvi8kvd

I now use the lowmem branch of the official Tremor codec instead of the RockBox version. The memory usage dropped from 128KB to 48KB. :D

TotOOntHeMooN
Interested
Posts: 38
Joined: Sun Jun 01, 2008 1:12 pm
Location: Lyon, France
Contact:

Post by TotOOntHeMooN » Sat Sep 17, 2011 7:41 pm

Great work ! :)

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

Post by Chilly Willy » Sun Sep 18, 2011 7:16 pm

Still needs some work on optimizing the codebook reading - if the codebook changes too much during the music, it results in popping. Some songs show this, and others don't. The issue is ogg-vorbis uses floating point for the codebook, so tremor converts the floats to an internal integer representation of the mantissa and exponent, and uses integer calculations for the floating point. While it seems like fixed point would be easier/faster, the comments specifically state they avoided fixed point for better accuracy as the range is beyond what fixed point can handle without significant distortion.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest