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

Audio::Wav::Write - Module for writing Microsoft Wav files.

SYNOPSIS

        use Audio::Wav;

        my $wav = new Audio::Wav;

        my $sample_rate = 44100;
        my $bits_sample = 16;

        my $details =   {
                        'bits_sample'   => $bits_sample,
                        'sample_rate'   => $sample_rate,
                        'channels'      => 1,
                        };

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

        &add_sine( 200, 1 );

        sub add_sine {
                my $hz = shift;
                my $length = shift;
                my $pi = ( 22 / 7 ) * 2;
                $length *= $sample_rate;
                my $max_no =  ( 2 ** $bits_sample ) / 2;
                for my $pos ( 0 .. $length ) {
                        $time = $pos / $sample_rate;
                        $time *= $hz;
                        my $val = sin $pi * $time;
                        my $samp = $val * $max_no;
                        $write -> write( $samp );
                }
        }

        $write -> finish();

DESCRIPTION

Currently only writes to a file.

AUTHOR

Nick Peskett - nick@soup.demon.co.uk

SEE ALSO

Audio::Wav

Audio::Wav::Read

NOTES

This module shouldn't be used directly, a blessed object can be returned from Audio::Wav.

METHODS

finish

Finishes off & closes the current wav file.

        $write -> finish();

add_cue

Adds a cue point to the wav file.

        $write -> add_cue( $byte_offset, "label", "note"  );

file_name

Returns the current filename (silly, I know).

        my $file = $write -> file_name();

write

Adds a sample to the current file.

        $write -> write( @sample_channels );

Each element in @sample_channels should be in the range of;

        where $samp_max = ( 2 ** bits_per_sample ) / 2
        -$samp_max to +$samp_max

write_raw

Adds a some pre-packed data to the current file.

        $write -> write_raw( $data, $data_length );

Where;

        $data is the packed data
        $data_length (optional) is the length in bytes of the data