3

Is there a way i can send PCM (.wav) data to an audio device on raspberry pi? I am looking for something like

FILE* file_out = fopen("/dev/snd/pcmC0D0p", "wb");

so i can easily open the device in binary mode (using c code), and write samples to it.

I want to take the samples from a .wav file, process them, and send them directly to the sound card for playing (without writing them in another output .wav file). Of course, i will need to create the header of the .wav, so the sound driver knows sample rate, number of channels, bits/sample...

I am trying to avoid using other libraries, but i think this is the way i'm heading now.

4
  • are you looking for C code to do it, or a commandline way to do it? Your title doesn't match the example. Apr 10, 2013 at 17:56
  • The SDL library has platform-independent support for this, and for loading audio files in various formats as well.
    – Frepa
    Apr 10, 2013 at 20:58
  • @Frepa can you please give me a link ?
    – Adrian
    Apr 11, 2013 at 22:02
  • Links: SDL library webpage, SDL mixer is an additional library that simplifies loading audio files and then playing them, and supports loading ogg files as well. At least on raspbian, both sdl and sdl_mixer are in the repositories, sudo apt-get install libsdl1.2-dev libsdl-mixer1.2-dev
    – Frepa
    Apr 12, 2013 at 10:27

1 Answer 1

2

Accessing ALSA sound device is always a bit tricky. I suspect there are ioctl calls for the pcm devices of ALSA, but it is probably best to use a library.

There is a very small library called tinyalsa, which already comes with an example called tinyplay. This could be a good starting point for you, without the need to use the heavyweight ALSA library.

SDL is also a good idea, as Frepa suggested.

1
  • thank you, i used tinyalsa, exactly what i was looking for!
    – Adrian
    Apr 12, 2013 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.