mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-18 14:41:55 +00:00
Clean up and factor jaudiolib.
git-svn-id: https://svn.eduke32.com/eduke32@3338 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
b6ddc6149e
commit
be03f29484
11 changed files with 1065 additions and 1254 deletions
|
@ -42,6 +42,7 @@ OBJECTS=$(OBJ)/drivers.o \
|
|||
$(OBJ)/mix.o \
|
||||
$(OBJ)/mixst.o \
|
||||
$(OBJ)/pitch.o \
|
||||
$(OBJ)/formats.o \
|
||||
$(OBJ)/vorbis.o \
|
||||
$(OBJ)/flac.o \
|
||||
$(OBJ)/driver_nosound.o
|
||||
|
|
|
@ -33,6 +33,7 @@ OBJECTS=$(OBJ)\drivers.o \
|
|||
$(OBJ)\mix.o \
|
||||
$(OBJ)\mixst.o \
|
||||
$(OBJ)\pitch.o \
|
||||
$(OBJ)\formats.o \
|
||||
$(OBJ)\vorbis.o \
|
||||
$(OBJ)\driver_nosound.o \
|
||||
$(OBJ)\driver_directsound.o
|
||||
|
|
|
@ -92,16 +92,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
//#define PI 3.1415926536
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Raw,
|
||||
VOC,
|
||||
DemandFeed,
|
||||
WAV,
|
||||
Vorbis,
|
||||
FLAC
|
||||
} wavedata;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NoMoreData,
|
||||
|
@ -237,6 +227,7 @@ VoiceNode *MV_AllocVoice( int32_t priority );
|
|||
|
||||
void MV_SetVoiceMixMode( VoiceNode *voice );
|
||||
void MV_SetVoiceVolume ( VoiceNode *voice, int32_t vol, int32_t left, int32_t right );
|
||||
void MV_SetVoicePitch ( VoiceNode *voice, uint32_t rate, int32_t pitchoffset );
|
||||
|
||||
void MV_ReleaseVorbisVoice( VoiceNode * voice );
|
||||
void MV_ReleaseFLACVoice( VoiceNode * voice );
|
||||
|
|
|
@ -37,10 +37,7 @@
|
|||
# include "SDL_thread.h"
|
||||
#endif
|
||||
#include "driver_sdl.h"
|
||||
|
||||
#ifndef UNREFERENCED_PARAMETER
|
||||
#define UNREFERENCED_PARAMETER(P) (P)=(P)
|
||||
#endif
|
||||
#include "multivoc.h"
|
||||
|
||||
enum {
|
||||
SDLErr_Warning = -2,
|
||||
|
|
|
@ -42,21 +42,6 @@
|
|||
#include "_multivc.h"
|
||||
|
||||
|
||||
#ifndef min
|
||||
#define min(x,y) ((x) < (y) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
# elif defined(__QNX__)
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# endif
|
||||
|
||||
typedef struct {
|
||||
void * ptr;
|
||||
size_t length;
|
||||
|
@ -232,6 +217,7 @@ FLAC__StreamDecoderWriteStatus write_flac_stream(const FLAC__StreamDecoder *deco
|
|||
voice->length = ((samples * (voice->bits/8))/2)<<voice->bits;
|
||||
voice->position = 0;
|
||||
voice->BlockLength = 0;
|
||||
// CODEDUP multivoc.c MV_SetVoicePitch
|
||||
voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
|
||||
voice->FixedPointBufferSize = ( voice->RateScale * MV_MIXBUFFERSIZE ) - voice->RateScale;
|
||||
MV_SetVoiceMixMode( voice );
|
||||
|
@ -352,12 +338,13 @@ static playbackstatus MV_GetNextFLACBlock
|
|||
voice->channels = FLAC__stream_decoder_get_channels(fd->stream);
|
||||
voice->bits = FLAC__stream_decoder_get_bits_per_sample(fd->stream);
|
||||
voice->SamplingRate = FLAC__stream_decoder_get_sample_rate(fd->stream);
|
||||
// CODEDUP multivoc.c MV_SetVoicePitch
|
||||
voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
|
||||
voice->FixedPointBufferSize = ( voice->RateScale * MV_MIXBUFFERSIZE ) - voice->RateScale;
|
||||
MV_SetVoiceMixMode( voice );
|
||||
#endif
|
||||
|
||||
return( KeepPlaying );
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
|
||||
|
@ -389,7 +376,7 @@ int32_t MV_PlayFLAC3D
|
|||
if ( !MV_Installed )
|
||||
{
|
||||
MV_SetErrorCode( MV_NotInstalled );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if ( distance < 0 )
|
||||
|
@ -407,10 +394,9 @@ int32_t MV_PlayFLAC3D
|
|||
right = MV_PanTable[ angle ][ volume ].right;
|
||||
mid = max( 0, 255 - distance );
|
||||
|
||||
status = MV_PlayFLAC( ptr, ptrlength, pitchoffset, mid, left, right, priority,
|
||||
callbackval );
|
||||
status = MV_PlayFLAC(ptr, ptrlength, pitchoffset, -1, -1, mid, left, right, priority, callbackval);
|
||||
|
||||
return( status );
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -422,35 +408,6 @@ priority.
|
|||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayFLAC
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t ptrlength,
|
||||
int32_t pitchoffset,
|
||||
int32_t vol,
|
||||
int32_t left,
|
||||
int32_t right,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
int32_t status;
|
||||
|
||||
status = MV_PlayLoopedFLAC( ptr, ptrlength, -1, -1, pitchoffset, vol, left, right,
|
||||
priority, callbackval );
|
||||
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayLoopedFLAC
|
||||
|
||||
Begin playback of sound data with the given sound levels and
|
||||
priority.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayLoopedFLAC
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t ptrlength,
|
||||
|
@ -474,7 +431,7 @@ int32_t MV_PlayLoopedFLAC
|
|||
if ( !MV_Installed )
|
||||
{
|
||||
MV_SetErrorCode( MV_NotInstalled );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
fd = (flac_data *) malloc( sizeof(flac_data) );
|
||||
|
@ -506,7 +463,7 @@ int32_t MV_PlayLoopedFLAC
|
|||
/*metadata_flac_stream*/ NULL,
|
||||
error_flac_stream,
|
||||
(void*) fd) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
|
||||
MV_Printf("MV_PlayLoopedFLAC: %s\n", FLAC__stream_decoder_get_resolved_state_string(fd->stream));
|
||||
MV_Printf("MV_PlayFLAC: %s\n", FLAC__stream_decoder_get_resolved_state_string(fd->stream));
|
||||
MV_SetErrorCode( MV_InvalidFLACFile );
|
||||
return MV_Error;
|
||||
}
|
||||
|
@ -519,7 +476,7 @@ int32_t MV_PlayLoopedFLAC
|
|||
FLAC__stream_decoder_delete(fd->stream);
|
||||
free(fd);
|
||||
MV_SetErrorCode( MV_NoVoices );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
fd->owner = voice;
|
||||
|
@ -665,6 +622,7 @@ int32_t MV_PlayLoopedFLAC
|
|||
else
|
||||
MV_Printf("Error allocating FLAC__Metadata_Chain!\n");
|
||||
|
||||
// CODEDUP multivoc.c MV_SetVoicePitch
|
||||
voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
|
||||
voice->FixedPointBufferSize = ( voice->RateScale * MV_MIXBUFFERSIZE ) -
|
||||
voice->RateScale;
|
||||
|
@ -673,7 +631,7 @@ int32_t MV_PlayLoopedFLAC
|
|||
MV_SetVoiceVolume( voice, vol, left, right );
|
||||
MV_PlayVoice( voice );
|
||||
|
||||
return( voice->handle );
|
||||
return voice->handle;
|
||||
}
|
||||
|
||||
|
||||
|
|
855
polymer/eduke32/source/jaudiolib/src/formats.c
Normal file
855
polymer/eduke32/source/jaudiolib/src/formats.c
Normal file
|
@ -0,0 +1,855 @@
|
|||
/*
|
||||
Copyright (C) 2009 Jonathon Fowler <jf@jonof.id.au>
|
||||
|
||||
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
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Raw, DemandFeed, WAV, and VOC source support for MultiVoc
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "pitch.h"
|
||||
#include "multivoc.h"
|
||||
#include "_multivc.h"
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_GetNextRawBlock
|
||||
|
||||
Controls playback of demand fed data.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
static playbackstatus MV_GetNextRawBlock(VoiceNode *voice)
|
||||
{
|
||||
if (voice->BlockLength <= 0)
|
||||
{
|
||||
if (voice->LoopStart == NULL)
|
||||
{
|
||||
voice->Playing = FALSE;
|
||||
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, 0x8000);
|
||||
voice->NextBlock += voice->length * (voice->channels * voice->bits / 8);
|
||||
voice->BlockLength -= voice->length;
|
||||
voice->length <<= 16;
|
||||
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_GetNextWAVBlock
|
||||
|
||||
Controls playback of demand fed data.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
static playbackstatus MV_GetNextWAVBlock(VoiceNode *voice)
|
||||
{
|
||||
if (voice->BlockLength <= 0)
|
||||
{
|
||||
if (voice->LoopStart == NULL)
|
||||
{
|
||||
voice->Playing = FALSE;
|
||||
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, 0x8000);
|
||||
voice->NextBlock += voice->length * (voice->channels * voice->bits / 8);
|
||||
voice->BlockLength -= voice->length;
|
||||
voice->length <<= 16;
|
||||
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_GetNextVOCBlock
|
||||
|
||||
Interpret the information of a VOC format sound file.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
static playbackstatus MV_GetNextVOCBlock(VoiceNode *voice)
|
||||
{
|
||||
const uint8_t *ptr;
|
||||
int32_t blocktype;
|
||||
int32_t lastblocktype;
|
||||
size_t blocklength = 0;
|
||||
uint32_t samplespeed = 0; // XXX: compiler-happy on synthesis
|
||||
uint32_t tc = 0;
|
||||
int32_t packtype;
|
||||
int32_t voicemode;
|
||||
int32_t done;
|
||||
unsigned BitsPerSample;
|
||||
unsigned Channels;
|
||||
unsigned Format;
|
||||
|
||||
if (voice->BlockLength > 0)
|
||||
{
|
||||
voice->position -= voice->length;
|
||||
voice->sound += (voice->length >> 16) * (voice->channels * voice->bits / 8);
|
||||
voice->length = min(voice->BlockLength, 0x8000);
|
||||
voice->BlockLength -= voice->length;
|
||||
voice->length <<= 16;
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
ptr = (uint8_t *)voice->NextBlock;
|
||||
|
||||
voice->Playing = TRUE;
|
||||
voice->Paused = FALSE;
|
||||
|
||||
voicemode = 0;
|
||||
lastblocktype = 0;
|
||||
packtype = 0;
|
||||
|
||||
done = FALSE;
|
||||
|
||||
do
|
||||
{
|
||||
// Stop playing if we get a NULL pointer
|
||||
if (ptr == NULL)
|
||||
{
|
||||
voice->Playing = FALSE;
|
||||
done = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
// terminator is not mandatory according to
|
||||
// http://wiki.multimedia.cx/index.php?title=Creative_Voice
|
||||
|
||||
if (ptr - voice->rawdataptr >= voice->ptrlength)
|
||||
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:
|
||||
// blocklength = LITTLE32(*(uint32_t *)(ptr + 1)) & 0x00ffffff;
|
||||
|
||||
ptr += 4;
|
||||
|
||||
switch (blocktype)
|
||||
{
|
||||
case 0 :
|
||||
end_of_data:
|
||||
// End of data
|
||||
if ((voice->LoopStart == NULL) ||
|
||||
((intptr_t) voice->LoopStart >= ((intptr_t) ptr - 4)))
|
||||
{
|
||||
voice->Playing = FALSE;
|
||||
done = TRUE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (ptr - voice->rawdataptr >= voice->ptrlength)
|
||||
goto end_of_data;
|
||||
|
||||
voicemode = 0;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
// Sound continuation block
|
||||
samplespeed = voice->SamplingRate;
|
||||
done = TRUE;
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
// Silence
|
||||
// Not implimented.
|
||||
ptr += blocklength;
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
// Marker
|
||||
// Not implimented.
|
||||
ptr += blocklength;
|
||||
break;
|
||||
|
||||
case 5 :
|
||||
// ASCII string
|
||||
// Not implimented.
|
||||
ptr += blocklength;
|
||||
break;
|
||||
|
||||
case 6 :
|
||||
// Repeat begin
|
||||
if (voice->LoopEnd == NULL)
|
||||
{
|
||||
voice->LoopCount = LITTLE16(*(uint16_t *)ptr);
|
||||
voice->LoopStart = (char *)((intptr_t) ptr + blocklength);
|
||||
}
|
||||
ptr += blocklength;
|
||||
break;
|
||||
|
||||
case 7 :
|
||||
// Repeat end
|
||||
ptr += blocklength;
|
||||
if (lastblocktype == 6)
|
||||
{
|
||||
voice->LoopCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((voice->LoopCount > 0) && (voice->LoopStart != NULL))
|
||||
{
|
||||
ptr = (uint8_t *) voice->LoopStart;
|
||||
if (voice->LoopCount < 0xffff)
|
||||
{
|
||||
voice->LoopCount--;
|
||||
if (voice->LoopCount == 0)
|
||||
{
|
||||
voice->LoopStart = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 8 :
|
||||
// Extended block
|
||||
voice->bits = 8;
|
||||
voice->channels = 1;
|
||||
tc = LITTLE16(*(uint16_t *)ptr);
|
||||
packtype = *(ptr + 2);
|
||||
voicemode = *(ptr + 3);
|
||||
ptr += blocklength;
|
||||
break;
|
||||
|
||||
case 9 :
|
||||
// New sound data block
|
||||
samplespeed = LITTLE32(*(uint32_t *)ptr);
|
||||
BitsPerSample = (unsigned)*(ptr + 4);
|
||||
Channels = (unsigned)*(ptr + 5);
|
||||
Format = (unsigned)LITTLE16(*(uint16_t *)(ptr + 6));
|
||||
|
||||
if ((BitsPerSample == 8) && (Channels == 1 || Channels == 2) &&
|
||||
(Format == VOC_8BIT))
|
||||
{
|
||||
ptr += 12;
|
||||
blocklength -= 12;
|
||||
voice->bits = 8;
|
||||
voice->channels = Channels;
|
||||
done = TRUE;
|
||||
}
|
||||
else if ((BitsPerSample == 16) && (Channels == 1 || Channels == 2) &&
|
||||
(Format == VOC_16BIT))
|
||||
{
|
||||
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.
|
||||
if (ptr - voice->rawdataptr >= voice->ptrlength)
|
||||
goto end_of_data;
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
// Unknown data. Probably not a VOC file.
|
||||
voice->Playing = FALSE;
|
||||
done = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
lastblocktype = blocktype;
|
||||
}
|
||||
while (!done);
|
||||
|
||||
if (voice->Playing)
|
||||
{
|
||||
voice->NextBlock = (char *)ptr + blocklength;
|
||||
voice->sound = (char *)ptr;
|
||||
|
||||
// CODEDUP multivoc.c MV_SetVoicePitch
|
||||
voice->SamplingRate = samplespeed;
|
||||
voice->RateScale = (voice->SamplingRate * voice->PitchScale) / MV_MixRate;
|
||||
|
||||
// Multiply by MV_MIXBUFFERSIZE - 1
|
||||
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) -
|
||||
voice->RateScale;
|
||||
|
||||
if (voice->LoopEnd != NULL)
|
||||
{
|
||||
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;
|
||||
voice->length = min(blocklength, 0x8000);
|
||||
voice->BlockLength = blocklength - voice->length;
|
||||
voice->length <<= 16;
|
||||
|
||||
MV_SetVoiceMixMode(voice);
|
||||
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
return NoMoreData;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_GetNextDemandFeedBlock
|
||||
|
||||
Controls playback of demand fed data.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
static playbackstatus MV_GetNextDemandFeedBlock(VoiceNode *voice)
|
||||
{
|
||||
if (voice->BlockLength > 0)
|
||||
{
|
||||
voice->position -= voice->length;
|
||||
voice->sound += voice->length >> 16;
|
||||
voice->length = min(voice->BlockLength, 0x8000);
|
||||
voice->BlockLength -= voice->length;
|
||||
voice->length <<= 16;
|
||||
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
if (voice->DemandFeed == NULL)
|
||||
return NoMoreData;
|
||||
|
||||
voice->position = 0;
|
||||
// TODO: learn how to properly attach the 'const' in pointer-pointers :O
|
||||
(voice->DemandFeed)((char **)&voice->sound, &voice->BlockLength);
|
||||
voice->length = min(voice->BlockLength, 0x8000);
|
||||
voice->BlockLength -= voice->length;
|
||||
voice->length <<= 16;
|
||||
|
||||
return ((voice->length > 0) && (voice->sound != NULL) ? KeepPlaying : NoMoreData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayRaw
|
||||
|
||||
Begin playback of sound data with the given sound levels and
|
||||
priority.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayRaw
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t length,
|
||||
char *loopstart,
|
||||
char *loopend,
|
||||
unsigned rate,
|
||||
int32_t pitchoffset,
|
||||
int32_t vol,
|
||||
int32_t left,
|
||||
int32_t right,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
VoiceNode *voice;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
// Request a voice from the voice pool
|
||||
voice = MV_AllocVoice(priority);
|
||||
if (voice == NULL)
|
||||
{
|
||||
MV_SetErrorCode(MV_NoVoices);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
voice->wavetype = Raw;
|
||||
voice->bits = 8;
|
||||
voice->channels = 1;
|
||||
voice->GetSound = MV_GetNextRawBlock;
|
||||
voice->Playing = TRUE;
|
||||
voice->Paused = FALSE;
|
||||
voice->NextBlock = ptr;
|
||||
voice->position = 0;
|
||||
voice->BlockLength = length;
|
||||
voice->length = 0;
|
||||
voice->next = NULL;
|
||||
voice->prev = NULL;
|
||||
voice->priority = priority;
|
||||
voice->callbackval = callbackval;
|
||||
voice->LoopStart = loopstart;
|
||||
voice->LoopEnd = loopend;
|
||||
voice->LoopSize = loopend > (char*) 0 ? (uintptr_t) loopend - (uintptr_t) loopstart + 1 : length;
|
||||
|
||||
MV_SetVoicePitch(voice, rate, pitchoffset);
|
||||
MV_SetVoiceVolume(voice, vol, left, right);
|
||||
MV_PlayVoice(voice);
|
||||
|
||||
return voice->handle;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayWAV3D
|
||||
|
||||
Begin playback of sound data at specified angle and distance
|
||||
from listener.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayWAV3D
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t length,
|
||||
int32_t pitchoffset,
|
||||
int32_t angle,
|
||||
int32_t distance,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
int32_t left;
|
||||
int32_t right;
|
||||
int32_t mid;
|
||||
int32_t volume;
|
||||
int32_t status;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if (distance < 0)
|
||||
{
|
||||
distance = -distance;
|
||||
angle += MV_NUMPANPOSITIONS / 2;
|
||||
}
|
||||
|
||||
volume = MIX_VOLUME(distance);
|
||||
|
||||
// Ensure angle is within 0 - 127
|
||||
angle &= MV_MAXPANPOSITION;
|
||||
|
||||
left = MV_PanTable[ angle ][ volume ].left;
|
||||
right = MV_PanTable[ angle ][ volume ].right;
|
||||
mid = max(0, 255 - distance);
|
||||
|
||||
status = MV_PlayWAV(ptr, length, -1, -1, pitchoffset, mid, left, right, priority, callbackval);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayWAV
|
||||
|
||||
Begin playback of sound data with the given sound levels and
|
||||
priority.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayWAV
|
||||
(
|
||||
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
|
||||
)
|
||||
|
||||
{
|
||||
riff_header riff;
|
||||
format_header format;
|
||||
data_header data;
|
||||
VoiceNode *voice;
|
||||
int32_t length;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
memcpy(&riff, ptr, sizeof(riff_header));
|
||||
riff.file_size = LITTLE32(riff.file_size);
|
||||
riff.format_size = LITTLE32(riff.format_size);
|
||||
|
||||
if ((memcmp(riff.RIFF, "RIFF", 4) != 0) ||
|
||||
(memcmp(riff.WAVE, "WAVE", 4) != 0) ||
|
||||
(memcmp(riff.fmt, "fmt ", 4) != 0))
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidWAVFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
memcpy(&format, ptr + sizeof(riff_header), sizeof(format_header));
|
||||
format.wFormatTag = LITTLE16(format.wFormatTag);
|
||||
format.nChannels = LITTLE16(format.nChannels);
|
||||
format.nSamplesPerSec = LITTLE32(format.nSamplesPerSec);
|
||||
format.nAvgBytesPerSec = LITTLE32(format.nAvgBytesPerSec);
|
||||
format.nBlockAlign = LITTLE16(format.nBlockAlign);
|
||||
format.nBitsPerSample = LITTLE16(format.nBitsPerSample);
|
||||
|
||||
memcpy(&data, ptr + sizeof(riff_header) + riff.format_size, sizeof(data_header));
|
||||
data.size = LITTLE32(data.size);
|
||||
|
||||
// Check if it's PCM data.
|
||||
if (format.wFormatTag != 1)
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidWAVFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if (format.nChannels != 1 && format.nChannels != 2)
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidWAVFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if ((format.nBitsPerSample != 8) &&
|
||||
(format.nBitsPerSample != 16))
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidWAVFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if (memcmp(data.DATA, "data", 4) != 0)
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidWAVFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
// Request a voice from the voice pool
|
||||
voice = MV_AllocVoice(priority);
|
||||
if (voice == NULL)
|
||||
{
|
||||
MV_SetErrorCode(MV_NoVoices);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
voice->wavetype = WAV;
|
||||
voice->bits = format.nBitsPerSample;
|
||||
voice->channels = format.nChannels;
|
||||
voice->GetSound = MV_GetNextWAVBlock;
|
||||
|
||||
length = data.size;
|
||||
if (voice->bits == 16)
|
||||
{
|
||||
data.size &= ~1;
|
||||
length /= 2;
|
||||
}
|
||||
if (voice->channels == 2)
|
||||
{
|
||||
data.size &= ~1;
|
||||
length /= 2;
|
||||
}
|
||||
|
||||
voice->rawdataptr = (uint8_t *)ptr;
|
||||
voice->ptrlength = ptrlength;
|
||||
voice->Playing = TRUE;
|
||||
voice->Paused = FALSE;
|
||||
voice->DemandFeed = NULL;
|
||||
voice->LoopCount = 0;
|
||||
voice->position = 0;
|
||||
voice->length = 0;
|
||||
voice->BlockLength = length;
|
||||
voice->NextBlock = (char *)((intptr_t) ptr + sizeof(riff_header) + riff.format_size + sizeof(data_header));
|
||||
voice->next = NULL;
|
||||
voice->prev = NULL;
|
||||
voice->priority = priority;
|
||||
voice->callbackval = callbackval;
|
||||
voice->LoopStart = loopstart >= 0 ? voice->NextBlock : NULL;
|
||||
voice->LoopEnd = NULL;
|
||||
voice->LoopSize = loopend > 0 ? loopend - loopstart + 1 : length;
|
||||
|
||||
MV_SetVoicePitch(voice, format.nSamplesPerSec, pitchoffset);
|
||||
MV_SetVoiceVolume(voice, vol, left, right);
|
||||
MV_PlayVoice(voice);
|
||||
|
||||
return voice->handle;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayVOC3D
|
||||
|
||||
Begin playback of sound data at specified angle and distance
|
||||
from listener.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayVOC3D
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t ptrlength,
|
||||
int32_t pitchoffset,
|
||||
int32_t angle,
|
||||
int32_t distance,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
int32_t left;
|
||||
int32_t right;
|
||||
int32_t mid;
|
||||
int32_t volume;
|
||||
int32_t status;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if (distance < 0)
|
||||
{
|
||||
distance = -distance;
|
||||
angle += MV_NUMPANPOSITIONS / 2;
|
||||
}
|
||||
|
||||
volume = MIX_VOLUME(distance);
|
||||
|
||||
// Ensure angle is within 0 - 127
|
||||
angle &= MV_MAXPANPOSITION;
|
||||
|
||||
left = MV_PanTable[ angle ][ volume ].left;
|
||||
right = MV_PanTable[ angle ][ volume ].right;
|
||||
mid = max(0, 255 - distance);
|
||||
|
||||
status = MV_PlayVOC(ptr, ptrlength, -1, -1, pitchoffset, mid, left, right, priority, callbackval);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayVOC
|
||||
|
||||
Begin playback of sound data with the given sound levels and
|
||||
priority.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayVOC
|
||||
(
|
||||
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
|
||||
)
|
||||
|
||||
{
|
||||
VoiceNode *voice;
|
||||
int32_t status;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
// Make sure it looks like a valid VOC file.
|
||||
status = memcmp(ptr, "Creative Voice File", 19);
|
||||
if (status != 0)
|
||||
{
|
||||
MV_SetErrorCode(MV_InvalidVOCFile);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
// Request a voice from the voice pool
|
||||
voice = MV_AllocVoice(priority);
|
||||
if (voice == NULL)
|
||||
{
|
||||
MV_SetErrorCode(MV_NoVoices);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
voice->rawdataptr = (uint8_t *)ptr;
|
||||
voice->ptrlength = ptrlength;
|
||||
voice->Playing = TRUE;
|
||||
voice->Paused = FALSE;
|
||||
voice->wavetype = VOC;
|
||||
voice->bits = 8;
|
||||
voice->channels = 1;
|
||||
voice->GetSound = MV_GetNextVOCBlock;
|
||||
voice->NextBlock = ptr + LITTLE16(*(uint16_t *)(ptr + 0x14));
|
||||
voice->DemandFeed = NULL;
|
||||
voice->LoopCount = 0;
|
||||
voice->BlockLength = 0;
|
||||
voice->PitchScale = PITCH_GetScale(pitchoffset);
|
||||
voice->length = 0;
|
||||
voice->next = NULL;
|
||||
voice->prev = NULL;
|
||||
voice->priority = priority;
|
||||
voice->callbackval = callbackval;
|
||||
voice->LoopStart = loopstart >= 0 ? voice->NextBlock : NULL;
|
||||
voice->LoopEnd = NULL;
|
||||
voice->LoopSize = loopend - loopstart + 1;
|
||||
|
||||
MV_SetVoiceVolume(voice, vol, left, right);
|
||||
MV_PlayVoice(voice);
|
||||
|
||||
return voice->handle;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_StartDemandFeedPlayback
|
||||
|
||||
Plays a digitized sound from a user controlled buffering system.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_StartDemandFeedPlayback
|
||||
(
|
||||
void (*function)(char **ptr, uint32_t *length),
|
||||
int32_t rate,
|
||||
int32_t pitchoffset,
|
||||
int32_t vol,
|
||||
int32_t left,
|
||||
int32_t right,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
VoiceNode *voice;
|
||||
|
||||
if (!MV_Installed)
|
||||
{
|
||||
MV_SetErrorCode(MV_NotInstalled);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
// Request a voice from the voice pool
|
||||
voice = MV_AllocVoice(priority);
|
||||
if (voice == NULL)
|
||||
{
|
||||
MV_SetErrorCode(MV_NoVoices);
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
voice->wavetype = DemandFeed;
|
||||
voice->bits = 8;
|
||||
voice->channels = 1;
|
||||
voice->GetSound = MV_GetNextDemandFeedBlock;
|
||||
voice->NextBlock = NULL;
|
||||
voice->DemandFeed = function;
|
||||
voice->LoopStart = NULL;
|
||||
voice->LoopCount = 0;
|
||||
voice->position = 0;
|
||||
voice->sound = NULL;
|
||||
voice->length = 0;
|
||||
voice->BlockLength = 0;
|
||||
voice->Playing = TRUE;
|
||||
voice->next = NULL;
|
||||
voice->prev = NULL;
|
||||
voice->priority = priority;
|
||||
voice->callbackval = callbackval;
|
||||
|
||||
MV_SetVoicePitch(voice, rate, pitchoffset);
|
||||
MV_SetVoiceVolume(voice, vol, left, right);
|
||||
MV_PlayVoice(voice);
|
||||
|
||||
return voice->handle;
|
||||
}
|
|
@ -97,7 +97,7 @@ const char *FX_ErrorString
|
|||
break;
|
||||
}
|
||||
|
||||
return(ErrorString);
|
||||
return ErrorString;
|
||||
}
|
||||
|
||||
|
||||
|
@ -164,7 +164,7 @@ int32_t FX_Init
|
|||
FX_Installed = TRUE;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,7 +184,7 @@ int32_t FX_Shutdown
|
|||
|
||||
if (!FX_Installed)
|
||||
{
|
||||
return(FX_Ok);
|
||||
return FX_Ok;
|
||||
}
|
||||
|
||||
status = MV_Shutdown();
|
||||
|
@ -196,7 +196,7 @@ int32_t FX_Shutdown
|
|||
|
||||
FX_Installed = FALSE;
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,7 +218,7 @@ int32_t FX_SetCallBack
|
|||
|
||||
MV_SetCallBack(function);
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,7 +254,7 @@ int32_t FX_GetVolume
|
|||
|
||||
volume = MV_GetVolume();
|
||||
|
||||
return(volume);
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
|
@ -408,7 +408,7 @@ int32_t FX_PauseVoice
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -434,7 +434,7 @@ int32_t FX_EndLooping
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
|
@ -462,7 +462,7 @@ int32_t FX_SetPan
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -488,7 +488,7 @@ int32_t FX_SetPitch
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -514,7 +514,7 @@ int32_t FX_SetFrequency
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -537,17 +537,7 @@ int32_t FX_PlayVOC
|
|||
)
|
||||
|
||||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayVOC(ptr, ptrlength, pitchoffset, vol, left, right,
|
||||
priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return FX_PlayLoopedVOC(ptr, ptrlength, -1, -1, pitchoffset, vol, left, right, priority, callbackval);
|
||||
}
|
||||
|
||||
|
||||
|
@ -574,7 +564,7 @@ int32_t FX_PlayLoopedVOC
|
|||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayLoopedVOC(ptr, ptrlength, loopstart, loopend, pitchoffset,
|
||||
handle = MV_PlayVOC(ptr, ptrlength, loopstart, loopend, pitchoffset,
|
||||
vol, left, right, priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
|
@ -582,7 +572,7 @@ int32_t FX_PlayLoopedVOC
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -605,17 +595,7 @@ int32_t FX_PlayWAV
|
|||
)
|
||||
|
||||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayWAV(ptr, ptrlength, pitchoffset, vol, left, right,
|
||||
priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return FX_PlayLoopedWAV(ptr, ptrlength, -1, -1, pitchoffset, vol, left, right, priority, callbackval);
|
||||
}
|
||||
|
||||
|
||||
|
@ -642,7 +622,7 @@ int32_t FX_PlayLoopedWAV
|
|||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayLoopedWAV(ptr, ptrlength, loopstart, loopend,
|
||||
handle = MV_PlayWAV(ptr, ptrlength, loopstart, loopend,
|
||||
pitchoffset, vol, left, right, priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
|
@ -650,7 +630,7 @@ int32_t FX_PlayLoopedWAV
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -683,7 +663,7 @@ int32_t FX_PlayVOC3D
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -716,7 +696,7 @@ int32_t FX_PlayWAV3D
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -740,17 +720,7 @@ int32_t FX_PlayRaw
|
|||
)
|
||||
|
||||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayRaw(ptr, length, rate, pitchoffset,
|
||||
vol, left, right, priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return FX_PlayLoopedRaw(ptr, length, NULL, NULL, rate, pitchoffset, vol, left, right, priority, callbackval);
|
||||
}
|
||||
|
||||
|
||||
|
@ -778,7 +748,7 @@ int32_t FX_PlayLoopedRaw
|
|||
{
|
||||
int32_t handle;
|
||||
|
||||
handle = MV_PlayLoopedRaw(ptr, length, loopstart, loopend,
|
||||
handle = MV_PlayRaw(ptr, length, loopstart, loopend,
|
||||
rate, pitchoffset, vol, left, right, priority, callbackval);
|
||||
if (handle < MV_Ok)
|
||||
{
|
||||
|
@ -786,7 +756,7 @@ int32_t FX_PlayLoopedRaw
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
|
@ -808,7 +778,7 @@ int32_t FX_Pan3D(int32_t handle,int32_t angle,int32_t distance)
|
|||
status = FX_Warning;
|
||||
}
|
||||
|
||||
return(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -820,7 +790,7 @@ int32_t FX_Pan3D(int32_t handle,int32_t angle,int32_t distance)
|
|||
|
||||
int32_t FX_SoundActive(int32_t handle)
|
||||
{
|
||||
return(MV_VoicePlaying(handle));
|
||||
return MV_VoicePlaying(handle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -832,7 +802,7 @@ int32_t FX_SoundActive(int32_t handle)
|
|||
|
||||
int32_t FX_SoundsPlaying(void)
|
||||
{
|
||||
return(MV_VoicesPlaying());
|
||||
return MV_VoicesPlaying();
|
||||
}
|
||||
|
||||
|
||||
|
@ -850,10 +820,10 @@ int32_t FX_StopSound(int32_t handle)
|
|||
if (status != MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
return(FX_Warning);
|
||||
return FX_Warning;
|
||||
}
|
||||
|
||||
return(FX_Ok);
|
||||
return FX_Ok;
|
||||
}
|
||||
|
||||
|
||||
|
@ -875,10 +845,10 @@ int32_t FX_StopAllSounds
|
|||
if (status != MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
return(FX_Warning);
|
||||
return FX_Warning;
|
||||
}
|
||||
|
||||
return(FX_Ok);
|
||||
return FX_Ok;
|
||||
}
|
||||
|
||||
|
||||
|
@ -911,10 +881,39 @@ int32_t FX_StartDemandFeedPlayback
|
|||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
static wavedata FX_AutoDetectFormat(const char *ptr)
|
||||
{
|
||||
switch (LITTLE32(*(int32_t *)ptr))
|
||||
{
|
||||
case 'C'+('r'<<8)+('e'<<16)+('a'<<24): // Crea
|
||||
return VOC;
|
||||
break;
|
||||
case 'R'+('I'<<8)+('F'<<16)+('F'<<24): // RIFF
|
||||
return WAV;
|
||||
break;
|
||||
case 'O'+('g'<<8)+('g'<<16)+('S'<<24): // OggS
|
||||
return Vorbis;
|
||||
break;
|
||||
case 'f'+('L'<<8)+('a'<<16)+('C'<<24): // fLaC
|
||||
return FLAC;
|
||||
break;
|
||||
default:
|
||||
switch (LITTLE32(*(int32_t *)(ptr + 8)))
|
||||
{
|
||||
case 'W'+('A'<<8)+('V'<<16)+('E'<<24): // WAVE
|
||||
return WAV;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: FX_PlayAuto
|
||||
|
||||
|
@ -923,50 +922,7 @@ int32_t FX_StartDemandFeedPlayback
|
|||
int32_t FX_PlayAuto(char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol,
|
||||
int32_t left, int32_t right, int32_t priority, uint32_t callbackval)
|
||||
{
|
||||
int32_t handle = -1;
|
||||
|
||||
switch (LITTLE32(*(int32_t *)ptr))
|
||||
{
|
||||
case 'C'+('r'<<8)+('e'<<16)+('a'<<24):
|
||||
handle = MV_PlayVOC(ptr, length, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
case 'R'+('I'<<8)+('F'<<16)+('F'<<24):
|
||||
handle = MV_PlayWAV(ptr, length, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
#ifdef HAVE_VORBIS
|
||||
case 'O'+('g'<<8)+('g'<<16)+('S'<<24):
|
||||
handle = MV_PlayVorbis(ptr, length, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_FLAC
|
||||
case 'f'+('L'<<8)+('a'<<16)+('C'<<24):
|
||||
handle = MV_PlayFLAC(ptr, length, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
switch (LITTLE32(*(int32_t *)(ptr + 8)))
|
||||
{
|
||||
case 'W'+('A'<<8)+('V'<<16)+('E'<<24):
|
||||
handle = MV_PlayWAV(ptr, length, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (handle <= MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
handle = FX_Warning;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
int32_t FX_SetPrintf(void (*function)(const char *, ...))
|
||||
{
|
||||
MV_SetPrintf(function);
|
||||
|
||||
return FX_Ok;
|
||||
return FX_PlayLoopedAuto(ptr, length, -1, -1, pitchoffset, vol, left, right, priority, callbackval);;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
|
@ -979,39 +935,31 @@ int32_t FX_PlayLoopedAuto(char *ptr, uint32_t length, int32_t loopstart, int32_t
|
|||
uint32_t callbackval)
|
||||
{
|
||||
int32_t handle = -1;
|
||||
#if 0
|
||||
|
||||
switch (FX_AutoDetectFormat(ptr))
|
||||
{
|
||||
char fmtstr[5];
|
||||
Bmemcpy(fmtstr, ptr, 4);
|
||||
fmtstr[4] = 0;
|
||||
printf("FX_PlayLoopedAuto %s\n", fmtstr);
|
||||
}
|
||||
#endif
|
||||
switch (LITTLE32(*(int32_t *)ptr))
|
||||
{
|
||||
case 'C'+('r'<<8)+('e'<<16)+('a'<<24):
|
||||
handle = MV_PlayLoopedVOC(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
case VOC:
|
||||
handle = MV_PlayVOC(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
case 'R'+('I'<<8)+('F'<<16)+('F'<<24):
|
||||
handle = MV_PlayLoopedWAV(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
case WAV:
|
||||
handle = MV_PlayWAV(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
case Vorbis:
|
||||
#ifdef HAVE_VORBIS
|
||||
case 'O'+('g'<<8)+('g'<<16)+('S'<<24):
|
||||
handle = MV_PlayLoopedVorbis(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
handle = MV_PlayVorbis(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
#else
|
||||
MV_Printf("FX_PlayLoopedAuto: OggVorbis support not included in this binary.\n");
|
||||
#endif
|
||||
break;
|
||||
case FLAC:
|
||||
#ifdef HAVE_FLAC
|
||||
case 'f'+('L'<<8)+('a'<<16)+('C'<<24):
|
||||
handle = MV_PlayLoopedFLAC(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
handle = MV_PlayFLAC(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
#else
|
||||
MV_Printf("FX_PlayLoopedAuto: FLAC support not included in this binary.\n");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
switch (LITTLE32(*(int32_t *)(ptr + 8)))
|
||||
{
|
||||
case 'W'+('A'<<8)+('V'<<16)+('E'<<24):
|
||||
handle = MV_PlayLoopedWAV(ptr, length, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval);
|
||||
break;
|
||||
}
|
||||
MV_Printf("FX_PlayLoopedAuto: Unknown or unsupported format.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1035,31 +983,30 @@ int32_t FX_PlayAuto3D(char *ptr, uint32_t length, int32_t pitchoffset, int32_t a
|
|||
{
|
||||
int32_t handle = -1;
|
||||
|
||||
switch (LITTLE32(*(int32_t *)ptr))
|
||||
switch (FX_AutoDetectFormat(ptr))
|
||||
{
|
||||
case 'C'+('r'<<8)+('e'<<16)+('a'<<24): // Crea
|
||||
case VOC:
|
||||
handle = MV_PlayVOC3D(ptr, length, pitchoffset, angle, distance, priority, callbackval);
|
||||
break;
|
||||
case 'R'+('I'<<8)+('F'<<16)+('F'<<24): // RIFF
|
||||
case WAV:
|
||||
handle = MV_PlayWAV3D(ptr, length, pitchoffset, angle, distance, priority, callbackval);
|
||||
break;
|
||||
case Vorbis:
|
||||
#ifdef HAVE_VORBIS
|
||||
case 'O'+('g'<<8)+('g'<<16)+('S'<<24): // OggS
|
||||
handle = MV_PlayVorbis3D(ptr, length, pitchoffset, angle, distance, priority, callbackval);
|
||||
break;
|
||||
#else
|
||||
MV_Printf("FX_PlayAuto3D: OggVorbis support not included in this binary.\n");
|
||||
#endif
|
||||
break;
|
||||
case FLAC:
|
||||
#ifdef HAVE_FLAC
|
||||
case 'f'+('L'<<8)+('a'<<16)+('C'<<24): // fLaC
|
||||
handle = MV_PlayFLAC3D(ptr, length, pitchoffset, angle, distance, priority, callbackval);
|
||||
break;
|
||||
#else
|
||||
MV_Printf("FX_PlayAuto3D: FLAC support not included in this binary.\n");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
switch (LITTLE32(*(int32_t *)(ptr + 8)))
|
||||
{
|
||||
case 'W'+('A'<<8)+('V'<<16)+('E'<<24): // WAVE
|
||||
handle = MV_PlayWAV3D(ptr, length, pitchoffset, angle, distance, priority, callbackval);
|
||||
break;
|
||||
}
|
||||
MV_Printf("FX_PlayAuto3D: Unknown or unsupported format.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1080,8 +1027,15 @@ int32_t FX_SetVoiceCallback(int32_t handle, uint32_t callbackval)
|
|||
if (status != MV_Ok)
|
||||
{
|
||||
FX_SetErrorCode(FX_MultiVocError);
|
||||
return(FX_Warning);
|
||||
return FX_Warning;
|
||||
}
|
||||
|
||||
return(FX_Ok);
|
||||
return FX_Ok;
|
||||
}
|
||||
|
||||
int32_t FX_SetPrintf(void (*function)(const char *, ...))
|
||||
{
|
||||
MV_SetPrintf(function);
|
||||
|
||||
return FX_Ok;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -32,9 +32,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define __MULTIVOC_H
|
||||
|
||||
#ifndef UNREFERENCED_PARAMETER
|
||||
#define UNREFERENCED_PARAMETER(x) x=x
|
||||
# define UNREFERENCED_PARAMETER(x) x=x
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define inline __inline
|
||||
#endif
|
||||
|
||||
#ifdef __POWERPC__
|
||||
# define LITTLE16 SWAP16
|
||||
# define LITTLE32 SWAP32
|
||||
#else
|
||||
# define LITTLE16
|
||||
# define LITTLE32
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
# define min(x,y) ((x) < (y) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef max
|
||||
# define max(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define strcasecmp _stricmp
|
||||
# define strncasecmp _strnicmp
|
||||
#elif defined(__QNX__)
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Unknown,
|
||||
Raw,
|
||||
VOC,
|
||||
DemandFeed,
|
||||
WAV,
|
||||
Vorbis,
|
||||
FLAC,
|
||||
} wavedata;
|
||||
|
||||
#define MV_MINVOICEHANDLE 1
|
||||
|
||||
extern int32_t MV_ErrorCode;
|
||||
|
@ -83,38 +121,27 @@ int32_t MV_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *
|
|||
int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayRaw( char *ptr, uint32_t length,
|
||||
unsigned rate, int32_t pitchoffset, int32_t vol, int32_t left,
|
||||
int32_t right, int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayLoopedRaw( char *ptr, uint32_t length,
|
||||
char *loopstart, char *loopend, unsigned rate, int32_t pitchoffset,
|
||||
int32_t vol, int32_t left, int32_t right, int32_t priority,
|
||||
uint32_t callbackval );
|
||||
int32_t MV_PlayWAV( char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol, int32_t left,
|
||||
int32_t right, int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayWAV3D( char *ptr, uint32_t length, int32_t pitchoffset, int32_t angle, int32_t distance,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayLoopedWAV( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t MV_PlayWAV( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
|
||||
uint32_t callbackval );
|
||||
int32_t MV_PlayVOC3D( char *ptr, uint32_t length, int32_t pitchoffset, int32_t angle, int32_t distance,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayVOC( char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayLoopedVOC( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t MV_PlayVOC( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
|
||||
uint32_t callbackval );
|
||||
int32_t MV_PlayVorbis3D( char *ptr, uint32_t length, int32_t pitchoffset, int32_t angle, int32_t distance,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayVorbis( char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayLoopedVorbis( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t MV_PlayVorbis( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
|
||||
uint32_t callbackval );
|
||||
int32_t MV_PlayFLAC3D( char *ptr, uint32_t length, int32_t pitchoffset, int32_t angle, int32_t distance,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayFLAC( char *ptr, uint32_t length, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
|
||||
int32_t priority, uint32_t callbackval );
|
||||
int32_t MV_PlayLoopedFLAC( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t MV_PlayFLAC( char *ptr, uint32_t length, int32_t loopstart, int32_t loopend,
|
||||
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
|
||||
uint32_t callbackval );
|
||||
//void MV_CreateVolumeTable( int32_t index, int32_t volume, int32_t MaxVolume );
|
||||
|
|
|
@ -84,7 +84,7 @@ uint32_t PITCH_GetScale(int32_t pitchoffset)
|
|||
PITCH_Init();
|
||||
|
||||
if (pitchoffset == 0)
|
||||
return(PitchTable[ 0 ][ 0 ]);
|
||||
return PitchTable[ 0 ][ 0 ];
|
||||
|
||||
noteshift = pitchoffset % 1200;
|
||||
if (noteshift < 0)
|
||||
|
|
|
@ -43,15 +43,9 @@
|
|||
# include "vorbis/vorbisfile.h"
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(x,y) ((x) < (y) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#define BLOCKSIZE 0x8000
|
||||
|
||||
|
||||
typedef struct {
|
||||
void * ptr;
|
||||
size_t length;
|
||||
|
@ -280,7 +274,7 @@ static playbackstatus MV_GetNextVorbisBlock
|
|||
voice->BlockLength = 0;
|
||||
voice->length = bytesread << 16; // ???: Should the literal 16 be voice->bits?
|
||||
|
||||
return( KeepPlaying );
|
||||
return KeepPlaying;
|
||||
}
|
||||
|
||||
|
||||
|
@ -312,7 +306,7 @@ int32_t MV_PlayVorbis3D
|
|||
if ( !MV_Installed )
|
||||
{
|
||||
MV_SetErrorCode( MV_NotInstalled );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
if ( distance < 0 )
|
||||
|
@ -330,10 +324,9 @@ int32_t MV_PlayVorbis3D
|
|||
right = MV_PanTable[ angle ][ volume ].right;
|
||||
mid = max( 0, 255 - distance );
|
||||
|
||||
status = MV_PlayVorbis( ptr, ptrlength, pitchoffset, mid, left, right, priority,
|
||||
callbackval );
|
||||
status = MV_PlayVorbis(ptr, ptrlength, -1, -1, pitchoffset, mid, left, right, priority, callbackval);
|
||||
|
||||
return( status );
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,35 +338,6 @@ priority.
|
|||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayVorbis
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t ptrlength,
|
||||
int32_t pitchoffset,
|
||||
int32_t vol,
|
||||
int32_t left,
|
||||
int32_t right,
|
||||
int32_t priority,
|
||||
uint32_t callbackval
|
||||
)
|
||||
|
||||
{
|
||||
int32_t status;
|
||||
|
||||
status = MV_PlayLoopedVorbis( ptr, ptrlength, -1, -1, pitchoffset, vol, left, right,
|
||||
priority, callbackval );
|
||||
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
Function: MV_PlayLoopedVorbis
|
||||
|
||||
Begin playback of sound data with the given sound levels and
|
||||
priority.
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
int32_t MV_PlayLoopedVorbis
|
||||
(
|
||||
char *ptr,
|
||||
uint32_t ptrlength,
|
||||
|
@ -398,7 +362,7 @@ int32_t MV_PlayLoopedVorbis
|
|||
if ( !MV_Installed )
|
||||
{
|
||||
MV_SetErrorCode( MV_NotInstalled );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
vd = (vorbis_data *) malloc( sizeof(vorbis_data) );
|
||||
|
@ -415,7 +379,7 @@ int32_t MV_PlayLoopedVorbis
|
|||
|
||||
status = ov_open_callbacks((void *) vd, &vd->vf, 0, 0, vorbis_callbacks);
|
||||
if (status < 0) {
|
||||
MV_Printf("MV_PlayLoopedVorbis: err %d\n", status);
|
||||
MV_Printf("MV_PlayVorbis: err %d\n", status);
|
||||
MV_SetErrorCode( MV_InvalidVorbisFile );
|
||||
return MV_Error;
|
||||
}
|
||||
|
@ -442,7 +406,7 @@ int32_t MV_PlayLoopedVorbis
|
|||
ov_clear(&vd->vf);
|
||||
free(vd);
|
||||
MV_SetErrorCode( MV_NoVoices );
|
||||
return( MV_Error );
|
||||
return MV_Error;
|
||||
}
|
||||
|
||||
voice->wavetype = Vorbis;
|
||||
|
@ -454,7 +418,6 @@ int32_t MV_PlayLoopedVorbis
|
|||
voice->DemandFeed = NULL;
|
||||
voice->LoopCount = 0;
|
||||
voice->BlockLength = 0;
|
||||
voice->PitchScale = PITCH_GetScale( pitchoffset );
|
||||
voice->length = 0;
|
||||
voice->next = NULL;
|
||||
voice->prev = NULL;
|
||||
|
@ -470,17 +433,14 @@ int32_t MV_PlayLoopedVorbis
|
|||
|
||||
voice->Playing = TRUE;
|
||||
voice->Paused = FALSE;
|
||||
|
||||
voice->SamplingRate = vi->rate;
|
||||
voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate;
|
||||
voice->FixedPointBufferSize = ( voice->RateScale * MV_MIXBUFFERSIZE ) -
|
||||
voice->RateScale;
|
||||
|
||||
MV_SetVoicePitch(voice, vi->rate, pitchoffset);
|
||||
MV_SetVoiceMixMode( voice );
|
||||
|
||||
MV_SetVoiceVolume( voice, vol, left, right );
|
||||
MV_PlayVoice( voice );
|
||||
|
||||
return( voice->handle );
|
||||
return voice->handle;
|
||||
}
|
||||
|
||||
void MV_ReleaseVorbisVoice( VoiceNode * voice )
|
||||
|
|
Loading…
Reference in a new issue