NAME

Audio::Wav - Modules for reading & writing Microsoft WAV files.

SYNOPSIS

    use Audio::Wav;
    my $wav = new Audio::Wav;
    my $read = $wav -> read( 'input.wav' );
    my $write = $wav -> write( 'output.wav', $read -> details() );
    print "input is ", $read -> length_seconds(), " seconds long\n";

    $write -> set_info( 'software' => 'Audio::Wav' );
    my $data;
    while ( defined( $data = $read -> read_raw( $buffer ) ) ) {
	$write -> write_raw( $data );
    }
    my $length = $read -> length_samples();
    my( $third, $half, $twothirds ) = map int( $length / $_ ), ( 3, 2, 1.5 );
    my %samp_loop = (
		    'start'	=> $third,
		    'end'	=> $twothirds,
		    );
    $write -> add_sampler_loop( %samp_loop );
    $write -> add_cue( $half, "cue label 1", "cue note 1" );
    $write -> finish();

NOTES

All sample positions are now in sample offsets (unless option '.01compatible' is true).

DESCRIPTION

These modules provide a method of reading & writing uncompressed Microsoft WAV files.

SEE ALSO

L<Audio::Wav::Read>

L<Audio::Wav::Write>

METHODS

new

Returns a blessed Audio::Wav object. All the parameters are optional and default to 0

    my %options = (
		    '.01compatible'	=> 0,
		    'oldcooledithack'	=> 0,
		    'debug'		=> 0,
		  );
    my $wav = Audio::Wav -> new( %options );

write

Returns a blessed Audio::Wav::Write object.

    my $details = {
		    'bits_sample'	=> 16,
		    'sample_rate'	=> 44100,
		    'channels'		=> 2,
		  };

    my $write = $wav -> write( 'testout.wav', $details );

See Audio::Wav::Write for methods.

read

Returns a blessed Audio::Wav::Read object.

my $read = $wav -> read( 'testout.wav' );

See Audio::Wav::Read for methods.

set_error_handler

Specifies a subroutine for catching errors. The subroutine should take a hash as input. The keys in the hash are 'filename', 'message' (error message), and 'warning'. If no error handler is set, die and warn will be used.

    sub myErrorHandler {
	my( %parameters ) = @_;
	if ( $parameters{'warning'} ) {
	    # This is a non-critical warning
	    warn "Warning: $parameters{'filename'}: $parameters{'message'}\n";
	} else {
	    # Critical error!
	    die "ERROR: $parameters{'filename'}: $parameters{'message'}\n";
	}
    }
    $wav -> set_error_handler( \&myErrorHandler );

AUTHORS

Nick Peskett <cpan@peskett.com>.
Kurt George Gjerde <kurt.gjerde@media.uib.no>. (0.02)