[Scummvm-devel] [Scummvm-cvs-logs] SF.net SVN: scummvm:[43161] scummvm/branches/gsoc2009-draci/engines/draci

Filippos Karapetis philipk79 at hotmail.com
Mon Aug 10 00:36:24 CEST 2009


> also, if you are willing to do it, I would like to kindly ask you to implement playing not only the current dubbing stored as uncompressed 8-bit 22kHz samples, but also dubbing stored in 
> some new Ogg-compressed format, and making the game support both and auto-detect which one is used.  if that is done, then we could release new game archive, much shorter than 
> the old one, with the same functionality.

Sorry to intervene here, I just wanted to say that this functionality should be very easy to do in ScummVM. We got classes which can handle MP3/OGG/FLAC encoded files, and the change needed is minimal (1-2 lines change). So theoretically, you could have some other extension for compressed sounds, and if the compressed file is found, play it with the appropriate class for compressed sound files.

An example code would be something like this (this is just something I quickly whipped up in a hurry, it needs refining):

Audio::AudioStream *audioStream = 0;
Audio::SoundHandle _sfxHandle;

if (playUncompressedAudio) {
  Common::File *audioFile = new Common::File("audio.xxx");  // TODO: proper audio file here
  int sampleOffset = 0; // TODO: set this properly
  int sampleSize = 0;   // TODO: set this properly
  byte *buffer = new byte[sampleSize];
  audioFile->seek(sampleOffset, SEEK_SET);
  audioFile->read(buffer, sampleSize);
  delete audioFile;  // this closes the file
  audioStream = Audio::makeLinearInputStream(buffer, sampleSize, 22050, Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED, 0, 0);
} else {
#ifdef USE_VORBIS
  Common::File *audioFile = new Common::File("audio.yyy");  // TODO: proper audio file here
  int sampleOffset = 0; // TODO: set this properly

  int sampleSize = 0;   // TODO: set this properly

  Common::SeekableSubReadStream *audioStream = new
Common::SeekableSubReadStream(audioFile, sampleOffset, sampleOffset +
sampleSize, true);
  audioStream = Audio::makeVorbisStream(musicStream, true, 0, 0, 1);
  // No need to delete the file here - it's done by makeVorbisStream once the sound is finished playing
#endif
}

_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, audioStream);


Note that with the code above, uncompressed sound is first loaded in a buffer, which is then freed by makeLinearInputStream when it finishes
playing (because of FLAG_AUTOFREE). The compressed sound is played directly from disk. If you wish to load it in memory, you can read it in a buffer
and load it in a MemoryReadStream. This discrepancy with compressed and uncompressed sound will hopefully be addressed with patch #2834001.
You can play MP3 and FLAC audio by swapping makeVorbisStream with makeMP3Stream and makeFlacStream - just make sure that these calls are
enclosed in the appropriate ifdef blocks (#ifdef USE_MAD and #ifdef USE_FLAC).

Regards
Filippos

_________________________________________________________________
Get your vacation photos on your phone!
http://windowsliveformobile.com/en-us/photos/default.aspx?&OCID=0809TL-HM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20090809/322ee028/attachment.html>


More information about the Scummvm-devel mailing list