flac-0.2.0: Complete high-level binding to libFLAC
Copyright© 2016–present Mark Karpov
LicenseBSD 3 clause
MaintainerMark Karpov <markkarpov92@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Codec.Audio.FLAC.StreamEncoder

Description

The module contains a Haskell interface to FLAC stream encoder.

How to use this module

Just call the encodeFlac function with EncoderSettings, input and output file names. The encodeFlac function only encodes vanilla WAVE and RF64.

Low-level details

The implementation uses the reference implementation of FLAC—libFLAC (C library) under the hood. This means you'll need at least version 1.3.0 of libFLAC (released 26 May 2013) installed for the binding to work.

The binding works with minimal overhead compared to the C implementation. Encoding speed is equal to that of flac command line tool. Memory consumption is minimal and remains constant regardless of size of file to decode.

Synopsis

Documentation

data EncoderSettings Source #

Parameters of the stream encoder. Note that the encoderCompression parameter influences a number of other parameters on its own as specified here https://xiph.org/flac/api/group__flac__stream__encoder.html#gae49cf32f5256cb47eecd33779493ac85. The parameters that it sets automatically are wrapped in Maybes, so you can choose whether to use the value that is set by encoderCompression specifying Nothing (default), or use something specific by passing a value inside Just. Thorough understanding of the FLAC format is necessary to achieve good results, though.

Constructors

EncoderSettings 

Fields

data EncoderException Source #

Exception that is thrown when encoding fails for some reason.

Constructors

EncoderInvalidSampleFormat SampleFormat

Input WAVE file had this sample format, which is not supported (usually happens with floating point samples right now).

EncoderInitFailed EncoderInitStatus

Encoder initialization failed.

EncoderFailed EncoderState

Encoder failed.

data EncoderInitStatus Source #

Status of encoder initialization process.

Constructors

EncoderInitStatusOK

Initialization was successful.

EncoderInitStatusEncoderError

General failure to set up encoder.

EncoderInitStatusUnsupportedCointainer

The library was not compiled with support for the given container format.

EncoderInitStatusInvalidCallbacks

A required callback was not supplied.

EncoderInitStatusInvalidNumberOfChannels

The encoder has an invalid setting for the number of channels.

EncoderInitStatusInvalidBitsPerSample

The encoder has an invalid setting for the bits-per-sample. FLAC supports 4-32 bps but the reference encoder currently supports only up to 24 bps.

EncoderInitStatusInvalidSampleRate

The encoder has an invalid setting for the sample rate.

EncoderInitStatusInvalidBlockSize

The encoder has an invalid setting for the block size.

EncoderInitStatusInvalidMaxLpcOrder

The encoder has an invalid setting for the maximum LPC order.

EncoderInitStatusInvalidQlpCoeffPrecision

The encoder has an invalid setting for the precision of the quantized linear predictor coefficients.

EncoderInitStatusBlockSizeTooSmallForLpcOrder

The specified block size is less than the maximum LPC order.

EncoderInitStatusNotStreamable

The encoder is bound to the Subset but other settings violate it.

EncoderInitStatusInvalidMetadata

The metadata input to the encoder is invalid (should never happen with this binding).

EncoderInitStatusAlreadyInitialized

Initialization was attempted on already initialized encoder.

Instances

Instances details
Bounded EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Enum EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Eq EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Ord EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Read EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Show EncoderInitStatus Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

data EncoderState Source #

Enumeration of encoder states.

Constructors

EncoderStateOK

The encoder is in the normal OK state and samples can be processed.

EncoderStateUninitialized

The encoder is in the uninitialized state.

EncoderStateOggError

An error occurred in the underlying Ogg layer.

EncoderStateVerifyDecoderError

An error occurred in the underlying verify stream decoder.

EncoderStateVerifyMismatchInAudioData

The verify decoder detected a mismatch between the original audio signal and the decoded audio signal.

EncoderStateClientError

One of the callbacks returned a fatal error.

EncoderStateIOError

An I/O error occurred while opening/reading/writing a file.

EncoderStateFramingError

An error occurred while writing the stream.

EncoderStateMemoryAllocationError

Memory allocation failed.

Instances

Instances details
Bounded EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Enum EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Eq EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Ord EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Read EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

Show EncoderState Source # 
Instance details

Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types

encodeFlac Source #

Arguments

:: MonadIO m 
=> EncoderSettings

Encoder settings

-> FilePath

File to encode

-> FilePath

Where to save the resulting FLAC file

-> m () 

Encode a WAVE file or RF64 file to native FLAC.

If the input file is not a valid WAVE file, WaveException will be thrown. EncoderException is thrown when underlying FLAC encoder reports a problem.

Please note that there are a number of limitations on parameters of input audio stream (imposed by current reference FLAC implementation):

  • Number of channels may be only 1–8 inclusive.
  • Supported values for bits per sample are 4–24 inclusive.
  • Acceptable sample rate lies in the range 1–655350 inclusive.