Hi all, I am trying to record sound using SndStreamCreate. it is giving invalid param error 0x80100000
What could be the reason I am using a Tungsten T regards /****************************************************************************** * * Copyright (c) 1999-2004 PalmSource, Inc. All rights reserved. * * File: AppMain.c * *****************************************************************************/ #include <PalmOS.h> #include "AppResources.h" /*********************************************************************** * * Entry Points * ***********************************************************************/ /*********************************************************************** * * Internal Constants * ***********************************************************************/ #define appFileCreator 'SNfd' // register your own at http://www.palmos.com/dev/creatorid/ #define appVersionNum 0x01 #define appPrefID 0x00 #define appPrefVersionNum 0x01 /*********************************************************************** * * Internal Functions * ***********************************************************************/ #define BUFLEN 4096 //Int16 mbf[BUFLEN]; //Int16* buf_ptr; Int16 i = 0; typedef struct oeCallbackDataType { FileHand fileRef; SndStreamRef streamRef; Boolean finished; UInt16 frameWidth; // number of bytes in each sample frame } oeCallbackDataType; oeCallbackDataType* cbDataP; //enum ActionType {sndRecord, sndPlay, sndStop}; void WriteInfo(char * inf) { WinDrawChars(inf, StrLen(inf), 10, 20); } static Err SndTestRec_Callback (void *userData, SndStreamRef stream, void *buffer, UInt32 frameCount) { Err result = errNone; Err result2 = errNone; SysNotifyParamType notifyParams; if(((oeCallbackDataType*)userData)->finished == true) WriteInfo("Entered callback after stopping."); FileWrite(((oeCallbackDataType*)(userData))->fileRef, buffer, (frameCount * ((oeCallbackDataType*)(userData))->frameWidth), 1, &result); if(result != errNone) WriteInfo("Error while recording to file."); if(result != errNone) { // stop the stream result2 = SndStreamStop(stream); ((oeCallbackDataType*)userData)->finished = true; MemSet(¬ifyParams, sizeof(SysNotifyParamType), 0); notifyParams.notifyType = appFileCreator; notifyParams.broadcaster = appFileCreator; notifyParams.notifyDetailsP = &userData; SysNotifyBroadcastDeferred(¬ifyParams, sizeof(void*)); return errNone; if(result2 != errNone) WriteInfo("Can't close sound stream."); } if(result != errNone) WriteInfo("Can't read from file."); return errNone; } /* Int32 j = 0; Int16 buf_ptr = MemPtrNew(BUFLEN); MemMove(buf_ptr, buffer, frameCount); WinDrawChars(buf_ptr, frameCount, 10, 10); for (j=0; ((j < frameCount) && (j <= BUFLEN)); j++) { //i++; WinDrawChars("1", 1, 10, j); mbf[j] = buf_ptr[j]; } */ //return errNone; /* 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; } */ static Err SndTest_Callback (void *userData, SndStreamRef stream, void *buffer, UInt32 frameCount) { Err result = errNone; Err result2 = errNone; SysNotifyParamType notifyParams; if(((oeCallbackDataType*)userData)->finished == true) WriteInfo("Entered callback after stopping."); FileRead(((oeCallbackDataType*)(userData))->fileRef, buffer, (frameCount * ((oeCallbackDataType*)(userData))->frameWidth), 1, &result); if(result != errNone) WriteInfo("Entered callback after stopping."); if(result == fileErrEOF) { // stop the stream result2 = SndStreamStop(stream); ((oeCallbackDataType*)userData)->finished = true; MemSet(¬ifyParams, sizeof(SysNotifyParamType), 0); notifyParams.notifyType = appFileCreator; notifyParams.broadcaster = appFileCreator; notifyParams.notifyDetailsP = &userData; SysNotifyBroadcastDeferred(¬ifyParams, sizeof(void*)); return errNone; if(result2 != errNone) WriteInfo("Can't close sound stream."); } if(result != errNone) WriteInfo("Can't read from file."); return errNone; } static Err OpenFile(UInt16 cardNo, const char * fileName, oeCallbackDataType* callbackDataP, UInt32 filemode) { Err err; callbackDataP->fileRef = FileOpen(cardNo, fileName, 0, 0/*'SNff'*/, filemode, &err); if(err != errNone) WriteInfo("Can't Open/Create file."); return err; } void sndRecSoundTest(oeCallbackDataType* callbackDataP, UInt32 sampleRate, SndStreamWidth sampleWidth) { Err result = errNone; result = SndStreamCreate ( &(callbackDataP->streamRef), sndInput, sampleRate, sndInt16Big, sampleWidth, SndTestRec_Callback, callbackDataP, BUFLEN, false); { char temp[16] = {0x00,}; StrPrintF(temp, "%lx", result); WinDrawChars(temp, StrLen(temp), 10, 30); } if(result != errNone) WriteInfo("Can't create sound stream."); callbackDataP->finished = false; if (sampleWidth == sndMono) callbackDataP->frameWidth = 2; else callbackDataP->frameWidth = 4; // twice the samples for stereo result = SndStreamStart(callbackDataP->streamRef); if(result != errNone) WriteInfo("Can't start sound stream."); } void sndPlaySoundTest(oeCallbackDataType* callbackDataP, UInt32 sampleRate, SndStreamWidth sampleWidth) { Err result; result = SndStreamCreate ( &(callbackDataP->streamRef), sndOutput, sampleRate, sndInt16Big, sampleWidth, SndTest_Callback, callbackDataP, BUFLEN, false); if(result != errNone) WriteInfo("Can't create sound stream."); callbackDataP->finished = false; if (sampleWidth == sndMono) callbackDataP->frameWidth = 2; else callbackDataP->frameWidth = 4; // twice the samples for stereo result = SndStreamStart(callbackDataP->streamRef); if(result != errNone) WriteInfo("Can't start sound stream."); /* i = 0; err = SndStreamCreate ( &streamP, sndOutput, 8000, sndInt16Big, sndStereo, SndTest_Callback, NULL, 250, false); //SndStreamStop(streamP); */ } static void FDPlay(UInt8 typeAc) { if(typeAc == 0) { //ErrNonFatalDisplayIf(true, "Record"); cbDataP = MemPtrNew(sizeof(oeCallbackDataType)); if(OpenFile(0, "SMH.pdb", cbDataP, fileModeAppend) == errNone) { sndRecSoundTest(cbDataP, 8192, sndMono); } } else if(typeAc == 1) { //ErrNonFatalDisplayIf(true, "Play"); if(OpenFile(0, "SMH.pdb", cbDataP, fileModeReadOnly) == errNone) { sndPlaySoundTest(cbDataP, 8192, sndStereo); } //FileRewind(cbDataP->fileRef); //sndPlaySoundTest(cbDataP, 8192, sndStereo); } else if (typeAc == 2) { //ErrNonFatalDisplayIf(true, "Stop"); FileClose(cbDataP->fileRef); SndStreamStop(cbDataP->streamRef); } } /* void Test() { // rscWavFile SndPtr soundP; MemHandle recordH; recordH = DmGet1Resource(sysResTSound,rscWavFile); soundP = (SndPtr) MemHandleLock(recordH); SndPlayResource(soundP,1024,sndFlagSync); // 1024 is 0dB // (unity) gain MemHandleUnlock(recordH); } */ /*********************************************************************** * * FUNCTION: MainFormDoCommand * * DESCRIPTION: This routine performs the menu command specified. * * PARAMETERS: command - menu item id * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static Boolean MainFormDoCommand(UInt16 command) { Boolean handled = false; FormType * pForm; switch (command) { case MainOptionsAboutStarterApp: pForm = FrmInitForm(AboutForm); FrmDoDialog(pForm); // Display the About Box. FrmDeleteForm(pForm); handled = true; break; case MainOptionsPlaySnd: //Play(); //Test(); handled = true; break; } return handled; } /*********************************************************************** * * FUNCTION: MainFormHandleEvent * * DESCRIPTION: This routine is the event handler for the * "MainForm" of this application. * * PARAMETERS: pEvent - a pointer to an EventType structure * * RETURNED: true if the event has handle and should not be passed * to a higher level handler. * * REVISION HISTORY: * * ***********************************************************************/ static Boolean MainFormHandleEvent(EventType* pEvent) { Boolean handled = false; FormType* pForm; switch (pEvent->eType) { case menuEvent: return MainFormDoCommand(pEvent->data.menu.itemID); case frmOpenEvent: pForm = FrmGetActiveForm(); FrmDrawForm(pForm); handled = true; break; case ctlSelectEvent: switch (pEvent->data.ctlSelect.controlID) { case MainPlayBtn: //PlayRawVFSFile("testsound22kHz1Ch.raw", 22050, sndMono); FDPlay(1); handled = true; break; case MainRecBtn: //PlayRawVFSFile("testsound44kHz2Ch.raw", 44100, sndStereo); FDPlay(0); handled = true; break; case MainStopBtn: FDPlay(2); handled = true; break; default: break; } break; default: break; } return handled; } /*********************************************************************** * * FUNCTION: AppHandleEvent * * DESCRIPTION: This routine loads form resources and set the event * handler for the form loaded. * * PARAMETERS: event - a pointer to an EventType structure * * RETURNED: true if the event has handle and should not be passed * to a higher level handler. * * REVISION HISTORY: * * ***********************************************************************/ static Boolean AppHandleEvent(EventType* pEvent) { UInt16 formId; FormType* pForm; Boolean handled = false; if (pEvent->eType == frmLoadEvent) { // Load the form resource. formId = pEvent->data.frmLoad.formID; pForm = FrmInitForm(formId); FrmSetActiveForm(pForm); // Set the event handler for the form. The handler of the currently // active form is called by FrmHandleEvent each time is receives an // event. switch (formId) { case MainForm: FrmSetEventHandler(pForm, MainFormHandleEvent); break; default: break; } handled = true; } return handled; } /*********************************************************************** * * FUNCTION: AppStart * * DESCRIPTION: Get the current application's preferences. * * PARAMETERS: nothing * * RETURNED: Err value errNone if nothing went wrong * * REVISION HISTORY: * * ***********************************************************************/ static Err AppStart(void) { FrmGotoForm(MainForm); return errNone; } /*********************************************************************** * * FUNCTION: AppStop * * DESCRIPTION: Save the current state of the application. * * PARAMETERS: nothing * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static void AppStop(void) { // Close all the open forms. FrmCloseAllForms(); } /*********************************************************************** * * FUNCTION: AppEventLoop * * DESCRIPTION: This routine is the event loop for the application. * * PARAMETERS: nothing * * RETURNED: nothing * * REVISION HISTORY: * * ***********************************************************************/ static void AppEventLoop(void) { Err error; EventType event; do { EvtGetEvent(&event, evtWaitForever); if (SysHandleEvent(&event)) continue; if (MenuHandleEvent(0, &event, &error)) continue; if (AppHandleEvent(&event)) continue; FrmDispatchEvent(&event); } while (event.eType != appStopEvent); } /*********************************************************************** * * FUNCTION: PilotMain * * DESCRIPTION: This is the main entry point for the application. * * PARAMETERS: cmd - word value specifying the launch code. * cmdPB - pointer to a structure that is associated with the launch code. * launchFlags - word value providing extra information about the launch. * RETURNED: Result of launch * * REVISION HISTORY: * * ***********************************************************************/ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) { Err error = errNone; switch (cmd) { case sysAppLaunchCmdNormalLaunch: if ((error = AppStart()) == 0) { AppEventLoop(); AppStop(); } break; default: break; } return error; } -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
