2012-12-29 10:59:21 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
|
2015-07-08 03:33:56 +00:00
|
|
|
Copyright (C) 2015 EDuke32 developers
|
|
|
|
Copyright (C) 2015 Voidpoint, LLC
|
2012-12-29 10:59:21 +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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
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.
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-07-08 03:33:56 +00:00
|
|
|
* Raw, WAV, and VOC source support for MultiVoc
|
2012-12-29 10:59:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-19 23:47:19 +00:00
|
|
|
#include "_multivc.h"
|
2017-02-25 08:15:36 +00:00
|
|
|
#include "compat.h"
|
2012-12-29 10:59:21 +00:00
|
|
|
#include "multivoc.h"
|
2019-10-19 23:47:19 +00:00
|
|
|
#include "pitch.h"
|
|
|
|
#include "pragmas.h"
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
static playbackstatus MV_GetNextWAVBlock(VoiceNode *voice)
|
|
|
|
{
|
2018-10-07 05:23:34 +00:00
|
|
|
if (voice->BlockLength == 0)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
2019-10-19 23:47:19 +00:00
|
|
|
if (voice->LoopStart == nullptr)
|
2012-12-29 10:59:21 +00:00
|
|
|
return NoMoreData;
|
|
|
|
|
|
|
|
voice->BlockLength = voice->LoopSize;
|
|
|
|
voice->NextBlock = voice->LoopStart;
|
|
|
|
voice->length = 0;
|
|
|
|
voice->position = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
voice->sound = voice->NextBlock;
|
|
|
|
voice->position -= voice->length;
|
2018-10-16 06:09:54 +00:00
|
|
|
voice->length = min(voice->BlockLength, 0x8000u);
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->NextBlock += voice->length * ((voice->channels * voice->bits) >> 3);
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->BlockLength -= voice->length;
|
|
|
|
voice->length <<= 16;
|
|
|
|
|
|
|
|
return KeepPlaying;
|
|
|
|
}
|
|
|
|
|
|
|
|
static playbackstatus MV_GetNextVOCBlock(VoiceNode *voice)
|
|
|
|
{
|
2018-10-16 06:09:54 +00:00
|
|
|
size_t blocklength = 0;
|
|
|
|
uint32_t samplespeed = 0; // XXX: compiler-happy on synthesis
|
|
|
|
uint32_t tc = 0;
|
|
|
|
unsigned BitsPerSample;
|
|
|
|
unsigned Channels;
|
|
|
|
unsigned Format;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
if (voice->BlockLength > 0)
|
|
|
|
{
|
|
|
|
voice->position -= voice->length;
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->sound += (voice->length >> 16) * ((voice->channels * voice->bits) >> 3);
|
2018-10-16 06:09:54 +00:00
|
|
|
voice->length = min(voice->BlockLength, 0x8000u);
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->BlockLength -= voice->length;
|
|
|
|
voice->length <<= 16;
|
|
|
|
return KeepPlaying;
|
|
|
|
}
|
|
|
|
|
2018-12-15 01:39:51 +00:00
|
|
|
auto ptr = (uint8_t const *)voice->NextBlock;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
voice->Paused = FALSE;
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int voicemode = 0;
|
|
|
|
int blocktype = 0;
|
|
|
|
int lastblocktype = 0;
|
|
|
|
int packtype = 0;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
int done = FALSE;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2019-10-19 23:47:19 +00:00
|
|
|
// Stop playing if we get a null pointer
|
|
|
|
if (ptr == nullptr)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
2018-10-25 23:33:04 +00:00
|
|
|
done = 2;
|
2012-12-29 10:59:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// terminator is not mandatory according to
|
|
|
|
// http://wiki.multimedia.cx/index.php?title=Creative_Voice
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if (ptr - (uint8_t *)voice->rawdataptr >= voice->ptrlength)
|
2012-12-29 10:59:21 +00:00
|
|
|
blocktype = 0; // fake a terminator
|
|
|
|
else
|
|
|
|
blocktype = *ptr;
|
|
|
|
|
|
|
|
if (blocktype != 0)
|
|
|
|
blocklength = ptr[1]|(ptr[2]<<8)|(ptr[3]<<16);
|
|
|
|
else
|
|
|
|
blocklength = 0;
|
|
|
|
// would need one byte pad at end of alloc'd region:
|
2017-02-19 22:15:56 +00:00
|
|
|
// blocklength = B_LITTLE32(*(uint32_t *)(ptr + 1)) & 0x00ffffff;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
ptr += 4;
|
|
|
|
|
|
|
|
switch (blocktype)
|
|
|
|
{
|
|
|
|
case 0 :
|
|
|
|
end_of_data:
|
|
|
|
// End of data
|
2019-10-19 23:47:19 +00:00
|
|
|
if ((voice->LoopStart == nullptr) ||
|
2012-12-29 10:59:21 +00:00
|
|
|
((intptr_t) voice->LoopStart >= ((intptr_t) ptr - 4)))
|
|
|
|
{
|
2018-10-25 23:33:04 +00:00
|
|
|
done = 2;
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
voice->NextBlock = voice->LoopStart;
|
|
|
|
voice->BlockLength = 0;
|
|
|
|
voice->position = 0;
|
|
|
|
return MV_GetNextVOCBlock(voice);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1 :
|
|
|
|
// Sound data block
|
|
|
|
voice->bits = 8;
|
|
|
|
voice->channels = voicemode + 1;
|
|
|
|
if (lastblocktype != 8)
|
|
|
|
{
|
|
|
|
tc = (uint32_t)*ptr << 8;
|
|
|
|
packtype = *(ptr + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr += 2;
|
|
|
|
blocklength -= 2;
|
|
|
|
|
|
|
|
samplespeed = 256000000L / (voice->channels * (65536 - tc));
|
|
|
|
|
|
|
|
// Skip packed or stereo data
|
|
|
|
if ((packtype != 0) || (voicemode != 0 && voicemode != 1))
|
|
|
|
ptr += blocklength;
|
|
|
|
else
|
|
|
|
done = TRUE;
|
2015-07-08 03:33:56 +00:00
|
|
|
|
|
|
|
if (ptr - (uint8_t *)voice->rawdataptr >= voice->ptrlength)
|
2012-12-29 10:59:21 +00:00
|
|
|
goto end_of_data;
|
|
|
|
|
|
|
|
voicemode = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 :
|
|
|
|
// Sound continuation block
|
|
|
|
samplespeed = voice->SamplingRate;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3 :
|
|
|
|
// Silence
|
|
|
|
case 4 :
|
|
|
|
// Marker
|
|
|
|
case 5 :
|
|
|
|
// ASCII string
|
2015-07-08 03:33:56 +00:00
|
|
|
// All not implemented.
|
2012-12-29 10:59:21 +00:00
|
|
|
ptr += blocklength;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6 :
|
|
|
|
// Repeat begin
|
2019-10-19 23:47:19 +00:00
|
|
|
if (voice->LoopEnd == nullptr)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
2017-02-19 22:15:56 +00:00
|
|
|
voice->LoopCount = B_LITTLE16(*(uint16_t const *)ptr);
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->LoopStart = (char *)((intptr_t) ptr + blocklength);
|
|
|
|
}
|
|
|
|
ptr += blocklength;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7 :
|
|
|
|
// Repeat end
|
|
|
|
ptr += blocklength;
|
|
|
|
if (lastblocktype == 6)
|
|
|
|
voice->LoopCount = 0;
|
|
|
|
else
|
|
|
|
{
|
2019-10-19 23:47:19 +00:00
|
|
|
if ((voice->LoopCount > 0) && (voice->LoopStart != nullptr))
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
ptr = (uint8_t const *) voice->LoopStart;
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
if (voice->LoopCount < 0xffff)
|
|
|
|
{
|
2015-07-08 03:33:56 +00:00
|
|
|
if (--voice->LoopCount == 0)
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->LoopStart = nullptr;
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8 :
|
|
|
|
// Extended block
|
|
|
|
voice->bits = 8;
|
|
|
|
voice->channels = 1;
|
2017-02-19 22:15:56 +00:00
|
|
|
tc = B_LITTLE16(*(uint16_t const *)ptr);
|
2012-12-29 10:59:21 +00:00
|
|
|
packtype = *(ptr + 2);
|
|
|
|
voicemode = *(ptr + 3);
|
|
|
|
ptr += blocklength;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9 :
|
|
|
|
// New sound data block
|
2017-02-19 22:15:56 +00:00
|
|
|
samplespeed = B_LITTLE32(*(uint32_t const *)ptr);
|
2012-12-29 10:59:21 +00:00
|
|
|
BitsPerSample = (unsigned)*(ptr + 4);
|
|
|
|
Channels = (unsigned)*(ptr + 5);
|
2017-02-19 22:15:56 +00:00
|
|
|
Format = (unsigned)B_LITTLE16(*(uint16_t const *)(ptr + 6));
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if ((BitsPerSample == 8) && (Channels == 1 || Channels == 2) && (Format == VOC_8BIT))
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
ptr += 12;
|
|
|
|
blocklength -= 12;
|
|
|
|
voice->bits = 8;
|
|
|
|
voice->channels = Channels;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
else if ((BitsPerSample == 16) && (Channels == 1 || Channels == 2) && (Format == VOC_16BIT))
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
ptr += 12;
|
|
|
|
blocklength -= 12;
|
|
|
|
voice->bits = 16;
|
|
|
|
voice->channels = Channels;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr += blocklength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CAUTION:
|
|
|
|
// SNAKRM.VOC is corrupt! blocklength gets us beyond the
|
|
|
|
// end of the file.
|
2015-07-08 03:33:56 +00:00
|
|
|
if (ptr - (uint8_t *)voice->rawdataptr >= voice->ptrlength)
|
2012-12-29 10:59:21 +00:00
|
|
|
goto end_of_data;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
// Unknown data. Probably not a VOC file.
|
2018-10-25 23:33:04 +00:00
|
|
|
done = 2;
|
2012-12-29 10:59:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastblocktype = blocktype;
|
|
|
|
}
|
|
|
|
while (!done);
|
|
|
|
|
2018-10-25 23:33:04 +00:00
|
|
|
if (done != 2)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
2016-01-11 05:05:38 +00:00
|
|
|
voice->NextBlock = (char const *)ptr + blocklength;
|
|
|
|
voice->sound = (char const *)ptr;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// CODEDUP multivoc.c MV_SetVoicePitch
|
|
|
|
voice->SamplingRate = samplespeed;
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->RateScale = divideu32(voice->SamplingRate * voice->PitchScale, MV_MixRate);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// Multiply by MV_MIXBUFFERSIZE - 1
|
|
|
|
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) -
|
|
|
|
voice->RateScale;
|
|
|
|
|
2019-10-19 23:47:19 +00:00
|
|
|
if (voice->LoopEnd != nullptr)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
if (blocklength > (uintptr_t)voice->LoopEnd)
|
|
|
|
blocklength = (uintptr_t)voice->LoopEnd;
|
|
|
|
else
|
|
|
|
voice->LoopEnd = (char *)blocklength;
|
|
|
|
|
|
|
|
voice->LoopStart = voice->sound + (uintptr_t)voice->LoopStart;
|
|
|
|
voice->LoopEnd = voice->sound + (uintptr_t)voice->LoopEnd;
|
|
|
|
voice->LoopSize = voice->LoopEnd - voice->LoopStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (voice->bits == 16)
|
|
|
|
blocklength /= 2;
|
|
|
|
|
|
|
|
if (voice->channels == 2)
|
|
|
|
blocklength /= 2;
|
|
|
|
|
|
|
|
voice->position = 0;
|
2018-10-25 23:29:08 +00:00
|
|
|
voice->length = min<uint32_t>(blocklength, 0x8000u);
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->BlockLength = blocklength - voice->length;
|
|
|
|
voice->length <<= 16;
|
|
|
|
|
|
|
|
MV_SetVoiceMixMode(voice);
|
|
|
|
|
|
|
|
return KeepPlaying;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NoMoreData;
|
|
|
|
}
|
|
|
|
|
2019-10-24 13:25:34 +00:00
|
|
|
static playbackstatus MV_GetNextRAWBlock(VoiceNode *voice)
|
|
|
|
{
|
|
|
|
if (voice->BlockLength == 0)
|
|
|
|
{
|
|
|
|
if (voice->LoopStart == NULL)
|
|
|
|
return NoMoreData;
|
|
|
|
|
|
|
|
voice->BlockLength = voice->LoopSize;
|
|
|
|
voice->NextBlock = voice->LoopStart;
|
|
|
|
voice->length = 0;
|
|
|
|
voice->position = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
voice->sound = voice->NextBlock;
|
|
|
|
voice->position -= voice->length;
|
|
|
|
voice->length = min(voice->BlockLength, 0x8000u);
|
|
|
|
voice->NextBlock += voice->length * (voice->channels * voice->bits / 8);
|
|
|
|
voice->BlockLength -= voice->length;
|
|
|
|
voice->length <<= 16;
|
|
|
|
|
|
|
|
return KeepPlaying;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int MV_PlayWAV3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int angle, int distance,
|
2019-10-24 13:25:34 +00:00
|
|
|
int priority, float volume, intptr_t callbackval)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
return MV_Error;
|
|
|
|
|
|
|
|
if (distance < 0)
|
|
|
|
{
|
|
|
|
distance = -distance;
|
|
|
|
angle += MV_NUMPANPOSITIONS / 2;
|
|
|
|
}
|
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
int const vol = MIX_VOLUME(distance);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// Ensure angle is within 0 - 127
|
|
|
|
angle &= MV_MAXPANPOSITION;
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
return MV_PlayWAV(ptr, length, loophow, -1, pitchoffset, max(0, 255 - distance),
|
2018-10-25 23:32:14 +00:00
|
|
|
MV_PanTable[ angle ][ vol ].left, MV_PanTable[ angle ][ vol ].right, priority, volume, callbackval);
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int MV_PlayWAV(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol,
|
2019-10-24 13:25:34 +00:00
|
|
|
int left, int right, int priority, float volume, intptr_t callbackval)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
return MV_Error;
|
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
riff_header riff;
|
2012-12-29 10:59:21 +00:00
|
|
|
memcpy(&riff, ptr, sizeof(riff_header));
|
2017-02-19 22:15:56 +00:00
|
|
|
riff.file_size = B_LITTLE32(riff.file_size);
|
|
|
|
riff.format_size = B_LITTLE32(riff.format_size);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
if ((memcmp(riff.RIFF, "RIFF", 4) != 0) || (memcmp(riff.WAVE, "WAVE", 4) != 0) || (memcmp(riff.fmt, "fmt ", 4) != 0))
|
2019-10-19 23:47:19 +00:00
|
|
|
return MV_SetErrorCode(MV_InvalidFile);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
format_header format;
|
2012-12-29 10:59:21 +00:00
|
|
|
memcpy(&format, ptr + sizeof(riff_header), sizeof(format_header));
|
2017-02-19 22:15:56 +00:00
|
|
|
format.wFormatTag = B_LITTLE16(format.wFormatTag);
|
|
|
|
format.nChannels = B_LITTLE16(format.nChannels);
|
|
|
|
format.nSamplesPerSec = B_LITTLE32(format.nSamplesPerSec);
|
|
|
|
format.nAvgBytesPerSec = B_LITTLE32(format.nAvgBytesPerSec);
|
|
|
|
format.nBlockAlign = B_LITTLE16(format.nBlockAlign);
|
|
|
|
format.nBitsPerSample = B_LITTLE16(format.nBitsPerSample);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
data_header data;
|
2012-12-29 10:59:21 +00:00
|
|
|
memcpy(&data, ptr + sizeof(riff_header) + riff.format_size, sizeof(data_header));
|
2017-02-19 22:15:56 +00:00
|
|
|
data.size = B_LITTLE32(data.size);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// Check if it's PCM data.
|
2015-07-08 03:33:56 +00:00
|
|
|
if (format.wFormatTag != 1 || (format.nChannels != 1 && format.nChannels != 2) ||
|
|
|
|
((format.nBitsPerSample != 8) && (format.nBitsPerSample != 16)) || memcmp(data.DATA, "data", 4) != 0)
|
2019-10-19 23:47:19 +00:00
|
|
|
return MV_SetErrorCode(MV_InvalidFile);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
// Request a voice from the voice pool
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
VoiceNode *voice = MV_AllocVoice(priority);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2019-10-19 23:47:19 +00:00
|
|
|
if (voice == nullptr)
|
|
|
|
return MV_SetErrorCode(MV_NoVoices);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
2015-07-08 03:33:56 +00:00
|
|
|
voice->wavetype = FMT_WAV;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->bits = format.nBitsPerSample;
|
|
|
|
voice->channels = format.nChannels;
|
|
|
|
voice->GetSound = MV_GetNextWAVBlock;
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int blocklen = data.size;
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
if (voice->bits == 16)
|
|
|
|
{
|
|
|
|
data.size &= ~1;
|
2018-10-25 23:32:14 +00:00
|
|
|
blocklen /= 2;
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
2015-07-08 03:33:56 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
if (voice->channels == 2)
|
|
|
|
{
|
|
|
|
data.size &= ~1;
|
2018-10-25 23:32:14 +00:00
|
|
|
blocklen /= 2;
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice->rawdataptr = (uint8_t *)ptr;
|
2018-10-25 23:32:14 +00:00
|
|
|
voice->ptrlength = length;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->Paused = FALSE;
|
|
|
|
voice->LoopCount = 0;
|
|
|
|
voice->position = 0;
|
|
|
|
voice->length = 0;
|
2018-10-25 23:32:14 +00:00
|
|
|
voice->BlockLength = blocklen;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->NextBlock = (char *)((intptr_t) ptr + sizeof(riff_header) + riff.format_size + sizeof(data_header));
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->next = nullptr;
|
|
|
|
voice->prev = nullptr;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->priority = priority;
|
|
|
|
voice->callbackval = callbackval;
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->LoopStart = loopstart >= 0 ? voice->NextBlock : nullptr;
|
|
|
|
voice->LoopEnd = nullptr;
|
2018-10-25 23:32:14 +00:00
|
|
|
voice->LoopSize = loopend > 0 ? loopend - loopstart + 1 : blocklen;
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
MV_SetVoicePitch(voice, format.nSamplesPerSec, pitchoffset);
|
2018-10-25 23:32:50 +00:00
|
|
|
MV_SetVoiceVolume(voice, vol, left, right, volume);
|
2012-12-29 10:59:21 +00:00
|
|
|
MV_PlayVoice(voice);
|
|
|
|
|
|
|
|
return voice->handle;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int MV_PlayVOC3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int angle,
|
2019-10-24 13:25:34 +00:00
|
|
|
int distance, int priority, float volume, intptr_t callbackval)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
return MV_Error;
|
|
|
|
|
|
|
|
if (distance < 0)
|
|
|
|
{
|
|
|
|
distance = -distance;
|
|
|
|
angle += MV_NUMPANPOSITIONS / 2;
|
|
|
|
}
|
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
int const vol = MIX_VOLUME(distance);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// Ensure angle is within 0 - 127
|
|
|
|
angle &= MV_MAXPANPOSITION;
|
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
return MV_PlayVOC(ptr, length, loophow, -1, pitchoffset, max(0, 255 - distance),
|
|
|
|
MV_PanTable[ angle ][ vol ].left, MV_PanTable[ angle ][ vol ].right, priority, volume, callbackval);
|
2012-12-29 10:59:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 23:47:54 +00:00
|
|
|
int MV_PlayVOC(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol,
|
2019-10-24 13:25:34 +00:00
|
|
|
int left, int right, int priority, float volume, intptr_t callbackval)
|
2012-12-29 10:59:21 +00:00
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
return MV_Error;
|
|
|
|
|
|
|
|
// Make sure it looks like a valid VOC file.
|
2015-07-08 03:33:56 +00:00
|
|
|
if (memcmp(ptr, "Creative Voice File", 19) != 0)
|
2019-10-19 23:47:19 +00:00
|
|
|
return MV_SetErrorCode(MV_InvalidFile);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
// Request a voice from the voice pool
|
2015-07-08 03:33:56 +00:00
|
|
|
VoiceNode *voice = MV_AllocVoice(priority);
|
|
|
|
|
2019-10-19 23:47:19 +00:00
|
|
|
if (voice == nullptr)
|
|
|
|
return MV_SetErrorCode(MV_NoVoices);
|
2012-12-29 10:59:21 +00:00
|
|
|
|
|
|
|
voice->rawdataptr = (uint8_t *)ptr;
|
2018-10-25 23:32:14 +00:00
|
|
|
voice->ptrlength = length;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->Paused = FALSE;
|
2015-07-08 03:33:56 +00:00
|
|
|
voice->wavetype = FMT_VOC;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->bits = 8;
|
|
|
|
voice->channels = 1;
|
|
|
|
voice->GetSound = MV_GetNextVOCBlock;
|
2017-02-19 22:15:56 +00:00
|
|
|
voice->NextBlock = ptr + B_LITTLE16(*(uint16_t *)(ptr + 0x14));
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->LoopCount = 0;
|
|
|
|
voice->BlockLength = 0;
|
|
|
|
voice->PitchScale = PITCH_GetScale(pitchoffset);
|
|
|
|
voice->length = 0;
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->next = nullptr;
|
|
|
|
voice->prev = nullptr;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->priority = priority;
|
|
|
|
voice->callbackval = callbackval;
|
2019-10-19 23:47:19 +00:00
|
|
|
voice->LoopStart = loopstart >= 0 ? voice->NextBlock : nullptr;
|
|
|
|
voice->LoopEnd = nullptr;
|
2012-12-29 10:59:21 +00:00
|
|
|
voice->LoopSize = loopend - loopstart + 1;
|
|
|
|
|
2018-10-25 23:32:14 +00:00
|
|
|
voice->volume = volume;
|
|
|
|
|
2018-10-25 23:32:50 +00:00
|
|
|
MV_SetVoiceVolume(voice, vol, left, right, volume);
|
2012-12-29 10:59:21 +00:00
|
|
|
MV_PlayVoice(voice);
|
|
|
|
|
|
|
|
return voice->handle;
|
|
|
|
}
|
|
|
|
|
2019-10-24 13:25:34 +00:00
|
|
|
int MV_PlayRAW(char *ptr, uint32_t length, int rate, char *loopstart, char *loopend, int pitchoffset, int vol,
|
|
|
|
int left, int right, int priority, float volume, intptr_t callbackval)
|
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
return MV_Error;
|
|
|
|
|
|
|
|
// Request a voice from the voice pool
|
|
|
|
VoiceNode *voice = MV_AllocVoice(priority);
|
|
|
|
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NoVoices);
|
|
|
|
return MV_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
voice->rawdataptr = (uint8_t *)ptr;
|
|
|
|
voice->ptrlength = length;
|
|
|
|
voice->Paused = FALSE;
|
|
|
|
voice->wavetype = FMT_RAW;
|
|
|
|
voice->bits = 8;
|
|
|
|
voice->channels = 1;
|
|
|
|
voice->GetSound = MV_GetNextRAWBlock;
|
|
|
|
voice->NextBlock = ptr;
|
|
|
|
voice->LoopCount = 0;
|
|
|
|
voice->position = 0;
|
|
|
|
voice->BlockLength = length;
|
|
|
|
voice->PitchScale = PITCH_GetScale(pitchoffset);
|
|
|
|
voice->length = 0;
|
|
|
|
voice->next = NULL;
|
|
|
|
voice->prev = NULL;
|
|
|
|
voice->priority = priority;
|
|
|
|
voice->callbackval = callbackval;
|
|
|
|
voice->LoopStart = loopstart;
|
|
|
|
voice->LoopEnd = loopend;
|
|
|
|
voice->LoopSize = loopend - loopstart + 1;
|
|
|
|
|
|
|
|
voice->volume = volume;
|
|
|
|
|
|
|
|
MV_SetVoicePitch(voice, rate, pitchoffset);
|
|
|
|
MV_SetVoiceVolume(voice, vol, left, right, volume);
|
|
|
|
MV_PlayVoice(voice);
|
|
|
|
|
|
|
|
return voice->handle;
|
|
|
|
}
|