-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Work with WAVE and RF64 files -- -- Work with WAVE and RF64 files. @package wave @version 0.2.1 -- | This module provides a safe interface that allows us to manipulate -- WAVE files in their “classic” form as well as files in the RF64 format -- https://tech.ebu.ch/docs/tech/tech3306-2009.pdf. RF64 adds the -- ability to store files larger than 4 Gb. -- -- The main feature of the API is that it does not allow the user to -- duplicate information and introduce errors in that way. For example, -- the block alignment can be calculated from other parameters of an -- audio stream, thus we do not store it in the Wave record and do -- not allow user to specify it. We provide, however, a way to calculate -- it given a Wave record, see waveBlockAlign. The same is -- true for the number of channels. The channel mask is a more general -- means of providing the information about the number of channels and -- the corresponding speaker positions, thus we only store the channel -- mask. -- -- Another feature of the library is that it does not dictate how to read -- or write the audio data. To write the audio data the user passes a -- callback that receives a Handle as an argument. The size of the -- written data block is deduced automatically. This makes the library -- fast and open to different ways of handling the audio data, including -- via foreign code. module Codec.Audio.Wave -- | Representation of the “essential” information about a WAVE file. Every -- field in this record is an orthogonal piece of information, so no -- field can be calculated from other fields. The fields are complemented -- by the functions that calculate derivative parameters: -- waveByteRate, waveBitRate, waveBitsPerSample, -- waveBlockAlign, and waveChannels. data Wave Wave :: !WaveFormat -> !Word32 -> !SampleFormat -> !Set SpeakerPosition -> !Word32 -> !Word64 -> !Word64 -> [(ByteString, ByteString)] -> Wave -- | The format of the file this Wave record was extracted/to be -- written to, WaveFormat. Default value is: WaveVanilla. [waveFileFormat] :: Wave -> !WaveFormat -- | Sample rate in Hz, default is: 44100. [waveSampleRate] :: Wave -> !Word32 -- | Sample format. The library supports signed/unsigned integers and -- floats. Default value: SampleFormatPcmInt 16. [waveSampleFormat] :: Wave -> !SampleFormat -- | The channel mask as a Set of SpeakerPositions. Default -- value is speakerStereo. [waveChannelMask] :: Wave -> !Set SpeakerPosition -- | The offset in bytes where the actual sample data begins. Default -- value: 0. [waveDataOffset] :: Wave -> !Word32 -- | Size of the audio data in bytes. Default value: 0. [waveDataSize] :: Wave -> !Word64 -- | The total number of samples in the audio stream. “Samples” here mean -- multi-channel samples, so one second of 44.1 kHz audio will have 44100 -- samples regardless of the number of channels. For PCM format it's -- deduced from the size of the data block, for other formats it's read -- from/written to the “fact” chunk. Default value: 0. [waveSamplesTotal] :: Wave -> !Word64 -- | Other chunks as (tag, body) pairs. Only the first four bytes -- of tag are significant and it must be four bytes long, if -- it's too short it will be padded by null bytes. Default value: -- []. [waveOtherChunks] :: Wave -> [(ByteString, ByteString)] -- | WaveFormat as a flavor of WAVE file. data WaveFormat -- | Classic WAVE file, 4 Gb size limitation WaveVanilla :: WaveFormat -- | WAVE file with RF64 extension WaveRF64 :: WaveFormat -- | Sample formats with associated bit depth. data SampleFormat -- | Unsigned/signed integers, the argument is the number of bits per -- sample (8 bit and less are encoded as unsigned integers). SampleFormatPcmInt :: Word16 -> SampleFormat -- | Samples are 32 bit floating point numbers. SampleFormatIeeeFloat32Bit :: SampleFormat -- | Samples are 64 bit floating point numbers. SampleFormatIeeeFloat64Bit :: SampleFormat -- | Speaker positions clarifying which exactly channels are packed in the -- WAVE file. data SpeakerPosition -- | Front left SpeakerFrontLeft :: SpeakerPosition -- | Front right SpeakerFrontRight :: SpeakerPosition -- | Front center SpeakerFrontCenter :: SpeakerPosition -- | Sub-woofer SpeakerLowFrequency :: SpeakerPosition -- | Back left SpeakerBackLeft :: SpeakerPosition -- | Back right SpeakerBackRight :: SpeakerPosition -- | Front left of center SpeakerFrontLeftOfCenter :: SpeakerPosition -- | Front right of center SpeakerFrontRightOfCenter :: SpeakerPosition -- | Back center SpeakerBackCenter :: SpeakerPosition -- | Side left SpeakerSideLeft :: SpeakerPosition -- | Side right SpeakerSideRight :: SpeakerPosition -- | Top center SpeakerTopCenter :: SpeakerPosition -- | Top front left SpeakerTopFrontLeft :: SpeakerPosition -- | Top front center SpeakerTopFrontCenter :: SpeakerPosition -- | Top front right SpeakerTopFrontRight :: SpeakerPosition -- | Top back left SpeakerTopBackLeft :: SpeakerPosition -- | Top back center SpeakerTopBackCenter :: SpeakerPosition -- | Top back right SpeakerTopBackRight :: SpeakerPosition -- | Exceptions the library can throw. data WaveException -- | Format of the given file doesn't look like anything familiar. The -- first argument is a message explaining what's wrong and the second -- argument is the file name. BadFileFormat :: String -> FilePath -> WaveException -- | The library found a chunk which is not a data chunk but is -- way too long. The first argument is the tag of the chunk and the -- second argument is the file name. NonDataChunkIsTooLong :: ByteString -> FilePath -> WaveException -- | The specified format is non-PCM, it's vanilla WAVE, but the “fact” -- chunk is missing. NonPcmFormatButMissingFact :: FilePath -> WaveException -- | The byte rate of a given Wave file. The byte rate is the number -- of bytes it takes to encode one second of audio. waveByteRate :: Wave -> Word32 -- | The bit rate in kilobits per second. waveBitRate :: Wave -> Double -- | The number of significant bits in a sample. waveBitsPerSample :: Wave -> Word16 -- | The block alignment of samples as the number of bits per sample -- (rounded towards the next multiplier of 8 if necessary) multiplied by -- the number of channels. This is how many bytes it takes to encode a -- single multi-channel sample. waveBlockAlign :: Wave -> Word16 -- | The total number of channels present in the audio stream. waveChannels :: Wave -> Word16 -- | The duration in seconds. waveDuration :: Wave -> Double -- | Front center (C). speakerMono :: Set SpeakerPosition -- | Front left (L), front right (R). speakerStereo :: Set SpeakerPosition -- | L, R, back left (Lb), back right (Rb). speakerQuad :: Set SpeakerPosition -- | Surround: L, R, front center (C), back center (Cb). speakerSurround :: Set SpeakerPosition -- | L, R, C, Lb, Rb, low frequency (LFE). speaker5_1 :: Set SpeakerPosition -- | L, R, C, Lb, Rb, front left-of-center, front right-of-center, LFE. speaker7_1 :: Set SpeakerPosition -- | L, R, C, side left (Ls), side right (Rs), LFE. speaker5_1Surround :: Set SpeakerPosition -- | L, R, C, Lb, Rb, Ls, Rs, LFE. speaker7_1Surround :: Set SpeakerPosition -- | Read a Wave record from a WAVE file found at given path. This -- action throws WaveException if the file is malformed and cannot -- be read. -- -- Vanilla WAVE and RF64 files are supported. The format is detected -- automatically from the contents of the file, not by extension. -- -- Only PCM with samples in the form of integers or floats are supported, -- see SampleFormat. -- -- Finally, if “fmt” chunk is not extensible, we try to guess the channel -- mask from the number of channels alone, here is how: -- -- readWaveFile :: MonadIO m => FilePath -> m Wave -- | Write a WAVE file. The waveFileFormat value specifies in which -- of the supported formats the file should be written. The action uses -- the provided callback to write WAVE audio data. waveDataOffset -- and waveDataSize from Wave are ignored, instead the -- values are inferred dynamically after using the callback. Further, the -- function takes care of the requirement that WAVE data should end on an -- “even byte boundary”. The pad byte is written if necessary and -- included in the data size. -- -- The waveSamplesTotal field will be inferred, so the provided -- value is not used. -- -- If Wave specifies the floating point sample format, the “fact” -- chunk is automatically generated and written (the chunk is required -- for all non-PCM formats by the spec), but only for vanilla WAVE. writeWaveFile :: MonadIO m => FilePath -> Wave -> (Handle -> IO ()) -> m () instance Data.Data.Data Codec.Audio.Wave.WaveFormat instance GHC.Enum.Enum Codec.Audio.Wave.WaveFormat instance GHC.Enum.Bounded Codec.Audio.Wave.WaveFormat instance GHC.Classes.Ord Codec.Audio.Wave.WaveFormat instance GHC.Classes.Eq Codec.Audio.Wave.WaveFormat instance GHC.Read.Read Codec.Audio.Wave.WaveFormat instance GHC.Show.Show Codec.Audio.Wave.WaveFormat instance Data.Data.Data Codec.Audio.Wave.SampleFormat instance GHC.Classes.Ord Codec.Audio.Wave.SampleFormat instance GHC.Classes.Eq Codec.Audio.Wave.SampleFormat instance GHC.Read.Read Codec.Audio.Wave.SampleFormat instance GHC.Show.Show Codec.Audio.Wave.SampleFormat instance Data.Data.Data Codec.Audio.Wave.SpeakerPosition instance GHC.Enum.Enum Codec.Audio.Wave.SpeakerPosition instance GHC.Enum.Bounded Codec.Audio.Wave.SpeakerPosition instance GHC.Classes.Ord Codec.Audio.Wave.SpeakerPosition instance GHC.Classes.Eq Codec.Audio.Wave.SpeakerPosition instance GHC.Read.Read Codec.Audio.Wave.SpeakerPosition instance GHC.Show.Show Codec.Audio.Wave.SpeakerPosition instance Data.Data.Data Codec.Audio.Wave.Wave instance GHC.Classes.Ord Codec.Audio.Wave.Wave instance GHC.Classes.Eq Codec.Audio.Wave.Wave instance GHC.Read.Read Codec.Audio.Wave.Wave instance GHC.Show.Show Codec.Audio.Wave.Wave instance Data.Data.Data Codec.Audio.Wave.WaveException instance GHC.Classes.Eq Codec.Audio.Wave.WaveException instance GHC.Read.Read Codec.Audio.Wave.WaveException instance GHC.Show.Show Codec.Audio.Wave.WaveException instance GHC.Exception.Type.Exception Codec.Audio.Wave.WaveException