-- GENERATED by C->Haskell Compiler, version 0.16.0 Crystal Seed, 24 Jan 2009 (Haskell)-- Edit the ORIGNAL .chs file instead!{-# LINE 1 "./Sound/File/Sndfile/Interface.chs" #-}{-# LANGUAGE ForeignFunctionInterface #-}moduleSound.File.Sndfile.InterfacewhereimportC2HSimportControl.Monad(liftM,when)importData.BitsimportqualifiedSound.File.Sndfile.ExceptionasEimportSystem.IO.Unsafe(unsafePerformIO){-# LINE 13 "./Sound/File/Sndfile/Interface.chs" #-}-- ====================================================================-- Basic typestypeCount=Int-- ^ Type for expressing sample counts.typeIndex=Int-- ^ Type for expressing sample indices.-- ====================================================================-- Format-- | Header format.dataHeaderFormat=HeaderFormatNone|HeaderFormatWav|HeaderFormatAiff|HeaderFormatAu|HeaderFormatRaw|HeaderFormatPaf|HeaderFormatSvx|HeaderFormatNist|HeaderFormatVoc|HeaderFormatIrcam|HeaderFormatW64|HeaderFormatMat4|HeaderFormatMat5|HeaderFormatPvf|HeaderFormatXi|HeaderFormatHtk|HeaderFormatSds|HeaderFormatAvr|HeaderFormatWavex|HeaderFormatSd2|HeaderFormatFlac|HeaderFormatCafderiving(Eq,Show)instanceEnumHeaderFormatwherefromEnumHeaderFormatNone=0fromEnumHeaderFormatWav=65536fromEnumHeaderFormatAiff=131072fromEnumHeaderFormatAu=196608fromEnumHeaderFormatRaw=262144fromEnumHeaderFormatPaf=327680fromEnumHeaderFormatSvx=393216fromEnumHeaderFormatNist=458752fromEnumHeaderFormatVoc=524288fromEnumHeaderFormatIrcam=655360fromEnumHeaderFormatW64=720896fromEnumHeaderFormatMat4=786432fromEnumHeaderFormatMat5=851968fromEnumHeaderFormatPvf=917504fromEnumHeaderFormatXi=983040fromEnumHeaderFormatHtk=1048576fromEnumHeaderFormatSds=1114112fromEnumHeaderFormatAvr=1179648fromEnumHeaderFormatWavex=1245184fromEnumHeaderFormatSd2=1441792fromEnumHeaderFormatFlac=1507328fromEnumHeaderFormatCaf=1572864toEnum0=HeaderFormatNonetoEnum65536=HeaderFormatWavtoEnum131072=HeaderFormatAifftoEnum196608=HeaderFormatAutoEnum262144=HeaderFormatRawtoEnum327680=HeaderFormatPaftoEnum393216=HeaderFormatSvxtoEnum458752=HeaderFormatNisttoEnum524288=HeaderFormatVoctoEnum655360=HeaderFormatIrcamtoEnum720896=HeaderFormatW64toEnum786432=HeaderFormatMat4toEnum851968=HeaderFormatMat5toEnum917504=HeaderFormatPvftoEnum983040=HeaderFormatXitoEnum1048576=HeaderFormatHtktoEnum1114112=HeaderFormatSdstoEnum1179648=HeaderFormatAvrtoEnum1245184=HeaderFormatWavextoEnum1441792=HeaderFormatSd2toEnum1507328=HeaderFormatFlactoEnum1572864=HeaderFormatCaftoEnumunmatched=error("HeaderFormat.toEnum: Cannot match "++showunmatched){-# LINE 26 "./Sound/File/Sndfile/Interface.chs" #-}-- | Sample format.dataSampleFormat=SampleFormatNone|SampleFormatPcmS8|SampleFormatPcm16|SampleFormatPcm24|SampleFormatPcm32|SampleFormatPcmU8|SampleFormatFloat|SampleFormatDouble|SampleFormatUlaw|SampleFormatAlaw|SampleFormatImaAdpcm|SampleFormatMsAdpcm|SampleFormatGsm610|SampleFormatVoxAdpcm|SampleFormatG72132|SampleFormatG72324|SampleFormatG72340|SampleFormatDwvw12|SampleFormatDwvw16|SampleFormatDwvw24|SampleFormatDwvwN|SampleFormatFormatDpcm8|SampleFormatFormatDpcm16deriving(Eq,Show)instanceEnumSampleFormatwherefromEnumSampleFormatNone=0fromEnumSampleFormatPcmS8=1fromEnumSampleFormatPcm16=2fromEnumSampleFormatPcm24=3fromEnumSampleFormatPcm32=4fromEnumSampleFormatPcmU8=5fromEnumSampleFormatFloat=6fromEnumSampleFormatDouble=7fromEnumSampleFormatUlaw=16fromEnumSampleFormatAlaw=17fromEnumSampleFormatImaAdpcm=18fromEnumSampleFormatMsAdpcm=19fromEnumSampleFormatGsm610=32fromEnumSampleFormatVoxAdpcm=33fromEnumSampleFormatG72132=48fromEnumSampleFormatG72324=49fromEnumSampleFormatG72340=50fromEnumSampleFormatDwvw12=64fromEnumSampleFormatDwvw16=65fromEnumSampleFormatDwvw24=66fromEnumSampleFormatDwvwN=67fromEnumSampleFormatFormatDpcm8=80fromEnumSampleFormatFormatDpcm16=81toEnum0=SampleFormatNonetoEnum1=SampleFormatPcmS8toEnum2=SampleFormatPcm16toEnum3=SampleFormatPcm24toEnum4=SampleFormatPcm32toEnum5=SampleFormatPcmU8toEnum6=SampleFormatFloattoEnum7=SampleFormatDoubletoEnum16=SampleFormatUlawtoEnum17=SampleFormatAlawtoEnum18=SampleFormatImaAdpcmtoEnum19=SampleFormatMsAdpcmtoEnum32=SampleFormatGsm610toEnum33=SampleFormatVoxAdpcmtoEnum48=SampleFormatG72132toEnum49=SampleFormatG72324toEnum50=SampleFormatG72340toEnum64=SampleFormatDwvw12toEnum65=SampleFormatDwvw16toEnum66=SampleFormatDwvw24toEnum67=SampleFormatDwvwNtoEnum80=SampleFormatFormatDpcm8toEnum81=SampleFormatFormatDpcm16toEnumunmatched=error("SampleFormat.toEnum: Cannot match "++showunmatched){-# LINE 57 "./Sound/File/Sndfile/Interface.chs" #-}-- | Endianness.dataEndianFormat=EndianFile|EndianLittle|EndianBig|EndianCpuderiving(Eq,Show)instanceEnumEndianFormatwherefromEnumEndianFile=0fromEnumEndianLittle=268435456fromEnumEndianBig=536870912fromEnumEndianCpu=805306368toEnum0=EndianFiletoEnum268435456=EndianLittletoEnum536870912=EndianBigtoEnum805306368=EndianCputoEnumunmatched=error("EndianFormat.toEnum: Cannot match "++showunmatched){-# LINE 96 "./Sound/File/Sndfile/Interface.chs" #-}-- only used internallydataFormatMask=FormatSubMask|FormatTypeMask|FormatEndMaskderiving(Eq)instanceEnumFormatMaskwherefromEnumFormatSubMask=65535fromEnumFormatTypeMask=268369920fromEnumFormatEndMask=805306368toEnum65535=FormatSubMasktoEnum268369920=FormatTypeMasktoEnum805306368=FormatEndMasktoEnumunmatched=error("FormatMask.toEnum: Cannot match "++showunmatched){-# LINE 108 "./Sound/File/Sndfile/Interface.chs" #-}-- |Stream format specification, consisting of header, sample and endianness-- formats.---- Not all combinations of header, sample and endianness formats are valid;-- valid combinamtions can be checked with the 'checkFormat' function.dataFormat=Format{headerFormat::HeaderFormat,sampleFormat::SampleFormat,endianFormat::EndianFormat}deriving(Eq,Show)-- |Default \'empty\' format, useful when opening files for reading with 'ReadMode'.defaultFormat::FormatdefaultFormat=FormatHeaderFormatNoneSampleFormatNoneEndianFile-- Convert CInt to FormathsFormat::CInt->FormathsFormati=lethf=cToEnum(i.&.(cFromEnumFormatTypeMask).&.complement(cFromEnumFormatEndMask))sf=cToEnum(i.&.(cFromEnumFormatSubMask))ef=cToEnum(i.&.(cFromEnumFormatEndMask))inFormat{headerFormat=hf,sampleFormat=sf,endianFormat=ef}-- Convert Format to CIntcFormat::Format->CIntcFormat(Formathfsfef)=(cFromEnumhf).|.(cFromEnumsf).|.(cFromEnumef)-- ====================================================================-- Info-- |The 'Info' structure is for passing data between the calling function and-- the library when opening a stream for reading or writing.dataInfo=Info{frames::Count,-- ^Number of frames in filesamplerate::Int,-- ^Audio sample ratechannels::Int,-- ^Number of channelsformat::Format,-- ^Header and sample formatsections::Int,-- ^Number of sectionsseekable::Bool-- ^'True' when stream is seekable (e.g. local files)}deriving(Eq,Show)-- |Return soundfile duration in seconds computed via the 'Info' fields-- 'frames' and 'samplerate'.duration::Info->Doubledurationinfo=(fromIntegral$framesinfo)/(fromIntegral$samplerateinfo)-- |Default \'empty\' info, useful when opening files for reading with 'ReadMode'.defaultInfo::InfodefaultInfo=Info000defaultFormat0False-- |This function allows the caller to check if a set of parameters in the-- 'Info' struct is valid before calling 'openFile' ('WriteMode').---- 'checkFormat' returns 'True' if the parameters are valid and 'False' otherwise.{-# NOINLINE checkFormat #-}checkFormat::Info->BoolcheckFormatinfo=unsafePerformIO(withinfo(liftMcToBool.sf_format_check.castPtr))-- Storable instance for InfoinstanceStorable(Info)wherealignment_=alignment(undefined::CInt)-- hmmsizeOf_=28{-# LINE 185 "./Sound/File/Sndfile/Interface.chs" #-}-- Unmarshall Info from C representationpeekptr=doframes<-liftMfromIntegral$(\ptr->do{peekByteOffptr0::IOCLLong})ptrsamplerate<-liftMfromIntegral$(\ptr->do{peekByteOffptr8::IOCInt})ptrchannels<-liftMfromIntegral$(\ptr->do{peekByteOffptr12::IOCInt})ptrformat<-liftMhsFormat$(\ptr->do{peekByteOffptr16::IOCInt})ptrsections<-liftMfromIntegral$(\ptr->do{peekByteOffptr20::IOCInt})ptrseekable<-liftMtoBool$(\ptr->do{peekByteOffptr24::IOCInt})ptrreturn$Info{frames=frames,samplerate=samplerate,channels=channels,format=format,sections=sections,seekable=seekable}-- Marshall Info to C representationpokeptrinfo=do(\ptrval->do{pokeByteOffptr0(val::CLLong)})ptr$fromIntegral$framesinfo(\ptrval->do{pokeByteOffptr8(val::CInt)})ptr$fromIntegral$samplerateinfo(\ptrval->do{pokeByteOffptr12(val::CInt)})ptr$fromIntegral$channelsinfo(\ptrval->do{pokeByteOffptr16(val::CInt)})ptr$cFormat$formatinfo(\ptrval->do{pokeByteOffptr20(val::CInt)})ptr$fromIntegral$sectionsinfo(\ptrval->do{pokeByteOffptr24(val::CInt)})ptr$fromBool$seekableinfo-- ====================================================================-- ExceptionscheckHandle::HandlePtr->IOHandlePtrcheckHandlehandle=docode<-liftMfromIntegral$sf_errorhandlewhen(code/=0)$peekCString(sf_strerrorhandle)>>=E.throwcodereturnhandle-- ====================================================================-- Handle operations-- | Abstract file handle.dataHandle=Handle{hInfo::Info,-- ^Return the stream 'Info' associated with the 'Handle'.hPtr::HandlePtr}typeHandlePtr=Ptr()-- | I\/O mode.dataIOMode=ReadMode|WriteMode|ReadWriteModederiving(Eq,Show)instanceEnumIOModewherefromEnumReadMode=16fromEnumWriteMode=32fromEnumReadWriteMode=48toEnum16=ReadModetoEnum32=WriteModetoEnum48=ReadWriteModetoEnumunmatched=error("IOMode.toEnum: Cannot match "++showunmatched){-# LINE 234 "./Sound/File/Sndfile/Interface.chs" #-}-- |When opening a file for read ('ReadMode'), the format field should be set-- to 'defaultFormat' before calling 'openFile'. The only exception to this is-- the case of RAW files, where the caller has to set the samplerate, channels-- and format fields to valid values. All other fields of the structure are-- filled in by the library.---- When opening a file for write ('WriteMode'), the caller must fill in the-- structure members samplerate, channels, and format.---- Every call to 'openFile' should be matched with a call to 'hClose' to free-- up memory allocated during the call to 'openFile'.---- On success, the 'openFile' function returns a 'Handle' which should be-- passed as the first parameter to all subsequent libsndfile calls dealing-- with that audio stream. On fail, the 'openFile' function signals an-- 'Exception'.openFile::FilePath->IOMode->Info->IOHandleopenFilefilePathioModeinfo=withCStringfilePath(\cFilePath->withinfo(\cInfo->docHandle<-sf_open{-# LINE 263 "./Sound/File/Sndfile/Interface.chs" #-}cFilePath(cFromEnumioMode)(castPtrcInfo)>>=checkHandlenewInfo<-peekcInforeturn$HandlenewInfocHandle))-- |The 'hClose' function closes the stream, deallocates its internal buffers-- and returns () on success or signals an 'Exception' otherwise.hClose::Handle->IO()hClosehandle=dosf_close$hPtrhandlecheckHandlenullPtrreturn()-- |If the stream is opened with 'WriteMode' or 'ReadWriteMode', call the-- operating system\'s function to force the writing of all file cache buffers-- to disk. If the file is opened with 'ReadMode' no action is taken.hFlush::Handle->IO()hFlush(Handle_handle)=sf_write_synchandle-- |Get header format information associated with file.getFileInfo::FilePath->IOInfogetFileInfofilePath=doh<-openFilefilePathReadModedefaultInfoletinfo=hInfohhClosehreturninfo-- ====================================================================-- seekinghIsSeekable::Handle->IOBoolhIsSeekable=return.seekable.hInfodataSeekMode=AbsoluteSeek|RelativeSeek|SeekFromEndderiving(Eq,Show)instanceEnumSeekModewherefromEnumAbsoluteSeek=0fromEnumRelativeSeek=1fromEnumSeekFromEnd=2toEnum0=AbsoluteSeektoEnum1=RelativeSeektoEnum2=SeekFromEndtoEnumunmatched=error("SeekMode.toEnum: Cannot match "++showunmatched){-# LINE 298 "./Sound/File/Sndfile/Interface.chs" #-}-- Helper function for seeking, modifying either the read pointer, the write-- pointer, or both.{-# INLINE hSeek' #-}hSeek'::MaybeIOMode->Handle->SeekMode->Count->IOCounthSeek'ioMode(Handle_handle)seekModeframes=don<-liftMfromIntegral$sf_seek{-# LINE 313 "./Sound/File/Sndfile/Interface.chs" #-}handle(cIntConvframes)((cFromEnumseekMode).|.(caseioModeofNothing->0Justm->cFromEnumm))checkHandlehandlereturnn-- |The file seek functions work much like 'System.IO.hseek' with the-- exception that the non-audio data is ignored and the seek only moves within-- the audio data section of the file. In addition, seeks are defined in-- number of (multichannel) frames. Therefore, a seek in a stereo file from-- the current position forward with an offset of 1 would skip forward by one-- sample of both channels.---- like lseek(), the whence parameter can be any one of the following three-- values:---- * 'AbsoluteSeek' - The offset is set to the start of the audio data plus-- offset (multichannel) frames.---- * 'RelativeSeek' - The offset is set to its current location plus offset-- (multichannel) frames.---- * 'SeekFromEnd' - The offset is set to the end of the data plus offset-- (multichannel) frames.---- Internally, libsndfile keeps track of the read and write locations using-- separate read and write pointers. If a file has been opened with a mode of-- 'ReadWriteMode', calling either 'hSeekRead' or 'hSeekWrite' allows the read-- and write pointers to be modified separately. 'hSeek' modifies both the-- read and the write pointer.-- -- Note that the frames offset can be negative and in fact should be when-- SeekFromEnd is used for the whence parameter.-- -- 'hSeek' will return the offset in (multichannel) frames from the start of-- the audio data, or signal an error when an attempt is made to seek beyond-- the start or end of the file.hSeek::Handle->SeekMode->Count->IOCounthSeek=hSeek'Nothing--hSeek (Handle _ handle) seekMode frames = do-- n <- liftM fromIntegral $ {#call unsafe sf_seek#} handle (cIntConv frames) (cFromEnum seekMode)-- checkHandle handle-- return n-- |Like 'hSeek', but only the read pointer is modified.hSeekRead::Handle->SeekMode->Count->IOCounthSeekRead=hSeek'(JustReadMode)-- |Like 'hSeek', but only the write pointer is modified.hSeekWrite::Handle->SeekMode->Count->IOCounthSeekWrite=hSeek'(JustWriteMode)-- ====================================================================-- string access-- |Header string field types.dataStringType=StrTitle|StrCopyright|StrSoftware|StrArtist|StrComment|StrDatederiving(Eq,Show)instanceEnumStringTypewherefromEnumStrTitle=1fromEnumStrCopyright=2fromEnumStrSoftware=3fromEnumStrArtist=4fromEnumStrComment=5fromEnumStrDate=6toEnum1=StrTitletoEnum2=StrCopyrighttoEnum3=StrSoftwaretoEnum4=StrArtisttoEnum5=StrCommenttoEnum6=StrDatetoEnumunmatched=error("StringType.toEnum: Cannot match "++showunmatched){-# LINE 375 "./Sound/File/Sndfile/Interface.chs" #-}-- |The 'getString' function returns the specificed string from the stream-- header in the 'Maybe' monad if it exists and 'Nothing' otherwise.getString::Handle->StringType->IO(MaybeString)getString(Handle_handle)t=doptr<-sf_get_stringhandle(cFromEnumt)ifptr==(nullPtr::PtrCChar)thenreturnNothingelseliftMJust$peekCString=<<(returnptr)-- |The 'setString' function sets the string data associated with the-- respective 'StringType'.setString::Handle->StringType->String->IO()setString(Handle_handle)ts=withCStrings(\cs->dosf_set_stringhandle(cFromEnumt)cscheckHandlehandlereturn())-- EOFforeignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_format_check"sf_format_check::((Ptr())->(IOCInt))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_error"sf_error::((Ptr())->(IOCInt))foreignimportccallsafe"Sound/File/Sndfile/Interface.chs.h sf_strerror"sf_strerror::((Ptr())->(PtrCChar))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_open"sf_open::((PtrCChar)->(CInt->((Ptr())->(IO(Ptr())))))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_close"sf_close::((Ptr())->(IOCInt))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_write_sync"sf_write_sync::((Ptr())->(IO()))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_seek"sf_seek::((Ptr())->(CLLong->(CInt->(IOCLLong))))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_get_string"sf_get_string::((Ptr())->(CInt->(IO(PtrCChar))))foreignimportccallunsafe"Sound/File/Sndfile/Interface.chs.h sf_set_string"sf_set_string::((Ptr())->(CInt->((PtrCChar)->(IOCInt))))