
tals
Novice
Jul 28, 2011, 12:58 AM
Post #1 of 1
(2436 views)
|
Multi channel WAV file.
|
Can't Post
|
|
Hi, everyone, I need some help. I'm able to create a multi channel WAV file (using Audio::wav) but I'm no able to name each channel. Is there any way to give a diffrent name to each channel ? for example channel 0 name is "Phase 0", channel 1 name is "Phase 1" and channel 2 name is "Phase 2". You'll be able to open the file for review with Audacity http://audacity.sourceforge.net.
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; ## Wave file module use Audio::Wav; ## Pi Constants use Math::Trig ':pi'; my $wav = new Audio::Wav; my $sample_rate = 44100; my $bits_sample = 16; my $details = { 'bits_sample' => $bits_sample, 'sample_rate' => $sample_rate, 'channels' => 3, # 'info' => {}, # 'display' => [[0,1,2],["Phase 0","Phase 1","Phase 2"]], # if you'd like this module not to use a write cache, uncomment the next line #'no_cache' => 1, }; my $write = $wav -> write( '3ph.wav', $details ); &add_sine( 200, 1 ); sub add_sine { my $f = shift; my $length = shift; $length *= $sample_rate; my $max_no = (2 ** ($bits_sample - 1)) - 1; for my $pos ( 0 .. $length ) { my $ph0 = $max_no * sin(pi2 * $f * ($pos / $sample_rate)); my $ph1 = $max_no * sin(pi2 * $f * ($pos / $sample_rate) + pi2/3); my $ph2 = $max_no * sin(pi2 * $f * ($pos / $sample_rate) - pi2/3); # printf "tick #%d, phase0 = %.4f, phase1 = %.4f, phase2 = %.4f\n", $pos, $ph0, $ph1, $ph2; $write -> write( ($ph0, $ph1, $ph2) ); } } #print Dumper \$write; $write -> finish();
|