| 1 | package Peta::Synth::Profile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: what a piece will cost to render, second by second, before it is rendered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # What a piece will cost to render, before it is rendered: its voices (when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # each starts and falls silent, what it is made of: Peta::Synth::Synth's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # foresee), what sounds at each moment, and with an engine's costs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # measured (calibrate) how long each second of it takes to render. For | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # planning: which notes to prepare, which stretches to render ahead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # The cost model: a quantum costs the synthesizer's own work (events, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # mixing, the reverb, the limiter: quantum), and each voice sounding in it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # its controls (voice) and what it is made of: its partials (partial each; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # filter each more under a moving filter), its string, its FM, its bands of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # noise. calibrate measures them on an engine, as render_arrays spends them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use List::Util qw(max min sum0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Peta::Synth::Engine::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Peta::Synth::Patch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Peta::Synth::Synth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = '0.2610180'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use constant QUANTUM => 1024; # as Peta::Synth plays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # A piece's voices: timeline (events, times in seconds, as Peta::Synth::Synth's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # schedule takes them), length (seconds, where the events end), tail (the most | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # seconds sounded after it: 30, as rendering does), rate (48000), partials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # (48), bank, waves (as Peta::Synth::Synth takes them: 1 by default; a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # store is filled with the sequences the piece needs). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub new ($class, %arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | my $rate = $arg{rate} // 48000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"rate"} // 48000
MC/DC0%0/1
$arg{"rate"} // 48000
$arg{"rate"}
Truth table50%1/2
A
A= $arg{"rate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my $partials = $arg{partials} // 48; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"partials"} // 48
MC/DC0%0/1
$arg{"partials"} // 48
$arg{"partials"}
Truth table50%1/2
A
A= $arg{"partials"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $synth = Peta::Synth::Synth->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | rate => $rate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | partials => $partials, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | engine => Peta::Synth::Engine::Perl->new, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | waves => $arg{waves} // 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"waves"} // 1
MC/DC0%0/1
$arg{"waves"} // 1
$arg{"waves"}
Truth table50%1/2
A
A= $arg{"waves"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | $synth->apply_edits($arg{bank}) if $arg{bank}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $synth->schedule($arg{timeline}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | my $length = $arg{length} // max(0, map { $_->{time} } @{ $arg{timeline} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg{"length"} // &max(0, map({$_->{"time"};} @{$arg{"timeline"};}))
MC/DC0%0/2
$arg{"length"} // &max(0, map({$_->{"time"};} @{$arg{"timeline"};}))
$arg{"length"}
&max(0, map({$_->{"time"};} @{$arg{"timeline"};}))
Truth table33%1/3
A // B
A= $arg{"length"}B= &max(0, map({$_->{"time"};} @{$arg{"timeline"};}))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | my $until = $length + ($arg{tail} // 30); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"tail"} // 30
MC/DC0%0/1
$arg{"tail"} // 30
$arg{"tail"}
Truth table50%1/2
A
A= $arg{"tail"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my @voices = map { _summary($_, $until) } grep { $_->{start} < $until } @{ $synth->foresee }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | rate => $rate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | length => $length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | until => $until, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | end => max($length, map { $_->{end} } @voices), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$synth->waves // 0
MC/DC0%0/1
$synth->waves // 0
$synth->waves
Truth table50%1/2
A
A= $synth->waves
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | voices => \@voices, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | partials => $partials, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | bank => $arg{bank}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | timeline => $arg{timeline}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | waves => $synth->waves // 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # A foreseen voice as the profile keeps it: when it sounds (to $until at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # most), whose it is, and what it is made of. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | sub _summary ($v, $until) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_summary: called CC=9 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | my $voice = $v->{voice}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | my $wave = $voice->{wave}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | start => $v->{start}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | end => $v->{end} eq 'inf' || $v->{end} > $until ? $until : $v->{end}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | channel => $voice->{channel}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | program => $v->{program}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | key => $voice->{key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | velocity => $voice->{velocity}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | ▶ | partials => $wave ? 0 : scalar @{ $voice->{ratio} }, # turned one by one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | copies => $wave ? scalar @$wave : 0, # read from wave sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | filter => $voice->{fmode} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | string => $voice->{string} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | fm => $voice->{fm} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | bands => scalar @{ $voice->{bands} // [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition40%2/5
$v->{"end"} eq "inf" or $v->{"end"} > $until
$voice->{"bands"} // []
MC/DC0%0/2
$v->{"end"} eq "inf" or $v->{"end"} > $until
$v->{"end"} eq "inf"
$v->{"end"} > $until
MC/DC0%0/1
$voice->{"bands"} // []
$voice->{"bands"}
Truth table33%1/3
A or B
A= $v->{"end"} eq "inf"B= $v->{"end"} > $until
Truth table50%1/2
A
A= $voice->{"bands"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub voices ($self) { return $self->{voices} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
voices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub seconds ($self) { return $self->{length} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seconds: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # The steps (seconds) a voice sounds in: [index, share of the step], the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # last step the one holding the end. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | ▶ | sub _steps ($v, $step, $count) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_steps: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | my @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | for my $i (int($v->{start} / $step) .. min($count - 1, int($v->{end} / $step))) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 52 | my $share = (min($v->{end}, ($i + 1) * $step) - max($v->{start}, $i * $step)) / $step; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 52 | ▶ | push @steps, [ $i, $share ] if $share > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | return @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # What sounds, step by step (seconds): for each step from 0 to where the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # last voice falls silent, the time it starts at and the mean, over the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # step, of the voices sounding, their partials (and those under a filter), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # the copies read from wave sequences, strings, FM voices and bands of noise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | sub load ($self, $step = 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $count = int($self->{end} / $step) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my @load; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | for my $i (0 .. $count - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | push @load, { at => $i * $step, map { $_ => 0 } qw(voices partials filtered copies strings fm bands) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | for my $v (@{ $self->{voices} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | for (_steps($v, $step, $count)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 26 | my ($i, $share) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | my $l = $load[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 26 | $l->{voices} += $share; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 26 | $l->{partials} += $share * $v->{partials}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | $l->{filtered} += $share * $v->{partials} * $v->{filter}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | $l->{copies} += $share * $v->{copies}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | $l->{strings} += $share * $v->{string}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 26 | $l->{fm} += $share * $v->{fm}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | $l->{bands} += $share * $v->{bands}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | return \@load; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Seconds of rendering a second of sound takes, step by step, by the costs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # calibrate measured: [ { at, load } ] (load 1: just in real time). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | sub predict ($self, $costs, $step = 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
predict: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $count = int($self->{end} / $step) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my @spent = (0) x $count; # a quantum's seconds, the voices' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | for my $v (@{ $self->{voices} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | my $cost = _voice_cost($v, $costs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | $spent[ $_->[0] ] += $_->[1] * $cost for _steps($v, $step, $count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my $quanta = $self->{rate} / QUANTUM; # a second's | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | return [ map { { at => $_ * $step, load => ($costs->{quantum} + $spent[$_]) * $quanta } } 0 .. $count - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # A voice's seconds a quantum: what its program (or drum) was measured to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # cost beside its partials (its filter in that), and its partials; one not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # measured what it is made of. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | sub _voice_cost ($v, $costs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_voice_cost: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | ▶ | my $own = defined $v->{program} ? $costs->{programs}{ $v->{program} } : $costs->{drums}{ $v->{key} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | return $own + $v->{partials} * $costs->{partial} if defined $own; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | return $costs->{voice} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | + $v->{copies} * $costs->{copy} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | + $v->{string} * $costs->{string} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | + $v->{fm} * $costs->{fm} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | + $v->{bands} * $costs->{band} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | + $v->{partials} * ($costs->{partial} + $v->{filter} * $costs->{filter}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # The programs the piece plays, and its drums (their keys). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | sub programs ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
programs: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | return [ sort { $a <=> $b } grep { !$seen{$_}++ } map { $_->{program} // () } @{ $self->{voices} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{"program"} // ()
MC/DC0%0/2
$_->{"program"} // ()
$_->{"program"}
()
Truth table66%2/3
A // B
A= $_->{"program"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub drums ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drums: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return [ sort { $a <=> $b } grep { !$seen{$_}++ } map { defined $_->{program} ? () : $_->{key} } @{ $self->{voices} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # The notes the piece plays, as wavetables would be made for them: program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # (or the drum: program undef, the key its drum), key, velocity; how often, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # for how many seconds in all. Most seconds first; the same seconds by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # program (the drums last), key and velocity. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub notes ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notes: called CC=9 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my %note; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | for my $v (@{ $self->{voices} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | my $id = join ',', $v->{program} // 'drum', $v->{key}, $v->{velocity}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$v->{"program"} // "drum"
MC/DC100%1/1
$v->{"program"} // "drum"
$v->{"program"}
Truth table100%2/2
A
A= $v->{"program"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | ▶ | my $n = $note{$id} //= { program => $v->{program}, key => $v->{key}, velocity => $v->{velocity}, count => 0, seconds => 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$note{$id} //= {"program", $v->{"program"}, "key", $v->{"key"}, "velocity", $v->{"velocity"}, "count", 0, "seconds", 0}
MC/DC0%0/1
$note{$id} //= {"program", $v->{"program"}, "key", $v->{"key"}, "velocity", $v->{"velocity"}, "count", 0, "seconds", 0}
$note{$id}
Truth table50%1/2
A
A= $note{$id}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | $n->{count}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | $n->{seconds} += $v->{end} - $v->{start}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | $b->{seconds} <=> $a->{seconds} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | || ($a->{program} // 128) <=> ($b->{program} // 128) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | || $a->{key} <=> $b->{key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | || $a->{velocity} <=> $b->{velocity} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | ▶ | } values %note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition23%3/13
$Peta::Synth::Profile::b->{'seconds'} <=> $Peta::Synth::Profile::a->{'seconds'} || ($Peta::Synth::Profile::a->{'program'} // 128) <=> ($Peta::Synth::Profile::b->{'program'} // 128) || $Peta::Synth::Profile::a->{'key'} <=> $Peta::Synth::Profile::b->{'key'} || $Peta::Synth::Profile::a->{'velocity'} <=> $Peta::Synth::Profile::b->{'velocity'}
$Peta::Synth::Profile::b->{"seconds"} <=> $Peta::Synth::Profile::a->{"seconds"} or ($Peta::Synth::Profile::a->{"program"} // 128) <=> ($Peta::Synth::Profile::b->{"program"} // 128) or $Peta::Synth::Profile::a->{"key"} <=> $Peta::Synth::Profile::b->{"key"}
$Peta::Synth::Profile::b->{"seconds"} <=> $Peta::Synth::Profile::a->{"seconds"} or ($Peta::Synth::Profile::a->{"program"} // 128) <=> ($Peta::Synth::Profile::b->{"program"} // 128)
$Peta::Synth::Profile::a->{"program"} // 128
$Peta::Synth::Profile::b->{"program"} // 128
MC/DC0%0/4
$Peta::Synth::Profile::b->{'seconds'} <=> $Peta::Synth::Profile::a->{'seconds'} || ($Peta::Synth::Profile::a->{'program'} // 128) <=> ($Peta::Synth::Profile::b->{'program'} // 128) || $Peta::Synth::Profile::a->{'key'} <=> $Peta::Synth::Profile::b->{'key'} || $Peta::Synth::Profile::a->{'velocity'} <=> $Peta::Synth::Profile::b->{'velocity'}
$Peta::Synth::Profile::b->{"seconds"} <=> $Peta::Synth::Profile::a->{"seconds"}
$Peta::Synth::Profile::a->{"program"}
$Peta::Synth::Profile::a->{"key"} <=> $Peta::Synth::Profile::b->{"key"}
$Peta::Synth::Profile::a->{'velocity'} <=> $Peta::Synth::Profile::b->{'velocity'}
MC/DC0%0/1
$Peta::Synth::Profile::b->{"program"} // 128
$Peta::Synth::Profile::b->{"program"}
Truth table20%1/5
A or B or C || D
A= $Peta::Synth::Profile::b->{"seconds"} <=> $Peta::Synth::Profile::a->{"seconds"}B= $Peta::Synth::Profile::a->{"program"}C= $Peta::Synth::Profile::a->{"key"} <=> $Peta::Synth::Profile::b->{"key"}D= $Peta::Synth::Profile::a->{'velocity'} <=> $Peta::Synth::Profile::b->{'velocity'}
Truth table0%0/2
A
A= $Peta::Synth::Profile::b->{"program"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # The costs of an engine, in seconds a quantum (of QUANTUM samples): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # quantum (the synthesizer's own work), voice, partial, filter (a partial's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # more under a moving filter), copy (a copy of a voice read from a wave | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # sequence), string, fm, band: each from 16 held notes of a plain patch of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # one kind. And with programs and drums (keys) given (and waves, as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # synthesizer will have them), what a voice of each costs beside its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # partials, from 8 notes of it: programs => { n => seconds }, drums => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # { key => seconds }. Each the quickest of a few quanta, the notes' first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # quantum (making them) not counted, after the engine (and pperl's JIT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # warmed up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub calibrate (%arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
calibrate: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $engine = $arg{engine} // die "calibrate needs an engine\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$arg{"engine"} // die("calibrate needs an engine\n")
MC/DC0%0/1
$arg{"engine"} // die("calibrate needs an engine\n")
$arg{"engine"}
Truth table0%0/2
A
A= $arg{"engine"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $rate = $arg{rate} // 48000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$arg{"rate"} // 48000
MC/DC0%0/1
$arg{"rate"} // 48000
$arg{"rate"}
Truth table0%0/2
A
A= $arg{"rate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my $timer = sub (%test) { _quickest($engine, $rate, %test) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | _quickest($engine, $rate, _plain({}, 48)) for 1 .. 2; # warming up | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ($quantum) = $timer->(keys => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # A voice of a plain patch so changed: its seconds a quantum. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $each = sub ($edits, $partials, $waves = 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($took) = $timer->(_plain($edits, $partials, $waves)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return max(0, ($took - $quantum) / 16); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my %costs = (engine => $engine->name, quantum => $quantum); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $p8 = $each->({}, 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $p48 = $each->({}, 48); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $costs{partial} = max(0, ($p48 - $p8) / 40); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $costs{voice} = max(0, $p8 - 8 * $costs{partial}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $costs{filter} = max(0, ($each->({ filter => 'lp12', filter_cutoff => 2000 }, 48) - $p48) / 48); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $costs{copy} = max(0, $each->({}, 48, 1) - $costs{voice}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $costs{string} = max(0, $each->({ partials => [], string => 1, string_decay => 30 }, 48) - $costs{voice}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $costs{fm} = max(0, $each->({ partials => [], fm => 1 }, 48) - $costs{voice}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $costs{band} = max(0, $each->({ partials => [], noise => 1, noise_sustain => 1, noise_decay => 0 }, 48) - $costs{voice}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # A program's or a drum's voices: beside their partials, what they cost. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $waves = $arg{waves} // ($engine->can('reads_waves') ? $engine->reads_waves : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg{"waves"} // ($engine->can("reads_waves") ? $engine->reads_waves : 1)
MC/DC0%0/2
$arg{"waves"} // ($engine->can("reads_waves") ? $engine->reads_waves : 1)
$arg{"waves"}
($engine->can("reads_waves") ? $engine->reads_waves : 1)
Truth table0%0/3
A // B
A= $arg{"waves"}B= ($engine->can("reads_waves") ? $engine->reads_waves : 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my $own = sub (%test) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | my ($took, $partials, $n) = $timer->(%test, bank => $arg{bank}, partials => $arg{partials} // 48, waves => $waves); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$arg{"partials"} // 48
MC/DC0%0/1
$arg{"partials"} // 48
$arg{"partials"}
Truth table0%0/2
A
A= $arg{"partials"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return undef if $took > 1e9 || !$n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$took > "1000000000" or not $n
MC/DC0%0/2
$took > "1000000000" or not $n
$took > "1000000000"
not $n
Truth table0%0/3
A or not(B)
A= $took > "1000000000"B= not $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return max(0, ($took - $quantum) / $n - $partials / $n * $costs{partial}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | for my $program (@{ $arg{programs} // [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$arg{"programs"} // []
MC/DC0%0/1
$arg{"programs"} // []
$arg{"programs"}
Truth table0%0/2
A
A= $arg{"programs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $c = $own->(program => $program, keys => [ map { 48 + 2 * $_ } 0 .. 7 ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $costs{programs}{$program} = $c if defined $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | for my $key (@{ $arg{drums} // [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$arg{"drums"} // []
MC/DC0%0/1
$arg{"drums"} // []
$arg{"drums"}
Truth table0%0/2
A
A= $arg{"drums"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $c = $own->(channel => 9, keys => [ ($key) x 8 ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $costs{drums}{$key} = $c if defined $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return \%costs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # A test of 16 held notes of a plain patch (one partial-for-partial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # sustained sound) with these changes, at most $partials partials. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub _plain ($edits, $partials, $waves = 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | my %plain = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | %{ Peta::Synth::Patch::defaults() }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | attack => 0.001, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sustain => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | decay => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | release => 0.1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | cutoff => 20000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | noise => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | unison => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | vibrato => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | tremolo => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | bank => { programs => { 0 => { %plain, %$edits } } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | program => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | partials => $partials, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | keys => [ map { 36 + 2 * $_ } 0 .. 15 ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | waves => $waves, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # The quickest quantum of notes held (so long as they all sound): its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # seconds, the partials turned one by one, and how many notes sounded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # (drums of a class cut each other off). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub _quickest ($engine, $rate, %test) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quickest: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my $synth = Peta::Synth::Synth->new(rate => $rate, partials => $test{partials} // 48, engine => $engine, waves => $test{waves}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$test{"partials"} // 48
MC/DC0%0/1
$test{"partials"} // 48
$test{"partials"}
Truth table0%0/2
A
A= $test{"partials"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $synth->apply_edits($test{bank}) if $test{bank}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $ch = $test{channel} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$test{"channel"} // 0
MC/DC0%0/1
$test{"channel"} // 0
$test{"channel"}
Truth table0%0/2
A
A= $test{"channel"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $synth->play({ type => 'program', channel => $ch, program => $test{program} }) if defined $test{program}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $synth->play({ type => 'note_on', channel => $ch, key => $_, velocity => 100 }) for @{ $test{keys} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $synth->render_arrays(QUANTUM); # the notes made: not counted | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $partials = sum0(map { $_->{wave} ? 0 : $_->partials } @{ $synth->{active} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $sounding = $synth->active; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my ($best, $spent) = (9**9**9, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | for (1 .. 8) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | last if $synth->active < $sounding; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $started = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $synth->render_arrays(QUANTUM); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $took = Time::HiRes::time() - $started; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | $best = $took if $took < $best; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | last if ($spent += $took) > 0.3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return ($best, $partials, $sounding); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # What rendering the piece takes, measured: rendered by an engine as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # Peta::Synth plays it, quantum by quantum; the seconds spent in each step: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # [ { at, load } ]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub measure ($self, $engine, $step = 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
measure: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $rate = $self->{rate}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $synth = Peta::Synth::Synth->new(rate => $rate, partials => $self->{partials}, engine => $engine, waves => $self->{waves}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | $synth->apply_edits($self->{bank}) if $self->{bank}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $synth->schedule($self->{timeline}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $until = int($self->{until} * $rate); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my @spent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | while ($synth->busy && $synth->now < $until) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$synth->busy and $synth->now < $until
MC/DC0%0/2
$synth->busy and $synth->now < $until
$synth->busy
$synth->now < $until
Truth table0%0/3
A and B
A= $synth->busyB= $synth->now < $until
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $at = $synth->now / $rate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $started = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $synth->render_arrays(QUANTUM); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $spent[ int($at / $step) ] += Time::HiRes::time() - $started; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | return [ map { { at => $_ * $step, load => ($spent[$_] // 0) / $step } } 0 .. $#spent ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$spent[$_] // 0
MC/DC0%0/1
$spent[$_] // 0
$spent[$_]
Truth table0%0/2
A
A= $spent[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||