2009-07-27 05:47:50 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1994-1995 Apogee Software, Ltd.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/**********************************************************************
|
|
|
|
module: MULTIVOC.C
|
|
|
|
|
|
|
|
author: James R. Dose
|
|
|
|
date: December 20, 1993
|
|
|
|
|
|
|
|
Routines to provide multichannel digitized sound playback for
|
|
|
|
Sound Blaster compatible sound cards.
|
|
|
|
|
|
|
|
(c) Copyright 1993 James R. Dose. All Rights Reserved.
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "sndcards.h"
|
|
|
|
#include "drivers.h"
|
|
|
|
#include "pitch.h"
|
|
|
|
#include "multivoc.h"
|
|
|
|
#include "_multivc.h"
|
|
|
|
|
2009-07-27 10:46:42 +00:00
|
|
|
static void MV_Mix( VoiceNode *voice, int32_t buffer );
|
|
|
|
static void MV_StopVoice( VoiceNode *voice );
|
|
|
|
static void MV_ServiceVoc( void );
|
|
|
|
|
|
|
|
static VoiceNode *MV_GetVoice( int32_t handle );
|
|
|
|
|
|
|
|
static int16_t *MV_GetVolumeTable( int32_t vol );
|
|
|
|
|
|
|
|
static void MV_CalcVolume( int32_t MaxLevel );
|
|
|
|
static void MV_CalcPanTable( void );
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
/*
|
2009-07-27 05:47:50 +00:00
|
|
|
#define RoundFixed( fixedval, bits ) \
|
|
|
|
( \
|
|
|
|
( \
|
|
|
|
(fixedval) + ( 1 << ( (bits) - 1 ) )\
|
|
|
|
) >> (bits) \
|
|
|
|
)
|
2011-11-01 22:01:54 +00:00
|
|
|
*/
|
2009-07-27 05:47:50 +00:00
|
|
|
#define IS_QUIET( ptr ) ( ( void * )( ptr ) == ( void * )&MV_VolumeTable[ 0 ] )
|
|
|
|
|
|
|
|
static int32_t MV_ReverbLevel;
|
|
|
|
static int32_t MV_ReverbDelay;
|
|
|
|
static VOLUME16 *MV_ReverbTable = NULL;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
static int16_t MV_VolumeTable[ MV_MAXVOLUME + 1 ][ 256 ];
|
|
|
|
Pan MV_PanTable[ MV_NUMPANPOSITIONS ][ MV_MAXVOLUME + 1 ];
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
int32_t MV_Installed = FALSE;
|
2011-11-01 22:02:14 +00:00
|
|
|
static int32_t MV_TotalVolume = MV_MAXTOTALVOLUME;
|
2009-07-27 05:47:50 +00:00
|
|
|
static int32_t MV_MaxVoices = 1;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
static int32_t MV_BufferSize = MV_MIXBUFFERSIZE;
|
2009-07-27 05:47:50 +00:00
|
|
|
static int32_t MV_BufferLength;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
static int32_t MV_NumberOfBuffers = MV_NUMBEROFBUFFERS;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
static int32_t MV_MixMode = MONO_8BIT;
|
|
|
|
static int32_t MV_Channels = 1;
|
|
|
|
static int32_t MV_Bits = 8;
|
|
|
|
|
|
|
|
static int32_t MV_Silence = SILENCE_8BIT;
|
|
|
|
static int32_t MV_SwapLeftRight = FALSE;
|
|
|
|
|
|
|
|
static int32_t MV_RequestedMixRate;
|
|
|
|
int32_t MV_MixRate;
|
|
|
|
|
|
|
|
static int32_t MV_BuffShift;
|
|
|
|
|
|
|
|
static int32_t MV_TotalMemory;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
static int32_t MV_BufferEmpty[ MV_NUMBEROFBUFFERS ];
|
|
|
|
char *MV_MixBuffer[ MV_NUMBEROFBUFFERS + 1 ];
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
static VoiceNode *MV_Voices = NULL;
|
|
|
|
|
|
|
|
static volatile VoiceNode VoiceList;
|
|
|
|
static volatile VoiceNode VoicePool;
|
|
|
|
|
|
|
|
static int32_t MV_MixPage = 0;
|
2011-11-01 22:02:14 +00:00
|
|
|
static int32_t MV_VoiceHandle = MV_MINVOICEHANDLE;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
void (*MV_Printf)(const char *fmt, ...) = NULL;
|
2009-07-27 05:47:50 +00:00
|
|
|
static void (*MV_CallBackFunc)(uint32_t) = NULL;
|
|
|
|
static void (*MV_MixFunction)(VoiceNode *voice, int32_t buffer);
|
|
|
|
|
|
|
|
char *MV_HarshClipTable;
|
|
|
|
char *MV_MixDestination;
|
2011-11-01 22:02:37 +00:00
|
|
|
const int16_t *MV_LeftVolume;
|
|
|
|
const int16_t *MV_RightVolume;
|
2009-07-27 05:47:50 +00:00
|
|
|
int32_t MV_SampleSize = 1;
|
|
|
|
int32_t MV_RightChannelOffset;
|
|
|
|
|
|
|
|
uint32_t MV_MixPosition;
|
|
|
|
|
|
|
|
int32_t MV_ErrorCode = MV_Ok;
|
|
|
|
|
|
|
|
static int32_t lockdepth = 0;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
|
|
|
static inline void DisableInterrupts(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (lockdepth++ > 0)
|
2009-12-05 09:22:43 +00:00
|
|
|
return;
|
2009-07-27 05:47:50 +00:00
|
|
|
SoundDriver_Lock();
|
2009-12-05 09:22:43 +00:00
|
|
|
return;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
static inline void RestoreInterrupts(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (--lockdepth > 0)
|
|
|
|
return;
|
|
|
|
SoundDriver_Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_ErrorString
|
|
|
|
|
|
|
|
Returns a pointer to the error message associated with an error
|
|
|
|
number. A -1 returns a pointer the current error.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
const char *MV_ErrorString(int32_t ErrorNumber)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
switch (ErrorNumber)
|
|
|
|
{
|
|
|
|
case MV_Warning :
|
|
|
|
case MV_Error :
|
2010-06-22 21:50:01 +00:00
|
|
|
return MV_ErrorString(MV_ErrorCode);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_Ok :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Multivoc ok.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_UnsupportedCard :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Selected sound card is not supported by Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_NotInstalled :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Multivoc not installed.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_DriverError :
|
2010-06-22 21:50:01 +00:00
|
|
|
return SoundDriver_ErrorString(SoundDriver_GetError());
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_NoVoices :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "No free voices available to Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_NoMem :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Out of memory in Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_VoiceNotFound :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "No voice with matching handle found.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_InvalidVOCFile :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Invalid VOC file passed in to Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_InvalidWAVFile :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Invalid WAV file passed in to Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
case MV_InvalidVorbisFile :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Invalid OggVorbis file passed in to Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-12-29 10:57:24 +00:00
|
|
|
case MV_InvalidFLACFile :
|
|
|
|
return "Invalid FLAC file passed in to Multivoc.";
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
case MV_InvalidMixMode :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Invalid mix mode request in Multivoc.";
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
default :
|
2010-06-22 21:50:01 +00:00
|
|
|
return "Unknown Multivoc error code.";
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_Mix
|
|
|
|
|
|
|
|
Mixes the sound into the buffer.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
static void MV_Mix(VoiceNode *voice,int32_t buffer)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2011-11-01 22:02:37 +00:00
|
|
|
const char *start;
|
2009-07-27 05:47:50 +00:00
|
|
|
int32_t length;
|
|
|
|
int32_t voclength;
|
|
|
|
uint32_t position;
|
|
|
|
uint32_t rate;
|
|
|
|
uint32_t FixedPointBufferSize;
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
/* cheap fix for a crash under 64-bit linux */
|
|
|
|
/* v v v v */
|
2009-10-03 14:34:05 +00:00
|
|
|
if (voice->length == 0 && (!voice->GetSound || voice->GetSound(voice) != KeepPlaying))
|
2009-07-27 05:47:50 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
length = MV_MIXBUFFERSIZE;
|
2009-07-27 05:47:50 +00:00
|
|
|
FixedPointBufferSize = voice->FixedPointBufferSize;
|
|
|
|
|
|
|
|
MV_MixDestination = MV_MixBuffer[ buffer ];
|
|
|
|
MV_LeftVolume = voice->LeftVolume;
|
|
|
|
MV_RightVolume = voice->RightVolume;
|
|
|
|
|
|
|
|
if ((MV_Channels == 2) && (IS_QUIET(MV_LeftVolume)))
|
|
|
|
{
|
|
|
|
MV_LeftVolume = MV_RightVolume;
|
|
|
|
MV_MixDestination += MV_RightChannelOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this voice to the mix
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
start = voice->sound;
|
|
|
|
rate = voice->RateScale;
|
|
|
|
position = voice->position;
|
|
|
|
|
|
|
|
// Check if the last sample in this buffer would be
|
|
|
|
// beyond the length of the sample block
|
|
|
|
if ((position + FixedPointBufferSize) >= voice->length)
|
|
|
|
{
|
|
|
|
if (position < voice->length)
|
|
|
|
{
|
|
|
|
voclength = (voice->length - position + rate - voice->channels) / rate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
voice->GetSound(voice);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
voclength = length;
|
|
|
|
|
|
|
|
if (voice->mix)
|
|
|
|
voice->mix(position, rate, start, voclength);
|
|
|
|
|
|
|
|
voice->position = MV_MixPosition;
|
|
|
|
|
|
|
|
length -= voclength;
|
|
|
|
|
|
|
|
if (voice->position >= voice->length)
|
|
|
|
{
|
|
|
|
// Get the next block of sound
|
|
|
|
if (voice->GetSound(voice) != KeepPlaying)
|
|
|
|
return;
|
|
|
|
|
2009-10-03 14:34:05 +00:00
|
|
|
if (length > (voice->channels - 1))
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
// Get the position of the last sample in the buffer
|
|
|
|
FixedPointBufferSize = voice->RateScale * (length - voice->channels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_PlayVoice
|
|
|
|
|
|
|
|
Adds a voice to the play list.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
void MV_PlayVoice(VoiceNode *voice)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
LL_SortedInsertion(&VoiceList, voice, prev, next, VoiceNode, priority);
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_StopVoice
|
|
|
|
|
|
|
|
Removes the voice from the play list and adds it to the free list.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_StopVoice(VoiceNode *voice)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// move the voice from the play list to the free list
|
|
|
|
LL_Remove(voice, next, prev);
|
|
|
|
LL_Add((VoiceNode*) &VoicePool, voice, next, prev);
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-06-02 00:01:36 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
2009-07-27 05:47:50 +00:00
|
|
|
if (voice->wavetype == Vorbis)
|
|
|
|
MV_ReleaseVorbisVoice(voice);
|
2012-05-01 12:40:53 +00:00
|
|
|
#endif
|
2012-12-29 10:57:24 +00:00
|
|
|
#ifdef HAVE_FLAC
|
|
|
|
if (voice->wavetype == FLAC)
|
|
|
|
MV_ReleaseFLACVoice(voice);
|
|
|
|
#endif
|
2010-06-22 21:50:01 +00:00
|
|
|
|
|
|
|
voice->handle = 0;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_ServiceVoc
|
|
|
|
|
|
|
|
Starts playback of the waiting buffer and mixes the next one.
|
|
|
|
|
|
|
|
JBF: no synchronisation happens inside MV_ServiceVoc nor the
|
|
|
|
supporting functions it calls. This would cause a deadlock
|
|
|
|
between the mixer thread in the driver vs the nested
|
|
|
|
locking in the user-space functions of MultiVoc. The call
|
|
|
|
to MV_ServiceVoc is synchronised in the driver.
|
|
|
|
---------------------------------------------------------------------*/
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_ServiceVoc(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
VoiceNode *next;
|
|
|
|
//int32_t flags;
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t iter;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// Toggle which buffer we'll mix next
|
2010-06-22 21:50:01 +00:00
|
|
|
if (++MV_MixPage >= MV_NumberOfBuffers)
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_MixPage -= MV_NumberOfBuffers;
|
|
|
|
|
|
|
|
if (MV_ReverbLevel == 0)
|
|
|
|
{
|
|
|
|
// Initialize buffer
|
|
|
|
//Commented out so that the buffer is always cleared.
|
|
|
|
//This is so the guys at Echo Speech can mix into the
|
|
|
|
//buffer even when no sounds are playing.
|
2010-07-22 20:29:09 +00:00
|
|
|
if (!MV_BufferEmpty[MV_MixPage])
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
ClearBuffer_DW(MV_MixBuffer[ MV_MixPage ], MV_Silence, MV_BufferSize >> 2);
|
|
|
|
MV_BufferEmpty[ MV_MixPage ] = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
char *source;
|
|
|
|
char *dest;
|
|
|
|
int32_t count;
|
|
|
|
int32_t length;
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
end = MV_MixBuffer[ 0 ] + MV_BufferLength;
|
2009-07-27 05:47:50 +00:00
|
|
|
dest = MV_MixBuffer[ MV_MixPage ];
|
|
|
|
source = MV_MixBuffer[ MV_MixPage ] - MV_ReverbDelay;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
if (source < MV_MixBuffer[ 0 ])
|
|
|
|
source += MV_BufferLength;
|
|
|
|
|
|
|
|
length = MV_BufferSize;
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
count = length;
|
|
|
|
if (source + count > end)
|
|
|
|
count = end - source;
|
|
|
|
|
|
|
|
if (MV_Bits == 16)
|
|
|
|
{
|
|
|
|
if (MV_ReverbTable != NULL)
|
|
|
|
MV_16BitReverb(source, dest, MV_ReverbTable, count / 2);
|
|
|
|
else
|
|
|
|
MV_16BitReverbFast(source, dest, count / 2, MV_ReverbLevel);
|
|
|
|
}
|
2012-12-29 10:58:09 +00:00
|
|
|
else // if (MV_Bits == 8)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (MV_ReverbTable != NULL)
|
|
|
|
MV_8BitReverb((int8_t *) source, (int8_t *) dest, MV_ReverbTable, count);
|
|
|
|
else
|
|
|
|
MV_8BitReverbFast((int8_t *) source, (int8_t *) dest, count, MV_ReverbLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we go through the loop again, it means that we've wrapped around the buffer
|
|
|
|
source = MV_MixBuffer[ 0 ];
|
|
|
|
dest += count;
|
|
|
|
length -= count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Play any waiting voices
|
2009-12-05 09:22:43 +00:00
|
|
|
//DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
if (!VoiceList.next || (voice = VoiceList.next) == &VoiceList)
|
2009-07-27 05:47:50 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
iter = 0;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
do
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
next = voice->next;
|
2010-06-22 21:50:01 +00:00
|
|
|
iter++;
|
|
|
|
|
|
|
|
if (iter > MV_MaxVoices && MV_Printf)
|
|
|
|
MV_Printf("more iterations than voices! iter: %d\n",iter);
|
2009-12-05 09:22:43 +00:00
|
|
|
|
2011-10-03 17:43:16 +00:00
|
|
|
if (voice->Paused)
|
|
|
|
continue;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
MV_BufferEmpty[ MV_MixPage ] = FALSE;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
MV_MixFunction(voice, MV_MixPage);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
// Is this voice done?
|
2009-12-05 09:22:43 +00:00
|
|
|
if (!voice->Playing)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
//JBF: prevent a deadlock caused by MV_StopVoice grabbing the mutex again
|
|
|
|
//MV_StopVoice( voice );
|
|
|
|
LL_Remove(voice, next, prev);
|
|
|
|
LL_Add((VoiceNode*) &VoicePool, voice, next, prev);
|
2012-06-02 00:01:36 +00:00
|
|
|
#ifdef HAVE_VORBIS
|
2009-12-05 09:22:43 +00:00
|
|
|
if (voice->wavetype == Vorbis)
|
|
|
|
MV_ReleaseVorbisVoice(voice);
|
2012-12-29 10:57:24 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC
|
|
|
|
if (voice->wavetype == FLAC)
|
|
|
|
MV_ReleaseFLACVoice(voice);
|
2012-05-01 12:40:53 +00:00
|
|
|
#endif
|
2010-06-22 21:50:01 +00:00
|
|
|
voice->handle = 0;
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
if (MV_CallBackFunc)
|
|
|
|
MV_CallBackFunc(voice->callbackval);
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 09:22:43 +00:00
|
|
|
while ((voice = next) != &VoiceList);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
//RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetVoice
|
|
|
|
|
|
|
|
Locates the voice with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static VoiceNode *MV_GetVoice(int32_t handle)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
if (handle < MV_MINVOICEHANDLE || handle > MV_MaxVoices)
|
2010-06-22 21:50:01 +00:00
|
|
|
{
|
|
|
|
if (MV_Printf)
|
|
|
|
MV_Printf("MV_GetVoice(): bad handle (%d)!\n", handle);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next)
|
|
|
|
{
|
|
|
|
if (handle == voice->handle)
|
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
RestoreInterrupts();
|
|
|
|
return voice;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2010-06-22 21:50:01 +00:00
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
|
|
|
return NULL;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_VoicePlaying
|
|
|
|
|
|
|
|
Checks if the voice associated with the specified handle is
|
|
|
|
playing.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_VoicePlaying(int32_t handle)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return FALSE;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
return MV_GetVoice(handle) ? TRUE : FALSE;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_KillAllVoices
|
|
|
|
|
|
|
|
Stops output of all currently active voices.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_KillAllVoices(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
VoiceNode * voice;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
DisableInterrupts();
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
if (&VoiceList == VoiceList.next)
|
2010-06-22 21:50:01 +00:00
|
|
|
{
|
|
|
|
RestoreInterrupts();
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
2009-12-05 09:22:43 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
voice = VoiceList.prev;
|
2009-07-29 20:26:03 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
// Remove all the voices from the list
|
2009-12-05 09:22:43 +00:00
|
|
|
while (voice != &VoiceList)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
if (voice->priority == MV_MUSIC_PRIORITY)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
voice = voice->prev;
|
|
|
|
continue;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
2009-12-05 09:22:43 +00:00
|
|
|
|
|
|
|
MV_Kill(voice->handle);
|
|
|
|
voice = VoiceList.prev;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-29 20:26:03 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_Kill
|
|
|
|
|
|
|
|
Stops output of the voice associated with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_Kill(int32_t handle)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
uint32_t callbackval;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if ((voice = MV_GetVoice(handle)) == NULL)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
callbackval = voice->callbackval;
|
|
|
|
|
|
|
|
MV_StopVoice(voice);
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
if (MV_CallBackFunc)
|
|
|
|
MV_CallBackFunc(callbackval);
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_VoicesPlaying
|
|
|
|
|
|
|
|
Determines the number of currently active voices.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_VoicesPlaying(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t NumVoices = 0;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return 0;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
for (voice = VoiceList.next; voice != &VoiceList; voice = voice->next)
|
|
|
|
NumVoices++;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return NumVoices;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_AllocVoice
|
|
|
|
|
|
|
|
Retrieve an inactive or lower priority voice for output.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
VoiceNode *MV_AllocVoice(int32_t priority)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
VoiceNode *node;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// Check if we have any free voices
|
|
|
|
if (LL_Empty(&VoicePool, next, prev))
|
|
|
|
{
|
|
|
|
// check if we have a higher priority than a voice that is playing.
|
2011-03-04 08:50:58 +00:00
|
|
|
for (voice = node = VoiceList.next; node != &VoiceList; node = node->next)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (node->priority < voice->priority)
|
|
|
|
voice = node;
|
|
|
|
}
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
if (priority >= voice->priority && voice != &VoiceList && voice->handle >= MV_MINVOICEHANDLE)
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_Kill(voice->handle);
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
if (LL_Empty(&VoicePool, next, prev))
|
|
|
|
{
|
|
|
|
// No free voices
|
|
|
|
RestoreInterrupts();
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice = VoicePool.next;
|
|
|
|
LL_Remove(voice, next, prev);
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_VoiceHandle = MV_MINVOICEHANDLE;
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
// Find a free voice handle
|
|
|
|
do
|
|
|
|
{
|
2011-11-01 22:02:14 +00:00
|
|
|
if (++MV_VoiceHandle < MV_MINVOICEHANDLE || MV_VoiceHandle > MV_MaxVoices)
|
|
|
|
MV_VoiceHandle = MV_MINVOICEHANDLE;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
while (MV_VoicePlaying(MV_VoiceHandle));
|
|
|
|
|
|
|
|
voice->handle = MV_VoiceHandle;
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
return voice;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_VoiceAvailable
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
Checks if a voice can be played at the specified priority.
|
2009-07-27 05:47:50 +00:00
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_VoiceAvailable(int32_t priority)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
VoiceNode *node;
|
|
|
|
|
|
|
|
// Check if we have any free voices
|
|
|
|
if (!LL_Empty(&VoicePool, next, prev))
|
2010-06-22 21:50:01 +00:00
|
|
|
return TRUE;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// check if we have a higher priority than a voice that is playing.
|
2010-06-22 21:50:01 +00:00
|
|
|
for (voice = node = VoiceList.next; node != &VoiceList; node = node->next)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
if (node->priority < voice->priority)
|
|
|
|
voice = node;
|
|
|
|
}
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
if ((voice == &VoiceList) || (priority < voice->priority))
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
RestoreInterrupts();
|
2011-03-04 08:50:58 +00:00
|
|
|
return FALSE;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
RestoreInterrupts();
|
2011-03-04 08:50:58 +00:00
|
|
|
return TRUE;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetVoicePitch
|
|
|
|
|
|
|
|
Sets the pitch for the specified voice.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
void MV_SetVoicePitch
|
2009-07-27 05:47:50 +00:00
|
|
|
(
|
|
|
|
VoiceNode *voice,
|
|
|
|
uint32_t rate,
|
|
|
|
int32_t pitchoffset
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
voice->SamplingRate = rate;
|
|
|
|
voice->PitchScale = PITCH_GetScale(pitchoffset);
|
|
|
|
voice->RateScale = (rate * voice->PitchScale) / MV_MixRate;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
// Multiply by MV_MIXBUFFERSIZE - 1
|
|
|
|
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) -
|
2009-07-27 05:47:50 +00:00
|
|
|
voice->RateScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetPitch
|
|
|
|
|
|
|
|
Sets the pitch for the voice associated with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_SetPitch
|
|
|
|
(
|
|
|
|
int32_t handle,
|
|
|
|
int32_t pitchoffset
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice = MV_GetVoice(handle);
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetVoicePitch(voice, voice->SamplingRate, pitchoffset);
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetFrequency
|
|
|
|
|
|
|
|
Sets the frequency for the voice associated with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_SetFrequency
|
|
|
|
(
|
|
|
|
int32_t handle,
|
|
|
|
int32_t frequency
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice = MV_GetVoice(handle);
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetVoicePitch(voice, frequency, 0);
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetVolumeTable
|
|
|
|
|
|
|
|
Returns a pointer to the volume table associated with the specified
|
|
|
|
volume.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static int16_t *MV_GetVolumeTable(int32_t vol)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t volume;
|
|
|
|
int16_t *table;
|
|
|
|
|
|
|
|
volume = MIX_VOLUME(vol);
|
|
|
|
|
|
|
|
table = (int16_t *) &MV_VolumeTable[ volume ];
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return table;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetVoiceMixMode
|
|
|
|
|
|
|
|
Selects which method should be used to mix the voice.
|
|
|
|
|
|
|
|
8Bit 16Bit 8Bit 16Bit | 8Bit 16Bit 8Bit 16Bit |
|
|
|
|
Mono Mono Ster Ster | Mono Mono Ster Ster | Mixer
|
|
|
|
Out Out Out Out | In In In In |
|
|
|
|
--------------------------+---------------------------+-------------
|
|
|
|
X | X | Mix8BitMono16
|
|
|
|
X | X | Mix8BitMono
|
|
|
|
X | X | Mix8BitStereo16
|
|
|
|
X | X | Mix8BitStereo
|
|
|
|
X | X | Mix16BitMono16
|
|
|
|
X | X | Mix16BitMono
|
|
|
|
X | X | Mix16BitStereo16
|
|
|
|
X | X | Mix16BitStereo
|
|
|
|
--------------------------+---------------------------+-------------
|
|
|
|
X | X | Mix16BitStereo16Stereo
|
|
|
|
X | X | Mix16BitStereo8Stereo
|
2011-11-01 22:01:54 +00:00
|
|
|
X | X | Mix8BitStereo16Stereo
|
2009-07-27 05:47:50 +00:00
|
|
|
X | X | Mix8BitStereo8Stereo
|
2011-11-01 22:01:54 +00:00
|
|
|
X | X | Mix16BitMono16Stereo
|
2009-07-27 05:47:50 +00:00
|
|
|
X | X | Mix16BitMono8Stereo
|
|
|
|
X | X | Mix8BitMono16Stereo
|
|
|
|
X | X | Mix8BitMono8Stereo
|
|
|
|
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetVoiceMixMode(VoiceNode *voice)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
//int32_t flags;
|
|
|
|
int32_t test;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
//DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
test = T_DEFAULT;
|
|
|
|
if (MV_Bits == 8)
|
|
|
|
{
|
|
|
|
test |= T_8BITS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MV_Channels == 1)
|
|
|
|
{
|
|
|
|
test |= T_MONO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_QUIET(voice->RightVolume))
|
|
|
|
{
|
|
|
|
test |= T_RIGHTQUIET;
|
|
|
|
}
|
|
|
|
else if (IS_QUIET(voice->LeftVolume))
|
|
|
|
{
|
|
|
|
test |= T_LEFTQUIET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (voice->bits == 16)
|
|
|
|
{
|
|
|
|
test |= T_16BITSOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (voice->channels == 2)
|
|
|
|
{
|
|
|
|
test |= T_STEREOSOURCE;
|
|
|
|
test &= ~(T_RIGHTQUIET | T_LEFTQUIET);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (test)
|
|
|
|
{
|
|
|
|
case T_8BITS | T_MONO | T_16BITSOURCE :
|
|
|
|
voice->mix = MV_Mix8BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_MONO :
|
|
|
|
voice->mix = MV_Mix8BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_16BITSOURCE | T_LEFTQUIET :
|
|
|
|
MV_LeftVolume = MV_RightVolume;
|
|
|
|
voice->mix = MV_Mix8BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_LEFTQUIET :
|
|
|
|
MV_LeftVolume = MV_RightVolume;
|
|
|
|
voice->mix = MV_Mix8BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_16BITSOURCE | T_RIGHTQUIET :
|
|
|
|
voice->mix = MV_Mix8BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_RIGHTQUIET :
|
|
|
|
voice->mix = MV_Mix8BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS | T_16BITSOURCE :
|
|
|
|
voice->mix = MV_Mix8BitStereo16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_8BITS :
|
|
|
|
voice->mix = MV_Mix8BitStereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MONO | T_16BITSOURCE :
|
|
|
|
voice->mix = MV_Mix16BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_MONO :
|
|
|
|
voice->mix = MV_Mix16BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_LEFTQUIET :
|
|
|
|
MV_LeftVolume = MV_RightVolume;
|
|
|
|
voice->mix = MV_Mix16BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LEFTQUIET :
|
|
|
|
MV_LeftVolume = MV_RightVolume;
|
|
|
|
voice->mix = MV_Mix16BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_RIGHTQUIET :
|
|
|
|
voice->mix = MV_Mix16BitMono16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_RIGHTQUIET :
|
|
|
|
voice->mix = MV_Mix16BitMono;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE :
|
|
|
|
voice->mix = MV_Mix16BitStereo16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SIXTEENBIT_STEREO :
|
|
|
|
voice->mix = MV_Mix16BitStereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_STEREOSOURCE:
|
|
|
|
voice->mix = MV_Mix16BitStereo16Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_STEREOSOURCE | T_8BITS:
|
|
|
|
voice->mix = MV_Mix8BitStereo16Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_STEREOSOURCE | T_MONO:
|
|
|
|
voice->mix = MV_Mix16BitMono16Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_16BITSOURCE | T_STEREOSOURCE | T_8BITS | T_MONO:
|
|
|
|
voice->mix = MV_Mix8BitMono16Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STEREOSOURCE:
|
|
|
|
voice->mix = MV_Mix16BitStereo8Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STEREOSOURCE | T_8BITS:
|
|
|
|
voice->mix = MV_Mix8BitStereo8Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STEREOSOURCE | T_MONO:
|
|
|
|
voice->mix = MV_Mix16BitMono8Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STEREOSOURCE | T_8BITS | T_MONO:
|
|
|
|
voice->mix = MV_Mix8BitMono8Stereo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
voice->mix = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//RestoreInterrupts( flags );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetVoiceVolume
|
|
|
|
|
|
|
|
Sets the stereo and mono volume level of the voice associated
|
|
|
|
with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void MV_SetVoiceVolume
|
|
|
|
(
|
|
|
|
VoiceNode *voice,
|
|
|
|
int32_t vol,
|
|
|
|
int32_t left,
|
|
|
|
int32_t right
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (MV_Channels == 1)
|
|
|
|
{
|
|
|
|
left = vol;
|
|
|
|
right = vol;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MV_SwapLeftRight)
|
|
|
|
{
|
|
|
|
// SBPro uses reversed panning
|
|
|
|
voice->LeftVolume = MV_GetVolumeTable(right);
|
|
|
|
voice->RightVolume = MV_GetVolumeTable(left);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
voice->LeftVolume = MV_GetVolumeTable(left);
|
|
|
|
voice->RightVolume = MV_GetVolumeTable(right);
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetVoiceMixMode(voice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_PauseVoice
|
|
|
|
|
|
|
|
Pauses the voice associated with the specified handle
|
|
|
|
without stoping the sound.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_PauseVoice
|
|
|
|
(
|
|
|
|
int32_t handle,
|
|
|
|
int32_t pause
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
voice = MV_GetVoice(handle);
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Warning;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice->Paused = pause;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_EndLooping
|
|
|
|
|
|
|
|
Stops the voice associated with the specified handle from looping
|
|
|
|
without stoping the sound.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_EndLooping(int32_t handle)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
voice = MV_GetVoice(handle);
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Warning;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice->LoopCount = 0;
|
|
|
|
voice->LoopStart = NULL;
|
|
|
|
voice->LoopEnd = NULL;
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetPan
|
|
|
|
|
|
|
|
Sets the stereo and mono volume level of the voice associated
|
|
|
|
with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_SetPan
|
|
|
|
(
|
|
|
|
int32_t handle,
|
|
|
|
int32_t vol,
|
|
|
|
int32_t left,
|
|
|
|
int32_t right
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice = MV_GetVoice(handle);
|
|
|
|
if (voice == NULL)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Warning;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetVoiceVolume(voice, vol, left, right);
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_Pan3D
|
|
|
|
|
|
|
|
Set the angle and distance from the listener of the voice associated
|
|
|
|
with the specified handle.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_Pan3D
|
|
|
|
(
|
|
|
|
int32_t handle,
|
|
|
|
int32_t angle,
|
|
|
|
int32_t distance
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t left;
|
|
|
|
int32_t right;
|
|
|
|
int32_t mid;
|
|
|
|
int32_t volume;
|
|
|
|
int32_t status;
|
|
|
|
|
|
|
|
if (distance < 0)
|
|
|
|
{
|
|
|
|
distance = -distance;
|
2011-11-01 22:02:14 +00:00
|
|
|
angle += MV_NUMPANPOSITIONS / 2;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
volume = MIX_VOLUME(distance);
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
// Ensure angle is within 0 - 127
|
|
|
|
angle &= MV_MAXPANPOSITION;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
left = MV_PanTable[ angle ][ volume ].left;
|
|
|
|
right = MV_PanTable[ angle ][ volume ].right;
|
|
|
|
mid = max(0, 255 - distance);
|
|
|
|
|
|
|
|
status = MV_SetPan(handle, mid, left, right);
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return status;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetReverb
|
|
|
|
|
|
|
|
Sets the level of reverb to add to mix.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetReverb(int32_t reverb)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_ReverbLevel = MIX_VOLUME(reverb);
|
|
|
|
MV_ReverbTable = &MV_VolumeTable[ MV_ReverbLevel ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetFastReverb
|
|
|
|
|
|
|
|
Sets the level of reverb to add to mix.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetFastReverb(int32_t reverb)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_ReverbLevel = max(0, min(16, reverb));
|
|
|
|
MV_ReverbTable = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetMaxReverbDelay
|
|
|
|
|
|
|
|
Returns the maximum delay time for reverb.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_GetMaxReverbDelay(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t maxdelay;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
maxdelay = MV_MIXBUFFERSIZE * MV_NumberOfBuffers;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
return maxdelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetReverbDelay
|
|
|
|
|
|
|
|
Returns the current delay time for reverb.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_GetReverbDelay(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
return MV_ReverbDelay / MV_SampleSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetReverbDelay
|
|
|
|
|
|
|
|
Sets the delay level of reverb to add to mix.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetReverbDelay(int32_t delay)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t maxdelay;
|
|
|
|
|
|
|
|
maxdelay = MV_GetMaxReverbDelay();
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_ReverbDelay = max(MV_MIXBUFFERSIZE, min(delay, maxdelay));
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_ReverbDelay *= MV_SampleSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetMixMode
|
|
|
|
|
|
|
|
Prepares Multivoc to play stereo of mono digitized sounds.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static int32_t MV_SetMixMode
|
2009-07-27 05:47:50 +00:00
|
|
|
(
|
|
|
|
int32_t numchannels,
|
|
|
|
int32_t samplebits
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t mode;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
if (numchannels == 2)
|
|
|
|
{
|
|
|
|
mode |= STEREO;
|
|
|
|
}
|
|
|
|
if (samplebits == 16)
|
|
|
|
{
|
|
|
|
mode |= SIXTEEN_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_MixMode = mode;
|
|
|
|
|
|
|
|
MV_Channels = 1;
|
|
|
|
if (MV_MixMode & STEREO)
|
|
|
|
{
|
|
|
|
MV_Channels = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_Bits = 8;
|
|
|
|
if (MV_MixMode & SIXTEEN_BIT)
|
|
|
|
{
|
|
|
|
MV_Bits = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_BuffShift = 7 + MV_Channels;
|
|
|
|
MV_SampleSize = sizeof(MONO8) * MV_Channels;
|
|
|
|
|
|
|
|
if (MV_Bits == 8)
|
|
|
|
{
|
|
|
|
MV_Silence = SILENCE_8BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MV_Silence = SILENCE_16BIT;
|
|
|
|
MV_BuffShift += 1;
|
|
|
|
MV_SampleSize *= 2;
|
|
|
|
}
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_BufferSize = MV_MIXBUFFERSIZE * MV_SampleSize;
|
|
|
|
MV_NumberOfBuffers = MV_TOTALBUFFERSIZE / MV_BufferSize;
|
|
|
|
MV_BufferLength = MV_TOTALBUFFERSIZE;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
MV_RightChannelOffset = MV_SampleSize / 2;
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_StartPlayback
|
|
|
|
|
|
|
|
Starts the sound playback engine.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static int32_t MV_StartPlayback(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t status;
|
|
|
|
int32_t buffer;
|
|
|
|
|
|
|
|
// Initialize the buffers
|
2011-11-01 22:02:14 +00:00
|
|
|
ClearBuffer_DW(MV_MixBuffer[ 0 ], MV_Silence, MV_TOTALBUFFERSIZE >> 2);
|
2009-07-27 05:47:50 +00:00
|
|
|
for (buffer = 0; buffer < MV_NumberOfBuffers; buffer++)
|
|
|
|
{
|
|
|
|
MV_BufferEmpty[ buffer ] = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the mix buffer variables
|
|
|
|
MV_MixPage = 1;
|
|
|
|
|
|
|
|
MV_MixFunction = MV_Mix;
|
|
|
|
|
|
|
|
//JIM
|
|
|
|
// MV_MixRate = MV_RequestedMixRate;
|
2012-12-29 10:59:21 +00:00
|
|
|
// return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// Start playback
|
|
|
|
status = SoundDriver_BeginPlayback(MV_MixBuffer[0], MV_BufferSize,
|
|
|
|
MV_NumberOfBuffers, MV_ServiceVoc);
|
|
|
|
if (status != MV_Ok)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_DriverError);
|
|
|
|
return MV_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_MixRate = MV_RequestedMixRate;
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_StopPlayback
|
|
|
|
|
|
|
|
Stops the sound playback engine.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_StopPlayback(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
VoiceNode *next;
|
|
|
|
|
|
|
|
// Stop sound playback
|
|
|
|
SoundDriver_StopPlayback();
|
|
|
|
|
|
|
|
// Make sure all callbacks are done.
|
2009-12-05 09:22:43 +00:00
|
|
|
DisableInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
for (voice = VoiceList.next; voice != &VoiceList; voice = next)
|
|
|
|
{
|
|
|
|
next = voice->next;
|
|
|
|
|
|
|
|
MV_StopVoice(voice);
|
|
|
|
|
|
|
|
if (MV_CallBackFunc)
|
|
|
|
MV_CallBackFunc(voice->callbackval);
|
|
|
|
}
|
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
RestoreInterrupts();
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_CreateVolumeTable
|
|
|
|
|
|
|
|
Create the table used to convert sound data to a specific volume
|
|
|
|
level.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_CreateVolumeTable
|
2009-07-27 05:47:50 +00:00
|
|
|
(
|
|
|
|
int32_t index,
|
|
|
|
int32_t volume,
|
|
|
|
int32_t MaxVolume
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
int32_t level;
|
|
|
|
int32_t i;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
level = (volume * MaxVolume) / MV_MAXTOTALVOLUME;
|
2009-07-27 05:47:50 +00:00
|
|
|
if (MV_Bits == 16)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 65536; i += 256)
|
|
|
|
{
|
|
|
|
val = i - 0x8000;
|
|
|
|
val *= level;
|
2011-11-01 22:02:14 +00:00
|
|
|
val /= MV_MAXVOLUME;
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_VolumeTable[ index ][ i / 256 ] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
val = i - 0x80;
|
|
|
|
val *= level;
|
2011-11-01 22:02:14 +00:00
|
|
|
val /= MV_MAXVOLUME;
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_VolumeTable[ volume ][ i ] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_CalcVolume
|
|
|
|
|
|
|
|
Create the table used to convert sound data to a specific volume
|
|
|
|
level.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_CalcVolume(int32_t MaxVolume)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t volume;
|
|
|
|
|
|
|
|
for (volume = 0; volume < 128; volume++)
|
|
|
|
{
|
|
|
|
MV_HarshClipTable[ volume ] = 0;
|
|
|
|
MV_HarshClipTable[ volume + 384 ] = 255;
|
|
|
|
}
|
|
|
|
for (volume = 0; volume < 256; volume++)
|
|
|
|
{
|
|
|
|
MV_HarshClipTable[ volume + 128 ] = volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each volume level, create a translation table with the
|
|
|
|
// appropriate volume calculated.
|
2011-11-01 22:02:14 +00:00
|
|
|
for (volume = 0; volume <= MV_MAXVOLUME; volume++)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_CreateVolumeTable(volume, volume, MaxVolume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_CalcPanTable
|
|
|
|
|
|
|
|
Create the table used to determine the stereo volume level of
|
|
|
|
a sound located at a specific angle and distance from the listener.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
static void MV_CalcPanTable(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t level;
|
|
|
|
int32_t angle;
|
|
|
|
int32_t distance;
|
|
|
|
int32_t HalfAngle;
|
|
|
|
int32_t ramp;
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
HalfAngle = (MV_NUMPANPOSITIONS / 2);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
for (distance = 0; distance <= MV_MAXVOLUME; distance++)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2011-11-01 22:02:14 +00:00
|
|
|
level = (255 * (MV_MAXVOLUME - distance)) / MV_MAXVOLUME;
|
2009-07-27 05:47:50 +00:00
|
|
|
for (angle = 0; angle <= HalfAngle / 2; angle++)
|
|
|
|
{
|
|
|
|
ramp = level - ((level * angle) /
|
2011-11-01 22:02:14 +00:00
|
|
|
(MV_NUMPANPOSITIONS / 4));
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
MV_PanTable[ angle ][ distance ].left = ramp;
|
|
|
|
MV_PanTable[ HalfAngle - angle ][ distance ].left = ramp;
|
|
|
|
MV_PanTable[ HalfAngle + angle ][ distance ].left = level;
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_PanTable[ MV_MAXPANPOSITION - angle ][ distance ].left = level;
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
MV_PanTable[ angle ][ distance ].right = level;
|
|
|
|
MV_PanTable[ HalfAngle - angle ][ distance ].right = level;
|
|
|
|
MV_PanTable[ HalfAngle + angle ][ distance ].right = ramp;
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_PanTable[ MV_MAXPANPOSITION - angle ][ distance ].right = ramp;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetVolume
|
|
|
|
|
|
|
|
Sets the volume of digitized sound playback.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetVolume(int32_t volume)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
volume = max(0, volume);
|
2011-11-01 22:02:14 +00:00
|
|
|
volume = min(volume, MV_MAXTOTALVOLUME);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
MV_TotalVolume = volume;
|
|
|
|
|
|
|
|
// Calculate volume table
|
|
|
|
MV_CalcVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetVolume
|
|
|
|
|
|
|
|
Returns the volume of digitized sound playback.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_GetVolume(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_TotalVolume;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetCallBack
|
|
|
|
|
|
|
|
Set the function to call when a voice stops.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetCallBack(void (*function)(uint32_t))
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_CallBackFunc = function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_SetReverseStereo
|
|
|
|
|
|
|
|
Set the orientation of the left and right channels.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
void MV_SetReverseStereo(int32_t setting)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_SwapLeftRight = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_GetReverseStereo
|
|
|
|
|
|
|
|
Returns the orientation of the left and right channels.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_GetReverseStereo(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_SwapLeftRight;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_Init
|
|
|
|
|
|
|
|
Perform the initialization of variables and memory used by
|
|
|
|
Multivoc.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t MV_Init
|
|
|
|
(
|
|
|
|
int32_t soundcard,
|
|
|
|
int32_t MixRate,
|
|
|
|
int32_t Voices,
|
|
|
|
int32_t numchannels,
|
|
|
|
int32_t samplebits,
|
|
|
|
void * initdata
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
int32_t status;
|
|
|
|
int32_t buffer;
|
|
|
|
int32_t index;
|
|
|
|
|
|
|
|
if (MV_Installed)
|
|
|
|
{
|
|
|
|
MV_Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetErrorCode(MV_Ok);
|
|
|
|
|
2012-02-12 13:47:15 +00:00
|
|
|
// MV_TotalMemory + 2: FIXME
|
|
|
|
// Thread 3:
|
|
|
|
// Invalid read of size 2
|
|
|
|
// at 0x8730513: MV_Mix16BitStereo16Stereo (mixst.c:272)
|
|
|
|
// by 0x872A5A2: MV_Mix (multivoc.c:285)
|
|
|
|
// by 0x872B0EA: MV_ServiceVoc (multivoc.c:449)
|
|
|
|
// by 0x87342C1: fillData (driver_sdl.c:80)
|
|
|
|
// by 0x428F2AD: ??? (in /usr/lib/libSDL_mixer-1.2.so.0.2.6)
|
|
|
|
// . . .
|
|
|
|
// Address 0x11e9fa10 is 0 bytes after a block of size 9,728 alloc'd
|
|
|
|
// at 0x402732C: calloc (vg_replace_malloc.c:467)
|
|
|
|
// by 0x87288C8: MV_Init (multivoc.c:2528)
|
|
|
|
// by 0x871BD20: FX_Init (fx_man.c:160)
|
|
|
|
// by 0x84597CA: S_SoundStartup (sounds.c:62)
|
|
|
|
// by 0x80D7869: app_main (game.c:10378)
|
|
|
|
// by 0x870C9C0: main (sdlayer.c:222)
|
|
|
|
MV_TotalMemory = Voices * sizeof(VoiceNode) + sizeof(HARSH_CLIP_TABLE_8) + MV_TOTALBUFFERSIZE + 2;
|
|
|
|
|
2009-07-29 10:33:56 +00:00
|
|
|
ptr = (char *) calloc(1, MV_TotalMemory);
|
2009-07-27 05:47:50 +00:00
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NoMem);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_Voices = (VoiceNode *)ptr;
|
|
|
|
ptr += Voices * sizeof(VoiceNode);
|
|
|
|
|
|
|
|
MV_HarshClipTable = ptr;
|
|
|
|
ptr += sizeof(HARSH_CLIP_TABLE_8);
|
|
|
|
|
|
|
|
// Set number of voices before calculating volume table
|
|
|
|
MV_MaxVoices = Voices;
|
|
|
|
|
|
|
|
LL_Reset((VoiceNode*) &VoiceList, next, prev);
|
|
|
|
LL_Reset((VoiceNode*) &VoicePool, next, prev);
|
|
|
|
|
|
|
|
for (index = 0; index < Voices; index++)
|
|
|
|
{
|
|
|
|
LL_Add((VoiceNode*) &VoicePool, &MV_Voices[ index ], next, prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
MV_SetReverseStereo(FALSE);
|
|
|
|
|
|
|
|
ASS_SoundDriver = soundcard;
|
|
|
|
|
|
|
|
// Initialize the sound card
|
2009-07-31 11:45:29 +00:00
|
|
|
status = SoundDriver_Init(&MixRate, &numchannels, &samplebits, initdata);
|
2009-07-27 05:47:50 +00:00
|
|
|
if (status != MV_Ok)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_DriverError);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MV_ErrorCode != MV_Ok)
|
|
|
|
{
|
|
|
|
status = MV_ErrorCode;
|
|
|
|
|
2010-06-26 08:51:42 +00:00
|
|
|
free(MV_Voices);
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_Voices = NULL;
|
|
|
|
MV_HarshClipTable = NULL;
|
|
|
|
MV_TotalMemory = 0;
|
|
|
|
|
|
|
|
MV_SetErrorCode(status);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_Installed = TRUE;
|
|
|
|
MV_CallBackFunc = NULL;
|
|
|
|
MV_ReverbLevel = 0;
|
|
|
|
MV_ReverbTable = NULL;
|
|
|
|
|
|
|
|
// Set the sampling rate
|
|
|
|
MV_RequestedMixRate = MixRate;
|
|
|
|
|
|
|
|
// Set Mixer to play stereo digitized sound
|
|
|
|
MV_SetMixMode(numchannels, samplebits);
|
|
|
|
MV_ReverbDelay = MV_BufferSize * 3;
|
|
|
|
|
|
|
|
// Make sure we don't cross a physical page
|
|
|
|
MV_MixBuffer[ MV_NumberOfBuffers ] = ptr;
|
|
|
|
for (buffer = 0; buffer < MV_NumberOfBuffers; buffer++)
|
|
|
|
{
|
|
|
|
MV_MixBuffer[ buffer ] = ptr;
|
|
|
|
ptr += MV_BufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate pan table
|
|
|
|
MV_CalcPanTable();
|
|
|
|
|
2011-11-01 22:02:14 +00:00
|
|
|
MV_SetVolume(MV_MAXTOTALVOLUME);
|
2009-07-27 05:47:50 +00:00
|
|
|
|
|
|
|
// Start the playback engine
|
|
|
|
status = MV_StartPlayback();
|
|
|
|
if (status != MV_Ok)
|
|
|
|
{
|
|
|
|
// Preserve error code while we shutdown.
|
|
|
|
status = MV_ErrorCode;
|
|
|
|
MV_Shutdown();
|
|
|
|
MV_SetErrorCode(status);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
Function: MV_Shutdown
|
|
|
|
|
|
|
|
Restore any resources allocated by Multivoc back to the system.
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 22:01:54 +00:00
|
|
|
int32_t MV_Shutdown(void)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
int32_t buffer;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MV_KillAllVoices();
|
|
|
|
|
|
|
|
MV_Installed = FALSE;
|
|
|
|
|
|
|
|
// Stop the sound playback engine
|
|
|
|
MV_StopPlayback();
|
|
|
|
|
|
|
|
// Shutdown the sound card
|
|
|
|
SoundDriver_Shutdown();
|
|
|
|
|
|
|
|
// Free any voices we allocated
|
2010-06-26 08:51:42 +00:00
|
|
|
free(MV_Voices);
|
2009-07-27 05:47:50 +00:00
|
|
|
MV_Voices = NULL;
|
|
|
|
MV_TotalMemory = 0;
|
|
|
|
|
|
|
|
LL_Reset((VoiceNode*) &VoiceList, next, prev);
|
|
|
|
LL_Reset((VoiceNode*) &VoicePool, next, prev);
|
|
|
|
|
|
|
|
MV_MaxVoices = 1;
|
|
|
|
|
|
|
|
// Release the descriptor from our mix buffer
|
2011-11-01 22:02:14 +00:00
|
|
|
for (buffer = 0; buffer < MV_NUMBEROFBUFFERS; buffer++)
|
2009-07-27 05:47:50 +00:00
|
|
|
{
|
|
|
|
MV_MixBuffer[ buffer ] = NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2009-07-27 05:47:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t MV_SetVoiceCallback(int32_t handle, uint32_t callbackval)
|
|
|
|
{
|
|
|
|
VoiceNode *voice;
|
|
|
|
|
|
|
|
if (!MV_Installed)
|
|
|
|
{
|
|
|
|
MV_SetErrorCode(MV_NotInstalled);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DisableInterrupts();
|
|
|
|
|
|
|
|
if ((voice = MV_GetVoice(handle)) == NULL)
|
|
|
|
{
|
|
|
|
RestoreInterrupts();
|
|
|
|
MV_SetErrorCode(MV_VoiceNotFound);
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Error;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice->callbackval = callbackval;
|
|
|
|
|
|
|
|
RestoreInterrupts();
|
|
|
|
|
2012-12-29 10:59:21 +00:00
|
|
|
return MV_Ok;
|
2010-06-22 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MV_SetPrintf(void (*function)(const char *, ...))
|
|
|
|
{
|
|
|
|
MV_Printf = function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-29 10:57:24 +00:00
|
|
|
const char *loopStartTags[loopStartTagCount] = {
|
|
|
|
"LOOP_START",
|
|
|
|
"LOOPSTART"
|
|
|
|
};
|
|
|
|
const char *loopEndTags[loopEndTagCount] = {
|
|
|
|
"LOOP_END",
|
|
|
|
"LOOPEND"
|
|
|
|
};
|
|
|
|
const char *loopLengthTags[loopLengthTagCount] = {
|
|
|
|
"LOOP_LENGTH",
|
|
|
|
"LOOPLENGTH"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-27 05:47:50 +00:00
|
|
|
// vim:ts=3:expandtab:
|