+ // !!! FIXME: if it's not Ogg, we don't have a decoder. I'm lazy. :/
+ char *fname = (char *) alloca(strlen(_fname) + 16);
+ strcpy(fname, _fname);
+ char *ptr = strchr(fname, '.');
+ if (ptr) *ptr = NULL;
+ strcat(fname, ".ogg");
+
+ // just in case...
+ #undef fopen
+ FILE *io = fopen(fname, "rb");
+ if (io == NULL)
+ return NULL;
+
+ ALubyte *retval = NULL;
+
+ #if 0 // untested, so disable this!
+ // Can we just feed it to the AL compressed?
+ if (alIsExtensionPresent((const ALubyte *) "AL_EXT_vorbis"))
+ {
+ format = alGetEnumValue((const ALubyte *) "AL_FORMAT_VORBIS_EXT");
+ freq = 44100;
+ fseek(io, 0, SEEK_END);
+ size = ftell(io);
+ fseek(io, 0, SEEK_SET);
+ retval = (ALubyte *) malloc(size);
+ size_t rc = fread(retval, size, 1, io);
+ fclose(io);
+ if (rc != 1)
+ {
+ free(retval);
+ return NULL;
+ }
+ return retval;
+ }
+ #endif
+
+ // Uncompress and feed to the AL.
+ OggVorbis_File vf;
+ memset(&vf, '\0', sizeof (vf));
+ if (ov_open(io, &vf, NULL, 0) == 0)
+ {
+ int bitstream = 0;
+ vorbis_info *info = ov_info(&vf, -1);
+ size = 0;
+ format = (info->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
+ freq = info->rate;
+
+ if ((info->channels != 1) && (info->channels != 2))
+ {
+ ov_clear(&vf);
+ return NULL;
+ }
+
+ char buf[1024 * 16];
+ long rc = 0;
+ size_t allocated = 64 * 1024;
+ retval = (ALubyte *) malloc(allocated);
+ while ( (rc = ov_read(&vf, buf, sizeof (buf), 0, 2, 1, &bitstream)) != 0 )
+ {
+ if (rc > 0)
+ {
+ size += rc;
+ if (size >= allocated)
+ {
+ allocated *= 2;
+ ALubyte *tmp = (ALubyte *) realloc(retval, allocated);
+ if (tmp == NULL)
+ {
+ free(retval);
+ retval = NULL;
+ break;
+ }
+ retval = tmp;
+ }
+ memcpy(retval + (size - rc), buf, rc);
+ }
+ }
+ ov_clear(&vf);
+ return retval;
+ }
+
+ fclose(io);
+ return NULL;