# # Fourier Synthesis # sub fourier { my ($s1,@spectrum) = @_; my $coef; foreach $coef (@spectrum) { my @fpa = split /_/, $coef; # get frequency,phase and amplitude &osc::sinus($s1,$fpa[0],$fpa[1],$fpa[2],1); } } #### # # set the maximum amplitude to 1/-1 # sub normalize { my $s1 = shift; my $max = &max($s1); &scale($s1,1/$max) if $max; } # # reduce/expand the frequency of a given sample # sub redex { my ($s1,$new_freq) = @_; my $old_freq = $$s1[$SMP_FREQ]; my $cells = $$s1[$SMP_CELLS]; my $redex = $new_freq / $old_freq; return if($redex == 1); # Nothing to be done my $newcells = $cells * $redex; my $a; if($redex > 1) { # Expand the original sample } elsif($redex < 1) { # Reduce the original sample for($a = 0; $a < $newcells; $a++) { $$s1[$a + $SMP_DATA] = $$s1[$a/$redex + $SMP_DATA]; } $$#s1 = $newcells + $SMP_DATA; } $$s1[$SMP_CELLS] = $newcells; # update the amount of cells in sample }