I am trying to play a midi file i've downloaded by using SndStreamCreate.
I've stored the file in a database and have a pointer to the midi data.

I'm not sure what the original sample rate was for the sound file, but when i 
try to play the midi using the code below, i get nothing but a bit of a crackle.

Can anyone shed some light on how to play a midi file please..

I've used the following code.

typedef struct 
        {
                Boolean                 active;
                UInt8                   *currP;
                UInt8                   *endP;
        }AudioDataBlockType


static void PlayMidi(void)
{
Err             err;
SndStreamRef stream;

AudioDataBlockType dataBlock;

        dataBlock.currP = theMidiData; // pointer to the start of the midi data
        dataBlock.active = true;
        dataBlock.endP = endOfMidi; // pointer to the end of the midi data

      

        err = SndStreamCreate(&stream, sndOutput, 8000 /*Hz*/,
                        sndUInt8 /*8-bit signed*/, sndMono,
                        StreamCallback /*callback*/, &dataBlock /*callback 
data*/,
                        1024 /*requested block size*/, false /*not a PNO*/);
                        
       err = SndStreamStart (stream);

}

And i'm using the following call back function...

  static Err StreamCallback (void *userData, SndStreamRef stream, void *buffer, 
UInt32 frameCount)
  {
   AudioDataBlockType   *dataBlockP;
   UInt8                                *outP, sample;
   Int16                                fc;
   
   
        dataBlockP = (AudioDataBlockType *)userData;
        outP = (UInt8 *)buffer;

                if (!dataBlockP->active)
                {
                        MemSet(buffer, frameCount * sizeof(Int8), 0);
                        return errNone;
                }

                for (fc = (Int16)frameCount - 1; fc >= 0; fc--)
                {
                        sample = 0;

                        if (dataBlockP->active)
                        {
                                sample = *(dataBlockP->currP++);
                                if (dataBlockP->currP >= dataBlockP->endP)
                                {
                                        dataBlockP->active = false;
                                }
                        }
                        *(outP++) = sample;
                }

                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