packages feed

proteaaudio 0.7.1.0 → 0.8.0

raw patch · 7 files changed

+72/−26 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Sound.ProteaAudio: data Sound
- Sound.ProteaAudio: soundLoop :: Sample -> Float -> Float -> Float -> Float -> IO ()
+ Sound.ProteaAudio: soundLoop :: Sample -> Float -> Float -> Float -> Float -> IO Sound
- Sound.ProteaAudio: soundPlay :: Sample -> Float -> Float -> Float -> Float -> IO ()
+ Sound.ProteaAudio: soundPlay :: Sample -> Float -> Float -> Float -> Float -> IO Sound
- Sound.ProteaAudio: soundStop :: Sample -> IO Bool
+ Sound.ProteaAudio: soundStop :: Sound -> IO Bool
- Sound.ProteaAudio: soundUpdate :: Sample -> Float -> Float -> Float -> Float -> IO Bool
+ Sound.ProteaAudio: soundUpdate :: Sound -> Float -> Float -> Float -> Float -> IO Bool

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+# 0.8.0+- fix: distinct data and playback handles+- introduce Sound handle type, an abstraction for playback audio track+- soundLoop, soundPlay return a Sound handle+- soundUpdate, soundStop take a Sound handle parameter+ # 0.7.1.0 - add sampleFromMemoryPcm - update stb_vorbis to v1.14
README.md view
@@ -13,6 +13,21 @@  Samples can be loaded from file or memory. +# Build++### Stack++```bash+stack setup+stack build+```++### Nix:++``` bash+stack --nix build+```+ # Example  ```haskell@@ -27,9 +42,12 @@ waitPayback = do   n <- soundActive   when  (n > 0) $ do-    threadDelay 1000000+    threadDelay oneSec     waitPayback +oneSec :: Int+oneSec = 1000000 -- micro seconds+ main = do     args <- getArgs     filename <- case args of@@ -42,7 +60,14 @@     -- (A) load sample from file     sampleA <- sampleFromFile filename 1.0 -- volume -    soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    -- start two sound tracks with shared sample data+    sndTrkA <- soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    threadDelay oneSec -- wait 1 sec+    sndTrkB <- soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    -- play 3 sec+    threadDelay $ 3 * oneSec+    soundStop sndTrkB+    -- wait sndTrkA to finish     waitPayback      -- (B) load from memory buffer
Sound/ProteaAudio.chs view
@@ -12,6 +12,7 @@ module Sound.ProteaAudio (     -- * Sample     Sample(),+    Sound(),      -- * Audio System Setup     initAudio,@@ -29,7 +30,7 @@     sampleFromMemoryOgg,     sampleFromFile, -    -- * Sample Palyback+    -- * Sample Playback     soundLoop,     soundPlay,     soundUpdate,@@ -40,10 +41,13 @@ import Foreign.C import Data.ByteString (ByteString, useAsCStringLen) --- | Audio sample handle+-- | Audio sample resource handle. A sample can be shared between multiple Sound tracks. (abstraction for data) newtype Sample = Sample{ fromSample :: {#type sample_t#} } +-- | Sound track handle. It is used to control the audio playback. (abstraction for playback)+newtype Sound = Sound{ fromSound :: {#type sound_t#} } + -- | Initializes the audio system. {#fun initAudio     { `Int' -- ^ the maximum number of sounds that are played parallely. Computation time is linearly correlated to this factor.@@ -140,7 +144,7 @@   , `Float' -- ^ right volume   , `Float' -- ^ time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right   , `Float' -- ^ pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample-  } -> `()'+  } -> `Sound' Sound #}  -- | Plays a specified sound sample once and sets its parameters.@@ -150,12 +154,12 @@   , `Float' -- ^ right volume   , `Float' -- ^ time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right   , `Float' -- ^ pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample-  } -> `()'+  } -> `Sound' Sound #}  -- | Updates parameters of a specified sound. {#fun soundUpdate-  { fromSample `Sample' -- ^ handle of a currently active sound+  { fromSound `Sound' -- ^ handle of a currently active sound   , `Float' -- ^ left volume   , `Float' -- ^ right volume   , `Float' -- ^ time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right@@ -164,5 +168,5 @@ #}  -- | Stops a specified sound immediately.-{#fun soundStop {fromSample `Sample'} -> `Bool'#}+{#fun soundStop {fromSound `Sound'} -> `Bool'#} 
cbits/proteaaudio_binding.cpp view
@@ -127,26 +127,26 @@ }  // sound-void soundLoop(sample_t sample, float volumeL, float volumeR, float disparity, float pitch) {+sound_t soundLoop(sample_t sample, float volumeL, float volumeR, float disparity, float pitch) {     DeviceAudio & audio = DeviceAudio::singleton();-    if((&audio) == 0) return;-    audio.soundLoop(sample, volumeL,volumeR,disparity,pitch);+    if((&audio) == 0) return 0;+    return audio.soundLoop(sample, volumeL, volumeR, disparity, pitch); } -void soundPlay(sample_t sample, float volumeL, float volumeR, float disparity, float pitch) {+sound_t  soundPlay(sample_t sample, float volumeL, float volumeR, float disparity, float pitch) {     DeviceAudio & audio = DeviceAudio::singleton();-    if((&audio) == 0) return;-    audio.soundPlay(sample, volumeL,volumeR,disparity,pitch);+    if((&audio) == 0) return 0;+    return audio.soundPlay(sample, volumeL, volumeR, disparity, pitch); } -int soundUpdate(sample_t sample, float volumeL, float volumeR, float disparity, float pitch) {+int soundUpdate(sound_t sound, float volumeL, float volumeR, float disparity, float pitch) {     DeviceAudio & audio = DeviceAudio::singleton();     if((&audio) == 0) return 0;-    return audio.soundUpdate(sample, volumeL,volumeR,disparity,pitch);+    return audio.soundUpdate(sound, volumeL, volumeR, disparity, pitch); } -int soundStop(sample_t sample) {+int soundStop(sound_t sound) {     DeviceAudio & audio = DeviceAudio::singleton();     if((&audio) == 0) return 0;-    return audio.soundStop(sample);+    return audio.soundStop(sound); }
cbits/proteaaudio_binding.h view
@@ -1,8 +1,9 @@ #ifdef __cplusplus-extern "C" { +extern "C" { #endif  typedef int sample_t;+typedef int sound_t;  int initAudio(int nTracks, int frequency, int chunkSize); void finishAudio();@@ -14,10 +15,10 @@ sample_t sampleFromFile(char* filename, float volume); int soundActive(); void soundStopAll();-void soundLoop(sample_t sample, float volumeL, float volumeR, float disparity, float pitch);-void soundPlay(sample_t sample, float volumeL, float volumeR, float disparity, float pitch);-int soundUpdate(sample_t sample, float volumeL, float volumeR, float disparity, float pitch);-int soundStop(sample_t sample);+sound_t soundLoop(sample_t sample, float volumeL, float volumeR, float disparity, float pitch);+sound_t soundPlay(sample_t sample, float volumeL, float volumeR, float disparity, float pitch);+int soundUpdate(sound_t sound, float volumeL, float volumeR, float disparity, float pitch);+int soundStop(sound_t sound); #ifdef __cplusplus } #endif
example/play.hs view
@@ -9,9 +9,12 @@ waitPayback = do   n <- soundActive   when  (n > 0) $ do-    threadDelay 1000000+    threadDelay oneSec     waitPayback +oneSec :: Int+oneSec = 1000000 -- micro seconds+ main = do     args <- getArgs     filename <- case args of@@ -24,7 +27,14 @@     -- (A) load sample from file     sampleA <- sampleFromFile filename 1.0 -- volume -    soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    -- start two sound tracks with shared sample data+    sndTrkA <- soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    threadDelay oneSec -- wait 1 sec+    sndTrkB <- soundPlay sampleA 1 1 0 1 -- left volume, right volume, time difference between left and right, pitch factor for playback+    -- play 3 sec+    threadDelay $ 3 * oneSec+    soundStop sndTrkB+    -- wait sndTrkA to finish     waitPayback      -- (B) load from memory buffer
proteaaudio.cabal view
@@ -1,5 +1,5 @@ Name:                proteaaudio-Version:             0.7.1.0+Version:             0.8.0 Synopsis:            Simple audio library for Windows, Linux, OSX. Description:         Simple audio library for Windows, Linux, OSX. Supports PCM, Ogg and Wav playback and multichannel mixing. License:             BSD3