[Scummvm-cvs-logs] CVS: scummvm/queen resource.cpp,1.21,1.22 resource.h,1.16,1.17 sound.cpp,1.5,1.6 sound.h,1.2,1.3
Joost Peters
joostp at users.sourceforge.net
Tue Oct 28 07:30:23 CET 2003
Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv1435/queen
Modified Files:
resource.cpp resource.h sound.cpp sound.h
Log Message:
add OGG playback to queen
Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- resource.cpp 28 Oct 2003 13:27:37 -0000 1.21
+++ resource.cpp 28 Oct 2003 15:26:05 -0000 1.22
@@ -276,7 +276,7 @@
}
}
-File *Resource::giveMP3(const char *filename) {
+File *Resource::giveCompressedSound(const char *filename) {
assert(strstr(filename, ".SB"));
_resourceFile->seek(fileOffset(filename), SEEK_SET);
return _resourceFile;
Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- resource.h 28 Oct 2003 12:42:35 -0000 1.16
+++ resource.h 28 Oct 2003 15:26:05 -0000 1.17
@@ -68,7 +68,8 @@
bool isFloppy();
uint8 compression() { return _compression; }
uint32 fileSize(const char *filename);
- File *giveMP3(const char *filename);
+ uint32 fileOffset(const char *filename);
+ File *giveCompressedSound(const char *filename);
Language getLanguage();
const char *JASVersion();
@@ -85,7 +86,6 @@
static ResourceEntry _resourceTablePEM10[];
int32 resourceIndex(const char *filename);
- uint32 fileOffset(const char *filename);
bool readTableFile();
void readTableCompResource();
static const GameVersion *detectGameVersion(uint32 dataFilesize);
Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/sound.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- sound.cpp 28 Oct 2003 12:42:35 -0000 1.5
+++ sound.cpp 28 Oct 2003 15:26:05 -0000 1.6
@@ -30,6 +30,69 @@
namespace Queen {
+#ifdef USE_VORBIS
+// These are wrapper functions to allow using a File object to
+// provide data to the OggVorbis_File object.
+
+struct file_info {
+ File *file;
+ int start, curr_pos;
+ size_t len;
+};
+
+static size_t read_wrap(void *ptr, size_t size, size_t nmemb, void *datasource) {
+ file_info *f = (file_info *) datasource;
+ int result;
+
+ nmemb *= size;
+ if (f->curr_pos > (int) f->len)
+ nmemb = 0;
+ else if (nmemb > f->len - f->curr_pos)
+ nmemb = f->len - f->curr_pos;
+ result = f->file->read(ptr, nmemb);
+ if (result == -1) {
+ f->curr_pos = f->file->pos() - f->start;
+ return (size_t) -1;
+ } else {
+ f->curr_pos += result;
+ return result / size;
+ }
+}
+
+static int seek_wrap(void *datasource, ogg_int64_t offset, int whence) {
+ file_info *f = (file_info *) datasource;
+
+ if (whence == SEEK_SET)
+ offset += f->start;
+ else if (whence == SEEK_END) {
+ offset += f->start + f->len;
+ whence = SEEK_SET;
+ }
+
+ f->file->seek(offset, whence);
+ f->curr_pos = f->file->pos() - f->start;
+ return f->curr_pos;
+}
+
+static int close_wrap(void *datasource) {
+ file_info *f = (file_info *) datasource;
+
+ f->file->close();
+ delete f;
+ return 0;
+}
+
+static long tell_wrap(void *datasource) {
+ file_info *f = (file_info *) datasource;
+
+ return f->curr_pos;
+}
+
+static ov_callbacks g_File_wrap = {
+ read_wrap, seek_wrap, close_wrap, tell_wrap
+};
+#endif
+
Sound::Sound(SoundMixer *mixer, Input *input, Resource *resource) :
_mixer(mixer), _input(input), _resource(resource), _sfxHandle(0) {
}
@@ -51,6 +114,13 @@
#endif
break;
+ case COMPRESSION_OGG:
+ #ifndef USE_VORBIS
+ warning("Using OGG compressed datafile, but OGG support not compiled in");
+ #else
+ return new OGGSound(mixer, input, resource);
+ #endif
+ break;
default:
warning("Unknown compression type");
return new SilentSound(mixer, input, resource);
@@ -98,7 +168,39 @@
_input->delay(10);
if (_resource->exists(name))
- _mixer->playMP3(&_sfxHandle, _resource->giveMP3(name), _resource->fileSize(name));
+ _mixer->playMP3(&_sfxHandle, _resource->giveCompressedSound(name), _resource->fileSize(name));
+}
+#endif
+
+#ifdef USE_VORBIS
+void OGGSound::sfxPlay(const char *base) {
+ char name[13];
+ strcpy(name, base);
+ //alter filename to add zeros and append ".SB"
+ for (int i = 0; i < 8; i++) {
+ if (name[i] == ' ')
+ name[i] = '0';
+ }
+ strcat(name, ".SB");
+
+ while(isPlaying())
+ _input->delay(10);
+
+ if (_resource->exists(name)) {
+ OggVorbis_File *oggFile = new OggVorbis_File;
+ file_info *f = new file_info;
+
+ f->file = _resource->giveCompressedSound(name);
+ f->start = _resource->fileOffset(name);
+ f->len = _resource->fileSize(name);
+ f->curr_pos = 0;
+
+ if (ov_open_callbacks((void *)f, oggFile, NULL, 0, g_File_wrap) < 0) {
+ delete oggFile;
+ delete f;
+ } else
+ _mixer->playVorbis(&_sfxHandle, oggFile, 0, false);
+ }
}
#endif
Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/sound.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sound.h 23 Oct 2003 06:44:35 -0000 1.2
+++ sound.h 28 Oct 2003 15:26:05 -0000 1.3
@@ -41,7 +41,7 @@
protected:
SoundMixer *_mixer;
- Input *_input;
+ Input *_input;
Resource *_resource;
PlayingSoundHandle _sfxHandle;
@@ -56,8 +56,9 @@
class SBSound : public Sound {
public:
SBSound(SoundMixer *mixer, Input *input, Resource *resource) : Sound(mixer, input, resource) {};
- int playSound(byte *sound, uint32 size);
void sfxPlay(const char *base);
+protected:
+ int playSound(byte *sound, uint32 size);
};
#ifdef USE_MAD
@@ -68,6 +69,13 @@
};
#endif
+#ifdef USE_VORBIS
+class OGGSound : public Sound {
+public:
+ OGGSound(SoundMixer *mixer, Input *input, Resource *resource) : Sound(mixer, input, resource) {};
+ void sfxPlay(const char *base);
+};
+#endif
} // End of namespace Queen
#endif
More information about the Scummvm-git-logs
mailing list