Wav::Write(3pm)
π 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::WavAudio::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_maxto+$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
- ubuntu noble: libaudio-wav-perl 0.14-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libaudio-wav-perl 0.14-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libaudio-wav-perl 0.14-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms