Audio-Mad

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

31
32
33
34
35
36
37
38
39
40
41
42
43
44
          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

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
                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

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
=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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* 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

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## 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

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        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.283 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )