[ANN] "Pure" Ogg-Vorbis decoder

Russell Penney russell.penney at tincanct.com
Fri Jun 11 11:02:11 UTC 2004


I have just released onto SqueakMap a "pure" Smalltalk port of the
Ogg-Vorbis decoder from Xiph.

It is VERY slow, very buggy and the code is so ugly that it would definitely
win the "Ugliest Code Competition".

I have had a compulsion to write an Ogg decoder and so I took the hardest,
slowest way I possibly could because I am lazy (confused? Me too).

I could have linked the libraries via a plugin and saved myself a huge
amount of work, but I convinced myself that a "pure" codec would be so cool.

I think it is definitely useable after much refactoring and optimisation. I
have very little experience in Smalltalk, I use it as a hobby and so my
knowledge of the correct structure for code like the Ogg stuff is very
limited.

I am not going to have much time to spend on the code for at least a month
probably two so rather than the code gather dust, I thought I would put it
out so I can get some suggestions on the best way of tiding up the code.
Great learning experience for me.

The code is a mixture of the documented algorithm and the C code for the
reference codec. It is missing many things (error checking being the main
one) and will probably not decode all types of Ogg files. 

 

I think Exceptions can be used for the error handling as sometimes reaching
the end of a packet unexpectedly is fatal and sometimes its ok (you just
return what you had decoded to that point). Is that right? Or is there
something better (or more standard)?

 

There are a lot of loops; I guess you could say a lot of "passes" over the
data to recover the audio. There is probably not a lot to be done to reduce
the number of passes but a lot could be done to optimise each step
individually. I must admit I only understand the algorithm a little bit and
sections like the MDCT (Modified Discrete Cosine Transform) I have had to
rip almost straight from the C code. I looked at the code for ages and could
not figure out any way to make that code better/easy to understand. I don't
have enough of a maths background to understand the original equation for
the transform and come up with a better way of doing it in Smalltalk.

 

Xiph released a version of OggVorbis called Tremour which is integer only
(mainly for embedded devices). Would it be faster to modify the code to use
integers only?

 

Obviously making sections of the code a plugin would be a good idea. One of
reasons I wrote the whole thing in Smalltalk was so it would be easy to use
Slang instead. I have left most of the loops as zero based and most 'at:'
statements have "+1" added separately to make them easier to remove. I
haven't had the time to really get into Slang and plugins so any advice
would be appreciated! :)  What is the best class to subclass from? How do I
do a plugin that doesn't need any external code? For sections like the MDCT
can I just put a huge chunk of C code in a method? How do I pass an array of
floats?

I did try a little bit while I was coding but after my image crashed for the
10th time I gave up! :)

 

I have attached my test ogg file. You really want to try it on a small file
as it is SLOW :)

Have fun

Russell

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040611/b42fa097/attachment.htm


More information about the Squeak-dev mailing list