Audio-Mad

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

	  suitable to be sent at /dev/dsp.

0.2  Wed Jun  5 12:00:00 2002
	- created perl package Mad::Dither from code found in
	  the mad source distribution.  it preforms generic
	  dithering and linear resampling on data derived from
	  mad_synth to provide raw pcm data to perl script.

0.1  Sat Jun  1 12:00:00 2002
	- created perl interfaces for:  mad_stream,  mad_frame,
	  mad_synth,  and mad_timer (in Mad::Stream, Mad::Frame, etc..).

	- original version; created by h2xs 1.21 with options
		-a -n Mad -x /usr/include/mad.h -lmad

Mad.pm  view on Meta::CPAN

		MAD_FLAG_INCOMPLETE      MAD_FLAG_I_STEREO
		MAD_FLAG_LSF_EXT         MAD_FLAG_MS_STEREO
		MAD_FLAG_MC_EXT          MAD_FLAG_MPEG_2_5_EXT
		MAD_FLAG_NPRIVATE_III    MAD_FLAG_ORIGINAL
		MAD_FLAG_PROTECTION      MAD_FLAG_PADDING
	)],
	f      => [qw(MAD_F_ONE MAD_F_MIN MAD_F_MAX MAD_F_FRACBITS)],
	layer  => [qw(MAD_LAYER_I MAD_LAYER_II MAD_LAYER_III)],
	mode   => [qw(MAD_MODE_SINGLE_CHANNEL MAD_MODE_DUAL_CHANNEL MAD_MODE_JOINT_STEREO MAD_MODE_STEREO)],
	option => [qw(MAD_OPTION_HALFSAMPLERATE MAD_OPTION_IGNORECRC)],
	timer  => [qw(MAD_TIMER_RESOLUTION)],
	units  => [qw(
		MAD_UNITS_11025_HZ     MAD_UNITS_12000_HZ     MAD_UNITS_16000_HZ
	        MAD_UNITS_22050_HZ     MAD_UNITS_24000_HZ     MAD_UNITS_32000_HZ
	        MAD_UNITS_44100_HZ     MAD_UNITS_48000_HZ     MAD_UNITS_8000_HZ
	        MAD_UNITS_CENTISECONDS MAD_UNITS_DECISECONDS  MAD_UNITS_HOURS
	        MAD_UNITS_MINUTES      MAD_UNITS_MILLISECONDS MAD_UNITS_SECONDS
	)],
);


Mad.pm  view on Meta::CPAN


Audio::Mad - Perl interface to the mad MPEG decoder library

=head1 SYNOPSIS

  use Audio::Mad qw(:all);
  
  my $stream   = new Audio::Mad::Stream();
  my $frame    = new Audio::Mad::Frame();
  my $synth    = new Audio::Mad::Synth();
  my $timer    = new Audio::Mad::Timer();
  my $resample = new Audio::Mad::Resample(44100, 22050);
  my $dither   = new Audio::Mad::Dither();

  my $buffer = join('', <STDIN>);
  $stream->buffer($buffer);

  FRAME: {
  	if ($frame->decode($stream) == -1) {
  		last FRAME unless ($stream->err_ok());

Mad.pm  view on Meta::CPAN

=item * :layer
	
	MAD_LAYER_I               MAD_LAYER_III
	MAD_LAYER_II

=item * :mode
	
	MAD_MODE_SINGLE_CHANNEL   MAD_MODE_STEREO
	MAD_MODE_DUAL_CHANNEL     MAD_MODE_JOINT_STEREO

=item * :timer	

	MAD_TIMER_RESOLUTION

=item * :units
	
	MAD_UNITS_8000_HZ         MAD_UNITS_MILLISECONDS
	MAD_UNITS_11025_HZ        MAD_UNITS_CENTISECONDS
	MAD_UNITS_12000_HZ        MAD_UNITS_DECISECONDS
	MAD_UNITS_16000_HZ        MAD_UNITS_SECONDS
	MAD_UNITS_22050_HZ        MAD_UNITS_MINUTES

Mad.xs  view on Meta::CPAN

/* pull in the two more complex interface headers */
#include "resample.h"
#include "dither.h"

/* now the constants that everything is in line */
#include "constants.h"

typedef struct mad_stream   * Audio_Mad_Stream;
typedef struct mad_frame    * Audio_Mad_Frame;
typedef struct mad_synth    * Audio_Mad_Synth;
typedef mad_timer_t         * Audio_Mad_Timer;
typedef struct mad_resample * Audio_Mad_Resample;
typedef struct mad_dither   * Audio_Mad_Dither;

MODULE = Audio::Mad		PACKAGE = Audio::Mad		
PROTOTYPES: ENABLE

double
constant(sv,arg)
    PREINIT:
	STRLEN		len;

Mad.xs  view on Meta::CPAN

MODULE = Audio::Mad		PACKAGE = Audio::Mad::Timer

Audio_Mad_Timer
new(CLASS, seconds=0, frac=0, denom=0)
		char *CLASS = NO_INIT;
		unsigned long seconds;
		unsigned long frac;
		unsigned long denom;
	CODE:
		Newz(0, (void *)RETVAL, sizeof(*RETVAL), char);
		*RETVAL = mad_timer_zero;

		if (items == 3)
			mad_timer_set(RETVAL, seconds, frac, denom);
	OUTPUT:
		RETVAL
		
Audio_Mad_Timer
new_copy(THIS)
		Audio_Mad_Timer THIS
	CODE:
		Newz(0, (void *)RETVAL, sizeof(*RETVAL), char);
		*RETVAL = *THIS;
	OUTPUT:
		RETVAL

void
set(THIS, seconds, frac, denom)
		Audio_Mad_Timer THIS
		unsigned long seconds
		unsigned long frac
		unsigned long denom
	CODE:
		mad_timer_set(THIS, seconds, frac, denom);
		XSRETURN(1);

void
reset(THIS)
		Audio_Mad_Timer THIS
	CODE:
		*THIS = mad_timer_zero;
		XSRETURN(1);
		
void
negate(THIS)
		Audio_Mad_Timer THIS
	CODE:
		mad_timer_negate(THIS);
		XSRETURN(1);
		
int
compare(THIS, OTHER)
		Audio_Mad_Timer THIS
		Audio_Mad_Timer OTHER
	CODE:
		RETVAL = mad_timer_compare(*THIS, *OTHER);
	OUTPUT:
		RETVAL
		
int 
sign(THIS)
		Audio_Mad_Timer THIS
	CODE:	
		RETVAL = mad_timer_compare(*THIS, mad_timer_zero);
	OUTPUT:
		RETVAL

void
abs(THIS)
		Audio_Mad_Timer THIS
	PREINIT:
		Audio_Mad_Timer ABS;
	CODE:
		*ABS  = mad_timer_abs(*THIS);
		*THIS = *ABS;
		XSRETURN(1);
		
void
add(THIS, OTHER)
		Audio_Mad_Timer THIS
		Audio_Mad_Timer OTHER
	CODE:
		mad_timer_add(THIS, *OTHER);
		XSRETURN(1);
		
void
multiply(THIS, value)
		Audio_Mad_Timer THIS
		long value
	CODE:
		mad_timer_multiply(THIS, value);
		XSRETURN(1);
		
long
count(THIS, units)
		Audio_Mad_Timer THIS
		int units
	CODE:
		RETVAL = mad_timer_count(*THIS, units);
	OUTPUT:
		RETVAL
		
unsigned long
fraction(THIS, denom)
		Audio_Mad_Timer THIS
		int denom
	CODE:
		RETVAL = mad_timer_fraction(*THIS, denom);
	OUTPUT:
		RETVAL
		
void
DESTROY(THIS)
		Audio_Mad_Timer THIS;
	CODE:
		Safefree(THIS);
		XSRETURN_UNDEF;

README  view on Meta::CPAN

Audio::Mad - Perl interface to the mad mpeg decoder library.

Version 0.6

Description

	Audio::Mad is a perl module designed to provide an abstract 
	interface to the low level mad mpeg decoder library.  Interfaces for 
	mad_stream, mad_frame, mad_synth, and mad_timer_t are provided.  
	Two addon interfaces Audio::Mad::Resample and Audio::Mad::Dither 
	provide methods for manipulating raw mad_fixed_t data into usable 
	strings.

Requirements

	In order to use Audio::Mad, you will have to install the MAD
	decoder library version 0.14.2b or greater.  This can be
	retrieved at http://mad.sf.net/
	

lib/Audio/Mad/Frame.pm  view on Meta::CPAN

 FRAME: while(1) {
 	if ($frame->decode($stream) == -1) {
 		print "stream error: " . $stream->error() . "\n";
 		last FRAME;
 	}
 	
 	my $layer      = $frame->layer();
 	my $mode       = $frame->mode();
 	my $bitrate    = $frame->bitrate();
 	my $samplerate = $frame->samplerate();
 	my $timer      = $frame->duration(); #see Audio::Mad::Timer
 	my $flags      = $frame->flags();
 	
 	# do something with the frame.  usually requires
 	# Audio::Mad::Synth (see docs)
 }
 	
=head1 DESCRIPTION

  This package provides an interface to the underlying mad_frame
  structure used in the decoder library.  Most of the functions

lib/Audio/Mad/Timer.pm  view on Meta::CPAN

package Audio::Mad::Timer;
1;
__END__

=head1 NAME

  Audio::Mad::Timer - Interface to mad_timer_t structure
  
=head1 SYPNOSIS

  my $timer = new Audio::Mad::Timer(15, 505, MAD_UNITS_MILLISECONDS);
  
  my $timer2 = $timer->new_copy();
  $timer2->set(31, 5, MAD_UNITS_CENTISECONDS);
  
  $timer->reset();
  $timer->negate();
  
  if ($timer->compare($timer2) == -1) { print "timer < timer2" }
  
  if ($timer2->sign() == -1) { 
  	print "timer2 is < 0";
  	$timer2->abs();
  	print "timer2 is > 0";
  }
  
  $timer->add($timer2);
  $timer2->multiply(15);
  
  my $ms = $timer2->count(MAD_UNITS_MILLISECONDS);
  my $cs = $timer->fraction(MAD_UNITS_CENTISECONDS);
  
=head1 DESCRIPTION

  This package provides access to the underlying mad_timer_t data
  structure used in the decoder library.  It also provides several
  overloaded methods so you can treat the timer more like a
  fundamental data type than an object.
  
=head1 METHODS

=over 4

=item * new([seconds, fraction, denominator])

  Creates a new timer,  and optionally initializes it's 
  initial count with it's paramaters.  seconds is the whole 
  seconds to add to the timer,  fraction is the whole number of 
  fractional seconds to add to the timer,  denominator is used 
  to divide the fractional seconds before it's added to the timer.
  
=item * new_copy

  Creates a new timer,  and sets the initial value to the
  value of the object it was called on.
  
=item * set(seconds, fraction, denominator])

  Sets the value of the timer,  see the ->new method,  above.
  
=item * reset

  Resets the value of the timer to zero.
  
=item * negate

  Negates the current value of the timer,  in place.
  
=item * compare(timer)

  Returns -1, 0, or 1 if the value of the object is currently
  less than,  equal to,  or greater than (respectively) the
  value of timer.
  
=item * sign

  Returns -1, 0, or 1 if the value of the object is currently
  less than,  equal to,  or greater than (respectively) zero.
  
=item * abs

  Resets the timer to the abosolute value of itself,  in place.
  
=item * add(timer)

  Adds the value of timer to the value of the object.
  
=item * multiply(int)

  Multiplies the value of the object by int.
  
=item * count(units)

  Returns the current count of the timer,  in units,
  generally expressed as a MAD_UNITS constant.
  
=item * fraction(denominator)

  Returns the current whole number of fractional seconds
  in terms of the denominator.
  
=item * +, ++, -, --, *, /

  The set of mathemetical operators that work on Audio::Mad::Timer

lib/Audio/Mad/Util.pm  view on Meta::CPAN

	## setup some initial counter type things.
	$h->{s_frames}   = 0;
	$h->{s_vbr}      = 0;

	## s_size is the size of the stream,  and we attempt to
	## correct this key for ID3 tags and other extraneous
	## data -- in the case of a xing header,  we use it's
	## size variable if possible..
	$h->{s_size}     = $h->{f_size};

	## create a mad_timer structure
	$h->{s_duration} = new Audio::Mad::Timer;

	## we use these variables to calaculate a toc strucutre
	## when requested by the do_toc argument to this sub,
	## it provides an easy index for searching through the
	## stream.
	my $scale = $h->{s_size} / 100;
	my @toc   = ();
	
	## to start,  we cycle on a frame-by-frame basis..

test.pl  view on Meta::CPAN

	if ($frame->decode($stream) == -1) {
		next FRAME if ($stream->err_ok()); #recoverable
		last FRAME if ($stream->error() == MAD_ERROR_BUFLEN); #done
		print "FAILED,  stream error: " . $stream->error();
		ok(0);
	}
}
print "decoded " . ($#frames + 1) . " frames.. ";
ok(1);

print "timer test..    ";
my $timer = new Audio::Mad::Timer;
foreach my $frame (@frames) {
	$timer += $frame->duration();
}
print "timer total: ${timer}.. ";
ok(1);

	
print "synth test..    ";
my $synth = new Audio::Mad::Synth;
my @pcmout;
foreach my $frame (@frames) {
	$synth->synth($frame);
	my ($left, $right, $shit) = $synth->samples();



( run in 0.416 second using v1.01-cache-2.11-cpan-55f5a4728d2 )