I've been using PortAudio successfully.
I took some excerpts from my toy program to make a very simple "echo" example, below:
(run with headphones. this is a feedback loop from the mic to the speakers and may become very loud after a few feedback rounds)
import Control.Monad (forever)
import Data.Int (Int16)
import Foreign.Ptr (nullPtr)
import Sound.PortAudio
initPortAudio :: Int -> IO (PaStream Int16)
initPortAudio blockSize = do
Right NoError <- initialize
Just micDevIdx <- getDefaultInputDevice
Just spkDevIdx <- getDefaultOutputDevice
Right paStream <-
openStream
(Just (StreamParameters micDevIdx 1 PaInt16 0.1 nullPtr))
(Just (StreamParameters spkDevIdx 1 PaInt16 0.1 nullPtr))
44100 blockSize
:: IO (Either String (PaStream Int16))
Right NoError <- startStream paStream
let zeroBlock = replicate blockSize [0]
Right NoError <- writeStream paStream zeroBlock blockSize
return paStream
main :: IO ()
main = do
paStream <- initPortAudio blockSize
forever $ do
Right numSampsAvail <- getStreamReadAvailable paStream
Right curSamps <- readStream paStream 1 numSampsAvail
Right NoError <- writeStream paStream curSamps numSampsAvail
return ()
where
blockSize = 0x800
Works here in Leopard with GHC 6.10.4.
My own toy program actually only uses audio input, and it outputs zeros to audio output (without doing that PortAudio complains).