Re: MAD and Jack.....

[email protected] (Jens Lippmann) 07 Sep 2004 17:02 GMT
Newsgroups gmane.comp.audio.mad.user
Message-ID <[email protected]>
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);
}