## Chapter 7 Listing 024
# Loop over the mod file datastructures, splicing each note encountere
+d into
# the wav data
use PDL;
use Perl6::Variables;
my $offset = 0; # Output wav data offset
my $offset_step = $sample_rate / 10; # 10 times a second notes may ch
+ange
for my $position (@positions) {
for my $frame ( 0 .. 63 ) {
for my $channel ( 0 .. 3 ) {
my $note = @patterns[$position][$frame][$channel];
if($note->{sample}) {
# the note for this channel changed
my $scaled_sample = scale_sample($note, \@samples);
my $scaled_sample_length = $scaled_sample->dim(0);
$audio->range(
[$channel, $offset], [0, $scaled_sample_length]
) .= $scaled_sample;
}
}
$offset += $offset_step;
}
}
## Chapter 8 Listing 070
# @array_of_arrays will always contain exactly 5 array references afte
+r this,
# assuming @array_of_arrays and @array1 through @array5 have been decl
+ared
# Perl 5
my @array_of_arrays = (\@array1, \@array2, \@array3, \@array4);
push @array_of_arrays, \@array5;
# Perl 6
my @array_of_arrays = (@array1, @array2, @array3, @array4);
push @array_of_arrays, @array5;
Update: One more example added.
|