module SFML.Audio.SoundStream
(
SoundStreamChunk(..)
, SoundStreamGetDataCallback
, SoundStreamSeekCallback
, createSoundStream
, destroy
, play
, pause
, stop
, getAttenuation
, getLoop
, getMinDistance
, getPitch
, getPlayingOffset
, getPosition
, getStatus
, getVolume
, isRelativeToListener
, setAttenuation
, setLoop
, setMinDistance
, setPitch
, setPlayingOffset
, setPosition
, setRelativeToListener
, setVolume
)
where
import SFML.Audio.SFSound
import SFML.Audio.SoundStatus
import SFML.Audio.Types
import SFML.SFResource
import SFML.System.Time
import SFML.System.Vector3
import Control.Applicative ((<$>), (<*>))
import Control.Monad ((>=>))
import Data.Word (Word16)
import Foreign.C.Types
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr)
import Foreign.Storable
data SoundStreamChunk = SoundStreamChunk
{ samples :: Ptr Word16
, sampleCount :: Int
}
size_SoundStreamChunk = (16)
instance Storable SoundStreamChunk where
sizeOf _ = size_SoundStreamChunk
alignment _ = alignment (undefined :: CInt)
peek ptr = SoundStreamChunk
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
<*> fmap fromIntegral ((\hsc_ptr -> peekByteOff hsc_ptr 8) ptr :: IO CUInt)
poke ptr (SoundStreamChunk samples sampleCount) = do
(\hsc_ptr -> pokeByteOff hsc_ptr 0) ptr samples
(\hsc_ptr -> pokeByteOff hsc_ptr 8) ptr (fromIntegral sampleCount :: CUInt)
type SoundStreamGetDataCallback a = Ptr SoundStreamChunk -> Ptr a -> IO CInt
type SoundStreamSeekCallback a = Time -> Ptr a -> IO ()
createSoundStream
:: Ptr (SoundStreamGetDataCallback a)
-> Ptr (SoundStreamSeekCallback a)
-> Int
-> Int
-> Ptr a
-> IO SoundStream
createSoundStream = sfSoundStream_create
foreign import ccall unsafe "sfSoundStream_create"
sfSoundStream_create
:: Ptr (SoundStreamGetDataCallback a)
-> Ptr (SoundStreamSeekCallback a)
-> Int
-> Int
-> Ptr a
-> IO SoundStream
instance SFResource SoundStream where
destroy = sfSoundStream_destroy
foreign import ccall unsafe "sfSoundStream_destroy"
sfSoundStream_destroy :: SoundStream -> IO ()
instance SFSound SoundStream where
play = sfSoundStream_play
pause = sfSoundStream_pause
stop = sfSoundStream_stop
getAttenuation = sfSoundStream_getAttenuation >=> return . realToFrac
getLoop music = fmap (toEnum . fromIntegral) $ sfSoundStream_getLoop music
getMinDistance = sfSoundStream_getMinDistance >=> return . realToFrac
getPitch = sfSoundStream_getPitch >=> return . realToFrac
getPlayingOffset music = alloca $ \ptr -> sfSoundStream_getPlayingOffset_helper music ptr >> peek ptr
getPosition music = alloca $ \ptr -> sfSoundStream_getPosition_helper music ptr >> peek ptr
getStatus = sfSoundStream_getStatus >=> return . toEnum . fromIntegral
getVolume = sfSoundStream_getVolume >=> return . realToFrac
isRelativeToListener = sfSoundStream_isRelativeToListener >=> return . toEnum . fromIntegral
setAttenuation m a = sfSoundStream_setAttenuation m (realToFrac a)
setLoop music val = sfSoundStream_setLoop music (fromIntegral . fromEnum $ val)
setMinDistance m d = sfSoundStream_setMinDistance m (realToFrac d)
setPitch m p = sfSoundStream_setPitch m (realToFrac p)
setPlayingOffset = sfSoundStream_setPlayingOffset
setPosition music pos = with pos $ sfSoundStream_setPosition_helper music
setRelativeToListener music val = sfSoundStream_setRelativeToListener music (fromIntegral . fromEnum $ val)
setVolume m v = sfSoundStream_setVolume m (realToFrac v)
foreign import ccall unsafe "sfSoundStream_play"
sfSoundStream_play :: SoundStream -> IO ()
foreign import ccall unsafe "sfSoundStream_pause"
sfSoundStream_pause :: SoundStream -> IO ()
foreign import ccall unsafe "sfSoundStream_stop"
sfSoundStream_stop :: SoundStream -> IO ()
foreign import ccall unsafe "sfSoundStream_getStatus"
sfSoundStream_getStatus :: SoundStream -> IO CInt
foreign import ccall unsafe "sfSoundStream_getChannelCount"
sfSoundStream_getChannelCount :: SoundStream -> IO CUInt
foreign import ccall unsafe "sfSoundStream_getSampleRate"
sfSoundStream_getSampleRate :: SoundStream -> IO CUInt
foreign import ccall unsafe "sfSoundStream_setPitch"
sfSoundStream_setPitch :: SoundStream -> CFloat -> IO ()
foreign import ccall unsafe "sfSoundStream_setVolume"
sfSoundStream_setVolume :: SoundStream -> CFloat -> IO ()
foreign import ccall unsafe "sfSoundStream_setPosition_helper"
sfSoundStream_setPosition_helper :: SoundStream -> Ptr Vec3f -> IO ()
foreign import ccall unsafe "sfSoundStream_setRelativeToListener"
sfSoundStream_setRelativeToListener :: SoundStream -> CInt -> IO ()
foreign import ccall unsafe "sfSoundStream_setMinDistance"
sfSoundStream_setMinDistance :: SoundStream -> CFloat -> IO ()
foreign import ccall unsafe "sfSoundStream_setAttenuation"
sfSoundStream_setAttenuation :: SoundStream -> CFloat -> IO ()
foreign import ccall unsafe "sfSoundStream_setPlayingOffset"
sfSoundStream_setPlayingOffset :: SoundStream -> Time -> IO ()
foreign import ccall unsafe "sfSoundStream_setLoop"
sfSoundStream_setLoop :: SoundStream -> CInt -> IO ()
foreign import ccall unsafe "sfSoundStream_getPitch"
sfSoundStream_getPitch :: SoundStream -> IO CFloat
foreign import ccall unsafe "sfSoundStream_getVolume"
sfSoundStream_getVolume :: SoundStream -> IO CFloat
foreign import ccall unsafe "sfSoundStream_getPosition_helper"
sfSoundStream_getPosition_helper :: SoundStream -> Ptr Vec3f -> IO ()
foreign import ccall unsafe "sfSoundStream_isRelativeToListener"
sfSoundStream_isRelativeToListener :: SoundStream -> IO CInt
foreign import ccall unsafe "sfSoundStream_getMinDistance"
sfSoundStream_getMinDistance :: SoundStream -> IO CFloat
foreign import ccall unsafe "sfSoundStream_getAttenuation"
sfSoundStream_getAttenuation :: SoundStream -> IO CFloat
foreign import ccall unsafe "sfSoundStream_getLoop"
sfSoundStream_getLoop :: SoundStream -> IO CInt
foreign import ccall unsafe "sfSoundStream_getPlayingOffset_helper"
sfSoundStream_getPlayingOffset_helper :: SoundStream -> Ptr Time -> IO ()