http://nintencer.fobby.net/sexyal-29may2005.zip
You can use this small library to help you if you'd like.
Instruct your C compiler to define HAVE_DIRECTSOUND. Compile sexyal.c, smallc.c, convert.c, and drivers/dsound.c.
You will need to write floating-point PCM audio data, in the range of [0:1](0.0000... through 1.0000..., inclusive).
You can have 1 channel(mono) or 2 channels(stereo, interleaved).
Example code:
#include "sexyal/sexyal.h"
static SexyAL *Interface;
static SexyAL_device *Output;
static SexyAL_format format;
static SexyAL_buffering buffering;
static SexyAL_enumtype *DriverTypes;
static int CurDriverIndex = 0;
uint32 GetMaxSound(void)
{
return(buffering.totalsize);
}
uint32 GetWriteSound(void)
{
return(Output->CanWrite(Output));
}
void WriteSound(float *Buffer, int Count)
{
//printf("%d\n",Output->CanWrite(Output));
Output->Write(Output, Buffer, Count);
}
int InitSound(int *rate, int channels)
{
memset(&format,0,sizeof(format));
memset(&buffering,0,sizeof(buffering));
Interface = (SexyAL *)SexyAL_Init(0);
DriverTypes = Interface->EnumerateTypes(Interface);
format.sampformat=SEXYAL_FMT_PCMFLOAT;
format.channels=channels;
format.rate=*rate;
buffering.fragcount=buffering.fragsize=0;
buffering.ms=soundbufsize;
if(!(Output=Interface->Open(Interface,NULL,&format,&buffering, DriverTypes[CurDriverIndex].type)))
{
Interface->Destroy(Interface);
Interface=0;
return(0);
}
format.sampformat=SEXYAL_FMT_PCMFLOAT;
format.channels=channels;
format.byteorder=0;
Output->SetConvert(Output,&format);
*rate = format.rate
return(1);
}
int KillSound(void)
{
if(Output)
Output->Close(Output);
if(Interface)
Interface->Destroy(Interface);
Interface=0;
if(!Output) return(0);
Output=0;
return(1);
}