As you suggested, I tried to play a long 440Hz tone:
Using 16bit samples at a 44100 rate, I used this code:
SndStreamCreate(&playstream, sndOutput, 44100, sndInt16Little, sndMono,
getbuf, &pctx, 16384, false);
UInt16 getbuf(void *userData, SndStreamRef stream, void *buffer, UInt32
frameCount) {
Int32 buf_size;
Int16 *buf_ptr=buffer;
buf_size=frameCount;
{
Int32 i;
UInt32 rate, fract, freq, freq2;
freq=440; // 440Hz
rate=44100;
freq2=(freq<<16)/rate;
fract=0;
//eprintf("freq2=%ld", freq2);
for (i=0; i<buf_size; i++) {
buf_ptr[i]=fract&0x8000?0xff7f:0x0080;
fract+=freq2;
}
return errNone;
}
}
When I run this, I hear a 440Hz tone, the problem is it isn't continuous. I
think each buffer gets played properly, but in between, I hear some
artefacts. (the sound is "chopped" into pieces).
When I run the same code using UInt8 samples, I have exactly the same
problem.
Do you have the sample problem when running the same code?
What should I do to get a continous 440Hz tone?
thanks,
David
"Carsten" <[EMAIL PROTECTED]> wrote in message
news:110699@palm-dev-forum...
>
> "news.palmos.com" wrote:
>
> > Has anyone managed to play sampled sound on the Palm tungsten using the
> > Sound manager?
> > I'm testing the Stream Manager by outputting random samples:
> >
> > SndStreamCreate(&stream, sndOutput, 44100, sndInt16, sndStereo, getbuf,
0,
> > 8192, false);
> >
> > The callback function getbuf gets called properly and is defined as
follows:
> >
> > UInt&6 getbuf(void *userData, SndStreamRef stream, void *buffer, UInt32
> > frameCount) {
> > Int32 buf_size=frameCount*4 // stereo and Int16 frames
> > char *buf_ptr=buffer;
> > Int32 i;
> > for (i=0; i<buf_size; i++) {
> > buf_ptr[i]=SysRandom(0)%256;
> > }
> > }
> >
> > As you can see, getbuf, simply fills the buffer with random data.
> >
> > The problem I encounter is that the first filled buffer gets played, but
> > after that nothing gets played anymore, I simply hear some kind of
ticking
> > (although getbuf is called properly each time).
> >
> > Can someone please tell me how to play random samples using the Sound
> > Manager?
> >
> > Thanks,
> > David
>
> For me the soundstuff works fine. I just do it like you do.. although I
use
> 8-bit samples and I do it in assembly... ;)
> Calling SysRandom (or OS-routine in general) in a time-critical code-area
might
> not be the best solution.
> Just try to play a simple square-wave to test your soundroutine.
> (f.e.: buf_ptr[i] = (fract>>8)&0x8000; fract+=frequency; this
should
> work. (8bit fractional freq. precision) )
> (Or use a simple feedback algorithm.)
> (Or just use a short sample from a database)
> ...
>
> Something I encountered: some frequency are rejected by SndStreamCreate.
>
> Btw, why is *buff_ptr a char* ? Shouldn't it be a u16 * ? (because
of
> SndInt16)
>
>
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/