5

I am using the Raspbian “wheezy” image and I copied over a wav file and played it successfully doing:

aplay test.wav

So then I knocked up this little console application:

using System;
using System.Media;
using System.IO;

namespace SoundPlayingTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            using(var file = new FileStream("test.wav", 
                FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var player = new SoundPlayer(file);
                player.PlaySync();
            }
        }
    }
}

I expected that to play the wav just like aplay but it finishes (with no error) and I hear nothing from the headphones I have plugged in.

I found this thread "System.Media.SoundPlayer silent" that suggested it wasn't working but was fixed and the workaround suggested there is exactly what I am doing so I am not really any further.

To give some further information I ran:

mono --version

And this was the result:

Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors.     www.mono-project.com
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,vfp
Disabled:      none
Misc:          softdebug 
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

So, is it possible to get SoundPlayer to work (it should play a wav file right?) or is there some alternative I can use in order to play a sound file from mono running on the PI?

(by the way, I installed mono by doing sudo apt-get install mono-complete so I guess I am not missing any dependencies)

kmp
  • 257
  • 1
  • 4
  • 12

2 Answers2

2

There are allot of sound issues with the Raspberry Pi - and I mono on Pi(or any Linux actually) was no exception.

There has been an issue with this and it is resolved in the master repo.

How to solve the problem? You can try and build mono from the latest source or wait a while until it is pushed into the next update. But it seems mono on "wheezy" does not support audio because ...

p/invokes are broken on raspbian. especially if floating point values are involved

So sources have suggested :

run any non-hard-float os on the pi. or wait for hf support in mono 3.0 packages in debian experimental. couple of weeks for that, imho.

Piotr Kula
  • 17,336
  • 6
  • 66
  • 105
0

Your sample code played for me, however if I run my console app as sudo, the SSH session hangs and I need to start a new one.

This doesn't happen if not sudo (I need sudo to access i2c)

pi@raspberrypi ~ $ mono --version
Mono Runtime Engine version 3.2.7 (master/d7ce227 Monday 23 December  21:49:08 EST 2013)
Copyright (C) 2002-2013 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

I also get some audio errors to std out but otherwise the sound plays

*** glibc detected *** mono: double free or corruption (!prev): 0x01b862a8 ***
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Mono.Audio.AlsaDevice.snd_pcm_hw_params_free (intptr) <0xffffffff>
  at Mono.Audio.AlsaDevice.Dispose (bool) <0x0004f>
  at Mono.Audio.AlsaDevice.Finalize () <0x00027>
  at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) <0xffffffff>
fiat
  • 149
  • 6