View Source Membrane.WAV.Parser (Membrane WAV Plugin v0.8.0)
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 of the raw audio format. 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 * number of channels bits.
wav-header
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
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 lengthandformat, so it is able to raise an error in case of differentformatthan 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 -fmtchunk (bytes 20 - 35) withoutformatand either"fact"andfact chunk lengthor"data"anddata length in bytes. Then it parses it and createMembrane.RawAudiostruct with audio format to send it as stream_format to the next element. Stage is set to:factor:datadepending on last 8 bytes.:fact- Parser waits for8 + fact chunk lengthbytes. 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.
pads
Pads
input
:input
| Accepted formats |
|
| Availability | :always |
| Demand mode | :auto |
| Demand unit | :bytes |
| Direction | :input |
| Mode | :pull |
| Name | :input |
output
:output
| Accepted formats |
|
| Availability | :always |
| Demand mode | :auto |
| Direction | :output |
| Mode | :pull |
| Name | :output |