Discussion:
[mad-user] MAD and Jack.....
a***@fnarg.demon.co.uk
2004-09-07 11:53:10 UTC
Permalink
Hi there,

I'm writing a playout system which utilises Jack and MAD to play MP3 files. I've written a simple app which under libao (I was using this prior to Jack) will happily play any MP3 file I throw at it. However, upon adding the relevant code to make it a Jack client I've run across a problem. MAD seems to output audio at either 24bit fixed point or 16bit signed whereas Jack expects audio in 32bit floating point. Is there an easy way to make this work, am I being thick?

Please help!

Cheers,

Andy M
Jens Lippmann
2004-09-07 17:02:00 UTC
Permalink
Hi!

I'm new to the list and I'm not familiar with
libmad, but have a look at this function from the
madlld sample.
You can easily change it to produce 32-bit
floating point:

float f;
if (Fixed & (1<<31)) {
// negative
Fixed = Fixed & ((1<<31)-1); // strip sign
f = -(float)Fixed / (1<<MAD_F_FRACBITS);
}
else {
f = (float)Fixed / (1<<MAD_F_FRACBITS);
}
return f;

hope this helps
Jens


/****************************************************************************
* Converts a sample from mad's fixed point number format to an unsigned *
* short (16 bits). *
****************************************************************************/
static unsigned short MadFixedToUshort(mad_fixed_t Fixed)
{
/* A fixed point number is formed of the following bit pattern:
*
* SWWWFFFFFFFFFFFFFFFFFFFFFFFFFFFF
* MSB LSB
* S ==> Sign (0 is positive, 1 is negative)
* W ==> Whole part bits
* F ==> Fractional part bits
*
* This pattern contains MAD_F_FRACBITS fractional bits, one
* should alway use this macro when working on the bits of a fixed
* point number. It is not guaranteed to be constant over the
* different platforms supported by libmad.
*
* The unsigned short value is formed by the least significant
* whole part bit, followed by the 15 most significant fractional
* part bits. Warning: this is a quick and dirty way to compute
* the 16-bit number, madplay includes much better algorithms.
*/
Fixed=Fixed>>(MAD_F_FRACBITS-15);
return((unsigned short)Fixed);
}
Jamie Wilkinson
2004-09-08 03:37:40 UTC
Permalink
Post by a***@fnarg.demon.co.uk
Hi there,
I'm writing a playout system which utilises Jack and MAD to play MP3 files. I've written a simple app which under libao (I was using this prior to Jack) will happily play any MP3 file I throw at it. However, upon adding the relevant code to make it a Jack client I've run across a problem. MAD seems to output audio at either 24bit fixed point or 16bit signed whereas Jack expects audio in 32bit floating point. Is there an easy way to make this work, am I being thick?
A friend of mine is writing a library that does fast sample rate
conversions:

http://mega-nerd.com/SRC/
--
***@spacepants.org http://spacepants.org/jaq.gpg
Loading...