mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
Added ADP/DTK decoding.
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@26 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
c962ae7257
commit
8c44ea407b
53
src/coding/ngc_dtk_decoder.c
Normal file
53
src/coding/ngc_dtk_decoder.c
Normal file
@ -0,0 +1,53 @@
|
||||
#include "ngc_dtk_decoder.h"
|
||||
#include "../util.h"
|
||||
|
||||
void decode_ngc_dtk(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel) {
|
||||
int i=first_sample;
|
||||
int32_t sample_count;
|
||||
|
||||
int framesin = first_sample/28;
|
||||
|
||||
uint8_t q = read_8bit(framesin*32+stream->offset+channel,stream->streamfile);
|
||||
int32_t hist1 = stream->adpcm_history1_32;
|
||||
int32_t hist2 = stream->adpcm_history2_32;
|
||||
|
||||
first_sample = first_sample%28;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
int sample_byte = read_8bit(framesin*32+stream->offset+4+i,stream->streamfile);
|
||||
|
||||
int32_t hist;
|
||||
|
||||
switch (q>>4)
|
||||
{
|
||||
case 0:
|
||||
hist = 0;
|
||||
break;
|
||||
case 1:
|
||||
hist = (hist1 * 0x3c);
|
||||
break;
|
||||
case 2:
|
||||
hist = (hist1 * 0x73) - (hist2 * 0x34);
|
||||
break;
|
||||
case 3:
|
||||
hist = (hist1 * 0x62) - (hist2 * 0x37);
|
||||
break;
|
||||
}
|
||||
|
||||
hist = (hist+0x20)>>6;
|
||||
if (hist > 0x1fffff) hist = 0x1fffff;
|
||||
if (hist < -0x200000) hist = -0x200000;
|
||||
|
||||
hist2 = hist1;
|
||||
|
||||
hist1 = ((((channel==0?
|
||||
get_low_nibble_signed(sample_byte):
|
||||
get_high_nibble_signed(sample_byte)
|
||||
) << 12) >> (q & 0xf)) << 6) + hist;
|
||||
|
||||
outbuf[sample_count] = clamp16(hist1 >> 6);
|
||||
}
|
||||
|
||||
stream->adpcm_history1_32 = hist1;
|
||||
stream->adpcm_history2_32 = hist2;
|
||||
}
|
8
src/coding/ngc_dtk_decoder.h
Normal file
8
src/coding/ngc_dtk_decoder.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include "../vgmstream.h"
|
||||
|
||||
#ifndef _NGC_DTK_DECODER_H
|
||||
#define _NGC_DTK_DECODER_H
|
||||
|
||||
void decode_ngc_dtk(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
|
||||
|
||||
#endif
|
54
src/meta/ngc_adpdtk.c
Normal file
54
src/meta/ngc_adpdtk.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <math.h>
|
||||
#include "ngc_adpdtk.h"
|
||||
#include "../util.h"
|
||||
|
||||
VGMSTREAM * init_vgmstream_ngc_adpdtk(const char * const filename) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
STREAMFILE * infile = NULL;
|
||||
|
||||
size_t file_size;
|
||||
int i;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
if (strcasecmp("adp",filename_extension(filename))) goto fail;
|
||||
|
||||
/* try to open the file for checking */
|
||||
infile = open_streamfile(filename);
|
||||
if (!infile) goto fail;
|
||||
|
||||
/* file size is the only way to determine sample count */
|
||||
file_size = get_streamfile_size(infile);
|
||||
|
||||
/* .adp files have no header, so all we can do is look for a valid first frame */
|
||||
if (read_8bit(0,infile)!=read_8bit(2,infile) || read_8bit(1,infile)!=read_8bit(3,infile)) goto fail;
|
||||
|
||||
/* done with checking */
|
||||
close_streamfile(infile);
|
||||
|
||||
/* Hopefully we haven't falsely detected something else... */
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(2,0); /* always stereo, no loop */
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->num_samples = file_size/32*28;
|
||||
vgmstream->sample_rate = 48000;
|
||||
vgmstream->coding_type = coding_NGC_DTK;
|
||||
vgmstream->layout_type = layout_dtk_interleave;
|
||||
vgmstream->meta_type = meta_NGC_ADPDTK;
|
||||
|
||||
for (i=0;i<2;i++) {
|
||||
vgmstream->ch[i].channel_start_offset =
|
||||
vgmstream->ch[i].offset = 0;
|
||||
|
||||
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,32*0x400);
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
fail:
|
||||
if (infile) close_streamfile(infile);
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
12
src/meta/ngc_adpdtk.h
Normal file
12
src/meta/ngc_adpdtk.h
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* ngc_adpdtk.h - GC "DTK" ADPCM
|
||||
*/
|
||||
|
||||
#include "../vgmstream.h"
|
||||
|
||||
#ifndef _NGC_ADPDTK_H
|
||||
#define _NGC_ADPDTK_H
|
||||
|
||||
VGMSTREAM * init_vgmstream_ngc_adpdtk(const char * const filename);
|
||||
|
||||
#endif
|
@ -3,22 +3,25 @@
|
||||
#include "meta/brstm.h"
|
||||
#include "meta/nds_strm.h"
|
||||
#include "meta/agsc.h"
|
||||
#include "meta/ngc_adpdtk.h"
|
||||
#include "layout/interleave.h"
|
||||
#include "layout/nolayout.h"
|
||||
#include "coding/adx_decoder.h"
|
||||
#include "coding/gcdsp_decoder.h"
|
||||
#include "coding/pcm_decoder.h"
|
||||
#include "coding/ngc_dtk_decoder.h"
|
||||
|
||||
/*
|
||||
* List of functions that will recognize files. These should correspond pretty
|
||||
* directly to the metadata types
|
||||
*/
|
||||
#define INIT_VGMSTREAM_FCNS 4
|
||||
#define INIT_VGMSTREAM_FCNS 5
|
||||
VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = {
|
||||
init_vgmstream_adx,
|
||||
init_vgmstream_brstm,
|
||||
init_vgmstream_nds_strm,
|
||||
init_vgmstream_agsc,
|
||||
init_vgmstream_ngc_adpdtk,
|
||||
};
|
||||
|
||||
/* format detection and VGMSTREAM setup */
|
||||
@ -113,6 +116,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
|
||||
case layout_interleave_shortblock:
|
||||
render_vgmstream_interleave(buffer,sample_count,vgmstream);
|
||||
break;
|
||||
case layout_dtk_interleave:
|
||||
case layout_none:
|
||||
render_vgmstream_nolayout(buffer,sample_count,vgmstream);
|
||||
break;
|
||||
@ -131,6 +135,8 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
||||
return 1;
|
||||
case coding_NDS_IMA:
|
||||
return (vgmstream->interleave_block_size-4)*2;
|
||||
case coding_NGC_DTK:
|
||||
return 28;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -158,6 +164,8 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
|
||||
return 1;
|
||||
case coding_NDS_IMA:
|
||||
return vgmstream->interleave_block_size;
|
||||
case coding_NGC_DTK:
|
||||
return 32;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -219,6 +227,13 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_NGC_DTK:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_ngc_dtk(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do,chan);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,6 +331,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream) {
|
||||
case meta_DSP_AGSC:
|
||||
printf("AGSC header");
|
||||
break;
|
||||
case meta_NGC_ADPDTK:
|
||||
printf("assumed NGC DTK by .adp extension and valid first frame");
|
||||
break;
|
||||
default:
|
||||
printf("THEY SHOULD HAVE SENT A POET");
|
||||
}
|
||||
@ -341,6 +359,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream) {
|
||||
case coding_NDS_IMA:
|
||||
printf("NDS-style 4-bit IMA ADPCM");
|
||||
break;
|
||||
case coding_NGC_DTK:
|
||||
printf("Gamecube \"ADP\"/\"DTK\" 4-bit ADPCM");
|
||||
break;
|
||||
default:
|
||||
printf("CANNOT DECODE");
|
||||
}
|
||||
@ -357,6 +378,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream) {
|
||||
case layout_interleave_shortblock:
|
||||
printf("interleave with short last block");
|
||||
break;
|
||||
case layout_dtk_interleave:
|
||||
printf("nibble interleave");
|
||||
break;
|
||||
default:
|
||||
printf("INCONCEIVABLE");
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ typedef enum {
|
||||
coding_CRI_ADX, /* CRI ADX */
|
||||
coding_NGC_DSP, /* NGC ADPCM, called DSP */
|
||||
coding_NGC_AFC, /* other NGC ADPCM, called AFC */
|
||||
coding_NGC_DTK, /* NGC hardware disc ADPCM, called DTK or ADP */
|
||||
coding_NGC_DTK, /* NGC hardware disc ADPCM, called DTK, TRK or ADP */
|
||||
coding_PS2ADPCM, /* PS2 ADPCM, sometimes called "VAG" */
|
||||
coding_EA_XA, /* Electronic Arts XA */
|
||||
coding_CD_XA, /* CD-XA */
|
||||
@ -40,6 +40,8 @@ typedef enum {
|
||||
layout_halp_blocked, /* blocks with HALP-format header */
|
||||
layout_ast_blocked, /* */
|
||||
layout_strm_blocked, /* */
|
||||
/* otherwise odd */
|
||||
layout_dtk_interleave, /* dtk interleaves channels by nibble */
|
||||
} layout_t;
|
||||
|
||||
/* The meta type specifies how we know what we know about the file. We may know because of a header we read, some of it may have been guessed from filenames, etc. */
|
||||
@ -59,7 +61,7 @@ typedef enum {
|
||||
meta_ADX_03, /* ADX "type 03" */
|
||||
meta_ADX_04, /* ADX "type 04" */
|
||||
/* etc */
|
||||
meta_NGC_DTK, /* NGC DTK/ADP */
|
||||
meta_NGC_ADPDTK, /* NGC DTK/ADP, no header */
|
||||
meta_kRAW, /* almost headerless PCM */
|
||||
|
||||
} meta_t;
|
||||
|
@ -1,7 +1,7 @@
|
||||
SHELL = /bin/sh
|
||||
CFLAGS=-lm -O3
|
||||
|
||||
VGMSTREAMFILES = ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/meta/adx_header.c ../src/coding/adx_decoder.c ../src/coding/gcdsp_decoder.c ../src/meta/brstm.c ../src/layout/interleave.c ../src/layout/nolayout.c ../src/coding/pcm_decoder.c ../src/meta/nds_strm.c ../src/coding/ima_decoder.c ../src/meta/agsc.c
|
||||
VGMSTREAMFILES = ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/meta/adx_header.c ../src/coding/adx_decoder.c ../src/coding/gcdsp_decoder.c ../src/meta/brstm.c ../src/layout/interleave.c ../src/layout/nolayout.c ../src/coding/pcm_decoder.c ../src/meta/nds_strm.c ../src/coding/ima_decoder.c ../src/meta/agsc.c ../src/meta/ngc_adpdtk.c ../src/coding/ngc_dtk_decoder.c
|
||||
|
||||
test: test.c $(VGMSTREAMFILES)
|
||||
gcc $(CFLAGS) test.c $(VGMSTREAMFILES) -o test
|
||||
|
Loading…
Reference in New Issue
Block a user