OS X 上的 Haskell 音频输出?

发布于 2024-08-20 15:34:22 字数 172 浏览 5 评论 0原文

我希望能够从 Haskell 输出音频。我目前在 OS X (Snow Leopard) 上使用 GHC 6.10。我尝试过构建 jack 库(使用 JackOSX)和 PortAudio 库,但它们似乎都没有效果。有没有一种相对简单的方法可以在 Mac 上从 Haskell 程序进行实时音频输出?

编辑:清晰度

I'd like to be able to output audio from Haskell. I'm currently using GHC 6.10 on OS X (Snow Leopard). I've tried building the jack library (using JackOSX) and the PortAudio library, but neither of them seemed effective. Is there a relatively simple way to do live audio output from a Haskell program on a Mac?

Edit: Clarity

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李白 2024-08-27 15:34:22

我已经成功地使用了 PortAudio。

我从我的玩具程序中摘录了一些内容,制作了一个非常简单的“回声”示例,如下所示:(

使用耳机运行。这是从麦克风到扬声器的反馈循环,在一段时间后可能会变得非常响亮几轮反馈)

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

在 Leopard 中与 GHC 6.10.4 一起工作。

我自己的玩具程序实际上只使用音频输入,并且它向音频输出输出零(没有这样做 PortAudio 抱怨的)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文