Membrane.WAV.Parser (Membrane WAV Plugin v0.2.0-alpha) View Source
Element responsible for parsing WAV files.
It requires WAV file in uncompressed, PCM format on the input (otherwise error is raised) and provides raw audio on the output. WAV header is parsed to extract metadata for creating caps. Then it is dropped and only samples are sent to the next element.
The element has one option - frames_per_buffer
. User can specify number of frames sent in one
buffer when demand unit on the output is :buffers
. One frame contains bits per sample
x
number of channels
bits.
WAV Header
0 4 8 12 16
_________________________________________________________________________________
0 | | | | |
| "RIFF" | file length | "WAVE" | "fmt " |
| | | | |
|___________________|___________________|___________________|___________________|
16 | | | | | |
| format chunk | format |number of| sample | data transmission |
| length |(1 - PCM)|channels | rate | rate |
|___________________|_________|_________|___________________|___________________|
32 | block | bits | | | |
| align | per | "fact" | fact chunk | samples per |
| unit | sample | | length | channel |
|_________|_________|___________________|___________________|___________________|
48 | | | |
| "data" | data length | DATA |
| | in bytes | |
|___________________|___________________|_______________________________________|
Header may contain additional bytes between bits per sample
and "fact"
in case of format
different from 1 (1 represents PCM / uncompressed format). Length of block from format
until
"fact"
is present in format chunk length
(it is 16 for PCM).
Blocks from byte 36 to 48 are optional. There can be additional bytes after samples per channel
if fact chunk length
contains number bigger than 4.
Parsing
Stages of parsing:
:init
- Parser waits for the first 22 bytes. After getting them, it parses these bytes to ensure that it is a WAV file. Parser knowsformat chunk length
andformat
, so it is able to raise an error in case of differentformat
than 1 (PCM) or different length than 16 (for PCM). After parsing, the stage is set to:format
.:format
- Parser waits for the next 22 bytes -fmt
chunk (bytes 20 - 35) withoutformat
and either"fact"
andfact chunk length
or"data"
anddata length in bytes
. Then it parses it and createMembrane.Caps.Audio.Raw
struct with audio format to send it as caps to the next element. Stage is set to:fact
or:data
depending on last 8 bytes.:fact
- Parser waits for8 + fact chunk length
bytes. It parses them only to check if the header is correct, but does not use that data in any way. After parsing, the stage is set to:data
.:data
- header is already fully parsed. All new data from the input is sent to the output.
Element options
Passed via struct Membrane.WAV.Parser.t/0
frames_per_buffer
pos_integer()
Default value:
2048
Assumed number of raw audio frames in each buffer. Used when converting demand from buffers into bytes.
Pads
:input
Availability | :always |
Caps | :any |
Demand unit | :bytes |
Direction | :input |
Mode | :pull |
Name | :input |
:output
Availability | :always |
Caps | Membrane.Caps.Audio.Raw |
Direction | :output |
Mode | :pull |
Name | :output |
Link to this section Summary
Types
Struct containing options for Membrane.WAV.Parser
Functions
Returns pads descriptions for Membrane.WAV.Parser
Returns description of options available for this module
Link to this section Types
Specs
t() :: %Membrane.WAV.Parser{frames_per_buffer: pos_integer()}
Struct containing options for Membrane.WAV.Parser
Link to this section Functions
Specs
membrane_pads() :: [{Membrane.Pad.name_t(), Membrane.Pad.description_t()}]
Returns pads descriptions for Membrane.WAV.Parser
Specs
options() :: keyword()
Returns description of options available for this module