DragonFly BSD
DragonFly users List (threaded) for 2012-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: sound


From: "Joel K. Pettersson" <joelkpettersson@xxxxxxxxx>
Date: Wed, 21 Mar 2012 10:04:55 +0100

On 2012-03-20, Pierre Abbat wrote:
> I'm writing a program that generates sound samples at (theoretically) 44100 Hz
> and writes them to a .wav file, which I then play with xmms. How can I hear the
> sound as the program generates it? Can the same code work on both DFly and
> Linux?
>
> Pierre

For the simplest (except when it comes to running it on Linux)
solution, look into the <sys/soundcard.h> API - the basic, common OSS
interface which is pretty much a de-facto UNIX standard outside Linux;
a program written using it will for instance Just Work on all BSDs. It
can also work on Linux *if* you either install OSS v4, replacing ALSA
- or get the OSS emulation for ALSA to work.

Using the OSS API is basically just opening /dev/dsp as a file, doing
some initial sound setup (sample format, number of channels, sample
rate) and then writing the samples to it.

There are examples to be found by Googling. Then I have one of my own
(sgensys.c in the present snapshot release) here:
http://download.gna.org/sgensys/


A "real" cross-platform solution (ie. working on standard Linux
distros out of the box) would have to either: 1. Implement OSS as
above, but also implement ALSA and instead use this by default when
built on Linux. Or: 2. Instead use a cross-platform library or other
abstraction layer - any with a functional sound API should basically
do the job - which is perhaps simpler than #1 at the cost of a
dependency.

-- 
  Joel K. Pettersson



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]