The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mad - Perl interface to the mad MPEG decoder library

SYNOPSIS

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

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

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

                warn "decoding error: " . $stream->error();
                next FRAME;
        }

        $synth->synth($frame);
        my $pcm = $dither->dither($resample->resample($synth->samples()));

        print $pcm;
        next FRAME;
  }
                             

DESCRIPTION

 This module is an attempt to provide a perl interface to the MAD
 (MPEG Audio Decoder) library,  written by Robert Leslie.  It has
 been designed to be 100% object oriented,  and to follow the MAD
 interface as closely as possible.

 So far,  most of the MAD library,  plus two companion modules
 are provided as part of the interface.  

CONSTRUCTORS

    The three basic mad structures, and their perl counterparts, require no paramaters for initalization. They are simply allocated, referenced, and sent to the appropriate mad_*_init function.

    • new Mad::Stream

    • new Mad::Frame

    • new Mad::Synth

    The Mad::Timer structure can be called without paramaters, which returns a zeroed out timer. Optionally, you can provide it with three paramaters to initialize the value of the new timer before it is returned.

    • new Mad::Timer ([seconds, fraction, denominator])

      • seconds

        The number of whole seconds to add on to the timer.

      • fraction

        The number of fractional seconds to add on to the timer.

      • denominator

        The denomination of the fractional seconds, usually expressed as a MAD_UNITS constant; although you're free to use any number, I guess.

    Mad::Resample can be created with or without parmaters. If called without paramaters, you must call the resulting object's ->init method before you attempt to resample any data. Returns undef on error, 1 if resampling is necessary, and 2 if resample is not necessary.

    • new Mad::Resample (oldrate, newrate)

      • oldrate

        The sampling rate of the input stream. Usually, you derive this by calling the ->samplerate method of a Mad::Frame object. You can specify any sampling rate you wish, but the underlying engine relies on the value you provide here to resample the input streams. Possible values are: 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000.

      • newrate

        The desired output sample rate of returned pcm streams. Possible values are the same as the 'oldrate' paramater above.

    Mad::Dither can also be constructed with or without paramaters. If called without a "type" paramater, you must pass one to the object's ->init method later.

    • new Mad::Dither (type)

      • type

        The desired format of returned pcm streams. Possible values are any of the MAD_DITHER constants listed below.

EXPORT

    None by default.

EXPORT_OK

  • :dither

            MAD_DITHER_S8             MAD_DITHER_U8
            MAD_DITHER_S16_LE         MAD_DITHER_S16_BE
            MAD_DITHER_S24_LE         MAD_DITHER_S24_BE
            MAD_DITHER_S32_LE         MAD_DITHER_S32_BE
  • :error

            MAD_ERROR_BADHUFFDATA     MAD_ERROR_LOSTSYNC       
            MAD_ERROR_BADCRC          MAD_ERROR_BADBITALLOC  
            MAD_ERROR_BADBITRATE      MAD_ERROR_BADSAMPLERATE
            MAD_ERROR_BADBLOCKTYPE    MAD_ERROR_BADHUFFTABLE   
            MAD_ERROR_BADSCFSI        MAD_ERROR_NOMEM        
            MAD_ERROR_BUFLEN          MAD_ERROR_BADFRAMELEN
            MAD_ERROR_BADPART3LEN     MAD_ERROR_BADSTEREO
            MAD_ERROR_BUFPTR          MAD_ERROR_BADLAYER
            MAD_ERROR_BADSCALEFACTOR  MAD_ERROR_BADDATAPTR
            MAD_ERROR_BADEMPHASIS     MAD_ERROR_BADBIGVALUES
            
  • :flag

            MAD_FLAG_COPYRIGHT        MAD_FLAG_FREEFORMAT
            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

            MAD_F_ONE                 MAD_F_MAX
            MAD_F_FRACBITS            MAD_F_MIN 
  • :layer

            MAD_LAYER_I               MAD_LAYER_III
            MAD_LAYER_II
  • :mode

            MAD_MODE_SINGLE_CHANNEL   MAD_MODE_STEREO
            MAD_MODE_DUAL_CHANNEL     MAD_MODE_JOINT_STEREO
  • :timer

            MAD_TIMER_RESOLUTION
  • :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_UNITS_24000_HZ        MAD_UNITS_HOURS
            MAD_UNITS_32000_HZ
            MAD_UNITS_44100_HZ
            MAD_UNITS_48000_HZ
            

AUTHOR

Mark McConnell <mischke@cpan.org>

SEE ALSO

perl(1)