Safe Haskell | None |
---|
Everything about WAVE files is contained here: reading, editing and writing the data within is all possible in this module.
- decodeWave :: ByteString -> WaveFile
- decodeWaveFile :: FilePath -> IO WaveFile
- decodeWaveFileOrFail :: FilePath -> IO (Either (ByteOffset, String) WaveFile)
- withWaveFile :: FilePath -> (Either WaveParseError WaveFile -> IO ()) -> IO ()
- encodeWaveFile :: FilePath -> WaveFile -> IO ()
- data WaveFile = WaveFile {
- waveFormat :: WaveFormat
- waveData :: RawWaveData
- waveFact :: Maybe WaveFact
- waveInfo :: Maybe WaveInfo
- data WaveFormat = WaveFormat {
- waveAudioFormat :: AudioFormat
- waveNumChannels :: Word16
- waveSampleRate :: SampleRate
- waveByteRate :: ByteRate
- waveBlockAlignment :: BlockAlignment
- waveBitsPerSample :: BitsPerSample
- data WaveFact = WaveFact {}
- data WaveInfo = WaveInfo {
- archiveLocation :: Maybe String
- artist :: Maybe String
- commissionedBy :: Maybe String
- comments :: Maybe String
- copyrights :: Maybe [String]
- creationDate :: Maybe String
- croppedDetails :: Maybe String
- originalDimensions :: Maybe String
- dotsPerInch :: Maybe String
- engineers :: Maybe [String]
- genre :: Maybe String
- keywords :: Maybe [String]
- lightness :: Maybe String
- originalMedium :: Maybe String
- name :: Maybe String
- coloursInPalette :: Maybe String
- originalProduct :: Maybe String
- subject :: Maybe String
- creationSoftware :: Maybe String
- sharpness :: Maybe String
- contentSource :: Maybe String
- originalForm :: Maybe String
- technician :: Maybe String
- waveInfoDefault :: WaveInfo
- data IntegralWaveData = IntegralWaveData [IntegralWaveChannel]
- type IntegralWaveChannel = Vector Int64
- data FloatingWaveData = FloatingWaveData [FloatingWaveChannel]
- type FloatingWaveChannel = Vector Double
- type WaveParseError = String
- getInfoData :: WaveFile -> WaveInfo
- updateWaveInfo :: (WaveInfo -> WaveInfo) -> WaveFile -> WaveFile
- prettyShowAudioFormat :: AudioFormat -> String
- data AudioFormat
- = MicrosoftPCM
- | MicrosoftADPCM
- | MicrosoftIEEEfloat
- | CompaqVSELP
- | IBMCVSD
- | MicrosoftaLaw
- | MicrosoftuLaw
- | MicrosoftDTS
- | DRM
- | WMA9Speech
- | MicrosoftWindowsMediaRTVoice
- | OKIADPCM
- | IntelIMADVIADPCM
- | VideologicMediaspaceADPCM
- | SierraADPCM
- | AntexG723ADPCM
- | DSPSolutionsDIGISTD
- | DSPSolutionsDIGIFIX
- | DialoicOKIADPCM
- | MediaVisionADPCM
- | HPCU
- | HPDynamicVoice
- | YamahaADPCM
- | SONARCSpeechCompression
- | DSPGroupTrueSpeech
- | EchoSpeechCorp
- | VirtualMusicAudiofileAF36
- | AudioProcessingTech
- | VirtualMusicAudiofileAF10
- | AculabProsody1612
- | MergingTechLRC
- | DolbyAC2
- | MicrosoftGSM610
- | MSNAudio
- | AntexADPCME
- | ControlResourcesVQLPC
- | DSPSolutionsDIGIREAL
- | DSPSolutionsDIGIADPCM
- | ControlResourcesCR10
- | NaturalMicroSystemsVBXADPCM
- | CrystalSemiconductorIMAADPCM
- | EchoSpeechECHOSC3
- | RockwellADPCM
- | RockwellDIGITALK
- | XebecMultimedia
- | AntexG721ADPCM
- | AntexG728CELP
- | MicrosoftMSG723
- | IBMAVCADPCM
- | ITUTG726
- | MicrosoftMPEG
- | RT23orPAC
- | InSoftRT24
- | InSoftPAC
- | MP3
- | Cirrus
- | CirrusLogic
- | ESSTechPCM
- | VoxwareInc
- | CanopusATRAC
- | APICOMG726ADPCM
- | APICOMG722ADPCM
- | MicrosoftDSAT
- | MicorsoftDSATDISPLAY
- | VoxwareByteAligned
- | VoxwareAC8
- | VoxwareAC10
- | VoxwareAC16
- | VoxwareAC20
- | VoxwareMetaVoice
- | VoxwareMetaSound
- | VoxwareRT29HW
- | VoxwareVR12
- | VoxwareVR18
- | VoxwareTQ40
- | VoxwareSC3
- | Soundsoft
- | VoxwareTQ60
- | MicrosoftMSRT24
- | ATandTG729A
- | MotionPixelsMVIMV12
- | DataFusionG726
- | DataFusionGSM610
- | IteratedSystemsAudio
- | Onlive
- | MultitudeIncFTSX20
- | InfocomITSASG721ADPCM
- | ConvediaG729
- | NotspecifiedcongruencyInc
- | SiemensSBC24
- | SonicFoundryDolbyAC3APDIF
- | MediaSonicG723
- | AculabProsody8kbps
- | ZyXELADPCM
- | PhilipsLPCBB
- | StuderProfessionalAudioPacked
- | MaldenPhonyTalk
- | RacalRecorderGSM
- | RacalRecorderG720a
- | RacalG7231
- | RacalTetraACELP
- | NECAACNECCorporation
- | AAC
- | RhetorexADPCM
- | IBMuLaw
- | IBMaLaw
- | IBMADPCM
- | VivoG723
- | VivoSiren
- | PhilipsSpeechProcessingCELP
- | PhilipsSpeechProcessingGRUNDIG
- | DigitalG723
- | SanyoLDADPCM
- | SiproLabACEPLNET
- | SiproLabACELP4800
- | SiproLabACELP8V3
- | SiproLabG729
- | SiproLabG729A
- | SiproLabKelvin
- | VoiceAgeAMR
- | DictaphoneG726ADPCM
- | QualcommPureVoice
- | QualcommHalfRate
- | RingZeroSystemsTUBGSM
- | MicrosoftAudio1
- | WindowsMediaAudioV2V7V8V9DivXaudioSpecWMAAlexAC3Audio
- | WindowsMediaAudioProfessionalV9
- | WindowsMediaAudioLosslessV9
- | WMAProoverSPDIF
- | UNISYSNAPADPCM
- | UNISYSNAPULAW
- | UNISYSNAPALAW
- | UNISYSNAP16K
- | MMSYCOMACMSYC008SyComTechnologies
- | MMSYCOMACMSYC701G726LSyComTechnologies
- | MMSYCOMACMSYC701CELP54SyComTechnologies
- | MMSYCOMACMSYC701CELP68SyComTechnologies
- | KnowledgeAdventureADPCM
- | FraunhoferIISMPEG2AAC
- | DigitalTheaterSystemsDTSDS
- | CreativeLabsADPCM
- | CreativeLabsFASTSPEECH8
- | CreativeLabsFASTSPEECH10
- | UHERADPCM
- | UleadDVACM
- | QuarterdeckCorp
- | ILinkVC
- | AurealSemiconductorRawSport
- | ESSTAC3
- | InteractiveProductsHSX
- | InteractiveProductsRPELP
- | ConsistentCS2
- | SonySCX
- | SonySCY
- | SonyATRAC3
- | SonySPC
- | TELUMTelumInc
- | TELUMIATelumInc
- | NorcomVoiceSystemsADPCM
- | FujitsuFMTOWNSSND
- | FujitsuSpecnotspecified
- | MicronasSemiconductorsIncDevelopment
- | MicronasSemiconductorsIncCELP833
- | BrooktreeDigital
- | IntelMusicCoderSpecIMC
- | LigosIndeoAudio
- | QDesignMusic
- | On2VP7On2Technologies
- | On2VP6On2Technologies
- | ATandTVMEVMPCM
- | ATandTTCP
- | YMPEGAlphaSpecdummyforMPEG2compressor
- | ClearJumpLiteWaveSpeclossless
- | OlivettiGSM
- | OlivettiADPCM
- | OlivettiCELP
- | OlivettiSBC
- | OlivettiOPR
- | LernoutandHauspie
- | LernoutandHauspieCELPcodec
- | LernoutandHauspieSBCcodec
- | NorrisCommInc
- | ISIAudio
- | ATandTSoundspaceMusicCompression
- | VoxWareRT24speechcodec
- | LucentelemediaAX24000PMusiccodec
- | SonicFoundryLOSSLESS
- | InningsTelecomIncADPCM
- | LucentSX8300Pspeechcodec
- | LucentSX5363SG723compliantcodec
- | CUseeMeDigiTalkSpecexRocwell
- | NCTSoftALF2CDACM
- | FASTMultimediaDVM
- | DolbyDTSSpecDigitalTheaterSystem
- | RealAudio12144
- | RealAudio1Slash2288
- | RealAudioG2Slash8CookSpeclowbitrate
- | RealAudio3Slash4Slash5MusicSpecDNET
- | RealAudio10AACSpecRAAC
- | RealAudio10AACPlusSpecRACP
- | Reservedrangeto0x2600Microsoft
- | MakeAVISSpecffvfwfakeAVIsoundfromAviSynthscripts
- | DivioMPEG4AACaudio
- | Nokiaadaptivemultirate
- | DivioG726DivioInc
- | LEADSpeech
- | LEADVorbis
- | WavPackAudio
- | OggVorbisSpecmode1
- | OggVorbisSpecmode2
- | OggVorbisSpecmode3
- | OggVorbisSpecmode1Plus
- | OggVorbisSpecmode2Plus
- | OggVorbisSpecmode3Plus
- | ThreeCOMNBX3ComCorporation
- | FAADAAC
- | GSMAMRSpecCBRnoSID
- | GSMAMRSpecVBRincludingSID
- | ComverseInfosysLtdG7231
- | ComverseInfosysLtdAVQSBC
- | ComverseInfosysLtdOLDSBC
- | SymbolTechnologiesG729A
- | VoiceAgeAMRWBVoiceAgeCorporation
- | IngenientTechnologiesIncG726
- | ISOSlashMPEG4advancedaudioCoding
- | EncoreSoftwareLtdG726
- | SpeexACMCodecxiphorg
- | DebugModeSonicFoundryVegasFrameServerACMCodec
- | Unknown
- | FreeLosslessAudioCodecFLAC
- | Extensible
- | Development
- | UnknownFormat AudioFormatData
- type ByteOffset = Int64
Reading Riff Files
These functions allow you to read WAVE data from bytestrings and the filesystem.
:: ByteString | The bytestring to attempt to parse. |
-> WaveFile | The returned WaveFile containing WAVE data. |
Decodes a lazy bytestring into a WaveFile.
Give this function the path to a WAVE file and it will parse it into our internal | representation.
:: FilePath | The location of the file that contains WAVE data. |
-> IO (Either (ByteOffset, String) WaveFile) | The error (left) or successful result (right). |
Give this function the path to a WAVE file and it will Either return an error or a WaveFile containing WAVE data. This does the exact same thing as decodeWaveFile except that, instead of failing on an error, it returns the error in an either.
:: FilePath | The location of the WaveFile in the filesystem. |
-> (Either WaveParseError WaveFile -> IO ()) | A handler for the parse result. Note that the parse may fail and you should handle that. |
-> IO () | An IO context is required because you are reading from the filesystem. |
We would like to be able to pass in a path to a WaveFile and a handler so that we don't have to deal with opening / closing a file and parsing the contents just to apply a handler to the data. This is a convenience method that just lets you do something with a wave file.
Writing Riff Files
You will need to write out your WAVE file data eventually and these functions will allow you to do that.
:: FilePath | The file to dump the WAVE data. |
-> WaveFile | The internal representation of a WAVE file. |
-> IO () | This is performed inside an IO action. |
Outputs a WAVE file representation to a file (that can then be understood by other WAVE file reading programs). The output of this function should fully comply to the WAVE specifications.
WAVE Data
There is a nested structure all WaveFiles and these pieces of data attempt to encapsulate that structure and make it easy for you to access the internal state of your files.
The representation of a WaveFile. This ADT is this libraries representation of a WaveFile. It is important to note that the format chunk and data chunks are not optional. Also, the wave data is left in it's raw format so that it can be parsed appropriately later depending on wether you even want to parse the data or if you have the data in a special encoding that requires special handling.
WaveFile | |
|
data WaveFormat Source
Each Riff file has a Format chunk and this data structure encapsulates the data that is usually contained within. The format chunk gives you useful information: such as what encoding was run over the data in the file and how many bits were used per sample.
WaveFormat | |
|
From the specifications:
"The fact chunk is required if the waveform data is contained in a wavl LIST chunk and for all compressed audio formats. The chunk is not required for PCM files using the data chunk format."
This means that this section will become more important as this library matures and
begins to support a whole range of AudioFormat
s.
WaveFact | |
|
This datatype defines an INFO chunk and our internal representation of it. It is actually defined very clearly in section 2-14 of the Spec and we have tried to mirror that representation here. The spec says the following:
An INFO list should contain only the following chunks. New chunks may be defined, but an application should ignore any chunk it doesn't understand. The chunks listed below may only appear in an INFO list. Each chunk contains a ZSTR, or null-terminated text string.
Manipulations of that data structure should adhere to that specification.
WaveInfo | |
|
waveInfoDefault :: WaveInfoSource
This is the default value that an INFO chunk can take, a chunk that contains no metadata at all.
data IntegralWaveData Source
A multi-channel structure for holding integral wave data efficiently.
type IntegralWaveChannel = Vector Int64Source
An efficient data structure for holding a single channel of integral wave data.
data FloatingWaveData Source
A multi-channel structure for holding floating wave data efficiently.
type FloatingWaveChannel = Vector DoubleSource
An efficient data structure for holding a single channel of floating wave data.
type WaveParseError = StringSource
The representation for parser errors when attempting to read WaveFiles or their data.
Info Editing and Retrieval
These functions let you get the metadata section of your WAVE files; otherwise known as the INFO section of the RIFF file.
You want to be able to get the info chunk from your WaveFiles, however, if the info chunk does not exist then you will be provided with a default info chunk.
:: (WaveInfo -> WaveInfo) | The conversion function from original to new metadata. |
-> WaveFile | The input WaveFile that will be modified. |
-> WaveFile | A new WaveFile that contains the updated INFO section. |
Update the INFO metadata chunk inside an existing WaveFile. This will allow you to edit the metadata inside a file.
Audio Formats
You can place many different types of audio data inside an audio file, all of which is encoded in a different way. An audio format represents a different encoding of the audio data inside the data section of the file.
:: AudioFormat | The audio format that you wish to display to a human. |
-> String | The human readable description of this audio format. |
This function is reponsible for converting an AudioFormat into a representation that is human readable and what people would expect. It is useful if you need to display your AudioFormat to a human and you want to know, quickly, what to call it.
data AudioFormat Source
This is a massive data structure that contains every single different audio format that I could find. It allows us to represent AudioFormats in a very human readable and easy to understand manner insize wavy. This data structure will be constantly growing and changing. Do not be surprised if names change or elements are added. Because this list is always growing we have an UnknownFormat element that can wrap and AudioFormatData so that, in the event that we do not know about an audio format. You can still deal with it naturally.
Extras
These are the exported extras of the package that you may find useful to browse and employ.
type ByteOffset = Int64
An offset, counted in bytes.