NAME
Peta::Synth::Output - sound to WAV, FLAC, MP3, Ogg Vorbis and Opus files
VERSION
version 0.2610180
SYNOPSIS
use Peta::Synth::Output;
my $out = Peta::Synth::Output->open('song.flac', rate => 48000, bits => 24);
while (...) {
$out->write(\@left, \@right); # floats in -1 .. 1
}
$out->close;
my $have = Peta::Synth::Output::formats(); # { wav => 'native', flac => 'native', mp3 => 'external', ... }
DESCRIPTION
Writers that take sound in pieces. WAV, FLAC, MP3 and Ogg Vorbis are written by this distribution and need nothing else; Opus is, for now, encoded by ffmpeg fed through a pipe. Samples outside -1 .. 1 are clipped; 16-bit output is dithered.
METHODS
open
open($file, rate => 48000, bits => 16, quality => ..., ffmpeg_gapless => 0): a writer for the format the extension names (.wav, .flac, .mp3, .ogg, .oga, .opus). bits is 16, 24 or 32 (float) for WAV, 16 or 24 for FLAC. quality is the compression level for FLAC (0 .. 8, default 5), the bitrate in kbit/s for MP3 (default 192; 32 to 320; at 16 to 24 kHz default 96, 8 to 160) or V0 to V9 for a variable one (as LAME's -V), the Vorbis quality (0 .. 10, default 6), kbit/s for Opus (default 160). MP3 is written at 32, 44.1 or 48 kHz (MPEG-1) or 16, 22.05 or 24 kHz (MPEG-2). ffmpeg_gapless: an MP3's Info tag names the encoder LavfPeta, so that FFmpeg plays it gapless; see "THE ENCODER'S NAME" in Peta::MP3::Encode.
write, close
write(\@left, \@right) appends; close finishes the file and returns its name.
write_file
write_file($file, \@left, \@right, %opt): a whole sound at once.
FUNCTIONS
formats
The formats this machine can write: native or external.
format_of
The format a file name asks for.
interleave
interleave(\@left, \@right): the samples of both channels in one array, left, right, left, ...
to_integers
to_integers(\@left, \@right, $bits, \$state): interleaved integer samples of 16 bits (dithered) or 24 bits.
which
The path of a program on the PATH, or nothing.
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.