Hi palm-dev-forum,
I'm writing an app which (for the moment anyway) gets audio input
and writes it immediately to audio output. I've got a callback
defined for each audio stream and a buffer which they can both
access: the audio in callback fills the buffer, the audio out
callback empties it.
My problem is that when the user taps a button I call SndStreamStop()
and SndStreamDelete() on the two streams but nothing happens.
Sounds that go in the microphone continue to come out the headphones
and if I free the shared buffer I get a memory error. When I quit
and restart the simulator and try again, SndStreamCreate() fails with
an error code FFFF (as displayed by ErrAlert()). The only way to
get audio working is to reboot my desktop.
Anyone have any ideas what is going wrong? Relevant code is included
below.
Thanks,
Chris
Create and start the streams:
result = SndStreamCreate(
&(callbackDataP->recordStreamRef),
sndInput,
sampleRate,
sndInt16Little,
sampleWidth,
recordCallbackFunc,
callbackDataP,
REQUESTED_BUFFER_SIZE,
false);
result = SndStreamCreate(
&(callbackDataP->playStreamRef),
sndOutput,
sampleRate,
sndInt16Little,
sampleWidth,
playCallbackFunc,
callbackDataP,
REQUESTED_BUFFER_SIZE,
false);
result = SndStreamStart(callbackDataP->recordStreamRef);
result = SndStreamStart(callbackDataP->playStreamRef);
Here are the callbacks:
static Err recordCallbackFunc(void* UserDataP, SndStreamRef stream,
void* bufferP, UInt32 frameCount)
{
CallbackDataType *callbackDataP = UserDataP;
if(!callbackDataP->buffer) {
callbackDataP->bufferSize = frameCount * callbackDataP->frameWidth;
callbackDataP->buffer = MemPtrNew(callbackDataP->bufferSize);
}
ErrFatalDisplayIf(callbackDataP->bufferSize < callbackDataP->frameWidth *
frameCount,
"record callback was passed more data than it can handle");
MemMove(callbackDataP->buffer, bufferP, frameCount *
callbackDataP->frameWidth);
return errNone;
}
static Err playCallbackFunc(void* UserDataP, SndStreamRef stream,
void* bufferP, UInt32
frameCount)
{
CallbackDataType *callbackDataP = UserDataP;
ErrNonFatalDisplayIf(!callbackDataP->buffer,
"play callback was passed an unallocated shared buffer");
ErrFatalDisplayIf(callbackDataP->bufferSize > callbackDataP->frameWidth *
frameCount,
"play callback was passed more data than it can handle");
MemMove(bufferP, callbackDataP->buffer, frameCount *
callbackDataP->frameWidth);
return errNone;
}
Elsewhere, stop and delete the streams:
SndStreamStop(cdP->recordStreamRef);
SndStreamDelete(cdP->recordStreamRef);
SndStreamStop(cdP->playStreamRef);
SndStreamDelete(cdP->playStreamRef);
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/