On Sun, 1 Feb 2004 11:29:15 +0000 (GMT),
=?iso-8859-1?q?vikram=20sonawane?= <[EMAIL PROTECTED]> wrote:

>hello,
>      i'm having a problem using SndStreamCreate for
>recording....Can n e one give me a WORKING sample code
>
>demostrating the working of sndstreamcreate.i'm using
>Tungsten T simulator....
>thanx,

My application is too big to post, but the essentials are these:
The sound stream is opened with:

Err error = SndStreamCreate(&soundStream,
                sndInput,
                11025,  //NominalSamplesPerSecond
                sndInt16Little,
                sndMono,
                soundInCallback,
                (void*)&Ibufptrs,
                2048,   //RequestedBlockSize,
                0);             //..0 = callback is NOT ARM..

where the call back is:

Err soundInCallback(void *userData,
        SndStreamRef stream,
        void *buffer,
        UInt32 frameCount)
{
        Int16 *p;
        p = ((BufPtrs*)userData)->bufCurrent;
        if(p)
        {
                MemMove(p,buffer,RequestedBlockSize*sizeof(Int16));
                p += RequestedBlockSize;
                if(p >= ((BufPtrs*)userData)->bufPastEnd)
                        p = ((BufPtrs*)userData)->bufOrigin;
                ((BufPtrs*)userData)->bufCurrent = p;
                EvtWakeup();
        }
        return errNone;
}

where the BufPtrs structure is defined by:

typedef struct {
        Int16 *bufOrigin;
        Int16 *bufPastEnd;
        Int16 *bufCurrent;
} BufPtrs;

Then, I field the nilEvent in the main form event handler:

        case nilEvent:
                CheckSoundCallback();
                break;

where CheckSoundCallback() is defined by:

void CheckSoundCallback(void)
{
        Int16 *p;
        p = Mbufptrs.bufCurrent;
        while((p!=Ibufptrs.bufCurrent) && Ibufptrs.bufCurrent)
        {
                /*--process Mbufptrs.bufCurrent--*/
                //..then:...
                p += RequestedBlockSize;
                if(p >= Mbufptrs.bufPastEnd)
                        p = Mbufptrs.bufOrigin;
                Mbufptrs.bufCurrent = p;
        }
}

In this way, the callback does minimal processing, and leaves all the
heavy lifting to the event handler.


Robert Scott, Ypsilanti, MI
(reply through this forum, not by e-mailing me directly)

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to