From 8aa476aeeb9a51c2b9fcfed0abab0e2bdd476526 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Thu, 21 Feb 2019 14:56:25 +0000 Subject: [PATCH] Previous mpeg audio code worked for me in debug mode, but the release build had some serious corruption issues when being built in visual studio. Replaced the old spaghetti code with a more modern implementation. --- Src/Model3/DSB.cpp | 256 ++-- Src/Model3/DSB.h | 14 +- Src/Pkgs/minimp3.h | 1807 +++++++++++++++++++++++++++++ Src/Sound/MPEG/MPEG.h | 138 --- Src/Sound/MPEG/MpegAudio.cpp | 130 +++ Src/Sound/MPEG/MpegAudio.h | 18 + Src/Sound/MPEG/amp.h | 91 -- Src/Sound/MPEG/amp_audio.cpp | 432 ------- Src/Sound/MPEG/amp_audio.h | 208 ---- Src/Sound/MPEG/config.h | 90 -- Src/Sound/MPEG/dump.cpp | 92 -- Src/Sound/MPEG/dump.h | 46 - Src/Sound/MPEG/formats.h | 42 - Src/Sound/MPEG/getbits.cpp | 412 ------- Src/Sound/MPEG/getbits.h | 107 -- Src/Sound/MPEG/getdata.cpp | 260 ----- Src/Sound/MPEG/getdata.h | 70 -- Src/Sound/MPEG/huffman.cpp | 240 ---- Src/Sound/MPEG/huffman.h | 287 ----- Src/Sound/MPEG/layer2.cpp | 354 ------ Src/Sound/MPEG/layer2.h | 218 ---- Src/Sound/MPEG/layer3.cpp | 225 ---- Src/Sound/MPEG/layer3.h | 44 - Src/Sound/MPEG/misc2.cpp | 852 -------------- Src/Sound/MPEG/misc2.h | 281 ----- Src/Sound/MPEG/position.cpp | 131 --- Src/Sound/MPEG/position.h | 38 - Src/Sound/MPEG/proto.h | 54 - Src/Sound/MPEG/rtbuf.h | 91 -- Src/Sound/MPEG/transform.cpp | 1546 ------------------------ Src/Sound/MPEG/transform.h | 196 ---- Src/Sound/MPEG/util.cpp | 143 --- Src/Supermodel.h | 1 - VS2008/Supermodel.vcxproj | 80 +- VS2008/Supermodel.vcxproj.filters | 90 +- 35 files changed, 2100 insertions(+), 6984 deletions(-) create mode 100644 Src/Pkgs/minimp3.h delete mode 100644 Src/Sound/MPEG/MPEG.h create mode 100644 Src/Sound/MPEG/MpegAudio.cpp create mode 100644 Src/Sound/MPEG/MpegAudio.h delete mode 100644 Src/Sound/MPEG/amp.h delete mode 100644 Src/Sound/MPEG/amp_audio.cpp delete mode 100644 Src/Sound/MPEG/amp_audio.h delete mode 100644 Src/Sound/MPEG/config.h delete mode 100644 Src/Sound/MPEG/dump.cpp delete mode 100644 Src/Sound/MPEG/dump.h delete mode 100644 Src/Sound/MPEG/formats.h delete mode 100644 Src/Sound/MPEG/getbits.cpp delete mode 100644 Src/Sound/MPEG/getbits.h delete mode 100644 Src/Sound/MPEG/getdata.cpp delete mode 100644 Src/Sound/MPEG/getdata.h delete mode 100644 Src/Sound/MPEG/huffman.cpp delete mode 100644 Src/Sound/MPEG/huffman.h delete mode 100644 Src/Sound/MPEG/layer2.cpp delete mode 100644 Src/Sound/MPEG/layer2.h delete mode 100644 Src/Sound/MPEG/layer3.cpp delete mode 100644 Src/Sound/MPEG/layer3.h delete mode 100644 Src/Sound/MPEG/misc2.cpp delete mode 100644 Src/Sound/MPEG/misc2.h delete mode 100644 Src/Sound/MPEG/position.cpp delete mode 100644 Src/Sound/MPEG/position.h delete mode 100644 Src/Sound/MPEG/proto.h delete mode 100644 Src/Sound/MPEG/rtbuf.h delete mode 100644 Src/Sound/MPEG/transform.cpp delete mode 100644 Src/Sound/MPEG/transform.h delete mode 100644 Src/Sound/MPEG/util.cpp diff --git a/Src/Model3/DSB.cpp b/Src/Model3/DSB.cpp index 5aba1ec..74eb582 100644 --- a/Src/Model3/DSB.cpp +++ b/Src/Model3/DSB.cpp @@ -39,7 +39,7 @@ */ #include "Supermodel.h" - +#include "Sound/MPEG/MpegAudio.h" /****************************************************************************** Resampler @@ -230,30 +230,32 @@ void CDSB1::IOWrite8(UINT32 addr, UINT8 data) if (data == 0) // stop { - MPEG_StopPlaying(); + MpegDec::Stop(); return; } if (data == 1) // play without loop { //printf("====> Playing %06X (mpegEnd=%06X)\n", mpegStart, mpegEnd); - MPEG_SetLoop(NULL, 0); - usingLoopStart = 0; // save the settings of the MPEG currently playing - usingLoopEnd = 0; - usingMPEGStart = mpegStart; - usingMPEGEnd = mpegEnd; - MPEG_PlayMemory((const char *) &mpegROM[mpegStart], mpegEnd-mpegStart); + + usingLoopStart = 0; // save the settings of the MPEG currently playing + usingLoopEnd = 0; + usingMPEGStart = mpegStart; + usingMPEGEnd = mpegEnd; + + MpegDec::SetMemory(&mpegROM[mpegStart], mpegEnd - mpegStart, false); return; } if (data == 2) // play with loop (NOTE: I don't think this actually loops b/c MPEG_PlayMemory() clears lstart) { //printf("====> Playing w/ loop %06X (mpegEnd=%06X, loopStart=%06X, loopEnd=%06X)\n", mpegStart, mpegEnd, loopStart, loopEnd); - usingLoopStart = 0; // MPEG_PlayMemory() clears these settings and Z80 will set them up later - usingLoopEnd = 0; - usingMPEGStart = mpegStart; - usingMPEGEnd = mpegEnd; - MPEG_PlayMemory((const char *) &mpegROM[mpegStart], mpegEnd-mpegStart); + usingLoopStart = 0; // MPEG_PlayMemory() clears these settings and Z80 will set them up later + usingLoopEnd = 0; + usingMPEGStart = mpegStart; + usingMPEGEnd = mpegEnd; + + MpegDec::SetMemory(&mpegROM[mpegStart], mpegEnd - mpegStart, false); // assume not looped for now return; } break; @@ -284,15 +286,15 @@ void CDSB1::IOWrite8(UINT32 addr, UINT8 data) // SWA: if loop end is zero, it means "keep previous end marker" if (loopEnd == 0) { - usingLoopStart = loopStart; - usingLoopEnd = mpegEnd-loopStart; - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); + usingLoopStart = loopStart; + usingLoopEnd = mpegEnd-loopStart; + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); } else { - usingLoopStart = loopStart; - usingLoopEnd = loopEnd-loopStart; - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); + usingLoopStart = loopStart; + usingLoopEnd = loopEnd-loopStart; + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); } } @@ -319,11 +321,11 @@ void CDSB1::IOWrite8(UINT32 addr, UINT8 data) } else { - loopEnd = endLatch; + loopEnd = endLatch; + usingLoopStart = loopStart; + usingLoopEnd = loopEnd-loopStart; + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); //printf("loopEnd = %08X\n", loopEnd); - usingLoopStart = loopStart; - usingLoopEnd = loopEnd-loopStart; - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); } break; @@ -347,22 +349,22 @@ void CDSB1::IOWrite8(UINT32 addr, UINT8 data) UINT8 CDSB1::IORead8(UINT32 addr) { - int progress, end; + int progress; switch ((addr&0xFF)) { case 0xE2: // MPEG position, high byte - MPEG_GetPlayPosition(&progress, &end); + progress = MpegDec::GetPosition(); progress += mpegStart; // byte address currently playing return (progress>>16)&0xFF; case 0xE3: // MPEG position, middle byte - MPEG_GetPlayPosition(&progress, &end); + progress = MpegDec::GetPosition(); progress += mpegStart; return (progress>>8)&0xFF; case 0xE4: // MPEG position, low byte - MPEG_GetPlayPosition(&progress, &end); + progress = MpegDec::GetPosition(); progress += mpegStart; return progress&0xFF; @@ -452,14 +454,13 @@ void CDSB1::RunFrame(INT16 *audioL, INT16 *audioR) v = (UINT8) ((float) 255.0f * (float) volume /127.0f); // Decode MPEG for this frame - INT16 *mpegFill[2] = { &mpegL[retainedSamples], &mpegR[retainedSamples] }; - MPEG_Decode(mpegFill, 32000/60-retainedSamples+2); + MpegDec::DecodeAudio(&mpegL[retainedSamples], &mpegR[retainedSamples], 32000 / 60 - retainedSamples + 2); retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, mpegL, mpegR, v, v, 44100/60, 32000/60+2, 44100, 32000); } void CDSB1::Reset(void) { - MPEG_StopPlaying(); + MpegDec::Stop(); Resampler.Reset(); retainedSamples = 0; @@ -478,17 +479,16 @@ void CDSB1::Reset(void) void CDSB1::SaveState(CBlockFile *StateFile) { - int i, j; UINT32 playOffset, endOffset; UINT8 isPlaying; StateFile->NewBlock("DSB1", __FILE__); // MPEG playback state - isPlaying = (UINT8) MPEG_IsPlaying(); - MPEG_GetPlayPosition(&i, &j); - playOffset = (UINT32) i; // in case sizeof(int) != sizeof(INT32) - endOffset = (UINT32) j; + isPlaying = (UINT8)MpegDec::IsLoaded(); + playOffset = (UINT32)MpegDec::GetPosition(); + endOffset = 0; + StateFile->Write(&isPlaying, sizeof(isPlaying)); StateFile->Write(&playOffset, sizeof(playOffset)); StateFile->Write(&endOffset, sizeof(endOffset)); @@ -553,13 +553,17 @@ void CDSB1::LoadState(CBlockFile *StateFile) // Restart MPEG audio at the appropriate position if (isPlaying) { - MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart); - if (usingLoopEnd != 0) // only if looping was actually enabled - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); - MPEG_SetPlayPosition(playOffset, endOffset); + MpegDec::SetMemory(&mpegROM[usingMPEGStart], usingMPEGEnd - usingMPEGStart, false); + + if (usingLoopEnd != 0) { // only if looping was actually enabled + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); + } + + MpegDec::SetPosition(playOffset); + } + else { + MpegDec::Stop(); } - else - MPEG_StopPlaying(); } // Offsets of memory regions within DSB1's pool @@ -590,9 +594,6 @@ bool CDSB1::Init(const UINT8 *progROMPtr, const UINT8 *mpegROMPtr) // Initialize Z80 CPU Z80.Init(this, Z80IRQCallback); - // MPEG decoder - if (OKAY != MPEG_Init()) - return ErrorLog("Insufficient memory to initialize MPEG decoder."); retainedSamples = 0; return OKAY; @@ -607,31 +608,36 @@ CDSB1::CDSB1(const Util::Config::Node &config) : m_config(config), Resampler(config) { - progROM = NULL; - mpegROM = NULL; - memoryPool = NULL; - ram = NULL; - mpegL = NULL; - mpegR = NULL; + progROM = NULL; + mpegROM = NULL; + memoryPool = NULL; + ram = NULL; + mpegL = NULL; + mpegR = NULL; + + // must init these otherwise we end up trying to read illegal addresses + mpegStart = 0; + mpegEnd = 0; + mpegState = 0; + loopStart = 0; + loopEnd = 0; DebugLog("Built DSB1 Board\n"); } CDSB1::~CDSB1(void) { - MPEG_Shutdown(); - if (memoryPool != NULL) { delete [] memoryPool; memoryPool = NULL; } - progROM = NULL; - mpegROM = NULL; - ram = NULL; - mpegL = NULL; - mpegR = NULL; + progROM = NULL; + mpegROM = NULL; + ram = NULL; + mpegL = NULL; + mpegR = NULL; DebugLog("Destroyed DSB1 Board\n"); } @@ -703,19 +709,20 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) else if (byte == 0x74 || byte == 0x75) // "start play" { - usingLoopStart = 0; - usingLoopEnd = 0; - usingMPEGStart = mpegStart; - usingMPEGEnd = mpegEnd; - MPEG_PlayMemory((const char *) &mpegROM[mpegStart], mpegEnd-mpegStart); - //printf("playing %X\n", mpegStart); - mpegState = ST_IDLE; - playing = 1; + usingLoopStart = 0; + usingLoopEnd = 0; + usingMPEGStart = mpegStart; + usingMPEGEnd = mpegEnd; + playing = 1; + + MpegDec::SetMemory(&mpegROM[mpegStart], mpegEnd - mpegStart, false); + + mpegState = ST_IDLE; } else if (byte == 0x84 || byte == 0x85) { - MPEG_StopPlaying(); + MpegDec::Stop(); playing = 0; } @@ -752,13 +759,11 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) if (playing) { - //printf("Setting loop point to %x\n", mpegStart); - usingLoopStart = mpegStart; - usingLoopEnd = mpegEnd-mpegStart; - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); + usingLoopStart = mpegStart; + usingLoopEnd = mpegEnd - mpegStart; + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); } - //printf("mpegStart=%x\n", mpegStart); break; case ST_GOT24: mpegEnd &= 0x00FFFF; @@ -773,21 +778,13 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) case ST_24_1: mpegEnd &= 0xFFFF00; mpegEnd |= (byte); - //printf("mpegEnd=%x\n", mpegEnd); - // default to full stereo - //mixer_set_stereo_volume(0, 255, 255); - //mixer_set_stereo_pan(0, MIXER_PAN_RIGHT, MIXER_PAN_LEFT); stereo = StereoMode::Stereo; mpegState = ST_IDLE; break; case ST_GOTA0: - // ch 0 mono - //mixer_set_stereo_volume(0, 0, 255); - //printf("ch 0 mono\n"); - //mixer_set_stereo_pan(0, MIXER_PAN_CENTER, MIXER_PAN_CENTER); - stereo = (byte != 0x00) ? StereoMode::MonoRight : StereoMode::Stereo; + stereo = (byte != 0x00) ? StereoMode::MonoLeft : StereoMode::Stereo; mpegState = ST_IDLE; break; @@ -795,31 +792,26 @@ void CDSB2::WriteMPEGFIFO(UINT8 byte) mpegState = ST_IDLE; if (byte == 0x75) { - usingLoopStart = 0; - usingLoopEnd = 0; - usingMPEGStart = mpegStart; - usingMPEGEnd = mpegEnd; - MPEG_PlayMemory((const char *) &mpegROM[mpegStart], mpegEnd-mpegStart); - //printf("playing %X (from st_gota4)\n", mpegStart); - playing = 1; + usingLoopStart = 0; + usingLoopEnd = 0; + usingMPEGStart = mpegStart; + usingMPEGEnd = mpegEnd; + playing = 1; + MpegDec::SetMemory(&mpegROM[mpegStart], mpegEnd - mpegStart, false); } break; case ST_GOTA5: mpegState = ST_IDLE; break; case ST_GOTB1: - // ch 1 mono - //printf("ch 1 mono\n"); - //mixer_set_stereo_volume(0, 255, 0); - //mixer_set_stereo_pan(0, MIXER_PAN_CENTER, MIXER_PAN_CENTER); - stereo = (byte != 0x00) ? StereoMode::MonoLeft : StereoMode::Stereo; + stereo = (byte != 0x00) ? StereoMode::MonoRight : StereoMode::Stereo; mpegState = ST_IDLE; break; case ST_GOTB4: mpegState = ST_IDLE; if (byte == 0x96) { - MPEG_StopPlaying(); + MpegDec::Stop(); playing = 0; } break; @@ -1033,12 +1025,12 @@ void CDSB2::RunFrame(INT16 *audioL, INT16 *audioR) M68KGetContext(&M68K); // Decode MPEG for this frame - INT16 *mpegFill[2] = { &mpegL[retainedSamples], &mpegR[retainedSamples] }; - MPEG_Decode(mpegFill, 32000/60-retainedSamples+2); + MpegDec::DecodeAudio(&mpegL[retainedSamples], &mpegR[retainedSamples], 32000 / 60 - retainedSamples + 2); INT16 *leftChannelSource = nullptr; INT16 *rightChannelSource = nullptr; UINT8 volL=0, volR=0; + switch (stereo) { default: @@ -1051,22 +1043,23 @@ void CDSB2::RunFrame(INT16 *audioL, INT16 *audioR) case StereoMode::MonoLeft: leftChannelSource = mpegL; rightChannelSource = mpegL; - volL = volume[1]; - volR = volume[1]; + volL = volume[0]; + volR = volume[0]; break; case StereoMode::MonoRight: leftChannelSource = mpegR; rightChannelSource = mpegR; - volL = volume[0]; - volR = volume[0]; + volL = volume[1]; + volR = volume[1]; break; } - retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, leftChannelSource, rightChannelSource, volL, volR, 44100/60, 32000/60+2, 44100, 32000); + + retainedSamples = Resampler.UpSampleAndMix(audioL, audioR, leftChannelSource, rightChannelSource, volL, volR, 44100/60, 32000/60+2, 44100, 32000); } void CDSB2::Reset(void) { - MPEG_StopPlaying(); + MpegDec::Stop(); Resampler.Reset(); retainedSamples = 0; @@ -1092,17 +1085,16 @@ void CDSB2::Reset(void) void CDSB2::SaveState(CBlockFile *StateFile) { - int i, j; UINT32 playOffset, endOffset; UINT8 isPlaying; StateFile->NewBlock("DSB2", __FILE__); // MPEG playback state - isPlaying = (UINT8) MPEG_IsPlaying(); - MPEG_GetPlayPosition(&i, &j); - playOffset = (UINT32) i; // in case sizeof(int) != sizeof(INT32) - endOffset = (UINT32) j; + isPlaying = (UINT8)MpegDec::IsLoaded(); + playOffset = (UINT32)MpegDec::GetPosition(); + endOffset = 0; + StateFile->Write(&isPlaying, sizeof(isPlaying)); StateFile->Write(&playOffset, sizeof(playOffset)); StateFile->Write(&endOffset, sizeof(endOffset)); @@ -1173,13 +1165,17 @@ void CDSB2::LoadState(CBlockFile *StateFile) // Restart MPEG audio at the appropriate position if (isPlaying) { - MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart); - if (usingLoopEnd != 0) // only if looping was actually enabled - MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); - MPEG_SetPlayPosition(playOffset, endOffset); + MpegDec::SetMemory(&mpegROM[usingMPEGStart], usingMPEGEnd - usingMPEGStart, false); + + if (usingLoopEnd != 0) { // only if looping was actually enabled + MpegDec::UpdateMemory(&mpegROM[usingLoopStart], usingLoopEnd, true); + } + + MpegDec::SetPosition(playOffset); + } + else { + MpegDec::Stop(); } - else - MPEG_StopPlaying(); //DEBUG //printf("DSB2 PC=%06X\n", M68KGetPC()); @@ -1197,7 +1193,7 @@ void CDSB2::LoadState(CBlockFile *StateFile) bool CDSB2::Init(const UINT8 *progROMPtr, const UINT8 *mpegROMPtr) { - float memSizeMB = (float)DSB2_MEMORY_POOL_SIZE/(float)0x100000; + float memSizeMB = (float)DSB2_MEMORY_POOL_SIZE/(float)0x100000; // Receive ROM progROM = progROMPtr; @@ -1221,10 +1217,6 @@ bool CDSB2::Init(const UINT8 *progROMPtr, const UINT8 *mpegROMPtr) M68KSetIRQCallback(NULL); // use default behavior (autovector, clear interrupt) M68KGetContext(&M68K); - - // MPEG decoder - if (OKAY != MPEG_Init()) - return ErrorLog("Insufficient memory to initialize MPEG decoder."); retainedSamples = 0; return OKAY; @@ -1239,31 +1231,35 @@ CDSB2::CDSB2(const Util::Config::Node &config) : m_config(config), Resampler(config) { - progROM = NULL; - mpegROM = NULL; - memoryPool = NULL; - ram = NULL; - mpegL = NULL; - mpegR = NULL; + progROM = NULL; + mpegROM = NULL; + memoryPool = NULL; + ram = NULL; + mpegL = NULL; + mpegR = NULL; + + cmdLatch = 0; + mpegState = 0; + mpegStart = 0; + mpegEnd = 0; + playing = 0; DebugLog("Built DSB2 Board\n"); } CDSB2::~CDSB2(void) { - MPEG_Shutdown(); - if (memoryPool != NULL) { delete [] memoryPool; memoryPool = NULL; } - progROM = NULL; - mpegROM = NULL; - ram = NULL; - mpegL = NULL; - mpegR = NULL; + progROM = NULL; + mpegROM = NULL; + ram = NULL; + mpegL = NULL; + mpegR = NULL; DebugLog("Destroyed DSB2 Board\n"); } \ No newline at end of file diff --git a/Src/Model3/DSB.h b/Src/Model3/DSB.h index 2cb948d..10f5f8e 100644 --- a/Src/Model3/DSB.h +++ b/Src/Model3/DSB.h @@ -233,7 +233,7 @@ private: UINT8 status; UINT8 cmdLatch; UINT8 volume; // 0x00-0x7F - UINT8 stereo; + UINT8 stereo; // Z80 CPU CZ80 Z80; @@ -284,12 +284,12 @@ private: INT16 *mpegL, *mpegR; // Stereo mode (do not change values because they are used in save states!) - enum StereoMode: uint8_t - { - Stereo = 0, // both channels - MonoLeft = 1, // mono, using left stream as source data - MonoRight = 2 // mono, using right stream as source data - }; + enum class StereoMode: uint8_t + { + Stereo = 0, // both channels + MonoLeft = 1, // mono, using left stream as source data + MonoRight = 2 // mono, using right stream as source data + }; // DSB memory const UINT8 *progROM; // 68K program ROM (passed in from parent object) diff --git a/Src/Pkgs/minimp3.h b/Src/Pkgs/minimp3.h new file mode 100644 index 0000000..a878b12 --- /dev/null +++ b/Src/Pkgs/minimp3.h @@ -0,0 +1,1807 @@ +#ifndef MINIMP3_H +#define MINIMP3_H +/* + https://github.com/lieff/minimp3 + To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. + This software is distributed without any warranty. + See . +*/ +#include + +#define MINIMP3_MAX_SAMPLES_PER_FRAME (1152*2) + +typedef struct +{ + int frame_bytes, channels, hz, layer, bitrate_kbps; +} mp3dec_frame_info_t; + +typedef struct +{ + float mdct_overlap[2][9*32], qmf_state[15*2*32]; + int reserv, free_format_bytes; + unsigned char header[4], reserv_buf[511]; +} mp3dec_t; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void mp3dec_init(mp3dec_t *dec); +#ifndef MINIMP3_FLOAT_OUTPUT +typedef int16_t mp3d_sample_t; +#else /* MINIMP3_FLOAT_OUTPUT */ +typedef float mp3d_sample_t; +void mp3dec_f32_to_s16(const float *in, int16_t *out, int num_samples); +#endif /* MINIMP3_FLOAT_OUTPUT */ +int mp3dec_decode_frame(mp3dec_t *dec, const uint8_t *mp3, int mp3_bytes, mp3d_sample_t *pcm, mp3dec_frame_info_t *info); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* MINIMP3_H */ +#if defined(MINIMP3_IMPLEMENTATION) && !defined(_MINIMP3_IMPLEMENTATION_GUARD) +#define _MINIMP3_IMPLEMENTATION_GUARD + +#include +#include + +#define MAX_FREE_FORMAT_FRAME_SIZE 2304 /* more than ISO spec's */ +#ifndef MAX_FRAME_SYNC_MATCHES +#define MAX_FRAME_SYNC_MATCHES 10 +#endif /* MAX_FRAME_SYNC_MATCHES */ + +#define MAX_L3_FRAME_PAYLOAD_BYTES MAX_FREE_FORMAT_FRAME_SIZE /* MUST be >= 320000/8/32000*1152 = 1440 */ + +#define MAX_BITRESERVOIR_BYTES 511 +#define SHORT_BLOCK_TYPE 2 +#define STOP_BLOCK_TYPE 3 +#define MODE_MONO 3 +#define MODE_JOINT_STEREO 1 +#define HDR_SIZE 4 +#define HDR_IS_MONO(h) (((h[3]) & 0xC0) == 0xC0) +#define HDR_IS_MS_STEREO(h) (((h[3]) & 0xE0) == 0x60) +#define HDR_IS_FREE_FORMAT(h) (((h[2]) & 0xF0) == 0) +#define HDR_IS_CRC(h) (!((h[1]) & 1)) +#define HDR_TEST_PADDING(h) ((h[2]) & 0x2) +#define HDR_TEST_MPEG1(h) ((h[1]) & 0x8) +#define HDR_TEST_NOT_MPEG25(h) ((h[1]) & 0x10) +#define HDR_TEST_I_STEREO(h) ((h[3]) & 0x10) +#define HDR_TEST_MS_STEREO(h) ((h[3]) & 0x20) +#define HDR_GET_STEREO_MODE(h) (((h[3]) >> 6) & 3) +#define HDR_GET_STEREO_MODE_EXT(h) (((h[3]) >> 4) & 3) +#define HDR_GET_LAYER(h) (((h[1]) >> 1) & 3) +#define HDR_GET_BITRATE(h) ((h[2]) >> 4) +#define HDR_GET_SAMPLE_RATE(h) (((h[2]) >> 2) & 3) +#define HDR_GET_MY_SAMPLE_RATE(h) (HDR_GET_SAMPLE_RATE(h) + (((h[1] >> 3) & 1) + ((h[1] >> 4) & 1))*3) +#define HDR_IS_FRAME_576(h) ((h[1] & 14) == 2) +#define HDR_IS_LAYER_1(h) ((h[1] & 6) == 6) + +#define BITS_DEQUANTIZER_OUT -1 +#define MAX_SCF (255 + BITS_DEQUANTIZER_OUT*4 - 210) +#define MAX_SCFI ((MAX_SCF + 3) & ~3) + +#define MINIMP3_MIN(a, b) ((a) > (b) ? (b) : (a)) +#define MINIMP3_MAX(a, b) ((a) < (b) ? (b) : (a)) + +#if !defined(MINIMP3_NO_SIMD) + +#if !defined(MINIMP3_ONLY_SIMD) && (defined(_M_X64) || defined(_M_ARM64) || defined(__x86_64__) || defined(__aarch64__)) +/* x64 always have SSE2, arm64 always have neon, no need for generic code */ +#define MINIMP3_ONLY_SIMD +#endif /* SIMD checks... */ + +#if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || ((defined(__i386__) || defined(__x86_64__)) && defined(__SSE2__)) +#if defined(_MSC_VER) +#include +#endif /* defined(_MSC_VER) */ +#include +#define HAVE_SSE 1 +#define HAVE_SIMD 1 +#define VSTORE _mm_storeu_ps +#define VLD _mm_loadu_ps +#define VSET _mm_set1_ps +#define VADD _mm_add_ps +#define VSUB _mm_sub_ps +#define VMUL _mm_mul_ps +#define VMAC(a, x, y) _mm_add_ps(a, _mm_mul_ps(x, y)) +#define VMSB(a, x, y) _mm_sub_ps(a, _mm_mul_ps(x, y)) +#define VMUL_S(x, s) _mm_mul_ps(x, _mm_set1_ps(s)) +#define VREV(x) _mm_shuffle_ps(x, x, _MM_SHUFFLE(0, 1, 2, 3)) +typedef __m128 f4; +#if defined(_MSC_VER) || defined(MINIMP3_ONLY_SIMD) +#define minimp3_cpuid __cpuid +#else /* defined(_MSC_VER) || defined(MINIMP3_ONLY_SIMD) */ +static __inline__ __attribute__((always_inline)) void minimp3_cpuid(int CPUInfo[], const int InfoType) +{ +#if defined(__PIC__) + __asm__ __volatile__( +#if defined(__x86_64__) + "push %%rbx\n" + "cpuid\n" + "xchgl %%ebx, %1\n" + "pop %%rbx\n" +#else /* defined(__x86_64__) */ + "xchgl %%ebx, %1\n" + "cpuid\n" + "xchgl %%ebx, %1\n" +#endif /* defined(__x86_64__) */ + : "=a" (CPUInfo[0]), "=r" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) + : "a" (InfoType)); +#else /* defined(__PIC__) */ + __asm__ __volatile__( + "cpuid" + : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) + : "a" (InfoType)); +#endif /* defined(__PIC__)*/ +} +#endif /* defined(_MSC_VER) || defined(MINIMP3_ONLY_SIMD) */ +static int have_simd() +{ +#ifdef MINIMP3_ONLY_SIMD + return 1; +#else /* MINIMP3_ONLY_SIMD */ + static int g_have_simd; + int CPUInfo[4]; +#ifdef MINIMP3_TEST + static int g_counter; + if (g_counter++ > 100) + return 0; +#endif /* MINIMP3_TEST */ + if (g_have_simd) + goto end; + minimp3_cpuid(CPUInfo, 0); + g_have_simd = 1; + if (CPUInfo[0] > 0) + { + minimp3_cpuid(CPUInfo, 1); + g_have_simd = (CPUInfo[3] & (1 << 26)) + 1; /* SSE2 */ + } +end: + return g_have_simd - 1; +#endif /* MINIMP3_ONLY_SIMD */ +} +#elif defined(__ARM_NEON) || defined(__aarch64__) +#include +#define HAVE_SIMD 1 +#define VSTORE vst1q_f32 +#define VLD vld1q_f32 +#define VSET vmovq_n_f32 +#define VADD vaddq_f32 +#define VSUB vsubq_f32 +#define VMUL vmulq_f32 +#define VMAC(a, x, y) vmlaq_f32(a, x, y) +#define VMSB(a, x, y) vmlsq_f32(a, x, y) +#define VMUL_S(x, s) vmulq_f32(x, vmovq_n_f32(s)) +#define VREV(x) vcombine_f32(vget_high_f32(vrev64q_f32(x)), vget_low_f32(vrev64q_f32(x))) +typedef float32x4_t f4; +static int have_simd() +{ /* TODO: detect neon for !MINIMP3_ONLY_SIMD */ + return 1; +} +#else /* SIMD checks... */ +#define HAVE_SIMD 0 +#ifdef MINIMP3_ONLY_SIMD +#error MINIMP3_ONLY_SIMD used, but SSE/NEON not enabled +#endif /* MINIMP3_ONLY_SIMD */ +#endif /* SIMD checks... */ +#else /* !defined(MINIMP3_NO_SIMD) */ +#define HAVE_SIMD 0 +#endif /* !defined(MINIMP3_NO_SIMD) */ + +typedef struct +{ + const uint8_t *buf; + int pos, limit; +} bs_t; + +typedef struct +{ + float scf[3*64]; + uint8_t total_bands, stereo_bands, bitalloc[64], scfcod[64]; +} L12_scale_info; + +typedef struct +{ + uint8_t tab_offset, code_tab_width, band_count; +} L12_subband_alloc_t; + +typedef struct +{ + const uint8_t *sfbtab; + uint16_t part_23_length, big_values, scalefac_compress; + uint8_t global_gain, block_type, mixed_block_flag, n_long_sfb, n_short_sfb; + uint8_t table_select[3], region_count[3], subblock_gain[3]; + uint8_t preflag, scalefac_scale, count1_table, scfsi; +} L3_gr_info_t; + +typedef struct +{ + bs_t bs; + uint8_t maindata[MAX_BITRESERVOIR_BYTES + MAX_L3_FRAME_PAYLOAD_BYTES]; + L3_gr_info_t gr_info[4]; + float grbuf[2][576], scf[40], syn[18 + 15][2*32]; + uint8_t ist_pos[2][39]; +} mp3dec_scratch_t; + +static void bs_init(bs_t *bs, const uint8_t *data, int bytes) +{ + bs->buf = data; + bs->pos = 0; + bs->limit = bytes*8; +} + +static uint32_t get_bits(bs_t *bs, int n) +{ + uint32_t next, cache = 0, s = bs->pos & 7; + int shl = n + s; + const uint8_t *p = bs->buf + (bs->pos >> 3); + if ((bs->pos += n) > bs->limit) + return 0; + next = *p++ & (255 >> s); + while ((shl -= 8) > 0) + { + cache |= next << shl; + next = *p++; + } + return cache | (next >> -shl); +} + +static int hdr_valid(const uint8_t *h) +{ + return h[0] == 0xff && + ((h[1] & 0xF0) == 0xf0 || (h[1] & 0xFE) == 0xe2) && + (HDR_GET_LAYER(h) != 0) && + (HDR_GET_BITRATE(h) != 15) && + (HDR_GET_SAMPLE_RATE(h) != 3); +} + +static int hdr_compare(const uint8_t *h1, const uint8_t *h2) +{ + return hdr_valid(h2) && + ((h1[1] ^ h2[1]) & 0xFE) == 0 && + ((h1[2] ^ h2[2]) & 0x0C) == 0 && + !(HDR_IS_FREE_FORMAT(h1) ^ HDR_IS_FREE_FORMAT(h2)); +} + +static unsigned hdr_bitrate_kbps(const uint8_t *h) +{ + static const uint8_t halfrate[2][3][15] = { + { { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,4,8,12,16,20,24,28,32,40,48,56,64,72,80 }, { 0,16,24,28,32,40,48,56,64,72,80,88,96,112,128 } }, + { { 0,16,20,24,28,32,40,48,56,64,80,96,112,128,160 }, { 0,16,24,28,32,40,48,56,64,80,96,112,128,160,192 }, { 0,16,32,48,64,80,96,112,128,144,160,176,192,208,224 } }, + }; + return 2*halfrate[!!HDR_TEST_MPEG1(h)][HDR_GET_LAYER(h) - 1][HDR_GET_BITRATE(h)]; +} + +static unsigned hdr_sample_rate_hz(const uint8_t *h) +{ + static const unsigned g_hz[3] = { 44100, 48000, 32000 }; + return g_hz[HDR_GET_SAMPLE_RATE(h)] >> (int)!HDR_TEST_MPEG1(h) >> (int)!HDR_TEST_NOT_MPEG25(h); +} + +static unsigned hdr_frame_samples(const uint8_t *h) +{ + return HDR_IS_LAYER_1(h) ? 384 : (1152 >> (int)HDR_IS_FRAME_576(h)); +} + +static int hdr_frame_bytes(const uint8_t *h, int free_format_size) +{ + int frame_bytes = hdr_frame_samples(h)*hdr_bitrate_kbps(h)*125/hdr_sample_rate_hz(h); + if (HDR_IS_LAYER_1(h)) + { + frame_bytes &= ~3; /* slot align */ + } + return frame_bytes ? frame_bytes : free_format_size; +} + +static int hdr_padding(const uint8_t *h) +{ + return HDR_TEST_PADDING(h) ? (HDR_IS_LAYER_1(h) ? 4 : 1) : 0; +} + +#ifndef MINIMP3_ONLY_MP3 +static const L12_subband_alloc_t *L12_subband_alloc_table(const uint8_t *hdr, L12_scale_info *sci) +{ + const L12_subband_alloc_t *alloc; + int mode = HDR_GET_STEREO_MODE(hdr); + int nbands, stereo_bands = (mode == MODE_MONO) ? 0 : (mode == MODE_JOINT_STEREO) ? (HDR_GET_STEREO_MODE_EXT(hdr) << 2) + 4 : 32; + + if (HDR_IS_LAYER_1(hdr)) + { + static const L12_subband_alloc_t g_alloc_L1[] = { { 76, 4, 32 } }; + alloc = g_alloc_L1; + nbands = 32; + } else if (!HDR_TEST_MPEG1(hdr)) + { + static const L12_subband_alloc_t g_alloc_L2M2[] = { { 60, 4, 4 }, { 44, 3, 7 }, { 44, 2, 19 } }; + alloc = g_alloc_L2M2; + nbands = 30; + } else + { + static const L12_subband_alloc_t g_alloc_L2M1[] = { { 0, 4, 3 }, { 16, 4, 8 }, { 32, 3, 12 }, { 40, 2, 7 } }; + int sample_rate_idx = HDR_GET_SAMPLE_RATE(hdr); + unsigned kbps = hdr_bitrate_kbps(hdr) >> (int)(mode != MODE_MONO); + if (!kbps) /* free-format */ + { + kbps = 192; + } + + alloc = g_alloc_L2M1; + nbands = 27; + if (kbps < 56) + { + static const L12_subband_alloc_t g_alloc_L2M1_lowrate[] = { { 44, 4, 2 }, { 44, 3, 10 } }; + alloc = g_alloc_L2M1_lowrate; + nbands = sample_rate_idx == 2 ? 12 : 8; + } else if (kbps >= 96 && sample_rate_idx != 1) + { + nbands = 30; + } + } + + sci->total_bands = (uint8_t)nbands; + sci->stereo_bands = (uint8_t)MINIMP3_MIN(stereo_bands, nbands); + + return alloc; +} + +static void L12_read_scalefactors(bs_t *bs, uint8_t *pba, uint8_t *scfcod, int bands, float *scf) +{ + static const float g_deq_L12[18*3] = { +#define DQ(x) 9.53674316e-07f/x, 7.56931807e-07f/x, 6.00777173e-07f/x + DQ(3),DQ(7),DQ(15),DQ(31),DQ(63),DQ(127),DQ(255),DQ(511),DQ(1023),DQ(2047),DQ(4095),DQ(8191),DQ(16383),DQ(32767),DQ(65535),DQ(3),DQ(5),DQ(9) + }; + int i, m; + for (i = 0; i < bands; i++) + { + float s = 0; + int ba = *pba++; + int mask = ba ? 4 + ((19 >> scfcod[i]) & 3) : 0; + for (m = 4; m; m >>= 1) + { + if (mask & m) + { + int b = get_bits(bs, 6); + s = g_deq_L12[ba*3 - 6 + b % 3]*(1 << 21 >> b/3); + } + *scf++ = s; + } + } +} + +static void L12_read_scale_info(const uint8_t *hdr, bs_t *bs, L12_scale_info *sci) +{ + static const uint8_t g_bitalloc_code_tab[] = { + 0,17, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16, + 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,16, + 0,17,18, 3,19,4,5,16, + 0,17,18,16, + 0,17,18,19, 4,5,6, 7,8, 9,10,11,12,13,14,15, + 0,17,18, 3,19,4,5, 6,7, 8, 9,10,11,12,13,14, + 0, 2, 3, 4, 5,6,7, 8,9,10,11,12,13,14,15,16 + }; + const L12_subband_alloc_t *subband_alloc = L12_subband_alloc_table(hdr, sci); + + int i, k = 0, ba_bits = 0; + const uint8_t *ba_code_tab = g_bitalloc_code_tab; + + for (i = 0; i < sci->total_bands; i++) + { + uint8_t ba; + if (i == k) + { + k += subband_alloc->band_count; + ba_bits = subband_alloc->code_tab_width; + ba_code_tab = g_bitalloc_code_tab + subband_alloc->tab_offset; + subband_alloc++; + } + ba = ba_code_tab[get_bits(bs, ba_bits)]; + sci->bitalloc[2*i] = ba; + if (i < sci->stereo_bands) + { + ba = ba_code_tab[get_bits(bs, ba_bits)]; + } + sci->bitalloc[2*i + 1] = sci->stereo_bands ? ba : 0; + } + + for (i = 0; i < 2*sci->total_bands; i++) + { + sci->scfcod[i] = sci->bitalloc[i] ? HDR_IS_LAYER_1(hdr) ? 2 : get_bits(bs, 2) : 6; + } + + L12_read_scalefactors(bs, sci->bitalloc, sci->scfcod, sci->total_bands*2, sci->scf); + + for (i = sci->stereo_bands; i < sci->total_bands; i++) + { + sci->bitalloc[2*i + 1] = 0; + } +} + +static int L12_dequantize_granule(float *grbuf, bs_t *bs, L12_scale_info *sci, int group_size) +{ + int i, j, k, choff = 576; + for (j = 0; j < 4; j++) + { + float *dst = grbuf + group_size*j; + for (i = 0; i < 2*sci->total_bands; i++) + { + int ba = sci->bitalloc[i]; + if (ba != 0) + { + if (ba < 17) + { + int half = (1 << (ba - 1)) - 1; + for (k = 0; k < group_size; k++) + { + dst[k] = (float)((int)get_bits(bs, ba) - half); + } + } else + { + unsigned mod = (2 << (ba - 17)) + 1; /* 3, 5, 9 */ + unsigned code = get_bits(bs, mod + 2 - (mod >> 3)); /* 5, 7, 10 */ + for (k = 0; k < group_size; k++, code /= mod) + { + dst[k] = (float)((int)(code % mod - mod/2)); + } + } + } + dst += choff; + choff = 18 - choff; + } + } + return group_size*4; +} + +static void L12_apply_scf_384(L12_scale_info *sci, const float *scf, float *dst) +{ + int i, k; + memcpy(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float)); + for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6) + { + for (k = 0; k < 12; k++) + { + dst[k + 0] *= scf[0]; + dst[k + 576] *= scf[3]; + } + } +} +#endif /* MINIMP3_ONLY_MP3 */ + +static int L3_read_side_info(bs_t *bs, L3_gr_info_t *gr, const uint8_t *hdr) +{ + static const uint8_t g_scf_long[8][23] = { + { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 }, + { 12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2,0 }, + { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 }, + { 6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36,0 }, + { 6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54,0 }, + { 4,4,4,4,4,4,6,6,8,8,10,12,16,20,24,28,34,42,50,54,76,158,0 }, + { 4,4,4,4,4,4,6,6,6,8,10,12,16,18,22,28,34,40,46,54,54,192,0 }, + { 4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102,26,0 } + }; + static const uint8_t g_scf_short[8][40] = { + { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 }, + { 8,8,8,8,8,8,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 }, + { 4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 }, + { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 }, + { 4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 }, + { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 }, + { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 }, + { 4,4,4,4,4,4,4,4,4,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 } + }; + static const uint8_t g_scf_mixed[8][40] = { + { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 }, + { 12,12,12,4,4,4,8,8,8,12,12,12,16,16,16,20,20,20,24,24,24,28,28,28,36,36,36,2,2,2,2,2,2,2,2,2,26,26,26,0 }, + { 6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,14,14,14,18,18,18,26,26,26,32,32,32,42,42,42,18,18,18,0 }, + { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,32,32,32,44,44,44,12,12,12,0 }, + { 6,6,6,6,6,6,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,24,24,24,30,30,30,40,40,40,18,18,18,0 }, + { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,10,10,10,12,12,12,14,14,14,18,18,18,22,22,22,30,30,30,56,56,56,0 }, + { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,6,6,6,10,10,10,12,12,12,14,14,14,16,16,16,20,20,20,26,26,26,66,66,66,0 }, + { 4,4,4,4,4,4,6,6,4,4,4,6,6,6,8,8,8,12,12,12,16,16,16,20,20,20,26,26,26,34,34,34,42,42,42,12,12,12,0 } + }; + + unsigned tables, scfsi = 0; + int main_data_begin, part_23_sum = 0; + int sr_idx = HDR_GET_MY_SAMPLE_RATE(hdr); sr_idx -= (sr_idx != 0); + int gr_count = HDR_IS_MONO(hdr) ? 1 : 2; + + if (HDR_TEST_MPEG1(hdr)) + { + gr_count *= 2; + main_data_begin = get_bits(bs, 9); + scfsi = get_bits(bs, 7 + gr_count); + } else + { + main_data_begin = get_bits(bs, 8 + gr_count) >> gr_count; + } + + do + { + if (HDR_IS_MONO(hdr)) + { + scfsi <<= 4; + } + gr->part_23_length = (uint16_t)get_bits(bs, 12); + part_23_sum += gr->part_23_length; + gr->big_values = (uint16_t)get_bits(bs, 9); + if (gr->big_values > 288) + { + return -1; + } + gr->global_gain = (uint8_t)get_bits(bs, 8); + gr->scalefac_compress = (uint16_t)get_bits(bs, HDR_TEST_MPEG1(hdr) ? 4 : 9); + gr->sfbtab = g_scf_long[sr_idx]; + gr->n_long_sfb = 22; + gr->n_short_sfb = 0; + if (get_bits(bs, 1)) + { + gr->block_type = (uint8_t)get_bits(bs, 2); + if (!gr->block_type) + { + return -1; + } + gr->mixed_block_flag = (uint8_t)get_bits(bs, 1); + gr->region_count[0] = 7; + gr->region_count[1] = 255; + if (gr->block_type == SHORT_BLOCK_TYPE) + { + scfsi &= 0x0F0F; + if (!gr->mixed_block_flag) + { + gr->region_count[0] = 8; + gr->sfbtab = g_scf_short[sr_idx]; + gr->n_long_sfb = 0; + gr->n_short_sfb = 39; + } else + { + gr->sfbtab = g_scf_mixed[sr_idx]; + gr->n_long_sfb = HDR_TEST_MPEG1(hdr) ? 8 : 6; + gr->n_short_sfb = 30; + } + } + tables = get_bits(bs, 10); + tables <<= 5; + gr->subblock_gain[0] = (uint8_t)get_bits(bs, 3); + gr->subblock_gain[1] = (uint8_t)get_bits(bs, 3); + gr->subblock_gain[2] = (uint8_t)get_bits(bs, 3); + } else + { + gr->block_type = 0; + gr->mixed_block_flag = 0; + tables = get_bits(bs, 15); + gr->region_count[0] = (uint8_t)get_bits(bs, 4); + gr->region_count[1] = (uint8_t)get_bits(bs, 3); + gr->region_count[2] = 255; + } + gr->table_select[0] = (uint8_t)(tables >> 10); + gr->table_select[1] = (uint8_t)((tables >> 5) & 31); + gr->table_select[2] = (uint8_t)((tables) & 31); + gr->preflag = HDR_TEST_MPEG1(hdr) ? get_bits(bs, 1) : (gr->scalefac_compress >= 500); + gr->scalefac_scale = (uint8_t)get_bits(bs, 1); + gr->count1_table = (uint8_t)get_bits(bs, 1); + gr->scfsi = (uint8_t)((scfsi >> 12) & 15); + scfsi <<= 4; + gr++; + } while(--gr_count); + + if (part_23_sum + bs->pos > bs->limit + main_data_begin*8) + { + return -1; + } + + return main_data_begin; +} + +static void L3_read_scalefactors(uint8_t *scf, uint8_t *ist_pos, const uint8_t *scf_size, const uint8_t *scf_count, bs_t *bitbuf, int scfsi) +{ + int i, k; + for (i = 0; i < 4 && scf_count[i]; i++, scfsi *= 2) + { + int cnt = scf_count[i]; + if (scfsi & 8) + { + memcpy(scf, ist_pos, cnt); + } else + { + int bits = scf_size[i]; + if (!bits) + { + memset(scf, 0, cnt); + memset(ist_pos, 0, cnt); + } else + { + int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1; + for (k = 0; k < cnt; k++) + { + int s = get_bits(bitbuf, bits); + ist_pos[k] = (s == max_scf ? -1 : s); + scf[k] = s; + } + } + } + ist_pos += cnt; + scf += cnt; + } + scf[0] = scf[1] = scf[2] = 0; +} + +static float L3_ldexp_q2(float y, int exp_q2) +{ + static const float g_expfrac[4] = { 9.31322575e-10f,7.83145814e-10f,6.58544508e-10f,5.53767716e-10f }; + int e; + do + { + e = MINIMP3_MIN(30*4, exp_q2); + y *= g_expfrac[e & 3]*(1 << 30 >> (e >> 2)); + } while ((exp_q2 -= e) > 0); + return y; +} + +static void L3_decode_scalefactors(const uint8_t *hdr, uint8_t *ist_pos, bs_t *bs, const L3_gr_info_t *gr, float *scf, int ch) +{ + static const uint8_t g_scf_partitions[3][28] = { + { 6,5,5, 5,6,5,5,5,6,5, 7,3,11,10,0,0, 7, 7, 7,0, 6, 6,6,3, 8, 8,5,0 }, + { 8,9,6,12,6,9,9,9,6,9,12,6,15,18,0,0, 6,15,12,0, 6,12,9,6, 6,18,9,0 }, + { 9,9,6,12,9,9,9,9,9,9,12,6,18,18,0,0,12,12,12,0,12, 9,9,6,15,12,9,0 } + }; + const uint8_t *scf_partition = g_scf_partitions[!!gr->n_short_sfb + !gr->n_long_sfb]; + uint8_t scf_size[4], iscf[40]; + int i, scf_shift = gr->scalefac_scale + 1, gain_exp, scfsi = gr->scfsi; + float gain; + + if (HDR_TEST_MPEG1(hdr)) + { + static const uint8_t g_scfc_decode[16] = { 0,1,2,3, 12,5,6,7, 9,10,11,13, 14,15,18,19 }; + int part = g_scfc_decode[gr->scalefac_compress]; + scf_size[1] = scf_size[0] = (uint8_t)(part >> 2); + scf_size[3] = scf_size[2] = (uint8_t)(part & 3); + } else + { + static const uint8_t g_mod[6*4] = { 5,5,4,4,5,5,4,1,4,3,1,1,5,6,6,1,4,4,4,1,4,3,1,1 }; + int k, modprod, sfc, ist = HDR_TEST_I_STEREO(hdr) && ch; + sfc = gr->scalefac_compress >> ist; + for (k = ist*3*4; sfc >= 0; sfc -= modprod, k += 4) + { + for (modprod = 1, i = 3; i >= 0; i--) + { + scf_size[i] = (uint8_t)(sfc / modprod % g_mod[k + i]); + modprod *= g_mod[k + i]; + } + } + scf_partition += k; + scfsi = -16; + } + L3_read_scalefactors(iscf, ist_pos, scf_size, scf_partition, bs, scfsi); + + if (gr->n_short_sfb) + { + int sh = 3 - scf_shift; + for (i = 0; i < gr->n_short_sfb; i += 3) + { + iscf[gr->n_long_sfb + i + 0] += gr->subblock_gain[0] << sh; + iscf[gr->n_long_sfb + i + 1] += gr->subblock_gain[1] << sh; + iscf[gr->n_long_sfb + i + 2] += gr->subblock_gain[2] << sh; + } + } else if (gr->preflag) + { + static const uint8_t g_preamp[10] = { 1,1,1,1,2,2,3,3,3,2 }; + for (i = 0; i < 10; i++) + { + iscf[11 + i] += g_preamp[i]; + } + } + + gain_exp = gr->global_gain + BITS_DEQUANTIZER_OUT*4 - 210 - (HDR_IS_MS_STEREO(hdr) ? 2 : 0); + gain = L3_ldexp_q2(1 << (MAX_SCFI/4), MAX_SCFI - gain_exp); + for (i = 0; i < (int)(gr->n_long_sfb + gr->n_short_sfb); i++) + { + scf[i] = L3_ldexp_q2(gain, iscf[i] << scf_shift); + } +} + +static const float g_pow43[129 + 16] = { + 0,-1,-2.519842f,-4.326749f,-6.349604f,-8.549880f,-10.902724f,-13.390518f,-16.000000f,-18.720754f,-21.544347f,-24.463781f,-27.473142f,-30.567351f,-33.741992f,-36.993181f, + 0,1,2.519842f,4.326749f,6.349604f,8.549880f,10.902724f,13.390518f,16.000000f,18.720754f,21.544347f,24.463781f,27.473142f,30.567351f,33.741992f,36.993181f,40.317474f,43.711787f,47.173345f,50.699631f,54.288352f,57.937408f,61.644865f,65.408941f,69.227979f,73.100443f,77.024898f,81.000000f,85.024491f,89.097188f,93.216975f,97.382800f,101.593667f,105.848633f,110.146801f,114.487321f,118.869381f,123.292209f,127.755065f,132.257246f,136.798076f,141.376907f,145.993119f,150.646117f,155.335327f,160.060199f,164.820202f,169.614826f,174.443577f,179.305980f,184.201575f,189.129918f,194.090580f,199.083145f,204.107210f,209.162385f,214.248292f,219.364564f,224.510845f,229.686789f,234.892058f,240.126328f,245.389280f,250.680604f,256.000000f,261.347174f,266.721841f,272.123723f,277.552547f,283.008049f,288.489971f,293.998060f,299.532071f,305.091761f,310.676898f,316.287249f,321.922592f,327.582707f,333.267377f,338.976394f,344.709550f,350.466646f,356.247482f,362.051866f,367.879608f,373.730522f,379.604427f,385.501143f,391.420496f,397.362314f,403.326427f,409.312672f,415.320884f,421.350905f,427.402579f,433.475750f,439.570269f,445.685987f,451.822757f,457.980436f,464.158883f,470.357960f,476.577530f,482.817459f,489.077615f,495.357868f,501.658090f,507.978156f,514.317941f,520.677324f,527.056184f,533.454404f,539.871867f,546.308458f,552.764065f,559.238575f,565.731879f,572.243870f,578.774440f,585.323483f,591.890898f,598.476581f,605.080431f,611.702349f,618.342238f,625.000000f,631.675540f,638.368763f,645.079578f +}; + +static float L3_pow_43(int x) +{ + float frac; + int sign, mult = 256; + + if (x < 129) + { + return g_pow43[16 + x]; + } + + if (x < 1024) + { + mult = 16; + x <<= 3; + } + + sign = 2*x & 64; + frac = (float)((x & 63) - sign) / ((x & ~63) + sign); + return g_pow43[16 + ((x + sign) >> 6)]*(1.f + frac*((4.f/3) + frac*(2.f/9)))*mult; +} + +static void L3_huffman(float *dst, bs_t *bs, const L3_gr_info_t *gr_info, const float *scf, int layer3gr_limit) +{ + static const int16_t tabs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 785,785,785,785,784,784,784,784,513,513,513,513,513,513,513,513,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256, + -255,1313,1298,1282,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,290,288, + -255,1313,1298,1282,769,769,769,769,529,529,529,529,529,529,529,529,528,528,528,528,528,528,528,528,512,512,512,512,512,512,512,512,290,288, + -253,-318,-351,-367,785,785,785,785,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,819,818,547,547,275,275,275,275,561,560,515,546,289,274,288,258, + -254,-287,1329,1299,1314,1312,1057,1057,1042,1042,1026,1026,784,784,784,784,529,529,529,529,529,529,529,529,769,769,769,769,768,768,768,768,563,560,306,306,291,259, + -252,-413,-477,-542,1298,-575,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-383,-399,1107,1092,1106,1061,849,849,789,789,1104,1091,773,773,1076,1075,341,340,325,309,834,804,577,577,532,532,516,516,832,818,803,816,561,561,531,531,515,546,289,289,288,258, + -252,-429,-493,-559,1057,1057,1042,1042,529,529,529,529,529,529,529,529,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,-382,1077,-415,1106,1061,1104,849,849,789,789,1091,1076,1029,1075,834,834,597,581,340,340,339,324,804,833,532,532,832,772,818,803,817,787,816,771,290,290,290,290,288,258, + -253,-349,-414,-447,-463,1329,1299,-479,1314,1312,1057,1057,1042,1042,1026,1026,785,785,785,785,784,784,784,784,769,769,769,769,768,768,768,768,-319,851,821,-335,836,850,805,849,341,340,325,336,533,533,579,579,564,564,773,832,578,548,563,516,321,276,306,291,304,259, + -251,-572,-733,-830,-863,-879,1041,1041,784,784,784,784,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,1396,1351,1381,1366,1395,1335,1380,-559,1334,1138,1138,1063,1063,1350,1392,1031,1031,1062,1062,1364,1363,1120,1120,1333,1348,881,881,881,881,375,374,359,373,343,358,341,325,791,791,1123,1122,-703,1105,1045,-719,865,865,790,790,774,774,1104,1029,338,293,323,308,-799,-815,833,788,772,818,803,816,322,292,307,320,561,531,515,546,289,274,288,258, + -251,-525,-605,-685,-765,-831,-846,1298,1057,1057,1312,1282,785,785,785,785,784,784,784,784,769,769,769,769,512,512,512,512,512,512,512,512,1399,1398,1383,1367,1382,1396,1351,-511,1381,1366,1139,1139,1079,1079,1124,1124,1364,1349,1363,1333,882,882,882,882,807,807,807,807,1094,1094,1136,1136,373,341,535,535,881,775,867,822,774,-591,324,338,-671,849,550,550,866,864,609,609,293,336,534,534,789,835,773,-751,834,804,308,307,833,788,832,772,562,562,547,547,305,275,560,515,290,290, + -252,-397,-477,-557,-622,-653,-719,-735,-750,1329,1299,1314,1057,1057,1042,1042,1312,1282,1024,1024,785,785,785,785,784,784,784,784,769,769,769,769,-383,1127,1141,1111,1126,1140,1095,1110,869,869,883,883,1079,1109,882,882,375,374,807,868,838,881,791,-463,867,822,368,263,852,837,836,-543,610,610,550,550,352,336,534,534,865,774,851,821,850,805,593,533,579,564,773,832,578,578,548,548,577,577,307,276,306,291,516,560,259,259, + -250,-2107,-2507,-2764,-2909,-2974,-3007,-3023,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-767,-1052,-1213,-1277,-1358,-1405,-1469,-1535,-1550,-1582,-1614,-1647,-1662,-1694,-1726,-1759,-1774,-1807,-1822,-1854,-1886,1565,-1919,-1935,-1951,-1967,1731,1730,1580,1717,-1983,1729,1564,-1999,1548,-2015,-2031,1715,1595,-2047,1714,-2063,1610,-2079,1609,-2095,1323,1323,1457,1457,1307,1307,1712,1547,1641,1700,1699,1594,1685,1625,1442,1442,1322,1322,-780,-973,-910,1279,1278,1277,1262,1276,1261,1275,1215,1260,1229,-959,974,974,989,989,-943,735,478,478,495,463,506,414,-1039,1003,958,1017,927,942,987,957,431,476,1272,1167,1228,-1183,1256,-1199,895,895,941,941,1242,1227,1212,1135,1014,1014,490,489,503,487,910,1013,985,925,863,894,970,955,1012,847,-1343,831,755,755,984,909,428,366,754,559,-1391,752,486,457,924,997,698,698,983,893,740,740,908,877,739,739,667,667,953,938,497,287,271,271,683,606,590,712,726,574,302,302,738,736,481,286,526,725,605,711,636,724,696,651,589,681,666,710,364,467,573,695,466,466,301,465,379,379,709,604,665,679,316,316,634,633,436,436,464,269,424,394,452,332,438,363,347,408,393,448,331,422,362,407,392,421,346,406,391,376,375,359,1441,1306,-2367,1290,-2383,1337,-2399,-2415,1426,1321,-2431,1411,1336,-2447,-2463,-2479,1169,1169,1049,1049,1424,1289,1412,1352,1319,-2495,1154,1154,1064,1064,1153,1153,416,390,360,404,403,389,344,374,373,343,358,372,327,357,342,311,356,326,1395,1394,1137,1137,1047,1047,1365,1392,1287,1379,1334,1364,1349,1378,1318,1363,792,792,792,792,1152,1152,1032,1032,1121,1121,1046,1046,1120,1120,1030,1030,-2895,1106,1061,1104,849,849,789,789,1091,1076,1029,1090,1060,1075,833,833,309,324,532,532,832,772,818,803,561,561,531,560,515,546,289,274,288,258, + -250,-1179,-1579,-1836,-1996,-2124,-2253,-2333,-2413,-2477,-2542,-2574,-2607,-2622,-2655,1314,1313,1298,1312,1282,785,785,785,785,1040,1040,1025,1025,768,768,768,768,-766,-798,-830,-862,-895,-911,-927,-943,-959,-975,-991,-1007,-1023,-1039,-1055,-1070,1724,1647,-1103,-1119,1631,1767,1662,1738,1708,1723,-1135,1780,1615,1779,1599,1677,1646,1778,1583,-1151,1777,1567,1737,1692,1765,1722,1707,1630,1751,1661,1764,1614,1736,1676,1763,1750,1645,1598,1721,1691,1762,1706,1582,1761,1566,-1167,1749,1629,767,766,751,765,494,494,735,764,719,749,734,763,447,447,748,718,477,506,431,491,446,476,461,505,415,430,475,445,504,399,460,489,414,503,383,474,429,459,502,502,746,752,488,398,501,473,413,472,486,271,480,270,-1439,-1455,1357,-1471,-1487,-1503,1341,1325,-1519,1489,1463,1403,1309,-1535,1372,1448,1418,1476,1356,1462,1387,-1551,1475,1340,1447,1402,1386,-1567,1068,1068,1474,1461,455,380,468,440,395,425,410,454,364,467,466,464,453,269,409,448,268,432,1371,1473,1432,1417,1308,1460,1355,1446,1459,1431,1083,1083,1401,1416,1458,1445,1067,1067,1370,1457,1051,1051,1291,1430,1385,1444,1354,1415,1400,1443,1082,1082,1173,1113,1186,1066,1185,1050,-1967,1158,1128,1172,1097,1171,1081,-1983,1157,1112,416,266,375,400,1170,1142,1127,1065,793,793,1169,1033,1156,1096,1141,1111,1155,1080,1126,1140,898,898,808,808,897,897,792,792,1095,1152,1032,1125,1110,1139,1079,1124,882,807,838,881,853,791,-2319,867,368,263,822,852,837,866,806,865,-2399,851,352,262,534,534,821,836,594,594,549,549,593,593,533,533,848,773,579,579,564,578,548,563,276,276,577,576,306,291,516,560,305,305,275,259, + -251,-892,-2058,-2620,-2828,-2957,-3023,-3039,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,-559,1530,-575,-591,1528,1527,1407,1526,1391,1023,1023,1023,1023,1525,1375,1268,1268,1103,1103,1087,1087,1039,1039,1523,-604,815,815,815,815,510,495,509,479,508,463,507,447,431,505,415,399,-734,-782,1262,-815,1259,1244,-831,1258,1228,-847,-863,1196,-879,1253,987,987,748,-767,493,493,462,477,414,414,686,669,478,446,461,445,474,429,487,458,412,471,1266,1264,1009,1009,799,799,-1019,-1276,-1452,-1581,-1677,-1757,-1821,-1886,-1933,-1997,1257,1257,1483,1468,1512,1422,1497,1406,1467,1496,1421,1510,1134,1134,1225,1225,1466,1451,1374,1405,1252,1252,1358,1480,1164,1164,1251,1251,1238,1238,1389,1465,-1407,1054,1101,-1423,1207,-1439,830,830,1248,1038,1237,1117,1223,1148,1236,1208,411,426,395,410,379,269,1193,1222,1132,1235,1221,1116,976,976,1192,1162,1177,1220,1131,1191,963,963,-1647,961,780,-1663,558,558,994,993,437,408,393,407,829,978,813,797,947,-1743,721,721,377,392,844,950,828,890,706,706,812,859,796,960,948,843,934,874,571,571,-1919,690,555,689,421,346,539,539,944,779,918,873,932,842,903,888,570,570,931,917,674,674,-2575,1562,-2591,1609,-2607,1654,1322,1322,1441,1441,1696,1546,1683,1593,1669,1624,1426,1426,1321,1321,1639,1680,1425,1425,1305,1305,1545,1668,1608,1623,1667,1592,1638,1666,1320,1320,1652,1607,1409,1409,1304,1304,1288,1288,1664,1637,1395,1395,1335,1335,1622,1636,1394,1394,1319,1319,1606,1621,1392,1392,1137,1137,1137,1137,345,390,360,375,404,373,1047,-2751,-2767,-2783,1062,1121,1046,-2799,1077,-2815,1106,1061,789,789,1105,1104,263,355,310,340,325,354,352,262,339,324,1091,1076,1029,1090,1060,1075,833,833,788,788,1088,1028,818,818,803,803,561,561,531,531,816,771,546,546,289,274,288,258, + -253,-317,-381,-446,-478,-509,1279,1279,-811,-1179,-1451,-1756,-1900,-2028,-2189,-2253,-2333,-2414,-2445,-2511,-2526,1313,1298,-2559,1041,1041,1040,1040,1025,1025,1024,1024,1022,1007,1021,991,1020,975,1019,959,687,687,1018,1017,671,671,655,655,1016,1015,639,639,758,758,623,623,757,607,756,591,755,575,754,559,543,543,1009,783,-575,-621,-685,-749,496,-590,750,749,734,748,974,989,1003,958,988,973,1002,942,987,957,972,1001,926,986,941,971,956,1000,910,985,925,999,894,970,-1071,-1087,-1102,1390,-1135,1436,1509,1451,1374,-1151,1405,1358,1480,1420,-1167,1507,1494,1389,1342,1465,1435,1450,1326,1505,1310,1493,1373,1479,1404,1492,1464,1419,428,443,472,397,736,526,464,464,486,457,442,471,484,482,1357,1449,1434,1478,1388,1491,1341,1490,1325,1489,1463,1403,1309,1477,1372,1448,1418,1433,1476,1356,1462,1387,-1439,1475,1340,1447,1402,1474,1324,1461,1371,1473,269,448,1432,1417,1308,1460,-1711,1459,-1727,1441,1099,1099,1446,1386,1431,1401,-1743,1289,1083,1083,1160,1160,1458,1445,1067,1067,1370,1457,1307,1430,1129,1129,1098,1098,268,432,267,416,266,400,-1887,1144,1187,1082,1173,1113,1186,1066,1050,1158,1128,1143,1172,1097,1171,1081,420,391,1157,1112,1170,1142,1127,1065,1169,1049,1156,1096,1141,1111,1155,1080,1126,1154,1064,1153,1140,1095,1048,-2159,1125,1110,1137,-2175,823,823,1139,1138,807,807,384,264,368,263,868,838,853,791,867,822,852,837,866,806,865,790,-2319,851,821,836,352,262,850,805,849,-2399,533,533,835,820,336,261,578,548,563,577,532,532,832,772,562,562,547,547,305,275,560,515,290,290,288,258 }; + static const uint8_t tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205 }; + static const uint8_t tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 }; + static const int16_t tabindex[2*16] = { 0,32,64,98,0,132,180,218,292,364,426,538,648,746,0,1126,1460,1460,1460,1460,1460,1460,1460,1460,1842,1842,1842,1842,1842,1842,1842,1842 }; + static const uint8_t g_linbits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 }; + +#define PEEK_BITS(n) (bs_cache >> (32 - n)) +#define FLUSH_BITS(n) { bs_cache <<= (n); bs_sh += (n); } +#define CHECK_BITS while (bs_sh >= 0) { bs_cache |= (uint32_t)*bs_next_ptr++ << bs_sh; bs_sh -= 8; } +#define BSPOS ((bs_next_ptr - bs->buf)*8 - 24 + bs_sh) + + float one = 0.0f; + int ireg = 0, big_val_cnt = gr_info->big_values; + const uint8_t *sfb = gr_info->sfbtab; + const uint8_t *bs_next_ptr = bs->buf + bs->pos/8; + uint32_t bs_cache = (((bs_next_ptr[0]*256u + bs_next_ptr[1])*256u + bs_next_ptr[2])*256u + bs_next_ptr[3]) << (bs->pos & 7); + int pairs_to_decode, np, bs_sh = (bs->pos & 7) - 8; + bs_next_ptr += 4; + + while (big_val_cnt > 0) + { + int tab_num = gr_info->table_select[ireg]; + int sfb_cnt = gr_info->region_count[ireg++]; + const int16_t *codebook = tabs + tabindex[tab_num]; + int linbits = g_linbits[tab_num]; + do + { + np = *sfb++ / 2; + pairs_to_decode = MINIMP3_MIN(big_val_cnt, np); + one = *scf++; + do + { + int j, w = 5; + int leaf = codebook[PEEK_BITS(w)]; + while (leaf < 0) + { + FLUSH_BITS(w); + w = leaf & 7; + leaf = codebook[PEEK_BITS(w) - (leaf >> 3)]; + } + FLUSH_BITS(leaf >> 8); + + for (j = 0; j < 2; j++, dst++, leaf >>= 4) + { + int lsb = leaf & 0x0F; + if (lsb == 15 && linbits) + { + lsb += PEEK_BITS(linbits); + FLUSH_BITS(linbits); + CHECK_BITS; + *dst = one*L3_pow_43(lsb)*((int32_t)bs_cache < 0 ? -1: 1); + } else + { + *dst = g_pow43[16 + lsb - 16*(bs_cache >> 31)]*one; + } + FLUSH_BITS(lsb ? 1 : 0); + } + CHECK_BITS; + } while (--pairs_to_decode); + } while ((big_val_cnt -= np) > 0 && --sfb_cnt >= 0); + } + + for (np = 1 - big_val_cnt;; dst += 4) + { + const uint8_t *codebook_count1 = (gr_info->count1_table) ? tab33 : tab32; + int leaf = codebook_count1[PEEK_BITS(4)]; + if (!(leaf & 8)) + { + leaf = codebook_count1[(leaf >> 3) + (bs_cache << 4 >> (32 - (leaf & 3)))]; + } + FLUSH_BITS(leaf & 7); + if (BSPOS > layer3gr_limit) + { + break; + } +#define RELOAD_SCALEFACTOR if (!--np) { np = *sfb++/2; if (!np) break; one = *scf++; } +#define DEQ_COUNT1(s) if (leaf & (128 >> s)) { dst[s] = ((int32_t)bs_cache < 0) ? -one : one; FLUSH_BITS(1) } + RELOAD_SCALEFACTOR; + DEQ_COUNT1(0); + DEQ_COUNT1(1); + RELOAD_SCALEFACTOR; + DEQ_COUNT1(2); + DEQ_COUNT1(3); + CHECK_BITS; + } + + bs->pos = layer3gr_limit; +} + +static void L3_midside_stereo(float *left, int n) +{ + int i = 0; + float *right = left + 576; +#if HAVE_SIMD + if (have_simd()) for (; i < n - 3; i += 4) + { + f4 vl = VLD(left + i); + f4 vr = VLD(right + i); + VSTORE(left + i, VADD(vl, vr)); + VSTORE(right + i, VSUB(vl, vr)); + } +#endif /* HAVE_SIMD */ + for (; i < n; i++) + { + float a = left[i]; + float b = right[i]; + left[i] = a + b; + right[i] = a - b; + } +} + +static void L3_intensity_stereo_band(float *left, int n, float kl, float kr) +{ + int i; + for (i = 0; i < n; i++) + { + left[i + 576] = left[i]*kr; + left[i] = left[i]*kl; + } +} + +static void L3_stereo_top_band(const float *right, const uint8_t *sfb, int nbands, int max_band[3]) +{ + int i, k; + + max_band[0] = max_band[1] = max_band[2] = -1; + + for (i = 0; i < nbands; i++) + { + for (k = 0; k < sfb[i]; k += 2) + { + if (right[k] != 0 || right[k + 1] != 0) + { + max_band[i % 3] = i; + break; + } + } + right += sfb[i]; + } +} + +static void L3_stereo_process(float *left, const uint8_t *ist_pos, const uint8_t *sfb, const uint8_t *hdr, int max_band[3], int mpeg2_sh) +{ + static const float g_pan[7*2] = { 0,1,0.21132487f,0.78867513f,0.36602540f,0.63397460f,0.5f,0.5f,0.63397460f,0.36602540f,0.78867513f,0.21132487f,1,0 }; + unsigned i, max_pos = HDR_TEST_MPEG1(hdr) ? 7 : 64; + + for (i = 0; sfb[i]; i++) + { + unsigned ipos = ist_pos[i]; + if ((int)i > max_band[i % 3] && ipos < max_pos) + { + float kl, kr, s = HDR_TEST_MS_STEREO(hdr) ? 1.41421356f : 1; + if (HDR_TEST_MPEG1(hdr)) + { + kl = g_pan[2*ipos]; + kr = g_pan[2*ipos + 1]; + } else + { + kl = 1; + kr = L3_ldexp_q2(1, (ipos + 1) >> 1 << mpeg2_sh); + if (ipos & 1) + { + kl = kr; + kr = 1; + } + } + L3_intensity_stereo_band(left, sfb[i], kl*s, kr*s); + } else if (HDR_TEST_MS_STEREO(hdr)) + { + L3_midside_stereo(left, sfb[i]); + } + left += sfb[i]; + } +} + +static void L3_intensity_stereo(float *left, uint8_t *ist_pos, const L3_gr_info_t *gr, const uint8_t *hdr) +{ + int max_band[3], n_sfb = gr->n_long_sfb + gr->n_short_sfb; + int i, max_blocks = gr->n_short_sfb ? 3 : 1; + + L3_stereo_top_band(left + 576, gr->sfbtab, n_sfb, max_band); + if (gr->n_long_sfb) + { + max_band[0] = max_band[1] = max_band[2] = MINIMP3_MAX(MINIMP3_MAX(max_band[0], max_band[1]), max_band[2]); + } + for (i = 0; i < max_blocks; i++) + { + int default_pos = HDR_TEST_MPEG1(hdr) ? 3 : 0; + int itop = n_sfb - max_blocks + i; + int prev = itop - max_blocks; + ist_pos[itop] = max_band[i] >= prev ? default_pos : ist_pos[prev]; + } + L3_stereo_process(left, ist_pos, gr->sfbtab, hdr, max_band, gr[1].scalefac_compress & 1); +} + +static void L3_reorder(float *grbuf, float *scratch, const uint8_t *sfb) +{ + int i, len; + float *src = grbuf, *dst = scratch; + + for (;0 != (len = *sfb); sfb += 3, src += 2*len) + { + for (i = 0; i < len; i++, src++) + { + *dst++ = src[0*len]; + *dst++ = src[1*len]; + *dst++ = src[2*len]; + } + } + memcpy(grbuf, scratch, (dst - scratch)*sizeof(float)); +} + +static void L3_antialias(float *grbuf, int nbands) +{ + static const float g_aa[2][8] = { + {0.85749293f,0.88174200f,0.94962865f,0.98331459f,0.99551782f,0.99916056f,0.99989920f,0.99999316f}, + {0.51449576f,0.47173197f,0.31337745f,0.18191320f,0.09457419f,0.04096558f,0.01419856f,0.00369997f} + }; + + for (; nbands > 0; nbands--, grbuf += 18) + { + int i = 0; +#if HAVE_SIMD + if (have_simd()) for (; i < 8; i += 4) + { + f4 vu = VLD(grbuf + 18 + i); + f4 vd = VLD(grbuf + 14 - i); + f4 vc0 = VLD(g_aa[0] + i); + f4 vc1 = VLD(g_aa[1] + i); + vd = VREV(vd); + VSTORE(grbuf + 18 + i, VSUB(VMUL(vu, vc0), VMUL(vd, vc1))); + vd = VADD(VMUL(vu, vc1), VMUL(vd, vc0)); + VSTORE(grbuf + 14 - i, VREV(vd)); + } +#endif /* HAVE_SIMD */ +#ifndef MINIMP3_ONLY_SIMD + for(; i < 8; i++) + { + float u = grbuf[18 + i]; + float d = grbuf[17 - i]; + grbuf[18 + i] = u*g_aa[0][i] - d*g_aa[1][i]; + grbuf[17 - i] = u*g_aa[1][i] + d*g_aa[0][i]; + } +#endif /* MINIMP3_ONLY_SIMD */ + } +} + +static void L3_dct3_9(float *y) +{ + float s0, s1, s2, s3, s4, s5, s6, s7, s8, t0, t2, t4; + + s0 = y[0]; s2 = y[2]; s4 = y[4]; s6 = y[6]; s8 = y[8]; + t0 = s0 + s6*0.5f; + s0 -= s6; + t4 = (s4 + s2)*0.93969262f; + t2 = (s8 + s2)*0.76604444f; + s6 = (s4 - s8)*0.17364818f; + s4 += s8 - s2; + + s2 = s0 - s4*0.5f; + y[4] = s4 + s0; + s8 = t0 - t2 + s6; + s0 = t0 - t4 + t2; + s4 = t0 + t4 - s6; + + s1 = y[1]; s3 = y[3]; s5 = y[5]; s7 = y[7]; + + s3 *= 0.86602540f; + t0 = (s5 + s1)*0.98480775f; + t4 = (s5 - s7)*0.34202014f; + t2 = (s1 + s7)*0.64278761f; + s1 = (s1 - s5 - s7)*0.86602540f; + + s5 = t0 - s3 - t2; + s7 = t4 - s3 - t0; + s3 = t4 + s3 - t2; + + y[0] = s4 - s7; + y[1] = s2 + s1; + y[2] = s0 - s3; + y[3] = s8 + s5; + y[5] = s8 - s5; + y[6] = s0 + s3; + y[7] = s2 - s1; + y[8] = s4 + s7; +} + +static void L3_imdct36(float *grbuf, float *overlap, const float *window, int nbands) +{ + int i, j; + static const float g_twid9[18] = { + 0.73727734f,0.79335334f,0.84339145f,0.88701083f,0.92387953f,0.95371695f,0.97629601f,0.99144486f,0.99904822f,0.67559021f,0.60876143f,0.53729961f,0.46174861f,0.38268343f,0.30070580f,0.21643961f,0.13052619f,0.04361938f + }; + + for (j = 0; j < nbands; j++, grbuf += 18, overlap += 9) + { + float co[9], si[9]; + co[0] = -grbuf[0]; + si[0] = grbuf[17]; + for (i = 0; i < 4; i++) + { + si[8 - 2*i] = grbuf[4*i + 1] - grbuf[4*i + 2]; + co[1 + 2*i] = grbuf[4*i + 1] + grbuf[4*i + 2]; + si[7 - 2*i] = grbuf[4*i + 4] - grbuf[4*i + 3]; + co[2 + 2*i] = -(grbuf[4*i + 3] + grbuf[4*i + 4]); + } + L3_dct3_9(co); + L3_dct3_9(si); + + si[1] = -si[1]; + si[3] = -si[3]; + si[5] = -si[5]; + si[7] = -si[7]; + + i = 0; + +#if HAVE_SIMD + if (have_simd()) for (; i < 8; i += 4) + { + f4 vovl = VLD(overlap + i); + f4 vc = VLD(co + i); + f4 vs = VLD(si + i); + f4 vr0 = VLD(g_twid9 + i); + f4 vr1 = VLD(g_twid9 + 9 + i); + f4 vw0 = VLD(window + i); + f4 vw1 = VLD(window + 9 + i); + f4 vsum = VADD(VMUL(vc, vr1), VMUL(vs, vr0)); + VSTORE(overlap + i, VSUB(VMUL(vc, vr0), VMUL(vs, vr1))); + VSTORE(grbuf + i, VSUB(VMUL(vovl, vw0), VMUL(vsum, vw1))); + vsum = VADD(VMUL(vovl, vw1), VMUL(vsum, vw0)); + VSTORE(grbuf + 14 - i, VREV(vsum)); + } +#endif /* HAVE_SIMD */ + for (; i < 9; i++) + { + float ovl = overlap[i]; + float sum = co[i]*g_twid9[9 + i] + si[i]*g_twid9[0 + i]; + overlap[i] = co[i]*g_twid9[0 + i] - si[i]*g_twid9[9 + i]; + grbuf[i] = ovl*window[0 + i] - sum*window[9 + i]; + grbuf[17 - i] = ovl*window[9 + i] + sum*window[0 + i]; + } + } +} + +static void L3_idct3(float x0, float x1, float x2, float *dst) +{ + float m1 = x1*0.86602540f; + float a1 = x0 - x2*0.5f; + dst[1] = x0 + x2; + dst[0] = a1 + m1; + dst[2] = a1 - m1; +} + +static void L3_imdct12(float *x, float *dst, float *overlap) +{ + static const float g_twid3[6] = { 0.79335334f,0.92387953f,0.99144486f, 0.60876143f,0.38268343f,0.13052619f }; + float co[3], si[3]; + int i; + + L3_idct3(-x[0], x[6] + x[3], x[12] + x[9], co); + L3_idct3(x[15], x[12] - x[9], x[6] - x[3], si); + si[1] = -si[1]; + + for (i = 0; i < 3; i++) + { + float ovl = overlap[i]; + float sum = co[i]*g_twid3[3 + i] + si[i]*g_twid3[0 + i]; + overlap[i] = co[i]*g_twid3[0 + i] - si[i]*g_twid3[3 + i]; + dst[i] = ovl*g_twid3[2 - i] - sum*g_twid3[5 - i]; + dst[5 - i] = ovl*g_twid3[5 - i] + sum*g_twid3[2 - i]; + } +} + +static void L3_imdct_short(float *grbuf, float *overlap, int nbands) +{ + for (;nbands > 0; nbands--, overlap += 9, grbuf += 18) + { + float tmp[18]; + memcpy(tmp, grbuf, sizeof(tmp)); + memcpy(grbuf, overlap, 6*sizeof(float)); + L3_imdct12(tmp, grbuf + 6, overlap + 6); + L3_imdct12(tmp + 1, grbuf + 12, overlap + 6); + L3_imdct12(tmp + 2, overlap, overlap + 6); + } +} + +static void L3_change_sign(float *grbuf) +{ + int b, i; + for (b = 0, grbuf += 18; b < 32; b += 2, grbuf += 36) + for (i = 1; i < 18; i += 2) + grbuf[i] = -grbuf[i]; +} + +static void L3_imdct_gr(float *grbuf, float *overlap, unsigned block_type, unsigned n_long_bands) +{ + static const float g_mdct_window[2][18] = { + { 0.99904822f,0.99144486f,0.97629601f,0.95371695f,0.92387953f,0.88701083f,0.84339145f,0.79335334f,0.73727734f,0.04361938f,0.13052619f,0.21643961f,0.30070580f,0.38268343f,0.46174861f,0.53729961f,0.60876143f,0.67559021f }, + { 1,1,1,1,1,1,0.99144486f,0.92387953f,0.79335334f,0,0,0,0,0,0,0.13052619f,0.38268343f,0.60876143f } + }; + if (n_long_bands) + { + L3_imdct36(grbuf, overlap, g_mdct_window[0], n_long_bands); + grbuf += 18*n_long_bands; + overlap += 9*n_long_bands; + } + if (block_type == SHORT_BLOCK_TYPE) + L3_imdct_short(grbuf, overlap, 32 - n_long_bands); + else + L3_imdct36(grbuf, overlap, g_mdct_window[block_type == STOP_BLOCK_TYPE], 32 - n_long_bands); +} + +static void L3_save_reservoir(mp3dec_t *h, mp3dec_scratch_t *s) +{ + int pos = (s->bs.pos + 7)/8u; + int remains = s->bs.limit/8u - pos; + if (remains > MAX_BITRESERVOIR_BYTES) + { + pos += remains - MAX_BITRESERVOIR_BYTES; + remains = MAX_BITRESERVOIR_BYTES; + } + if (remains > 0) + { + memmove(h->reserv_buf, s->maindata + pos, remains); + } + h->reserv = remains; +} + +static int L3_restore_reservoir(mp3dec_t *h, bs_t *bs, mp3dec_scratch_t *s, int main_data_begin) +{ + int frame_bytes = (bs->limit - bs->pos)/8; + int bytes_have = MINIMP3_MIN(h->reserv, main_data_begin); + memcpy(s->maindata, h->reserv_buf + MINIMP3_MAX(0, h->reserv - main_data_begin), MINIMP3_MIN(h->reserv, main_data_begin)); + memcpy(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes); + bs_init(&s->bs, s->maindata, bytes_have + frame_bytes); + return h->reserv >= main_data_begin; +} + +static void L3_decode(mp3dec_t *h, mp3dec_scratch_t *s, L3_gr_info_t *gr_info, int nch) +{ + int ch; + + for (ch = 0; ch < nch; ch++) + { + int layer3gr_limit = s->bs.pos + gr_info[ch].part_23_length; + L3_decode_scalefactors(h->header, s->ist_pos[ch], &s->bs, gr_info + ch, s->scf, ch); + L3_huffman(s->grbuf[ch], &s->bs, gr_info + ch, s->scf, layer3gr_limit); + } + + if (HDR_TEST_I_STEREO(h->header)) + { + L3_intensity_stereo(s->grbuf[0], s->ist_pos[1], gr_info, h->header); + } else if (HDR_IS_MS_STEREO(h->header)) + { + L3_midside_stereo(s->grbuf[0], 576); + } + + for (ch = 0; ch < nch; ch++, gr_info++) + { + int aa_bands = 31; + int n_long_bands = (gr_info->mixed_block_flag ? 2 : 0) << (int)(HDR_GET_MY_SAMPLE_RATE(h->header) == 2); + + if (gr_info->n_short_sfb) + { + aa_bands = n_long_bands - 1; + L3_reorder(s->grbuf[ch] + n_long_bands*18, s->syn[0], gr_info->sfbtab + gr_info->n_long_sfb); + } + + L3_antialias(s->grbuf[ch], aa_bands); + L3_imdct_gr(s->grbuf[ch], h->mdct_overlap[ch], gr_info->block_type, n_long_bands); + L3_change_sign(s->grbuf[ch]); + } +} + +static void mp3d_DCT_II(float *grbuf, int n) +{ + static const float g_sec[24] = { + 10.19000816f,0.50060302f,0.50241929f,3.40760851f,0.50547093f,0.52249861f,2.05778098f,0.51544732f,0.56694406f,1.48416460f,0.53104258f,0.64682180f,1.16943991f,0.55310392f,0.78815460f,0.97256821f,0.58293498f,1.06067765f,0.83934963f,0.62250412f,1.72244716f,0.74453628f,0.67480832f,5.10114861f + }; + int i, k = 0; +#if HAVE_SIMD + if (have_simd()) for (; k < n; k += 4) + { + f4 t[4][8], *x; + float *y = grbuf + k; + + for (x = t[0], i = 0; i < 8; i++, x++) + { + f4 x0 = VLD(&y[i*18]); + f4 x1 = VLD(&y[(15 - i)*18]); + f4 x2 = VLD(&y[(16 + i)*18]); + f4 x3 = VLD(&y[(31 - i)*18]); + f4 t0 = VADD(x0, x3); + f4 t1 = VADD(x1, x2); + f4 t2 = VMUL_S(VSUB(x1, x2), g_sec[3*i + 0]); + f4 t3 = VMUL_S(VSUB(x0, x3), g_sec[3*i + 1]); + x[0] = VADD(t0, t1); + x[8] = VMUL_S(VSUB(t0, t1), g_sec[3*i + 2]); + x[16] = VADD(t3, t2); + x[24] = VMUL_S(VSUB(t3, t2), g_sec[3*i + 2]); + } + for (x = t[0], i = 0; i < 4; i++, x += 8) + { + f4 x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt; + xt = VSUB(x0, x7); x0 = VADD(x0, x7); + x7 = VSUB(x1, x6); x1 = VADD(x1, x6); + x6 = VSUB(x2, x5); x2 = VADD(x2, x5); + x5 = VSUB(x3, x4); x3 = VADD(x3, x4); + x4 = VSUB(x0, x3); x0 = VADD(x0, x3); + x3 = VSUB(x1, x2); x1 = VADD(x1, x2); + x[0] = VADD(x0, x1); + x[4] = VMUL_S(VSUB(x0, x1), 0.70710677f); + x5 = VADD(x5, x6); + x6 = VMUL_S(VADD(x6, x7), 0.70710677f); + x7 = VADD(x7, xt); + x3 = VMUL_S(VADD(x3, x4), 0.70710677f); + x5 = VSUB(x5, VMUL_S(x7, 0.198912367f)); /* rotate by PI/8 */ + x7 = VADD(x7, VMUL_S(x5, 0.382683432f)); + x5 = VSUB(x5, VMUL_S(x7, 0.198912367f)); + x0 = VSUB(xt, x6); xt = VADD(xt, x6); + x[1] = VMUL_S(VADD(xt, x7), 0.50979561f); + x[2] = VMUL_S(VADD(x4, x3), 0.54119611f); + x[3] = VMUL_S(VSUB(x0, x5), 0.60134488f); + x[5] = VMUL_S(VADD(x0, x5), 0.89997619f); + x[6] = VMUL_S(VSUB(x4, x3), 1.30656302f); + x[7] = VMUL_S(VSUB(xt, x7), 2.56291556f); + } + + if (k > n - 3) + { +#if HAVE_SSE +#define VSAVE2(i, v) _mm_storel_pi((__m64 *)(void*)&y[i*18], v) +#else /* HAVE_SSE */ +#define VSAVE2(i, v) vst1_f32((float32_t *)&y[i*18], vget_low_f32(v)) +#endif /* HAVE_SSE */ + for (i = 0; i < 7; i++, y += 4*18) + { + f4 s = VADD(t[3][i], t[3][i + 1]); + VSAVE2(0, t[0][i]); + VSAVE2(1, VADD(t[2][i], s)); + VSAVE2(2, VADD(t[1][i], t[1][i + 1])); + VSAVE2(3, VADD(t[2][1 + i], s)); + } + VSAVE2(0, t[0][7]); + VSAVE2(1, VADD(t[2][7], t[3][7])); + VSAVE2(2, t[1][7]); + VSAVE2(3, t[3][7]); + } else + { +#define VSAVE4(i, v) VSTORE(&y[i*18], v) + for (i = 0; i < 7; i++, y += 4*18) + { + f4 s = VADD(t[3][i], t[3][i + 1]); + VSAVE4(0, t[0][i]); + VSAVE4(1, VADD(t[2][i], s)); + VSAVE4(2, VADD(t[1][i], t[1][i + 1])); + VSAVE4(3, VADD(t[2][1 + i], s)); + } + VSAVE4(0, t[0][7]); + VSAVE4(1, VADD(t[2][7], t[3][7])); + VSAVE4(2, t[1][7]); + VSAVE4(3, t[3][7]); + } + } else +#endif /* HAVE_SIMD */ +#ifdef MINIMP3_ONLY_SIMD + {} +#else /* MINIMP3_ONLY_SIMD */ + for (; k < n; k++) + { + float t[4][8], *x, *y = grbuf + k; + + for (x = t[0], i = 0; i < 8; i++, x++) + { + float x0 = y[i*18]; + float x1 = y[(15 - i)*18]; + float x2 = y[(16 + i)*18]; + float x3 = y[(31 - i)*18]; + float t0 = x0 + x3; + float t1 = x1 + x2; + float t2 = (x1 - x2)*g_sec[3*i + 0]; + float t3 = (x0 - x3)*g_sec[3*i + 1]; + x[0] = t0 + t1; + x[8] = (t0 - t1)*g_sec[3*i + 2]; + x[16] = t3 + t2; + x[24] = (t3 - t2)*g_sec[3*i + 2]; + } + for (x = t[0], i = 0; i < 4; i++, x += 8) + { + float x0 = x[0], x1 = x[1], x2 = x[2], x3 = x[3], x4 = x[4], x5 = x[5], x6 = x[6], x7 = x[7], xt; + xt = x0 - x7; x0 += x7; + x7 = x1 - x6; x1 += x6; + x6 = x2 - x5; x2 += x5; + x5 = x3 - x4; x3 += x4; + x4 = x0 - x3; x0 += x3; + x3 = x1 - x2; x1 += x2; + x[0] = x0 + x1; + x[4] = (x0 - x1)*0.70710677f; + x5 = x5 + x6; + x6 = (x6 + x7)*0.70710677f; + x7 = x7 + xt; + x3 = (x3 + x4)*0.70710677f; + x5 -= x7*0.198912367f; /* rotate by PI/8 */ + x7 += x5*0.382683432f; + x5 -= x7*0.198912367f; + x0 = xt - x6; xt += x6; + x[1] = (xt + x7)*0.50979561f; + x[2] = (x4 + x3)*0.54119611f; + x[3] = (x0 - x5)*0.60134488f; + x[5] = (x0 + x5)*0.89997619f; + x[6] = (x4 - x3)*1.30656302f; + x[7] = (xt - x7)*2.56291556f; + + } + for (i = 0; i < 7; i++, y += 4*18) + { + y[0*18] = t[0][i]; + y[1*18] = t[2][i] + t[3][i] + t[3][i + 1]; + y[2*18] = t[1][i] + t[1][i + 1]; + y[3*18] = t[2][i + 1] + t[3][i] + t[3][i + 1]; + } + y[0*18] = t[0][7]; + y[1*18] = t[2][7] + t[3][7]; + y[2*18] = t[1][7]; + y[3*18] = t[3][7]; + } +#endif /* MINIMP3_ONLY_SIMD */ +} + +#ifndef MINIMP3_FLOAT_OUTPUT +static int16_t mp3d_scale_pcm(float sample) +{ + if (sample >= 32766.5) return (int16_t) 32767; + if (sample <= -32767.5) return (int16_t)-32768; + int16_t s = (int16_t)(sample + .5f); + s -= (s < 0); /* away from zero, to be compliant */ + return s; +} +#else /* MINIMP3_FLOAT_OUTPUT */ +static float mp3d_scale_pcm(float sample) +{ + return sample*(1.f/32768.f); +} +#endif /* MINIMP3_FLOAT_OUTPUT */ + +static void mp3d_synth_pair(mp3d_sample_t *pcm, int nch, const float *z) +{ + float a; + a = (z[14*64] - z[ 0]) * 29; + a += (z[ 1*64] + z[13*64]) * 213; + a += (z[12*64] - z[ 2*64]) * 459; + a += (z[ 3*64] + z[11*64]) * 2037; + a += (z[10*64] - z[ 4*64]) * 5153; + a += (z[ 5*64] + z[ 9*64]) * 6574; + a += (z[ 8*64] - z[ 6*64]) * 37489; + a += z[ 7*64] * 75038; + pcm[0] = mp3d_scale_pcm(a); + + z += 2; + a = z[14*64] * 104; + a += z[12*64] * 1567; + a += z[10*64] * 9727; + a += z[ 8*64] * 64019; + a += z[ 6*64] * -9975; + a += z[ 4*64] * -45; + a += z[ 2*64] * 146; + a += z[ 0*64] * -5; + pcm[16*nch] = mp3d_scale_pcm(a); +} + +static void mp3d_synth(float *xl, mp3d_sample_t *dstl, int nch, float *lins) +{ + int i; + float *xr = xl + 576*(nch - 1); + mp3d_sample_t *dstr = dstl + (nch - 1); + + static const float g_win[] = { + -1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992, + -1,24,-35,202,222,347,-581,2080,1952,4425,-5879,7640,5288,33791,-41176,74856, + -1,21,-38,196,225,294,-645,2087,1893,4063,-6237,8092,4561,31947,-43006,74630, + -1,19,-41,190,227,244,-711,2085,1822,3705,-6589,8492,3776,30112,-44821,74313, + -1,17,-45,183,228,197,-779,2075,1739,3351,-6935,8840,2935,28289,-46617,73908, + -1,16,-49,176,228,153,-848,2057,1644,3004,-7271,9139,2037,26482,-48390,73415, + -2,14,-53,169,227,111,-919,2032,1535,2663,-7597,9389,1082,24694,-50137,72835, + -2,13,-58,161,224,72,-991,2001,1414,2330,-7910,9592,70,22929,-51853,72169, + -2,11,-63,154,221,36,-1064,1962,1280,2006,-8209,9750,-998,21189,-53534,71420, + -2,10,-68,147,215,2,-1137,1919,1131,1692,-8491,9863,-2122,19478,-55178,70590, + -3,9,-73,139,208,-29,-1210,1870,970,1388,-8755,9935,-3300,17799,-56778,69679, + -3,8,-79,132,200,-57,-1283,1817,794,1095,-8998,9966,-4533,16155,-58333,68692, + -4,7,-85,125,189,-83,-1356,1759,605,814,-9219,9959,-5818,14548,-59838,67629, + -4,7,-91,117,177,-106,-1428,1698,402,545,-9416,9916,-7154,12980,-61289,66494, + -5,6,-97,111,163,-127,-1498,1634,185,288,-9585,9838,-8540,11455,-62684,65290 + }; + float *zlin = lins + 15*64; + const float *w = g_win; + + zlin[4*15] = xl[18*16]; + zlin[4*15 + 1] = xr[18*16]; + zlin[4*15 + 2] = xl[0]; + zlin[4*15 + 3] = xr[0]; + + zlin[4*31] = xl[1 + 18*16]; + zlin[4*31 + 1] = xr[1 + 18*16]; + zlin[4*31 + 2] = xl[1]; + zlin[4*31 + 3] = xr[1]; + + mp3d_synth_pair(dstr, nch, lins + 4*15 + 1); + mp3d_synth_pair(dstr + 32*nch, nch, lins + 4*15 + 64 + 1); + mp3d_synth_pair(dstl, nch, lins + 4*15); + mp3d_synth_pair(dstl + 32*nch, nch, lins + 4*15 + 64); + +#if HAVE_SIMD + if (have_simd()) for (i = 14; i >= 0; i--) + { +#define VLOAD(k) f4 w0 = VSET(*w++); f4 w1 = VSET(*w++); f4 vz = VLD(&zlin[4*i - 64*k]); f4 vy = VLD(&zlin[4*i - 64*(15 - k)]); +#define V0(k) { VLOAD(k) b = VADD(VMUL(vz, w1), VMUL(vy, w0)) ; a = VSUB(VMUL(vz, w0), VMUL(vy, w1)); } +#define V1(k) { VLOAD(k) b = VADD(b, VADD(VMUL(vz, w1), VMUL(vy, w0))); a = VADD(a, VSUB(VMUL(vz, w0), VMUL(vy, w1))); } +#define V2(k) { VLOAD(k) b = VADD(b, VADD(VMUL(vz, w1), VMUL(vy, w0))); a = VADD(a, VSUB(VMUL(vy, w1), VMUL(vz, w0))); } + f4 a, b; + zlin[4*i] = xl[18*(31 - i)]; + zlin[4*i + 1] = xr[18*(31 - i)]; + zlin[4*i + 2] = xl[1 + 18*(31 - i)]; + zlin[4*i + 3] = xr[1 + 18*(31 - i)]; + zlin[4*i + 64] = xl[1 + 18*(1 + i)]; + zlin[4*i + 64 + 1] = xr[1 + 18*(1 + i)]; + zlin[4*i - 64 + 2] = xl[18*(1 + i)]; + zlin[4*i - 64 + 3] = xr[18*(1 + i)]; + + V0(0) V2(1) V1(2) V2(3) V1(4) V2(5) V1(6) V2(7) + + { +#ifndef MINIMP3_FLOAT_OUTPUT +#if HAVE_SSE + static const f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f }; + static const f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f }; + __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)), + _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min))); + dstr[(15 - i)*nch] = _mm_extract_epi16(pcm8, 1); + dstr[(17 + i)*nch] = _mm_extract_epi16(pcm8, 5); + dstl[(15 - i)*nch] = _mm_extract_epi16(pcm8, 0); + dstl[(17 + i)*nch] = _mm_extract_epi16(pcm8, 4); + dstr[(47 - i)*nch] = _mm_extract_epi16(pcm8, 3); + dstr[(49 + i)*nch] = _mm_extract_epi16(pcm8, 7); + dstl[(47 - i)*nch] = _mm_extract_epi16(pcm8, 2); + dstl[(49 + i)*nch] = _mm_extract_epi16(pcm8, 6); +#else /* HAVE_SSE */ + int16x4_t pcma, pcmb; + a = VADD(a, VSET(0.5f)); + b = VADD(b, VSET(0.5f)); + pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, VSET(0))))); + pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, VSET(0))))); + vst1_lane_s16(dstr + (15 - i)*nch, pcma, 1); + vst1_lane_s16(dstr + (17 + i)*nch, pcmb, 1); + vst1_lane_s16(dstl + (15 - i)*nch, pcma, 0); + vst1_lane_s16(dstl + (17 + i)*nch, pcmb, 0); + vst1_lane_s16(dstr + (47 - i)*nch, pcma, 3); + vst1_lane_s16(dstr + (49 + i)*nch, pcmb, 3); + vst1_lane_s16(dstl + (47 - i)*nch, pcma, 2); + vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2); +#endif /* HAVE_SSE */ + +#else /* MINIMP3_FLOAT_OUTPUT */ + + static const f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f }; + a = VMUL(a, g_scale); + b = VMUL(b, g_scale); +#if HAVE_SSE + _mm_store_ss(dstr + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1))); + _mm_store_ss(dstr + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(1, 1, 1, 1))); + _mm_store_ss(dstl + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0))); + _mm_store_ss(dstl + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(0, 0, 0, 0))); + _mm_store_ss(dstr + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 3, 3, 3))); + _mm_store_ss(dstr + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 3, 3, 3))); + _mm_store_ss(dstl + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2))); + _mm_store_ss(dstl + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 2, 2, 2))); +#else /* HAVE_SSE */ + vst1q_lane_f32(dstr + (15 - i)*nch, a, 1); + vst1q_lane_f32(dstr + (17 + i)*nch, b, 1); + vst1q_lane_f32(dstl + (15 - i)*nch, a, 0); + vst1q_lane_f32(dstl + (17 + i)*nch, b, 0); + vst1q_lane_f32(dstr + (47 - i)*nch, a, 3); + vst1q_lane_f32(dstr + (49 + i)*nch, b, 3); + vst1q_lane_f32(dstl + (47 - i)*nch, a, 2); + vst1q_lane_f32(dstl + (49 + i)*nch, b, 2); +#endif /* HAVE_SSE */ +#endif /* MINIMP3_FLOAT_OUTPUT */ + } + } else +#endif /* HAVE_SIMD */ +#ifdef MINIMP3_ONLY_SIMD + {} +#else /* MINIMP3_ONLY_SIMD */ + for (i = 14; i >= 0; i--) + { +#define LOAD(k) float w0 = *w++; float w1 = *w++; float *vz = &zlin[4*i - k*64]; float *vy = &zlin[4*i - (15 - k)*64]; +#define S0(k) { int j; LOAD(k); for (j = 0; j < 4; j++) b[j] = vz[j]*w1 + vy[j]*w0, a[j] = vz[j]*w0 - vy[j]*w1; } +#define S1(k) { int j; LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vz[j]*w0 - vy[j]*w1; } +#define S2(k) { int j; LOAD(k); for (j = 0; j < 4; j++) b[j] += vz[j]*w1 + vy[j]*w0, a[j] += vy[j]*w1 - vz[j]*w0; } + float a[4], b[4]; + + zlin[4*i] = xl[18*(31 - i)]; + zlin[4*i + 1] = xr[18*(31 - i)]; + zlin[4*i + 2] = xl[1 + 18*(31 - i)]; + zlin[4*i + 3] = xr[1 + 18*(31 - i)]; + zlin[4*(i + 16)] = xl[1 + 18*(1 + i)]; + zlin[4*(i + 16) + 1] = xr[1 + 18*(1 + i)]; + zlin[4*(i - 16) + 2] = xl[18*(1 + i)]; + zlin[4*(i - 16) + 3] = xr[18*(1 + i)]; + + S0(0) S2(1) S1(2) S2(3) S1(4) S2(5) S1(6) S2(7) + + dstr[(15 - i)*nch] = mp3d_scale_pcm(a[1]); + dstr[(17 + i)*nch] = mp3d_scale_pcm(b[1]); + dstl[(15 - i)*nch] = mp3d_scale_pcm(a[0]); + dstl[(17 + i)*nch] = mp3d_scale_pcm(b[0]); + dstr[(47 - i)*nch] = mp3d_scale_pcm(a[3]); + dstr[(49 + i)*nch] = mp3d_scale_pcm(b[3]); + dstl[(47 - i)*nch] = mp3d_scale_pcm(a[2]); + dstl[(49 + i)*nch] = mp3d_scale_pcm(b[2]); + } +#endif /* MINIMP3_ONLY_SIMD */ +} + +static void mp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, mp3d_sample_t *pcm, float *lins) +{ + int i; + for (i = 0; i < nch; i++) + { + mp3d_DCT_II(grbuf + 576*i, nbands); + } + + memcpy(lins, qmf_state, sizeof(float)*15*64); + + for (i = 0; i < nbands; i += 2) + { + mp3d_synth(grbuf + i, pcm + 32*nch*i, nch, lins + i*64); + } +#ifndef MINIMP3_NONSTANDARD_BUT_LOGICAL + if (nch == 1) + { + for (i = 0; i < 15*64; i += 2) + { + qmf_state[i] = lins[nbands*64 + i]; + } + } else +#endif /* MINIMP3_NONSTANDARD_BUT_LOGICAL */ + { + memcpy(qmf_state, lins + nbands*64, sizeof(float)*15*64); + } +} + +static int mp3d_match_frame(const uint8_t *hdr, int mp3_bytes, int frame_bytes) +{ + int i, nmatch; + for (i = 0, nmatch = 0; nmatch < MAX_FRAME_SYNC_MATCHES; nmatch++) + { + i += hdr_frame_bytes(hdr + i, frame_bytes) + hdr_padding(hdr + i); + if (i + HDR_SIZE > mp3_bytes) + return nmatch > 0; + if (!hdr_compare(hdr, hdr + i)) + return 0; + } + return 1; +} + +static int mp3d_find_frame(const uint8_t *mp3, int mp3_bytes, int *free_format_bytes, int *ptr_frame_bytes) +{ + int i, k; + for (i = 0; i < mp3_bytes - HDR_SIZE; i++, mp3++) + { + if (hdr_valid(mp3)) + { + int frame_bytes = hdr_frame_bytes(mp3, *free_format_bytes); + int frame_and_padding = frame_bytes + hdr_padding(mp3); + + for (k = HDR_SIZE; !frame_bytes && k < MAX_FREE_FORMAT_FRAME_SIZE && i + 2*k < mp3_bytes - HDR_SIZE; k++) + { + if (hdr_compare(mp3, mp3 + k)) + { + int fb = k - hdr_padding(mp3); + int nextfb = fb + hdr_padding(mp3 + k); + if (i + k + nextfb + HDR_SIZE > mp3_bytes || !hdr_compare(mp3, mp3 + k + nextfb)) + continue; + frame_and_padding = k; + frame_bytes = fb; + *free_format_bytes = fb; + } + } + if ((frame_bytes && i + frame_and_padding <= mp3_bytes && + mp3d_match_frame(mp3, mp3_bytes - i, frame_bytes)) || + (!i && frame_and_padding == mp3_bytes)) + { + *ptr_frame_bytes = frame_and_padding; + return i; + } + *free_format_bytes = 0; + } + } + *ptr_frame_bytes = 0; + return i; +} + +void mp3dec_init(mp3dec_t *dec) +{ + dec->header[0] = 0; +} + +int mp3dec_decode_frame(mp3dec_t *dec, const uint8_t *mp3, int mp3_bytes, mp3d_sample_t *pcm, mp3dec_frame_info_t *info) +{ + int i = 0, igr, frame_size = 0, success = 1; + const uint8_t *hdr; + bs_t bs_frame[1]; + mp3dec_scratch_t scratch; + + if (mp3_bytes > 4 && dec->header[0] == 0xff && hdr_compare(dec->header, mp3)) + { + frame_size = hdr_frame_bytes(mp3, dec->free_format_bytes) + hdr_padding(mp3); + if (frame_size != mp3_bytes && (frame_size + HDR_SIZE > mp3_bytes || !hdr_compare(mp3, mp3 + frame_size))) + { + frame_size = 0; + } + } + if (!frame_size) + { + memset(dec, 0, sizeof(mp3dec_t)); + i = mp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size); + if (!frame_size || i + frame_size > mp3_bytes) + { + info->frame_bytes = i; + return 0; + } + } + + hdr = mp3 + i; + memcpy(dec->header, hdr, HDR_SIZE); + info->frame_bytes = i + frame_size; + info->channels = HDR_IS_MONO(hdr) ? 1 : 2; + info->hz = hdr_sample_rate_hz(hdr); + info->layer = 4 - HDR_GET_LAYER(hdr); + info->bitrate_kbps = hdr_bitrate_kbps(hdr); + + if (!pcm) + { + return hdr_frame_samples(hdr); + } + + bs_init(bs_frame, hdr + HDR_SIZE, frame_size - HDR_SIZE); + if (HDR_IS_CRC(hdr)) + { + get_bits(bs_frame, 16); + } + + if (info->layer == 3) + { + int main_data_begin = L3_read_side_info(bs_frame, scratch.gr_info, hdr); + if (main_data_begin < 0 || bs_frame->pos > bs_frame->limit) + { + mp3dec_init(dec); + return 0; + } + success = L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin); + if (success) + { + for (igr = 0; igr < (HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm += 576*info->channels) + { + memset(scratch.grbuf[0], 0, 576*2*sizeof(float)); + L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels); + mp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, pcm, scratch.syn[0]); + } + } + L3_save_reservoir(dec, &scratch); + } else + { +#ifdef MINIMP3_ONLY_MP3 + return 0; +#else /* MINIMP3_ONLY_MP3 */ + L12_scale_info sci[1]; + L12_read_scale_info(hdr, bs_frame, sci); + + memset(scratch.grbuf[0], 0, 576*2*sizeof(float)); + for (i = 0, igr = 0; igr < 3; igr++) + { + if (12 == (i += L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1))) + { + i = 0; + L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]); + mp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, pcm, scratch.syn[0]); + memset(scratch.grbuf[0], 0, 576*2*sizeof(float)); + pcm += 384*info->channels; + } + if (bs_frame->pos > bs_frame->limit) + { + mp3dec_init(dec); + return 0; + } + } +#endif /* MINIMP3_ONLY_MP3 */ + } + return success*hdr_frame_samples(dec->header); +} + +#ifdef MINIMP3_FLOAT_OUTPUT +void mp3dec_f32_to_s16(const float *in, int16_t *out, int num_samples) +{ + if(num_samples > 0) + { + int i = 0; +#if HAVE_SIMD + int aligned_count = num_samples & ~7; + + for(;i < aligned_count;i+=8) + { + static const f4 g_scale = { 32768.0f, 32768.0f, 32768.0f, 32768.0f }; + f4 a = VMUL(VLD(&in[i ]), g_scale); + f4 b = VMUL(VLD(&in[i+4]), g_scale); +#if HAVE_SSE + static const f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f }; + static const f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f }; + __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)), + _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min))); + out[i ] = _mm_extract_epi16(pcm8, 0); + out[i+1] = _mm_extract_epi16(pcm8, 1); + out[i+2] = _mm_extract_epi16(pcm8, 2); + out[i+3] = _mm_extract_epi16(pcm8, 3); + out[i+4] = _mm_extract_epi16(pcm8, 4); + out[i+5] = _mm_extract_epi16(pcm8, 5); + out[i+6] = _mm_extract_epi16(pcm8, 6); + out[i+7] = _mm_extract_epi16(pcm8, 7); +#else /* HAVE_SSE */ + int16x4_t pcma, pcmb; + a = VADD(a, VSET(0.5f)); + b = VADD(b, VSET(0.5f)); + pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, VSET(0))))); + pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, VSET(0))))); + vst1_lane_s16(out+i , pcma, 0); + vst1_lane_s16(out+i+1, pcma, 1); + vst1_lane_s16(out+i+2, pcma, 2); + vst1_lane_s16(out+i+3, pcma, 3); + vst1_lane_s16(out+i+4, pcmb, 0); + vst1_lane_s16(out+i+5, pcmb, 1); + vst1_lane_s16(out+i+6, pcmb, 2); + vst1_lane_s16(out+i+7, pcmb, 3); +#endif /* HAVE_SSE */ + } +#endif /* HAVE_SIMD */ + for(; i < num_samples; i++) + { + float sample = in[i] * 32768.0f; + if (sample >= 32766.5) + out[i] = (int16_t) 32767; + else if (sample <= -32767.5) + out[i] = (int16_t)-32768; + else + { + int16_t s = (int16_t)(sample + .5f); + s -= (s < 0); /* away from zero, to be compliant */ + out[i] = s; + } + } + } +} +#endif /* MINIMP3_FLOAT_OUTPUT */ +#endif /* MINIMP3_IMPLEMENTATION && !_MINIMP3_IMPLEMENTATION_GUARD */ diff --git a/Src/Sound/MPEG/MPEG.h b/Src/Sound/MPEG/MPEG.h deleted file mode 100644 index f23e590..0000000 --- a/Src/Sound/MPEG/MPEG.h +++ /dev/null @@ -1,138 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * MPEG.h - * - * Header file for MPEG decoder based on AMP by Tomislav Uzalec. Modified to - * play from memory buffers by R. Belmont for his arcade music player, M1. - */ - -#ifndef INCLUDED_MPEG_H -#define INCLUDED_MPEG_H - -#include "Types.h" - - -/****************************************************************************** - Functions - - The MPEG decoder is not thread-safe and must not be used by multiple sources. - These functions are located in audio.cpp and getbits.cpp. -******************************************************************************/ - -/* - * MPEG_IsPlaying(void): - * - * Returns: - * TRUE if an MPEG stream is currently playing, otherwise false. - */ -extern bool MPEG_IsPlaying(void); - -/* - * MPEG_GetPlayPosition(playOffset, endOffset): - * - * Obtains the current playback and end offsets of the MPEG stream. - * - * Parameters: - * playOffset Pointer to which playback byte offset will be written. - * endOffset Pointer to which end offset will be written. - */ -extern void MPEG_GetPlayPosition(int *playOffset, int *endOffset); - -/* - * MPEG_SetPlayPosition(playOffset, endOffset): - * - * Sets the playback position within an MPEG stream. - * - * Parameters: - * playOffset Playback byte offset (relative to beginning of the current - * MPEG stream). - * endOffset End offset. - */ -extern void MPEG_SetPlayPosition(int playOffset, int endOffset); - -/* - * MPEG_SetLoop(loop, loopend): - * - * Sets the start and end offsets for looped playback. - * - * Parameters: - * loop Start address. - * loopend End offset. Must NOT be 0! - */ -extern void MPEG_SetLoop(const char *loop, int loopend); - -/* - * MPEG_Decode(outputs, length): - * - * Decodes the requested number of samples from the currently playing MPEG - * stream and updates the internal play position. If an MPEG is not playing, - * writes silence (zeros). - * - * Parameters: - * outputs A two-element array of pointers to equal-length signed 16- - * bit sample buffers. The first is the left channel and the - * second is the right channel. Audio is decoded to these. - * length Number of samples to decode. - */ -extern void MPEG_Decode(INT16 **outputs, int length); - -/* - * MPEG_PlayMemory(sa, length): - * - * Specifies the memory buffer to decode from. This initializes the playback - * process and will decode the first MPEG frame internally. The loop start - * position is cleared (set looping after this call). - * - * Parameters: - * sa Start address of MPEG stream. - * length Length in bytes. - */ -extern void MPEG_PlayMemory(const char *sa, int length); - -/* - * MPEG_StopPlaying(void): - * - * Stop playing the current MPEG stream. The decoder will return silence. - */ -extern void MPEG_StopPlaying(void); - -/* - * MPEG_Init(void): - * - * Initializes the MPEG decoder. This should be called once per program - * session. Allocates an internal buffer for MPEG decoding. - * - * Returns: - * OKAY if successful, FAIL if internal buffer could not be allocated. - */ -extern bool MPEG_Init(void); - -/* - * MPEG_Shutdown(void): - * - * Shuts down the MPEG decoder. Releases internal memory. - */ -extern void MPEG_Shutdown(void); - - -#endif // INCLUDED_MPEG_H \ No newline at end of file diff --git a/Src/Sound/MPEG/MpegAudio.cpp b/Src/Sound/MPEG/MpegAudio.cpp new file mode 100644 index 0000000..6f92e04 --- /dev/null +++ b/Src/Sound/MPEG/MpegAudio.cpp @@ -0,0 +1,130 @@ +#define MINIMP3_IMPLEMENTATION +#include "Pkgs/minimp3.h" +#include "MpegAudio.h" + +struct Decoder +{ + mp3dec_t mp3d; + mp3dec_frame_info_t info; + const uint8_t* buffer; + size_t size, pos; + bool loop; + bool stopped; + int numSamples; + int pcmPos; + short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME]; +}; + +static Decoder dec = { 0 }; + +void MpegDec::SetMemory(const uint8_t *data, int length, bool loop) +{ + mp3dec_init(&dec.mp3d); + + dec.buffer = data; + dec.size = length; + dec.pos = 0; + dec.numSamples = 0; + dec.pcmPos = 0; + dec.loop = loop; + dec.stopped = false; +} + +void MpegDec::UpdateMemory(const uint8_t* data, int length, bool loop) +{ + auto pos = dec.buffer + dec.pos; + + dec.buffer = data; + dec.size = length; + dec.pos = pos - dec.buffer; // update position relative to our new start location + dec.loop = loop; +} + +int MpegDec::GetPosition() +{ + return (int)dec.pos; +} + +void MpegDec::SetPosition(int pos) +{ + dec.pos = pos; +} + +static void FlushBuffer(int16_t*& left, int16_t*& right, int& numStereoSamples) +{ + int numChans = dec.info.channels; + + int &i = dec.pcmPos; + + for (; i < (dec.numSamples * numChans) && numStereoSamples; i += numChans) { + *left++ = dec.pcm[i]; + *right++ = dec.pcm[i + numChans - 1]; + numStereoSamples--; + } +} + +// might need to copy some silence to end the buffer if we aren't looping +static void EndWithSilence(int16_t*& left, int16_t*& right, int& numStereoSamples) +{ + while (numStereoSamples) + { + *left++ = 0; + *right++ = 0; + numStereoSamples--; + } +} + +static bool EndOfBuffer() +{ + return dec.pos >= dec.size - HDR_SIZE; +} + +void MpegDec::Stop() +{ + dec.stopped = true; +} + +bool MpegDec::IsLoaded() +{ + return dec.buffer != nullptr; +} + +void MpegDec::DecodeAudio(int16_t* left, int16_t* right, int numStereoSamples) +{ + // if we are stopped return silence + if (dec.stopped || !dec.buffer) { + EndWithSilence(left, right, numStereoSamples); + } + + // copy any left over samples first + FlushBuffer(left, right, numStereoSamples); + + while (numStereoSamples) { + + dec.numSamples = mp3dec_decode_frame( + &dec.mp3d, + dec.buffer + dec.pos, + dec.size - dec.pos, + dec.pcm, + &dec.info); + + dec.pos += dec.info.frame_bytes; + dec.pcmPos = 0; // reset pos + + FlushBuffer(left, right, numStereoSamples); + + // check end of buffer handling + if (EndOfBuffer()) { + if (dec.loop) { + dec.pos = 0; + } + else { + EndWithSilence(left, right, numStereoSamples); + } + } + + } + +} + + diff --git a/Src/Sound/MPEG/MpegAudio.h b/Src/Sound/MPEG/MpegAudio.h new file mode 100644 index 0000000..2a5b156 --- /dev/null +++ b/Src/Sound/MPEG/MpegAudio.h @@ -0,0 +1,18 @@ +#ifndef _MPEG_AUDIO_H_ +#define _MPEG_AUDIO_H_ + +#include + +namespace MpegDec +{ + void SetMemory(const uint8_t *data, int length, bool loop); + void UpdateMemory(const uint8_t *data, int length, bool loop); + int GetPosition(); + void SetPosition(int pos); + void DecodeAudio(int16_t* left, int16_t* right, int numStereoSamples); + void Stop(); + bool IsLoaded(); +} + +#endif + diff --git a/Src/Sound/MPEG/amp.h b/Src/Sound/MPEG/amp.h deleted file mode 100644 index 05d7a19..0000000 --- a/Src/Sound/MPEG/amp.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * amp.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* these should not be touched -*/ -#define SYNCWORD 0xfff -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif - -/* version -*/ -#define MAJOR 0 -#define MINOR 7 -#define PATCH 6 - -#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define MAX3(a,b,c) ((a) > (b) ? MAX(a, c) : MAX(b, c)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) - - -/* Debugging flags */ - -struct debugFlags_t { - int audio,args,buffer,buffer2,misc,misc2; -}; - -struct debugLookup_t { - char *name; int *var; -}; - -extern struct debugFlags_t debugFlags; - -/* This is only here to keep all the debug stuff together */ -#ifdef AMP_UTIL -struct debugLookup_t debugLookup[] = { - {"audio", &debugFlags.audio}, - {"args", &debugFlags.args}, - {"buffer", &debugFlags.buffer}, - {"buffer2", &debugFlags.buffer2}, - {"misc", &debugFlags.misc}, - {"misc2", &debugFlags.misc2}, - {0,0} -}; -#endif /* AMP_UTIL */ - -extern struct debugLookup_t debugLookup[]; - - -#ifdef DEBUG - #define DB(type,cmd) if (debugFlags.type) { cmd ; } -#else - #define DB(type,cmd) -#endif - -#include "config.h" -#include "proto.h" - - -extern int AUDIO_BUFFER_SIZE; diff --git a/Src/Sound/MPEG/amp_audio.cpp b/Src/Sound/MPEG/amp_audio.cpp deleted file mode 100644 index 0ebc5ff..0000000 --- a/Src/Sound/MPEG/amp_audio.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * audio.cpp - * - * Main Amp module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* audio.c main amp source file - * - * Created by: tomislav uzelac Apr 1996 - * Karl Anders Oygard added the IRIX code, 10 Mar 1997. - * Ilkka Karvinen fixed /dev/dsp initialization, 11 Mar 1997. - * Lutz Vieweg added the HP/UX code, 14 Mar 1997. - * Dan Nelson added FreeBSD modifications, 23 Mar 1997. - * Andrew Richards complete reorganisation, new features, 25 Mar 1997 - * Edouard Lafargue added sajber jukebox support, 12 May 1997 - */ - - -#include "amp.h" - -#define AUDIO -#include "amp_audio.h" -#include "formats.h" -#include "getbits.h" -#include "huffman.h" -#include "layer2.h" -#include "layer3.h" -#include "position.h" -#include "rtbuf.h" -#include "transform.h" - -//#ifndef __BEOS__ -//typedef int bool; -//#endif - -#include -#include -#include "Supermodel.h" -#include "MPEG.h" - -//#include "m1snd.h" -//#include "oss.h" -//#include "mpeg.h" - -#define BUF_SIZE (1152 * sizeof(short) * 2) - -void calculate_t43(void); - -static int decoder_init = 0; -static int cnt = 0; -static int stream = -1; -static char *buf0; -static int playing = 0; -static int outpos = 0; -static int mpeg_eof = 0; -static char *dst, *readbuf; -static struct AUDIO_HEADER m1hdr;; - -void statusDisplay(struct AUDIO_HEADER *header, int frameNo) -{ - int minutes,seconds; - - if ((A_SHOW_CNT || A_SHOW_TIME) && !(frameNo%10)) - msg("\r"); - if (A_SHOW_CNT && !(frameNo%10) ) { - msg("{ %d } ",frameNo); - } - if (A_SHOW_TIME && !(frameNo%10)) { - seconds=frameNo*1152/t_sampling_frequency[header->ID][header->sampling_frequency]; - minutes=seconds/60; - seconds=seconds % 60; - msg("[%d:%02d]",minutes,seconds); - } - if (A_SHOW_CNT || A_SHOW_TIME) - fflush(stderr); -} - -// one mpeg frame is 576 samples. -int decodeMPEGOneFrame(struct AUDIO_HEADER *header) -{ - int snd_eof = 0, g; - - if ((g=gethdr(header))!=0) { - report_header_error(g); - snd_eof=1; - return snd_eof; - } - - if (header->protection_bit==0) getcrc(); - - statusDisplay(header,0); - - if (header->layer==1) { - if (layer3_frame(header,cnt)) { - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - return -1; - } - } else if (header->layer==2) - if (layer2_frame(header,cnt)) { - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - return -1; - } - - cnt++; - - return snd_eof; -} - -int decodeMPEG(void) -{ -struct AUDIO_HEADER header; -int g,snd_eof=0; - - initialise_globals(); - - cnt = 0; - - if ((g=gethdr(&header))!=0) { - report_header_error(g); - return -1; - } - - if (header.protection_bit==0) getcrc(); - - //printf("%d Hz, layer %d\n", t_sampling_frequency[header.ID][header.sampling_frequency], header.layer); - - if (setup_audio(&header)!=0) { // will never fail (setup_audio() does nothing) - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - return -1; - } - - if (header.layer==1) { - if (layer3_frame(&header,cnt)) { - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - return -1; - } - } else if (header.layer==2) - if (layer2_frame(&header,cnt)) { - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - return -1; - } - - /* - * decoder loop ********************************** - */ - snd_eof=0; - while (!snd_eof) { - while (!snd_eof && ready_audio()) { - snd_eof = decodeMPEGOneFrame(&header); - } - } - return 0; -} - -/* call this once at the beginning - */ -void initialise_decoder(void) -{ - premultiply(); - imdct_init(); - calculate_t43(); -} - -/* call this before each file is played - */ -void initialise_globals(void) -{ - append=::data=nch=0; - f_bdirty=TRUE; - bclean_bytes=0; - - memset(s,0,sizeof s); - memset(res,0,sizeof res); -} - -void report_header_error(int err) -{ - switch (err) { - case GETHDR_ERR: - ErrorLog("Internal error in MPEG decoder: unable to read bit stream."); - break; - case GETHDR_NS : - ErrorLog("Internal error in MPEG decoder: invalid MPEG format encountered."); - break; - case GETHDR_FL1: - ErrorLog("Internal error in MPEG decoder: unsupported MPEG format encountered."); - break; - case GETHDR_FF : - ErrorLog("Internal error in MPEG decoder: unsupported bit stream encountered."); - break; - case GETHDR_SYN: - ErrorLog("Internal error in MPEG decoder: out of sync!"); - break; - case GETHDR_EOF: - default: ; /* some stupid compilers need the semicolon */ - } -} - -int setup_audio(struct AUDIO_HEADER *header) -{ - return 0; -} - -void close_audio(void) -{ -} - -int ready_audio(void) -{ - return 1; -} - -// callback: called by the engine to output a frame of audio -void printout(void) -{ - int j; - - if (nch==2) - { - j=32 * 18 * 2; - } - else - { - j=32 * 18; - } - -// printf("printout: %x, %d\n", (unsigned int), j*2); - memcpy(dst, sample_buffer, j*2); - - dst += j*2; - outpos += j/2; -} - -void MPEG_Decode(INT16 **outputs, int length) -{ - int i, remaining, bias; - INT16 *get; - - remaining = length; - -// printf("%d: %x %x\n", length, (unsigned int)outputs[0], (unsigned int)outputs[1]); - - if (!playing) - { - memset(&outputs[0][0], 0, length * sizeof(INT16)); - memset(&outputs[1][0], 0, length * sizeof(INT16)); - return; - } - - bias = 0; - - // will we need more data from the decoder? - if (outpos < length) - { - // if there's anything left in the current buffer, drain it first - if (outpos != 0) - { - get = (INT16 *)readbuf; - - for (i = 0; i < outpos; i++) - { - outputs[1][i] = *get++; - outputs[0][i] = *get++; - } - - remaining -= outpos; - bias = outpos; - readbuf += (outpos * 4); - } - - outpos = 0; - dst = buf0; - while ((outpos < remaining) && (playing)) - { - mpeg_eof = decodeMPEGOneFrame(&m1hdr); - if (mpeg_eof) - { - MPEG_StopPlaying(); - } - } - - // reset read pointer - readbuf = buf0; - } - - get = (INT16 *)readbuf; - - for (i = 0; i < remaining; i++) - { - outputs[1][i+bias] = *get++; - outputs[0][i+bias] = *get++; - } - - outpos -= remaining; - readbuf += (remaining * 4); -} - -void MPEG_PlayFile(char *filename) -{ - memset(buf0, 0, BUF_SIZE); - - in_file = fopen(filename, "rb"); - - initialise_globals(); - - cnt = 0; - mpeg_eof = 0; - outpos = 0; - dst = buf0; - readbuf = buf0; - - gethdr(&m1hdr); - if (m1hdr.protection_bit == 0) getcrc(); - -// printf("%d Hz, layer %d\n", t_sampling_frequency[m1hdr.ID][m1hdr.sampling_frequency], m1hdr.layer); - -// stream_set_srate(stream, t_sampling_frequency[m1hdr.ID][m1hdr.sampling_frequency]); - - // prime the stream - if (m1hdr.layer == 1) - { - layer3_frame(&m1hdr, cnt); - } - else if (m1hdr.layer == 2) - { - layer2_frame(&m1hdr, cnt); - } - - playing = 1; -} - -extern void m1setfile(const char *mstart, int mend); -void MPEG_PlayMemory(const char *sa, int length) -{ - memset(buf0, 0, BUF_SIZE); - - m1setfile(sa, length); - - initialise_globals(); - - cnt = 0; - mpeg_eof = 0; - outpos = 0; - dst = buf0; - readbuf = buf0; - - gethdr(&m1hdr); - if (m1hdr.protection_bit == 0) getcrc(); - -// printf("%d Hz, layer %d\n", t_sampling_frequency[m1hdr.ID][m1hdr.sampling_frequency], m1hdr.layer); - -// stream_set_srate(stream, t_sampling_frequency[m1hdr.ID][m1hdr.sampling_frequency]); - - // prime the stream - if (m1hdr.layer == 1) - { - layer3_frame(&m1hdr, cnt); - } - else if (m1hdr.layer == 2) - { - layer2_frame(&m1hdr, cnt); - } - - in_file = NULL; - - playing = 1; -} - -void MPEG_StopPlaying(void) -{ - if (playing) - { - playing = 0; - if (in_file) - fclose(in_file); - } -} - -bool MPEG_IsPlaying(void) -{ - return playing ? TRUE : false; -} - -bool MPEG_Init(void) -{ - if (!decoder_init) - { - initialise_decoder(); /* initialise decoder */ - decoder_init = 1; - buf0 = new(std::nothrow) char[BUF_SIZE]; - if (NULL == buf0) - return FAIL; - memset(buf0, 0, BUF_SIZE); - playing = 0; - } - - return OKAY; -} - -void MPEG_Shutdown( void ) -{ - decoder_init = 0; - if (buf0 != NULL) - delete [] buf0; - buf0 = NULL; -} - diff --git a/Src/Sound/MPEG/amp_audio.h b/Src/Sound/MPEG/amp_audio.h deleted file mode 100644 index a584335..0000000 --- a/Src/Sound/MPEG/amp_audio.h +++ /dev/null @@ -1,208 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * audio.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* audio.h some global variables - * - * Created by: tomislav uzelac Mar/Apr, Jul 96 - */ - -#include - -struct AUDIO_HEADER { - int ID; - int layer; - int protection_bit; - int bitrate_index; - int sampling_frequency; - int padding_bit; - int private_bit; - int mode; - int mode_extension; - int copyright; - int original; - int emphasis; -}; - -struct SIDE_INFO { - int main_data_begin; - int scfsi[2][4]; - int part2_3_length[2][2]; - int big_values[2][2]; - int global_gain[2][2]; - int scalefac_compress[2][2]; - int window_switching_flag[2][2]; - int block_type[2][2]; - int mixed_block_flag[2][2]; - int table_select[2][2][3]; - int subblock_gain[2][2][3]; - int region0_count[2][2]; - int region1_count[2][2]; - int preflag[2][2]; - int scalefac_scale[2][2]; - int count1table_select[2][2]; -}; - - -/* global stuff -*/ - -extern FILE *in_file,*out_file; - -extern void statusDisplay(struct AUDIO_HEADER *header, int frameNo); -extern int decodeMPEG(void); -extern void initialise_globals(void); -extern void report_header_error(int err); - -extern int scalefac_l[2][2][22]; -extern int scalefac_s[2][2][13][3]; -extern int t_b8_l[2][3][22]; -extern int t_b8_s[2][3][13]; -extern short t_bitrate[2][3][15]; - -extern int is[2][578]; -extern float xr[2][32][18]; - -extern int *t_l,*t_s; -extern int nch; -extern int t_sampling_frequency[2][3]; - -extern int A_QUIET,A_SHOW_CNT,A_FORMAT_WAVE,A_DUMP_BINARY; -extern int A_WRITE_TO_AUDIO,A_WRITE_TO_FILE; -extern short pcm_sample[64]; -extern int A_AUDIO_PLAY; -extern int A_SET_VOLUME,A_SHOW_TIME; -extern int A_MSG_STDOUT; -extern int A_DOWNMIX; - -/* GUI CONTROL STUFF */ -extern int GUI_PLAY; -extern int GUI_PLAYING; -extern int GUI_PAUSE; -extern int GUI_PAUSED; -extern int GUI_STOP; -extern int GUI_STOPPED; -extern int GUI_FD_TO_PLAY; -extern int GUI_NEXT_FILE_READY; - -/* GUI control stuff */ -extern int send_fd; -extern int receive_fd; - -extern int stop_flag; -extern int quit_flag; - -/* ... -*/ - -#ifdef AUDIO - -FILE *in_file,*out_file; - -int scalefac_l[2][2][22]; -int scalefac_s[2][2][13][3]; - -int is[2][578]; -float xr[2][32][18]; - -int *t_l,*t_s; -int nch; -int t_sampling_frequency[2][3] = { -{ 22050 , 24000 , 16000}, -{ 44100 , 48000 , 32000} -}; - -/* GUI control stuff */ -int send_fd; -int receive_fd; - -int stop_flag; -int quit_flag; - -int GUI_PLAY,GUI_PLAYING,GUI_STOP,GUI_STOPPED,GUI_PAUSE,GUI_PAUSED; -int GUI_FD_TO_PLAY,GUI_NEXT_FILE_READY; - -int A_QUIET,A_SHOW_CNT,A_FORMAT_WAVE,A_DUMP_BINARY; -int A_WRITE_TO_FILE; -int A_AUDIO_PLAY; -int A_SET_VOLUME, A_SHOW_TIME; -int A_MSG_STDOUT; -int A_DOWNMIX; - -short pcm_sample[64]; - -short t_bitrate[2][3][15] = {{ -{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256}, -{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160}, -{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160} -},{ -{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448}, -{0,32,48,56,64,80,96,112,128,160,192,224,256,320,384}, -{0,32,40,48,56,64,80,96,112,128,160,192,224,256,320} -}}; - -/* the last sfb is given implicitly on pg.28. of the standard. scalefactors - * for that one are 0, pretab also - */ -/* leftmost index denotes ID, so first three tables are for MPEG2 (header->ID==0) - * and the other three are for MPEG1 (header->ID==1) - */ -/* 22.05, 24, 16 */ -int t_b8_l[2][3][22]={{ /* table B.8b ISO/IEC 11172-3 */ -{5,11,17,23,29,35,43,53,65,79,95,115,139,167,199,237,283,335,395,463,521,575}, -{5,11,17,23,29,35,43,53,65,79,95,113,135,161,193,231,277,331,393,463,539,575}, -{5,11,17,23,29,35,43,53,65,79,95,115,139,167,199,237,283,335,395,463,521,575} -},{ -{3,7,11,15,19,23,29,35,43,51,61,73,89,109,133,161,195,237,287,341,417,575}, -{3,7,11,15,19,23,29,35,41,49,59,71,87,105,127,155,189,229,275,329,383,575}, -{3,7,11,15,19,23,29,35,43,53,65,81,101,125,155,193,239,295,363,447,549,575} -}}; -int t_b8_s[2][3][13]={{ /* table B.8b ISO/IEC 11172-3 */ -{3,7,11,17,23,31,41,55,73,99,131,173,191}, -{3,7,11,17,25,35,47,61,79,103,135,179,191}, -{3,7,11,17,25,35,47,61,79,103,133,173,191} -},{ -{3,7,11,15,21,29,39,51,65,83,105,135,191}, -{3,7,11,15,21,27,37,49,63,79,99,125,191}, -{3,7,11,15,21,29,41,57,77,103,137,179,191} -}}; - -int args(int argc,char **argv); -void initialise_decoder(void); -int decodeMPEG(void); -void initialise_globals(void); -void report_header_error(int err); -int setup_audio(struct AUDIO_HEADER *header); -void close_audio(void); -int ready_audio(void); - -void play(char *inFileStr, char *outFileStr); - -#endif /* AUDIO */ diff --git a/Src/Sound/MPEG/config.h b/Src/Sound/MPEG/config.h deleted file mode 100644 index c2e8331..0000000 --- a/Src/Sound/MPEG/config.h +++ /dev/null @@ -1,90 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * config.h - * - * Amp library internal header file. - */ - - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define if you don't have vprintf but do have _doprnt. */ -/* #undef HAVE_DOPRNT */ - -/* Define if you have that is POSIX.1 compatible. */ -//#define HAVE_SYS_WAIT_H 1 - -/* Define if you have the vprintf function. */ -//#define HAVE_VPRINTF 1 - -/* Define as __inline if that's what the C compiler calls it. */ -/* #undef inline */ - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define if you can safely include both and . */ -//#define TIME_WITH_SYS_TIME 1 - -/* Define if you have the mlock function. */ -//#define HAVE_MLOCK 1 - -/* Define if you have the mlockall function. */ -//#define HAVE_MLOCKALL 1 - -/* Define if you have the sched_setscheduler function. */ -//#define HAVE_SCHED_SETSCHEDULER 1 - -/* Define if you have the select function. */ -//#define HAVE_SELECT 1 - -/* Define if you have the header file. */ -/* #undef HAVE_DMEDIA_AUDIO_H */ - -/* Define if you have the header file. */ -//#define HAVE_FCNTL_H 1 - -/* Define if you have the header file. */ -//#define HAVE_LINUX_SOUNDCARD_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_MACHINE_SOUNDCARD_H */ - -/* Define if you have the header file. */ -/* #undef HAVE_SYS_AUDIOIO_H */ - -/* Define if you have the header file. */ -//#define HAVE_SYS_IOCTL_H 1 - -/* Define if you have the header file. */ -//#define HAVE_SYS_SELECT_H 1 - -/* Define if you have the header file. */ -//#define HAVE_SYS_TIME_H 1 - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* define if you want playing to use Linux realtime features */ -/* #undef LINUX_REALTIME */ diff --git a/Src/Sound/MPEG/dump.cpp b/Src/Sound/MPEG/dump.cpp deleted file mode 100644 index 4b9a91d..0000000 --- a/Src/Sound/MPEG/dump.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * dump.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* dump.c binary/hex dump from buffer - * - * Created by: tomislav uzelac May 1996 - * Last modified by: tomislav May 31 1997 - */ -//#include -#include - -#include "amp_audio.h" -#include "getbits.h" - -#define DUMP -#include "dump.h" - -/* no hex dump, sorry - */ -void dump(int *length) /* in fact int length[4] */ -{ -int i,j; -int _data,space=0; - printf(" *********** binary dump\n"); - _data=data; - for (i=0;i<4;i++) { - for (j=0;j> (7-(_data&7)) )&1 ); - space++; - _data++; - _data&=8*BUFFER_SIZE-1; - if (!(_data & 7)) { - printf(" "); - space++; - if (space>70) { - printf("\n"); - space=0; - } - } - } - printf("~\n"); - } -} - -void show_header(struct AUDIO_HEADER *header) -{ -int bitrate=t_bitrate[header->ID][3-header->layer][header->bitrate_index]; -int fs=t_sampling_frequency[header->ID][header->sampling_frequency]; -int mpg,layer; -char stm[8]; - if (A_QUIET) return; - layer=4-header->layer; - if (header->ID==1) mpg=1; - else mpg=2; - if (header->mode==3) strcpy(stm,"mono"); - else strcpy(stm,"stereo"); - - printf("\n\ -Properties: %s %dHz\n\ -Coding Method: MPEG%1d.0 layer%1d\n\ -Bitrate: %dkbit/s\n"\ - ,stm,fs,mpg,layer,bitrate); -} diff --git a/Src/Sound/MPEG/dump.h b/Src/Sound/MPEG/dump.h deleted file mode 100644 index a698561..0000000 --- a/Src/Sound/MPEG/dump.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * dump.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ -/* dump.h - * - * Last modified by: tomislav uzelac May 31 1997 - */ - -extern void dump(int *length); -extern void show_header(struct AUDIO_HEADER *header); - -#ifdef DUMP -void dump(int *length); -void show_header(struct AUDIO_HEADER *header); -/* -static char *t_modes[] = { - "stereo","joint_stereo","dual_channel","single_channel"}; -*/ -#endif /* DUMP */ diff --git a/Src/Sound/MPEG/formats.h b/Src/Sound/MPEG/formats.h deleted file mode 100644 index ae0c9bf..0000000 --- a/Src/Sound/MPEG/formats.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * formats.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* formats.h - * - * Created by: tomislav uzelac Dec 22 1996 - */ -extern void wav_end(struct AUDIO_HEADER *header); -extern void wav_begin(void); - -#ifdef FORMATS -void wav_end(struct AUDIO_HEADER *header); -void wav_begin(void); -#endif /* FORMATS */ diff --git a/Src/Sound/MPEG/getbits.cpp b/Src/Sound/MPEG/getbits.cpp deleted file mode 100644 index 9ceab86..0000000 --- a/Src/Sound/MPEG/getbits.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * getbits.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* getbits.c bit level routines, input buffer - * - * Created by: tomislav uzelac Apr 1996 - * better synchronization, tomislav uzelac, Apr 23 1997 - */ -#include -#include -#include -#include "amp.h" -#include "amp_audio.h" -#include "formats.h" -#include "rtbuf.h" - -#define GETBITS -#include "getbits.h" - -static const char *fstart, *lstart; -static int offset, end, eof, lend; - -void MPEG_GetPlayPosition(int *playOffset, int *endOffset) -{ - if (in_file) - *playOffset = ftell(in_file); - else - *playOffset = offset; - *endOffset = end; -} - -void MPEG_SetPlayPosition(int playOffset, int endOffset) -{ - offset = playOffset; - end = endOffset; -} - -void m1setfile(const char *mstart, int mend) -{ - fstart = mstart; - offset = 0; - eof = 0; - end = mend; - lstart = NULL; -} - -void MPEG_SetLoop(const char *loop, int loopend) -{ - lstart = loop; - lend = loopend; -} - -int m1fread(unsigned char *buf, int size1, int size2, void *f) -{ - int total = size1 * size2; - - if (in_file) return fread(buf, size1, size2, (FILE *) f); - - //printf("fstart=%X, total=%X, offset=%X, end=%X\n", fstart, total, offset, end); - - // if past EOF - if ((total + offset) >= end) - { - if (lstart == NULL) - { - total = end - offset; - eof = 1; - } - else - { - // if past the end, do the xfer in 2 pieces - if ((total + offset) > end) - { - int temp = end - offset; // this part could be removed - if (temp > 0) // since music lenght - { // - memcpy(buf, fstart + offset, temp); // always multiple - buf += temp; // of 0x240 - total -= temp; // I let this as is in case - } // - - offset = 0; - fstart = lstart; - end = lend; - } - } - } - - memcpy(buf, fstart + offset, total); - - offset += total; - - return total; -} - -int m1feof(void *f) -{ - if (in_file) return feof((FILE *)f); - return eof; -} - -int m1fseek(void *f, int offs, int whence) -{ - if (in_file) return fseek((FILE *) f, offs, whence); - - switch (whence) - { - case SEEK_CUR: - if ((offset + offs) < 0) - { - offset = 0; - eof = 0; - return -1; - } - if ((offset + offs) > end) - { - offset = end; - eof = 1; - return end; - } - offset += offs; - eof = 0; - break; - } - return 0; -} - -/* - * buffer and bit manipulation functions *************************************** - */ -static inline int _fillbfr(unsigned int size) -{ - _bptr=0; - return get_input(_buffer, size); -} - -static inline int readsync() -{ - _bptr=0; - _buffer[0]=_buffer[1]; - _buffer[1]=_buffer[2]; - _buffer[2]=_buffer[3]; - return get_input(&_buffer[3],1); -} - -static inline unsigned int _getbits(int n) -{ -unsigned int pos,ret_value; - - pos = _bptr >> 3; - ret_value = _buffer[pos] << 24 | - _buffer[pos+1] << 16 | - _buffer[pos+2] << 8 | - _buffer[pos+3]; - ret_value <<= _bptr & 7; - ret_value >>= 32 - n; - _bptr += n; - return ret_value; -} - -int fillbfr(unsigned int advance) -{ -int overflow,retval; - - retval=get_input(&buffer[append], advance); - - if ( append + advance >= BUFFER_SIZE ) { - overflow = append + advance - BUFFER_SIZE; - memcpy (buffer,&buffer[BUFFER_SIZE], overflow); - if (overflow < 4) memcpy(&buffer[BUFFER_SIZE],buffer,4); - append = overflow; - } else { - if (append==0) memcpy(&buffer[BUFFER_SIZE],buffer,4); - append+=advance; - } - return retval; -} - -unsigned int getbits(int n) -{ - if (n) { - unsigned int pos,ret_value; - - pos = data >> 3; - ret_value = buffer[pos] << 24 | - buffer[pos+1] << 16 | - buffer[pos+2] << 8 | - buffer[pos+3]; - ret_value <<= data & 7; - ret_value >>= 32 - n; - - data += n; - data &= (8*BUFFER_SIZE)-1; - - return ret_value; - } else - return 0; -} - -/* - * header and side info parsing stuff ****************************************** - */ -static inline void parse_header(struct AUDIO_HEADER *header) -{ - header->ID=_getbits(1); - header->layer=_getbits(2); - header->protection_bit=_getbits(1); - header->bitrate_index=_getbits(4); - header->sampling_frequency=_getbits(2); - header->padding_bit=_getbits(1); - header->private_bit=_getbits(1); - header->mode=_getbits(2); - header->mode_extension=_getbits(2); - if (!header->mode) header->mode_extension=0; - header->copyright=_getbits(1); - header->original=_getbits(1); - header->emphasis=_getbits(2); -} - -static inline int header_sanity_check(struct AUDIO_HEADER *header) -{ - if ( header->layer==0 || - header->bitrate_index==15 || - header->sampling_frequency==3) return -1; - - /* an additional check to make shure that stuffing never gets mistaken - * for a syncword. This rules out some legal layer1 streams, but who - * cares about layer1 anyway :-). I must get this right sometime. - */ - if ( header->ID==1 && header->layer==3 && header->protection_bit==1) return -1; - return 0; -} - - -int gethdr(struct AUDIO_HEADER *header) -{ -int s,retval; -struct AUDIO_HEADER tmp; - - /* TODO: add a simple byte counter to check only first, say, 1024 - * bytes for a new header and then return GETHDR_SYN - */ - if ((retval=_fillbfr(4))!=0) return retval; - - for(;;) { - while ((s=_getbits(12)) != 0xfff) { - if (s==0xffe) { - parse_header(&tmp); - if (header_sanity_check(&tmp)==0) return GETHDR_NS; - } - if ((retval=readsync())!=0) return retval; - } - - parse_header(&tmp); - if (header_sanity_check(&tmp)!=0) { - if ((retval=readsync())!=0) return retval; - } else break; - } - - if (tmp.layer==3) return GETHDR_FL1; - /* if (tmp.layer==2) return GETHDR_FL2; */ - if (tmp.bitrate_index==0) return GETHDR_FF; - - //printf("layer: %d\n", tmp.layer); - //printf("sampling frequency: %d\n", tmp.sampling_frequency); - - memcpy(header,&tmp,sizeof(tmp)); - return 0; -} - -/* dummy function, to get crc out of the way -*/ -void getcrc() -{ - _fillbfr(2); - _getbits(16); -} - -/* sizes of side_info: - * MPEG1 1ch 17 2ch 32 - * MPEG2 1ch 9 2ch 17 - */ -void getinfo(struct AUDIO_HEADER *header,struct SIDE_INFO *info) -{ -int gr,ch,scfsi_band,region,window; -int nch; - if (header->mode==3) { - nch=1; - if (header->ID) { - _fillbfr(17); - info->main_data_begin=_getbits(9); - _getbits(5); - } else { - _fillbfr(9); - info->main_data_begin=_getbits(8); - _getbits(1); - } - } else { - nch=2; - if (header->ID) { - _fillbfr(32); - info->main_data_begin=_getbits(9); - _getbits(3); - } else { - _fillbfr(17); - info->main_data_begin=_getbits(8); - _getbits(2); - } - } - - if (header->ID) for (ch=0;chscfsi[ch][scfsi_band]=_getbits(1); - - for (gr=0;gr<(header->ID ? 2:1);gr++) - for (ch=0;chpart2_3_length[gr][ch]=_getbits(12); - info->big_values[gr][ch]=_getbits(9); - info->global_gain[gr][ch]=_getbits(8); - if (header->ID) info->scalefac_compress[gr][ch]=_getbits(4); - else info->scalefac_compress[gr][ch]=_getbits(9); - info->window_switching_flag[gr][ch]=_getbits(1); - - if (info->window_switching_flag[gr][ch]) { - info->block_type[gr][ch]=_getbits(2); - info->mixed_block_flag[gr][ch]=_getbits(1); - - for (region=0;region<2;region++) - info->table_select[gr][ch][region]=_getbits(5); - info->table_select[gr][ch][2]=0; - - for (window=0;window<3;window++) - info->subblock_gain[gr][ch][window]=_getbits(3); - } else { - for (region=0;region<3;region++) - info->table_select[gr][ch][region]=_getbits(5); - - info->region0_count[gr][ch]=_getbits(4); - info->region1_count[gr][ch]=_getbits(3); - info->block_type[gr][ch]=0; - } - - if (header->ID) info->preflag[gr][ch]=_getbits(1); - info->scalefac_scale[gr][ch]=_getbits(1); - info->count1table_select[gr][ch]=_getbits(1); - } - return; -} - -int dummy_getinfo(int n) -{ - n-=4; - if ( m1fseek(in_file,n,SEEK_CUR) != 0) - { - if (m1feof(in_file)) return GETHDR_EOF; - else return GETHDR_ERR; - } - return 0; -} - -int rewind_stream(int nbytes) -{ - nbytes+=5; - if (m1fseek(in_file, -nbytes, SEEK_CUR) != 0) { - /* what if we need to be at the very beginning? */ - nbytes--; - if (m1fseek(in_file, -nbytes, SEEK_CUR) != 0) return GETHDR_ERR; - } - return 0; -} - -static inline int get_input(unsigned char* bp, unsigned int size) -{ -#ifdef LINUX_REALTIME - return prefetch_get_input(bp,size); -#else /* LINUX_REALTIME */ - if ( m1fread( bp , 1, size, in_file) != size) - { - if (m1feof(in_file)) return GETHDR_EOF; - else return GETHDR_ERR; - } - return 0; -#endif /* LINUX_REALTIME */ -} diff --git a/Src/Sound/MPEG/getbits.h b/Src/Sound/MPEG/getbits.h deleted file mode 100644 index e1d65af..0000000 --- a/Src/Sound/MPEG/getbits.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * getbits.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* getbits.h - * - * Created by: tomislav uzelac Apr 1996 - */ - -/* gethdr() error codes -*/ -#define GETHDR_ERR 0x1 -#define GETHDR_NS 0x2 -#define GETHDR_FL1 0x4 -#define GETHDR_FL2 0x8 -#define GETHDR_FF 0x10 -#define GETHDR_SYN 0x20 -#define GETHDR_EOF 0x30 - -/* buffer for the 'bit reservoir' -*/ -#define BUFFER_SIZE 4096 -#define BUFFER_AUX 2048 -extern unsigned char buffer[]; -extern int append,data,f_bdirty,bclean_bytes; - -/* exports -*/ -extern int fillbfr(unsigned int advance); -extern unsigned int getbits(int n); -extern int gethdr(struct AUDIO_HEADER *header); -extern void getcrc(); -extern void getinfo(struct AUDIO_HEADER *header,struct SIDE_INFO *info); -extern int dummy_getinfo(int n); -extern int rewind_stream(int nbytes); - - -#ifdef GETBITS - -/* buffer, AUX is used in case of input buffer "overflow", and its contents - * are copied to the beginning of the buffer -*/ -unsigned char buffer[BUFFER_SIZE+BUFFER_AUX]; - -/* buffer pointers: append counts in bytes, data in bits - */ -int append,data; - -/* bit reservoir stuff. f_bdirty must be set to TRUE when starting play! - */ -int f_bdirty,bclean_bytes; - -/* internal buffer, _bptr holds the position in _bits_ - */ -static unsigned char _buffer[32]; -static int _bptr; - - -/* buffer and bit manipulation functions - */ -static inline int _fillbfr(unsigned int size); -static inline int readsync(); -static inline int get_input(unsigned char* bp, unsigned int size); -static inline unsigned int _getbits(int n); -int fillbfr(unsigned int advance); -unsigned int getbits(int n); -int dummy_getinfo(int n); -int rewind_stream(int nbytes); - -/* header and side info parsing stuff - */ -static inline void parse_header(struct AUDIO_HEADER *header); -static inline int header_sanity_check(struct AUDIO_HEADER *header); - -int gethdr(struct AUDIO_HEADER *header); -void getcrc(); -void getinfo(struct AUDIO_HEADER *header,struct SIDE_INFO *info); - -#endif /* GETBITS */ - diff --git a/Src/Sound/MPEG/getdata.cpp b/Src/Sound/MPEG/getdata.cpp deleted file mode 100644 index 28322ff..0000000 --- a/Src/Sound/MPEG/getdata.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * getdata.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* getdata.c scalefactor & huffman data extraction - * - * Created by: tomislav uzelac Apr 1996 - * Last modified by: tomislav uzelac Feb 27 1997 - */ -#include "amp.h" -#include "amp_audio.h" -#include "getbits.h" -#include "huffman.h" - -#define GETDATA -#include "getdata.h" - -/* layer3 scalefactor decoding. should we check for the number - * of bits read, just in case? - */ -int decode_scalefactors(struct SIDE_INFO *info,struct AUDIO_HEADER *header,int gr,int ch) -{ -int sfb,window; -int slen1,slen2; -int i1,i2,i=0; -int j,k; - if (header->ID==1) { - /* this is MPEG-1 scalefactors format, quite different than - * the MPEG-2 format. - */ - slen1=t_slen1[info->scalefac_compress[gr][ch]]; - slen2=t_slen2[info->scalefac_compress[gr][ch]]; - i1=3*slen1; - i2=3*slen2; - - if (info->window_switching_flag[gr][ch] && info->block_type[gr][ch]==2) { - if (info->mixed_block_flag[gr][ch]) { - for (sfb=0;sfb<8;sfb++) { - scalefac_l[gr][ch][sfb]=getbits(slen1); - i+=slen1; - } - for (sfb=3;sfb<6;sfb++) { - for (window=0;window<3;window++) - scalefac_s[gr][ch][sfb][window]=getbits(slen1); - i+=i1; - } - for (;sfb<12;sfb++) { - for (window=0;window<3;window++) - scalefac_s[gr][ch][sfb][window]=getbits(slen2); - i+=i2; - } - } else { /* !mixed_block_flag */ - for (sfb=0;sfb<6;sfb++) { - for (window=0;window<3;window++) - scalefac_s[gr][ch][sfb][window]=getbits(slen1); - i+=i1; - } - for (;sfb<12;sfb++) { - for (window=0;window<3;window++) - scalefac_s[gr][ch][sfb][window]=getbits(slen2); - i+=i2; - } - } - for (window=0;window<3;window++) - scalefac_s[gr][ch][12][window]=0; - } else { /* block_type!=2 */ - if ( !info->scfsi[ch][0] || !gr ) - for (sfb=0;sfb<6;sfb++) { - scalefac_l[gr][ch][sfb]=getbits(slen1); - i+=slen1; - } - else for (sfb=0;sfb<6;sfb++) { - scalefac_l[1][ch][sfb]=scalefac_l[0][ch][sfb]; - } - if ( !info->scfsi[ch][1] || !gr ) - for (sfb=6;sfb<11;sfb++) { - scalefac_l[gr][ch][sfb]=getbits(slen1); - i+=slen1; - } - else for (sfb=6;sfb<11;sfb++) { - scalefac_l[1][ch][sfb]=scalefac_l[0][ch][sfb]; - } - if ( !info->scfsi[ch][2] || !gr ) - for (sfb=11;sfb<16;sfb++) { - scalefac_l[gr][ch][sfb]=getbits(slen2); - i+=slen2; - } - else for (sfb=11;sfb<16;sfb++) { - scalefac_l[1][ch][sfb]=scalefac_l[0][ch][sfb]; - } - if ( !info->scfsi[ch][3] || !gr ) - for (sfb=16;sfb<21;sfb++) { - scalefac_l[gr][ch][sfb]=getbits(slen2); - i+=slen2; - } - else for (sfb=16;sfb<21;sfb++) { - scalefac_l[1][ch][sfb]=scalefac_l[0][ch][sfb]; - } - scalefac_l[gr][ch][21]=0; - } - } else { /* ID==0 */ - int index=0,index2,spooky_index; - int slen[6],nr_of_sfb[6]; /* actually, there's four of each, not five, labelled 1 through 4, but - * what's a word of storage compared to one's sanity. so [0] is irellevant. - */ - - /* ok, so we got 3 indexes. - * spooky_index - indicates whether we use the normal set of slen eqs and nr_of_sfb tables - * or the one for the right channel of intensity stereo coded frame - * index - corresponds to the value of scalefac_compress, as listed in the standard - * index2 - 0 for long blocks, 1 for short wo/ mixed_block_flag, 2 for short with it - */ - if ( (header->mode_extension==1 || header->mode_extension==3) && ch==1) { /* right ch... */ - int int_scalefac_compress=info->scalefac_compress[0][ch]>>1; - intensity_scale=info->scalefac_compress[0][1]&1; - spooky_index=1; - if (int_scalefac_compress < 180) { - slen[1]=int_scalefac_compress/36; - slen[2]=(int_scalefac_compress%36)/6; - slen[3]=(int_scalefac_compress%36)%6; - slen[4]=0; - info->preflag[0][ch]=0; - index=0; - } - if ( 180 <= int_scalefac_compress && int_scalefac_compress < 244) { - slen[1]=((int_scalefac_compress-180)%64)>>4; - slen[2]=((int_scalefac_compress-180)%16)>>2; - slen[3]=(int_scalefac_compress-180)%4; - slen[4]=0; - info->preflag[0][ch]=0; - index=1; - } - if ( 244 <= int_scalefac_compress && int_scalefac_compress < 255) { - slen[1]=(int_scalefac_compress-244)/3; - slen[2]=(int_scalefac_compress-244)%3; - slen[3]=0; - slen[4]=0; - info->preflag[0][ch]=0; - index=2; - } - } else { /* the usual */ - spooky_index=0; - if (info->scalefac_compress[0][ch] < 400) { - slen[1]=(info->scalefac_compress[0][ch]>>4)/5; - slen[2]=(info->scalefac_compress[0][ch]>>4)%5; - slen[3]=(info->scalefac_compress[0][ch]%16)>>2; - slen[4]=info->scalefac_compress[0][ch]%4; - info->preflag[0][ch]=0; - index=0; - } - if (info->scalefac_compress[0][ch] >= 400 && info->scalefac_compress[0][ch] < 500) { - slen[1]=((info->scalefac_compress[0][ch]-400)>>2)/5; - slen[2]=((info->scalefac_compress[0][ch]-400)>>2)%5; - slen[3]=(info->scalefac_compress[0][ch]-400)%4; - slen[4]=0; - info->preflag[0][ch]=0; - index=1; - } - if (info->scalefac_compress[0][ch] >= 500 && info->scalefac_compress[0][ch] < 512) { - slen[1]=(info->scalefac_compress[0][ch]-500)/3; - slen[2]=(info->scalefac_compress[0][ch]-500)%3; - slen[3]=0; - slen[4]=0; - info->preflag[0][ch]=1; - index=2; - } - } - - if (info->window_switching_flag[0][ch] && info->block_type[0][ch]==2) - if (info->mixed_block_flag[0][ch]) index2=2; - else index2=1; - else index2=0; - - for (j=1;j<=4;j++) nr_of_sfb[j]=spooky_table[spooky_index][index][index2][j-1]; - - /* now we'll do some actual scalefactor extraction, and a little more. - * for each scalefactor band we'll set the value of is_max to indicate - * illegal is_pos, since with MPEG2 it's not 'hardcoded' to 7. - */ - if (!info->window_switching_flag[0][ch] || (info->window_switching_flag[0][ch] && info->block_type[0][ch]!=2)) { - sfb=0; - for (j=1;j<=4;j++) - for (k=0;kblock_type[0][ch]==2) - { - if (!info->mixed_block_flag[0][ch]) { - sfb=0; - for (j=1;j<=4;j++) - for (k=0;k. - **/ - -/* - * getdata.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* getdata.h - * - * tomislav uzelac Apr 1996 - */ - -extern int decode_scalefactors(struct SIDE_INFO *info,struct AUDIO_HEADER *header,int gr,int ch); - -extern int is_max[21]; -extern int intensity_scale; - -#ifdef GETDATA - -static char t_slen1[16]={0,0,0,0,3,1,1,1,2,2,2,3,3,3,4,4}; -static char t_slen2[16]={0,1,2,3,0,1,2,3,1,2,3,1,2,3,2,3}; - -int is_max[21]; /* the maximum value of is_pos. for short blocks is_max[sfb=0] == is_max[6], - * it's sloppy but i'm sick of waisting storage. blaah... - */ -int intensity_scale; - -int decode_scalefactors(struct SIDE_INFO *info,struct AUDIO_HEADER *header,int gr,int ch); - -/* my implementation of MPEG2 scalefactor decoding is, admitably, horrible - * anyway, just take a look at pg.18 of MPEG2 specs, and you'll know what - * this is all about - */ -static const char spooky_table[2][3][3][4]={ -{ -{ {6,5,5,5}, {9,9,9,9}, {6,9,9,9} }, -{ {6,5,7,3}, {9,9,12,6}, {6,9,12,6}}, -{ {11,10,0,0}, {18,18,0,0}, {15,18,0,0}} -}, -{ -{ {7,7,7,0}, {12,12,12,0}, {6,15,12,0}}, -{ {6,6,6,3}, {12,9,9,6}, {6,12,9,6}}, -{ {8,8,5,0}, {15,12,9,0}, {6,18,9,0}} -}}; - -#endif /* GETDATA */ diff --git a/Src/Sound/MPEG/huffman.cpp b/Src/Sound/MPEG/huffman.cpp deleted file mode 100644 index b521ac7..0000000 --- a/Src/Sound/MPEG/huffman.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * huffman.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* huffman.c huffman decoding - * - * Created by: tomislav uzelac Mar,Apr 1996 - * Last modified by: tomislav uzelac Mar 8 97 - */ -#include -#include "amp_audio.h" -#include "getbits.h" - -#define HUFFMAN -#include "huffman.h" - -#include "Supermodel.h" - -static inline unsigned int viewbits(int n) -{ -unsigned int pos,ret_value; - - pos = ::data >> 3; - ret_value = buffer[pos] << 24 | - buffer[pos+1] << 16 | - buffer[pos+2] << 8 | - buffer[pos+3]; - ret_value <<= ::data & 7; - ret_value >>= 32 - n; - - return ret_value; -} - -static inline void sackbits(int n) -{ - ::data += n; - ::data &= 8*BUFFER_SIZE-1; -} - -/* huffman_decode() is supposed to be faster now - * decodes one codeword and returns no. of bits - */ -static inline int huffman_decode(int tbl,int *x,int *y) -{ -unsigned int chunk; -register unsigned int *h_tab; -register unsigned int lag; -register unsigned int half_lag; -int len; - - h_tab=tables[tbl]; - chunk=viewbits(19); - - h_tab += h_cue[tbl][chunk >> (19-NC_O)]; - - len=(*h_tab>>8)&0x1f; - - /* check for an immediate hit, so we can decode those short codes very fast - */ - if ((*h_tab>>(32-len)) != (chunk>>(19-len))) { - if (chunk >> (19-NC_O) < N_CUE-1) - lag=(h_cue[tbl][(chunk >> (19-NC_O))+1] - - h_cue[tbl][chunk >> (19-NC_O)]); - else { - /* we strongly depend on h_cue[N_CUE-1] to point to - * the last entry in the huffman table, so we should - * not get here anyway. if it didn't, we'd have to - * have another table with huffman tables lengths, and - * it would be a mess. just in case, scream&shout. - */ - - ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); // h_cue clobbered - exit (-1); - } - chunk <<= 32-19; - chunk |= 0x1ff; - - half_lag = lag >> 1; - - h_tab += half_lag; - lag -= half_lag; - - while (lag > 1) { - half_lag = lag >> 1; - - if (*h_tab < chunk) - h_tab += half_lag; - else - h_tab -= half_lag; - - lag -= half_lag; - } - - len=(*h_tab>>8)&0x1f; - if ((*h_tab>>(32-len)) != (chunk>>(32-len))) { - if (*h_tab > chunk) - h_tab--; - else - h_tab++; - - len=(*h_tab>>8)&0x1f; - } - } - sackbits(len); - *x=(*h_tab>>4)&0xf; - *y=*h_tab&0xf; - return len; -} - -static inline int _qsign(int x,int *q) -{ -int ret_value=0,i; - for (i=3;i>=0;i--) - if ((x>>i) & 1) { - if (getbits(1)) *q++=-1; - else *q++=1; - ret_value++; - } - else *q++=0; - return ret_value; -} - -int decode_huffman_data(struct SIDE_INFO *info,int gr,int ch,int ssize) -{ -int l,i,cnt,x,y; -int q[4],r[3],linbits[3],tr[4]={0,0,0,0}; -int big_value = info->big_values[gr][ch] << 1; - - for (l=0;l<3;l++) { - tr[l]=info->table_select[gr][ch][l]; - linbits[l]=t_linbits[info->table_select[gr][ch][l]]; - } - - tr[3]=32+info->count1table_select[gr][ch]; - - /* we have to be careful here because big_values are not necessarily - * aligned with sfb boundaries - */ - if (!info->window_switching_flag[gr][ch] && info->block_type[gr][ch]==0) { - - /* this code needed some cleanup - */ - r[0]=t_l[info->region0_count[gr][ch]] + 1; - if (r[0] > big_value) - r[0]=r[1]=big_value; - else { - r[1]=t_l[ info->region0_count[gr][ch] + info->region1_count[gr][ch] + 1 ] + 1; - if (r[1] > big_value) - r[1]=big_value; - } - r[2]=big_value; - - } else { - - if (info->block_type[gr][ch]==2 && info->mixed_block_flag[gr][ch]==0) - r[0]=3*(t_s[2]+1); - else - r[0]=t_l[7]+1; - - if (r[0] > big_value) - r[0]=big_value; - - r[1]=r[2]=big_value; - } - - l=0; cnt=0; - for (i=0;i<3;i++) { - for (;l0) { - x+=getbits(j); - cnt+=j; - } - if (x) { - if (getbits(1)) x=-x; - cnt++; - } - if (y==15 && j>0) { - y+=getbits(j); - cnt+=j; - } - if (y) { - if (getbits(1)) y=-y; - cnt++; - } - - is[ch][l]=x; - is[ch][l+1]=y; - } - } - while ((cnt < info->part2_3_length[gr][ch]-ssize) && (l<576)) { - cnt+=huffman_decode(tr[3],&x,&y); - cnt+=_qsign(x,q); - for (i=0;i<4;i++) is[ch][l+i]=q[i]; /* ziher je ziher, is[578]*/ - l+=4; - } - - /* set position to start of the next gr/ch - */ - if (cnt != info->part2_3_length[gr][ch] - ssize ) { - ::data-=cnt-(info->part2_3_length[gr][ch] - ssize); - ::data&= 8*BUFFER_SIZE - 1; - } - if (l<576) non_zero[ch]=l; - else non_zero[ch]=576; - /* zero out everything else - */ - for (;l<576;l++) is[ch][l]=0; - return 1; -} diff --git a/Src/Sound/MPEG/huffman.h b/Src/Sound/MPEG/huffman.h deleted file mode 100644 index 0566f55..0000000 --- a/Src/Sound/MPEG/huffman.h +++ /dev/null @@ -1,287 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * huffman.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* huffman.h - * - * Created by: tomislav uzelac Mar 1996 - * Last edited by: tomislav uzelac Mar 8 97 - */ - -extern int decode_huffman_data(struct SIDE_INFO *info,int gr,int ch,int ssize); - -extern int non_zero[2]; -extern int t_linbits[32]; - -#ifdef HUFFMAN - -static inline unsigned int viewbits(int n); -static inline void sackbits(int n); -static inline int huffman_decode(int tbl,int *x,int *y); -static inline int _qsign(int x,int *q); -int decode_huffman_data(struct SIDE_INFO *info,int gr,int ch,int ssize); - -int non_zero[2]; /* this is 2*bigvalues+4*count1, i guess...*/ - -#define N_CUE 16 -#define NC_O 4 - -int t_linbits[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13}; - -/* these are the huffman tables, rearranged for lookup -*/ -unsigned int h0[1]={0x0}; -unsigned int h1[4]={0x311, 0x20000301, 0x40000210, 0x80000100}; -unsigned int h2[9]={0x622, 0x4000602, 0x8000512, 0x10000521, 0x18000520, 0x20000311, 0x40000301, 0x60000310, - 0x80000100}; -unsigned int h3[9]={ 0x622, 0x4000602, 0x8000512, 0x10000521, 0x18000520, 0x20000310, 0x40000211, 0x80000201, - 0xc0000200}; -unsigned int h5[16]={0x833, 0x1000823, 0x2000732, 0x4000631, 0x8000713, 0xa000703, 0xc000730, 0xe000722, - 0x10000612, 0x14000621, 0x18000602, 0x1c000620, 0x20000311, 0x40000301, 0x60000310, 0x80000100}; -unsigned int h6[16]={0x733, 0x2000703, 0x4000623, 0x8000632, 0xc000630, 0x10000513, 0x18000531, 0x20000522, - 0x28000502, 0x30000412, 0x40000421, 0x50000420, 0x60000301, 0x80000211, 0xc0000310, 0xe0000300}; -unsigned int h7[36]={ 0xa55, 0x400a45, 0x800a54, 0xc00a53, 0x1000935, 0x1800944, 0x2000925, 0x2800952, - 0x3000815, 0x4000851, 0x5000905, 0x5800934, 0x6000850, 0x7000943, 0x7800933, 0x8000824, - 0x9000842, 0xa000714, 0xc000741, 0xe000740, 0x10000804, 0x11000823, 0x12000832, 0x13000803, - 0x14000713, 0x16000731, 0x18000730, 0x1a000722, 0x1c000612, 0x20000521, 0x28000602, 0x2c000620, - 0x30000411, 0x40000301, 0x60000310, 0x80000100}; -unsigned int h8[36]={0xb55, 0x200b54, 0x400a45, 0x800953, 0x1000a35, 0x1400a44, 0x1800925, 0x2000952, - 0x2800905, 0x3000815, 0x4000851, 0x5000934, 0x5800943, 0x6000950, 0x6800933, 0x7000824, - 0x8000842, 0x9000814, 0xa000741, 0xc000804, 0xd000840, 0xe000823, 0xf000832, 0x10000813, - 0x11000831, 0x12000803, 0x13000830, 0x14000622, 0x18000602, 0x1c000620, 0x20000412, 0x30000421, - 0x40000211, 0x80000301, 0xa0000310, 0xc0000200}; -unsigned int h9[36]={ 0x955, 0x800945, 0x1000835, 0x2000853, 0x3000954, 0x3800905, 0x4000844, 0x5000825, - 0x6000852, 0x7000815, 0x8000751, 0xa000734, 0xc000743, 0xe000850, 0xf000804, 0x10000724, - 0x12000742, 0x14000733, 0x16000740, 0x18000614, 0x1c000641, 0x20000623, 0x24000632, 0x28000513, - 0x30000531, 0x38000603, 0x3c000630, 0x40000522, 0x48000502, 0x50000412, 0x60000421, 0x70000420, - 0x80000311, 0xa0000301, 0xc0000310, 0xe0000300}; -unsigned int h10[64]={ 0xb77, 0x200b67, 0x400b76, 0x600b57, 0x800b75, 0xa00b66, 0xc00a47, 0x1000a74, - 0x1400a56, 0x1800a65, 0x1c00a37, 0x2000a73, 0x2400a46, 0x2800b55, 0x2a00b54, 0x2c00a63, - 0x3000927, 0x3800972, 0x4000a64, 0x4400a07, 0x4800970, 0x5000962, 0x5800a45, 0x5c00a35, - 0x6000906, 0x6800a53, 0x6c00a44, 0x7000817, 0x8000871, 0x9000936, 0x9800926, 0xa000a25, - 0xa400a52, 0xa800915, 0xb000951, 0xb800a34, 0xbc00a43, 0xc000816, 0xd000861, 0xe000860, - 0xf000905, 0xf800950, 0x10000924, 0x10800942, 0x11000933, 0x11800904, 0x12000814, 0x13000841, - 0x14000840, 0x15000823, 0x16000832, 0x17000803, 0x18000713, 0x1a000731, 0x1c000730, 0x1e000722, - 0x20000612, 0x24000621, 0x28000602, 0x2c000620, 0x30000411, 0x40000301, 0x60000310, 0x80000100}; -unsigned int h11[64]={ 0xa77, 0x400a67, 0x800a76, 0xc00a75, 0x1000a66, 0x1400a47, 0x1800a74, 0x1c00b57, - 0x1e00b55, 0x2000a56, 0x2400a65, 0x2800937, 0x3000973, 0x3800946, 0x4000a45, 0x4400a54, - 0x4800a35, 0x4c00a53, 0x5000827, 0x6000872, 0x7000964, 0x7800907, 0x8000771, 0xa000817, - 0xb000870, 0xc000836, 0xd000863, 0xe000860, 0xf000944, 0xf800925, 0x10000952, 0x10800905, - 0x11000815, 0x12000762, 0x14000826, 0x15000806, 0x16000716, 0x18000761, 0x1a000851, 0x1b000834, - 0x1c000850, 0x1d000943, 0x1d800933, 0x1e000824, 0x1f000842, 0x20000814, 0x21000841, 0x22000804, - 0x23000840, 0x24000723, 0x26000732, 0x28000613, 0x2c000631, 0x30000703, 0x32000730, 0x34000622, - 0x38000521, 0x40000412, 0x50000502, 0x58000520, 0x60000311, 0x80000301, 0xa0000310, 0xc0000200}; -unsigned int h12[64]={ 0xa77, 0x400a67, 0x800976, 0x1000957, 0x1800975, 0x2000966, 0x2800947, 0x3000974, - 0x3800965, 0x4000856, 0x5000837, 0x6000973, 0x6800955, 0x7000827, 0x8000872, 0x9000846, - 0xa000864, 0xb000817, 0xc000871, 0xd000907, 0xd800970, 0xe000836, 0xf000863, 0x10000845, - 0x11000854, 0x12000844, 0x13000906, 0x13800905, 0x14000726, 0x16000762, 0x18000761, 0x1a000816, - 0x1b000860, 0x1c000835, 0x1d000853, 0x1e000825, 0x1f000852, 0x20000715, 0x22000751, 0x24000734, - 0x26000743, 0x28000850, 0x29000804, 0x2a000724, 0x2c000742, 0x2e000714, 0x30000633, 0x34000641, - 0x38000623, 0x3c000632, 0x40000740, 0x42000703, 0x44000630, 0x48000513, 0x50000531, 0x58000522, - 0x60000412, 0x70000421, 0x80000502, 0x88000520, 0x90000400, 0xa0000311, 0xc0000301, 0xe0000310}; -unsigned int h13[256]={ - 0x13fe, 0x33fc, 0x52fd, 0x91ed, 0x110ff, 0x210ef, 0x310df, 0x410ee, - 0x510cf, 0x610de, 0x710bf, 0x810fb, 0x910ce, 0xa10dc, 0xb11af, 0xb91e9, - 0xc0fec, 0xe0fdd, 0x1010fa, 0x1110cd, 0x120fbe, 0x140feb, 0x160f9f, 0x180ff9, - 0x1a0fea, 0x1c0fbd, 0x1e0fdb, 0x200f8f, 0x220ff8, 0x240fcc, 0x2610ae, 0x27109e, - 0x280f8e, 0x2a107f, 0x2b107e, 0x2c0ef7, 0x300eda, 0x340fad, 0x360fbc, 0x380fcb, - 0x3a0ff6, 0x3c0e6f, 0x400ee8, 0x440e5f, 0x480e9d, 0x4c0ed9, 0x500ef5, 0x540ee7, - 0x580eac, 0x5c0ebb, 0x600e4f, 0x640ef4, 0x680fca, 0x6a0fe6, 0x6c0ef3, 0x700d3f, - 0x780e8d, 0x7c0ed8, 0x800d2f, 0x880df2, 0x900e6e, 0x940e9c, 0x980d0f, 0xa00ec9, - 0xa40e5e, 0xa80dab, 0xb00e7d, 0xb40ed7, 0xb80d4e, 0xc00ec8, 0xc40ed6, 0xc80d3e, - 0xd00db9, 0xd80e9b, 0xdc0eaa, 0xe00c1f, 0xf00cf1, 0x1000cf0, 0x1100dba, 0x1180de5, - 0x1200de4, 0x1280d8c, 0x1300d6d, 0x1380de3, 0x1400ce2, 0x1500d2e, 0x1580d0e, 0x1600c1e, - 0x1700ce1, 0x1800de0, 0x1880d5d, 0x1900dd5, 0x1980d7c, 0x1a00dc7, 0x1a80d4d, 0x1b00d8b, - 0x1b80db8, 0x1c00dd4, 0x1c80d9a, 0x1d00da9, 0x1d80d6c, 0x1e00cc6, 0x1f00c3d, 0x2000dd3, - 0x2080d7b, 0x2100c2d, 0x2200cd2, 0x2300c1d, 0x2400cb7, 0x2500d5c, 0x2580dc5, 0x2600d99, - 0x2680d7a, 0x2700cc3, 0x2800da7, 0x2880d97, 0x2900c4b, 0x2a00bd1, 0x2c00c0d, 0x2d00cd0, - 0x2e00c8a, 0x2f00ca8, 0x3000c4c, 0x3100cc4, 0x3200c6b, 0x3300cb6, 0x3400b3c, 0x3600b2c, - 0x3800bc2, 0x3a00b5b, 0x3c00cb5, 0x3d00c89, 0x3e00b1c, 0x4000bc1, 0x4200c98, 0x4300c0c, - 0x4400bc0, 0x4600cb4, 0x4700c6a, 0x4800ca6, 0x4900c79, 0x4a00b3b, 0x4c00bb3, 0x4e00c88, - 0x4f00c5a, 0x5000b2b, 0x5200ca5, 0x5300c69, 0x5400ba4, 0x5600c78, 0x5700c87, 0x5800b94, - 0x5a00c77, 0x5b00c76, 0x5c00ab2, 0x6000a1b, 0x6400ab1, 0x6800b0b, 0x6a00bb0, 0x6c00b96, - 0x6e00b4a, 0x7000b3a, 0x7200ba3, 0x7400b59, 0x7600b95, 0x7800a2a, 0x7c00aa2, 0x8000a1a, - 0x8400aa1, 0x8800b0a, 0x8a00b68, 0x8c00aa0, 0x9000b86, 0x9200b49, 0x9400a93, 0x9800b39, - 0x9a00b58, 0x9c00b85, 0x9e00b67, 0xa000a29, 0xa400a92, 0xa800b57, 0xaa00b75, 0xac00a38, - 0xb000a83, 0xb400b66, 0xb600b47, 0xb800b74, 0xba00b56, 0xbc00b65, 0xbe00b73, 0xc000919, - 0xc800991, 0xd000a09, 0xd400a90, 0xd800a48, 0xdc00a84, 0xe000a72, 0xe400b46, 0xe600b64, - 0xe800928, 0xf000982, 0xf800918, 0x10000a37, 0x10400a27, 0x10800917, 0x11000971, 0x11800a55, - 0x11c00a07, 0x12000a70, 0x12400a36, 0x12800a63, 0x12c00a45, 0x13000a54, 0x13400a26, 0x13800a62, - 0x13c00a35, 0x14000881, 0x15000908, 0x15800980, 0x16000916, 0x16800961, 0x17000906, 0x17800960, - 0x18000a53, 0x18400a44, 0x18800925, 0x19000952, 0x19800905, 0x1a000815, 0x1b000851, 0x1c000934, - 0x1c800943, 0x1d000950, 0x1d800924, 0x1e000942, 0x1e800933, 0x1f000814, 0x20000741, 0x22000804, - 0x23000840, 0x24000823, 0x25000832, 0x26000713, 0x28000731, 0x2a000703, 0x2c000730, 0x2e000722, - 0x30000612, 0x34000621, 0x38000602, 0x3c000620, 0x40000411, 0x50000401, 0x60000310, 0x80000100}; -unsigned int h15[256]={ 0xdff, 0x80def, 0x100dfe, 0x180ddf, 0x200cee, 0x300dfd, 0x380dcf, 0x400dfc, - 0x480dde, 0x500ded, 0x580dbf, 0x600cfb, 0x700dce, 0x780dec, 0x800cdd, 0x900caf, - 0xa00cfa, 0xb00cbe, 0xc00ceb, 0xd00ccd, 0xe00cdc, 0xf00c9f, 0x1000cf9, 0x1100cea, - 0x1200cbd, 0x1300cdb, 0x1400c8f, 0x1500cf8, 0x1600ccc, 0x1700c9e, 0x1800ce9, 0x1900c7f, - 0x1a00cf7, 0x1b00cad, 0x1c00cda, 0x1d00cbc, 0x1e00c6f, 0x1f00dae, 0x1f80d0f, 0x2000bcb, - 0x2200bf6, 0x2400c8e, 0x2500ce8, 0x2600c5f, 0x2700c9d, 0x2800bf5, 0x2a00b7e, 0x2c00be7, - 0x2e00bac, 0x3000bca, 0x3200bbb, 0x3400cd9, 0x3500c8d, 0x3600b4f, 0x3800bf4, 0x3a00b3f, - 0x3c00bf3, 0x3e00bd8, 0x4000be6, 0x4200b2f, 0x4400bf2, 0x4600c6e, 0x4700cf0, 0x4800b1f, - 0x4a00bf1, 0x4c00b9c, 0x4e00bc9, 0x5000b5e, 0x5200bab, 0x5400bba, 0x5600be5, 0x5800b7d, - 0x5a00bd7, 0x5c00b4e, 0x5e00be4, 0x6000b8c, 0x6200bc8, 0x6400b3e, 0x6600b6d, 0x6800bd6, - 0x6a00be3, 0x6c00b9b, 0x6e00bb9, 0x7000b2e, 0x7200baa, 0x7400be2, 0x7600b1e, 0x7800be1, - 0x7a00c0e, 0x7b00ce0, 0x7c00b5d, 0x7e00bd5, 0x8000b7c, 0x8200bc7, 0x8400b4d, 0x8600b8b, - 0x8800ad4, 0x8c00bb8, 0x8e00b9a, 0x9000ba9, 0x9200b6c, 0x9400bc6, 0x9600b3d, 0x9800ad3, - 0x9c00ad2, 0xa000b2d, 0xa200b0d, 0xa400a1d, 0xa800a7b, 0xac00ab7, 0xb000ad1, 0xb400b5c, - 0xb600bd0, 0xb800ac5, 0xbc00a8a, 0xc000aa8, 0xc400a4c, 0xc800ac4, 0xcc00a6b, 0xd000ab6, - 0xd400b99, 0xd600b0c, 0xd800a3c, 0xdc00ac3, 0xe000a7a, 0xe400aa7, 0xe800aa6, 0xec00bc0, - 0xee00b0b, 0xf0009c2, 0xf800a2c, 0xfc00a5b, 0x10000ab5, 0x10400a1c, 0x10800a89, 0x10c00a98, - 0x11000ac1, 0x11400a4b, 0x11800ab4, 0x11c00a6a, 0x12000a3b, 0x12400a79, 0x128009b3, 0x13000a97, - 0x13400a88, 0x13800a2b, 0x13c00a5a, 0x140009b2, 0x14800aa5, 0x14c00a1b, 0x150009b1, 0x15800ab0, - 0x15c00a69, 0x16000a96, 0x16400a4a, 0x16800aa4, 0x16c00a78, 0x17000a87, 0x17400a3a, 0x178009a3, - 0x18000959, 0x18800995, 0x1900092a, 0x198009a2, 0x1a00091a, 0x1a8009a1, 0x1b000a0a, 0x1b400aa0, - 0x1b800968, 0x1c000986, 0x1c800949, 0x1d000994, 0x1d800939, 0x1e000993, 0x1e800a77, 0x1ec00a09, - 0x1f000958, 0x1f800985, 0x20000929, 0x20800967, 0x21000976, 0x21800992, 0x22000891, 0x23000919, - 0x23800990, 0x24000948, 0x24800984, 0x25000957, 0x25800975, 0x26000938, 0x26800983, 0x27000966, - 0x27800947, 0x28000828, 0x29000882, 0x2a000818, 0x2b000881, 0x2c000974, 0x2c800908, 0x2d000980, - 0x2d800956, 0x2e000965, 0x2e800937, 0x2f000973, 0x2f800946, 0x30000827, 0x31000872, 0x32000864, - 0x33000817, 0x34000855, 0x35000871, 0x36000907, 0x36800970, 0x37000836, 0x38000863, 0x39000845, - 0x3a000854, 0x3b000826, 0x3c000862, 0x3d000816, 0x3e000906, 0x3e800960, 0x3f000835, 0x40000761, - 0x42000853, 0x43000844, 0x44000725, 0x46000752, 0x48000715, 0x4a000751, 0x4c000805, 0x4d000850, - 0x4e000734, 0x50000743, 0x52000724, 0x54000742, 0x56000733, 0x58000641, 0x5c000714, 0x5e000704, - 0x60000623, 0x64000632, 0x68000740, 0x6a000703, 0x6c000613, 0x70000631, 0x74000630, 0x78000522, - 0x80000512, 0x88000521, 0x90000502, 0x98000520, 0xa0000311, 0xc0000401, 0xd0000410, 0xe0000300}; -unsigned int h16[256]={ 0xbef, 0x200bfe, 0x400bdf, 0x600bfd, 0x800bcf, 0xa00bfc, 0xc00bbf, 0xe00bfb, - 0x1000aaf, 0x1400bfa, 0x1600b9f, 0x1800bf9, 0x1a00bf8, 0x1c00a8f, 0x2000a7f, 0x2400af7, - 0x2800a6f, 0x2c00af6, 0x30008ff, 0x4000a5f, 0x4400af5, 0x480094f, 0x50009f4, 0x58009f3, - 0x60009f0, 0x6800a3f, 0x6c010ce, 0x6c111ec, 0x6c191dd, 0x6c20fde, 0x6c40fe9, 0x6c610ea, - 0x6c710d9, 0x6c80eee, 0x6cc0fed, 0x6ce0feb, 0x6d00ebe, 0x6d40ecd, 0x6d80fdc, 0x6da0fdb, - 0x6dc0eae, 0x6e00ecc, 0x6e40fad, 0x6e60fda, 0x6e80f7e, 0x6ea0fac, 0x6ec0eca, 0x6f00fc9, - 0x6f20f7d, 0x6f40e5e, 0x6f80dbd, 0x70008f2, 0x800092f, 0x880090f, 0x900081f, 0xa0008f1, - 0xb000d9e, 0xb080ebc, 0xb0c0ecb, 0xb100e8e, 0xb140ee8, 0xb180e9d, 0xb1c0ee7, 0xb200ebb, - 0xb240e8d, 0xb280ed8, 0xb2c0e6e, 0xb300de6, 0xb380d9c, 0xb400eab, 0xb440eba, 0xb480ee5, - 0xb4c0ed7, 0xb500d4e, 0xb580ee4, 0xb5c0e8c, 0xb600dc8, 0xb680d3e, 0xb700d6d, 0xb780ed6, - 0xb7c0e9b, 0xb800eb9, 0xb840eaa, 0xb880de1, 0xb900dd4, 0xb980eb8, 0xb9c0ea9, 0xba00d7b, - 0xba80eb7, 0xbac0ed0, 0xbb00ce3, 0xbc00d0e, 0xbc80de0, 0xbd00d5d, 0xbd80dd5, 0xbe00d7c, - 0xbe80dc7, 0xbf00d4d, 0xbf80d8b, 0xc000d9a, 0xc080d6c, 0xc100dc6, 0xc180d3d, 0xc200d5c, - 0xc280dc5, 0xc300c0d, 0xc400d8a, 0xc480da8, 0xc500d99, 0xc580d4c, 0xc600db6, 0xc680d7a, - 0xc700c3c, 0xc800d5b, 0xc880d89, 0xc900c1c, 0xca00cc0, 0xcb00d98, 0xcb80d79, 0xcc00be2, - 0xce00c2e, 0xcf00c1e, 0xd000cd3, 0xd100c2d, 0xd200cd2, 0xd300cd1, 0xd400c3b, 0xd500d97, - 0xd580d88, 0xd600b1d, 0xd800cc4, 0xd900c6b, 0xda00cc3, 0xdb00ca7, 0xdc00b2c, 0xde00cc2, - 0xdf00cb5, 0xe000cc1, 0xe100c0c, 0xe200c4b, 0xe300cb4, 0xe400c6a, 0xe500ca6, 0xe600bb3, - 0xe800c5a, 0xe900ca5, 0xea00b2b, 0xec00bb2, 0xee00b1b, 0xf000bb1, 0xf200c0b, 0xf300cb0, - 0xf400c69, 0xf500c96, 0xf600c4a, 0xf700ca4, 0xf800c78, 0xf900c87, 0xfa00ba3, 0xfc00c3a, - 0xfd00c59, 0xfe00b2a, 0x10000c95, 0x10100c68, 0x10200ba1, 0x10400c86, 0x10500c77, 0x10600b94, - 0x10800c49, 0x10900c57, 0x10a00b67, 0x10c00aa2, 0x11000a1a, 0x11400b0a, 0x11600ba0, 0x11800b39, - 0x11a00b93, 0x11c00b58, 0x11e00b85, 0x12000a29, 0x12400a92, 0x12800b76, 0x12a00b09, 0x12c00a19, - 0x13000a91, 0x13400b90, 0x13600b48, 0x13800b84, 0x13a00b75, 0x13c00b38, 0x13e00b83, 0x14000b66, - 0x14200b28, 0x14400a82, 0x14800b47, 0x14a00b74, 0x14c00a18, 0x15000a81, 0x15400a80, 0x15800b08, - 0x15a00b56, 0x15c00a37, 0x16000a73, 0x16400b65, 0x16600b46, 0x16800a27, 0x16c00a72, 0x17000b64, - 0x17200b55, 0x17400a07, 0x17800917, 0x18000971, 0x18800a70, 0x18c00a36, 0x19000a63, 0x19400a45, - 0x19800a54, 0x19c00a26, 0x1a000962, 0x1a800916, 0x1b000961, 0x1b800a06, 0x1bc00a60, 0x1c000953, - 0x1c800a35, 0x1cc00a44, 0x1d000925, 0x1d800952, 0x1e000851, 0x1f000915, 0x1f800905, 0x20000934, - 0x20800943, 0x21000950, 0x21800924, 0x22000942, 0x22800933, 0x23000814, 0x24000841, 0x25000904, - 0x25800940, 0x26000823, 0x27000832, 0x28000713, 0x2a000731, 0x2c000803, 0x2d000830, 0x2e000722, - 0x30000612, 0x34000621, 0x38000602, 0x3c000620, 0x40000411, 0x50000401, 0x60000310, 0x80000100}; -unsigned int h24[256]={ 0x8ef, 0x10008fe, 0x20008df, 0x30008fd, 0x40008cf, 0x50008fc, 0x60008bf, 0x70008fb, - 0x80007fa, 0xa0008af, 0xb00089f, 0xc0007f9, 0xe0007f8, 0x1000088f, 0x1100087f, 0x120007f7, - 0x1400076f, 0x160007f6, 0x1800075f, 0x1a0007f5, 0x1c00074f, 0x1e0007f4, 0x2000073f, 0x220007f3, - 0x2400072f, 0x260007f2, 0x280007f1, 0x2a00081f, 0x2b0008f0, 0x2c00090f, 0x2c800bee, 0x2ca00bde, - 0x2cc00bed, 0x2ce00bce, 0x2d000bec, 0x2d200bdd, 0x2d400bbe, 0x2d600beb, 0x2d800bcd, 0x2da00bdc, - 0x2dc00bae, 0x2de00bea, 0x2e000bbd, 0x2e200bdb, 0x2e400bcc, 0x2e600b9e, 0x2e800be9, 0x2ea00bad, - 0x2ec00bda, 0x2ee00bbc, 0x2f000bcb, 0x2f200b8e, 0x2f400be8, 0x2f600b9d, 0x2f800bd9, 0x2fa00b7e, - 0x2fc00be7, 0x2fe00bac, 0x300004ff, 0x40000bca, 0x40200bbb, 0x40400b8d, 0x40600bd8, 0x40800c0e, - 0x40900ce0, 0x40a00b0d, 0x40c00ae6, 0x41000b6e, 0x41200b9c, 0x41400ac9, 0x41800a5e, 0x41c00aba, - 0x42000ae5, 0x42400bab, 0x42600b7d, 0x42800ad7, 0x42c00ae4, 0x43000a8c, 0x43400ac8, 0x43800b4e, - 0x43a00b2e, 0x43c00a3e, 0x44000a6d, 0x44400ad6, 0x44800ae3, 0x44c00a9b, 0x45000ab9, 0x45400aaa, - 0x45800ae2, 0x45c00a1e, 0x46000ae1, 0x46400a5d, 0x46800ad5, 0x46c00a7c, 0x47000ac7, 0x47400a4d, - 0x47800a8b, 0x47c00ab8, 0x48000ad4, 0x48400a9a, 0x48800aa9, 0x48c00a6c, 0x49000ac6, 0x49400a3d, - 0x49800ad3, 0x49c00a2d, 0x4a000ad2, 0x4a400a1d, 0x4a800a7b, 0x4ac00ab7, 0x4b000ad1, 0x4b400a5c, - 0x4b800ac5, 0x4bc00a8a, 0x4c000aa8, 0x4c400a99, 0x4c800a4c, 0x4cc00ac4, 0x4d000a6b, 0x4d400ab6, - 0x4d800bd0, 0x4da00b0c, 0x4dc00a3c, 0x4e000ac3, 0x4e400a7a, 0x4e800aa7, 0x4ec00a2c, 0x4f000ac2, - 0x4f400a5b, 0x4f800ab5, 0x4fc00a1c, 0x50000a89, 0x50400a98, 0x50800ac1, 0x50c00a4b, 0x51000bc0, - 0x51200b0b, 0x51400a3b, 0x51800bb0, 0x51a00b0a, 0x51c00a1a, 0x520009b4, 0x52800a6a, 0x52c00aa6, - 0x53000a79, 0x53400a97, 0x53800ba0, 0x53a00b09, 0x53c00a90, 0x540009b3, 0x54800988, 0x55000a2b, - 0x55400a5a, 0x558009b2, 0x56000aa5, 0x56400a1b, 0x56800ab1, 0x56c00a69, 0x57000996, 0x578009a4, - 0x58000a4a, 0x58400a78, 0x58800987, 0x5900093a, 0x598009a3, 0x5a000959, 0x5a800995, 0x5b00092a, - 0x5b8009a2, 0x5c0009a1, 0x5c800968, 0x5d000986, 0x5d800977, 0x5e000949, 0x5e800994, 0x5f000939, - 0x5f800993, 0x60000958, 0x60800985, 0x61000929, 0x61800967, 0x62000976, 0x62800992, 0x63000919, - 0x63800991, 0x64000948, 0x64800984, 0x65000957, 0x65800975, 0x66000938, 0x66800983, 0x67000966, - 0x67800928, 0x68000982, 0x68800918, 0x69000947, 0x69800974, 0x6a000981, 0x6a800a08, 0x6ac00a80, - 0x6b000956, 0x6b800965, 0x6c000917, 0x6c800a07, 0x6cc00a70, 0x6d000873, 0x6e000937, 0x6e800927, - 0x6f000872, 0x70000846, 0x71000864, 0x72000855, 0x73000871, 0x74000836, 0x75000863, 0x76000845, - 0x77000854, 0x78000826, 0x79000862, 0x7a000816, 0x7b000861, 0x7c000906, 0x7c800960, 0x7d000835, - 0x7e000853, 0x7f000844, 0x80000825, 0x81000852, 0x82000815, 0x83000905, 0x83800950, 0x84000751, - 0x86000834, 0x87000843, 0x88000724, 0x8a000742, 0x8c000733, 0x8e000714, 0x90000741, 0x92000804, - 0x93000840, 0x94000723, 0x96000732, 0x98000613, 0x9c000631, 0xa0000703, 0xa2000730, 0xa4000622, - 0xa8000512, 0xb0000521, 0xb8000602, 0xbc000620, 0xc0000411, 0xd0000401, 0xe0000410, 0xf0000400}; -unsigned int hA[16]={ 0x6b0, 0x40006f0, 0x80006d0, 0xc0006e0, 0x10000670, 0x14000650, 0x18000590, 0x20000560, - 0x28000530, 0x300005a0, 0x380005c0, 0x40000420, 0x50000410, 0x60000440, 0x70000480, 0x80000100}; -unsigned int hB[16]={ 0x4f0, 0x100004e0, 0x200004d0, 0x300004c0, 0x400004b0, 0x500004a0, 0x60000490, 0x70000480, - 0x80000470, 0x90000460, 0xa0000450, 0xb0000440, 0xc0000430, 0xd0000420, 0xe0000410, 0xf0000400}; - -/* now the cues, remember to change these tables if you change N_CUE -*/ -unsigned char h_cue[34][N_CUE]={ -{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, -{0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3}, -{0,3,5,5,6,6,7,7,8,8,8,8,8,8,8,8}, -{0,3,5,5,6,6,6,6,7,7,7,7,8,8,8,8}, -{0,8,12,12,13,13,14,14,15,15,15,15,15,15,15,15}, -{0,8,12,12,13,13,14,14,15,15,15,15,15,15,15,15}, -{0,5,7,9,10,11,12,12,13,13,13,13,14,14,15,15}, -{0,20,29,32,33,33,34,34,35,35,35,35,35,35,35,35}, -{0,23,30,31,32,32,32,32,33,33,34,34,35,35,35,35}, -{0,15,21,24,27,29,30,31,32,32,33,33,34,34,35,35}, -{0,42,56,60,61,61,62,62,63,63,63,63,63,63,63,63}, -{0,30,45,53,57,58,60,60,61,61,62,62,63,63,63,63}, -{0,23,37,46,50,54,56,57,58,60,61,61,62,62,63,63}, -{0,203,238,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,132,178,205,223,233,240,245,248,250,252,252,253,254,255,255}, -{0,132,178,205,223,233,240,245,248,250,252,252,253,254,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,162,231,248,252,253,254,254,255,255,255,255,255,255,255,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,13,22,58,59,131,177,209,226,238,245,249,252,253,254,255}, -{0,4,7,9,11,12,13,14,15,15,15,15,15,15,15,15}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} -}; - -/* h4->h5, h14->h15 as suggested by Fraunhofer - * tomislav Aug 21 1997 - */ -unsigned int *tables[34]={h0,h1,h2,h3,h5,h5,h6,h7,h8,h9,h10,h11,h12,h13,h15,h15, - h16,h16,h16,h16,h16,h16,h16,h16,h24,h24,h24,h24,h24,h24,h24,h24,hA,hB}; -#endif /* HUFFMAN */ diff --git a/Src/Sound/MPEG/layer2.cpp b/Src/Sound/MPEG/layer2.cpp deleted file mode 100644 index e06e4ef..0000000 --- a/Src/Sound/MPEG/layer2.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * layer2.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* layer2.c MPEG audio layer2 support - * - * Created by: Tomislav Uzelac Mar 1996 - * merged with amp, May 19 1997 - */ -#include "amp.h" -#include "amp_audio.h" -#include "getbits.h" -#include "transform.h" - -#define LAYER2 -#include "layer2.h" - -#include "Supermodel.h" - -int layer2_frame(struct AUDIO_HEADER *header,int cnt) -{ -int i,s,sb,ch,gr,bitrate,bound=0; -char (*nbal)[],(*bit_alloc_index)[][16]; -unsigned char allocation[2][32]; -unsigned char scfsi[2][32]; -float scalefactor[2][32][3]; -float subband_sample[2][32][36]; -int sblimit,nlevels,grouping; - -float c,d; -int no_of_bits,mpi; -unsigned short sb_sample_buf[3]; - -int hsize,fs,mean_frame_size; - - bit_alloc_index=(char (*)[][16])&t_alloc0; - nbal=(char (*)[])&t_nbal0; // shut up compiler - sblimit = 0; - - hsize=4; - if (header->protection_bit==0) hsize+=2; - - bitrate=t_bitrate[header->ID][3-header->layer][header->bitrate_index]; - fs=t_sampling_frequency[header->ID][header->sampling_frequency]; - if (header->ID) mean_frame_size=144000*bitrate/fs; - else mean_frame_size=72000*bitrate/fs; - - /* layers 1 and 2 do not have a 'bit reservoir' - */ - append=::data=0; - - fillbfr(mean_frame_size + header->padding_bit - hsize); - - switch (header->mode) - { - case 0 : - case 2 : nch=2; bound=32; bitrate=bitrate/2; - break; - case 3 : nch=1; bound=32; - break; - case 1 : nch=2; bitrate=bitrate/2; bound=(header->mode_extension+1)*4; - } - - if (header->ID==1) switch (header->sampling_frequency) { - case 0 : switch (bitrate) /* 0 = 44.1 kHz */ - { - case 56 : - case 64 : - case 80 : bit_alloc_index=(char (*)[][16])&t_alloc0; - nbal=(char (*)[])&t_nbal0; - sblimit=27; - break; - case 96 : - case 112 : - case 128 : - case 160 : - case 192 : bit_alloc_index=(char (*)[][16])&t_alloc1; - nbal=(char (*)[])&t_nbal1; - sblimit=30; - break; - case 32 : - case 48 : bit_alloc_index=(char (*)[][16])&t_alloc2; - nbal=(char (*)[])&t_nbal2; - sblimit=8; - break; - default : ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - } - break; - case 1 : switch (bitrate) /* 1 = 48 kHz */ - { - case 56 : - case 64 : - case 80 : - case 96 : - case 112 : - case 128 : - case 160 : - case 192 : bit_alloc_index=(char (*)[][16])&t_alloc0; - nbal=(char (*)[])&t_nbal0; - sblimit=27; - break; - case 32 : - case 48 : bit_alloc_index=(char (*)[][16])&t_alloc2; - nbal=(char (*)[])&t_nbal2; - sblimit=8; - break; - default : ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - } - break; - case 2 : switch (bitrate) /* 2 = 32 kHz */ - { - case 56 : - case 64 : - case 80 : bit_alloc_index=(char (*)[][16])&t_alloc0; - nbal=(char (*)[])&t_nbal0; - sblimit=27; - break; - case 96 : - case 112 : - case 128 : - case 160 : - case 192 : bit_alloc_index=(char (*)[][16])&t_alloc1; - nbal=(char (*)[])&t_nbal1; - sblimit=30; - break; - case 32 : - case 48 : bit_alloc_index=(char (*)[][16])&t_alloc3; - nbal=(char (*)[])&t_nbal3; - sblimit=12; - break; - default : ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); - } - break; - default : ErrorLog("Internal error in MPEG decoder (%s:%d).", __FILE__, __LINE__); // sampling frequency no good - } else { - bit_alloc_index=(char (*)[][16])&t_allocMPG2; - nbal=(char (*)[])&t_nbalMPG2; - sblimit=30; - } - -/* - * bit allocation per subband per channel decoding ***************************** - */ - - if (bound==32) bound=sblimit; /* bound=32 means there is no intensity stereo */ - - for (sb=0;sb>2]; - } - } - } else - for (s=0;s<3;s++) subband_sample[ch][sb][3*gr+s]=0; - - - /* - * joint stereo ******************************************** - */ - - for (sb=bound;sb>2]; - } - } - - } else for (s=0;s<3;s++) { - subband_sample[0][sb][3*gr+s]=0; - subband_sample[1][sb][3*gr+s]=0; - } - - /* - * the rest ******************************************* - */ - for (sb=sblimit;sb<32;sb++) - for (ch=0;chmode!=3) { - for (ch=0;chmode!=3) nch=2; - - return 0; -} -/****************************************************************************/ -/****************************************************************************/ - -void convert_samplecode(unsigned int samplecode,unsigned int nlevels,unsigned short* sb_sample_buf) -{ -int i; - - for (i=0;i<3;i++) { - *sb_sample_buf=samplecode%nlevels; - samplecode=samplecode/nlevels; - sb_sample_buf++; - } -} - -float requantize_sample(unsigned short s4,unsigned short nlevels,float c,float d,float factor) -{ -register float s,s2,s3; -s3=(float) (-1.0+s4*2.0/(nlevels+1)); -s2=c*(s3+d); -s=factor*s2; -return s; -} diff --git a/Src/Sound/MPEG/layer2.h b/Src/Sound/MPEG/layer2.h deleted file mode 100644 index 3972401..0000000 --- a/Src/Sound/MPEG/layer2.h +++ /dev/null @@ -1,218 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * layer2.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ -/* layer2.h - * Tomislav Uzelac - cca. Feb 1996 - */ - - -extern int layer2_frame(struct AUDIO_HEADER *header,int cnt); - -#ifdef LAYER2 - -int layer2_frame(struct AUDIO_HEADER *header,int cnt); -float requantize_sample(unsigned short s4,unsigned short nlevels,float c,float d,float factor); -void convert_samplecode(unsigned int samplecode,unsigned int nlevels,unsigned short* sb_sample_buf); - -char t_nbal0[27]={4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2}; -char t_nbal1[30]={4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2}; -char t_nbal2[8] ={4,4,3,3,3,3,3,3}; -char t_nbal3[12]={4,4,3,3,3,3,3,3,3,3,3,3}; -char t_nbalMPG2[30]={4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}; - -char t_alloc0[27][16] = { /* table B.2a ISO/IEC 11172-3 */ -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}}; - -char t_alloc1[30][16] = { /* table B.2b ISO/IEC 11172-3 */ -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,3,5,6,7,8,9,10,11,12,13,14,15,16,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,3,4,5,6,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}, -{0,1,2,17}}; - -char t_alloc2[8][16] = { /* table B.2c ISO/IEC 11172-3 */ -{0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16}, -{0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}}; - -char t_alloc3[12][16] = { /* table B.2d ISO/IEC 11172-3 */ -{0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16}, -{0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}, -{0,1,2,4,5,6,7,127}}; - -char t_allocMPG2[30][16] = { /* table B.1. ISO/IEC 13818-3 */ -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, -{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4,5,6,7,8}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}, -{0,1,2,4}}; - -double t_scalefactor[64] = { -2.00000000000000, 1.58740105196820, 1.25992104989487, -1.00000000000000, 0.79370052598410, 0.62996052494744, 0.50000000000000, -0.39685026299205, 0.31498026247372, 0.25000000000000, 0.19842513149602, -0.15749013123686, 0.12500000000000, 0.09921256574801, 0.07874506561843, -0.06250000000000, 0.04960628287401, 0.03937253280921, 0.03125000000000, -0.02480314143700, 0.01968626640461, 0.01562500000000, 0.01240157071850, -0.00984313320230, 0.00781250000000, 0.00620078535925, 0.00492156660115, -0.00390625000000, 0.00310039267963, 0.00246078330058, 0.00195312500000, -0.00155019633981, 0.00123039165029, 0.00097656250000, 0.00077509816991, -0.00061519582514, 0.00048828125000, 0.00038754908495, 0.00030759791257, -0.00024414062500, 0.00019377454248, 0.00015379895629, 0.00012207031250, -0.00009688727124, 0.00007689947814, 0.00006103515625, 0.00004844363562, -0.00003844973907, 0.00003051757813, 0.00002422181781, 0.00001922486954, -0.00001525878906, 0.00001211090890, 0.00000961243477, 0.00000762939453, -0.00000605545445, 0.00000480621738, 0.00000381469727, 0.00000302772723, -0.00000240310869, 0.00000190734863, 0.00000151386361, 0.00000120155435, -1E-20}; - -double t_c[18] = { 0, - 1.33333333333, 1.60000000000, 1.14285714286, - 1.77777777777, 1.06666666666, 1.03225806452, - 1.01587301587, 1.00787401575, 1.00392156863, - 1.00195694716, 1.00097751711, 1.00048851979, - 1.00024420024, 1.00012208522, 1.00006103888, - 1.00003051851, 1.00001525902 }; - -double t_d[18] = {0, - 0.500000000, 0.500000000, 0.250000000, 0.500000000, - 0.125000000, 0.062500000, 0.031250000, 0.015625000, - 0.007812500, 0.003906250, 0.001953125, 0.0009765625, - 0.00048828125,0.00024414063,0.00012207031, - 0.00006103516,0.00003051758 }; - -float t_dd[18]={ -1.0f, -0.5f, -0.5f, -0.75f, -0.5f, -0.875f, -0.9375f, -0.96875f, -0.984375f, --0.992188f, -0.996094f, -0.998047f, -0.999023f, -0.999512f, -0.999756f, -0.999878f, -0.999939f, --0.999969f}; - -char t_grouping[18]={0,3,5,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0}; - -/* -int t_nlevels[18] = {0,3,5,7,9,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; -*/ -int t_nlevels[18] = {0,3,7,7,15,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; - - -float t_nli[18]={ 0.0f, 0.5f, 0.25f, 0.25f, 0.125f, 0.125f, 0.0625f, 0.03125f, 0.015625f, 0.0078125f, 0.00390625f, -0.00195313f, 0.000976563f, 0.000488281f, 0.000244141f, 0.00012207f, 6.10352e-05f, 3.05176e-05f}; - -int t_bpc[18] = {0,5,7,3,10,4,5,6,7,8,9,10,11,12,13,14,15,16}; - -#endif /* LAYER2 */ diff --git a/Src/Sound/MPEG/layer3.cpp b/Src/Sound/MPEG/layer3.cpp deleted file mode 100644 index 9730776..0000000 --- a/Src/Sound/MPEG/layer3.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * layer3.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* layer3.c layer3 audio decoding - * - * Created by: tomislav uzelac Mar 1 97 - * Last modified by: - */ -#include "amp.h" -#include "amp_audio.h" -#include "dump.h" -#include "getbits.h" -#include "getdata.h" -#include "huffman.h" -#include "misc2.h" -#include "rtbuf.h" -#include "transform.h" - -#define LAYER3 -#include "layer3.h" - -void requantize_downmix(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header); - -/* this function decodes one layer3 audio frame, except for the header decoding - * which is done in main() [audio.c]. returns 0 if everything is ok. - */ -int layer3_frame(struct AUDIO_HEADER *header,int cnt) -{ -static struct SIDE_INFO info; - -int gr,ch,sb,i; -int mean_frame_size,bitrate,fs,hsize,ssize; - -/* we need these later, hsize is the size of header+side_info -*/ - if (header->ID) - if (header->mode==3) { - nch=1; - hsize=21; - } else { - nch=2; - hsize=36; - } - else - if (header->mode==3) { - nch=1; - hsize=13; - } else { - nch=2; - hsize=21; - } - -/* crc increases hsize by 2 -*/ - if (header->protection_bit==0) hsize+=2; - - -/* read layer3 specific side_info -*/ - getinfo(header,&info); - - -/* MPEG2 only has one granule -*/ - bitrate=t_bitrate[header->ID][3-header->layer][header->bitrate_index]; - fs=t_sampling_frequency[header->ID][header->sampling_frequency]; - if (header->ID) mean_frame_size=144000*bitrate/fs; - else mean_frame_size=72000*bitrate/fs; - - -/* check if mdb is too big for the first few frames. this means that - * a part of the stream could be missing. We must still fill the buffer - * - * don't forget to (re)initialise bclean_bytes to 0, and f_bdirty to FALSE!!! - */ - if (f_bdirty) - { - if (info.main_data_begin > bclean_bytes) { - fillbfr(mean_frame_size + header->padding_bit - hsize); - bclean_bytes+=mean_frame_size + header->padding_bit - hsize; - /* warn(" frame %d discarded, incomplete main_data\n",cnt); */ - return 0; - } else { - /* re-initialise */ - f_bdirty=FALSE; - bclean_bytes=0; - } - } - -/* now update the data 'pointer' (counting in bits) according to - * the main_data_begin information - */ - data = 8 * ((append - info.main_data_begin) & (BUFFER_SIZE-1)); - - -/* read into the buffer all bytes up to the start of next header -*/ - fillbfr(mean_frame_size + header->padding_bit - hsize); - - -/* these two should go away -*/ - t_l=&t_b8_l[header->ID][header->sampling_frequency][0]; - t_s=&t_b8_s[header->ID][header->sampling_frequency][0]; - -/* debug/dump stuff -*/ - if (A_DUMP_BINARY) dump((int *)info.part2_3_length); - -/* decode the scalefactors and huffman data - * this part needs to be enhanced for error robustness - */ - for (gr=0;gr < ((header->ID) ? 2 : 1);gr++) { - for (ch=0;chmode!=1 || (header->mode==1 && header->mode_extension==0)) - for (ch=0;chmode!=3) nch=2; - - } /* for (gr... */ - - /* return status: 0 for ok, errors will be added - */ - return 0; -} - diff --git a/Src/Sound/MPEG/layer3.h b/Src/Sound/MPEG/layer3.h deleted file mode 100644 index 9690621..0000000 --- a/Src/Sound/MPEG/layer3.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * layer3.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* layer3.h - * - * Created by: tomislav uzelac Mar 1 97 - * Last modified by: - */ - -extern int layer3_frame(struct AUDIO_HEADER *header,int cnt); - -#ifdef LAYER3 - -int layer3_frame(struct AUDIO_HEADER *header,int cnt); - -#endif /* LAYER3 */ diff --git a/Src/Sound/MPEG/misc2.cpp b/Src/Sound/MPEG/misc2.cpp deleted file mode 100644 index 908f225..0000000 --- a/Src/Sound/MPEG/misc2.cpp +++ /dev/null @@ -1,852 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * misc2.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* misc2.c requantization, stereo processing, reordering(shortbl) and antialiasing butterflies - * - * misc.c was created by tomislav uzelac in May 1996, and was completely awful - * Created by: tomislav uzelac Dec 22 1996 - * some more speed injected, cca. Jun 1 1997 - */ -#include -#include - -#include "amp.h" -#include "amp_audio.h" -#include "getdata.h" -#include "huffman.h" - -#define MISC2 -#include "misc2.h" - -#include "Supermodel.h" - -/* - * fras == Formula for Requantization and All Scaling ************************** - */ -static inline float fras_l(int sfb,int global_gain,int scalefac_scale,int scalefac,int preflag) -{ -register int a,scale; - /* - if (scalefac_scale) scale=2; - else scale=1; - */ - scale=scalefac_scale+1; - a= global_gain -210 -(scalefac << scale); - if (preflag) a-=(t_pretab[sfb] << scale); - -/* bugfix, Mar 13 97: shifting won't produce a legal result if we shift by more than 31 - * since global_gain<256, this can only occur for (very) negative values of a. -*/ - if (a < -127) return 0; - -/* a minor change here as well, no point in abs() if we now that a<0 -*/ - if (a>=0) return tab[a&3]*(1 << (a>>2)); - else return tabi[(-a)&3]/(1 << ((-a) >> 2)); -} - -static inline float fras_s(int global_gain,int subblock_gain,int scalefac_scale,int scalefac) -{ -int a; - a=global_gain - 210 - (subblock_gain << 3); - if (scalefac_scale) a-= (scalefac << 2); - else a-= (scalefac << 1); - - if (a < -127) return 0; - - if (a>=0) return tab[a&3]*(1 << (a>>2)); - else return tabi[(-a)&3]/(1 << ((-a) >> 2)); -} - -/* this should be faster than pow() - */ -static inline float fras2(int is,float a) -{ - if (is > 0) return t_43[is]*a; - else return -t_43[-is]*a; -} - -/* - * requantize_mono ************************************************************* - */ - -/* generally, the two channels do not have to be of the same block type - that's why we do two passes with requantize_mono. - * if ms or intensity stereo is enabled we do a single pass with requantize_ms because both channels are same block type - */ - -void requantize_mono(int gr,int ch,struct SIDE_INFO *info,struct AUDIO_HEADER *header) -{ -int l,i,sfb; -float a; -int global_gain=info->global_gain[gr][ch]; -int scalefac_scale=info->scalefac_scale[gr][ch]; -int sfreq=header->sampling_frequency; - - - no_of_imdcts[0]=no_of_imdcts[1]=32; - - if (info->window_switching_flag[gr][ch] && info->block_type[gr][ch]==2) - if (info->mixed_block_flag[gr][ch]) { - /* - * requantize_mono - mixed blocks/long block part ********************** - */ - int window,window_len,preflag=0; /* pretab is all zero in this low frequency area */ - int scalefac=scalefac_l[gr][ch][0]; - - l=0;sfb=0; - a=fras_l(sfb,global_gain,scalefac_scale,scalefac,preflag); - while (l<36) { - xr[ch][0][l]=fras2(is[ch][l],a); - if (l==t_l[sfb]) { - scalefac=scalefac_l[gr][ch][++sfb]; - a=fras_l(sfb,global_gain,scalefac_scale,scalefac,preflag); - } - l++; - } - /* - * requantize_mono - mixed blocks/short block part ********************* - */ - sfb=3; - window_len=t_s[sfb]-t_s[sfb-1]; - while (lsubblock_gain[gr][ch][window]; - a=fras_s(global_gain,subblock_gain,scalefac_scale,scalefac); - for (i=0;iID][sfreq][l]]=fras2(is[ch][l],a); - l++; - } - } - sfb++; - window_len=t_s[sfb]-t_s[sfb-1]; - } - while (l<576) xr[ch][0][t_reorder[header->ID][sfreq][l++]]=0; - } else { - /* - * requantize mono - short blocks ************************************** - */ - int window,window_len; - - sfb=0; l=0; - window_len=t_s[0]+1; - while (lsubblock_gain[gr][ch][window]; - float a=fras_s(global_gain,subblock_gain,scalefac_scale,scalefac); - for (i=0;iID][sfreq][l]]=fras2(is[ch][l],a); - l++; - } - } - sfb++; - window_len=t_s[sfb]-t_s[sfb-1]; - } - while (l<576) xr[ch][0][t_reorder[header->ID][sfreq][l++]]=0; - } - else { - /* long blocks */ - int preflag=info->preflag[gr][ch]; - int scalefac=scalefac_l[gr][ch][0]; - - sfb=0; l=0; - a=fras_l(sfb,global_gain,scalefac_scale,scalefac,preflag); - while (lmode_extension==1 || header->mode_extension==3) { - if (info->window_switching_flag[gr][0] && info->block_type[gr][0]==2) { - - /* find that isbound! - */ - tmp=non_zero[1]; - sfb=0; while ((3*t_s[sfb]+2) < tmp && sfb < 12) sfb++; - while ((isbound[0]<0 || isbound[1]<0 || isbound[2]<0) && !(info->mixed_block_flag[gr][0] && sfb<3) && sfb) { - for (window=0;window<3;window++) { - if (sfb==0) { - window_len=t_s[0]+1; - tmp=(window+1)*window_len - 1; - } else { - window_len=t_s[sfb]-t_s[sfb-1]; - tmp=(3*t_s[sfb-1]+2) + (window+1)*window_len; - } - if (isbound[window] < 0) - for (i=0;imixed_block_flag[gr][0]) - { - if (isbound[0]<0 && isbound[1]<0 && isbound[2]<0) - { - tmp=35; - while (is[1][tmp] == 0) tmp--; - sfb=0; while (t_l[sfb] < tmp && sfb < 21) sfb++; - isbound[0]=isbound[1]=isbound[2]=t_l[sfb]+1; - } - else for (window=0;window<3;window++) - if (isbound[window]<0) isbound[window]=36; - } - if (header->ID==1) isbound[0]=isbound[1]=isbound[2]=MAX(isbound[0],MAX(isbound[1],isbound[2])); - - /* just how many imdcts? - */ - tmp=non_zero[0]; - sfb=0; while ((3*t_s[sfb]+2) < tmp && sfb < 12) sfb++; - no_of_imdcts[0]=no_of_imdcts[1]=(t_s[sfb]-1)/6+1; - } else { - - /* long blocks now - */ - tmp=non_zero[1]; - while (is[1][tmp] == 0) tmp--; - sfb=0; while (t_l[sfb] < tmp && sfb < 21) sfb++; - isbound[0]=isbound[1]=isbound[2]=t_l[sfb]+1; - no_of_imdcts[0]=no_of_imdcts[1]=(non_zero[0]-1)/18+1; - } - if (header->mode_extension==1) ms_flag=0; - else ms_flag=1; - } else { - - /* intensity stereo is, regretably, turned off - */ - ms_flag=1; - - /* i really put a lot of work in this, but it still looks like shit (works, though) - */ - if (!info->window_switching_flag[gr][0] || (info->window_switching_flag[gr][0] && info->block_type[gr][0]!=2)) - isbound[0]=isbound[1]=isbound[2]=(MAX(non_zero[0],non_zero[1])); - else isbound[0]=isbound[1]=isbound[2]=576; - - if (info->window_switching_flag[gr][0] && info->block_type[gr][0]==2) { - /* should do for mixed blocks too, though i havent tested... */ - tmp=(MAX(non_zero[0],non_zero[1]))/3; - sfb=0; while (t_s[sfb]=576) return; /* brrr... */ - - if ((is_pos != IS_ILLEGAL) && (header->ID==1)) { - ftmp=fras2(is[0][l],a[0]); - xr[0][0][pos]=(1-t_is[is_pos])*ftmp; - xr[1][0][pos]=t_is[is_pos]*ftmp; - return; - } - - if ((is_pos != IS_ILLEGAL) && (header->ID==0)) { - ftmp=fras2(is[0][l],a[0]); - if (is_pos&1) { - xr[0][0][pos]= t_is2[intensity_scale][(is_pos+1)>>1] * ftmp; - xr[1][0][pos]= ftmp; - } else { - xr[0][0][pos]= ftmp; - xr[1][0][pos]= t_is2[intensity_scale][is_pos>>1] * ftmp; - } - return; - } - - if (ms_flag) { - Mi=fras2(is[0][l],a[0]); - Si=fras2(is[1][l],a[1]); - xr[0][0][pos]=(Mi+Si)*i_sq2; - xr[1][0][pos]=(Mi-Si)*i_sq2; - } else { - xr[0][0][pos]=fras2(is[0][l],a[0]); - xr[1][0][pos]=fras2(is[1][l],a[1]); - } -} - -static inline void stereo_l(int l,float a[2],int ms_flag,int is_pos,struct AUDIO_HEADER *header) -{ -float ftmp,Mi,Si; - if (l>=576) return; - -/* new code by ??? -*/ - if (is_pos != IS_ILLEGAL) { - ftmp = fras2(is[0][l], a[0]); - if (header -> ID ==1) { - xr[0][0][l] = (1 - t_is[is_pos]) * ftmp; - xr[1][0][l] = t_is[is_pos] * ftmp; - return; - } else if (is_pos & 1) { - xr[0][0][l] = t_is2[intensity_scale][(is_pos + 1) >> 1] * ftmp; - xr[1][0][l] = ftmp; - } else { - xr[0][0][l] = ftmp; - xr[1][0][l] = t_is2[intensity_scale][is_pos >> 1] * ftmp; - } - return; - } - - if (ms_flag) { - Mi=fras2(is[0][l],a[0]); - Si=fras2(is[1][l],a[1]); - xr[0][0][l]=(Mi+Si)*i_sq2; - xr[1][0][l]=(Mi-Si)*i_sq2; - } else { - xr[0][0][l]=fras2(is[0][l],a[0]); - xr[1][0][l]=fras2(is[1][l],a[1]); - } - -} - - -/* - * requantize_ms *************************************************************** - */ -void requantize_ms(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header) -{ -int l,sfb,ms_flag,is_pos,i,ch; -int *global_gain,subblock_gain[2],*scalefac_scale,scalefac[2],isbound[3]; -int sfreq=header->sampling_frequency; -int id = header->ID; -float a[2]; - -memset(a, 0, sizeof(a)); - -global_gain=info->global_gain[gr]; -scalefac_scale=info->scalefac_scale[gr]; - - if (info->window_switching_flag[gr][0] && info->block_type[gr][0]==2) - if (info->mixed_block_flag[gr][0]) { - /* - * mixed blocks w/stereo processing - long block part ****************** - */ - int window,window_len; - int preflag[2]={0,0}; - - ms_flag=find_isbound(isbound,gr,info,header); - - sfb=0; l=0; - for (ch=0;ch<2;ch++) { - scalefac[ch]=scalefac_l[gr][ch][0]; - a[ch]=fras_l(0,global_gain[ch],scalefac_scale[ch],scalefac[ch],preflag[ch]); - } - - - while (l<36) { - int is_pos; - if (lsubblock_gain[gr][0][window]; - subblock_gain[1]=info->subblock_gain[gr][1][window]; - scalefac[0]=scalefac_s[gr][0][sfb][window]; - scalefac[1]=scalefac_s[gr][1][sfb][window]; - - if (t_s[sfb] < isbound[window]) { - is_pos=IS_ILLEGAL; - a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]); - a[1]=fras_s(global_gain[1],subblock_gain[1],scalefac_scale[1],scalefac[1]); - } else { - is_pos=scalefac[1]; - if (id==1) /* MPEG1 */ - { - if (is_pos==7) is_pos=IS_ILLEGAL; - } - else /* MPEG2 */ - { - if (is_pos==is_max[sfb+6]) is_pos=IS_ILLEGAL; - } - - a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]); - } - - for (i=0;isubblock_gain[gr][0][window]; - subblock_gain[1]=info->subblock_gain[gr][1][window]; - scalefac[0]=scalefac_s[gr][0][sfb][window]; - scalefac[1]=scalefac_s[gr][1][sfb][window]; - - if (t_s[sfb] < isbound[window]) { - is_pos=IS_ILLEGAL; - a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]); - a[1]=fras_s(global_gain[1],subblock_gain[1],scalefac_scale[1],scalefac[1]); - } else { - is_pos=scalefac[1]; - if (id==1) /* MPEG1 */ - { - if (is_pos==7) is_pos=IS_ILLEGAL; - } - else /* MPEG2 */ - { - if (is_pos==is_max[sfb+6]) is_pos=IS_ILLEGAL; - } - a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]); - } - - for (i=0;ipreflag[gr]; - - ms_flag=find_isbound(isbound,gr,info,header); - - sfb=0; l=0; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]); - - /* no intensity stereo part - */ - if (ms_flag) - while (l< isbound[0]) { -#if defined(PENTIUM_RDTSC) - -unsigned int cnt4, cnt3, cnt2, cnt1; -static int min_cycles = 99999999; - - __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt4)); -#endif - - { - register float Mi = fras2(is[0][l],a[0]); - register float Si = fras2(is[1][l],a[1]); - register float tmp = i_sq2; - xr[0][0][l]=(Mi+Si)*tmp; - xr[1][0][l]=(Mi-Si)*tmp; - } - -#if defined(PENTIUM_RDTSC) - __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt4)); - - if (cnt2-cnt1 < min_cycles) { - min_cycles = cnt2-cnt1; - //printf("%d cycles\n", min_cycles); - } - -#endif - if (l==t_l[sfb]) { -#if defined(PENTIUM_RDTSC2) - -unsigned int cnt4, cnt2, cnt1; -static int min_cycles = 99999999; - - __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt4)); -#endif - - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]); -#if defined(PENTIUM_RDTSC2) - __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt4)); - - if (cnt2-cnt1 < min_cycles) { - min_cycles = cnt2-cnt1; - //printf("%d cycles, sfb %d\n", min_cycles, sfb); - } - -#endif - } - l++; - } - else - while (l< isbound[0]) { - xr[0][0][l]=fras2(is[0][l],a[0]); - xr[1][0][l]=fras2(is[1][l],a[1]); - if (l==t_l[sfb]) { - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]); - } - l++; - } - - - /* intensity stereo part - */ - while (l<(MAX(non_zero[0],non_zero[1]))) { - int is_pos=scalefac[1]; - - if (id==1) /* MPEG1 */ - { - if (is_pos==7) is_pos=IS_ILLEGAL; - } - else /* MPEG2 */ - { - if (is_pos==is_max[sfb]) is_pos=IS_ILLEGAL; - } - stereo_l(l,a,ms_flag,is_pos,header); - - if (l==t_l[sfb]) { - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - scalefac[1]=scalefac_l[gr][1][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - } - l++; - } - - while (l<576) { - xr[0][0][l]=0; - xr[1][0][l]=0; - l++; - } - } -} - -/* - * requantize_downmix ********************************************************** - */ -void requantize_downmix(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header) -{ -int l,sfb,ms_flag,i; -int *global_gain,subblock_gain[2],*scalefac_scale,scalefac[2]; -int sfreq=header->sampling_frequency; -int id = header->ID; -float a[2]; - - /* first set some variables - */ - global_gain=info->global_gain[gr]; - scalefac_scale=info->scalefac_scale[gr]; - - if (header->mode_extension==2 || header->mode_extension==3) ms_flag=1; - else ms_flag=0; - - /* ... and then we're off for requantization - */ - if (info->window_switching_flag[gr][0] && info->block_type[gr][0]==2) - if (info->mixed_block_flag[gr][0]) { - ErrorLog("Internal error in MPEG decoder: mixed blocks encountered."); - } else { - int window,window_len; - int isbound[3]; - int is_pos; - - memset(isbound, 0, sizeof(isbound)); - - sfb=0; l=0; window_len=t_s[0]+1; - - while (l<(MAX(non_zero[0],non_zero[1]))) { - for (window=0;window<3;window++) { - subblock_gain[0]=info->subblock_gain[gr][0][window]; - subblock_gain[1]=info->subblock_gain[gr][1][window]; - scalefac[0]=scalefac_s[gr][0][sfb][window]; - is_pos=scalefac[1]=scalefac_s[gr][1][sfb][window]; - - if (t_s[sfb] < isbound[window]) { - a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]); - if (ms_flag) { - for (i=0;i>1]; - xr[0][0][t_reorder[id][sfreq][l]] = ftmp; - l++; - } - } - } - window_len = -t_s[sfb++]; - window_len += t_s[sfb]; - } - while (l<576) { - xr[0][0][l]=0; - l++; - } - } - else { - int *preflag=info->preflag[gr]; - int isbound; - - if (header->mode_extension==1 || header->mode_extension==3) { - int tmp=non_zero[1]; - while (is[1][tmp] == 0) tmp--; - sfb=0; while (t_l[sfb] < tmp && sfb < 21) sfb++; - isbound=t_l[sfb]+1; - no_of_imdcts[0]=no_of_imdcts[1]=(non_zero[0]-1)/18+1; - } else { - isbound=(MAX(non_zero[0],non_zero[1])); - no_of_imdcts[0]=no_of_imdcts[1]=(isbound-1)/18+1; - } - - sfb=0; l=0; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]); - - /* no intensity stereo part - */ - if (ms_flag) - while (l < isbound) { - register float Mi = fras2(is[0][l],a[0]); - register float tmp = i_sq2; - xr[0][0][l]=Mi*tmp; - - if (l==t_l[sfb]) { - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - } - l++; - } - else - while (l < isbound) { - register float tmp1=fras2(is[0][l],a[0]); - register float tmp2=fras2(is[1][l],a[1]); - xr[0][0][l]=(tmp1+tmp2)*0.5f; - if (l==t_l[sfb]) { - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]); - } - l++; - } - /* intensity stereo part - */ - while (l<(MAX(non_zero[0],non_zero[1]))) { - int is_pos=scalefac[1]; - register float ftmp=fras2(is[0][l], a[0]); - - if (id==0 && is_pos>1]; - } - - xr[0][0][l] = ftmp; - - if (l==t_l[sfb]) { - sfb++; - scalefac[0]=scalefac_l[gr][0][sfb]; - a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]); - scalefac[1]=scalefac_l[gr][1][sfb]; - } - l++; - } - - /* _always_ zero out everything else - */ - while (l<576) { - xr[0][0][l]=0; - l++; - } - } -} - -/* - * antialiasing butterflies **************************************************** - * - */ -void alias_reduction(int ch) -{ -unsigned int sb; - - for (sb=1;sb<32;sb++) { - float *x = xr[ch][sb]; - register float a, b; - - a = x[0]; - b = x[-1]; - x[-1] = b * Cs[0] - a * Ca[0]; - x[0] = a * Cs[0] + b * Ca[0]; - - a = x[1]; - b = x[-2]; - x[-2] = b * Cs[1] - a * Ca[1]; - x[1] = a * Cs[1] + b * Ca[1]; - - a = x[2]; - b = x[-3]; - x[-3] = b * Cs[2] - a * Ca[2]; - x[2] = a * Cs[2] + b * Ca[2]; - - a = x[3]; - b = x[-4]; - x[-4] = b * Cs[3] - a * Ca[3]; - x[3] = a * Cs[3] + b * Ca[3]; - - a = x[4]; - b = x[-5]; - x[-5] = b * Cs[4] - a * Ca[4]; - x[4] = a * Cs[4] + b * Ca[4]; - - a = x[5]; - b = x[-6]; - x[-6] = b * Cs[5] - a * Ca[5]; - x[5] = a * Cs[5] + b * Ca[5]; - - a = x[6]; - b = x[-7]; - x[-7] = b * Cs[6] - a * Ca[6]; - x[6] = a * Cs[6] + b * Ca[6]; - - a = x[7]; - b = x[-8]; - x[-8] = b * Cs[7] - a * Ca[7]; - x[7] = a * Cs[7] + b * Ca[7]; - } -} - -/* calculating t_43 instead of having that big table in misc2.h - */ - -void calculate_t43(void) -{ -int i; - for (i=0;i<8192;i++) - t_43[i]=(float)pow((float)i,1.33333333333f); -} diff --git a/Src/Sound/MPEG/misc2.h b/Src/Sound/MPEG/misc2.h deleted file mode 100644 index 94a50f6..0000000 --- a/Src/Sound/MPEG/misc2.h +++ /dev/null @@ -1,281 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * misc2.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* misc2.h - * - * Created by: tomislav uzelac May 1996 - * Last modified by: tomislav uzelac Jan 8 1997 - */ - -extern void requantize_mono(int gr,int ch,struct SIDE_INFO *info,struct AUDIO_HEADER *header); -extern void requantize_ms(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header); -extern void alias_reduction(int ch); -extern void calculate_t43(void); - -extern int no_of_imdcts[2]; - -#ifdef MISC2 - -#define i_sq2 0.707106781188 -#define IS_ILLEGAL 0xfeed - -void requantize_mono(int gr,int ch,struct SIDE_INFO *info,struct AUDIO_HEADER *header); -void requantize_ms(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header); -void alias_reduction(int ch); - -static inline float fras_l(int sfb,int global_gain,int scalefac_scale,int scalefac,int preflag); -static inline float fras_s(int global_gain,int subblock_gain,int scalefac_scale,int scalefac); -static inline float fras2(int is,float a); -static int find_isbound(int isbound[3],int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header); -static inline void stereo_s(int l,float a[2],int pos,int ms_flag,int is_pos,struct AUDIO_HEADER *header); -static inline void stereo_l(int l,float a[2],int ms_flag,int is_pos,struct AUDIO_HEADER *header); - -int no_of_imdcts[2]; - -static const int t_pretab[22]={0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0}; -static const float t_is[7]={ 1.0f, 0.788675134596f, 0.633974596215f, - 0.5f, 0.366025403784f, 0.211324865405f, 0.0f}; -static const float t_is2[2][32]={ -{ 1.0f, 0.840896f, 0.707107f, 0.594604f, 0.5f, 0.420448f, - 0.353553f, 0.297302f, 0.25f, 0.210224f, 0.176777f, 0.148651f, - 0.125f, 0.105112f, 0.0883883f, 0.0743254f}, -{ 1.0f, 0.707107f, 0.5f, 0.353553f, 0.25f, 0.176777f, - 0.125f, 0.0883883f, 0.0625f, 0.0441942f, 0.03125f, 0.0220971f, - 0.015625f, 0.0110485f, 0.0078125f, 0.00552427f} -}; -static const float t_downmix[2][32]={ -{ 1.000000f, 0.920448f, 0.853554f, 0.797302f, 0.750000f, 0.710224f, - 0.676776f, 0.648651f, 0.625000f, 0.605112f, 0.588389f, 0.574326f, - 0.562500f, 0.552556f, 0.544194f, 0.537163f}, -{ 1.000000f, 0.853554f, 0.750000f, 0.676776f, 0.625000f, 0.588389f, - 0.562500f, 0.544194f, 0.531250f, 0.522097f, 0.515625f, 0.511049f, - 0.507813f, 0.505524f, 0.503906f, 0.502762f} -}; - -static const float Cs[8]={0.857492925712f, 0.881741997318f, 0.949628649103f, - 0.983314592492f, 0.995517816065f, 0.999160558175f, - 0.999899195243f, 0.999993155067f}; -static const float Ca[8]={-0.5144957554270f, -0.4717319685650f, -0.3133774542040f, - -0.1819131996110f, -0.0945741925262f, -0.0409655828852f, - -0.0141985685725f, -0.00369997467375f}; -static const float tab[4]={1.0f,1.189207115f,1.414213562f,1.6817928301f}; -static const float tabi[4]={1.0f,0.840896415f,0.707106781f,0.594603557f}; - -static float t_43[8192]; - - -/* leftmost index denotes header->ID, so first three are for MPEG2 - * and the others are for MPEG1 - */ -static const short t_reorder[2][3][576]={{ -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 90, 91, - 78, 79, 80, 81, 82, 83, 96, 97, 84, 85, 86, 87, 88, 89, 102, 103, 92, 93, 94, 95, - 108, 109, 110, 111, 112, 113, 98, 99, 100, 101, 114, 115, 116, 117, 118, 119, 104, 105, 106, 107, - 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 144, 145, 146, 147, 148, 149, 162, 163, - 132, 133, 134, 135, 136, 137, 150, 151, 152, 153, 154, 155, 168, 169, 138, 139, 140, 141, 142, 143, - 156, 157, 158, 159, 160, 161, 174, 175, 164, 165, 166, 167, 180, 181, 182, 183, 184, 185, 198, 199, - 200, 201, 202, 203, 216, 217, 170, 171, 172, 173, 186, 187, 188, 189, 190, 191, 204, 205, 206, 207, - 208, 209, 222, 223, 176, 177, 178, 179, 192, 193, 194, 195, 196, 197, 210, 211, 212, 213, 214, 215, - 228, 229, 218, 219, 220, 221, 234, 235, 236, 237, 238, 239, 252, 253, 254, 255, 256, 257, 270, 271, - 272, 273, 274, 275, 288, 289, 290, 291, 224, 225, 226, 227, 240, 241, 242, 243, 244, 245, 258, 259, - 260, 261, 262, 263, 276, 277, 278, 279, 280, 281, 294, 295, 296, 297, 230, 231, 232, 233, 246, 247, - 248, 249, 250, 251, 264, 265, 266, 267, 268, 269, 282, 283, 284, 285, 286, 287, 300, 301, 302, 303, - 292, 293, 306, 307, 308, 309, 310, 311, 324, 325, 326, 327, 328, 329, 342, 343, 344, 345, 346, 347, - 360, 361, 362, 363, 364, 365, 378, 379, 380, 381, 382, 383, 298, 299, 312, 313, 314, 315, 316, 317, - 330, 331, 332, 333, 334, 335, 348, 349, 350, 351, 352, 353, 366, 367, 368, 369, 370, 371, 384, 385, - 386, 387, 388, 389, 304, 305, 318, 319, 320, 321, 322, 323, 336, 337, 338, 339, 340, 341, 354, 355, - 356, 357, 358, 359, 372, 373, 374, 375, 376, 377, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 414, 415, 416, 417, 418, 419, 432, 433, 434, 435, 436, 437, 450, 451, 452, 453, 454, 455, - 468, 469, 470, 471, 472, 473, 486, 487, 488, 489, 490, 491, 504, 505, 506, 507, 508, 509, 402, 403, - 404, 405, 406, 407, 420, 421, 422, 423, 424, 425, 438, 439, 440, 441, 442, 443, 456, 457, 458, 459, - 460, 461, 474, 475, 476, 477, 478, 479, 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, 514, 515, - 408, 409, 410, 411, 412, 413, 426, 427, 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, - 464, 465, 466, 467, 480, 481, 482, 483, 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, - 520, 521, 522, 523, 524, 525, 526, 527, 540, 541, 542, 543, 544, 545, 558, 559, 560, 561, 562, 563, - 528, 529, 530, 531, 532, 533, 546, 547, 548, 549, 550, 551, 564, 565, 566, 567, 568, 569, 534, 535, - 536, 537, 538, 539, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575}, - -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 72, 73, 60, 61, 62, 63, 64, 65, 78, 79, 66, 67, 68, 69, 70, 71, 84, 85, 74, 75, - 76, 77, 90, 91, 92, 93, 94, 95, 80, 81, 82, 83, 96, 97, 98, 99, 100, 101, 86, 87, - 88, 89, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 126, 127, 128, 129, 130, 131, - 114, 115, 116, 117, 118, 119, 132, 133, 134, 135, 136, 137, 120, 121, 122, 123, 124, 125, 138, 139, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 162, 163, 164, 165, 166, 167, 180, 181, 150, 151, - 152, 153, 154, 155, 168, 169, 170, 171, 172, 173, 186, 187, 156, 157, 158, 159, 160, 161, 174, 175, - 176, 177, 178, 179, 192, 193, 182, 183, 184, 185, 198, 199, 200, 201, 202, 203, 216, 217, 218, 219, - 220, 221, 234, 235, 188, 189, 190, 191, 204, 205, 206, 207, 208, 209, 222, 223, 224, 225, 226, 227, - 240, 241, 194, 195, 196, 197, 210, 211, 212, 213, 214, 215, 228, 229, 230, 231, 232, 233, 246, 247, - 236, 237, 238, 239, 252, 253, 254, 255, 256, 257, 270, 271, 272, 273, 274, 275, 288, 289, 290, 291, - 292, 293, 306, 307, 242, 243, 244, 245, 258, 259, 260, 261, 262, 263, 276, 277, 278, 279, 280, 281, - 294, 295, 296, 297, 298, 299, 312, 313, 248, 249, 250, 251, 264, 265, 266, 267, 268, 269, 282, 283, - 284, 285, 286, 287, 300, 301, 302, 303, 304, 305, 318, 319, 308, 309, 310, 311, 324, 325, 326, 327, - 328, 329, 342, 343, 344, 345, 346, 347, 360, 361, 362, 363, 364, 365, 378, 379, 380, 381, 382, 383, - 396, 397, 398, 399, 314, 315, 316, 317, 330, 331, 332, 333, 334, 335, 348, 349, 350, 351, 352, 353, - 366, 367, 368, 369, 370, 371, 384, 385, 386, 387, 388, 389, 402, 403, 404, 405, 320, 321, 322, 323, - 336, 337, 338, 339, 340, 341, 354, 355, 356, 357, 358, 359, 372, 373, 374, 375, 376, 377, 390, 391, - 392, 393, 394, 395, 408, 409, 410, 411, 400, 401, 414, 415, 416, 417, 418, 419, 432, 433, 434, 435, - 436, 437, 450, 451, 452, 453, 454, 455, 468, 469, 470, 471, 472, 473, 486, 487, 488, 489, 490, 491, - 504, 505, 506, 507, 508, 509, 522, 523, 524, 525, 526, 527, 406, 407, 420, 421, 422, 423, 424, 425, - 438, 439, 440, 441, 442, 443, 456, 457, 458, 459, 460, 461, 474, 475, 476, 477, 478, 479, 492, 493, - 494, 495, 496, 497, 510, 511, 512, 513, 514, 515, 528, 529, 530, 531, 532, 533, 412, 413, 426, 427, - 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, 464, 465, 466, 467, 480, 481, 482, 483, - 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, 520, 521, 534, 535, 536, 537, 538, 539, - 540, 541, 542, 543, 544, 545, 558, 559, 560, 561, 562, 563, 546, 547, 548, 549, 550, 551, 564, 565, - 566, 567, 568, 569, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575}, - -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 72, 73, 60, 61, 62, 63, 64, 65, 78, 79, 66, 67, 68, 69, 70, 71, 84, 85, 74, 75, - 76, 77, 90, 91, 92, 93, 94, 95, 80, 81, 82, 83, 96, 97, 98, 99, 100, 101, 86, 87, - 88, 89, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 126, 127, 128, 129, 130, 131, - 114, 115, 116, 117, 118, 119, 132, 133, 134, 135, 136, 137, 120, 121, 122, 123, 124, 125, 138, 139, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 162, 163, 164, 165, 166, 167, 180, 181, 150, 151, - 152, 153, 154, 155, 168, 169, 170, 171, 172, 173, 186, 187, 156, 157, 158, 159, 160, 161, 174, 175, - 176, 177, 178, 179, 192, 193, 182, 183, 184, 185, 198, 199, 200, 201, 202, 203, 216, 217, 218, 219, - 220, 221, 234, 235, 188, 189, 190, 191, 204, 205, 206, 207, 208, 209, 222, 223, 224, 225, 226, 227, - 240, 241, 194, 195, 196, 197, 210, 211, 212, 213, 214, 215, 228, 229, 230, 231, 232, 233, 246, 247, - 236, 237, 238, 239, 252, 253, 254, 255, 256, 257, 270, 271, 272, 273, 274, 275, 288, 289, 290, 291, - 292, 293, 306, 307, 242, 243, 244, 245, 258, 259, 260, 261, 262, 263, 276, 277, 278, 279, 280, 281, - 294, 295, 296, 297, 298, 299, 312, 313, 248, 249, 250, 251, 264, 265, 266, 267, 268, 269, 282, 283, - 284, 285, 286, 287, 300, 301, 302, 303, 304, 305, 318, 319, 308, 309, 310, 311, 324, 325, 326, 327, - 328, 329, 342, 343, 344, 345, 346, 347, 360, 361, 362, 363, 364, 365, 378, 379, 380, 381, 382, 383, - 396, 397, 314, 315, 316, 317, 330, 331, 332, 333, 334, 335, 348, 349, 350, 351, 352, 353, 366, 367, - 368, 369, 370, 371, 384, 385, 386, 387, 388, 389, 402, 403, 320, 321, 322, 323, 336, 337, 338, 339, - 340, 341, 354, 355, 356, 357, 358, 359, 372, 373, 374, 375, 376, 377, 390, 391, 392, 393, 394, 395, - 408, 409, 398, 399, 400, 401, 414, 415, 416, 417, 418, 419, 432, 433, 434, 435, 436, 437, 450, 451, - 452, 453, 454, 455, 468, 469, 470, 471, 472, 473, 486, 487, 488, 489, 490, 491, 504, 505, 506, 507, - 508, 509, 404, 405, 406, 407, 420, 421, 422, 423, 424, 425, 438, 439, 440, 441, 442, 443, 456, 457, - 458, 459, 460, 461, 474, 475, 476, 477, 478, 479, 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, - 514, 515, 410, 411, 412, 413, 426, 427, 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, - 464, 465, 466, 467, 480, 481, 482, 483, 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, - 520, 521, 522, 523, 524, 525, 526, 527, 540, 541, 542, 543, 544, 545, 558, 559, 560, 561, 562, 563, - 528, 529, 530, 531, 532, 533, 546, 547, 548, 549, 550, 551, 564, 565, 566, 567, 568, 569, 534, 535, - 536, 537, 538, 539, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575} -}, -{ -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 42, 43, 44, 45, 48, 49, 50, 51, 40, 41, 54, 55, 56, 57, 46, 47, 60, 61, 62, 63, - 52, 53, 66, 67, 68, 69, 58, 59, 72, 73, 74, 75, 76, 77, 64, 65, 78, 79, 80, 81, - 82, 83, 70, 71, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 108, 109, 110, 111, - 96, 97, 98, 99, 100, 101, 114, 115, 116, 117, 102, 103, 104, 105, 106, 107, 120, 121, 122, 123, - 112, 113, 126, 127, 128, 129, 130, 131, 144, 145, 146, 147, 118, 119, 132, 133, 134, 135, 136, 137, - 150, 151, 152, 153, 124, 125, 138, 139, 140, 141, 142, 143, 156, 157, 158, 159, 148, 149, 162, 163, - 164, 165, 166, 167, 180, 181, 182, 183, 184, 185, 154, 155, 168, 169, 170, 171, 172, 173, 186, 187, - 188, 189, 190, 191, 160, 161, 174, 175, 176, 177, 178, 179, 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 216, 217, 218, 219, 220, 221, 234, 235, 236, 237, 238, 239, 204, 205, 206, 207, - 208, 209, 222, 223, 224, 225, 226, 227, 240, 241, 242, 243, 244, 245, 210, 211, 212, 213, 214, 215, - 228, 229, 230, 231, 232, 233, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 270, 271, - 272, 273, 274, 275, 288, 289, 290, 291, 292, 293, 306, 307, 308, 309, 258, 259, 260, 261, 262, 263, - 276, 277, 278, 279, 280, 281, 294, 295, 296, 297, 298, 299, 312, 313, 314, 315, 264, 265, 266, 267, - 268, 269, 282, 283, 284, 285, 286, 287, 300, 301, 302, 303, 304, 305, 318, 319, 320, 321, 310, 311, - 324, 325, 326, 327, 328, 329, 342, 343, 344, 345, 346, 347, 360, 361, 362, 363, 364, 365, 378, 379, - 380, 381, 382, 383, 396, 397, 398, 399, 316, 317, 330, 331, 332, 333, 334, 335, 348, 349, 350, 351, - 352, 353, 366, 367, 368, 369, 370, 371, 384, 385, 386, 387, 388, 389, 402, 403, 404, 405, 322, 323, - 336, 337, 338, 339, 340, 341, 354, 355, 356, 357, 358, 359, 372, 373, 374, 375, 376, 377, 390, 391, - 392, 393, 394, 395, 408, 409, 410, 411, 400, 401, 414, 415, 416, 417, 418, 419, 432, 433, 434, 435, - 436, 437, 450, 451, 452, 453, 454, 455, 468, 469, 470, 471, 472, 473, 486, 487, 488, 489, 490, 491, - 504, 505, 506, 507, 508, 509, 522, 523, 524, 525, 526, 527, 540, 541, 542, 543, 544, 545, 558, 559, - 560, 561, 562, 563, 406, 407, 420, 421, 422, 423, 424, 425, 438, 439, 440, 441, 442, 443, 456, 457, - 458, 459, 460, 461, 474, 475, 476, 477, 478, 479, 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, - 514, 515, 528, 529, 530, 531, 532, 533, 546, 547, 548, 549, 550, 551, 564, 565, 566, 567, 568, 569, - 412, 413, 426, 427, 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, 464, 465, 466, 467, - 480, 481, 482, 483, 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, 520, 521, 534, 535, - 536, 537, 538, 539, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575}, - -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 42, 43, 44, 45, 48, 49, 50, 51, 40, 41, 54, 55, 56, 57, 46, 47, 60, 61, 62, 63, - 52, 53, 66, 67, 68, 69, 58, 59, 72, 73, 74, 75, 64, 65, 78, 79, 80, 81, 70, 71, - 84, 85, 86, 87, 76, 77, 90, 91, 92, 93, 94, 95, 108, 109, 82, 83, 96, 97, 98, 99, - 100, 101, 114, 115, 88, 89, 102, 103, 104, 105, 106, 107, 120, 121, 110, 111, 112, 113, 126, 127, - 128, 129, 130, 131, 144, 145, 116, 117, 118, 119, 132, 133, 134, 135, 136, 137, 150, 151, 122, 123, - 124, 125, 138, 139, 140, 141, 142, 143, 156, 157, 146, 147, 148, 149, 162, 163, 164, 165, 166, 167, - 180, 181, 182, 183, 152, 153, 154, 155, 168, 169, 170, 171, 172, 173, 186, 187, 188, 189, 158, 159, - 160, 161, 174, 175, 176, 177, 178, 179, 192, 193, 194, 195, 184, 185, 198, 199, 200, 201, 202, 203, - 216, 217, 218, 219, 220, 221, 234, 235, 190, 191, 204, 205, 206, 207, 208, 209, 222, 223, 224, 225, - 226, 227, 240, 241, 196, 197, 210, 211, 212, 213, 214, 215, 228, 229, 230, 231, 232, 233, 246, 247, - 236, 237, 238, 239, 252, 253, 254, 255, 256, 257, 270, 271, 272, 273, 274, 275, 288, 289, 290, 291, - 242, 243, 244, 245, 258, 259, 260, 261, 262, 263, 276, 277, 278, 279, 280, 281, 294, 295, 296, 297, - 248, 249, 250, 251, 264, 265, 266, 267, 268, 269, 282, 283, 284, 285, 286, 287, 300, 301, 302, 303, - 292, 293, 306, 307, 308, 309, 310, 311, 324, 325, 326, 327, 328, 329, 342, 343, 344, 345, 346, 347, - 360, 361, 362, 363, 364, 365, 298, 299, 312, 313, 314, 315, 316, 317, 330, 331, 332, 333, 334, 335, - 348, 349, 350, 351, 352, 353, 366, 367, 368, 369, 370, 371, 304, 305, 318, 319, 320, 321, 322, 323, - 336, 337, 338, 339, 340, 341, 354, 355, 356, 357, 358, 359, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, 383, 396, 397, 398, 399, 400, 401, 414, 415, 416, 417, 418, 419, 432, 433, 434, 435, - 436, 437, 450, 451, 452, 453, 454, 455, 468, 469, 470, 471, 472, 473, 486, 487, 488, 489, 490, 491, - 504, 505, 506, 507, 508, 509, 522, 523, 524, 525, 526, 527, 540, 541, 542, 543, 544, 545, 558, 559, - 560, 561, 562, 563, 384, 385, 386, 387, 388, 389, 402, 403, 404, 405, 406, 407, 420, 421, 422, 423, - 424, 425, 438, 439, 440, 441, 442, 443, 456, 457, 458, 459, 460, 461, 474, 475, 476, 477, 478, 479, - 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, 514, 515, 528, 529, 530, 531, 532, 533, 546, 547, - 548, 549, 550, 551, 564, 565, 566, 567, 568, 569, 390, 391, 392, 393, 394, 395, 408, 409, 410, 411, - 412, 413, 426, 427, 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, 464, 465, 466, 467, - 480, 481, 482, 483, 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, 520, 521, 534, 535, - 536, 537, 538, 539, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575}, - -{ 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15, 4, 5, 18, 19, 10, 11, 24, 25, - 16, 17, 30, 31, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, - 42, 43, 44, 45, 48, 49, 50, 51, 40, 41, 54, 55, 56, 57, 46, 47, 60, 61, 62, 63, - 52, 53, 66, 67, 68, 69, 58, 59, 72, 73, 74, 75, 76, 77, 64, 65, 78, 79, 80, 81, - 82, 83, 70, 71, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 108, 109, 110, 111, - 112, 113, 96, 97, 98, 99, 100, 101, 114, 115, 116, 117, 118, 119, 102, 103, 104, 105, 106, 107, - 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 144, 145, 146, 147, 148, 149, 162, 163, - 164, 165, 132, 133, 134, 135, 136, 137, 150, 151, 152, 153, 154, 155, 168, 169, 170, 171, 138, 139, - 140, 141, 142, 143, 156, 157, 158, 159, 160, 161, 174, 175, 176, 177, 166, 167, 180, 181, 182, 183, - 184, 185, 198, 199, 200, 201, 202, 203, 216, 217, 218, 219, 220, 221, 172, 173, 186, 187, 188, 189, - 190, 191, 204, 205, 206, 207, 208, 209, 222, 223, 224, 225, 226, 227, 178, 179, 192, 193, 194, 195, - 196, 197, 210, 211, 212, 213, 214, 215, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - 252, 253, 254, 255, 256, 257, 270, 271, 272, 273, 274, 275, 288, 289, 290, 291, 292, 293, 306, 307, - 240, 241, 242, 243, 244, 245, 258, 259, 260, 261, 262, 263, 276, 277, 278, 279, 280, 281, 294, 295, - 296, 297, 298, 299, 312, 313, 246, 247, 248, 249, 250, 251, 264, 265, 266, 267, 268, 269, 282, 283, - 284, 285, 286, 287, 300, 301, 302, 303, 304, 305, 318, 319, 308, 309, 310, 311, 324, 325, 326, 327, - 328, 329, 342, 343, 344, 345, 346, 347, 360, 361, 362, 363, 364, 365, 378, 379, 380, 381, 382, 383, - 396, 397, 398, 399, 400, 401, 314, 315, 316, 317, 330, 331, 332, 333, 334, 335, 348, 349, 350, 351, - 352, 353, 366, 367, 368, 369, 370, 371, 384, 385, 386, 387, 388, 389, 402, 403, 404, 405, 406, 407, - 320, 321, 322, 323, 336, 337, 338, 339, 340, 341, 354, 355, 356, 357, 358, 359, 372, 373, 374, 375, - 376, 377, 390, 391, 392, 393, 394, 395, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 432, 433, 434, 435, 436, 437, 450, 451, 452, 453, 454, 455, 468, 469, 470, 471, 472, 473, 486, 487, - 488, 489, 490, 491, 504, 505, 506, 507, 508, 509, 522, 523, 524, 525, 526, 527, 420, 421, 422, 423, - 424, 425, 438, 439, 440, 441, 442, 443, 456, 457, 458, 459, 460, 461, 474, 475, 476, 477, 478, 479, - 492, 493, 494, 495, 496, 497, 510, 511, 512, 513, 514, 515, 528, 529, 530, 531, 532, 533, 426, 427, - 428, 429, 430, 431, 444, 445, 446, 447, 448, 449, 462, 463, 464, 465, 466, 467, 480, 481, 482, 483, - 484, 485, 498, 499, 500, 501, 502, 503, 516, 517, 518, 519, 520, 521, 534, 535, 536, 537, 538, 539, - 540, 541, 542, 543, 544, 545, 558, 559, 560, 561, 562, 563, 546, 547, 548, 549, 550, 551, 564, 565, - 566, 567, 568, 569, 552, 553, 554, 555, 556, 557, 570, 571, 572, 573, 574, 575} -}}; - -#endif diff --git a/Src/Sound/MPEG/position.cpp b/Src/Sound/MPEG/position.cpp deleted file mode 100644 index 296489a..0000000 --- a/Src/Sound/MPEG/position.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * position.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ -/* position.c ffwd/rew within a stream - * - * Creted by: Tomislav Uzelac, May 10 1997 - */ -#include -#include -#include "amp.h" -#include "amp_audio.h" -#include "getbits.h" - -#define POSITION -#include "position.h" - -/* Returns the number of frames actually skipped, -1 on error. - * - * Values in header are not changed if retval!=nframes. - * This is not necessary because gethdr() doesn't clobber - * the contents of header, but I don't want to rely on that. - */ -int ffwd(struct AUDIO_HEADER *header, int nframes) -{ -int cnt=0,g; -int hsize,bitrate,fs,mean_frame_size; -struct AUDIO_HEADER tmp; - memcpy(&tmp,header,sizeof(tmp)); - - while (cnt < nframes) { - if (tmp.ID) - if (tmp.mode==3) hsize=21; - else hsize=36; - else - if (tmp.mode==3) hsize=13; - else hsize=21; - if (tmp.protection_bit==0) hsize+=2; - if ((g=dummy_getinfo(hsize))) /* dummy_getinfo: reads hsize-4 bytes */ - switch (g) { - case GETHDR_EOF: return cnt; - case GETHDR_ERR: - default: return -1; - } - - bitrate=t_bitrate[tmp.ID][3-tmp.layer][tmp.bitrate_index]; - fs=t_sampling_frequency[tmp.ID][tmp.sampling_frequency]; - if (tmp.ID) mean_frame_size=144000*bitrate/fs; - else mean_frame_size=72000*bitrate/fs; - fillbfr(mean_frame_size + tmp.padding_bit - hsize); - - if ((g=gethdr(&tmp))) - switch (g) { - case GETHDR_EOF: return cnt; - case GETHDR_ERR: - default: return -1; - } - cnt++; - } - - memcpy(header,&tmp,sizeof(tmp)); - return cnt; -} - -/* Mostly the same as ffwd. Some streams might be 'tough', i.e. - * the ones switching bitrates. - */ -int rew(struct AUDIO_HEADER *header, int nframes) -{ -int cnt=0; -int bitrate,fs,mean_frame_size; -struct AUDIO_HEADER tmp; - memcpy(&tmp,header,sizeof(tmp)); - - while (cnt < nframes) { - /* ffwd/rew functions are to be called right after the header has been parsed - * so we have to go back one frame + 4 bytes + 1 byte (in case padding was used). - */ - bitrate=t_bitrate[tmp.ID][3-tmp.layer][tmp.bitrate_index]; - fs=t_sampling_frequency[tmp.ID][tmp.sampling_frequency]; - if (tmp.ID) mean_frame_size=144000*bitrate/fs; - else mean_frame_size=72000*bitrate/fs; - - if (rewind_stream(mean_frame_size) !=0) { - memcpy(header,&tmp,sizeof(tmp)); - return cnt; - } - if ((gethdr(&tmp))) return -1; - cnt++; - } - /* We have to make sure that the bit reservoir contains enough data. - * Hopefully, layer3_frame will take care of that. - */ - f_bdirty=TRUE; - bclean_bytes=0; - - memcpy(header,&tmp,sizeof(tmp)); - return cnt; -} - -/* TODO: after the gethdr function is enhanced with the counter to count - * the number of bytes to search for the next syncword, make the call to - * gethdr() from rew() have that counter something like (frame_size-1) so - * that we don't go back again and again to the same header. (not very important) - */ diff --git a/Src/Sound/MPEG/position.h b/Src/Sound/MPEG/position.h deleted file mode 100644 index 0b6f736..0000000 --- a/Src/Sound/MPEG/position.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * position.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -extern int ffwd(struct AUDIO_HEADER *header, int nframes); -extern int rew(struct AUDIO_HEADER *header, int nframes); - -#ifdef POSITION -int ffwd(struct AUDIO_HEADER *header, int nframes); -int rew(struct AUDIO_HEADER *header, int nframes); -#endif diff --git a/Src/Sound/MPEG/proto.h b/Src/Sound/MPEG/proto.h deleted file mode 100644 index a4c4d4b..0000000 --- a/Src/Sound/MPEG/proto.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * proto.h - * - * Amp library internal header file. - */ - - -/* From: util.c */ -void die(char *, ...); -void warn(char *, ...); -void msg(char *, ...); -void debugSetup(char *); -void debugOptions(); - -/* From: audioIO_.c */ -void audioOpen(int frequency, int stereo, int volume); -void audioSetVolume(int); -void audioFlush(); -void audioClose(); -int audioWrite(char *, int); -int getAudioFd(); -void audioBufferOn(int); - - -/* From: buffer.c */ -void printout(void); -int audioBufferOpen(int, int, int); -void audioBufferClose(); -void audioBufferWrite(char *, int); -void audioBufferFlush(); - -/* From: audio.c */ -void displayUsage(); diff --git a/Src/Sound/MPEG/rtbuf.h b/Src/Sound/MPEG/rtbuf.h deleted file mode 100644 index 7d24c38..0000000 --- a/Src/Sound/MPEG/rtbuf.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * rtbuf.h - * - * Amp library internal header file. - */ - - -/*****************************************************************************/ - -/* - * rtbuf.h -- Linux realtime audio output. - * - * Copyright (C) 1996 Thomas Sailer (sailer@ife.ee.ethz.ch) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * This is the Linux realtime sound output driver - */ - -/*****************************************************************************/ - -#include "config.h" - -#ifndef HAVE_MLOCKALL -#undef LINUX_REALTIME -#endif - -#ifndef HAVE_SCHED_SETSCHEDULER -#undef LINUX_REALTIME -#endif - -#if 0 -#ifndef _POSIX_MEMLOCK -#undef LINUX_REALTIME -#endif - -#ifndef _POSIX_PRIORITY_SCHEDULING -#undef LINUX_REALTIME -#endif -#endif - -#ifdef LINUX_REALTIME - -int prefetch_get_input(unsigned char *bp, int bytes); -int rt_play(char *file); -void rt_printout(short *sbuf, int ln); -int setup_fancy_audio(struct AUDIO_HEADER *mpegheader); -int start_fancy_audio(struct AUDIO_HEADER *mpegheader); -int stop_fancy_audio(void); -int block_fancy_audio(int snd_eof); -int ready_fancy_audio(void); -void cleanup_fancy_audio(void); -void prefetch_initial_fill(void); -int set_realtime_priority(void); - -#endif /* LINUX_REALTIME */ - diff --git a/Src/Sound/MPEG/transform.cpp b/Src/Sound/MPEG/transform.cpp deleted file mode 100644 index a57b4bc..0000000 --- a/Src/Sound/MPEG/transform.cpp +++ /dev/null @@ -1,1546 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * transform.cpp - * - * Amp library internal module. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* transform.c imdct and polyphase(DCT) transforms - * - * Created by: tomislav uzelac May 1996 - * Karl Anders Oygard optimized this for speed, Mar 13 97 - * Some optimisations based on ideas from Michael Hipp's mpg123 package - */ - -/* - * Comments for this file: - * - * The polyphase algorithm is clearly the most cpu consuming part of mpeg 1 - * layer 3 decoding. Thus, there has been some effort to optimise this - * particular algorithm. Currently, everything has been kept in straight C - * with no assembler optimisations, but in order to provide efficient paths - * for different architectures, alternative implementations of some - * critical sections has been done. You may want to experiment with these, - * to see which suits your architecture better. - * - * Selection of the different implementations is done with the following - * defines: - * - * HAS_AUTOINCREMENT - * - * Define this if your architecture supports preincrementation of - * pointers when referencing (applies to e.g. 68k) - * - * For those who are optimising amp, check out the Pentium rdtsc code - * (define PENTIUM_RDTSC). This code uses the rdtsc counter for showing - * how many cycles are spent in different parts of the code. - */ - -#include - -#include "amp_audio.h" -#include "getdata.h" -#include "misc2.h" - -#define TRANSFORM -#include "transform.h" - -#define PI12 0.261799387f -#define PI36 0.087266462f - -void imdct_init() -{ - int i; - - for(i=0;i<36;i++) /* 0 */ - win[0][i] = (float) sin(PI36 *(i+0.5)); - for(i=0;i<18;i++) /* 1 */ - win[1][i] = (float) sin(PI36 *(i+0.5)); - for(i=18;i<24;i++) - win[1][i] = 1.0f; - for(i=24;i<30;i++) - win[1][i] = (float) sin(PI12 *(i+0.5-18)); - for(i=30;i<36;i++) - win[1][i] = 0.0f; - for(i=0;i<6;i++) /* 3 */ - win[3][i] = 0.0f; - for(i=6;i<12;i++) - win[3][i] = (float) sin(PI12 * (i+ 0.5 - 6.0)); - for(i=12;i<18;i++) - win[3][i] = 1.0f; - for(i=18;i<36;i++) - win[3][i] = (float) sin(PI36 * (i + 0.5)); -} - -/* This uses Byeong Gi Lee's Fast Cosine Transform algorithm to decompose - the 36 point and 12 point IDCT's into 9 point and 3 point IDCT's, - respectively. Then the 9 point IDCT is computed by a modified version of - Mikko Tommila's IDCT algorithm, based on the WFTA. See his comments - before the first 9 point IDCT. The 3 point IDCT is already efficient to - implement. -- Jeff Tsay. */ -/* I got the unrolled IDCT from Jeff Tsay; the code is presumably by - Francois-Raymond Boyer - I unrolled it a little further. tu */ - -void imdct(int win_type,int sb,int ch) -{ -/*------------------------------------------------------------------*/ -/* */ -/* Function: Calculation of the inverse MDCT */ -/* In the case of short blocks the 3 output vectors are already */ -/* overlapped and added in this modul. */ -/* */ -/* New layer3 */ -/* */ -/*------------------------------------------------------------------*/ - - float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp11; - - register float save; - float pp1, pp2; - float *win_bt; - int i, p, ss; - float *in = xr[ch][sb]; - float *s_p = s[ch][sb]; - float *res_p = res[sb]; - float out[36]; - - if(win_type == 2){ - for(p=0;p<36;p+=9) { - out[p] = out[p+1] = out[p+2] = out[p+3] = - out[p+4] = out[p+5] = out[p+6] = out[p+7] = - out[p+8] = 0.0f; - } - - for(ss=0;ss<18;ss+=6) { - - /* - * 12 point IMDCT - */ - - /* Begin 12 point IDCT */ - - /* Input aliasing for 12 pt IDCT */ - in[5+ss]+=in[4+ss];in[4+ss]+=in[3+ss];in[3+ss]+=in[2+ss]; - in[2+ss]+=in[1+ss];in[1+ss]+=in[0+ss]; - - /* Input aliasing on odd indices (for 6 point IDCT) */ - in[5+ss] += in[3+ss]; in[3+ss] += in[1+ss]; - - /* 3 point IDCT on even indices */ - - pp2 = in[4+ss] * 0.500000000f; - pp1 = in[2+ss] * 0.866025403f; - save = in[0+ss] + pp2; - tmp1 = in[0+ss] - in[4+ss]; - tmp0 = save + pp1; - tmp2 = save - pp1; - - /* End 3 point IDCT on even indices */ - - /* 3 point IDCT on odd indices (for 6 point IDCT) */ - - pp2 = in[5+ss] * 0.500000000f; - pp1 = in[3+ss] * 0.866025403f; - save = in[1+ss] + pp2; - tmp4 = in[1+ss] - in[5+ss]; - tmp5 = save + pp1; - tmp3 = save - pp1; - - /* End 3 point IDCT on odd indices */ - - /* Twiddle factors on odd indices (for 6 point IDCT) */ - - tmp3 *= 1.931851653f; - tmp4 *= 0.707106781f; - tmp5 *= 0.517638090f; - - /* Output butterflies on 2 3 point IDCT's (for 6 point IDCT) */ - - save = tmp0; - tmp0 += tmp5; - tmp5 = save - tmp5; - - save = tmp1; - tmp1 += tmp4; - tmp4 = save - tmp4; - - save = tmp2; - tmp2 += tmp3; - tmp3 = save - tmp3; - - /* End 6 point IDCT */ - - /* Twiddle factors on indices (for 12 point IDCT) */ - - tmp0 *= 0.504314480f; - tmp1 *= 0.541196100f; - tmp2 *= 0.630236207f; - tmp3 *= 0.821339815f; - tmp4 *= 1.306562965f; - tmp5 *= 3.830648788f; - - /* End 12 point IDCT */ - - /* Shift to 12 point modified IDCT, multiply by window type 2 */ - tmp8 = tmp0 * -0.793353340f; - tmp9 = tmp0 * -0.608761429f; - tmp7 = tmp1 * -0.923879532f; - tmp10 = tmp1 * -0.382683432f; - tmp6 = tmp2 * -0.991444861f; - tmp11 = tmp2 * -0.130526192f; - - tmp0 = tmp3; - tmp1 = tmp4 * 0.382683432f; - tmp2 = tmp5 * 0.608761429f; - - tmp3 = tmp5 * -0.793353340f; - tmp4 = tmp4 * -0.923879532f; - tmp5 = tmp0 * -0.991444861f; - - tmp0 *= 0.130526192f; - - out[ss + 6] += tmp0; - out[ss + 7] += tmp1; - out[ss + 8] += tmp2; - out[ss + 9] += tmp3; - out[ss + 10] += tmp4; - out[ss + 11] += tmp5; - out[ss + 12] += tmp6; - out[ss + 13] += tmp7; - out[ss + 14] += tmp8; - out[ss + 15] += tmp9; - out[ss + 16] += tmp10; - out[ss + 17] += tmp11; - - } - if (sb&1) { - for (i=0;i<18;i+=2) res_p[i]=out[i] + s_p[i]; - for (i=1;i<18;i+=2) res_p[i]=-out[i] - s_p[i]; - } else - for (i=0;i<18;i++) res_p[i]=out[i] + s_p[i]; - for (i=18;i<36;i++) s_p[i-18]=out[i]; - - } else { -/* - * 36 point IDCT **************************************************************** - */ - float tmp[18]; - - /* input aliasing for 36 point IDCT */ - in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; in[14]+=in[13]; - in[13]+=in[12]; in[12]+=in[11]; in[11]+=in[10]; in[10]+=in[9]; - in[9] +=in[8]; in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; - in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; in[2] +=in[1]; - in[1] +=in[0]; - - /* 18 point IDCT for odd indices */ - - /* input aliasing for 18 point IDCT */ - in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; - in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; - - -{ - float tmp0,tmp1,tmp2,tmp3,tmp4,tmp0_,tmp1_,tmp2_,tmp3_; - float tmp0o,tmp1o,tmp2o,tmp3o,tmp4o,tmp0_o,tmp1_o,tmp2_o,tmp3_o; - -/* Fast 9 Point Inverse Discrete Cosine Transform -// -// By Francois-Raymond Boyer -// mailto:boyerf@iro.umontreal.ca -// http://www.iro.umontreal.ca/~boyerf -// -// The code has been optimized for Intel processors -// (takes a lot of time to convert float to and from iternal FPU representation) -// -// It is a simple "factorization" of the IDCT matrix. -*/ - /* 9 point IDCT on even indices */ - { - /* 5 points on odd indices (not realy an IDCT) */ - float i0 = in[0]+in[0]; - float i0p12 = i0 + in[12]; - - tmp0 = i0p12 + in[4]*1.8793852415718f + in[8]*1.532088886238f + in[16]*0.34729635533386f; - tmp1 = i0 + in[4] - in[8] - in[12] - in[12] - in[16]; - tmp2 = i0p12 - in[4]*0.34729635533386f - in[8]*1.8793852415718f + in[16]*1.532088886238f; - tmp3 = i0p12 - in[4]*1.532088886238f + in[8]*0.34729635533386f - in[16]*1.8793852415718f; - tmp4 = in[0] - in[4] + in[8] - in[12] + in[16]; - } - { - float i6_ = in[6]*1.732050808f; - - tmp0_ = in[2]*1.9696155060244f + i6_ + in[10]*1.2855752193731f + in[14]*0.68404028665134f; - tmp1_ = (in[2] - in[10] - in[14])*1.732050808f; - tmp2_ = in[2]*1.2855752193731f - i6_ - in[10]*0.68404028665134f + in[14]*1.9696155060244f; - tmp3_ = in[2]*0.68404028665134f - i6_ + in[10]*1.9696155060244f - in[14]*1.2855752193731f; - } - - /* 9 point IDCT on odd indices */ - { - /* 5 points on odd indices (not realy an IDCT) */ - float i0 = in[0+1]+in[0+1]; - float i0p12 = i0 + in[12+1]; - - tmp0o = i0p12 + in[4+1]*1.8793852415718f + in[8+1]*1.532088886238f + in[16+1]*0.34729635533386f; - tmp1o = i0 + in[4+1] - in[8+1] - in[12+1] - in[12+1] - in[16+1]; - tmp2o = i0p12 - in[4+1]*0.34729635533386f - in[8+1]*1.8793852415718f + in[16+1]*1.532088886238f; - tmp3o = i0p12 - in[4+1]*1.532088886238f + in[8+1]*0.34729635533386f - in[16+1]*1.8793852415718f; - tmp4o = (in[0+1] - in[4+1] + in[8+1] - in[12+1] + in[16+1])*0.707106781f; /* Twiddled */ - } - { - /* 4 points on even indices */ - float i6_ = in[6+1]*1.732050808f; /* Sqrt[3] */ - - tmp0_o = in[2+1]*1.9696155060244f + i6_ + in[10+1]*1.2855752193731f + in[14+1]*0.68404028665134f; - tmp1_o = (in[2+1] - in[10+1] - in[14+1])*1.732050808f; - tmp2_o = in[2+1]*1.2855752193731f - i6_ - in[10+1]*0.68404028665134f + in[14+1]*1.9696155060244f; - tmp3_o = in[2+1]*0.68404028665134f - i6_ + in[10+1]*1.9696155060244f - in[14+1]*1.2855752193731f; - } - - /* Twiddle factors on odd indices - // and - // Butterflies on 9 point IDCT's - // and - // twiddle factors for 36 point IDCT - */ - { - float e, o; - e = tmp0 + tmp0_; o = (tmp0o + tmp0_o)*0.501909918f; tmp[0] = (e + o)*(-0.500476342f*.5f); tmp[17] = (e - o)*(-11.46279281f*.5f); - e = tmp1 + tmp1_; o = (tmp1o + tmp1_o)*0.517638090f; tmp[1] = (e + o)*(-0.504314480f*.5f); tmp[16] = (e - o)*(-3.830648788f*.5f); - e = tmp2 + tmp2_; o = (tmp2o + tmp2_o)*0.551688959f; tmp[2] = (e + o)*(-0.512139757f*.5f); tmp[15] = (e - o)*(-2.310113158f*.5f); - e = tmp3 + tmp3_; o = (tmp3o + tmp3_o)*0.610387294f; tmp[3] = (e + o)*(-0.524264562f*.5f); tmp[14] = (e - o)*(-1.662754762f*.5f); - tmp[4] = (tmp4 + tmp4o)*(-0.541196100f); tmp[13] = (tmp4 - tmp4o)*(-1.306562965f); - e = tmp3 - tmp3_; o = (tmp3o - tmp3_o)*0.871723397f; tmp[5] = (e + o)*(-0.563690973f*.5f); tmp[12] = (e - o)*(-1.082840285f*.5f); - e = tmp2 - tmp2_; o = (tmp2o - tmp2_o)*1.183100792f; tmp[6] = (e + o)*(-0.592844523f*.5f); tmp[11] = (e - o)*(-0.930579498f*.5f); - e = tmp1 - tmp1_; o = (tmp1o - tmp1_o)*1.931851653f; tmp[7] = (e + o)*(-0.630236207f*.5f); tmp[10] = (e - o)*(-0.821339815f*.5f); - e = tmp0 - tmp0_; o = (tmp0o - tmp0_o)*5.736856623f; tmp[8] = (e + o)*(-0.678170852f*.5f); tmp[9] = (e - o)*(-0.740093616f*.5f); - } - } - /* shift to modified IDCT */ - win_bt = win[win_type]; - - if (sb&1) { - res_p[0] = -tmp[9] * win_bt[0] + s_p[0]; - res_p[1] =-(-tmp[10] * win_bt[1] + s_p[1]); - res_p[2] = -tmp[11] * win_bt[2] + s_p[2]; - res_p[3] =-(-tmp[12] * win_bt[3] + s_p[3]); - res_p[4] = -tmp[13] * win_bt[4] + s_p[4]; - res_p[5] =-(-tmp[14] * win_bt[5] + s_p[5]); - res_p[6] = -tmp[15] * win_bt[6] + s_p[6]; - res_p[7] =-(-tmp[16] * win_bt[7] + s_p[7]); - res_p[8] = -tmp[17] * win_bt[8] + s_p[8]; - - res_p[9] = -(tmp[17] * win_bt[9] + s_p[9]); - res_p[10]= tmp[16] * win_bt[10] + s_p[10]; - res_p[11]=-(tmp[15] * win_bt[11] + s_p[11]); - res_p[12]= tmp[14] * win_bt[12] + s_p[12]; - res_p[13]=-(tmp[13] * win_bt[13] + s_p[13]); - res_p[14]= tmp[12] * win_bt[14] + s_p[14]; - res_p[15]=-(tmp[11] * win_bt[15] + s_p[15]); - res_p[16]= tmp[10] * win_bt[16] + s_p[16]; - res_p[17]=-(tmp[9] * win_bt[17] + s_p[17]); - } else { - res_p[0] = -tmp[9] * win_bt[0] + s_p[0]; - res_p[1] = -tmp[10] * win_bt[1] + s_p[1]; - res_p[2] = -tmp[11] * win_bt[2] + s_p[2]; - res_p[3] = -tmp[12] * win_bt[3] + s_p[3]; - res_p[4] = -tmp[13] * win_bt[4] + s_p[4]; - res_p[5] = -tmp[14] * win_bt[5] + s_p[5]; - res_p[6] = -tmp[15] * win_bt[6] + s_p[6]; - res_p[7] = -tmp[16] * win_bt[7] + s_p[7]; - res_p[8] = -tmp[17] * win_bt[8] + s_p[8]; - - res_p[9] = tmp[17] * win_bt[9] + s_p[9]; - res_p[10]= tmp[16] * win_bt[10] + s_p[10]; - res_p[11]= tmp[15] * win_bt[11] + s_p[11]; - res_p[12]= tmp[14] * win_bt[12] + s_p[12]; - res_p[13]= tmp[13] * win_bt[13] + s_p[13]; - res_p[14]= tmp[12] * win_bt[14] + s_p[14]; - res_p[15]= tmp[11] * win_bt[15] + s_p[15]; - res_p[16]= tmp[10] * win_bt[16] + s_p[16]; - res_p[17]= tmp[9] * win_bt[17] + s_p[17]; - } - - s_p[0]= tmp[8] * win_bt[18]; - s_p[1]= tmp[7] * win_bt[19]; - s_p[2]= tmp[6] * win_bt[20]; - s_p[3]= tmp[5] * win_bt[21]; - s_p[4]= tmp[4] * win_bt[22]; - s_p[5]= tmp[3] * win_bt[23]; - s_p[6]= tmp[2] * win_bt[24]; - s_p[7]= tmp[1] * win_bt[25]; - s_p[8]= tmp[0] * win_bt[26]; - - s_p[9]= tmp[0] * win_bt[27]; - s_p[10]= tmp[1] * win_bt[28]; - s_p[11]= tmp[2] * win_bt[29]; - s_p[12]= tmp[3] * win_bt[30]; - s_p[13]= tmp[4] * win_bt[31]; - s_p[14]= tmp[5] * win_bt[32]; - s_p[15]= tmp[6] * win_bt[33]; - s_p[16]= tmp[7] * win_bt[34]; - s_p[17]= tmp[8] * win_bt[35]; - } -} - -/* fast DCT according to Lee[84] - * reordering according to Konstantinides[94] - */ -void poly(const int ch,int f) -{ -static float u[2][2][17][16]; /* no v[][], it's redundant */ -static int u_start[2]={0,0}; /* first element of u[][] */ -static int u_div[2]={0,0}; /* which part of u[][] is currently used */ -int start = u_start[ch]; -int div = u_div[ch]; -float (*u_p)[16]; - -#if defined(PENTIUM_RDTSC) -unsigned int cnt4, cnt3, cnt2, cnt1; -static int min_cycles = 99999999; - - __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt4)); -#endif - - { - float d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30,d31; - float d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15; - - /* step 1: initial reordering and 1st (16 wide) butterflies - */ - - d0 = res[ 0][f]; d16=(d0 - res[31][f]) * b1; d0 += res[31][f]; - d1 = res[ 1][f]; d17=(d1 - res[30][f]) * b3; d1 += res[30][f]; - d3 = res[ 2][f]; d19=(d3 - res[29][f]) * b5; d3 += res[29][f]; - d2 = res[ 3][f]; d18=(d2 - res[28][f]) * b7; d2 += res[28][f]; - d6 = res[ 4][f]; d22=(d6 - res[27][f]) * b9; d6 += res[27][f]; - d7 = res[ 5][f]; d23=(d7 - res[26][f]) * b11; d7 += res[26][f]; - d5 = res[ 6][f]; d21=(d5 - res[25][f]) * b13; d5 += res[25][f]; - d4 = res[ 7][f]; d20=(d4 - res[24][f]) * b15; d4 += res[24][f]; - d12= res[ 8][f]; d28=(d12 - res[23][f]) * b17; d12+= res[23][f]; - d13= res[ 9][f]; d29=(d13 - res[22][f]) * b19; d13+= res[22][f]; - d15= res[10][f]; d31=(d15 - res[21][f]) * b21; d15+= res[21][f]; - d14= res[11][f]; d30=(d14 - res[20][f]) * b23; d14+= res[20][f]; - d10= res[12][f]; d26=(d10 - res[19][f]) * b25; d10+= res[19][f]; - d11= res[13][f]; d27=(d11 - res[18][f]) * b27; d11+= res[18][f]; - d9 = res[14][f]; d25=(d9 - res[17][f]) * b29; d9 += res[17][f]; - d8 = res[15][f]; d24=(d8 - res[16][f]) * b31; d8 += res[16][f]; - - { - float c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15; - -/* a test to see what can be done with memory separation - * first we process indexes 0-15 -*/ - c0 = d0 + d8 ; c8 = ( d0 - d8 ) * b2; - c1 = d1 + d9 ; c9 = ( d1 - d9 ) * b6; - c2 = d2 + d10; c10= ( d2 - d10) * b14; - c3 = d3 + d11; c11= ( d3 - d11) * b10; - c4 = d4 + d12; c12= ( d4 - d12) * b30; - c5 = d5 + d13; c13= ( d5 - d13) * b26; - c6 = d6 + d14; c14= ( d6 - d14) * b18; - c7 = d7 + d15; c15= ( d7 - d15) * b22; - - /* step 3: 4-wide butterflies - */ - d0 = c0 + c4 ; d4 = ( c0 - c4 ) * b4; - d1 = c1 + c5 ; d5 = ( c1 - c5 ) * b12; - d2 = c2 + c6 ; d6 = ( c2 - c6 ) * b28; - d3 = c3 + c7 ; d7 = ( c3 - c7 ) * b20; - - d8 = c8 + c12; d12= ( c8 - c12) * b4; - d9 = c9 + c13; d13= ( c9 - c13) * b12; - d10= c10+ c14; d14= (c10 - c14) * b28; - d11= c11+ c15; d15= (c11 - c15) * b20; - - - /* step 4: 2-wide butterflies - */ - { - float rb8 = b8; - float rb24 = b24; - -/**/ c0 = d0 + d2 ; c2 = ( d0 - d2 ) * rb8; - c1 = d1 + d3 ; c3 = ( d1 - d3 ) * rb24; -/**/ c4 = d4 + d6 ; c6 = ( d4 - d6 ) * rb8; - c5 = d5 + d7 ; c7 = ( d5 - d7 ) * rb24; -/**/ c8 = d8 + d10; c10= ( d8 - d10) * rb8; - c9 = d9 + d11; c11= ( d9 - d11) * rb24; -/**/ c12= d12+ d14; c14= (d12 - d14) * rb8; - c13= d13+ d15; c15= (d13 - d15) * rb24; - } - - /* step 5: 1-wide butterflies - */ - { - float rb16 = b16; - - /* this is a little 'hacked up' - */ - d0 = (-c0 -c1) * 2; d1 = ( c0 - c1 ) * rb16; - d2 = c2 + c3; d3 = ( c2 - c3 ) * rb16; - d3 -= d2; - - d4 = c4 +c5; d5 = ( c4 - c5 ) * rb16; - d5 += d4; - d7 = -d5; - d7 += ( c6 - c7 ) * rb16; d6 = +c6 +c7; - - d8 = c8 + c9 ; d9 = ( c8 - c9 ) * rb16; - d11= +d8 +d9; - d11 +=(c10 - c11) * rb16; d10= c10+ c11; - - d12 = c12+ c13; d13 = (c12 - c13) * rb16; - d13 += -d8-d9+d12; - d14 = c14+ c15; d15 = (c14 - c15) * rb16; - d15-=d11; - d14 += -d8 -d10; - } - - /* step 6: final resolving & reordering - * the other 32 are stored for use with the next granule - */ - - u_p = (float (*)[16]) &u[ch][div][0][start]; - -/*16*/ u_p[ 0][0] =+d1 ; - u_p[ 2][0] = +d9 -d14; -/*20*/ u_p[ 4][0] = +d5 -d6; - u_p[ 6][0] = -d10 +d13; -/*24*/ u_p[ 8][0] =d3; - u_p[10][0] = -d8 -d9 +d11 -d13; -/*28*/ u_p[12][0] = +d7; - u_p[14][0] = +d15; - - /* the other 32 are stored for use with the next granule - */ - - u_p = (float (*)[16]) &u[ch][!div][0][start]; - -/*0*/ u_p[16][0] = d0; - u_p[14][0] = -(+d8 ); -/*4*/ u_p[12][0] = -(+d4 ); - u_p[10][0] = -(-d8 +d12 ); -/*8*/ u_p[ 8][0] = -(+d2 ); - u_p[ 6][0] = -(+d8 +d10 -d12 ); -/*12*/ u_p[ 4][0] = -(-d4 +d6 ); - u_p[ 2][0] = -d14; - u_p[ 0][0] = -d1; - } - - { - float c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15; - -/* memory separation, second part -*/ -/* 2 -*/ - c0=d16 + d24; c8= (d16 - d24) * b2; - c1=d17 + d25; c9= (d17 - d25) * b6; - c2=d18 + d26; c10= (d18 - d26) * b14; - c3=d19 + d27; c11= (d19 - d27) * b10; - c4=d20 + d28; c12= (d20 - d28) * b30; - c5=d21 + d29; c13= (d21 - d29) * b26; - c6=d22 + d30; c14= (d22 - d30) * b18; - c7=d23 + d31; c15= (d23 - d31) * b22; - -/* 3 -*/ - d16= c0+ c4; d20= (c0 - c4) * b4; - d17= c1+ c5; d21= (c1 - c5) * b12; - d18= c2+ c6; d22= (c2 - c6) * b28; - d19= c3+ c7; d23= (c3 - c7) * b20; - - d24= c8+ c12; d28= (c8 - c12) * b4; - d25= c9+ c13; d29= (c9 - c13) * b12; - d26= c10+ c14; d30= (c10 - c14) * b28; - d27= c11+ c15; d31= (c11 - c15) * b20; - -/* 4 -*/ - { - float rb8 = b8; - float rb24 = b24; - -/**/ c0= d16+ d18; c2= (d16 - d18) * rb8; - c1= d17+ d19; c3= (d17 - d19) * rb24; -/**/ c4= d20+ d22; c6= (d20 - d22) * rb8; - c5= d21+ d23; c7= (d21 - d23) * rb24; -/**/ c8= d24+ d26; c10= (d24 - d26) * rb8; - c9= d25+ d27; c11= (d25 - d27) * rb24; -/**/ c12= d28+ d30; c14= (d28 - d30) * rb8; - c13= d29+ d31; c15= (d29 - d31) * rb24; - } - -/* 5 -*/ - { - float rb16 = b16; - d16= c0+ c1; d17= (c0 - c1) * rb16; - d18= c2+ c3; d19= (c2 - c3) * rb16; - - d20= c4+ c5; d21= (c4 - c5) * rb16; - d20+=d16; d21+=d17; - d22= c6+ c7; d23= (c6 - c7) * rb16; - d22+=d16; d22+=d18; - d23+=d16; d23+=d17; d23+=d19; - - - d24= c8+ c9; d25= (c8 - c9) * rb16; - d26= c10+ c11; d27= (c10 - c11) * rb16; - d26+=d24; - d27+=d24; d27+=d25; - - d28= c12+ c13; d29= (c12 - c13) * rb16; - d28-=d20; d29+=d28; d29-=d21; - d30= c14+ c15; d31= (c14 - c15) * rb16; - d30-=d22; - d31-=d23; - } - - /* step 6: final resolving & reordering - * the other 32 are stored for use with the next granule - */ - - u_p = (float (*)[16]) &u[ch][!div][0][start]; - - u_p[ 1][0] = -(+d30 ); - u_p[ 3][0] = -(+d22 -d26 ); - u_p[ 5][0] = -(-d18 -d20 +d26 ); - u_p[ 7][0] = -(+d18 -d28 ); - u_p[ 9][0] = -(+d28 ); - u_p[11][0] = -(+d20 -d24 ); - u_p[13][0] = -(-d16 +d24 ); - u_p[15][0] = -(+d16 ); - - /* the other 32 are stored for use with the next granule - */ - - u_p = (float (*)[16]) &u[ch][div][0][start]; - - u_p[15][0] = +d31; - u_p[13][0] = +d23 -d27; - u_p[11][0] = -d19 -d20 -d21 +d27; - u_p[ 9][0] = +d19 -d29; - u_p[ 7][0] = -d18 +d29; - u_p[ 5][0] = +d18 +d20 +d21 -d25 -d26; - u_p[ 3][0] = -d17 -d22 +d25 +d26; - u_p[ 1][0] = +d17 -d30; - } - } - -#if defined(PENTIUM_RDTSC) - __asm__(".byte 0x0f,0x31" : "=a" (cnt3), "=d" (cnt4)); -#endif - - /* we're doing dewindowing and calculating final samples now - */ - -#if defined(ARCH_i586) - /* x86 assembler optimisations. These optimisations are tuned - specifically for Intel Pentiums. */ - - asm("movl $15,%%eax\n\t"\ - "1:\n\t"\ - "flds (%0)\n\t"\ - "fmuls (%1)\n\t"\ - "flds 4(%0)\n\t"\ - "fmuls 4(%1)\n\t"\ - "flds 8(%0)\n\t"\ - "fmuls 8(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 12(%0)\n\t"\ - "fmuls 12(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 16(%0)\n\t"\ - "fmuls 16(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 20(%0)\n\t"\ - "fmuls 20(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 24(%0)\n\t"\ - "fmuls 24(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 28(%0)\n\t"\ - "fmuls 28(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 32(%0)\n\t"\ - "fmuls 32(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 36(%0)\n\t"\ - "fmuls 36(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 40(%0)\n\t"\ - "fmuls 40(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 44(%0)\n\t"\ - "fmuls 44(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 48(%0)\n\t"\ - "fmuls 48(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 52(%0)\n\t"\ - "fmuls 52(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 56(%0)\n\t"\ - "fmuls 56(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 60(%0)\n\t"\ - "fmuls 60(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "addl $64,%0\n\t"\ - "addl $128,%1\n\t"\ - "subl $4,%%esp\n\t"\ - "faddp\n\t"\ - "fistpl (%%esp)\n\t"\ - "popl %%ecx\n\t"\ - "cmpl $32767,%%ecx\n\t"\ - "jle 2f\n\t"\ - "movw $32767,%%cx\n\t"\ - "jmp 3f\n\t"\ - "2: cmpl $-32768,%%ecx\n\t"\ - "jge 3f\n\t"\ - "movw $-32768,%%cx\n\t"\ - "3: movw %%cx,(%2)\n\t"\ - "addl %3,%2\n\t"\ - "decl %%eax\n\t"\ - "jns 1b\n\t"\ - - "testb $1,%4\n\t"\ - "je 4f\n\t" - - "flds (%0)\n\t"\ - "fmuls (%1)\n\t"\ - "flds 8(%0)\n\t"\ - "fmuls 8(%1)\n\t"\ - "flds 16(%0)\n\t"\ - "fmuls 16(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 24(%0)\n\t"\ - "fmuls 24(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 32(%0)\n\t"\ - "fmuls 32(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 40(%0)\n\t"\ - "fmuls 40(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 48(%0)\n\t"\ - "fmuls 48(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 56(%0)\n\t"\ - "fmuls 56(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "subl $4,%%esp\n\t"\ - "subl $64,%0\n\t"\ - "subl $192,%1\n\t"\ - "faddp\n\t"\ - "fistpl (%%esp)\n\t"\ - "popl %%ecx\n\t"\ - "cmpl $32767,%%ecx\n\t"\ - "jle 2f\n\t"\ - "movw $32767,%%cx\n\t"\ - "jmp 3f\n\t"\ - "2: cmpl $-32768,%%ecx\n\t"\ - "jge 3f\n\t"\ - "movw $-32768,%%cx\n\t"\ - "3: movw %%cx,(%2)\n\t"\ - - "movl %5,%%ecx\n\t"\ - "sall $3,%%ecx\n\t"\ - "addl %%ecx,%1\n\t"\ - "addl %3,%2\n\t"\ - "movl $14,%%eax\n\t"\ - - "1:flds 4(%0)\n\t"\ - "fmuls 56(%1)\n\t"\ - "flds (%0)\n\t"\ - "fmuls 60(%1)\n\t"\ - "flds 12(%0)\n\t"\ - "fmuls 48(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubp\n\t"\ - "flds 8(%0)\n\t"\ - "fmuls 52(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 20(%0)\n\t"\ - "fmuls 40(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 16(%0)\n\t"\ - "fmuls 44(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 28(%0)\n\t"\ - "fmuls 32(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 24(%0)\n\t"\ - "fmuls 36(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 36(%0)\n\t"\ - "fmuls 24(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 32(%0)\n\t"\ - "fmuls 28(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 44(%0)\n\t"\ - "fmuls 16(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 40(%0)\n\t"\ - "fmuls 20(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 52(%0)\n\t"\ - "fmuls 8(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 48(%0)\n\t"\ - "fmuls 12(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 60(%0)\n\t"\ - "fmuls (%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 56(%0)\n\t"\ - "fmuls 4(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "subl $64,%0\n\t"\ - "subl $128,%1\n\t"\ - "subl $4,%%esp\n\t"\ - "fsubp\n\t"\ - "fistpl (%%esp)\n\t"\ - "popl %%ecx\n\t"\ - "cmpl $32767,%%ecx\n\t"\ - "jle 2f\n\t"\ - "movw $32767,%%cx\n\t"\ - "jmp 3f\n\t"\ - "2: cmpl $-32768,%%ecx\n\t"\ - "jge 3f\n\t"\ - "movw $-32768,%%cx\n\t"\ - "3: movw %%cx,(%2)\n\t"\ - "addl %3,%2\n\t"\ - "decl %%eax\n\t"\ - "jns 1b\n\t"\ - "jmp 5f\n\t"\ - - "4:flds 4(%0)\n\t"\ - "fmuls 4(%1)\n\t"\ - "flds 12(%0)\n\t"\ - "fmuls 12(%1)\n\t"\ - "flds 20(%0)\n\t"\ - "fmuls 20(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 28(%0)\n\t"\ - "fmuls 28(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 36(%0)\n\t"\ - "fmuls 36(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 44(%0)\n\t"\ - "fmuls 44(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 52(%0)\n\t"\ - "fmuls 52(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 60(%0)\n\t"\ - "fmuls 60(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "subl $4,%%esp\n\t"\ - "subl $64,%0\n\t"\ - "subl $192,%1\n\t"\ - "faddp\n\t"\ - "fistpl (%%esp)\n\t"\ - "popl %%ecx\n\t"\ - "cmpl $32767,%%ecx\n\t"\ - "jle 2f\n\t"\ - "movw $32767,%%cx\n\t"\ - "jmp 3f\n\t"\ - "2: cmpl $-32768,%%ecx\n\t"\ - "jge 3f\n\t"\ - "movw $-32768,%%cx\n\t"\ - "3: movw %%cx,(%2)\n\t"\ - - "movl %5,%%ecx\n\t"\ - "sall $3,%%ecx\n\t"\ - "addl %%ecx,%1\n\t"\ - "addl %3,%2\n\t"\ - - "movl $14,%%eax\n\t"\ - "1:flds (%0)\n\t"\ - "fmuls 60(%1)\n\t"\ - "flds 4(%0)\n\t"\ - "fmuls 56(%1)\n\t"\ - "flds 8(%0)\n\t"\ - "fmuls 52(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubp\n\t"\ - "flds 12(%0)\n\t"\ - "fmuls 48(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 16(%0)\n\t"\ - "fmuls 44(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 20(%0)\n\t"\ - "fmuls 40(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 24(%0)\n\t"\ - "fmuls 36(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 28(%0)\n\t"\ - "fmuls 32(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 32(%0)\n\t"\ - "fmuls 28(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 36(%0)\n\t"\ - "fmuls 24(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 40(%0)\n\t"\ - "fmuls 20(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 44(%0)\n\t"\ - "fmuls 16(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 48(%0)\n\t"\ - "fmuls 12(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 52(%0)\n\t"\ - "fmuls 8(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "flds 56(%0)\n\t"\ - "fmuls 4(%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "fsubrp\n\t"\ - "flds 60(%0)\n\t"\ - "fmuls (%1)\n\t"\ - "fxch %%st(2)\n\t"\ - "faddp\n\t"\ - "subl $64,%0\n\t"\ - "subl $128,%1\n\t"\ - "subl $4,%%esp\n\t"\ - "fsubp\n\t"\ - "fistpl (%%esp)\n\t"\ - "popl %%ecx\n\t"\ - "cmpl $32767,%%ecx\n\t"\ - "jle 2f\n\t"\ - "movw $32767,%%cx\n\t"\ - "jmp 3f\n\t"\ - "2: cmpl $-32768,%%ecx\n\t"\ - "jge 3f\n\t"\ - "movw $-32768,%%cx\n\t"\ - "3: movw %%cx,(%2)\n\t"\ - "addl %3,%2\n\t"\ - "decl %%eax\n\t"\ - "jns 1b\n\t"\ - - "5:"\ - : : "b" (u[ch][div]), "d" (t_dewindow[0] + 16 - start), "S" (&sample_buffer[f>>(2-nch)][nch==2?0:(f&1?16:0)][ch]), "m" (sizeof(short) * nch), "m" (div), "m" (start)\ - : "eax", "ecx", "memory"); -#else - { - short *samples = (&sample_buffer[f>>(2-nch)][nch==2?0:(f&1?16:0)][ch]); - int out, j; - -#define PUT_SAMPLE(out) \ - if (out > 32767) \ - *samples = 32767; \ - else \ - if (out < -32768) \ - *samples = -32768; \ - else \ - *samples = out; \ - \ - samples += nch; - -#if defined(SUPERHACK) - /* These is a simple implementation which should be nicer to the - cache; computation of samples are done in one pass rather than - two. However, for various reasons which I do not have time to - investigate, it runs quite a lot slower than two pass - computations. If you have time, you are welcome to look into - it. */ - - { - float (*u_ptr)[16] = u[ch][div]; - const float *dewindow2 = t_dewindow[0] + start; - - { - float outf1, outf2, outf3, outf4; - - outf1 = u_ptr[0][ 0] * dewindow[0x0]; - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf3 = u_ptr[0][ 2] * dewindow[0x2]; - outf4 = u_ptr[0][ 3] * dewindow[0x3]; - outf1 += u_ptr[0][ 4] * dewindow[0x4]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf3 += u_ptr[0][ 6] * dewindow[0x6]; - outf4 += u_ptr[0][ 7] * dewindow[0x7]; - outf1 += u_ptr[0][ 8] * dewindow[0x8]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf3 += u_ptr[0][10] * dewindow[0xa]; - outf4 += u_ptr[0][11] * dewindow[0xb]; - outf1 += u_ptr[0][12] * dewindow[0xc]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf3 += u_ptr[0][14] * dewindow[0xe]; - outf4 += u_ptr[0][15] * dewindow[0xf]; - - out = outf1 + outf2 + outf3 + outf4; - - dewindow += 32; - dewindow2 += 32; - u_ptr++; - - if (out > 32767) - samples[0] = 32767; - else - if (out < -32768) - samples[0] = -32768; - else - samples[0] = out; - } - - if (div & 0x1) { - for (j = 1; j < 16; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = u_ptr[0][ 0] * dewindow[0x0]; - outf3 = u_ptr[0][ 0] * dewindow2[0xf]; - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf4 = u_ptr[0][ 1] * dewindow2[0xe]; - outf1 += u_ptr[0][ 2] * dewindow[0x2]; - outf3 += u_ptr[0][ 2] * dewindow2[0xd]; - outf2 += u_ptr[0][ 3] * dewindow[0x3]; - outf4 += u_ptr[0][ 3] * dewindow2[0xc]; - outf1 += u_ptr[0][ 4] * dewindow[0x4]; - outf3 += u_ptr[0][ 4] * dewindow2[0xb]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf4 += u_ptr[0][ 5] * dewindow2[0xa]; - outf1 += u_ptr[0][ 6] * dewindow[0x6]; - outf3 += u_ptr[0][ 6] * dewindow2[0x9]; - outf2 += u_ptr[0][ 7] * dewindow[0x7]; - outf4 += u_ptr[0][ 7] * dewindow2[0x8]; - outf1 += u_ptr[0][ 8] * dewindow[0x8]; - outf3 += u_ptr[0][ 8] * dewindow2[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf4 += u_ptr[0][ 9] * dewindow2[0x6]; - outf1 += u_ptr[0][10] * dewindow[0xa]; - outf3 += u_ptr[0][10] * dewindow2[0x5]; - outf2 += u_ptr[0][11] * dewindow[0xb]; - outf4 += u_ptr[0][11] * dewindow2[0x4]; - outf1 += u_ptr[0][12] * dewindow[0xc]; - outf3 += u_ptr[0][12] * dewindow2[0x3]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf4 += u_ptr[0][13] * dewindow2[0x2]; - outf1 += u_ptr[0][14] * dewindow[0xe]; - outf3 += u_ptr[0][14] * dewindow2[0x1]; - outf2 += u_ptr[0][15] * dewindow[0xf]; - outf4 += u_ptr[0][15] * dewindow2[0x0]; - - dewindow += 32; - dewindow2 += 32; - u_ptr++; - - out = outf1 + outf2; - - if (out > 32767) - samples[j * 2] = 32767; - else - if (out < -32768) - samples[j * 2] = -32768; - else - samples[j * 2] = out; - - out = outf4 - outf3; - - if (out > 32767) - samples[64 - (j * 2)] = 32767; - else - if (out < -32768) - samples[64 - (j * 2)] = -32768; - else - samples[64 - (j * 2)] = out; - } - - { - float outf2, outf4; - - outf2 = u_ptr[0][ 0] * dewindow[0x0]; - outf4 = u_ptr[0][ 2] * dewindow[0x2]; - outf2 += u_ptr[0][ 4] * dewindow[0x4]; - outf4 += u_ptr[0][ 6] * dewindow[0x6]; - outf2 += u_ptr[0][ 8] * dewindow[0x8]; - outf4 += u_ptr[0][10] * dewindow[0xa]; - outf2 += u_ptr[0][12] * dewindow[0xc]; - outf4 += u_ptr[0][14] * dewindow[0xe]; - - out = outf2 + outf4; - - if (out > 32767) - samples[16 * 2] = 32767; - else - if (out < -32768) - samples[16 * 2] = -32768; - else - samples[16 * 2] = out; - } - } else { - for (j = 1; j < 16; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = u_ptr[0][ 0] * dewindow[0x0]; - outf3 = u_ptr[0][ 0] * dewindow2[0xf]; - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf4 = u_ptr[0][ 1] * dewindow2[0xe]; - outf1 += u_ptr[0][ 2] * dewindow[0x2]; - outf3 += u_ptr[0][ 2] * dewindow2[0xd]; - outf2 += u_ptr[0][ 3] * dewindow[0x3]; - outf4 += u_ptr[0][ 3] * dewindow2[0xc]; - outf1 += u_ptr[0][ 4] * dewindow[0x4]; - outf3 += u_ptr[0][ 4] * dewindow2[0xb]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf4 += u_ptr[0][ 5] * dewindow2[0xa]; - outf1 += u_ptr[0][ 6] * dewindow[0x6]; - outf3 += u_ptr[0][ 6] * dewindow2[0x9]; - outf2 += u_ptr[0][ 7] * dewindow[0x7]; - outf4 += u_ptr[0][ 7] * dewindow2[0x8]; - outf1 += u_ptr[0][ 8] * dewindow[0x8]; - outf3 += u_ptr[0][ 8] * dewindow2[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf4 += u_ptr[0][ 9] * dewindow2[0x6]; - outf1 += u_ptr[0][10] * dewindow[0xa]; - outf3 += u_ptr[0][10] * dewindow2[0x5]; - outf2 += u_ptr[0][11] * dewindow[0xb]; - outf4 += u_ptr[0][11] * dewindow2[0x4]; - outf1 += u_ptr[0][12] * dewindow[0xc]; - outf3 += u_ptr[0][12] * dewindow2[0x3]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf4 += u_ptr[0][13] * dewindow2[0x2]; - outf1 += u_ptr[0][14] * dewindow[0xe]; - outf3 += u_ptr[0][14] * dewindow2[0x1]; - outf2 += u_ptr[0][15] * dewindow[0xf]; - outf4 += u_ptr[0][15] * dewindow2[0x0]; - - dewindow += 32; - dewindow2 += 32; - u_ptr++; - - out = outf1 + outf2; - - if (out > 32767) - samples[j * 2] = 32767; - else - if (out < -32768) - samples[j * 2] = -32768; - else - samples[j * 2] = out; - - out = outf3 - outf4; - - if (out > 32767) - samples[64 - (j * 2)] = 32767; - else - if (out < -32768) - samples[64 - (j * 2)] = -32768; - else - samples[64 - (j * 2)] = out; - } - - { - float outf2, outf4; - - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf4 = u_ptr[0][ 3] * dewindow[0x3]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf4 += u_ptr[0][ 7] * dewindow[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf4 += u_ptr[0][11] * dewindow[0xb]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf4 += u_ptr[0][15] * dewindow[0xf]; - - out = outf2 + outf4; - - if (out > 32767) - samples[16 * 2] = 32767; - else - if (out < -32768) - samples[16 * 2] = -32768; - else - samples[16 * 2] = out; - } - } - } -#elif defined(HAS_AUTOINCREMENT) - const float *dewindow = t_dewindow[0] + 15 - start; - - /* This is tuned specifically for architectures with - autoincrement and -decrement. */ - - { - float *u_ptr = (float*) u[ch][div]; - - u_ptr--; - - for (j = 0; j < 16; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = *++u_ptr * *++dewindow; - outf2 = *++u_ptr * *++dewindow; - outf3 = *++u_ptr * *++dewindow; - outf4 = *++u_ptr * *++dewindow; - outf1 += *++u_ptr * *++dewindow; - outf2 += *++u_ptr * *++dewindow; - outf3 += *++u_ptr * *++dewindow; - outf4 += *++u_ptr * *++dewindow; - outf1 += *++u_ptr * *++dewindow; - outf2 += *++u_ptr * *++dewindow; - outf3 += *++u_ptr * *++dewindow; - outf4 += *++u_ptr * *++dewindow; - outf1 += *++u_ptr * *++dewindow; - outf2 += *++u_ptr * *++dewindow; - outf3 += *++u_ptr * *++dewindow; - outf4 += *++u_ptr * *++dewindow; - - out = outf1 + outf2 + outf3 + outf4; - - dewindow += 16; - - PUT_SAMPLE(out) - } - - if (div & 0x1) { - { - float outf2, outf4; - - outf2 = u_ptr[ 1] * dewindow[0x1]; - outf4 = u_ptr[ 3] * dewindow[0x3]; - outf2 += u_ptr[ 5] * dewindow[0x5]; - outf4 += u_ptr[ 7] * dewindow[0x7]; - outf2 += u_ptr[ 9] * dewindow[0x9]; - outf4 += u_ptr[11] * dewindow[0xb]; - outf2 += u_ptr[13] * dewindow[0xd]; - outf4 += u_ptr[15] * dewindow[0xf]; - - out = outf2 + outf4; - - PUT_SAMPLE(out) - } - - dewindow -= 31; - dewindow += start; - dewindow += start; - u_ptr -= 16; - - for (; j < 31; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = *++u_ptr * *--dewindow; - outf2 = *++u_ptr * *--dewindow; - outf3 = *++u_ptr * *--dewindow; - outf4 = *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - - out = outf2 - outf1 + outf4 - outf3; - - dewindow -= 16; - u_ptr -= 32; - - PUT_SAMPLE(out) - } - } else { - { - float outf2, outf4; - - outf2 = u_ptr[ 2] * dewindow[ 0x2]; - outf4 = u_ptr[ 4] * dewindow[ 0x4]; - outf2 += u_ptr[ 6] * dewindow[ 0x6]; - outf4 += u_ptr[ 8] * dewindow[ 0x8]; - outf2 += u_ptr[10] * dewindow[ 0xa]; - outf4 += u_ptr[12] * dewindow[ 0xc]; - outf2 += u_ptr[14] * dewindow[ 0xe]; - outf4 += u_ptr[16] * dewindow[0x10]; - - out = outf2 + outf4; - - PUT_SAMPLE(out) - } - - dewindow -= 31; - dewindow += start; - dewindow += start; - u_ptr -= 16; - - for (; j < 31; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = *++u_ptr * *--dewindow; - outf2 = *++u_ptr * *--dewindow; - outf3 = *++u_ptr * *--dewindow; - outf4 = *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - outf1 += *++u_ptr * *--dewindow; - outf2 += *++u_ptr * *--dewindow; - outf3 += *++u_ptr * *--dewindow; - outf4 += *++u_ptr * *--dewindow; - - out = outf1 - outf2 + outf3 - outf4; - - dewindow -= 16; - u_ptr -= 32; - - PUT_SAMPLE(out) - } - } - } -#else - const float *dewindow = t_dewindow[0] + 16 - start; - - /* These optimisations are tuned specifically for architectures - without autoincrement and -decrement. */ - - { - float (*u_ptr)[16] = u[ch][div]; - - for (j = 0; j < 16; ++j) { - float outf1, outf2, outf3, outf4; - - outf1 = u_ptr[0][ 0] * dewindow[0x0]; - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf3 = u_ptr[0][ 2] * dewindow[0x2]; - outf4 = u_ptr[0][ 3] * dewindow[0x3]; - outf1 += u_ptr[0][ 4] * dewindow[0x4]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf3 += u_ptr[0][ 6] * dewindow[0x6]; - outf4 += u_ptr[0][ 7] * dewindow[0x7]; - outf1 += u_ptr[0][ 8] * dewindow[0x8]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf3 += u_ptr[0][10] * dewindow[0xa]; - outf4 += u_ptr[0][11] * dewindow[0xb]; - outf1 += u_ptr[0][12] * dewindow[0xc]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf3 += u_ptr[0][14] * dewindow[0xe]; - outf4 += u_ptr[0][15] * dewindow[0xf]; - - out = (int) (outf1 + outf2 + outf3 + outf4); - - dewindow += 32; - u_ptr++; - - PUT_SAMPLE(out) - } - - if (div & 0x1) { - { - float outf2, outf4; - - outf2 = u_ptr[0][ 0] * dewindow[0x0]; - outf4 = u_ptr[0][ 2] * dewindow[0x2]; - outf2 += u_ptr[0][ 4] * dewindow[0x4]; - outf4 += u_ptr[0][ 6] * dewindow[0x6]; - outf2 += u_ptr[0][ 8] * dewindow[0x8]; - outf4 += u_ptr[0][10] * dewindow[0xa]; - outf2 += u_ptr[0][12] * dewindow[0xc]; - outf4 += u_ptr[0][14] * dewindow[0xe]; - - out = (int) (outf2 + outf4); - - PUT_SAMPLE(out) - } - - dewindow -= 48; - dewindow += start; - dewindow += start; - - for (; j < 31; ++j) { - float outf1, outf2, outf3, outf4; - - --u_ptr; - - outf1 = u_ptr[0][ 0] * dewindow[0xf]; - outf2 = u_ptr[0][ 1] * dewindow[0xe]; - outf3 = u_ptr[0][ 2] * dewindow[0xd]; - outf4 = u_ptr[0][ 3] * dewindow[0xc]; - outf1 += u_ptr[0][ 4] * dewindow[0xb]; - outf2 += u_ptr[0][ 5] * dewindow[0xa]; - outf3 += u_ptr[0][ 6] * dewindow[0x9]; - outf4 += u_ptr[0][ 7] * dewindow[0x8]; - outf1 += u_ptr[0][ 8] * dewindow[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x6]; - outf3 += u_ptr[0][10] * dewindow[0x5]; - outf4 += u_ptr[0][11] * dewindow[0x4]; - outf1 += u_ptr[0][12] * dewindow[0x3]; - outf2 += u_ptr[0][13] * dewindow[0x2]; - outf3 += u_ptr[0][14] * dewindow[0x1]; - outf4 += u_ptr[0][15] * dewindow[0x0]; - - out = (int) (-outf1 + outf2 - outf3 + outf4); - - dewindow -= 32; - - PUT_SAMPLE(out) - } - } else { - { - float outf2, outf4; - - outf2 = u_ptr[0][ 1] * dewindow[0x1]; - outf4 = u_ptr[0][ 3] * dewindow[0x3]; - outf2 += u_ptr[0][ 5] * dewindow[0x5]; - outf4 += u_ptr[0][ 7] * dewindow[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x9]; - outf4 += u_ptr[0][11] * dewindow[0xb]; - outf2 += u_ptr[0][13] * dewindow[0xd]; - outf4 += u_ptr[0][15] * dewindow[0xf]; - - out = (int) (outf2 + outf4); - - PUT_SAMPLE(out) - } - - dewindow -= 48; - dewindow += start; - dewindow += start; - - for (; j < 31; ++j) { - float outf1, outf2, outf3, outf4; - - --u_ptr; - - outf1 = u_ptr[0][ 0] * dewindow[0xf]; - outf2 = u_ptr[0][ 1] * dewindow[0xe]; - outf3 = u_ptr[0][ 2] * dewindow[0xd]; - outf4 = u_ptr[0][ 3] * dewindow[0xc]; - outf1 += u_ptr[0][ 4] * dewindow[0xb]; - outf2 += u_ptr[0][ 5] * dewindow[0xa]; - outf3 += u_ptr[0][ 6] * dewindow[0x9]; - outf4 += u_ptr[0][ 7] * dewindow[0x8]; - outf1 += u_ptr[0][ 8] * dewindow[0x7]; - outf2 += u_ptr[0][ 9] * dewindow[0x6]; - outf3 += u_ptr[0][10] * dewindow[0x5]; - outf4 += u_ptr[0][11] * dewindow[0x4]; - outf1 += u_ptr[0][12] * dewindow[0x3]; - outf2 += u_ptr[0][13] * dewindow[0x2]; - outf3 += u_ptr[0][14] * dewindow[0x1]; - outf4 += u_ptr[0][15] * dewindow[0x0]; - - out = (int) (outf1 - outf2 + outf3 - outf4); - - dewindow -= 32; - - PUT_SAMPLE(out) - } - } - } -#endif - } -#endif - - --u_start[ch]; - u_start[ch] &= 0xf; - u_div[ch]=u_div[ch] ? 0 : 1; - -#if defined(PENTIUM_RDTSC) - __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt4)); - - if (cnt2-cnt1 < min_cycles) { - min_cycles = cnt2-cnt1; - //printf("%d, %d cycles, %d\n", cnt3-cnt1, min_cycles, start); - } -#endif -} - -void premultiply() -{ - int i,t; - - for (i = 0; i < 17; ++i) - for (t = 0; t < 32; ++t) - t_dewindow[i][t] *= 16383.5f; -} diff --git a/Src/Sound/MPEG/transform.h b/Src/Sound/MPEG/transform.h deleted file mode 100644 index 3fd14cb..0000000 --- a/Src/Sound/MPEG/transform.h +++ /dev/null @@ -1,196 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * transform.h - * - * Amp library internal header file. - */ - - -/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 -*/ - -/* transform.h tables galore - * - * Created by: tomislav uzelac May 1996 - * Last modified by: tomislav uzelac Mar 1 97 - */ -extern void imdct_init(); -extern void imdct(int win_type,int sb,int ch); -extern void poly(int ch,int i); -extern void premultiply(); - -extern short sample_buffer[18][32][2]; -extern float res[32][18]; -extern float s[2][32][18]; - -#ifdef TRANSFORM - -void imdct_init(); -void imdct(int win_type,int sb,int ch); -void poly(int ch,int i); -void premultiply(); - -short sample_buffer[18][32][2]; -float s[2][32][18]; -float res[32][18]; -float win[4][36]; - -static const float t_sin[4][36]={{ - -0.032160f, 0.103553f, -0.182543f, 0.266729f, -0.353554f, 0.440377f, - -0.524563f, 0.603553f, -0.674947f, 0.736575f, -0.786566f, 0.823400f, - -0.845957f, 0.853554f, -0.845957f, 0.823399f, -0.786566f, 0.736575f, - -0.674947f, 0.603553f, -0.524564f, 0.440378f, -0.353553f, 0.266729f, - -0.182544f, 0.103553f, -0.032160f, -0.029469f, 0.079459f, -0.116293f, - 0.138851f, -0.146446f, 0.138851f, -0.116293f, 0.079459f, -0.029469f -},{ - -0.032160f, 0.103553f, -0.182543f, 0.266729f, -0.353554f, 0.440377f, - -0.524563f, 0.603553f, -0.674947f, 0.736575f, -0.786566f, 0.823400f, - -0.845957f, 0.853554f, -0.845957f, 0.823399f, -0.786566f, 0.736575f, - -0.675590f, 0.608761f, -0.537300f, 0.461749f, -0.382683f, 0.300706f, - -0.214588f, 0.120590f, -0.034606f, -0.026554f, 0.049950f, -0.028251f, - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f -},{ - -0.103553f, 0.353554f, -0.603553f, 0.786566f, -0.853554f, 0.786566f, - -0.603553f, 0.353553f, -0.103553f, -0.079459f, 0.146446f, -0.079459f, - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f -},{ - 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, - -0.127432f, 0.379410f, -0.608182f, 0.792598f, -0.915976f, 0.967944f, - -0.953717f, 0.923880f, -0.887011f, 0.843391f, -0.793353f, 0.737277f, - -0.674947f, 0.603553f, -0.524564f, 0.440378f, -0.353553f, 0.266729f, - -0.182544f, 0.103553f, -0.032160f, -0.029469f, 0.079459f, -0.116293f, - 0.138851f, -0.146446f, 0.138851f, -0.116293f, 0.079459f, -0.029469f -}}; - -static const float t_2cos[4][18]={ -{ -0.174311f, -0.517638f, -0.845237f, -1.147153f, -1.414214f, -1.638304f, -1.812616f, -1.931852f, -1.992389f, - 0.174311f, 0.517638f, 0.845237f, 1.147153f, 1.414214f, 1.638304f, 1.812616f, 1.931852f, 1.992389f}, -{ -0.174311f, -0.517638f, -0.845237f, -1.147153f, -1.414214f, -1.638304f, -1.812616f, -1.931852f, -1.992389f, - 0.174311f, 0.517638f, 0.845237f, 1.147153f, 1.414214f, 1.638304f, 1.812616f, 1.931852f, 1.992389f}, -{ -0.517638f, -1.41421f, -1.93185f, 0.517638f, 1.41421f, 1.93185f,0,0,0,0,0,0,0,0,0,0,0,0}, -{ -0.174311f, -0.517638f, -0.845237f, -1.147153f, -1.414214f, -1.638304f, -1.812616f, -1.931852f, -1.992389f, - 0.174311f, 0.517638f, 0.845237f, 1.147153f, 1.414214f, 1.638304f, 1.812616f, 1.931852f, 1.992389f} -}; - -static const float b1 = 1.997590912f; static const float b2 = 1.990369453f; static const float b3 = 1.978353019f; -static const float b4 = 1.961570560f; static const float b5 = 1.940062506f; static const float b6 = 1.913880671f; -static const float b7 = 1.883088130f; static const float b8 = 1.847759065f; static const float b9 = 1.807978586f; -static const float b10= 1.763842529f; static const float b11= 1.715457220f; static const float b12= 1.662939225f; -static const float b13= 1.606415063f; static const float b14= 1.546020907f; static const float b15= 1.481902251f; -static const float b16= 1.414213562f; static const float b17= 1.343117910f; static const float b18= 1.268786568f; -static const float b19= 1.191398609f; static const float b20= 1.111140466f; static const float b21= 1.028205488f; -static const float b22= 0.942793474f; static const float b23= 0.855110187f; static const float b24= 0.765366865f; -static const float b25= 0.673779707f; static const float b26= 0.580569355f; static const float b27= 0.485960360f; -static const float b28= 0.390180644f; static const float b29= 0.293460949f; static const float b30= 0.196034281f; -static const float b31= 0.098135349f; - -static float t_dewindow[17][32] = {{ - 0.000000000f,-0.000442505f, 0.003250122f,-0.007003784f, 0.031082153f,-0.078628540f, 0.100311279f,-0.572036743f, - 1.144989014f, 0.572036743f, 0.100311279f, 0.078628540f, 0.031082153f, 0.007003784f, 0.003250122f, 0.000442505f, - 0.000000000f,-0.000442505f, 0.003250122f,-0.007003784f, 0.031082153f,-0.078628540f, 0.100311279f,-0.572036743f, - 1.144989014f, 0.572036743f, 0.100311279f, 0.078628540f, 0.031082153f, 0.007003784f, 0.003250122f, 0.000442505f, -},{ --0.000015259f,-0.000473022f, 0.003326416f,-0.007919312f, 0.030517578f,-0.084182739f, 0.090927124f,-0.600219727f, - 1.144287109f, 0.543823242f, 0.108856201f, 0.073059082f, 0.031478882f, 0.006118774f, 0.003173828f, 0.000396729f, --0.000015259f,-0.000473022f, 0.003326416f,-0.007919312f, 0.030517578f,-0.084182739f, 0.090927124f,-0.600219727f, - 1.144287109f, 0.543823242f, 0.108856201f, 0.073059082f, 0.031478882f, 0.006118774f, 0.003173828f, 0.000396729f, -},{ --0.000015259f,-0.000534058f, 0.003387451f,-0.008865356f, 0.029785156f,-0.089706421f, 0.080688477f,-0.628295898f, - 1.142211914f, 0.515609741f, 0.116577148f, 0.067520142f, 0.031738281f, 0.005294800f, 0.003082275f, 0.000366211f, --0.000015259f,-0.000534058f, 0.003387451f,-0.008865356f, 0.029785156f,-0.089706421f, 0.080688477f,-0.628295898f, - 1.142211914f, 0.515609741f, 0.116577148f, 0.067520142f, 0.031738281f, 0.005294800f, 0.003082275f, 0.000366211f, -},{ --0.000015259f,-0.000579834f, 0.003433228f,-0.009841919f, 0.028884888f,-0.095169067f, 0.069595337f,-0.656219482f, - 1.138763428f, 0.487472534f, 0.123474121f, 0.061996460f, 0.031845093f, 0.004486084f, 0.002990723f, 0.000320435f, --0.000015259f,-0.000579834f, 0.003433228f,-0.009841919f, 0.028884888f,-0.095169067f, 0.069595337f,-0.656219482f, - 1.138763428f, 0.487472534f, 0.123474121f, 0.061996460f, 0.031845093f, 0.004486084f, 0.002990723f, 0.000320435f, -},{ --0.000015259f,-0.000625610f, 0.003463745f,-0.010848999f, 0.027801514f,-0.100540161f, 0.057617187f,-0.683914185f, - 1.133926392f, 0.459472656f, 0.129577637f, 0.056533813f, 0.031814575f, 0.003723145f, 0.002899170f, 0.000289917f, --0.000015259f,-0.000625610f, 0.003463745f,-0.010848999f, 0.027801514f,-0.100540161f, 0.057617187f,-0.683914185f, - 1.133926392f, 0.459472656f, 0.129577637f, 0.056533813f, 0.031814575f, 0.003723145f, 0.002899170f, 0.000289917f, -},{ --0.000015259f,-0.000686646f, 0.003479004f,-0.011886597f, 0.026535034f,-0.105819702f, 0.044784546f,-0.711318970f, - 1.127746582f, 0.431655884f, 0.134887695f, 0.051132202f, 0.031661987f, 0.003005981f, 0.002792358f, 0.000259399f, --0.000015259f,-0.000686646f, 0.003479004f,-0.011886597f, 0.026535034f,-0.105819702f, 0.044784546f,-0.711318970f, - 1.127746582f, 0.431655884f, 0.134887695f, 0.051132202f, 0.031661987f, 0.003005981f, 0.002792358f, 0.000259399f, -},{ --0.000015259f,-0.000747681f, 0.003479004f,-0.012939453f, 0.025085449f,-0.110946655f, 0.031082153f,-0.738372803f, - 1.120223999f, 0.404083252f, 0.139450073f, 0.045837402f, 0.031387329f, 0.002334595f, 0.002685547f, 0.000244141f, --0.000015259f,-0.000747681f, 0.003479004f,-0.012939453f, 0.025085449f,-0.110946655f, 0.031082153f,-0.738372803f, - 1.120223999f, 0.404083252f, 0.139450073f, 0.045837402f, 0.031387329f, 0.002334595f, 0.002685547f, 0.000244141f, -},{ --0.000030518f,-0.000808716f, 0.003463745f,-0.014022827f, 0.023422241f,-0.115921021f, 0.016510010f,-0.765029907f, - 1.111373901f, 0.376800537f, 0.143264771f, 0.040634155f, 0.031005859f, 0.001693726f, 0.002578735f, 0.000213623f, --0.000030518f,-0.000808716f, 0.003463745f,-0.014022827f, 0.023422241f,-0.115921021f, 0.016510010f,-0.765029907f, - 1.111373901f, 0.376800537f, 0.143264771f, 0.040634155f, 0.031005859f, 0.001693726f, 0.002578735f, 0.000213623f, -},{ --0.000030518f,-0.000885010f, 0.003417969f,-0.015121460f, 0.021575928f,-0.120697021f, 0.001068115f,-0.791213989f, - 1.101211548f, 0.349868774f, 0.146362305f, 0.035552979f, 0.030532837f, 0.001098633f, 0.002456665f, 0.000198364f, --0.000030518f,-0.000885010f, 0.003417969f,-0.015121460f, 0.021575928f,-0.120697021f, 0.001068115f,-0.791213989f, - 1.101211548f, 0.349868774f, 0.146362305f, 0.035552979f, 0.030532837f, 0.001098633f, 0.002456665f, 0.000198364f, -},{ --0.000030518f,-0.000961304f, 0.003372192f,-0.016235352f, 0.019531250f,-0.125259399f,-0.015228271f,-0.816864014f, - 1.089782715f, 0.323318481f, 0.148773193f, 0.030609131f, 0.029937744f, 0.000549316f, 0.002349854f, 0.000167847f, --0.000030518f,-0.000961304f, 0.003372192f,-0.016235352f, 0.019531250f,-0.125259399f,-0.015228271f,-0.816864014f, - 1.089782715f, 0.323318481f, 0.148773193f, 0.030609131f, 0.029937744f, 0.000549316f, 0.002349854f, 0.000167847f, -},{ --0.000030518f,-0.001037598f, 0.003280640f,-0.017349243f, 0.017257690f,-0.129562378f,-0.032379150f,-0.841949463f, - 1.077117920f, 0.297210693f, 0.150497437f, 0.025817871f, 0.029281616f, 0.000030518f, 0.002243042f, 0.000152588f, --0.000030518f,-0.001037598f, 0.003280640f,-0.017349243f, 0.017257690f,-0.129562378f,-0.032379150f,-0.841949463f, - 1.077117920f, 0.297210693f, 0.150497437f, 0.025817871f, 0.029281616f, 0.000030518f, 0.002243042f, 0.000152588f, -},{ --0.000045776f,-0.001113892f, 0.003173828f,-0.018463135f, 0.014801025f,-0.133590698f,-0.050354004f,-0.866363525f, - 1.063217163f, 0.271591187f, 0.151596069f, 0.021179199f, 0.028533936f,-0.000442505f, 0.002120972f, 0.000137329f, --0.000045776f,-0.001113892f, 0.003173828f,-0.018463135f, 0.014801025f,-0.133590698f,-0.050354004f,-0.866363525f, - 1.063217163f, 0.271591187f, 0.151596069f, 0.021179199f, 0.028533936f,-0.000442505f, 0.002120972f, 0.000137329f, -},{ --0.000045776f,-0.001205444f, 0.003051758f,-0.019577026f, 0.012115479f,-0.137298584f,-0.069168091f,-0.890090942f, - 1.048156738f, 0.246505737f, 0.152069092f, 0.016708374f, 0.027725220f,-0.000869751f, 0.002014160f, 0.000122070f, --0.000045776f,-0.001205444f, 0.003051758f,-0.019577026f, 0.012115479f,-0.137298584f,-0.069168091f,-0.890090942f, - 1.048156738f, 0.246505737f, 0.152069092f, 0.016708374f, 0.027725220f,-0.000869751f, 0.002014160f, 0.000122070f, -},{ --0.000061035f,-0.001296997f, 0.002883911f,-0.020690918f, 0.009231567f,-0.140670776f,-0.088775635f,-0.913055420f, - 1.031936646f, 0.221984863f, 0.151962280f, 0.012420654f, 0.026840210f,-0.001266479f, 0.001907349f, 0.000106812f, --0.000061035f,-0.001296997f, 0.002883911f,-0.020690918f, 0.009231567f,-0.140670776f,-0.088775635f,-0.913055420f, - 1.031936646f, 0.221984863f, 0.151962280f, 0.012420654f, 0.026840210f,-0.001266479f, 0.001907349f, 0.000106812f, -},{ --0.000061035f,-0.001388550f, 0.002700806f,-0.021789551f, 0.006134033f,-0.143676758f,-0.109161377f,-0.935195923f, - 1.014617920f, 0.198059082f, 0.151306152f, 0.008316040f, 0.025909424f,-0.001617432f, 0.001785278f, 0.000106812f, --0.000061035f,-0.001388550f, 0.002700806f,-0.021789551f, 0.006134033f,-0.143676758f,-0.109161377f,-0.935195923f, - 1.014617920f, 0.198059082f, 0.151306152f, 0.008316040f, 0.025909424f,-0.001617432f, 0.001785278f, 0.000106812f, -},{ --0.000076294f,-0.001480103f, 0.002487183f,-0.022857666f, 0.002822876f,-0.146255493f,-0.130310059f,-0.956481934f, - 0.996246338f, 0.174789429f, 0.150115967f, 0.004394531f, 0.024932861f,-0.001937866f, 0.001693726f, 0.000091553f, --0.000076294f,-0.001480103f, 0.002487183f,-0.022857666f, 0.002822876f,-0.146255493f,-0.130310059f,-0.956481934f, - 0.996246338f, 0.174789429f, 0.150115967f, 0.004394531f, 0.024932861f,-0.001937866f, 0.001693726f, 0.000091553f, -},{ --0.000076294f,-0.001586914f, 0.002227783f,-0.023910522f,-0.000686646f,-0.148422241f,-0.152206421f,-0.976852417f, - 0.976852417f, 0.152206421f, 0.148422241f, 0.000686646f, 0.023910522f,-0.002227783f, 0.001586914f, 0.000076294f, --0.000076294f,-0.001586914f, 0.002227783f,-0.023910522f,-0.000686646f,-0.148422241f,-0.152206421f,-0.976852417f, - 0.976852417f, 0.152206421f, 0.148422241f, 0.000686646f, 0.023910522f,-0.002227783f, 0.001586914f, 0.000076294f, -} }; -#endif /* TRANSFORM */ diff --git a/Src/Sound/MPEG/util.cpp b/Src/Sound/MPEG/util.cpp deleted file mode 100644 index c869193..0000000 --- a/Src/Sound/MPEG/util.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - ** Supermodel - ** A Sega Model 3 Arcade Emulator. - ** Copyright 2011 Bart Trzynadlowski, Nik Henson - ** - ** This file is part of Supermodel. - ** - ** Supermodel is free software: you can redistribute it and/or modify it under - ** the terms of the GNU General Public License as published by the Free - ** Software Foundation, either version 3 of the License, or (at your option) - ** any later version. - ** - ** Supermodel is distributed in the hope that it will be useful, but WITHOUT - ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - ** more details. - ** - ** You should have received a copy of the GNU General Public License along - ** with Supermodel. If not, see . - **/ - -/* - * util.cpp - * - * Amp library internal module. - */ - - -/* - * None of these functions should ever be called in Supermodel. - */ - -/* this file is a part of amp software - - util.c: created by Andrew Richards - -*/ - -#define AMP_UTIL -#include "amp.h" - -#include -#include -#include -#include - -#include "amp_audio.h" - -struct debugFlags_t debugFlags; - - -/* die - for terminal conditions prints the error message and exits */ -/* can not be suppressed with -q,-quiet */ -void -die(char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - vfprintf(stderr, fmt, ap); -} - - -/* warn - for warning messages. Can be suppressed by -q,-quiet */ -void -warn(char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - if (!A_QUIET) { - fprintf(stderr,"Warning: "); - vfprintf(stderr, fmt, ap); - } -} - - -/* msg - for general output. Can be suppressed by -q,-quiet. Output */ -/* goes to stderr so it doesn't conflict with stdout output */ -void -msg(char *fmt, ...) -{ - va_list ap; - va_start(ap,fmt); - - if (!A_QUIET) - { - if (A_MSG_STDOUT) { - vfprintf(stdout, fmt, ap); - fflush(stdout); - } else { - vfprintf(stderr, fmt, ap); - fflush(stderr); - } - } -} - -void -debugOptions() -{ - int idx; - msg("Possible options are: "); - for(idx=0;debugLookup[idx].name!=0;idx++) - msg("%s,",debugLookup[idx].name); - msg("\010 \n"); -} - - -/* debugSetup - if debugging is turned on sets up the debug flags from */ -/* the command line arguments */ - -void -debugSetup(char *dbgFlags) -{ -#ifndef DEBUG - warn("Debugging has not been compiled into this version of amp\n"); -#else - char *ptr; - int idx; - - memset(&debugFlags,0,sizeof(debugFlags)); - - ptr=strtok(dbgFlags,","); - while(ptr) { - for(idx=0;debugLookup[idx].name!=0;idx++) { - if (strcmp(debugLookup[idx].name,ptr)==0) { - *(debugLookup[idx].var)=1; - break; - } - } - if (debugLookup[idx].name==0) { - warn("Debug option, %s, does not exist\n",ptr); - debugOptions(); - exit(1); - } - ptr=strtok(NULL,","); - } - - DB(args, - for(idx=0;debugLookup[idx].name!=0;idx++) - printf("Flag: %s = %d\n",debugLookup[idx].name,*(debugLookup[idx].var)); - ); -#endif -} - diff --git a/Src/Supermodel.h b/Src/Supermodel.h index 70e87a6..9922074 100644 --- a/Src/Supermodel.h +++ b/Src/Supermodel.h @@ -145,7 +145,6 @@ #include "Model3/TileGen.h" #include "Model3/Real3D.h" #include "Sound/SCSP.h" -#include "Sound/MPEG/MPEG.h" #include "Model3/SoundBoard.h" #include "Model3/DSB.h" #include "Model3/DriveBoard.h" diff --git a/VS2008/Supermodel.vcxproj b/VS2008/Supermodel.vcxproj index e414302..e7d9b55 100644 --- a/VS2008/Supermodel.vcxproj +++ b/VS2008/Supermodel.vcxproj @@ -379,67 +379,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - - - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - $(IntDir)amp_%(Filename).obj - + @@ -597,26 +537,12 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi + - - - - - - - - - - - - - - - - + diff --git a/VS2008/Supermodel.vcxproj.filters b/VS2008/Supermodel.vcxproj.filters index 36954d1..f8cec54 100644 --- a/VS2008/Supermodel.vcxproj.filters +++ b/VS2008/Supermodel.vcxproj.filters @@ -281,36 +281,6 @@ Source Files\Sound - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - - - Source Files\Sound\MPEG - Source Files\Debugger @@ -446,9 +416,6 @@ Source Files\Model3 - - Source Files\Sound\MPEG - Source Files\Network @@ -470,6 +437,9 @@ Source Files\Graphics\New + + Source Files\Sound\MPEG + @@ -655,51 +625,6 @@ Header Files\Sound - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - - - Header Files\Sound\MPEG - Header Files\Debugger @@ -847,9 +772,6 @@ Header Files\Util - - Header Files\Sound\MPEG - Header Files\Network @@ -880,6 +802,12 @@ Source Files\Graphics\New + + Header Files\Sound\MPEG + + + Header Files\Pkgs +