mirror of https://github.com/AxioDL/metaforce.git
THP audio fix
This commit is contained in:
parent
5f7c6769e3
commit
f53bdcc5bd
|
@ -30,13 +30,15 @@ void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
|
||||||
m_lineRenderer.reset(new urde::CLineRenderer(urde::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true));
|
m_lineRenderer.reset(new urde::CLineRenderer(urde::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true));
|
||||||
*/
|
*/
|
||||||
m_particleView.reset(new ParticleView(*this, m_viewResources, *m_rootView));
|
m_particleView.reset(new ParticleView(*this, m_viewResources, *m_rootView));
|
||||||
m_moviePlayer.reset(new CMoviePlayer("Video/00_first_start.thp", -1.f, false, false));
|
m_moviePlayer.reset(new CMoviePlayer("Video/SpecialEnding.thp", -1.f, false, true));
|
||||||
m_moviePlayer->SetFrame({-1.0f, 1.0f, 0.f}, {-1.0f, -1.0f, 0.f}, {1.0f, -1.0f, 0.f}, {1.0f, 1.0f, 0.f});
|
m_moviePlayer->SetFrame({-1.0f, 1.0f, 0.f}, {-1.0f, -1.0f, 0.f}, {1.0f, -1.0f, 0.f}, {1.0f, 1.0f, 0.f});
|
||||||
CDvdFile testRSF("Audio/frontend_1.rsf");
|
CDvdFile testRSF("Audio/frontend_1.rsf");
|
||||||
u64 rsfLen = testRSF.Length();
|
u64 rsfLen = testRSF.Length();
|
||||||
m_rsfBuf.reset(new u8[rsfLen]);
|
m_rsfBuf.reset(new u8[rsfLen]);
|
||||||
testRSF.SyncRead(m_rsfBuf.get(), rsfLen);
|
testRSF.SyncRead(m_rsfBuf.get(), rsfLen);
|
||||||
CMoviePlayer::SetStaticAudio(m_rsfBuf.get(), rsfLen, 416480, 1973664);
|
//CMoviePlayer::SetStaticAudio(m_rsfBuf.get(), rsfLen, 416480, 1973664);
|
||||||
|
|
||||||
|
m_videoVoice = m_voiceAllocator->allocateNewVoice(m_audioSet, 32000, &m_voiceCallback);
|
||||||
m_videoVoice->start();
|
m_videoVoice->start();
|
||||||
|
|
||||||
//m_rootView->accessContentViews().clear();
|
//m_rootView->accessContentViews().clear();
|
||||||
|
@ -83,6 +85,7 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
||||||
m_vm.m_moviePlayer.reset(new CMoviePlayer("Video/01_startloop.thp", -1.f, true, false));
|
m_vm.m_moviePlayer.reset(new CMoviePlayer("Video/01_startloop.thp", -1.f, true, false));
|
||||||
m_vm.m_moviePlayer->SetFrame({-1.0f, 1.0f, 0.f}, {-1.0f, -1.0f, 0.f}, {1.0f, -1.0f, 0.f}, {1.0f, 1.0f, 0.f});
|
m_vm.m_moviePlayer->SetFrame({-1.0f, 1.0f, 0.f}, {-1.0f, -1.0f, 0.f}, {1.0f, -1.0f, 0.f}, {1.0f, 1.0f, 0.f});
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vm.m_moviePlayer->Update(1.f / 60.f);
|
m_vm.m_moviePlayer->Update(1.f / 60.f);
|
||||||
m_vm.m_moviePlayer->DrawFrame();
|
m_vm.m_moviePlayer->DrawFrame();
|
||||||
}
|
}
|
||||||
|
@ -251,10 +254,9 @@ void ViewManager::init(boo::IApplication* app)
|
||||||
m_mainWindow->setWaitCursor(false);
|
m_mainWindow->setWaitCursor(false);
|
||||||
|
|
||||||
m_voiceAllocator = boo::NewAudioVoiceAllocator();
|
m_voiceAllocator = boo::NewAudioVoiceAllocator();
|
||||||
boo::AudioChannelSet audioSet = m_voiceAllocator->getAvailableSet();
|
m_audioSet = m_voiceAllocator->getAvailableSet();
|
||||||
m_stereoMatrix.setAudioChannelSet(audioSet);
|
m_stereoMatrix.setAudioChannelSet(m_audioSet);
|
||||||
m_stereoMatrix.setDefaultMatrixCoefficients();
|
m_stereoMatrix.setDefaultMatrixCoefficients();
|
||||||
m_videoVoice = m_voiceAllocator->allocateNewVoice(audioSet, 32000, &m_voiceCallback);
|
|
||||||
CGraphics::InitializeBoo(gf, m_mainWindow->getCommandQueue(), root->renderTex());
|
CGraphics::InitializeBoo(gf, m_mainWindow->getCommandQueue(), root->renderTex());
|
||||||
CElementGen::Initialize();
|
CElementGen::Initialize();
|
||||||
CMoviePlayer::Initialize();
|
CMoviePlayer::Initialize();
|
||||||
|
|
|
@ -53,6 +53,7 @@ class ViewManager : public specter::IViewManager
|
||||||
std::unique_ptr<CMoviePlayer> m_moviePlayer;
|
std::unique_ptr<CMoviePlayer> m_moviePlayer;
|
||||||
std::unique_ptr<u8[]> m_rsfBuf;
|
std::unique_ptr<u8[]> m_rsfBuf;
|
||||||
std::unique_ptr<boo::IAudioVoiceAllocator> m_voiceAllocator;
|
std::unique_ptr<boo::IAudioVoiceAllocator> m_voiceAllocator;
|
||||||
|
boo::AudioChannelSet m_audioSet = boo::AudioChannelSet::Unknown;
|
||||||
std::unique_ptr<boo::IAudioVoice> m_videoVoice;
|
std::unique_ptr<boo::IAudioVoice> m_videoVoice;
|
||||||
boo::AudioMatrixStereo m_stereoMatrix;
|
boo::AudioMatrixStereo m_stereoMatrix;
|
||||||
struct AudioVoiceCallback : boo::IAudioVoiceCallback
|
struct AudioVoiceCallback : boo::IAudioVoiceCallback
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
#include "dsp.h"
|
#include "dsp.h"
|
||||||
|
|
||||||
static const int NibbleToInt[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
|
static const int32_t NibbleToInt[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
|
||||||
|
|
||||||
void DSPDecompressFrame(int16_t* out, const uint8_t* in,
|
void DSPDecompressFrame(int16_t* out, const uint8_t* in,
|
||||||
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
||||||
unsigned lastSample)
|
unsigned lastSample)
|
||||||
{
|
{
|
||||||
uint8_t cIdx = (in[0]>>4) & 0xf;
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
||||||
int16_t factor1 = coefs[cIdx][0];
|
int32_t factor1 = coefs[cIdx][0];
|
||||||
int16_t factor2 = coefs[cIdx][1];
|
int32_t factor2 = coefs[cIdx][1];
|
||||||
uint8_t exp = in[0] & 0xf;
|
uint8_t exp = in[0] & 0xf;
|
||||||
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
||||||
{
|
{
|
||||||
int sampleData = (s&1)?
|
int32_t sampleData = (s&1)?
|
||||||
NibbleToInt[(in[s/2+1])&0xf]:
|
NibbleToInt[(in[s/2+1])&0xf]:
|
||||||
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
NibbleToInt[(in[s/2+1]>>4)&0xf];
|
||||||
sampleData <<= exp;
|
sampleData <<= exp;
|
||||||
sampleData <<= 11;
|
sampleData <<= 11;
|
||||||
sampleData += 1024;
|
sampleData += 1024;
|
||||||
sampleData +=
|
sampleData +=
|
||||||
factor1 * *prev1 +
|
factor1 * ((int32_t)(*prev1)) +
|
||||||
factor2 * *prev2;
|
factor2 * ((int32_t)(*prev2));
|
||||||
sampleData >>= 11;
|
sampleData >>= 11;
|
||||||
sampleData = DSPSampClamp(sampleData);
|
sampleData = DSPSampClamp(sampleData);
|
||||||
out[s] = sampleData;
|
out[s] = sampleData;
|
||||||
|
@ -33,10 +33,10 @@ void DSPDecompressFrameStereoStride(int16_t* out, const uint8_t* in,
|
||||||
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
const int16_t coefs[8][2], int16_t* prev1, int16_t* prev2,
|
||||||
unsigned lastSample)
|
unsigned lastSample)
|
||||||
{
|
{
|
||||||
uint8_t cIdx = (in[0]>>4) & 0xf;
|
uint32_t cIdx = (in[0]>>4) & 0xf;
|
||||||
int16_t factor1 = coefs[cIdx][0];
|
int32_t factor1 = coefs[cIdx][0];
|
||||||
int16_t factor2 = coefs[cIdx][1];
|
int32_t factor2 = coefs[cIdx][1];
|
||||||
uint8_t exp = in[0] & 0xf;
|
uint32_t exp = in[0] & 0xf;
|
||||||
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
||||||
{
|
{
|
||||||
int sampleData = (s&1)?
|
int sampleData = (s&1)?
|
||||||
|
@ -46,8 +46,8 @@ void DSPDecompressFrameStereoStride(int16_t* out, const uint8_t* in,
|
||||||
sampleData <<= 11;
|
sampleData <<= 11;
|
||||||
sampleData += 1024;
|
sampleData += 1024;
|
||||||
sampleData +=
|
sampleData +=
|
||||||
factor1 * *prev1 +
|
factor1 * ((int32_t)(*prev1)) +
|
||||||
factor2 * *prev2;
|
factor2 * ((int32_t)(*prev2));
|
||||||
sampleData >>= 11;
|
sampleData >>= 11;
|
||||||
sampleData = DSPSampClamp(sampleData);
|
sampleData = DSPSampClamp(sampleData);
|
||||||
out[s*2] = sampleData;
|
out[s*2] = sampleData;
|
||||||
|
@ -61,8 +61,8 @@ void DSPDecompressFrameStereoDupe(int16_t* out, const uint8_t* in,
|
||||||
unsigned lastSample)
|
unsigned lastSample)
|
||||||
{
|
{
|
||||||
uint8_t cIdx = (in[0]>>4) & 0xf;
|
uint8_t cIdx = (in[0]>>4) & 0xf;
|
||||||
int16_t factor1 = coefs[cIdx][0];
|
int32_t factor1 = coefs[cIdx][0];
|
||||||
int16_t factor2 = coefs[cIdx][1];
|
int32_t factor2 = coefs[cIdx][1];
|
||||||
uint8_t exp = in[0] & 0xf;
|
uint8_t exp = in[0] & 0xf;
|
||||||
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
for (int s=0 ; s<14 && s<lastSample ; ++s)
|
||||||
{
|
{
|
||||||
|
@ -73,8 +73,8 @@ void DSPDecompressFrameStereoDupe(int16_t* out, const uint8_t* in,
|
||||||
sampleData <<= 11;
|
sampleData <<= 11;
|
||||||
sampleData += 1024;
|
sampleData += 1024;
|
||||||
sampleData +=
|
sampleData +=
|
||||||
factor1 * *prev1 +
|
factor1 * ((int32_t)(*prev1)) +
|
||||||
factor2 * *prev2;
|
factor2 * ((int32_t)(*prev2));
|
||||||
sampleData >>= 11;
|
sampleData >>= 11;
|
||||||
sampleData = DSPSampClamp(sampleData);
|
sampleData = DSPSampClamp(sampleData);
|
||||||
out[s*2] = sampleData;
|
out[s*2] = sampleData;
|
||||||
|
|
|
@ -7,10 +7,10 @@ extern "C" {
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
static inline short DSPSampClamp(int val)
|
static inline short DSPSampClamp(int32_t val)
|
||||||
{
|
{
|
||||||
if (val < -32768) val = -32768;
|
if (val < -32768) val = -32768;
|
||||||
if (val > 32767) val = 32767;
|
else if (val > 32767) val = 32767;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -310,16 +310,15 @@ u32 CMoviePlayer::THPAudioDecode(s16* buffer, const u8* audioFrame, bool stereo)
|
||||||
{
|
{
|
||||||
unsigned samples = header.numSamples;
|
unsigned samples = header.numSamples;
|
||||||
s16* bufferCur = buffer+i;
|
s16* bufferCur = buffer+i;
|
||||||
const u8* audioFrameCur = audioFrame;
|
|
||||||
int16_t prev1 = header.channelPrevs[i][0];
|
int16_t prev1 = header.channelPrevs[i][0];
|
||||||
int16_t prev2 = header.channelPrevs[i][1];
|
int16_t prev2 = header.channelPrevs[i][1];
|
||||||
for (int f=0 ; f<header.channelSize/8 ; ++f)
|
for (int f=0 ; f<(header.numSamples + 13) / 14 ; ++f)
|
||||||
{
|
{
|
||||||
DSPDecompressFrameStereoStride(bufferCur, audioFrameCur,
|
DSPDecompressFrameStereoStride(bufferCur, audioFrame,
|
||||||
header.channelCoefs[i], &prev1, &prev2, samples);
|
header.channelCoefs[i], &prev1, &prev2, samples);
|
||||||
samples -= 14;
|
samples -= 14;
|
||||||
bufferCur += 28;
|
bufferCur += 28;
|
||||||
audioFrameCur += 8;
|
audioFrame += 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,16 +326,15 @@ u32 CMoviePlayer::THPAudioDecode(s16* buffer, const u8* audioFrame, bool stereo)
|
||||||
{
|
{
|
||||||
unsigned samples = header.numSamples;
|
unsigned samples = header.numSamples;
|
||||||
s16* bufferCur = buffer;
|
s16* bufferCur = buffer;
|
||||||
const u8* audioFrameCur = audioFrame;
|
|
||||||
int16_t prev1 = header.channelPrevs[0][0];
|
int16_t prev1 = header.channelPrevs[0][0];
|
||||||
int16_t prev2 = header.channelPrevs[0][1];
|
int16_t prev2 = header.channelPrevs[0][1];
|
||||||
for (int f=0 ; f<header.channelSize/8 ; ++f)
|
for (int f=0 ; f<(header.numSamples + 13) / 14 ; ++f)
|
||||||
{
|
{
|
||||||
DSPDecompressFrameStereoDupe(bufferCur, audioFrameCur,
|
DSPDecompressFrameStereoDupe(bufferCur, audioFrame,
|
||||||
header.channelCoefs[0], &prev1, &prev2, samples);
|
header.channelCoefs[0], &prev1, &prev2, samples);
|
||||||
samples -= 14;
|
samples -= 14;
|
||||||
bufferCur += 28;
|
bufferCur += 28;
|
||||||
audioFrameCur += 8;
|
audioFrame += 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,25 +522,22 @@ void CMoviePlayer::MixAudio(s16* out, const s16* in, u32 samples)
|
||||||
{
|
{
|
||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
for (u32 i=0 ; i<thisSamples ; ++i)
|
for (u32 i=0 ; i<thisSamples ; ++i, out += 2, in += 2)
|
||||||
{
|
{
|
||||||
out[0] = DSPSampClamp(in[0] +
|
out[0] = DSPSampClamp(in[0] +
|
||||||
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2]) * 0x50F4 / 0x8000));
|
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2]) * 0x50F4 / 0x8000));
|
||||||
out[1] = DSPSampClamp(in[1] +
|
out[1] = DSPSampClamp(in[1] +
|
||||||
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2+1]) * 0x50F4 / 0x8000));
|
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2+1]) * 0x50F4 / 0x8000));
|
||||||
out += 2;
|
|
||||||
in += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (u32 i=0 ; i<thisSamples ; ++i)
|
for (u32 i=0 ; i<thisSamples ; ++i, out += 2)
|
||||||
{
|
{
|
||||||
out[0] = DSPSampClamp(
|
out[0] = DSPSampClamp(
|
||||||
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2]) * 0x50F4 / 0x8000));
|
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2]) * 0x50F4 / 0x8000));
|
||||||
out[1] = DSPSampClamp(
|
out[1] = DSPSampClamp(
|
||||||
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2+1]) * 0x50F4 / 0x8000));
|
s16(s32(tex->audioBuf[(i+tex->playedSamples)*2+1]) * 0x50F4 / 0x8000));
|
||||||
out += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tex->playedSamples += thisSamples;
|
tex->playedSamples += thisSamples;
|
||||||
|
@ -554,6 +549,7 @@ void CMoviePlayer::MixAudio(s16* out, const s16* in, u32 samples)
|
||||||
memcpy(out, in, samples * 4);
|
memcpy(out, in, samples * 4);
|
||||||
else
|
else
|
||||||
memset(out, 0, samples * 4);
|
memset(out, 0, samples * 4);
|
||||||
|
//fprintf(stderr, "dropped %d samples\n", samples);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,6 +806,7 @@ void CMoviePlayer::DecodeFromRead(const void* data)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case THPComponents::Type::Audio:
|
case THPComponents::Type::Audio:
|
||||||
|
memset(tex.audioBuf.get(), 0, x28_thpHead.maxAudioSamples * 4);
|
||||||
tex.audioSamples = THPAudioDecode(tex.audioBuf.get(), (u8*)inptr, x74_audioInfo.numChannels == 2);
|
tex.audioSamples = THPAudioDecode(tex.audioBuf.get(), (u8*)inptr, x74_audioInfo.numChannels == 2);
|
||||||
tex.playedSamples = 0;
|
tex.playedSamples = 0;
|
||||||
inptr += frameHeader.audioSize;
|
inptr += frameHeader.audioSize;
|
||||||
|
|
Loading…
Reference in New Issue