aboutsummaryrefslogtreecommitdiff
path: root/Source/Support.cpp
diff options
context:
space:
mode:
authorrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-19 05:23:56 +0000
committerrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-19 05:23:56 +0000
commitd351dbc60b4a7ed4b5fea08c652c0cb4fc228661 (patch)
tree3f9fe168a914e1832aa9c57d5a705f4689b2ff7e /Source/Support.cpp
parent866995794baaa2a5f0f58662f2b4cccae9685de2 (diff)
downloadblackshades-d351dbc60b4a7ed4b5fea08c652c0cb4fc228661.tar.gz
added explicit ogg vorbis decoding
git-svn-id: svn://svn.icculus.org/blackshades/trunk@91 5198baeb-e213-0410-be47-fc2ff85ca46f
Diffstat (limited to 'Source/Support.cpp')
-rw-r--r--Source/Support.cpp101
1 files changed, 94 insertions, 7 deletions
diff --git a/Source/Support.cpp b/Source/Support.cpp
index f1cffdf..c48d1b3 100644
--- a/Source/Support.cpp
+++ b/Source/Support.cpp
@@ -250,7 +250,7 @@ void Files::EndLoad()
void alutLoadWAVFile_CFH(char *filename, ALenum *format, void **wave,
unsigned int *size, ALsizei *freq)
{
- char filename1[256];
+ char filename1[MAX_PATH];
ALsizei format1, size1, bits1, freq1;
fix_filename(filename, filename1);
@@ -268,25 +268,112 @@ void alutUnloadWAV_CFH(ALenum format, void *wave, unsigned int size,
free(wave);
}
#else
-void alutLoadVorbis_LOKI_CFH(char *filename, ALenum *format, void **wave,
+#include <vorbis/vorbisfile.h>
+/*
+Read the requested OGG file into memory, and extract the information required
+by OpenAL
+*/
+void LoadOGG_CFH(char *filename, ALenum *format, void **wave,
unsigned int *size, ALsizei *freq)
{
- char filename1[256];
- ALsizei format1, size1, bits1, freq1;
+ char filename1[MAX_PATH];
+ ALsizei format1, size1, freq1;
+ void *wave1;
+ OggVorbis_File vf;
+ vorbis_info *vi;
+ FILE *fp;
+ int current_section;
+ char *buf;
+ int asize;
+ int err;
+ int eof;
+ /* try to find the real file (and place it in filename1) */
fix_filename(filename, filename1);
+
+ /* open it for reading */
+ fp = fopen(filename1, "rb");
+ if (fp == NULL) {
+ fprintf(stderr, "ERROR: unable to open %s\n", filename1);
+ exit(EXIT_FAILURE);
+ }
- alutLoadWAV(filename1, wave, &format1, &size1, &bits1, &freq1);
+ /* open it up */
+ err = ov_open(fp, &vf, NULL, 0);
+ if (err < 0) {
+ fprintf(stderr, "ERROR: vorbis error %d opening %s\n", -err, filename1);
+ exit(EXIT_FAILURE);
+ }
+
+ /* get the ogg information */
+ vi = ov_info(&vf, -1);
+ if (vi == NULL) {
+ fprintf(stderr, "ERROR: vorbis error opening %s (ov_info failed)\n", filename1);
+ exit(EXIT_FAILURE);
+ }
+ /* calculate the byte size */
+ size1 = vi->channels * 2 * ov_pcm_total(&vf, -1);
+
+ /* hack around some possible ogg vorbis weirdness */
+ asize = ((size1 + 2047) / 2048 + 1) * 2048;
+
+ /* allocate our buffer */
+ wave1 = malloc(asize);
+
+ if (wave1 == NULL) {
+ fprintf(stderr, "ERROR: could not allocate %d bytes while loading %s\n", size1, filename1);
+ exit(EXIT_FAILURE);
+ }
+
+ /* read it in */
+ eof = 0;
+ buf = (char *)wave1;
+
+ while(!eof) {
+ long ret = ov_read(&vf, buf, 1024, 0, 2, 1, &current_section);
+
+ if (ret == 0) {
+ /* end of file */
+ eof = 1;
+ } else if (ret < 0) {
+ /* some sort of error */
+
+ /* TODO: is this ok to ignore? */
+ } else {
+ buf += ret;
+ }
+ }
+
+ /* get the rest of the information */
+ if (vi->channels == 1) {
+ format1 = AL_FORMAT_MONO16;
+ } else if (vi->channels == 2) {
+ format1 = AL_FORMAT_STEREO16;
+ } else {
+ fprintf(stderr, "ERROR: ogg %s has %d channels\n", filename1, vi->channels);
+ exit(EXIT_FAILURE);
+ }
+
+ freq1 = vi->rate;
+
+ /* we are done with the ogg, so free it */
+ ov_clear(&vf);
+
+ /* finall, give the values to the caller */
*format = format1;
*size = size1;
*freq = freq1;
+ *wave = wave1;
}
-/*void alutUnloadVorbis_CFH(ALenum format, void *wave, unsigned int size,
+/*
+Free the OGG buffer
+*/
+void FreeOGG(ALenum format, void *wave, unsigned int size,
ALsizei freq)
{
free(wave);
-} */
+}
#endif