Permalink
Browse files

発音中のループ処理をリファクタリング

  • Loading branch information...
techno-cat committed Oct 29, 2011
1 parent e5882fd commit 712a7a2620c1d037ff8936d86a45cfe86a7e3808
Showing with 7 additions and 11 deletions.
  1. +7 −11 p5-NeSynth/lib/Sound/NeSynth.pm
@@ -87,22 +87,18 @@ sub _create_oneshot {
if ( exists $amp->{attack} ) {
$attack = int( $samples_per_sec * $amp->{attack} );
}
- my $release = int( $samples_per_sec * $amp->{sec} ) - $attack;
+ my $gate_time = int( $samples_per_sec * $amp->{sec} );
- my @samples = ();
- if ( 0 < $attack ) {
- push @samples, map {
+ my @samples = map {
+ if ( $_ < $attack ) {
# 立ち上がりでプチッって言わないようにするための回避策なので、
# アタック感重視の係数が入れてある
$osc->() * $env->() * ( ($_ / $attack) ** 2.0 );
- } 0..($attack - 1);
- }
-
- if ( 0 < $release ) {
- push @samples, map {
+ }
+ else {
$osc->() * $env->();
- } 0..($release - 1);
- }
+ }
+ } 0..($gate_time - 1);
return \@samples;
}

0 comments on commit 712a7a2

Please sign in to comment.