I'm using SndStreamCreateExtended in my applications to play WAV audio. I haven't had any problems running them on my Tungsten T3 (Palm OS 5.2), but when I run them on the Palm OS 6 (Cobalt) Simulator, it crashes as soon as any sound is played. I've attached my callback routine below.

Does anybody have an idea why Cobalt crashes?

I've "solved" the problem temporarily by using SndPlayResource if it detects PalmOS 6, but isn't very good for audio that lasts for several seconds since you can't stop the playback after it has been started.

---------------------------------
A few clarifications for my code
---------------------------------
streamP->audioP->audioDataP is a locked pointer to a 'wave' resource located in a separate prc from the application. The resource is a Windows WAV file, mono, 8-bit, 11kHz, with a RIFF header.


streamP->audioP->streamStart is an offset to where the WAV data starts (points past the RIFF header).

streamP->streamStatus is an Enum set to streamActive when the routine should fill the buffer, and set to streamStop when the sound should stop. I call SndStreamDelete from a separate routine in the event loop once streamP->streamStatus==streamStop and TimGetTicks()>streamP->stopTime.


static Err FillExtendedAudioBuffer(void *userData, SndStreamRef stream, void *buffer, UInt32 *bufSize)
{
AudioStreamType *streamP;
UInt8 *wavBufP;
UInt8 *bufP;


  streamP = (AudioStreamType *)userData;
  bufP = (UInt8 *)buffer;
  wavBufP = (UInt8 *)(streamP->audioP->audioDataP);
        
  if (streamP->streamStatus != streamActive)
  {
    //fill buffer with silence
    *bufSize = streamP->lastBufferSize;
    MemSet(bufP, *bufSize, 128);

    return errNone;
  }

  wavBufP += streamP->streamOffset;
        
  if ((streamP->streamOffset + *bufSize) < streamP->audioP->streamEnd)
    streamP->streamOffset += *bufSize;
  else
  {
    *bufSize = streamP->audioP->streamEnd - streamP->streamOffset;

    if (streamP->audioP->loopAudio)
      streamP->streamOffset = streamP->audioP->streamStart;
    else
      streamP->streamStatus = streamStop;
  }
        
  streamP->bufferDuration=(*bufSize*1000 / streamP->audioP->sampleRate)
                       / (1000 / SysTicksPerSecond());
  streamP->lastBufferSize = *bufSize;
  streamP->stopTime = TimGetTicks() + streamP->bufferDuration;

  MemMove(bufP, wavBufP, *bufSize);
        
  return errNone;
}

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

Reply via email to