Forums > MaxMSP

### Realtime/dynamic mp3 compression (used as an effect)?

Feb 27 2012 | 1:28 am

Has anyone come across a realtime mp3 encoder/decoder in Max?
More specifically where you can control the bit rate in dynamic fashion (ie, with a number box).

The idea is to use the loss of resolution as a sort of ‘digital tone knob’ of sorts.

My understanding of how mp3 analysis/encoding is not great, but I know it’s an FFT-based process, so I’m wondering if it’s possible to do something like that in Max, in realtime.
Or at the very least try to emulate the ‘sound’ of what’s happening.

I found this pseudo-code that sort of summarises what’s happening:

algorithm MP3 {
/*Input: An audio signal in the time domain
Output: The same audio signal, compressed
/*
Process the audio signal in frames
For each frame {
Use the Fourier transform to transform the time domain data to the frequency domain, sending
the results to the psychoacoustical analyzer {
ratios (SMR) in areas across the frequency spectrum
Analyze the presence and interactions of transients
}
Divide the frame into 32 frequency bands
For each frequency band {
Use the modified discrete cosine transform (MDCT) to divide each of the 32 frequency bands
into 18 subbands, for a total of 576 frequency subbands
Sort the subbands into 22 groups, called scale factor bands, and based on the SMR, determine
a scaling factor for each scale factor band
Use nonuniform quantization combined with scaling factors to quantize
Encode side information
Use Huffman encoding on the resulting 576 quantized MDCT coefficients
Put the encoded data into a properly formatted frame in the bit stream
}
}

Feb 27 2012 | 6:30 pm

Also curious if anyone has done ‘data moshing’ type processing on audio, keeping frequencies static until new ones take over (similar to the i/p frame stuff in datamoshing).

Apr 03 2012 | 12:21 am

Hate to bump a somewhat old post, but does anyone have any ideas about this? I’d like to try and emulate something like http://mashable.com/2010/06/03/youtube-i-am-sitting/ – IE, really, really nasty audio codec compression. Doesn’t seem to be much literature on the subject, that I can find.

Apr 03 2012 | 12:32 am

I’ve actually got something super handy going, though it uses a custom external by Alex Harker, with some additional code by a good friend of mine.

I tweaked it a bit so you can select an arbitrary range that wraps around the spectrum (it makes sense if you look at it). I’ve also got a stereo 1-band version, and a stereo multi-band version kicking around.

###### Attachments:
1. mp3ify.zip
Apr 03 2012 | 2:22 am

Wow, I was just looking for that! Thanks Rodrigo!

Apr 03 2012 | 4:37 am

I was messing around with pfft~ a bit today, trying to get something like what I wanted. I think this works! At the very least, it’s… interesting. And sorta gross.

Bitcrush/sample rate reduce the phase/amplitude of a signal seperately from each other, as well as rounding the amplitude (but not the phase), and multiplying the phase (but not the amplitude). Try putting the phase at -1, it’s amusing. :D

It’s all pretty simple patching but it amuses me no less.