- some progress with sound. Still glitchy.

This commit is contained in:
Christoph Oelckers 2020-07-23 23:22:09 +02:00
parent 928a16983d
commit 75e8a71905
4 changed files with 10 additions and 7 deletions

View File

@ -97,7 +97,7 @@ static std::unique_ptr<SoundStream> musicStream;
SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata) SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata)
{ {
int flags = SoundStream::Float; int flags = 0;
if (numchannels < 2) flags |= SoundStream::Mono; if (numchannels < 2) flags |= SoundStream::Mono;
auto stream = GSnd->CreateStream(cb, size, flags, samplerate, userdata); auto stream = GSnd->CreateStream(cb, size, flags, samplerate, userdata);
if (stream) stream->Play(true, 1); if (stream) stream->Play(true, 1);

View File

@ -103,21 +103,24 @@ static int ClipRange(int val, int min, int max)
static bool StreamCallbackFunc(SoundStream* stream, void* buff, int len, void* userdata) static bool StreamCallbackFunc(SoundStream* stream, void* buff, int len, void* userdata)
{ {
InterplayDecoder* pId = (InterplayDecoder*)userdata; InterplayDecoder* pId = (InterplayDecoder*)userdata;
uint8_t* buf = (uint8_t*)buff; int16_t* buf = (int16_t*)buff;
len /= 2; // we're copying 16 bit values.
while (len > 0) while (len > 0)
{ {
uint32_t nSize = pId->audio.block[pId->audio.nRead].size; uint32_t nSize = pId->audio.block[pId->audio.nRead].size;
auto ptr = (uint8_t*)pId->audio.block[pId->audio.nRead].buf; auto ptr = pId->audio.block[pId->audio.nRead].buf;
auto copyofs = pId->audio.nSubIndex; auto copyofs = pId->audio.nSubIndex;
auto copylen = std::min<unsigned>(len, nSize - copyofs); auto copylen = std::min<unsigned>(len, nSize - copyofs);
memcpy(buf, ptr, copylen); for(int i=0;i<copylen;i++) *buf++ = *ptr++;
// memcpy(buf, ptr, copylen*2);
pId->audio.nSubIndex += copylen; pId->audio.nSubIndex += copylen;
buf += copylen;
len -= copylen; len -= copylen;
if (pId->audio.nSubIndex == nSize) if (pId->audio.nSubIndex == nSize)
{ {
pId->audio.nSubIndex = 0; pId->audio.nSubIndex = 0;
pId->audio.nRead++; pId->audio.nRead++;
if (pId->audio.nRead >= InterplayDecoder::kAudioBlocks) pId->audio.nRead = 0;
} }
} }
return true; return true;

View File

@ -53,6 +53,7 @@
class InterplayDecoder class InterplayDecoder
{ {
public:
enum enum
{ {
CHUNK_PREAMBLE_SIZE = 4, CHUNK_PREAMBLE_SIZE = 4,
@ -97,7 +98,6 @@ class InterplayDecoder
kAudioBlocks = 20 // alloc a lot of blocks - need to store lots of audio data before video frames start. kAudioBlocks = 20 // alloc a lot of blocks - need to store lots of audio data before video frames start.
}; };
public:
InterplayDecoder(); InterplayDecoder();
~InterplayDecoder(); ~InterplayDecoder();

View File

@ -202,7 +202,7 @@ public:
twod->ClearScreen(); twod->ClearScreen();
DrawTexture(twod, decoder.animTex().GetFrame(), 0, 0, DTA_FullscreenEx, 3, TAG_DONE); DrawTexture(twod, decoder.animTex().GetFrame(), 0, 0, DTA_FullscreenEx, 3, TAG_DONE);
return skiprequest ? -1 : playon ? 1 : 0; return /* skiprequest ? -1 :*/ playon ? 1 : 0;
} }
void OnDestroy() override void OnDestroy() override