ALUT 2.3.0.1 → 2.3.0.2
raw patch · 18 files changed
+585/−581 lines, 18 files
Files
- ALUT.cabal +54/−50
- README.md +1/−1
- Sound/ALUT.hs +0/−32
- Sound/ALUT/Config.hs +0/−159
- Sound/ALUT/Constants.hs +0/−38
- Sound/ALUT/Errors.hs +0/−51
- Sound/ALUT/Initialization.hs +0/−69
- Sound/ALUT/Loaders.hs +0/−121
- Sound/ALUT/Sleep.hs +0/−24
- Sound/ALUT/Version.hs +0/−36
- src/Sound/ALUT.hs +32/−0
- src/Sound/ALUT/Config.hs +159/−0
- src/Sound/ALUT/Constants.hs +38/−0
- src/Sound/ALUT/Errors.hs +51/−0
- src/Sound/ALUT/Initialization.hs +69/−0
- src/Sound/ALUT/Loaders.hs +121/−0
- src/Sound/ALUT/Sleep.hs +24/−0
- src/Sound/ALUT/Version.hs +36/−0
ALUT.cabal view
@@ -1,65 +1,69 @@ name: ALUT-version: 2.3.0.1+version: 2.3.0.2+synopsis: A binding for the OpenAL Utility Toolkit+description:+ A Haskell binding for the OpenAL Utility Toolkit, which makes+ managing of OpenAL contexts, loading sounds in various formats+ and creating waveforms very easy. For more information about the+ C library on which this binding is based, please see:+ <http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html>.+homepage: https://github.com/haskell-openal/ALUT+bug-reports: https://github.com/haskell-openal/ALUT/issues license: BSD3 license-file: LICENSE+author: Sven Panne maintainer: Sven Panne <svenpanne@gmail.com>-bug-reports: https://github.com/haskell-openal/ALUT/issues-homepage: https://github.com/haskell-openal/ALUT category: Sound-synopsis: A binding for the OpenAL Utility Toolkit-description:- A Haskell binding for the OpenAL Utility Toolkit, which makes- managing of OpenAL contexts, loading sounds in various formats- and creating waveforms very easy. For more information about the- C library on which this binding is based, please see:- <http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html>. build-type: Simple-cabal-version: >= 1.6+cabal-version: >= 1.10 extra-source-files:- README.md- examples/Basic/HelloWorld.hs- examples/Basic/OpenALInfo.hs- examples/Basic/PlayFile.hs- examples/TestSuite/TestErrorStuff.hs- examples/TestSuite/TestFileLoader.hs- examples/TestSuite/TestMemoryLoader.hs- examples/TestSuite/TestVersion.hs- examples/TestSuite/TestWaveforms.hs- examples/TestSuite/file1.wav- examples/TestSuite/file2.au- examples/TestSuite/file3.raw+ README.md+ examples/Basic/HelloWorld.hs+ examples/Basic/OpenALInfo.hs+ examples/Basic/PlayFile.hs+ examples/TestSuite/TestErrorStuff.hs+ examples/TestSuite/TestFileLoader.hs+ examples/TestSuite/TestMemoryLoader.hs+ examples/TestSuite/TestVersion.hs+ examples/TestSuite/TestWaveforms.hs+ examples/TestSuite/file1.wav+ examples/TestSuite/file2.au+ examples/TestSuite/file3.raw flag UseNativeWindowsLibraries- description:- When compiling under Windows, use the native libraries instead of e.g. the- ones coming with Cygwin.+ description:+ When compiling under Windows, use the native libraries instead of e.g. the+ ones coming with Cygwin. library- exposed-modules:- Sound.ALUT,- Sound.ALUT.Initialization,- Sound.ALUT.Loaders,- Sound.ALUT.Sleep,- Sound.ALUT.Version- other-modules:- Sound.ALUT.Config,- Sound.ALUT.Constants,- Sound.ALUT.Errors- ghc-options: -Wall -O2- build-depends: base >= 3 && < 5, OpenGL >= 2.9.0.0, OpenAL >= 1.6.0.0- if os(windows) && flag(UseNativeWindowsLibraries)- if arch(i386)- cpp-options: "-DCALLCONV=stdcall"- else- cpp-options: "-DCALLCONV=ccall"- extra-libraries: alut+ exposed-modules:+ Sound.ALUT+ Sound.ALUT.Initialization+ Sound.ALUT.Loaders+ Sound.ALUT.Sleep+ Sound.ALUT.Version+ other-modules:+ Sound.ALUT.Config+ Sound.ALUT.Constants+ Sound.ALUT.Errors+ hs-source-dirs: src+ ghc-options: -Wall -O2+ build-depends: base >= 3 && < 5, OpenGL >= 2.9.0.0, OpenAL >= 1.6.0.0+ default-language: Haskell2010+ other-extensions: CPP+ if os(windows) && flag(UseNativeWindowsLibraries)+ if arch(i386)+ cpp-options: "-DCALLCONV=stdcall" else cpp-options: "-DCALLCONV=ccall"- if os(darwin) || os(ios)- frameworks: ALUT- else- extra-libraries: alut+ extra-libraries: alut+ else+ cpp-options: "-DCALLCONV=ccall"+ if os(ios)+ frameworks: ALUT+ else+ extra-libraries: alut source-repository head- type: git- location: https://github.com/haskell-openal/ALUT+ type: git+ location: https://github.com/haskell-openal/ALUT.git
README.md view
@@ -3,4 +3,4 @@ A Haskell binding for the OpenAL Utility Toolkit, which makes managing of OpenAL contexts, loading sounds in various formats and creating waveforms very easy. -[](https://travis-ci.org/haskell-openal/ALUT)+[](https://hackage.haskell.org/package/ALUT) [](https://travis-ci.org/haskell-openal/ALUT)
− Sound/ALUT.hs
@@ -1,32 +0,0 @@------------------------------------------------------------------------------------ |--- Module : Sound.ALUT--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable------ A Haskell binding for the OpenAL Utility Toolkit, which makes managing of--- OpenAL contexts, loading sounds in various formats and creating waveforms--- very easy. For more information about the C library on which this binding is--- based, please see: <http://www.openal.org/openal_webstf/specs/alut.html>.--------------------------------------------------------------------------------------module Sound.ALUT (- module Sound.OpenAL,-- module Sound.ALUT.Initialization,- module Sound.ALUT.Loaders,- module Sound.ALUT.Version,- module Sound.ALUT.Sleep-) where--import Sound.OpenAL--import Sound.ALUT.Initialization-import Sound.ALUT.Loaders-import Sound.ALUT.Version-import Sound.ALUT.Sleep
− Sound/ALUT/Config.hs
@@ -1,159 +0,0 @@-{-# LANGUAGE ForeignFunctionInterface, CPP #-}-{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Config--- Copyright : (c) Sven Panne 2006-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable------ This purely internal module defines the platform-specific stuff which has--- been figured out by configure.--------------------------------------------------------------------------------------module Sound.ALUT.Config (- alut_Init,- alut_InitWithoutContext,- alut_Exit,-- alut_GetError,- alut_GetErrorString,-- alut_CreateBufferFromFile,- alut_CreateBufferFromFileImage,- alut_CreateBufferHelloWorld,- alut_CreateBufferWaveform,-- alut_LoadMemoryFromFile,- alut_LoadMemoryFromFileImage,- alut_LoadMemoryHelloWorld,- alut_LoadMemoryWaveform,-- alut_GetMIMETypes,-- alut_GetMajorVersion,- alut_GetMinorVersion,-- alut_Sleep-) where------------------------------------------------------------------------------------import Foreign.C-import Foreign.Ptr-import Sound.OpenAL.AL.BasicTypes------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutInit"- alut_Init :: Ptr CInt -> Ptr CString -> IO ALboolean------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutInitWithoutContext"- alut_InitWithoutContext :: Ptr CInt -> Ptr CString -> IO ALboolean------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutExit"- alut_Exit :: IO ALboolean------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutGetError"- alut_GetError :: IO ALenum------------------------------------------------------------------------------------alut_GetErrorString :: ALenum -> IO String-alut_GetErrorString e = peekCString =<< alutGetErrorString e--foreign import CALLCONV unsafe "alutGetErrorString"- alutGetErrorString :: ALenum -> IO CString------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutCreateBufferFromFile"- alut_CreateBufferFromFile :: CString -> IO ALuint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutCreateBufferFromFileImage"- alut_CreateBufferFromFileImage :: Ptr a -> ALsizei -> IO ALuint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutCreateBufferHelloWorld"- alut_CreateBufferHelloWorld :: IO ALuint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutCreateBufferWaveform"- alut_CreateBufferWaveform :: ALenum- -> ALfloat- -> ALfloat- -> ALfloat- -> IO ALuint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutLoadMemoryFromFile"- alut_LoadMemoryFromFile :: CString- -> Ptr ALenum- -> Ptr ALsizei- -> Ptr ALfloat- -> IO (Ptr b)------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutLoadMemoryFromFileImage"- alut_LoadMemoryFromFileImage :: Ptr a- -> ALsizei- -> Ptr ALenum- -> Ptr ALsizei- -> Ptr ALfloat- -> IO (Ptr b)------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutLoadMemoryHelloWorld"- alut_LoadMemoryHelloWorld :: Ptr ALenum- -> Ptr ALsizei- -> Ptr ALfloat- -> IO (Ptr b)------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutLoadMemoryWaveform"- alut_LoadMemoryWaveform :: ALenum- -> ALfloat- -> ALfloat- -> ALfloat- -> Ptr ALenum- -> Ptr ALsizei- -> Ptr ALfloat- -> IO (Ptr b)------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutGetMIMETypes"- alut_GetMIMETypes :: ALenum -> IO CString------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutGetMajorVersion"- alut_GetMajorVersion :: IO ALint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutGetMinorVersion"- alut_GetMinorVersion :: IO ALint------------------------------------------------------------------------------------foreign import CALLCONV unsafe "alutSleep"- alut_Sleep :: ALfloat -> IO ALboolean
− Sound/ALUT/Constants.hs
@@ -1,38 +0,0 @@-{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Constants--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Constants where--import Sound.OpenAL.AL.BasicTypes ( ALint, ALenum )------------------------------------------------------------------------------------alut_API_MAJOR_VERSION, alut_API_MINOR_VERSION :: ALint-alut_API_MAJOR_VERSION = 1-alut_API_MINOR_VERSION = 1------------------------------------------------------------------------------------alut_WAVEFORM_SINE, alut_WAVEFORM_SQUARE, alut_WAVEFORM_SAWTOOTH,- alut_WAVEFORM_IMPULSE, alut_WAVEFORM_WHITENOISE :: ALenum-alut_WAVEFORM_SINE = 0x100-alut_WAVEFORM_SQUARE = 0x101-alut_WAVEFORM_SAWTOOTH = 0x102-alut_WAVEFORM_WHITENOISE = 0x103-alut_WAVEFORM_IMPULSE = 0x104------------------------------------------------------------------------------------alut_LOADER_BUFFER, alut_LOADER_MEMORY :: ALenum-alut_LOADER_BUFFER = 0x300-alut_LOADER_MEMORY = 0x301
− Sound/ALUT/Errors.hs
@@ -1,51 +0,0 @@-{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Errors--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Errors (- throwIfALfalse, throwIfNullPtr, makeBuffer-) where--import Control.Monad ( void, when )-import Data.Maybe ( fromJust, isNothing )-import Foreign.Ptr ( Ptr, nullPtr )-import Sound.OpenAL.AL.BasicTypes ( ALboolean, ALuint )-import Sound.OpenAL.AL.Buffer ( Buffer )-import Sound.OpenAL.AL.Extensions ( unmarshalALboolean, unmarshalBuffer )-import Sound.ALUT.Config ( alut_GetError, alut_GetErrorString )------------------------------------------------------------------------------------throwIf :: (a -> Bool) -> String -> IO a -> IO a-throwIf failurePredicate name action = do- returnValue <- action- when (failurePredicate returnValue) $ do- description <- alut_GetErrorString =<< alut_GetError- ioError (userError (name ++ ": " ++ description))- return returnValue------------------------------------------------------------------------------------throwIfALfalse :: String -> IO ALboolean -> IO ()-throwIfALfalse name action =- void $ throwIf (not . unmarshalALboolean) name action------------------------------------------------------------------------------------throwIfNullPtr :: String -> IO (Ptr a) -> IO (Ptr a)-throwIfNullPtr = throwIf (== nullPtr)------------------------------------------------------------------------------------makeBuffer :: String -> IO ALuint -> IO Buffer-makeBuffer name =- fmap fromJust . throwIf isNothing name . fmap unmarshalBuffer
− Sound/ALUT/Initialization.hs
@@ -1,69 +0,0 @@------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Initialization--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Initialization (- ArgumentConsumer, Runner, runALUT, runALUTUsingCurrentContext,- withProgNameAndArgs-) where--import Control.Exception ( finally )-import Data.List ( genericLength )-import Foreign.C.String ( CString, withCString, peekCString )-import Foreign.C.Types ( CInt )-import Foreign.Marshal.Array ( withArray0, peekArray )-import Foreign.Marshal.Utils ( with, withMany )-import Foreign.Ptr ( Ptr, nullPtr )-import Foreign.Storable ( Storable(peek) )-import Sound.ALUT.Config ( alut_Init, alut_InitWithoutContext, alut_Exit )-import Sound.ALUT.Errors ( throwIfALfalse )-import Sound.OpenAL.AL.BasicTypes ( ALboolean )-import System.Environment ( getProgName, getArgs )------------------------------------------------------------------------------------type ArgumentConsumer a = String -> [String] -> a--type Runner a = ArgumentConsumer (IO a) -> IO a------------------------------------------------------------------------------------runALUT :: ArgumentConsumer (Runner a)-runALUT = runner "runALUT" alut_Init------------------------------------------------------------------------------------runALUTUsingCurrentContext :: ArgumentConsumer (Runner a)-runALUTUsingCurrentContext =- runner "runALUTUsingCurrentContext" alut_InitWithoutContext------------------------------------------------------------------------------------runner :: String -> (Ptr CInt -> Ptr CString -> IO ALboolean) -> String- -> [String] -> Runner a-runner name initAction progName args action =- with (1 + genericLength args) $ \argcBuf ->- withMany withCString (progName : args) $ \argvPtrs ->- withArray0 nullPtr argvPtrs $ \argvBuf -> do- throwIfALfalse name $ initAction argcBuf argvBuf- newArgc <- peek argcBuf- newArgvPtrs <- peekArray (fromIntegral newArgc) argvBuf- newArgv <- mapM peekCString newArgvPtrs- action (head newArgv) (tail newArgv)- `finally` throwIfALfalse name alut_Exit------------------------------------------------------------------------------------withProgNameAndArgs :: (ArgumentConsumer (Runner a)) -> Runner a-withProgNameAndArgs alutRunner action = do- n <- getProgName- a <- getArgs- alutRunner n a action
− Sound/ALUT/Loaders.hs
@@ -1,121 +0,0 @@------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Loaders--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Loaders (- Phase, Duration, SoundDataSource(..),- createBuffer, createBufferData,- bufferMIMETypes, bufferDataMIMETypes-) where--import Foreign.C.String ( peekCString, withCString )-import Foreign.Marshal.Alloc ( alloca )-import Foreign.Storable ( Storable(peek) )-import Foreign.Ptr ( Ptr )-import Graphics.Rendering.OpenGL ( GettableStateVar, makeGettableStateVar )-import Sound.ALUT.Config (- alut_CreateBufferFromFile, alut_CreateBufferFromFileImage,- alut_CreateBufferHelloWorld, alut_CreateBufferWaveform,- alut_LoadMemoryFromFile, alut_LoadMemoryFromFileImage,- alut_LoadMemoryHelloWorld, alut_LoadMemoryWaveform,- alut_GetMIMETypes )-import Sound.ALUT.Constants (- alut_WAVEFORM_SINE, alut_WAVEFORM_SQUARE, alut_WAVEFORM_SAWTOOTH,- alut_WAVEFORM_IMPULSE, alut_WAVEFORM_WHITENOISE,- alut_LOADER_BUFFER, alut_LOADER_MEMORY )-import Sound.ALUT.Errors ( makeBuffer, throwIfNullPtr )-import Sound.OpenAL.AL.BasicTypes-import Sound.OpenAL.AL.Buffer ( Buffer, MemoryRegion(..), BufferData(..) )-import Sound.OpenAL.AL.Extensions ( unmarshalFormat )-import Sound.OpenAL.ALC.Context ( Frequency )------------------------------------------------------------------------------------type Phase = Float--type Duration = Float--data SoundDataSource a =- File FilePath- | FileImage (MemoryRegion a)- | HelloWorld- | Sine Frequency Phase Duration- | Square Frequency Phase Duration- | Sawtooth Frequency Phase Duration- | Impulse Frequency Phase Duration- | WhiteNoise Duration- deriving ( Eq, Ord, Show )------------------------------------------------------------------------------------createBuffer :: SoundDataSource a -> IO Buffer-createBuffer src = makeBuffer "createBuffer" $ case src of- File filePath -> withCString filePath alut_CreateBufferFromFile- FileImage (MemoryRegion buf size) -> alut_CreateBufferFromFileImage buf size- HelloWorld -> alut_CreateBufferHelloWorld- Sine f p d -> createBufferWaveform alut_WAVEFORM_SINE f p d- Square f p d -> createBufferWaveform alut_WAVEFORM_SQUARE f p d- Sawtooth f p d -> createBufferWaveform alut_WAVEFORM_SAWTOOTH f p d- Impulse f p d -> createBufferWaveform alut_WAVEFORM_IMPULSE f p d- WhiteNoise d -> createBufferWaveform alut_WAVEFORM_WHITENOISE 1 0 d--createBufferWaveform :: ALenum -> Float -> Float -> Float -> IO ALuint-createBufferWaveform w f p d =- alut_CreateBufferWaveform w (realToFrac f) (realToFrac p) (realToFrac d)------------------------------------------------------------------------------------createBufferData :: SoundDataSource a -> IO (BufferData b)-createBufferData src = case src of- File filePath -> withCString filePath $ \fp -> loadWith (alut_LoadMemoryFromFile fp)- FileImage (MemoryRegion buf size) -> loadWith (alut_LoadMemoryFromFileImage buf size)- HelloWorld -> loadWith alut_LoadMemoryHelloWorld- Sine f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SINE f p d)- Square f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SQUARE f p d)- Sawtooth f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SAWTOOTH f p d)- Impulse f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_IMPULSE f p d)- WhiteNoise d -> loadWith (loadMemoryWaveform alut_WAVEFORM_WHITENOISE 1 0 d)--loadMemoryWaveform :: ALenum -> Float -> Float -> Float -> Ptr ALenum -> Ptr ALsizei -> Ptr ALfloat -> IO (Ptr b)-loadMemoryWaveform w f p d =- alut_LoadMemoryWaveform w (realToFrac f) (realToFrac p) (realToFrac d)--loadWith :: (Ptr ALenum -> Ptr ALsizei -> Ptr ALfloat -> IO (Ptr b)) -> IO (BufferData b)-loadWith loader =- alloca $ \formatBuf ->- alloca $ \sizeBuf ->- alloca $ \frequencyBuf -> do- buf <- throwIfNullPtr "createBufferData" $- loader formatBuf sizeBuf frequencyBuf- format <- peek formatBuf- size <- peek sizeBuf- frequency <- peek frequencyBuf- return $ BufferData (MemoryRegion buf size) (unmarshalFormat format) (realToFrac frequency)------------------------------------------------------------------------------------bufferMIMETypes :: GettableStateVar [String]-bufferMIMETypes = mimeTypes "bufferMIMETypes" alut_LOADER_BUFFER--bufferDataMIMETypes :: GettableStateVar [String]-bufferDataMIMETypes = mimeTypes "bufferDataMIMETypes" alut_LOADER_MEMORY--mimeTypes :: String -> ALenum -> GettableStateVar [String]-mimeTypes name loaderType =- makeGettableStateVar $ do- ts <- throwIfNullPtr name $ alut_GetMIMETypes loaderType- fmap (splitBy (== ',')) $ peekCString ts--splitBy :: (a -> Bool) -> [a] -> [[a]]-splitBy _ [] = []-splitBy p xs = case break p xs of- (ys, [] ) -> [ys]- (ys, _:zs) -> ys : splitBy p zs
− Sound/ALUT/Sleep.hs
@@ -1,24 +0,0 @@------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Sleep--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Sleep (- sleep-) where--import Sound.ALUT.Config ( alut_Sleep )-import Sound.ALUT.Errors ( throwIfALfalse )-import Sound.ALUT.Loaders ( Duration )------------------------------------------------------------------------------------sleep :: Duration -> IO ()-sleep = throwIfALfalse "sleep" . alut_Sleep . realToFrac
− Sound/ALUT/Version.hs
@@ -1,36 +0,0 @@------------------------------------------------------------------------------------ |--- Module : Sound.ALUT.Version--- Copyright : (c) Sven Panne 2005-2013--- License : BSD3------ Maintainer : Sven Panne <svenpanne@gmail.com>--- Stability : stable--- Portability : portable--------------------------------------------------------------------------------------module Sound.ALUT.Version (- alutAPIVersion, alutVersion-) where--import Control.Monad ( liftM2 )-import Graphics.Rendering.OpenGL ( GettableStateVar, makeGettableStateVar )-import Sound.OpenAL.AL.BasicTypes ( ALint )-import Sound.ALUT.Config ( alut_GetMajorVersion, alut_GetMinorVersion )-import Sound.ALUT.Constants ( alut_API_MAJOR_VERSION, alut_API_MINOR_VERSION )------------------------------------------------------------------------------------alutAPIVersion :: String-alutAPIVersion = makeVersionString alut_API_MAJOR_VERSION alut_API_MINOR_VERSION--makeVersionString :: ALint -> ALint -> String-makeVersionString major minor = show major ++ "." ++ show minor------------------------------------------------------------------------------------alutVersion :: GettableStateVar String-alutVersion =- makeGettableStateVar $- liftM2 makeVersionString alut_GetMajorVersion alut_GetMinorVersion
+ src/Sound/ALUT.hs view
@@ -0,0 +1,32 @@+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+-- A Haskell binding for the OpenAL Utility Toolkit, which makes managing of+-- OpenAL contexts, loading sounds in various formats and creating waveforms+-- very easy. For more information about the C library on which this binding is+-- based, please see: <http://www.openal.org/openal_webstf/specs/alut.html>.+--+--------------------------------------------------------------------------------++module Sound.ALUT (+ module Sound.OpenAL,++ module Sound.ALUT.Initialization,+ module Sound.ALUT.Loaders,+ module Sound.ALUT.Version,+ module Sound.ALUT.Sleep+) where++import Sound.OpenAL++import Sound.ALUT.Initialization+import Sound.ALUT.Loaders+import Sound.ALUT.Version+import Sound.ALUT.Sleep
+ src/Sound/ALUT/Config.hs view
@@ -0,0 +1,159 @@+{-# LANGUAGE CPP #-}+{-# OPTIONS_HADDOCK hide #-}+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Config+-- Copyright : (c) Sven Panne 2006-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+-- This purely internal module defines the platform-specific stuff which has+-- been figured out by configure.+--+--------------------------------------------------------------------------------++module Sound.ALUT.Config (+ alut_Init,+ alut_InitWithoutContext,+ alut_Exit,++ alut_GetError,+ alut_GetErrorString,++ alut_CreateBufferFromFile,+ alut_CreateBufferFromFileImage,+ alut_CreateBufferHelloWorld,+ alut_CreateBufferWaveform,++ alut_LoadMemoryFromFile,+ alut_LoadMemoryFromFileImage,+ alut_LoadMemoryHelloWorld,+ alut_LoadMemoryWaveform,++ alut_GetMIMETypes,++ alut_GetMajorVersion,+ alut_GetMinorVersion,++ alut_Sleep+) where++--------------------------------------------------------------------------------++import Foreign.C+import Foreign.Ptr+import Sound.OpenAL.AL.BasicTypes++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutInit"+ alut_Init :: Ptr CInt -> Ptr CString -> IO ALboolean++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutInitWithoutContext"+ alut_InitWithoutContext :: Ptr CInt -> Ptr CString -> IO ALboolean++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutExit"+ alut_Exit :: IO ALboolean++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutGetError"+ alut_GetError :: IO ALenum++--------------------------------------------------------------------------------++alut_GetErrorString :: ALenum -> IO String+alut_GetErrorString e = peekCString =<< alutGetErrorString e++foreign import CALLCONV unsafe "alutGetErrorString"+ alutGetErrorString :: ALenum -> IO CString++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutCreateBufferFromFile"+ alut_CreateBufferFromFile :: CString -> IO ALuint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutCreateBufferFromFileImage"+ alut_CreateBufferFromFileImage :: Ptr a -> ALsizei -> IO ALuint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutCreateBufferHelloWorld"+ alut_CreateBufferHelloWorld :: IO ALuint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutCreateBufferWaveform"+ alut_CreateBufferWaveform :: ALenum+ -> ALfloat+ -> ALfloat+ -> ALfloat+ -> IO ALuint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutLoadMemoryFromFile"+ alut_LoadMemoryFromFile :: CString+ -> Ptr ALenum+ -> Ptr ALsizei+ -> Ptr ALfloat+ -> IO (Ptr b)++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutLoadMemoryFromFileImage"+ alut_LoadMemoryFromFileImage :: Ptr a+ -> ALsizei+ -> Ptr ALenum+ -> Ptr ALsizei+ -> Ptr ALfloat+ -> IO (Ptr b)++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutLoadMemoryHelloWorld"+ alut_LoadMemoryHelloWorld :: Ptr ALenum+ -> Ptr ALsizei+ -> Ptr ALfloat+ -> IO (Ptr b)++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutLoadMemoryWaveform"+ alut_LoadMemoryWaveform :: ALenum+ -> ALfloat+ -> ALfloat+ -> ALfloat+ -> Ptr ALenum+ -> Ptr ALsizei+ -> Ptr ALfloat+ -> IO (Ptr b)++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutGetMIMETypes"+ alut_GetMIMETypes :: ALenum -> IO CString++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutGetMajorVersion"+ alut_GetMajorVersion :: IO ALint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutGetMinorVersion"+ alut_GetMinorVersion :: IO ALint++--------------------------------------------------------------------------------++foreign import CALLCONV unsafe "alutSleep"+ alut_Sleep :: ALfloat -> IO ALboolean
+ src/Sound/ALUT/Constants.hs view
@@ -0,0 +1,38 @@+{-# OPTIONS_HADDOCK hide #-}+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Constants+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Constants where++import Sound.OpenAL.AL.BasicTypes ( ALint, ALenum )++--------------------------------------------------------------------------------++alut_API_MAJOR_VERSION, alut_API_MINOR_VERSION :: ALint+alut_API_MAJOR_VERSION = 1+alut_API_MINOR_VERSION = 1++--------------------------------------------------------------------------------++alut_WAVEFORM_SINE, alut_WAVEFORM_SQUARE, alut_WAVEFORM_SAWTOOTH,+ alut_WAVEFORM_IMPULSE, alut_WAVEFORM_WHITENOISE :: ALenum+alut_WAVEFORM_SINE = 0x100+alut_WAVEFORM_SQUARE = 0x101+alut_WAVEFORM_SAWTOOTH = 0x102+alut_WAVEFORM_WHITENOISE = 0x103+alut_WAVEFORM_IMPULSE = 0x104++--------------------------------------------------------------------------------++alut_LOADER_BUFFER, alut_LOADER_MEMORY :: ALenum+alut_LOADER_BUFFER = 0x300+alut_LOADER_MEMORY = 0x301
+ src/Sound/ALUT/Errors.hs view
@@ -0,0 +1,51 @@+{-# OPTIONS_HADDOCK hide #-}+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Errors+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Errors (+ throwIfALfalse, throwIfNullPtr, makeBuffer+) where++import Control.Monad ( void, when )+import Data.Maybe ( fromJust, isNothing )+import Foreign.Ptr ( Ptr, nullPtr )+import Sound.OpenAL.AL.BasicTypes ( ALboolean, ALuint )+import Sound.OpenAL.AL.Buffer ( Buffer )+import Sound.OpenAL.AL.Extensions ( unmarshalALboolean, unmarshalBuffer )+import Sound.ALUT.Config ( alut_GetError, alut_GetErrorString )++--------------------------------------------------------------------------------++throwIf :: (a -> Bool) -> String -> IO a -> IO a+throwIf failurePredicate name action = do+ returnValue <- action+ when (failurePredicate returnValue) $ do+ description <- alut_GetErrorString =<< alut_GetError+ ioError (userError (name ++ ": " ++ description))+ return returnValue++--------------------------------------------------------------------------------++throwIfALfalse :: String -> IO ALboolean -> IO ()+throwIfALfalse name action =+ void $ throwIf (not . unmarshalALboolean) name action++--------------------------------------------------------------------------------++throwIfNullPtr :: String -> IO (Ptr a) -> IO (Ptr a)+throwIfNullPtr = throwIf (== nullPtr)++--------------------------------------------------------------------------------++makeBuffer :: String -> IO ALuint -> IO Buffer+makeBuffer name =+ fmap fromJust . throwIf isNothing name . fmap unmarshalBuffer
+ src/Sound/ALUT/Initialization.hs view
@@ -0,0 +1,69 @@+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Initialization+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Initialization (+ ArgumentConsumer, Runner, runALUT, runALUTUsingCurrentContext,+ withProgNameAndArgs+) where++import Control.Exception ( finally )+import Data.List ( genericLength )+import Foreign.C.String ( CString, withCString, peekCString )+import Foreign.C.Types ( CInt )+import Foreign.Marshal.Array ( withArray0, peekArray )+import Foreign.Marshal.Utils ( with, withMany )+import Foreign.Ptr ( Ptr, nullPtr )+import Foreign.Storable ( Storable(peek) )+import Sound.ALUT.Config ( alut_Init, alut_InitWithoutContext, alut_Exit )+import Sound.ALUT.Errors ( throwIfALfalse )+import Sound.OpenAL.AL.BasicTypes ( ALboolean )+import System.Environment ( getProgName, getArgs )++--------------------------------------------------------------------------------++type ArgumentConsumer a = String -> [String] -> a++type Runner a = ArgumentConsumer (IO a) -> IO a++--------------------------------------------------------------------------------++runALUT :: ArgumentConsumer (Runner a)+runALUT = runner "runALUT" alut_Init++--------------------------------------------------------------------------------++runALUTUsingCurrentContext :: ArgumentConsumer (Runner a)+runALUTUsingCurrentContext =+ runner "runALUTUsingCurrentContext" alut_InitWithoutContext++--------------------------------------------------------------------------------++runner :: String -> (Ptr CInt -> Ptr CString -> IO ALboolean) -> String+ -> [String] -> Runner a+runner name initAction progName args action =+ with (1 + genericLength args) $ \argcBuf ->+ withMany withCString (progName : args) $ \argvPtrs ->+ withArray0 nullPtr argvPtrs $ \argvBuf -> do+ throwIfALfalse name $ initAction argcBuf argvBuf+ newArgc <- peek argcBuf+ newArgvPtrs <- peekArray (fromIntegral newArgc) argvBuf+ newArgv <- mapM peekCString newArgvPtrs+ action (head newArgv) (tail newArgv)+ `finally` throwIfALfalse name alut_Exit++--------------------------------------------------------------------------------++withProgNameAndArgs :: (ArgumentConsumer (Runner a)) -> Runner a+withProgNameAndArgs alutRunner action = do+ n <- getProgName+ a <- getArgs+ alutRunner n a action
+ src/Sound/ALUT/Loaders.hs view
@@ -0,0 +1,121 @@+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Loaders+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Loaders (+ Phase, Duration, SoundDataSource(..),+ createBuffer, createBufferData,+ bufferMIMETypes, bufferDataMIMETypes+) where++import Foreign.C.String ( peekCString, withCString )+import Foreign.Marshal.Alloc ( alloca )+import Foreign.Storable ( Storable(peek) )+import Foreign.Ptr ( Ptr )+import Graphics.Rendering.OpenGL ( GettableStateVar, makeGettableStateVar )+import Sound.ALUT.Config (+ alut_CreateBufferFromFile, alut_CreateBufferFromFileImage,+ alut_CreateBufferHelloWorld, alut_CreateBufferWaveform,+ alut_LoadMemoryFromFile, alut_LoadMemoryFromFileImage,+ alut_LoadMemoryHelloWorld, alut_LoadMemoryWaveform,+ alut_GetMIMETypes )+import Sound.ALUT.Constants (+ alut_WAVEFORM_SINE, alut_WAVEFORM_SQUARE, alut_WAVEFORM_SAWTOOTH,+ alut_WAVEFORM_IMPULSE, alut_WAVEFORM_WHITENOISE,+ alut_LOADER_BUFFER, alut_LOADER_MEMORY )+import Sound.ALUT.Errors ( makeBuffer, throwIfNullPtr )+import Sound.OpenAL.AL.BasicTypes+import Sound.OpenAL.AL.Buffer ( Buffer, MemoryRegion(..), BufferData(..) )+import Sound.OpenAL.AL.Extensions ( unmarshalFormat )+import Sound.OpenAL.ALC.Context ( Frequency )++--------------------------------------------------------------------------------++type Phase = Float++type Duration = Float++data SoundDataSource a =+ File FilePath+ | FileImage (MemoryRegion a)+ | HelloWorld+ | Sine Frequency Phase Duration+ | Square Frequency Phase Duration+ | Sawtooth Frequency Phase Duration+ | Impulse Frequency Phase Duration+ | WhiteNoise Duration+ deriving ( Eq, Ord, Show )++--------------------------------------------------------------------------------++createBuffer :: SoundDataSource a -> IO Buffer+createBuffer src = makeBuffer "createBuffer" $ case src of+ File filePath -> withCString filePath alut_CreateBufferFromFile+ FileImage (MemoryRegion buf size) -> alut_CreateBufferFromFileImage buf size+ HelloWorld -> alut_CreateBufferHelloWorld+ Sine f p d -> createBufferWaveform alut_WAVEFORM_SINE f p d+ Square f p d -> createBufferWaveform alut_WAVEFORM_SQUARE f p d+ Sawtooth f p d -> createBufferWaveform alut_WAVEFORM_SAWTOOTH f p d+ Impulse f p d -> createBufferWaveform alut_WAVEFORM_IMPULSE f p d+ WhiteNoise d -> createBufferWaveform alut_WAVEFORM_WHITENOISE 1 0 d++createBufferWaveform :: ALenum -> Float -> Float -> Float -> IO ALuint+createBufferWaveform w f p d =+ alut_CreateBufferWaveform w (realToFrac f) (realToFrac p) (realToFrac d)++--------------------------------------------------------------------------------++createBufferData :: SoundDataSource a -> IO (BufferData b)+createBufferData src = case src of+ File filePath -> withCString filePath $ \fp -> loadWith (alut_LoadMemoryFromFile fp)+ FileImage (MemoryRegion buf size) -> loadWith (alut_LoadMemoryFromFileImage buf size)+ HelloWorld -> loadWith alut_LoadMemoryHelloWorld+ Sine f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SINE f p d)+ Square f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SQUARE f p d)+ Sawtooth f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_SAWTOOTH f p d)+ Impulse f p d -> loadWith (loadMemoryWaveform alut_WAVEFORM_IMPULSE f p d)+ WhiteNoise d -> loadWith (loadMemoryWaveform alut_WAVEFORM_WHITENOISE 1 0 d)++loadMemoryWaveform :: ALenum -> Float -> Float -> Float -> Ptr ALenum -> Ptr ALsizei -> Ptr ALfloat -> IO (Ptr b)+loadMemoryWaveform w f p d =+ alut_LoadMemoryWaveform w (realToFrac f) (realToFrac p) (realToFrac d)++loadWith :: (Ptr ALenum -> Ptr ALsizei -> Ptr ALfloat -> IO (Ptr b)) -> IO (BufferData b)+loadWith loader =+ alloca $ \formatBuf ->+ alloca $ \sizeBuf ->+ alloca $ \frequencyBuf -> do+ buf <- throwIfNullPtr "createBufferData" $+ loader formatBuf sizeBuf frequencyBuf+ format <- peek formatBuf+ size <- peek sizeBuf+ frequency <- peek frequencyBuf+ return $ BufferData (MemoryRegion buf size) (unmarshalFormat format) (realToFrac frequency)++--------------------------------------------------------------------------------++bufferMIMETypes :: GettableStateVar [String]+bufferMIMETypes = mimeTypes "bufferMIMETypes" alut_LOADER_BUFFER++bufferDataMIMETypes :: GettableStateVar [String]+bufferDataMIMETypes = mimeTypes "bufferDataMIMETypes" alut_LOADER_MEMORY++mimeTypes :: String -> ALenum -> GettableStateVar [String]+mimeTypes name loaderType =+ makeGettableStateVar $ do+ ts <- throwIfNullPtr name $ alut_GetMIMETypes loaderType+ fmap (splitBy (== ',')) $ peekCString ts++splitBy :: (a -> Bool) -> [a] -> [[a]]+splitBy _ [] = []+splitBy p xs = case break p xs of+ (ys, [] ) -> [ys]+ (ys, _:zs) -> ys : splitBy p zs
+ src/Sound/ALUT/Sleep.hs view
@@ -0,0 +1,24 @@+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Sleep+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Sleep (+ sleep+) where++import Sound.ALUT.Config ( alut_Sleep )+import Sound.ALUT.Errors ( throwIfALfalse )+import Sound.ALUT.Loaders ( Duration )++--------------------------------------------------------------------------------++sleep :: Duration -> IO ()+sleep = throwIfALfalse "sleep" . alut_Sleep . realToFrac
+ src/Sound/ALUT/Version.hs view
@@ -0,0 +1,36 @@+--------------------------------------------------------------------------------+-- |+-- Module : Sound.ALUT.Version+-- Copyright : (c) Sven Panne 2005-2013+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+--------------------------------------------------------------------------------++module Sound.ALUT.Version (+ alutAPIVersion, alutVersion+) where++import Control.Monad ( liftM2 )+import Graphics.Rendering.OpenGL ( GettableStateVar, makeGettableStateVar )+import Sound.OpenAL.AL.BasicTypes ( ALint )+import Sound.ALUT.Config ( alut_GetMajorVersion, alut_GetMinorVersion )+import Sound.ALUT.Constants ( alut_API_MAJOR_VERSION, alut_API_MINOR_VERSION )++--------------------------------------------------------------------------------++alutAPIVersion :: String+alutAPIVersion = makeVersionString alut_API_MAJOR_VERSION alut_API_MINOR_VERSION++makeVersionString :: ALint -> ALint -> String+makeVersionString major minor = show major ++ "." ++ show minor++--------------------------------------------------------------------------------++alutVersion :: GettableStateVar String+alutVersion =+ makeGettableStateVar $+ liftM2 makeVersionString alut_GetMajorVersion alut_GetMinorVersion