Decode audio and video separately in InterplayDecoder

This commit is contained in:
Chris Robinson 2022-10-06 10:37:07 -07:00 committed by Christoph Oelckers
parent fa2cea3e5b
commit bf933b3904
2 changed files with 557 additions and 449 deletions

File diff suppressed because it is too large Load diff

View file

@ -44,6 +44,9 @@
#pragma once #pragma once
#include <deque>
#include <memory>
#include <mutex>
#include <vector> #include <vector>
#include "files.h" #include "files.h"
@ -55,6 +58,21 @@
class InterplayDecoder class InterplayDecoder
{ {
struct AudioPacket
{
size_t nSize = 0;
std::unique_ptr<uint8_t[]> pData;
};
struct VideoPacket
{
uint16_t nPalStart=0, nPalCount=0;
uint32_t nDecodeMapSize = 0;
uint32_t nVideoDataSize = 0;
bool bSendFlag = false;
std::unique_ptr<uint8_t[]> pData;
};
public: public:
enum enum
{ {
@ -109,15 +127,16 @@ public:
struct AudioData struct AudioData
{ {
int hFx; int nChannels = 0;
int nChannels; uint16_t nSampleRate = 0;
uint16_t nSampleRate; uint8_t nBitDepth = 0;
uint8_t nBitDepth; bool bCompressed = false;
bool bCompressed;
int16_t samples[6000 * kAudioBlocks]; // must be a multiple of the stream buffer size std::unique_ptr<int16_t[]> samples;
int nWrite; int nWrite = 0;
int nRead; int nRead = 0;
std::deque<AudioPacket> Packets;
}; };
AudioData audio; AudioData audio;
@ -126,6 +145,10 @@ public:
AnimTextures& animTex() { return animtex; } AnimTextures& animTex() { return animtex; }
private: private:
bool StreamCallback(SoundStream *stream, void *buff, int len);
static bool StreamCallbackC(SoundStream *stream, void *buff, int len, void *userdata)
{ return static_cast<InterplayDecoder*>(userdata)->StreamCallback(stream, buff, len); }
struct DecodeMap struct DecodeMap
{ {
uint8_t* pData; uint8_t* pData;
@ -159,9 +182,11 @@ private:
void DecodeBlock14(int32_t offset); void DecodeBlock14(int32_t offset);
void DecodeBlock15(int32_t offset); void DecodeBlock15(int32_t offset);
std::mutex PacketMutex;
FileReader fr; FileReader fr;
bool bIsPlaying, bAudioStarted; bool bIsPlaying, bAudioStarted;
bool bAudioEnabled;
uint32_t nTimerRate, nTimerDiv; uint32_t nTimerRate, nTimerDiv;
uint32_t nWidth, nHeight, nFrame; uint32_t nWidth, nHeight, nFrame;
@ -169,12 +194,14 @@ private:
uint64_t nFrameDuration; uint64_t nFrameDuration;
std::vector<uint8_t> ChunkData; std::vector<uint8_t> ChunkData;
const uint8_t *ChunkPtr = nullptr; int ProcessNextChunk();
std::deque<VideoPacket> VideoPackets;
uint8_t* pVideoBuffers[2]; uint8_t* pVideoBuffers[2];
uint32_t nCurrentVideoBuffer, nPreviousVideoBuffer; uint32_t nCurrentVideoBuffer, nPreviousVideoBuffer;
int32_t videoStride; int32_t videoStride;
const uint8_t *ChunkPtr = nullptr;
DecodeMap decodeMap; DecodeMap decodeMap;
Palette palette[256]; Palette palette[256];