ピキューン!っていう音を作る

12/24に24個目の記事だなんて、めでたいですね!
1日遅れで収まれば良いと思ってましたが、なんとか追いつきました。
明日はまとめとかそういうのを書く予定なので、
Advent Calendarとしてのコードはこれで最後になりますね。

use v5.14;
use strict;
use warnings;

use Cassis;
use constant SAMPLING_RATE => 44100;

my $dco1 = Cassis::DCO::Tri->new( fs => SAMPLING_RATE, pitch => 1.5 );
my $dco2 = Cassis::DCO::Tri->new( fs => SAMPLING_RATE, pitch => 1.56 );

foreach my $release_time ( 0.7, 0.9, 1.2 ) {
    my $eg_out = Cassis::EG->new(
        fs      => SAMPLING_RATE,
        adsr    => [ 0.001, 0.0, 1.0, $release_time ],
        curve   => 1.3
    )->one_shot( gatetime => 0.001 );

    my $dco_out1 = $dco1->exec(
        num => scalar(@{$eg_out}),
        mod_pitch => {
            src => $eg_out,
            depth => 3.5
        }
    );
    my $dco_out2 = $dco2->exec(
        num => scalar(@{$eg_out}),
        mod_pitch => {
            src => $eg_out,
            depth => 3.5
        }
    );

    my $mixer_out = Cassis::Mixer::mix(
        { src => $dco_out1, volume => 0.8 },
        { src => $dco_out2, volume => 0.8 },
    );

    my $amp = Cassis::Amp->new();
    my $amp_out = $amp->exec(
        src => $mixer_out,
        mod_volume => {
            src => $eg_out,
            depth => 1.0
        }
    );

    Cassis::File::write(
        file => sprintf( 'pyuuuun_dco_%.1f.wav', $release_time ),
        fs => SAMPLING_RATE, channels => [ $amp_out ] );
}

Cassis::DCOを使うと、
3.5オクターブほど音程を変化させてるのが一目で分かりますね。

use v5.14;
use strict;
use warnings;

use Cassis;
use constant SAMPLING_RATE => 44100;

my $osc1 = Cassis::Osc::Tri->new( fs => SAMPLING_RATE, freq => 20 );
my $osc2 = Cassis::Osc::Tri->new( fs => SAMPLING_RATE, freq => 20.8 );

foreach my $release_time ( 0.7, 0.9, 1.2 ) {
    my $eg_out = Cassis::EG->new(
        fs      => SAMPLING_RATE,
        adsr    => [ 0.001, 0.0, 1.0, $release_time ],
        curve   => 0.6
    )->one_shot( gatetime => 0.001 );

    my $osc_out1 = $osc1->exec(
        num => scalar(@{$eg_out}),
        mod_freq => {
            src => $eg_out,
            depth => 46
        }
    );
    my $osc_out2 = $osc2->exec(
        num => scalar(@{$eg_out}),
        mod_freq => {
            src => $eg_out,
            depth => 46
        }
    );

    my $mixer_out = Cassis::Mixer::mix(
        { src => $osc_out1, volume => 0.8 },
        { src => $osc_out2, volume => 0.8 },
    );

    my $amp = Cassis::Amp->new();
    my $amp_out = $amp->exec(
        src => $mixer_out,
        mod_volume => {
            src => $eg_out,
            depth => 1.0
        }
    );

    Cassis::File::write(
        file => sprintf( 'pyuuuun_osc_%.1f.wav', $release_time ),
        fs => SAMPLING_RATE, channels => [ $amp_out ] );
}

Cassis::Oscだと、
周波数を指定するにしても、depthを指定するにしても、
なかなか思った通りにならなくて、とても苦労しました。

ただ、Cassis::DCOCassis::Oscは、
モジュレーションの掛かり方も異なるので、どちらを使うべきとかではないです。

おしまい。

Leave a Comment