Wav::Write(3pm)

πŸ“¦
version 0.14 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Wav::Write β€” bestie edition πŸ’–

okay so you found the manual page for Wav::Write(3pm), which lives in the User Contributed Perl Documentation corner of the Perl universe, and honestly? it's giving audio crafting. pull up a chair, we're writing Microsoft WAV files together and it's gonna be a whole moment. πŸŽ€


✨ NAME ✨

Audio::Wav::Write β€” the module for writing Microsoft WAV files. that's it, that's the whole identity. πŸ’…


🌸 SYNOPSIS 🌸

here's the vibe. copy-paste this into your soul (and your editor):

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,
    # if you'd like this module not to use a write cache, uncomment the next line
    #'no_cache'     => 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 - 1;
    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();

not the 22 / 7 pi approximation living its best life in there 😭 iconic, no notes, we stan an approximation. πŸ¦‹


πŸ‘‘ DESCRIPTION πŸ‘‘

Currently only writes to a file. that's the whole lore for now. πŸ’€


🌈 SEE ALSO 🌈

  • Audio::Wav
  • Audio::Wav::Read

go read the siblings, they're the other half of the family. 🫢


πŸ™ˆ NOTES πŸ™ˆ

this module shouldn't be used directly, okay?? a blessed object can be returned from Audio::Wav, and that's how you're supposed to get one. so like, don't go creating it yourself, let Audio::Wav do the matchmaking. main character energy is inherited, not manufactured. πŸ’…


⭐ METHODS ⭐

πŸ’— finish

Finishes off & closes the current wav file. like closing the group chat when the conversation has run its course. (affectionate.)

$write -> finish();

πŸŽ€ add_cue

Adds a cue point to the wav file. and here's the cute part: if $sample is undefined then the position will be the current position (end of all data written so far). so it just... knows where it is. self-aware king. ✨

# $byte_offset for 01 compatibility mode
$write -> add_cue( $sample, "label", "note"  );

πŸ¦‹ set_sampler_info

All parameters are optional. literally all of them. no pressure, bestie, fill in what you want. πŸ“

my %info = (
    'midi_pitch_fraction' => 0,
    'smpte_format'        => 0,
    'smpte_offset'        => 0,
    'product'             => 0,
    'sample_period'       => 0,
    'manufacturer'        => 0,
    'sample_data'         => 0,
    'midi_unity_note'     => 65,
);
$write -> set_sampler_info( %info );

🌸 add_sampler_loop

All parameters are optional except start & end. those two are mandatory, they're the whole point, the rest are just vibes. 🧚

my $length = $read -> length_samples();
my( $third, $twothirds ) = map int( $length / $_ ), ( 3, 1.5 );
my %loop = (
    'start'                 => $third,
    'end'                   => $twothirds,
    'fraction'              => 0,
    'type'                  => 0,
);
$write -> add_sampler_loop( %loop );

🫢 add_display

(no description given, she's mysterious like that. πŸ”₯)


πŸ’œ set_info

Sets information to be contained in the wav file. metadata, but make it personal.

$write -> set_info( 'artist' => 'Nightmares on Wax', 'name' => 'Mission Venice' );

okay "Mission Venice" by Nightmares on Wax is an actual taste selection, whoever wrote this doc ate and left no crumbs. πŸ‘‘


🌟 file_name

Returns the current filename. just the name. that's her whole job.

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
⚠️ stay in range bestie!! -$samp_max to +$samp_max, no going rogue past the edges. 🌈

✨ write_raw

Adds some pre-packed data to the current file. you already did the packing, she's just delivering it. πŸ’…

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

Where;

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

$data_length is optional, btw. so it's giving low effort, high impact. πŸŽ€


πŸ”₯ write_raw_samples

Adds some pre-packed data to the current file, returns number of samples written. same as above but she reports back β€” communication queen. 🫢

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

Where;

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

🌈 AUTHORS 🌈

  • Nick Peskett (see http://www.peskett.co.uk/ for contact details).
  • Kurt George Gjerde <kurt.gjerde@media.uib.no>. (0.02-0.03)

both legends, both contributing to the cause. πŸ’–


and that's the page, bestie!! this doc is from perl v5.36.0, dated 2022-10-13, so if you're reading this on a newer perl, just know the lore goes back. now go write some wav files, you absolute icon. πŸ’…βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ«ΆπŸ‘‘

πŸ“¦ where this page comes from