mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 19:19:16 +01:00
Adding NPSF (PS2) Support - Fixing PSX Decoder for interleaved formats
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@84 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
33b3a3c87e
commit
096cf2df70
@ -1,40 +1,42 @@
|
||||
#include "psx_decoder.h"
|
||||
#include "../util.h"
|
||||
|
||||
double VAG_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 } } ;
|
||||
|
||||
void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
|
||||
int predict_nr, shift_factor, sample;
|
||||
int16_t hist1=stream->adpcm_history1_16;
|
||||
int16_t hist2=stream->adpcm_history2_16;
|
||||
|
||||
int scale;
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
predict_nr = read_8bit(stream->offset,stream->streamfile) >> 4;
|
||||
shift_factor = read_8bit(stream->offset,stream->streamfile) & 0xf;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
int sample_byte = (short)read_8bit(stream->offset+2+i/2,stream->streamfile);
|
||||
|
||||
scale = (short)((i&1 ?
|
||||
sample_byte >> 4 :
|
||||
sample_byte & 0x0f)<<12);
|
||||
|
||||
sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]);
|
||||
outbuf[sample_count] = clamp16(sample);
|
||||
|
||||
hist2=hist1;
|
||||
hist1=sample;
|
||||
}
|
||||
stream->adpcm_history1_16=hist1;
|
||||
stream->adpcm_history2_16=hist2;
|
||||
}
|
||||
|
||||
|
||||
#include "psx_decoder.h"
|
||||
#include "../util.h"
|
||||
|
||||
double VAG_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 } } ;
|
||||
|
||||
void decode_psx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
|
||||
int predict_nr, shift_factor, sample;
|
||||
int16_t hist1=stream->adpcm_history1_16;
|
||||
int16_t hist2=stream->adpcm_history2_16;
|
||||
|
||||
int scale;
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
int framesin = first_sample/28;
|
||||
|
||||
predict_nr = read_8bit(stream->offset+framesin*16,stream->streamfile) >> 4;
|
||||
shift_factor = read_8bit(stream->offset+framesin*16,stream->streamfile) & 0xf;
|
||||
|
||||
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 = (short)read_8bit(stream->offset+(framesin*16)+2+i/2,stream->streamfile);
|
||||
|
||||
scale = (short)((i&1 ?
|
||||
sample_byte >> 4 :
|
||||
sample_byte & 0x0f)<<12);
|
||||
|
||||
sample=(int)((scale >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]);
|
||||
outbuf[sample_count] = clamp16(sample);
|
||||
|
||||
hist2=hist1;
|
||||
hist1=sample;
|
||||
}
|
||||
stream->adpcm_history1_16=hist1;
|
||||
stream->adpcm_history2_16=hist2;
|
||||
}
|
@ -238,6 +238,10 @@
|
||||
RelativePath=".\meta\ps2_ads.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\ps2_npsf.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\rs03.h"
|
||||
>
|
||||
@ -298,6 +302,10 @@
|
||||
RelativePath=".\meta\ps2_ads.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\ps2_npsf.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\rs03.c"
|
||||
>
|
||||
|
76
src/meta/ps2_npsf.c
Normal file
76
src/meta/ps2_npsf.c
Normal file
@ -0,0 +1,76 @@
|
||||
#include "ps2_npsf.h"
|
||||
#include "../util.h"
|
||||
|
||||
/* Sony .ADS with SShd & SSbd Headers */
|
||||
|
||||
VGMSTREAM * init_vgmstream_ps2_npsf(const char * const filename) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
STREAMFILE * infile = NULL;
|
||||
|
||||
int loop_flag=0;
|
||||
int channel_count;
|
||||
off_t start_offset;
|
||||
int i;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
if (strcasecmp("npsf",filename_extension(filename))) goto fail;
|
||||
|
||||
/* try to open the file for header reading */
|
||||
infile = open_streamfile(filename);
|
||||
if (!infile) goto fail;
|
||||
|
||||
/* check NPSF Header */
|
||||
if (read_32bitBE(0x00,infile) != 0x4E505346)
|
||||
goto fail;
|
||||
|
||||
/* check loop */
|
||||
loop_flag = (read_32bitLE(0x14,infile)!=0xFFFFFFFF);
|
||||
channel_count=read_32bitLE(0x0C,infile);
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
vgmstream->channels = read_32bitLE(0x0C,infile);
|
||||
vgmstream->sample_rate = read_32bitLE(0x18,infile);
|
||||
|
||||
/* Check for Compression Scheme */
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->num_samples = read_32bitLE(0x08,infile)*28/16;
|
||||
|
||||
/* Get loop point values */
|
||||
if(vgmstream->loop_flag) {
|
||||
vgmstream->loop_start_sample = read_32bitLE(0x14,infile);
|
||||
vgmstream->loop_end_sample = read_32bitLE(0x08,infile)*28/16;
|
||||
}
|
||||
|
||||
vgmstream->interleave_block_size = read_32bitLE(0x04,infile)/2;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->meta_type = meta_PS2_NPSF;
|
||||
|
||||
start_offset = (off_t)read_32bitLE(0x10,infile);
|
||||
|
||||
close_streamfile(infile); infile=NULL;
|
||||
|
||||
/* open the file for reading by each channel */
|
||||
{
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,0x8000);
|
||||
|
||||
if (!vgmstream->ch[i].streamfile) goto fail;
|
||||
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
vgmstream->ch[i].offset=
|
||||
start_offset+vgmstream->interleave_block_size*i;
|
||||
}
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
fail:
|
||||
if (infile) close_streamfile(infile);
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
8
src/meta/ps2_npsf.h
Normal file
8
src/meta/ps2_npsf.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include "../vgmstream.h"
|
||||
|
||||
#ifndef _PS2_NPSF_H
|
||||
#define _PS2_NPSF_H
|
||||
|
||||
VGMSTREAM * init_vgmstream_ps2_npsf(const char * const filename);
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@
|
||||
#include "meta/Cstr.h"
|
||||
#include "meta/gcsw.h"
|
||||
#include "meta/ps2_ads.h"
|
||||
#include "meta/ps2_npsf.h"
|
||||
#include "layout/interleave.h"
|
||||
#include "layout/nolayout.h"
|
||||
#include "layout/blocked.h"
|
||||
@ -37,7 +38,7 @@
|
||||
* List of functions that will recognize files. These should correspond pretty
|
||||
* directly to the metadata types
|
||||
*/
|
||||
#define INIT_VGMSTREAM_FCNS 14
|
||||
#define INIT_VGMSTREAM_FCNS 15
|
||||
VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = {
|
||||
init_vgmstream_adx,
|
||||
init_vgmstream_brstm,
|
||||
@ -53,6 +54,7 @@ VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = {
|
||||
init_vgmstream_Cstr,
|
||||
init_vgmstream_gcsw,
|
||||
init_vgmstream_ps2_ads,
|
||||
init_vgmstream_ps2_npsf,
|
||||
};
|
||||
|
||||
|
||||
@ -364,7 +366,8 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) {
|
||||
* history through loop for certain types */
|
||||
if (vgmstream->meta_type == meta_DSP_STD ||
|
||||
vgmstream->meta_type == meta_DSP_RS03 ||
|
||||
vgmstream->meta_type == meta_DSP_CSTR) {
|
||||
vgmstream->meta_type == meta_DSP_CSTR ||
|
||||
vgmstream->coding_type == coding_PSX) {
|
||||
int i;
|
||||
for (i=0;i<vgmstream->channels;i++) {
|
||||
vgmstream->loop_ch[i].adpcm_history1_16 = vgmstream->ch[i].adpcm_history1_16;
|
||||
@ -575,6 +578,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
|
||||
break;
|
||||
case meta_PS2_SShd:
|
||||
snprintf(temp,TEMPSIZE,"ADS File (with SShd header)");
|
||||
break;
|
||||
case meta_PS2_NPSF:
|
||||
snprintf(temp,TEMPSIZE,"Namco Production Sound File (NPSF)");
|
||||
break;
|
||||
default:
|
||||
snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET");
|
||||
|
@ -71,7 +71,8 @@ typedef enum {
|
||||
meta_HALPST, /* HAL Labs HALPST */
|
||||
meta_GCSW, /* GCSW (PCM) */
|
||||
|
||||
meta_PS2_SShd, /* .ADS with SShd header */
|
||||
meta_PS2_SShd, /* .ADS with SShd header */
|
||||
meta_PS2_NPSF, /* Namco Production Sound File */
|
||||
} meta_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -45,7 +45,7 @@ int fade_samples = 0;
|
||||
|
||||
#define EXTENSION_LIST_SIZE 1024
|
||||
char working_extension_list[EXTENSION_LIST_SIZE] = {0};
|
||||
#define EXTENSION_COUNT 13
|
||||
#define EXTENSION_COUNT 14
|
||||
char * extension_list[EXTENSION_COUNT] = {
|
||||
"adx\0ADX Audio File (*.ADX)\0",
|
||||
"afc\0AFC Audio File (*.AFC)\0",
|
||||
@ -60,6 +60,7 @@ char * extension_list[EXTENSION_COUNT] = {
|
||||
"gcw\0GCW Audio File (*.GCW)\0",
|
||||
"ads\0PS2 ADS Audio File (*.ADS)\0",
|
||||
"ss2\0PS2 SS2 Audio File (*.SS2)\0",
|
||||
"npsf\0PS2 NPSF Audio File (*.NPSF)\0",
|
||||
};
|
||||
|
||||
/* stubs, we don't do anything fancy yet */
|
||||
|
Loading…
x
Reference in New Issue
Block a user