77#include " Graphics/CGX.hpp"
88#include " GameGlobalObjects.hpp"
99
10- // #include <amuse/DSPCodec.hpp>
10+ // #include <amuse/DSPCodec.hpp>
1111#include < turbojpeg.h>
1212
1313namespace metaforce {
@@ -16,13 +16,13 @@ static void MyTHPYuv2RgbTextureSetup(void* dataY, void* dataU, void* dataV, u16
1616 GXTexObj texV;
1717 GXTexObj texU;
1818 GXTexObj texY;
19- GXInitTexObj (&texY, dataY, width, height, GX_TF_R8_PC, GX_CLAMP, GX_CLAMP, false );
19+ GXInitTexObj (&texY, dataY, width, height, static_cast <GXTexFmt>( GX_TF_R8_PC) , GX_CLAMP, GX_CLAMP, false );
2020 GXInitTexObjLOD (&texY, GX_NEAR, GX_NEAR, 0.0 , 0.0 , 0.0 , false , false , GX_ANISO_1);
2121 GXLoadTexObj (&texY, GX_TEXMAP0);
22- GXInitTexObj (&texU, dataU, width / 2 , height / 2 , GX_TF_R8_PC, GX_CLAMP, GX_CLAMP, false );
22+ GXInitTexObj (&texU, dataU, width / 2 , height / 2 , static_cast <GXTexFmt>( GX_TF_R8_PC) , GX_CLAMP, GX_CLAMP, false );
2323 GXInitTexObjLOD (&texU, GX_NEAR, GX_NEAR, 0.0 , 0.0 , 0.0 , false , false , GX_ANISO_1);
2424 GXLoadTexObj (&texU, GX_TEXMAP1);
25- GXInitTexObj (&texV, dataV, width / 2 , height / 2 , GX_TF_R8_PC, GX_CLAMP, GX_CLAMP, false );
25+ GXInitTexObj (&texV, dataV, width / 2 , height / 2 , static_cast <GXTexFmt>( GX_TF_R8_PC) , GX_CLAMP, GX_CLAMP, false );
2626 GXInitTexObjLOD (&texV, GX_NEAR, GX_NEAR, 0.0 , 0.0 , 0.0 , false , false , GX_ANISO_1);
2727 GXLoadTexObj (&texV, GX_TEXMAP2);
2828 CTexture::InvalidateTexMap (GX_TEXMAP0);
@@ -208,34 +208,34 @@ void CMoviePlayer::THPAudioFrameHeader::swapBig() {
208208/* Slightly modified from THPAudioDecode present in SDK; always interleaves */
209209u32 CMoviePlayer::THPAudioDecode (s16* buffer, const u8 * audioFrame, bool stereo) {
210210 THPAudioFrameHeader header = *((const THPAudioFrameHeader*)audioFrame);
211- // header.swapBig();
212- // audioFrame += sizeof(THPAudioFrameHeader);
213- //
214- // if (stereo) {
215- // for (int i = 0; i < 2; ++i) {
216- // unsigned samples = header.numSamples;
217- // s16* bufferCur = buffer + i;
218- // int16_t prev1 = header.channelPrevs[i][0];
219- // int16_t prev2 = header.channelPrevs[i][1];
220- // for (u32 f = 0; f < (header.numSamples + 13) / 14; ++f) {
221- // DSPDecompressFrameStereoStride(bufferCur, audioFrame, header.channelCoefs[i], &prev1, &prev2, samples);
222- // samples -= 14;
223- // bufferCur += 28;
224- // audioFrame += 8;
225- // }
226- // }
227- // } else {
228- // unsigned samples = header.numSamples;
229- // s16* bufferCur = buffer;
230- // int16_t prev1 = header.channelPrevs[0][0];
231- // int16_t prev2 = header.channelPrevs[0][1];
232- // for (u32 f = 0; f < (header.numSamples + 13) / 14; ++f) {
233- // DSPDecompressFrameStereoDupe(bufferCur, audioFrame, header.channelCoefs[0], &prev1, &prev2, samples);
234- // samples -= 14;
235- // bufferCur += 28;
236- // audioFrame += 8;
237- // }
238- // }
211+ // header.swapBig();
212+ // audioFrame += sizeof(THPAudioFrameHeader);
213+ //
214+ // if (stereo) {
215+ // for (int i = 0; i < 2; ++i) {
216+ // unsigned samples = header.numSamples;
217+ // s16* bufferCur = buffer + i;
218+ // int16_t prev1 = header.channelPrevs[i][0];
219+ // int16_t prev2 = header.channelPrevs[i][1];
220+ // for (u32 f = 0; f < (header.numSamples + 13) / 14; ++f) {
221+ // DSPDecompressFrameStereoStride(bufferCur, audioFrame, header.channelCoefs[i], &prev1, &prev2, samples);
222+ // samples -= 14;
223+ // bufferCur += 28;
224+ // audioFrame += 8;
225+ // }
226+ // }
227+ // } else {
228+ // unsigned samples = header.numSamples;
229+ // s16* bufferCur = buffer;
230+ // int16_t prev1 = header.channelPrevs[0][0];
231+ // int16_t prev2 = header.channelPrevs[0][1];
232+ // for (u32 f = 0; f < (header.numSamples + 13) / 14; ++f) {
233+ // DSPDecompressFrameStereoDupe(bufferCur, audioFrame, header.channelCoefs[0], &prev1, &prev2, samples);
234+ // samples -= 14;
235+ // bufferCur += 28;
236+ // audioFrame += 8;
237+ // }
238+ // }
239239
240240 return header.numSamples ;
241241}
@@ -332,99 +332,102 @@ void CMoviePlayer::SetSfxVolume(u8 volume) { SfxVolume = std::min(volume, u8(127
332332
333333void CMoviePlayer::MixAudio (s16* out, const s16* in, u32 samples) {
334334 /* No audio frames ready */
335- // if (xd4_audioSlot == UINT32_MAX) {
336- // if (in)
337- // memmove(out, in, samples * 4);
338- // else
339- // memset(out, 0, samples * 4);
340- // return;
341- // }
342- //
343- // while (samples) {
344- // CTHPTextureSet* tex = &x80_textures[xd4_audioSlot];
345- // u32 thisSamples = std::min(tex->audioSamples - tex->playedSamples, samples);
346- // if (!thisSamples) {
347- // /* Advance frame */
348- // ++xd4_audioSlot;
349- // if (xd4_audioSlot >= x80_textures.size())
350- // xd4_audioSlot = 0;
351- // tex = &x80_textures[xd4_audioSlot];
352- // thisSamples = std::min(tex->audioSamples - tex->playedSamples, samples);
353- // }
354- //
355- // if (thisSamples) {
356- // /* mix samples with `in` or no mix */
357- // if (in) {
358- // for (u32 i = 0; i < thisSamples; ++i, out += 2, in += 2) {
359- // out[0] = DSPSampClamp(in[0] + s32(tex->audioBuf[(i + tex->playedSamples) * 2]) * 0x50F4 / 0x8000 * SfxVolume);
360- // out[1] =
361- // DSPSampClamp(in[1] + s32(tex->audioBuf[(i + tex->playedSamples) * 2 + 1]) * 0x50F4 / 0x8000 * SfxVolume);
362- // }
363- // } else {
364- // for (u32 i = 0; i < thisSamples; ++i, out += 2) {
365- // out[0] = DSPSampClamp(s32(tex->audioBuf[(i + tex->playedSamples) * 2]) * 0x50F4 / 0x8000 * SfxVolume);
366- // out[1] = DSPSampClamp(s32(tex->audioBuf[(i + tex->playedSamples) * 2 + 1]) * 0x50F4 / 0x8000 * SfxVolume);
367- // }
368- // }
369- // tex->playedSamples += thisSamples;
370- // samples -= thisSamples;
371- // } else {
372- // /* metaforce addition: failsafe for buffer overrun */
373- // if (in)
374- // memmove(out, in, samples * 4);
375- // else
376- // memset(out, 0, samples * 4);
377- // // fprintf(stderr, "dropped %d samples\n", samples);
378- // return;
379- // }
380- // }
335+ // if (xd4_audioSlot == UINT32_MAX) {
336+ // if (in)
337+ // memmove(out, in, samples * 4);
338+ // else
339+ // memset(out, 0, samples * 4);
340+ // return;
341+ // }
342+ //
343+ // while (samples) {
344+ // CTHPTextureSet* tex = &x80_textures[xd4_audioSlot];
345+ // u32 thisSamples = std::min(tex->audioSamples - tex->playedSamples, samples);
346+ // if (!thisSamples) {
347+ // /* Advance frame */
348+ // ++xd4_audioSlot;
349+ // if (xd4_audioSlot >= x80_textures.size())
350+ // xd4_audioSlot = 0;
351+ // tex = &x80_textures[xd4_audioSlot];
352+ // thisSamples = std::min(tex->audioSamples - tex->playedSamples, samples);
353+ // }
354+ //
355+ // if (thisSamples) {
356+ // /* mix samples with `in` or no mix */
357+ // if (in) {
358+ // for (u32 i = 0; i < thisSamples; ++i, out += 2, in += 2) {
359+ // out[0] = DSPSampClamp(in[0] + s32(tex->audioBuf[(i + tex->playedSamples) * 2]) * 0x50F4 / 0x8000 *
360+ // SfxVolume); out[1] =
361+ // DSPSampClamp(in[1] + s32(tex->audioBuf[(i + tex->playedSamples) * 2 + 1]) * 0x50F4 / 0x8000 *
362+ // SfxVolume);
363+ // }
364+ // } else {
365+ // for (u32 i = 0; i < thisSamples; ++i, out += 2) {
366+ // out[0] = DSPSampClamp(s32(tex->audioBuf[(i + tex->playedSamples) * 2]) * 0x50F4 / 0x8000 * SfxVolume);
367+ // out[1] = DSPSampClamp(s32(tex->audioBuf[(i + tex->playedSamples) * 2 + 1]) * 0x50F4 / 0x8000 * SfxVolume);
368+ // }
369+ // }
370+ // tex->playedSamples += thisSamples;
371+ // samples -= thisSamples;
372+ // } else {
373+ // /* metaforce addition: failsafe for buffer overrun */
374+ // if (in)
375+ // memmove(out, in, samples * 4);
376+ // else
377+ // memset(out, 0, samples * 4);
378+ // // fprintf(stderr, "dropped %d samples\n", samples);
379+ // return;
380+ // }
381+ // }
381382}
382383
383384void CMoviePlayer::MixStaticAudio (s16* out, const s16* in, u32 samples) {
384- // if (!StaticAudio)
385- // return;
386- // while (samples) {
387- // u32 thisSamples = std::min(StaticLoopEnd - StaticAudioOffset, samples);
388- // const u8* thisOffsetLeft = &StaticAudio[StaticAudioOffset / 2];
389- // const u8* thisOffsetRight = &StaticAudio[StaticAudioSize / 2 + StaticAudioOffset / 2];
390- //
391- // /* metaforce addition: mix samples with `in` or no mix */
392- // if (in) {
393- // for (u32 i = 0; i < thisSamples; i += 2) {
394- // out[0] = DSPSampClamp(
395- // in[0] + s32(g721_decoder(thisOffsetLeft[0] & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
396- // out[1] = DSPSampClamp(
397- // in[1] + s32(g721_decoder(thisOffsetRight[0] & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
398- // out[2] = DSPSampClamp(
399- // in[2] + s32(g721_decoder(thisOffsetLeft[0] >> 4 & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
400- // out[3] = DSPSampClamp(
401- // in[3] + s32(g721_decoder(thisOffsetRight[0] >> 4 & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
402- // thisOffsetLeft += 1;
403- // thisOffsetRight += 1;
404- // out += 4;
405- // in += 4;
406- // }
407- // } else {
408- // for (u32 i = 0; i < thisSamples; i += 2) {
409- // out[0] =
410- // DSPSampClamp(s32(g721_decoder(thisOffsetLeft[0] & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
411- // out[1] =
412- // DSPSampClamp(s32(g721_decoder(thisOffsetRight[0] & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
413- // out[2] = DSPSampClamp(
414- // s32(g721_decoder(thisOffsetLeft[0] >> 4 & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
415- // out[3] = DSPSampClamp(
416- // s32(g721_decoder(thisOffsetRight[0] >> 4 & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
417- // thisOffsetLeft += 1;
418- // thisOffsetRight += 1;
419- // out += 4;
420- // }
421- // }
422- //
423- // StaticAudioOffset += thisSamples;
424- // if (StaticAudioOffset == StaticLoopEnd)
425- // StaticAudioOffset = StaticLoopBegin;
426- // samples -= thisSamples;
427- // }
385+ // if (!StaticAudio)
386+ // return;
387+ // while (samples) {
388+ // u32 thisSamples = std::min(StaticLoopEnd - StaticAudioOffset, samples);
389+ // const u8* thisOffsetLeft = &StaticAudio[StaticAudioOffset / 2];
390+ // const u8* thisOffsetRight = &StaticAudio[StaticAudioSize / 2 + StaticAudioOffset / 2];
391+ //
392+ // /* metaforce addition: mix samples with `in` or no mix */
393+ // if (in) {
394+ // for (u32 i = 0; i < thisSamples; i += 2) {
395+ // out[0] = DSPSampClamp(
396+ // in[0] + s32(g721_decoder(thisOffsetLeft[0] & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
397+ // out[1] = DSPSampClamp(
398+ // in[1] + s32(g721_decoder(thisOffsetRight[0] & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
399+ // out[2] = DSPSampClamp(
400+ // in[2] + s32(g721_decoder(thisOffsetLeft[0] >> 4 & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
401+ // out[3] = DSPSampClamp(
402+ // in[3] + s32(g721_decoder(thisOffsetRight[0] >> 4 & 0xf, &StaticStateRight) * StaticVolumeAtten /
403+ // 0x8000));
404+ // thisOffsetLeft += 1;
405+ // thisOffsetRight += 1;
406+ // out += 4;
407+ // in += 4;
408+ // }
409+ // } else {
410+ // for (u32 i = 0; i < thisSamples; i += 2) {
411+ // out[0] =
412+ // DSPSampClamp(s32(g721_decoder(thisOffsetLeft[0] & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
413+ // out[1] =
414+ // DSPSampClamp(s32(g721_decoder(thisOffsetRight[0] & 0xf, &StaticStateRight) * StaticVolumeAtten /
415+ // 0x8000));
416+ // out[2] = DSPSampClamp(
417+ // s32(g721_decoder(thisOffsetLeft[0] >> 4 & 0xf, &StaticStateLeft) * StaticVolumeAtten / 0x8000));
418+ // out[3] = DSPSampClamp(
419+ // s32(g721_decoder(thisOffsetRight[0] >> 4 & 0xf, &StaticStateRight) * StaticVolumeAtten / 0x8000));
420+ // thisOffsetLeft += 1;
421+ // thisOffsetRight += 1;
422+ // out += 4;
423+ // }
424+ // }
425+ //
426+ // StaticAudioOffset += thisSamples;
427+ // if (StaticAudioOffset == StaticLoopEnd)
428+ // StaticAudioOffset = StaticLoopBegin;
429+ // samples -= thisSamples;
430+ // }
428431}
429432
430433void CMoviePlayer::Rewind () {
0 commit comments