Add Demand Feed audio streaming support back to ASS audiolib. This is from the Rise of the Triad source release.

This commit is contained in:
sirlemonhead 2019-12-05 21:17:58 +00:00 committed by Christoph Oelckers
parent 77a2625a85
commit a191faf175
5 changed files with 140 additions and 0 deletions

View file

@ -69,6 +69,8 @@ int FX_PlayRaw(char *ptr, uint32_t ptrlength, int rate, int pitchoffset, int vol
int FX_PlayLoopedRaw(char *ptr, uint32_t ptrlength, char *loopstart, char *loopend, int rate,
int pitchoffset, int vol, int left, int right, int priority, float volume, intptr_t callbackval);
int FX_StartDemandFeedPlayback(void (*function)(const char** ptr, uint32_t* length), int rate, int pitchoffset,
int vol, int left, int right, int priority, fix16_t volume, uint32_t callbackval);
int FX_SetPrintf(void(*function)(const char *, ...));

View file

@ -105,6 +105,9 @@ int MV_PlayVOC3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int a
int MV_PlayVOC(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol,
int left, int right, int priority, float volume, intptr_t callbackval);
int MV_StartDemandFeedPlayback(void (*function)(const char** ptr, uint32_t* length), int rate,
int pitchoffset, int vol, int left, int right, int priority, fix16_t volume, uint32_t callbackval);
decltype(MV_PlayVOC3D) MV_PlayWAV3D;
decltype(MV_PlayVOC) MV_PlayWAV;
decltype(MV_PlayVOC3D) MV_PlayVorbis3D;

View file

@ -158,6 +158,8 @@ typedef struct VoiceNode
uint32_t (*mix)(struct VoiceNode *, uint32_t);
void (*DemandFeed)(const char** ptr, uint32_t* length);
const char *sound;
float LeftVolume, LeftVolumeDest;

View file

@ -225,3 +225,36 @@ int FX_SetPrintf(void (*function)(const char *, ...))
return FX_Ok;
}
/*---------------------------------------------------------------------
Function: FX_StartDemandFeedPlayback
Plays a digitized sound from a user controlled buffering system.
---------------------------------------------------------------------*/
int FX_StartDemandFeedPlayback
(
void (*function)(const char** ptr, uint32_t* length),
int rate,
int pitchoffset,
int vol,
int left,
int right,
int priority,
fix16_t volume,
uint32_t callbackval
)
{
int handle;
handle = MV_StartDemandFeedPlayback(function, rate,
pitchoffset, vol, left, right, priority, volume, callbackval);
if (handle < MV_Ok)
{
FX_SetErrorCode(FX_MultiVocError);
handle = FX_Warning;
}
return(handle);
}

View file

@ -899,3 +899,103 @@ const char *MV_ErrorString(int ErrorNumber)
}
}
/*---------------------------------------------------------------------
Function: MV_GetNextDemandFeedBlock
Controls playback of demand fed data.
---------------------------------------------------------------------*/
playbackstatus MV_GetNextDemandFeedBlock
(
VoiceNode* voice
)
{
if (voice->BlockLength > 0)
{
voice->position -= voice->length;
voice->sound += voice->length >> 16;
voice->length = min(voice->BlockLength, 0x8000u);
voice->BlockLength -= voice->length;
voice->length <<= 16;
return(KeepPlaying);
}
if (voice->DemandFeed == NULL)
{
return(NoMoreData);
}
voice->position = 0;
(voice->DemandFeed)(&voice->sound, &voice->BlockLength);
voice->length = min(voice->BlockLength, 0x8000u);
voice->BlockLength -= voice->length;
voice->length <<= 16;
if ((voice->length > 0) && (voice->sound != NULL))
{
return(KeepPlaying);
}
return(NoMoreData);
}
/*---------------------------------------------------------------------
Function: MV_StartDemandFeedPlayback
Plays a digitized sound from a user controlled buffering system.
---------------------------------------------------------------------*/
int MV_StartDemandFeedPlayback
(
void (*function)(const char** ptr, uint32_t* length),
int rate,
int pitchoffset,
int vol,
int left,
int right,
int priority,
fix16_t volume,
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 = FMT_DEMANDFED;
voice->bits = 8;
voice->channels = 1;
voice->GetSound = MV_GetNextDemandFeedBlock;
voice->NextBlock = NULL;
voice->DemandFeed = function;
voice->LoopStart = NULL;
voice->LoopCount = 0;
voice->BlockLength = 0;
voice->position = 0;
voice->sound = NULL;
voice->length = 0;
voice->next = NULL;
voice->prev = NULL;
voice->priority = priority;
voice->callbackval = callbackval;
MV_SetVoicePitch(voice, rate, pitchoffset);
MV_SetVoiceVolume(voice, vol, left, right, volume);
MV_PlayVoice(voice);
return(voice->handle);
}