mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Audiolib: Clean up samples handling
git-svn-id: https://svn.eduke32.com/eduke32@7683 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f92ec7bb89
commit
19a5e86a35
4 changed files with 45 additions and 36 deletions
|
@ -233,7 +233,8 @@ FLAC__StreamDecoderWriteStatus write_flac_stream(const FLAC__StreamDecoder *deco
|
|||
(FLAC__uint64)(uintptr_t)voice->LoopStart, (FLAC__uint64)(uintptr_t)voice->LoopEnd);
|
||||
}
|
||||
|
||||
voice->length = ((samples * (voice->bits / 8)) / 2) << voice->bits;
|
||||
size_t const size = samples * voice->channels * (voice->bits / 8);
|
||||
|
||||
voice->position = 0;
|
||||
voice->BlockLength = 0;
|
||||
// CODEDUP multivoc.c MV_SetVoicePitch
|
||||
|
@ -241,22 +242,18 @@ FLAC__StreamDecoderWriteStatus write_flac_stream(const FLAC__StreamDecoder *deco
|
|||
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) - voice->RateScale;
|
||||
MV_SetVoiceMixMode(voice);
|
||||
|
||||
char * block = fd->block;
|
||||
|
||||
if (size > fd->blocksize)
|
||||
{
|
||||
const size_t size = samples * voice->channels * (voice->bits / 8);
|
||||
if (size > fd->blocksize)
|
||||
{
|
||||
fd->blocksize = size;
|
||||
fd->block = (char *)realloc(fd->block, sizeof(char) * size);
|
||||
}
|
||||
block = (char *)malloc(size);
|
||||
|
||||
if (block == nullptr)
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||
}
|
||||
|
||||
if (!fd->block)
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||
|
||||
voice->sound = fd->block;
|
||||
|
||||
{
|
||||
char *obuffer = fd->block;
|
||||
char *obuffer = block;
|
||||
FLAC__uint64 sample;
|
||||
uint8_t channel;
|
||||
|
||||
|
@ -274,6 +271,17 @@ FLAC__StreamDecoderWriteStatus write_flac_stream(const FLAC__StreamDecoder *deco
|
|||
}
|
||||
}
|
||||
|
||||
voice->sound = block;
|
||||
voice->length = samples << 16;
|
||||
|
||||
if (block != fd->block)
|
||||
{
|
||||
char * oldblock = fd->block;
|
||||
fd->block = block;
|
||||
fd->blocksize = size;
|
||||
free(oldblock);
|
||||
}
|
||||
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -301,12 +301,12 @@ static playbackstatus MV_GetNextVorbisBlock(VoiceNode *voice)
|
|||
vd->lastbitstream = bitstream;
|
||||
}
|
||||
|
||||
bytesread /= 2 * voice->channels;
|
||||
uint32_t const samples = bytesread / ((voice->bits/8) * voice->channels);
|
||||
|
||||
voice->position = 0;
|
||||
voice->sound = vd->block;
|
||||
voice->BlockLength = 0;
|
||||
voice->length = bytesread << 16; // ???: Should the literal 16 be voice->bits?
|
||||
voice->length = samples << 16;
|
||||
|
||||
#ifdef GEKKO
|
||||
// If libtremor had the three additional ov_read() parameters that libvorbis has,
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
#define kNumOfSGs 18
|
||||
#define TTYWidth 80
|
||||
|
||||
#define kBufSize (kNumOfSGs*kNumOfSamples*(16/8))
|
||||
#define kSamplesMono (kNumOfSGs*kNumOfSamples)
|
||||
#define kSamplesStereo (kNumOfSGs*kNumOfSamples/2)
|
||||
|
||||
/* ADPCM */
|
||||
#define XA_DATA_START (0x44-48)
|
||||
|
||||
|
@ -41,8 +45,7 @@ typedef struct {
|
|||
double t1_x, t2_x;
|
||||
#endif
|
||||
|
||||
int8_t *block;
|
||||
size_t blocksize;
|
||||
int8_t block[kBufSize];
|
||||
|
||||
VoiceNode *owner;
|
||||
} xa_data;
|
||||
|
@ -153,7 +156,7 @@ static void decodeSoundSectMono(XASector *ssct, xa_data * xad)
|
|||
#else
|
||||
double tmp2, tmp3, tmp4, tmp5;
|
||||
#endif
|
||||
int8_t decodeBuf[kNumOfSGs*kNumOfSamples*2];
|
||||
int8_t decodeBuf[kBufSize];
|
||||
|
||||
for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
|
||||
{
|
||||
|
@ -187,11 +190,7 @@ static void decodeSoundSectMono(XASector *ssct, xa_data * xad)
|
|||
}
|
||||
}
|
||||
|
||||
if (count > xad->blocksize)
|
||||
xad->block = (int8_t *)Xrealloc(xad->block, count);
|
||||
|
||||
memcpy(xad->block, decodeBuf, count);
|
||||
xad->blocksize = count;
|
||||
memcpy(xad->block, decodeBuf, kBufSize);
|
||||
}
|
||||
|
||||
static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
|
||||
|
@ -207,7 +206,7 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
|
|||
#else
|
||||
double tmp2, tmp3, tmp4, tmp5;
|
||||
#endif
|
||||
int8_t decodeBuf[kNumOfSGs*kNumOfSamples*2];
|
||||
int8_t decodeBuf[kBufSize];
|
||||
|
||||
for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
|
||||
{
|
||||
|
@ -267,11 +266,7 @@ static void decodeSoundSectStereo(XASector *ssct, xa_data * xad)
|
|||
}
|
||||
}
|
||||
|
||||
if (count > xad->blocksize)
|
||||
xad->block = (int8_t *)Xrealloc(xad->block, count);
|
||||
|
||||
memcpy(xad->block, decodeBuf, count);
|
||||
xad->blocksize = count;
|
||||
memcpy(xad->block, decodeBuf, kBufSize);
|
||||
}
|
||||
|
||||
int32_t MV_GetXAPosition(VoiceNode *voice)
|
||||
|
@ -333,13 +328,21 @@ static playbackstatus MV_GetNextXABlock
|
|||
voice->FixedPointBufferSize = ( voice->RateScale * MV_MIXBUFFERSIZE ) - voice->RateScale;
|
||||
MV_SetVoiceMixMode( voice );
|
||||
|
||||
uint32_t samples;
|
||||
|
||||
if (voice->channels == 2)
|
||||
{
|
||||
decodeSoundSectStereo(&ssct, xad);
|
||||
samples = kSamplesStereo;
|
||||
}
|
||||
else
|
||||
{
|
||||
decodeSoundSectMono(&ssct, xad);
|
||||
samples = kSamplesMono;
|
||||
}
|
||||
|
||||
voice->sound = (char *)xad->block;
|
||||
voice->length = (((xad->blocksize * (voice->bits/8))/2)<<voice->bits) / 4;
|
||||
voice->length = samples << 16;
|
||||
voice->position = 0;
|
||||
voice->BlockLength = 0;
|
||||
|
||||
|
@ -431,11 +434,8 @@ int32_t MV_PlayXA(char *ptr, uint32_t length, int32_t loopstart, int32_t loopend
|
|||
xad->ptr = ptr;
|
||||
xad->pos = XA_DATA_START;
|
||||
xad->t1 = xad->t2 = xad->t1_x = xad->t2_x = 0;
|
||||
xad->blocksize = 0;
|
||||
xad->length = length;
|
||||
|
||||
xad->block = NULL;
|
||||
|
||||
// Request a voice from the voice pool
|
||||
voice = MV_AllocVoice( priority );
|
||||
if ( voice == NULL )
|
||||
|
@ -483,7 +483,6 @@ void MV_ReleaseXAVoice( VoiceNode * voice )
|
|||
return;
|
||||
}
|
||||
|
||||
free(xad->block);
|
||||
free(xad);
|
||||
|
||||
voice->rawdataptr = 0;
|
||||
|
|
|
@ -51,9 +51,11 @@ static playbackstatus MV_GetNextXMPBlock(VoiceNode *voice)
|
|||
|
||||
xmpd->time = mi.time;
|
||||
|
||||
uint32_t const samples = mi.buffer_size / (2 * (16/8)); // since 2-channel, 16-bit is hardcoded
|
||||
// uint32_t const samples = mi.buffer_size / (voice->channels * (voice->bits / 8));
|
||||
|
||||
voice->sound = (char const *)mi.buffer;
|
||||
voice->length = mi.buffer_size << 14; // since 2-channel, 16-bit is hardcoded
|
||||
// voice->length = (mi.buffer_size << 16) / (voice->channels * (voice->bits >> 3));
|
||||
voice->length = samples << 16;
|
||||
voice->position = 0;
|
||||
voice->BlockLength = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue