Qu

codec.decode_flac

Builtin index · File I/O

result = codec.decode_flac(src, [channel=])

Input: src, channel · Output: result

What it is

Decodes a FLAC file to samples. src (string path, or Vec of bytes) is the stream. channel (number, optional, named only) picks one channel out of a multi-channel file, numbered from 0.

Overloads

What comes back depends on how many series the call produces, because there is no one type that fits both without lying about one of them.

src can be string or Vec.

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = codec.decode_flac(src, [channel=])
src string or Vecsrc is a mono file.
channel number, optionalchannel, when given, picks one channel out of any file, numbered from 0.
result Signal
Returns a Signal: the sample rate travels with the samples, so spectrogram/welch/sosfilt need no second argument. That is the whole reason Signal exists, and it is the common case.

Examples

Written for this form. Not run by the build — it needs something the repository cannot supply, so there is no captured output below.

import codec

x = codec.decode_flac("take.flac", channel = 0)
spectrogram(x)
CodeInputOutputDescription
result = codec.decode_flac(src, [channel=])
src string or Vecsrc is a file with more than one channel.
channel number, optionalchannel is absent, so no single series is picked out.
fs Numthe sample rate in Hz
bits Numbits per sample
frames Numsamples per channel
channels List or SignalList of Signal, one per channel, each already carrying the rate — so a.channels[0] goes straight into anything that takes a signal, with no reassembly needed
Returns a Record with fields: fs (Num, the sample rate in Hz), bits (Num, bits per sample), frames (Num, samples per channel), channels (List of Signal, one per channel, each already carrying the rate — so a.channels[0] goes straight into anything that takes a signal, with no reassembly needed). A Signal is one series and a Mat has nowhere to put the sample rate, which is why this form cannot hand back either of them.

Examples

Written for this form. Not run by the build — it needs something the repository cannot supply, so there is no captured output below.

import codec

a = codec.decode_flac("stereo.flac")
print("{a.fs} Hz, {len(a.channels)} channels, {a.frames} frames")
welch(a.channels[0])

How it works

One body for all three. They differ only in which decoder runs, because qu_codec gives them a common Audio -- so the shape a script gets back cannot drift between formats, which is the thing that would actually hurt.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.