Play a Sound directly from a buffer

Windows specific forum
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Play a Sound directly from a buffer

Post by Kazmirzak »

I want to calculate a realtime sound and play it realtime - thats my wish! A solution should be to store the data into a buffer; Windows should read the content of the buffer without interruption. I think I need a double buffer - the one buffer plays, while the other buffer is ready to be filled.

The only thing I found yet is this, but it only uses one buffer who is never changed.

Do you know any API solution for that?
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

It sounds as if you want to solve it by 'the hard coded way', but if you haven't thought about or heard of, here's another elegant way for doing this :
fmod.dll (or bass.dll although, I think, but there's a PB-Import for fmod.) does this job very well and comfortable. One advantage is, that you can use this buffer with any outputdriver (DSound, WinMM, ALSA, etc.) on Windows, Linux, ....
And I think it uses double buffer: while one buffer (~25 ms by default) is played by the soundcard, the other one passes through the whole mixer- and DSP-routines and may be filled somewhere there with your data.

There are different ways to fill the buffer, an easy one is to create a stream 'on scratch' with a callback-function of type:

Code: Select all

Procedure.l Buffercallback(*hStream.l, *BufferPointer.l, length.l, param.l)  
This procedure is called each time when the new buffer requests further data. So you can easily fill the buffer with raw 16Bit-stereo-data now.
Using a stream-callback for this allows your data to pass the whole mixer and DSP-chain before being copied to the soundcard, so you can do anything that you want with it (pitching, volume, DSP-FX, FFT,...)
Other possibilities are:
- Using a Sample with Sample-Upload.
- Using a DSP-unit

You might have a look at SineMouse or Realtime-Keys at http://fmod.2mal2mal.de

But keep in mind that fmod / bass are not free for non-free software.
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply