Beispiel #1
0
void SoundStream::loop(double volume) {
  int numQueued = 0;
  AL(alGetSourcei(source.getId(), AL_BUFFERS_QUEUED, &numQueued));
  if (numQueued == 0) { /*fill and queue initial buffers*/
    vector<char> data = readSoundData(*file, streamingBufferSize);
    AL(alBufferData(buffers[0], (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(),
        data.size(), info->rate));
    data = readSoundData(*file, streamingBufferSize);
    AL(alBufferData(buffers[1], (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(),
        data.size(), info->rate));
    AL(alSourceQueueBuffers(source.getId(), 2, buffers));
    AL(alSourcef(source.getId(), AL_GAIN, volume));
    AL(alSourcePlay(source.getId()));
    startedPlaying = true;
    //CHECK(isPlaying()); fails if I unplug/plug the speaker cable...?
  } else { /*refill processed buffers*/
    int numProcessed = 0;
    AL(alGetSourcei(source.getId(), AL_BUFFERS_PROCESSED, &numProcessed));
    while (numProcessed--) {
      vector<char> data = readSoundData(*file, streamingBufferSize);
      if (data.size() == 0)
        break;
      else {
        ALuint buffer = 0;
        AL(alSourceUnqueueBuffers(source.getId(), 1, &buffer));
        AL(alBufferData(buffer, (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(),
            data.size(), info->rate));
        AL(alSourceQueueBuffers(source.getId(), 1, &buffer));
      }
    }
  }
  sleep_for(milliseconds(10));
}
Beispiel #2
0
SoundBuffer::SoundBuffer(const FilePath& path) {
  OggVorbis_File file;
  CHECK(ov_fopen(path.getPath(), &file) == 0) << "Error opening audio file: " << path;
  vorbis_info* info = ov_info(&file, -1);
  ov_raw_seek(&file, 0);
  vector<char> buffer = readSoundData(file);
  OpenalId id;
  AL(alGenBuffers(1, &id));
  AL(alBufferData(id, (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.data(), buffer.size(),
      info->rate));
  bufferId = id;
  ov_clear(&file);
}
Beispiel #3
0
bool DXADecoder::loadStream(Common::SeekableReadStream *stream) {
	close();

	uint32 tag = stream->readUint32BE();

	if (tag != MKTAG('D','E','X','A')) {
		close();
		return false;
	}

	DXAVideoTrack *track = new DXAVideoTrack(stream);
	addTrack(track);

	readSoundData(stream);

	track->setFrameStartPos();
	return true;
}