I'm attempting to write an application that can record voice memos. I need it to work without using a VFS drive. I've looked at the MiniADPCM example, but I don't want to rely on the MP3 library. As Katie Siek requested yesteday, it would be great to be able to see the source for the voice memo application.

Currently when ever I run my app, I get a fatal exception. If anyone can look at this code and tell me why, it would be greatly appreciated.

Here is the function that starts the recording:

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

BufPtrs gBufPtrs;

UInt32 RequestedBlockSize = 2048;

Int16 *buffer;



void StartRecording()
{
        HostTraceOutputTL(dmErrorClass, "Start");

        //BufPtrs bufPtrs;
        Err error = errNone;


        SndStreamMode mode = sndInput;  /* input/output, enum */
        UInt32 samplerate = 11025;                              
        SndSampleType type = sndInt8;                           
        SndStreamWidth width = sndMono;                 
        UInt32 buffsize = RequestedBlockSize ;                          
        Boolean armNative = false;
        MemHandle bufferHandle;

        
        bufferHandle = MemHandleNew(sizeof(Int16)*16000);
        buffer = (Int16*)MemHandleLock(bufferHandle);
        
        gBufPtrs.bufCurrent = buffer;
        gBufPtrs.bufOrigin = buffer;
        gBufPtrs.bufPastEnd = buffer + 16000;


        error = SndStreamCreate(&gBufPtrs.sndRef,
                                                mode,   
                                                samplerate,     
                                                type,   
                                                width,  
                                                RecordingCallback,
                                                &gBufPtrs/*userdata*/,
                                                buffsize,       
                                                armNative);

        
        
        error = SndStreamStart(gBufPtrs.sndRef);
}

Here is the call back function:


Err RecordingCallback(void *userdata, SndStreamRef channel, void *buffer, UInt32 numberofframes)
{
        Err error = errNone;
        
        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;
        }
        
        
        return error;

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

Reply via email to