Haskell OpenAl没有声音

时间:2016-08-26 13:51:46

标签: linux haskell audio openal

我目前正在尝试使用OpenAl在Haskell中播放音频文件。为了做到这一点,我试图在ALUT git存储库(https://github.com/haskell-openal/ALUT/blob/master/examples/Basic/PlayFile.hs)中获取示例代码。但是,它拒绝发出任何声音。我在这里缺少什么?

{-
   PlayFile.hs (adapted from playfile.c in freealut)
   Copyright (c) Sven Panne 2005-2016
   This file is part of the ALUT package & distributed under a BSD-style license.
   See the file LICENSE.
-}

import Control.Monad ( when, unless )
import Data.List ( intersperse )
import Sound.ALUT
import System.Exit ( exitFailure )
import System.IO ( hPutStrLn, stderr )

-- This program loads and plays a variety of files.

playFile :: FilePath -> IO ()
playFile fileName = do
   -- Create an AL buffer from the given sound file.
   buf <- createBuffer (File fileName)

   -- Generate a single source, attach the buffer to it and start playing.
   source <- genObjectName
   buffer source $= Just buf
   play [source]

   -- Normally nothing should go wrong above, but one never knows...
   errs <- get alErrors
   unless (null errs) $ do
      hPutStrLn stderr (concat (intersperse "," [ d | ALError _ d <- errs ]))
      exitFailure

   -- Check every 0.1 seconds if the sound is still playing.
   let waitWhilePlaying = do
          sleep 0.1
          state <- get (sourceState source)
          when (state == Playing) $
             waitWhilePlaying
   waitWhilePlaying

main :: IO ()
main = do
   -- Initialise ALUT and eat any ALUT-specific commandline flags.
   withProgNameAndArgs runALUT $ \progName args -> do

      -- Check for correct usage.
      unless (length args == 1) $ do
         hPutStrLn stderr ("usage: " ++ progName ++ " <fileName>")
         exitFailure

      -- If everything is OK, play the sound file and exit when finished.
      playFile (head args)

不幸的是,虽然我没有收到任何错误,但我也听不到任何声音。 Pavucontrol似乎也没有检测到任何内容(播放选项卡下没有额外的流)。

他们在同一个git存储库上的HelloWorld示例也没有给出错误和声音。

我还在同一个git存储库(https://github.com/haskell-openal/ALUT/blob/master/examples/Basic/OpenALInfo.hs)上尝试了OpenALInfo函数,这进一步证明了我实际连接到OpenAL,并提供了一些可能有用或可能没用的版本信息:

ALC version: 1.1
ALC extensions:
    ALC_ENUMERATE_ALL_EXT, ALC_ENUMERATION_EXT, ALC_EXT_CAPTURE,
    ALC_EXT_DEDICATED, ALC_EXT_disconnect, ALC_EXT_EFX,
    ALC_EXT_thread_local_context, ALC_SOFTX_device_clock,
    ALC_SOFT_HRTF, ALC_SOFT_loopback, ALC_SOFT_pause_device
AL version: 1.1 ALSOFT 1.17.2
AL renderer: OpenAL Soft
AL vendor: OpenAL Community
AL extensions:
    AL_EXT_ALAW, AL_EXT_BFORMAT, AL_EXT_DOUBLE,
    AL_EXT_EXPONENT_DISTANCE, AL_EXT_FLOAT32, AL_EXT_IMA4,
    AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS, AL_EXT_MULAW,
    AL_EXT_MULAW_BFORMAT, AL_EXT_MULAW_MCFORMATS, AL_EXT_OFFSET,
    AL_EXT_source_distance_model, AL_LOKI_quadriphonic,
    AL_SOFT_block_alignment, AL_SOFT_buffer_samples,
    AL_SOFT_buffer_sub_data, AL_SOFT_deferred_updates,
    AL_SOFT_direct_channels, AL_SOFT_loop_points, AL_SOFT_MSADPCM,
    AL_SOFT_source_latency, AL_SOFT_source_length

1 个答案:

答案 0 :(得分:4)

好吧,事实证明我在这里发布的有点太快了。我的代码没有问题,而是我的OpenAl设置。添加

drivers=pulse,alsa

到/etc/openal/alsoft.conf OpenAl工作。这在https://wiki.archlinux.org/index.php/PulseAudio#OpenAL

中有所描述