NAME
Peta::Synth::Engine - the engines that render voices
VERSION
version 0.2610180
SYNOPSIS
my $engine = Peta::Synth::Engine::create('auto', rate => 48000, partials => 48); # or 'perl', 'pdl', 'gpu'
print join ' ', Peta::Synth::Engine::available(); # gpu pdl perl
printf "%s %.1fx\n", $_->{name}, $_->{speed} for Peta::Synth::Engine::measure();
DESCRIPTION
Every engine renders the voice model of Peta::Synth::Voice and sounds the same; they differ in speed. perl is everywhere (and compiled by pperl's JIT), pdl needs PDL, gpu needs pperl with WebGPU and a graphics card. auto takes the fastest of those there are, measured, or $ENV{PETA_SYNTH_ENGINE} when set.
FUNCTIONS
create
create($name, %arg): an engine; dies if it is not available. For auto, rate and partials say what the synthesizer will have, for the measurement ("choose").
choose
choose(rate = $rate, partials => $partials)>: the name of the engine auto takes: $ENV{PETA_SYNTH_ENGINE} when set, or the fastest.
measure
measure(rate = $rate, partials => $partials)>: how fast each engine here renders a test, fastest first: [ { name => 'gpu', speed => 9.2 }, ... ], the speed in seconds of sound per second. The test is a chord of sixteen notes on four instruments and three drums, with the reverb, as the synthesizer plays them; the first quanta are not timed, so that pperl's JIT has compiled the loops. It takes a fraction of a second per engine.
Which engine is fastest depends on how much there is to render: the GPU costs a fixed time per quantum and pays from some number of partials on; the test is a moderate load.
try
The same, or undef with the reason in $@.
available, names
The engines that work here, and all of them.
perl_info
What this perl is and has: perl (pperl or perl5), version (pperl's own under pperl, not the perl it is compatible with), jit, pdl, gpu, cpus.
cpus
The number of processors.
THE ENGINE INTERFACE
- new
-
Dies when the engine cannot run here.
- name
- render
-
render(\@voices, $n, $rate): the voices' next$nsamples (a multiple of 64), each voice under its envelope and channel gains, mixed into three array references: left, right and the reverb send. The voices'phaseandnstateare carried on.
AUTHOR
PetaMem s.r.o. <info@petamem.com>
COPYRIGHT
Copyright (c) 2026 PetaMem s.r.o.
LICENSE
This package is free software, dual-licensed under the Artistic License 2.0 and the BSD 2-Clause License. See the LICENSE file of the distribution.