2009-07-27 05:47:50 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
See the GNU General Public License for more details.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OggVorbis source support for MultiVoc
|
|
|
|
*/
|
|
|
|
|
2017-02-25 08:15:36 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
#include "pitch.h"
|
|
|
|
#include "multivoc.h"
|
|
|
|
#include "_multivc.h"
|
|
|
|
|
2012-12-29 10:57:24 +00:00
|
|
|
#define OV_EXCLUDE_STATIC_CALLBACKS
|
|
|
|
|
2013-02-18 08:50:42 +00:00
|
|
|
#if defined __APPLE__
|
2012-12-29 10:57:24 +00:00
|
|
|
# include <vorbis/vorbisfile.h>
|
2013-02-18 08:50:42 +00:00
|
|
|
#elif defined GEKKO
|
|
|
|
# define USING_TREMOR
|
|
|
|
# include <tremor/ivorbisfile.h>
|
2012-12-29 10:57:24 +00:00
|
|
|
#else
|
|
|
|
# include "vorbis/vorbisfile.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
#define BLOCKSIZE 0x8000
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
typedef struct {
|
|
|
|
void * ptr;
|
|
|
|
size_t length;
|
|
|
|
size_t pos;
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
OggVorbis_File vf;
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
char block[BLOCKSIZE];
|
2009-07-27 05:47:50 +00:00
|
|
|
int32_t lastbitstream;
|
|
|
|
} vorbis_data;
|
|
|
|
|
2012-12-29 10:57:24 +00:00
|
|
|
// designed with multiple calls in mind
|
|
|
|
static void MV_GetVorbisCommentLoops(VoiceNode *voice, vorbis_comment *vc)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
if (vc == NULL)
|
|
|
|
return;
|
2012-12-29 10:57:24 +00:00
|
|
|
|
2013-02-18 08:50:42 +00:00
|
|
|
const char *vc_loopstart = NULL;
|
|
|
|
const char *vc_loopend = NULL;
|
|
|
|
const char *vc_looplength = NULL;
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
for (int comment = 0; comment < vc->comments; ++comment)
|
2012-12-29 10:57:24 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
const char *entry = (const char *)vc->user_comments[comment];
|
2013-02-18 08:50:42 +00:00
|
|
|
if (entry != NULL && entry[0] != '\0')
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
const char *value = strchr(entry, '=');
|
2015-06-04 00:03:55 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (!value)
|
|
|
|
continue;
|
2015-06-04 00:03:55 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
const size_t field = value - entry;
|
2013-02-18 08:50:42 +00:00
|
|
|
value += 1;
|
|
|
|
|
2016-10-14 07:40:59 +00:00
|
|
|
for (size_t t = 0; t < loopStartTagCount && vc_loopstart == NULL; ++t)
|
|
|
|
{
|
|
|
|
char const * const tag = loopStartTags[t];
|
2017-02-25 08:15:45 +00:00
|
|
|
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
|
2013-02-18 08:50:42 +00:00
|
|
|
vc_loopstart = value;
|
2016-10-14 07:40:59 +00:00
|
|
|
}
|
2013-02-18 08:50:42 +00:00
|
|
|
|
2016-10-14 07:40:59 +00:00
|
|
|
for (size_t t = 0; t < loopEndTagCount && vc_loopend == NULL; ++t)
|
|
|
|
{
|
|
|
|
char const * const tag = loopEndTags[t];
|
2017-02-25 08:15:45 +00:00
|
|
|
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
|
2013-02-18 08:50:42 +00:00
|
|
|
vc_loopend = value;
|
2016-10-14 07:40:59 +00:00
|
|
|
}
|
2012-12-29 10:57:24 +00:00
|
|
|
|
2016-10-14 07:40:59 +00:00
|
|
|
for (size_t t = 0; t < loopLengthTagCount && vc_looplength == NULL; ++t)
|
|
|
|
{
|
|
|
|
char const * const tag = loopLengthTags[t];
|
2017-02-25 08:15:45 +00:00
|
|
|
if (field == strlen(tag) && Bstrncasecmp(entry, tag, field) == 0)
|
2013-02-18 08:50:42 +00:00
|
|
|
vc_looplength = value;
|
2016-10-14 07:40:59 +00:00
|
|
|
}
|
2013-02-18 08:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-29 10:57:24 +00:00
|
|
|
|
2013-02-18 08:50:42 +00:00
|
|
|
if (vc_loopstart != NULL)
|
|
|
|
{
|
2012-12-29 10:57:24 +00:00
|
|
|
{
|
|
|
|
const ogg_int64_t ov_loopstart = atol(vc_loopstart);
|
|
|
|
if (ov_loopstart >= 0) // a loop starting at 0 is valid
|
|
|
|
{
|
|
|
|
voice->LoopStart = (const char *) (intptr_t) ov_loopstart;
|
|
|
|
voice->LoopSize = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 08:50:42 +00:00
|
|
|
if (vc_loopend != NULL)
|
2012-12-29 10:57:24 +00:00
|
|
|
{
|
2013-02-18 08:50:42 +00:00
|
|
|
if (voice->LoopSize > 0)
|
2012-12-29 10:57:24 +00:00
|
|
|
{
|
2013-02-18 08:50:42 +00:00
|
|
|
const ogg_int64_t ov_loopend = atol(vc_loopend);
|
|
|
|
if (ov_loopend > 0) // a loop ending at 0 is invalid
|
|
|
|
voice->LoopEnd = (const char *) (intptr_t) ov_loopend;
|
2012-12-29 10:57:24 +00:00
|
|
|
}
|
2013-02-18 08:50:42 +00:00
|
|
|
}
|
|
|
|
if (vc_looplength != NULL)
|
|
|
|
{
|
|
|
|
if (voice->LoopSize > 0 && voice->LoopEnd == 0)
|
2012-12-29 10:57:24 +00:00
|
|
|
{
|
2013-02-18 08:50:42 +00:00
|
|
|
const ogg_int64_t ov_looplength = atol(vc_looplength);
|
|
|
|
if (ov_looplength > 0) // a loop of length 0 is invalid
|
|
|
|
voice->LoopEnd = (const char *) ((intptr_t) ov_looplength + (intptr_t) voice->LoopStart);
|
2012-12-29 10:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// callbacks
|
2009-10-03 14:34:05 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
static size_t read_vorbis(void *ptr, size_t size, size_t nmemb, void *datasource)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_data *vorb = (vorbis_data *)datasource;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
if (vorb->length == vorb->pos)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size_t nread = 0;
|
|
|
|
|
|
|
|
for (; nmemb > 0; nmemb--, nread++)
|
|
|
|
{
|
|
|
|
size_t bytes = vorb->length - vorb->pos;
|
|
|
|
|
|
|
|
if (size < bytes)
|
|
|
|
bytes = size;
|
|
|
|
|
|
|
|
memcpy(ptr, (uint8_t *)vorb->ptr + vorb->pos, bytes);
|
|
|
|
vorb->pos += bytes;
|
|
|
|
ptr = (uint8_t *)ptr + bytes;
|
|
|
|
|
|
|
|
if (vorb->length == vorb->pos)
|
|
|
|
{
|
|
|
|
nread++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nread;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
|
2017-01-01 13:23:35 +00:00
|
|
|
static int seek_vorbis(void *datasource, ogg_int64_t offset, int whence)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_data *vorb = (vorbis_data *)datasource;
|
2009-10-03 14:34:05 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET: vorb->pos = 0; break;
|
|
|
|
case SEEK_CUR: break;
|
|
|
|
case SEEK_END: vorb->pos = vorb->length; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
vorb->pos += offset;
|
|
|
|
|
|
|
|
if (vorb->pos > vorb->length)
|
|
|
|
vorb->pos = vorb->length;
|
|
|
|
|
|
|
|
return vorb->pos;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 13:23:35 +00:00
|
|
|
static int close_vorbis(void *datasource)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
UNREFERENCED_PARAMETER(datasource);
|
2015-07-08 03:33:56 +00:00
|
|
|
return 0;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
static long tell_vorbis(void *datasource)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_data *vorb = (vorbis_data *)datasource;
|
|
|
|
|
|
|
|
return vorb->pos;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
static ov_callbacks vorbis_callbacks = { read_vorbis, seek_vorbis, close_vorbis, tell_vorbis };
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
|
2015-01-17 00:28:49 +00:00
|
|
|
int32_t MV_GetVorbisPosition(VoiceNode *voice)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_data * vd = (vorbis_data *) voice->rawdataptr;
|
2015-01-17 00:28:49 +00:00
|
|
|
|
|
|
|
return ov_pcm_tell(&vd->vf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MV_SetVorbisPosition(VoiceNode *voice, int32_t position)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_data * vd = (vorbis_data *) voice->rawdataptr;
|
2015-01-17 00:28:49 +00:00
|
|
|
|
|
|
|
ov_pcm_seek(&vd->vf, position);
|
|
|
|
}
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetNextVorbisBlock
|
|
|
|
|
|
|
|
Controls playback of OggVorbis data
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
static playbackstatus MV_GetNextVorbisBlock(VoiceNode *voice)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2017-01-01 13:23:35 +00:00
|
|
|
int bitstream;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
voice->Playing = TRUE;
|
|
|
|
|
|
|
|
int32_t bytesread = 0;
|
|
|
|
vorbis_data *vd = (vorbis_data *)voice->rawdataptr;
|
|
|
|
do
|
|
|
|
{
|
2013-02-18 08:50:42 +00:00
|
|
|
#ifdef USING_TREMOR
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t bytes = ov_read(&vd->vf, vd->block + bytesread, BLOCKSIZE - bytesread, &bitstream);
|
2013-02-18 08:50:42 +00:00
|
|
|
#else
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t bytes = ov_read(&vd->vf, vd->block + bytesread, BLOCKSIZE - bytesread, 0, 2, 1, &bitstream);
|
2013-02-18 08:50:42 +00:00
|
|
|
#endif
|
2015-07-08 03:33:56 +00:00
|
|
|
// fprintf(stderr, "ov_read = %d\n", bytes);
|
|
|
|
if (bytes > 0)
|
|
|
|
{
|
|
|
|
ogg_int64_t currentPosition;
|
|
|
|
bytesread += bytes;
|
|
|
|
if ((ogg_int64_t)(intptr_t)voice->LoopEnd > 0 &&
|
|
|
|
(currentPosition = ov_pcm_tell(&vd->vf)) >= (ogg_int64_t)(intptr_t)voice->LoopEnd)
|
|
|
|
{
|
|
|
|
bytesread -=
|
|
|
|
(currentPosition - (ogg_int64_t)(intptr_t)voice->LoopEnd) * voice->channels * 2; // (voice->bits>>3)
|
|
|
|
|
|
|
|
int const err = ov_pcm_seek(&vd->vf, (ogg_int64_t)(intptr_t)voice->LoopStart);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
MV_Printf("MV_GetNextVorbisBlock ov_pcm_seek: LOOP_START %l, LOOP_END %l, err %d\n",
|
|
|
|
(ogg_int64_t)(intptr_t)voice->LoopStart, (ogg_int64_t)(intptr_t)voice->LoopEnd, err);
|
|
|
|
}
|
|
|
|
}
|
2012-11-24 09:12:15 +00:00
|
|
|
continue;
|
2015-07-08 03:33:56 +00:00
|
|
|
}
|
|
|
|
else if (bytes == OV_HOLE)
|
|
|
|
continue;
|
|
|
|
else if (bytes == 0)
|
|
|
|
{
|
|
|
|
if (voice->LoopSize > 0)
|
|
|
|
{
|
|
|
|
int const err = ov_pcm_seek(&vd->vf, (ogg_int64_t)(intptr_t)voice->LoopStart);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
MV_Printf("MV_GetNextVorbisBlock ov_pcm_seek: LOOP_START %l, err %d\n",
|
|
|
|
(ogg_int64_t)(intptr_t)voice->LoopStart, err);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bytes < 0)
|
|
|
|
{
|
|
|
|
MV_Printf("MV_GetNextVorbisBlock ov_read: err %d\n", bytes);
|
|
|
|
voice->Playing = FALSE;
|
|
|
|
return NoMoreData;
|
|
|
|
}
|
|
|
|
} while (bytesread < BLOCKSIZE);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (bytesread == 0)
|
|
|
|
{
|
|
|
|
voice->Playing = FALSE;
|
|
|
|
return NoMoreData;
|
|
|
|
}
|
2013-02-18 08:50:42 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (bitstream != vd->lastbitstream)
|
2013-02-18 08:50:42 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
vorbis_info *vi = 0;
|
|
|
|
|
|
|
|
vi = ov_info(&vd->vf, -1);
|
|
|
|
if (!vi || (vi->channels != 1 && vi->channels != 2))
|
|
|
|
{
|
|
|
|
voice->Playing = FALSE;
|
|
|
|
return NoMoreData;
|
|
|
|
}
|
|
|
|
|
|
|
|
voice->channels = vi->channels;
|
|
|
|
voice->SamplingRate = vi->rate;
|
|
|
|
voice->RateScale = (voice->SamplingRate * voice->PitchScale) / MV_MixRate;
|
|
|
|
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) - voice->RateScale;
|
|
|
|
MV_SetVoiceMixMode(voice);
|
|
|
|
vd->lastbitstream = bitstream;
|
2013-02-18 08:50:42 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
bytesread /= 2 * voice->channels;
|
|
|
|
|
|
|
|
voice->position = 0;
|
|
|
|
voice->sound = vd->block;
|
|
|
|
voice->BlockLength = 0;
|
|
|
|
voice->length = bytesread << 16; // ???: Should the literal 16 be voice->bits?
|
|
|
|
|
|
|
|
#ifdef GEKKO
|
|
|
|
// If libtremor had the three additional ov_read() parameters that libvorbis has,
|
|
|
|
// this would be better handled using the endianness parameter.
|
2016-01-12 10:30:48 +00:00
|
|
|
int16_t *data = (int16_t *)(vd->block); // assumes signed 16-bit
|
2015-07-08 03:33:56 +00:00
|
|
|
for (bytesread = 0; bytesread < BLOCKSIZE / 2; ++bytesread)
|
|
|
|
data[bytesread] = (data[bytesread] & 0xff) << 8 | ((data[bytesread] & 0xff00) >> 8);
|
2013-02-18 08:50:42 +00:00
|
|
|
#endif
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
return KeepPlaying;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_PlayVorbis3D
|
|
|
|
|
|
|
|
Begin playback of sound data at specified angle and distance
|
|
|
|
from listener.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t MV_PlayVorbis3D(char *ptr, uint32_t ptrlength, int32_t loophow, int32_t pitchoffset, int32_t angle,
|
|
|
|
int32_t distance, int32_t priority, uint32_t callbackval)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
|
|
|
return MV_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distance < 0)
|
|
|
|
{
|
|
|
|
distance = -distance;
|
|
|
|
angle += MV_NUMPANPOSITIONS / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int const volume = MIX_VOLUME(distance);
|
|
|
|
|
|
|
|
// Ensure angle is within 0 - 127
|
|
|
|
angle &= MV_MAXPANPOSITION;
|
|
|
|
|
|
|
|
return MV_PlayVorbis(ptr, ptrlength, loophow, -1, pitchoffset, max(0, 255 - distance),
|
|
|
|
MV_PanTable[angle][volume].left, MV_PanTable[angle][volume].right, priority, callbackval);
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_PlayVorbis
|
|
|
|
|
|
|
|
Begin playback of sound data with the given sound levels and
|
|
|
|
priority.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t MV_PlayVorbis(char *ptr, uint32_t ptrlength, int32_t loopstart, int32_t loopend, int32_t pitchoffset,
|
|
|
|
int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2012-12-29 10:58:09 +00:00
|
|
|
UNREFERENCED_PARAMETER(loopend);
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (!MV_Installed)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
vorbis_data *vd = (vorbis_data *)calloc(1, sizeof(vorbis_data));
|
|
|
|
|
|
|
|
if (!vd)
|
|
|
|
{
|
2016-08-27 01:39:38 +00:00
|
|
|
MV_SetErrorCode(MV_InvalidFile);
|
2015-07-08 03:33:56 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
vd->ptr = ptr;
|
|
|
|
vd->pos = 0;
|
|
|
|
vd->length = ptrlength;
|
|
|
|
vd->lastbitstream = -1;
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
int32_t status = ov_open_callbacks((void *)vd, &vd->vf, 0, 0, vorbis_callbacks);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
MV_Printf("MV_PlayVorbis: err %d\n", status);
|
2016-08-27 01:39:38 +00:00
|
|
|
MV_SetErrorCode(MV_InvalidFile);
|
2015-07-08 03:33:56 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
vorbis_info *vi = ov_info(&vd->vf, 0);
|
|
|
|
|
|
|
|
if (!vi)
|
|
|
|
{
|
|
|
|
ov_clear(&vd->vf);
|
|
|
|
free(vd);
|
2016-08-27 01:39:38 +00:00
|
|
|
MV_SetErrorCode(MV_InvalidFile);
|
2015-07-08 03:33:56 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
if (vi->channels != 1 && vi->channels != 2)
|
|
|
|
{
|
|
|
|
ov_clear(&vd->vf);
|
|
|
|
free(vd);
|
2016-08-27 01:39:38 +00:00
|
|
|
MV_SetErrorCode(MV_InvalidFile);
|
2015-07-08 03:33:56 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
// Request a voice from the voice pool
|
2015-07-08 03:33:56 +00:00
|
|
|
VoiceNode *voice = MV_AllocVoice(priority);
|
|
|
|
|
|
|
|
if (voice == NULL)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
ov_clear(&vd->vf);
|
|
|
|
free(vd);
|
|
|
|
MV_SetErrorCode(MV_NoVoices);
|
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
voice->wavetype = FMT_VORBIS;
|
2009-07-27 05:47:50 +00:00
|
|
|
voice->bits = 16;
|
|
|
|
voice->channels = vi->channels;
|
2015-07-08 03:33:56 +00:00
|
|
|
voice->rawdataptr = (void *) vd;
|
2009-07-27 05:47:50 +00:00
|
|
|
voice->GetSound = MV_GetNextVorbisBlock;
|
|
|
|
voice->NextBlock = vd->block;
|
|
|
|
voice->LoopCount = 0;
|
|
|
|
voice->BlockLength = 0;
|
|
|
|
voice->length = 0;
|
|
|
|
voice->next = NULL;
|
|
|
|
voice->prev = NULL;
|
|
|
|
voice->priority = priority;
|
|
|
|
voice->callbackval = callbackval;
|
2012-11-24 09:12:15 +00:00
|
|
|
|
2012-12-29 10:58:09 +00:00
|
|
|
voice->LoopStart = 0;
|
|
|
|
voice->LoopEnd = 0;
|
2012-11-24 09:12:15 +00:00
|
|
|
voice->LoopSize = (loopstart >= 0 ? 1 : 0);
|
|
|
|
|
|
|
|
// load loop tags from metadata
|
2012-12-29 10:58:09 +00:00
|
|
|
MV_GetVorbisCommentLoops(voice, ov_comment(&vd->vf, 0));
|
2012-11-24 09:12:15 +00:00
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
voice->Playing = TRUE;
|
|
|
|
voice->Paused = FALSE;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
MV_SetVoicePitch(voice, vi->rate, pitchoffset);
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_SetVoiceMixMode( voice );
|
|
|
|
|
|
|
|
MV_SetVoiceVolume( voice, vol, left, right );
|
|
|
|
MV_PlayVoice( voice );
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return voice->handle;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MV_ReleaseVorbisVoice( VoiceNode * voice )
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
if (voice->wavetype != FMT_VORBIS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vorbis_data *vd = (vorbis_data *)voice->rawdataptr;
|
|
|
|
|
|
|
|
ov_clear(&vd->vf);
|
|
|
|
free(vd);
|
|
|
|
|
|
|
|
voice->rawdataptr = 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-07-08 03:34:09 +00:00
|
|
|
#include "_multivc.h"
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t MV_PlayVorbis(char *ptr, uint32_t ptrlength, int32_t loopstart, int32_t loopend, int32_t pitchoffset,
|
|
|
|
int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval)
|
|
|
|
{
|
2016-01-12 10:31:05 +00:00
|
|
|
UNREFERENCED_PARAMETER(ptr);
|
|
|
|
UNREFERENCED_PARAMETER(ptrlength);
|
|
|
|
UNREFERENCED_PARAMETER(loopstart);
|
|
|
|
UNREFERENCED_PARAMETER(loopend);
|
|
|
|
UNREFERENCED_PARAMETER(pitchoffset);
|
|
|
|
UNREFERENCED_PARAMETER(vol);
|
|
|
|
UNREFERENCED_PARAMETER(left);
|
|
|
|
UNREFERENCED_PARAMETER(right);
|
|
|
|
UNREFERENCED_PARAMETER(priority);
|
|
|
|
UNREFERENCED_PARAMETER(callbackval);
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
MV_Printf("MV_PlayVorbis: OggVorbis support not included in this binary.\n");
|
|
|
|
return -1;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int32_t MV_PlayVorbis3D(char *ptr, uint32_t ptrlength, int32_t loophow, int32_t pitchoffset, int32_t angle,
|
|
|
|
int32_t distance, int32_t priority, uint32_t callbackval)
|
|
|
|
{
|
2016-01-12 10:31:05 +00:00
|
|
|
UNREFERENCED_PARAMETER(ptr);
|
|
|
|
UNREFERENCED_PARAMETER(ptrlength);
|
|
|
|
UNREFERENCED_PARAMETER(loophow);
|
|
|
|
UNREFERENCED_PARAMETER(pitchoffset);
|
|
|
|
UNREFERENCED_PARAMETER(angle);
|
|
|
|
UNREFERENCED_PARAMETER(distance);
|
|
|
|
UNREFERENCED_PARAMETER(priority);
|
|
|
|
UNREFERENCED_PARAMETER(callbackval);
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
MV_Printf("MV_PlayVorbis: OggVorbis support not included in this binary.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-03 14:34:05 +00:00
|
|
|
#endif //HAVE_VORBIS
|