Skip to content

Commit

Permalink
VB -> VAG callbacks implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePLMonster committed Feb 5, 2017
1 parent 7a00b99 commit db4df74
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 168 deletions.
8 changes: 5 additions & 3 deletions dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "vbdec.h"
#include "vagdec.h"
#include "vbcalls.h"

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
Expand All @@ -12,10 +13,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved)
switch ( reason )
{
case DLL_PROCESS_ATTACH:
RegisterVBInterface();
RegisterVAGInterface();
AttachVBCallbacks();
break;
case DLL_PROCESS_DETACH:
UnregisterVBInterface();
UnRegisterVAGInterface();
break;
}
return TRUE;
Expand Down
Binary file added mss/mss32_2.lib
Binary file not shown.
211 changes: 105 additions & 106 deletions vbdec.cpp → vagdec.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "vbdec.h"
#include "vagdec.h"

#define GET_BLOCK(offset) ( offset >> 13 )
#define BE_TO_LE(i) ( ((i & 0xFF) << 24) | ((i & 0xFF00) << 8) | ((i & 0xFF0000) >> 8) | ((i & 0xFF000000) >> 24) )

static HPROVIDER providerHandle;
void RegisterVBInterface()
void RegisterVAGInterface()
{
// ASI codec
const RIB_INTERFACE_ENTRY codecEntries[] = {
Expand All @@ -22,31 +21,31 @@ void RegisterVBInterface()

// ASI stream
const RIB_INTERFACE_ENTRY streamEntries[] = {
REG_FN( ASI_stream_open ),
REG_FN( ASI_stream_process ),
REG_FN( ASI_stream_attribute ),
REG_FN( ASI_stream_set_preference ),
REG_FN( ASI_stream_seek ),
REG_FN( ASI_stream_open ),
REG_FN( ASI_stream_process ),
REG_FN( ASI_stream_attribute ),
REG_FN( ASI_stream_set_preference ),
REG_FN( ASI_stream_seek ),
REG_FN( ASI_stream_close ),
REG_AT("Input bit rate", INPUT_BIT_RATE, RIB_DEC),
REG_AT("Input sample rate", INPUT_SAMPLE_RATE, RIB_DEC),
REG_AT("Input sample width", INPUT_BITS, RIB_DEC),
REG_AT("Input channels", INPUT_CHANNELS, RIB_DEC),
REG_AT("Output bit rate", OUTPUT_BIT_RATE, RIB_DEC),
REG_AT("Output sample rate", OUTPUT_SAMPLE_RATE, RIB_DEC),
REG_AT("Output sample width", OUTPUT_BITS, RIB_DEC),
REG_AT("Input bit rate", INPUT_BIT_RATE, RIB_DEC),
REG_AT("Input sample rate", INPUT_SAMPLE_RATE, RIB_DEC),
REG_AT("Input sample width", INPUT_BITS, RIB_DEC),
REG_AT("Input channels", INPUT_CHANNELS, RIB_DEC),
REG_AT("Output bit rate", OUTPUT_BIT_RATE, RIB_DEC),
REG_AT("Output sample rate", OUTPUT_SAMPLE_RATE, RIB_DEC),
REG_AT("Output sample width", OUTPUT_BITS, RIB_DEC),
REG_AT("Output channels", OUTPUT_CHANNELS, RIB_DEC),
REG_AT("Position", POSITION, RIB_DEC),
REG_AT("Percent done", PERCENT_DONE, RIB_PERCENT),
REG_AT("Minimum input block size", MIN_INPUT_BLOCK_SIZE, RIB_DEC),
//REG_AT("MPEG version", MPEG_VERSION, RIB_DEC),
//REG_AT("MPEG layer", MPEG_LAYER, RIB_DEC),
//REG_AT("Interleave", INTERLEAVE, RIB_DEC),
//REG_PR("Raw source sample rate", RAW_RATE, RIB_DEC),
//REG_PR("Raw source sample width", RAW_BITS, RIB_DEC),
//REG_PR("Raw source channels", RAW_CHANNELS, RIB_DEC),
REG_PR("Requested sample rate", REQUESTED_RATE, RIB_DEC),
REG_PR("Requested sample width", REQUESTED_BITS, RIB_DEC),
REG_AT("Position", POSITION, RIB_DEC),
REG_AT("Percent done", PERCENT_DONE, RIB_PERCENT),
REG_AT("Minimum input block size", MIN_INPUT_BLOCK_SIZE, RIB_DEC),
//REG_AT("MPEG version", MPEG_VERSION, RIB_DEC),
//REG_AT("MPEG layer", MPEG_LAYER, RIB_DEC),
//REG_AT("Interleave", INTERLEAVE, RIB_DEC),
//REG_PR("Raw source sample rate", RAW_RATE, RIB_DEC),
//REG_PR("Raw source sample width", RAW_BITS, RIB_DEC),
//REG_PR("Raw source channels", RAW_CHANNELS, RIB_DEC),
REG_PR("Requested sample rate", REQUESTED_RATE, RIB_DEC),
REG_PR("Requested sample width", REQUESTED_BITS, RIB_DEC),
REG_PR("Requested channels", REQUESTED_CHANS, RIB_DEC)
};

Expand All @@ -55,7 +54,7 @@ void RegisterVBInterface()
RIB_register( providerHandle, "ASI stream", streamEntries );
}

void UnregisterVBInterface()
void UnRegisterVAGInterface()
{
RIB_unregister_all(providerHandle);
}
Expand Down Expand Up @@ -140,43 +139,43 @@ bool FetchStr( ASISTREAM *STR, int offset = -1 )
}
}

static const double f[5][2] = { { 0.0, 0.0 },
{ 60.0 / 64.0, 0.0 },
{ 115.0 / 64.0, -52.0 / 64.0 },
{ 98.0 / 64.0, -55.0 / 64.0 },
static const double f[5][2] = { { 0.0, 0.0 },
{ 60.0 / 64.0, 0.0 },
{ 115.0 / 64.0, -52.0 / 64.0 },
{ 98.0 / 64.0, -55.0 / 64.0 },
{ 122.0 / 64.0, -60.0 / 64.0 } };

U8 *bufs[] = { in_buf, &in_buf[0x10] };
S16 *dest[] = { STR->channels[0].decoded_samples, STR->channels[1].decoded_samples };
for (int c = 0; c < STR->num_of_channels; c++)
{
int predict_nr = *(bufs[c]++);
int shift_factor = predict_nr & 0xf;
predict_nr >>= 4;
int predict_nr = *(bufs[c]++);
int shift_factor = predict_nr & 0xf;
predict_nr >>= 4;
int flags = *(bufs[c]++);
if ( flags == 7 ) return false;
for ( int i = 0; i < 28; i += 2 )
{
int d = *(bufs[c]++);
int s = ( d & 0xf ) << 12;
if ( s & 0x8000 )
s |= 0xffff0000;
STR->channels[c].samples[i] = (double) ( s >> shift_factor );
s = ( d & 0xf0 ) << 8;
if ( s & 0x8000 )
s |= 0xffff0000;
STR->channels[c].samples[i+1] = (double) ( s >> shift_factor );

for ( int i = 0; i < 28; i += 2 )
{
int d = *(bufs[c]++);
int s = ( d & 0xf ) << 12;
if ( s & 0x8000 )
s |= 0xffff0000;
STR->channels[c].samples[i] = (double) ( s >> shift_factor );
s = ( d & 0xf0 ) << 8;
if ( s & 0x8000 )
s |= 0xffff0000;
STR->channels[c].samples[i+1] = (double) ( s >> shift_factor );

}
for ( int i = 0; i < 28; i++ )
{
STR->channels[c].samples[i] = STR->channels[c].samples[i] + STR->channels[c].s_1 * f[predict_nr][0] + STR->channels[c].s_2 * f[predict_nr][1];
STR->channels[c].s_2 = STR->channels[c].s_1;
STR->channels[c].s_1 = STR->channels[c].samples[i];
int d = (int) ( STR->channels[c].samples[i] + 0.5 );
if ( d & 0x8000 ) d |= 0xffff0000;
*(dest[c]++) = (d & 0xffff);
}
for ( int i = 0; i < 28; i++ )
{
STR->channels[c].samples[i] = STR->channels[c].samples[i] + STR->channels[c].s_1 * f[predict_nr][0] + STR->channels[c].s_2 * f[predict_nr][1];
STR->channels[c].s_2 = STR->channels[c].s_1;
STR->channels[c].s_1 = STR->channels[c].samples[i];
int d = (int) ( STR->channels[c].samples[i] + 0.5 );
if ( d & 0x8000 ) d |= 0xffff0000;
*(dest[c]++) = (d & 0xffff);
}
if ( flags == 1 ) break;
}
return true;
Expand All @@ -186,11 +185,11 @@ bool FetchStr( ASISTREAM *STR, int offset = -1 )
HASISTREAM AILCALL FAR ASI_stream_open(U32 user, AILASIFETCHCB fetch_CB, U32 total_size)
{
ASISTREAM FAR *STR = (ASISTREAM FAR *) AIL_mem_alloc_lock( sizeof(ASISTREAM) );
if (STR == nullptr)
{
return 0;
}

if (STR == nullptr)
{
return 0;
}

memset(STR, 0, sizeof(ASISTREAM));

STR->user = user;
Expand Down Expand Up @@ -218,59 +217,59 @@ HASISTREAM AILCALL FAR ASI_stream_open(U32 user, AILASIFETCHCB fetch_CB, U32 tot
return (HASISTREAM)STR;
}

ASIRESULT AILCALL ASI_stream_close(HASISTREAM stream)
{
ASISTREAM FAR *STR = (ASISTREAM FAR *) stream;

AIL_mem_free_lock(STR);

return ASI_NOERR;
ASIRESULT AILCALL ASI_stream_close(HASISTREAM stream)
{
ASISTREAM FAR *STR = (ASISTREAM FAR *) stream;

AIL_mem_free_lock(STR);

return ASI_NOERR;
}

S32 AILCALL FAR ASI_stream_process(HASISTREAM stream, void FAR *buffer, S32 buffer_size)
{
ASISTREAM *STR = (ASISTREAM*)stream;

S16 *dest = (S16 *)buffer;
S32 bytes_decoded = 0;

for (int i = 0; i < buffer_size / (2 * STR->num_of_channels); i++)
{
for (int c = 0; c < STR->num_of_channels; c++)
{
dest[i * STR->num_of_channels + c] = STR->channels[c].decoded_samples[STR->cursor];
bytes_decoded += sizeof(S16);
}
STR->cursor++;
if (STR->cursor >= 28)
{
STR->cursor = 0;
if (!FetchStr(STR))
break;
}
ASISTREAM *STR = (ASISTREAM*)stream;

S16 *dest = (S16 *)buffer;
S32 bytes_decoded = 0;

for (int i = 0; i < buffer_size / (2 * STR->num_of_channels); i++)
{
for (int c = 0; c < STR->num_of_channels; c++)
{
dest[i * STR->num_of_channels + c] = STR->channels[c].decoded_samples[STR->cursor];
bytes_decoded += sizeof(S16);
}
STR->cursor++;
if (STR->cursor >= 28)
{
STR->cursor = 0;
if (!FetchStr(STR))
break;
}
}
return bytes_decoded;
}

ASIRESULT AILCALL ASI_stream_seek (HASISTREAM stream, S32 stream_offset)
{
ASISTREAM *STR = (ASISTREAM*)stream;
if (stream_offset > STR->size) return ASI_INVALID_PARAM;

if (stream_offset == -2) // loop
{
stream_offset = sizeof(STR->VAGheader);
STR->loop = true;
}
else
{
STR->cursor = 0;
FetchStr(STR, stream_offset);
}

return ASI_NOERR;
}

ASIRESULT AILCALL ASI_stream_seek (HASISTREAM stream, S32 stream_offset)
{
ASISTREAM *STR = (ASISTREAM*)stream;
if (stream_offset > STR->size) return ASI_INVALID_PARAM;

if (stream_offset == -2) // loop
{
stream_offset = sizeof(STR->VAGheader);
STR->loop = true;
}
else
{
STR->cursor = 0;
FetchStr(STR, stream_offset);
}

return ASI_NOERR;
}

S32 AILCALL FAR ASI_stream_attribute (HASISTREAM stream, HATTRIB attrib)
{
ASISTREAM *STR = (ASISTREAM*)stream;
Expand All @@ -284,7 +283,7 @@ S32 AILCALL FAR ASI_stream_attribute (HASISTREAM stream, HATTRIB attrib)
case OUTPUT_SAMPLE_RATE: return STR->VAGheader.sample_rate;
case OUTPUT_BITS: return 16;
case OUTPUT_CHANNELS: return STR->num_of_channels;
case POSITION: return STR->offset;
case POSITION: return STR->offset;
case PERCENT_DONE:
{
float percent = ((float)(100.0 * STR->offset) / (STR->size / (STR->num_of_channels * 16 * 512)));
Expand Down
Loading

0 comments on commit db4df74

Please sign in to comment.