I wrote a piece of code which should be playing a continuous 440Hz tone, but
all I get is the tone with noises, clicks and lots of pauses. Anyone have an
idea of what I might be doing wrong?
Here is what I am doing:
int onoff;
SndStreamRef stream1;
const int Rate=11025;
typedef struct {
int freq;
Int32 fcount;
} data;
data mydata;
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
UInt16 getbuf(void *userData, SndStreamRef stream, void *buffer, UInt32
frameCount)
{
data *mydata=(data*)userData;
Int32 buf_size;
Int16 *buf_ptr=(Int16 *)buffer;
Int32 I,V;
UInt32 rate, freq;
Int32 L1,L2,K;
V=10;
freq=mydata->freq;
rate=Rate;
buf_size=frameCount;
K=0x10000*freq/rate;
L1=mydata->fcount;
for(I=0;I<buf_size;I++)
{
L2=L1+K;
buf_ptr[I]+=V*(L1&0x8000? (L2&0x8000? 1:0):(L2&0x8000? 0:-1));
L1=L2;
}
mydata->fcount=L1;
return errNone;
}
void suona(void)
{
Err err;
mydata.freq=440;
if(onoff==0){
mydata.fcount=0;
err=SndStreamCreate(&stream1, sndOutput, Rate, sndInt16Little, sndMono,
getbuf, &mydata, 256, false);
err=SndStreamStart(stream1);
onoff=1;
} else
{
err=SndStreamDelete(stream1);
onoff=0;
}
Thanks in advance,
Chris
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/