Logo Search packages:      
Sourcecode: scummvm version File versions  Download package

int Agi::SoundGenPCJr::readBuffer ( int16 *  buffer,
const int  numSamples 
) [virtual]

Fill the given buffer with up to numSamples samples. Returns the actual number of samples read, or -1 if a critical error occurred (note: you *must* check if this value is less than what you requested, this can happen when the stream is fully used up).

Data has to be in native endianess, 16 bit per sample, signed. For stereo stream, buffer will be filled with interleaved left and right channel samples, starting with a left sample. Furthermore, the samples in the left and right are summed up. So if you request 4 samples from a stereo stream, you will get a total of two left channel and two right channel samples.

Implements Audio::AudioStream.

Definition at line 479 of file sound_pcjr.cpp.

                                                         {
      int streamCount;
      int16 *sPtr, *cPtr;

      if (_chanAllocated < len) {
            free(_chanData);
            _chanData = (int16 *)malloc(len << 1);
            _chanAllocated = len;
      }
      memset(stream, 0, len << 1);

      assert(stream);

      bool finished = true;

      for (int i = 0; i < CHAN_MAX; i++) {
            // get channel data(chan.userdata)
            if (chanGen(i, _chanData, len) == 0) {
                  // divide by number of channels then add to stream
                  streamCount = len;
                  sPtr = stream;
                  cPtr = _chanData;

                  while (streamCount--)
                        *(sPtr++) += *(cPtr++) / CHAN_MAX;

                  finished = false;
            }
      }

      if (finished)
            _vm->_sound->soundIsFinished();

      return len;
}

Generated by  Doxygen 1.6.0   Back to index