Copyright | © 2016–present Mark Karpov |
---|---|
License | BSD 3 clause |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- data EncoderSettings = EncoderSettings {
- encoderCompression :: !Word32
- encoderBlockSize :: !Word32
- encoderVerify :: !Bool
- encoderDoMidSideStereo :: !(Maybe Bool)
- encoderLooseMidSideStereo :: !(Maybe Bool)
- encoderApodization :: !(Maybe (NonEmpty ApodizationFunction))
- encoderMaxLpcOrder :: !(Maybe Word32)
- encoderQlpCoeffPrecision :: !(Maybe Word32)
- encoderDoQlpCoeffPrecisionSearch :: !(Maybe Bool)
- encoderDoExhaustiveModelSearch :: !(Maybe Bool)
- encoderResidualPartitionOrders :: !(Maybe (Word32, Word32))
- defaultEncoderSettings :: EncoderSettings
- data EncoderException
- data EncoderInitStatus
- = EncoderInitStatusOK
- | EncoderInitStatusEncoderError
- | EncoderInitStatusUnsupportedCointainer
- | EncoderInitStatusInvalidCallbacks
- | EncoderInitStatusInvalidNumberOfChannels
- | EncoderInitStatusInvalidBitsPerSample
- | EncoderInitStatusInvalidSampleRate
- | EncoderInitStatusInvalidBlockSize
- | EncoderInitStatusInvalidMaxLpcOrder
- | EncoderInitStatusInvalidQlpCoeffPrecision
- | EncoderInitStatusBlockSizeTooSmallForLpcOrder
- | EncoderInitStatusNotStreamable
- | EncoderInitStatusInvalidMetadata
- | EncoderInitStatusAlreadyInitialized
- data EncoderState
- encodeFlac :: MonadIO m => EncoderSettings -> FilePath -> FilePath -> m ()
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 Maybe
s, 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.
EncoderSettings | |
|
Instances
Eq EncoderSettings Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder (==) :: EncoderSettings -> EncoderSettings -> Bool # (/=) :: EncoderSettings -> EncoderSettings -> Bool # | |
Ord EncoderSettings Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder compare :: EncoderSettings -> EncoderSettings -> Ordering # (<) :: EncoderSettings -> EncoderSettings -> Bool # (<=) :: EncoderSettings -> EncoderSettings -> Bool # (>) :: EncoderSettings -> EncoderSettings -> Bool # (>=) :: EncoderSettings -> EncoderSettings -> Bool # max :: EncoderSettings -> EncoderSettings -> EncoderSettings # min :: EncoderSettings -> EncoderSettings -> EncoderSettings # | |
Read EncoderSettings Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder | |
Show EncoderSettings Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder showsPrec :: Int -> EncoderSettings -> ShowS # show :: EncoderSettings -> String # showList :: [EncoderSettings] -> ShowS # |
defaultEncoderSettings :: EncoderSettings Source #
Default EncoderSettings
.
Since: 0.2.0
data EncoderException Source #
Exception that is thrown when encoding fails for some reason.
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. |
Instances
Eq EncoderException Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types (==) :: EncoderException -> EncoderException -> Bool # (/=) :: EncoderException -> EncoderException -> Bool # | |
Read EncoderException Source # | |
Show EncoderException Source # | |
Defined in Codec.Audio.FLAC.StreamEncoder.Internal.Types showsPrec :: Int -> EncoderException -> ShowS # show :: EncoderException -> String # showList :: [EncoderException] -> ShowS # | |
Exception EncoderException Source # | |
data EncoderInitStatus Source #
Status of encoder initialization process.
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
data EncoderState Source #
Enumeration of encoder states.
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
:: 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.