user6614616
user6614616

Reputation: 71

No sound with Haskell OpenAl

I am currently attempting to play audio files in Haskell using OpenAl. In order to do so, I am trying to get the example code at the ALUT git repository (https://github.com/haskell-openal/ALUT/blob/master/examples/Basic/PlayFile.hs) to work. However, it refuses to produce any sound. What am I missing here?

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

Unfortunately, while I don't get any errors, I also can\t hear any sound. Pavucontrol also does not seem to detect anything (no extra streams appear under the Playback tab).

Their HelloWorld example on the same git repository also gave neither errors nor sound.

I also tried the OpenALInfo function on the same git repository (https://github.com/haskell-openal/ALUT/blob/master/examples/Basic/OpenALInfo.hs), which further proves that I'm actually connecting to OpenAL, and gives some information about the versions which may or may not be useful:

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

Upvotes: 2

Views: 312

Answers (1)

user6614616
user6614616

Reputation: 71

Well, it turns out I posted here a bit too quickly. There was no problem with my code, but rather with my OpenAl settings. By adding

drivers=pulse,alsa

to /etc/openal/alsoft.conf OpenAl works. This is described in https://wiki.archlinux.org/index.php/PulseAudio#OpenAL.

Upvotes: 4

Related Questions