mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 09:40:51 +01:00
Fix Lunar 2 SCD loops/sample rate/stereo and PCM8 cleanup
This commit is contained in:
parent
5aad45ab87
commit
4ee39206c3
@ -62,14 +62,14 @@ void decode_ngc_dtk(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspaci
|
||||
void decode_ngc_afc(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
|
||||
/* pcm_decoder */
|
||||
void decode_pcm16LE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm16BE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm16le(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm16be(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm16_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int big_endian);
|
||||
void decode_pcm8(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_sb_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_unsigned_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_unsigned(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_unsigned_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_pcm8_sb(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_ulaw(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_ulaw_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
void decode_alaw(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "../util.h"
|
||||
#include <math.h>
|
||||
|
||||
void decode_pcm16LE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
void decode_pcm16le(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
@ -11,7 +11,7 @@ void decode_pcm16LE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspaci
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm16BE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
void decode_pcm16be(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
@ -20,6 +20,15 @@ void decode_pcm16BE(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspaci
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm16_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int big_endian) {
|
||||
int i, sample_count;
|
||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = big_endian ? read_16bitBE : read_16bitLE;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
outbuf[sample_count]=read_16bit(stream->offset+i*2*channelspacing,stream->streamfile);
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm8(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
@ -38,14 +47,13 @@ void decode_pcm8_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspac
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm8_sb_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
void decode_pcm8_unsigned(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
int16_t v = (uint8_t)read_8bit(stream->offset+i*channelspacing,stream->streamfile);
|
||||
if (v&0x80) v = 0-(v&0x7f);
|
||||
outbuf[sample_count] = v*0x100;
|
||||
int16_t v = (uint8_t)read_8bit(stream->offset+i,stream->streamfile);
|
||||
outbuf[sample_count] = v*0x100 - 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,22 +67,14 @@ void decode_pcm8_unsigned_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int ch
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm8_unsigned(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
void decode_pcm8_sb(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
|
||||
int i;
|
||||
int32_t sample_count;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
int16_t v = (uint8_t)read_8bit(stream->offset+i,stream->streamfile);
|
||||
outbuf[sample_count] = v*0x100 - 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
void decode_pcm16_int(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int big_endian) {
|
||||
int i, sample_count;
|
||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = big_endian ? read_16bitBE : read_16bitLE;
|
||||
|
||||
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
|
||||
outbuf[sample_count]=read_16bit(stream->offset+i*2*channelspacing,stream->streamfile);
|
||||
if (v&0x80) v = 0-(v&0x7f);
|
||||
outbuf[sample_count] = v*0x100;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,6 +215,7 @@ static const char* extension_list[] = {
|
||||
"mihb",
|
||||
"mnstr",
|
||||
"mogg",
|
||||
//"mp3", //common
|
||||
//"mp4", //common
|
||||
//"mpc", //FFmpeg, not parsed (musepack) //common
|
||||
"mpdsp",
|
||||
@ -496,7 +497,7 @@ static const coding_info coding_info_list[] = {
|
||||
{coding_PCM8_int, "8-bit PCM with 1 byte interleave (block)"},
|
||||
{coding_PCM8_U, "8-bit unsigned PCM"},
|
||||
{coding_PCM8_U_int, "8-bit unsigned PCM with 1 byte interleave (block)"},
|
||||
{coding_PCM8_SB_int, "8-bit PCM with sign bit, 1 byte interleave (block)"},
|
||||
{coding_PCM8_SB, "8-bit PCM with sign bit"},
|
||||
{coding_ULAW, "8-bit u-Law"},
|
||||
{coding_ULAW_int, "8-bit u-Law with 1 byte interleave (block)"},
|
||||
{coding_ALAW, "8-bit a-Law"},
|
||||
|
@ -1,63 +1,65 @@
|
||||
#include "meta.h"
|
||||
#include "../util.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
/* PCM (from Lunar: Eternal Blue (Sega CD) */
|
||||
|
||||
/* .PCM - from Lunar: Eternal Blue (Sega CD) */
|
||||
VGMSTREAM * init_vgmstream_scd_pcm(STREAMFILE *streamFile) {
|
||||
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
off_t start_offset;
|
||||
int loop_flag, channel_count;
|
||||
|
||||
int loop_flag;
|
||||
int channel_count;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("pcm",filename_extension(filename))) goto fail;
|
||||
|
||||
/* check header */
|
||||
if (read_32bitBE(0x0,streamFile) != 0x00020000)
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "pcm"))
|
||||
goto fail;
|
||||
|
||||
loop_flag = (read_32bitLE(0x02,streamFile)!=0);
|
||||
channel_count = 1;
|
||||
if (read_16bitBE(0x00,streamFile) == 0x0002) {
|
||||
channel_count = 1;
|
||||
}
|
||||
else if (read_16bitBE(0x00,streamFile) == 0x0001) {
|
||||
channel_count = 2; /* RP025.PCM, RP039.PCM */
|
||||
}
|
||||
else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
start_offset = 0x800;
|
||||
|
||||
|
||||
/* extra validations since .pcm it's kinda generic */
|
||||
{
|
||||
off_t i;
|
||||
/* should be empty up to start (~0x0a/~0x10 sometimes has unknown values) */
|
||||
for (i = 0x20; i < start_offset; i++) {
|
||||
if (read_8bit(i, streamFile) != 0)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* loops start 0 is possible, plus all? files loops
|
||||
* (even sfx/voices loop, but those set loop start in silence near the end) */
|
||||
loop_flag = (read_32bitBE(0x06,streamFile) != 0);
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
start_offset = 0x200;
|
||||
vgmstream->channels = channel_count;
|
||||
vgmstream->sample_rate = 32000;
|
||||
vgmstream->coding_type = coding_PCM8_SB_int;
|
||||
vgmstream->num_samples = read_32bitBE(0x06,streamFile)*2;
|
||||
if(loop_flag) {
|
||||
vgmstream->loop_start_sample = read_32bitBE(0x02,streamFile)*0x400*2;
|
||||
vgmstream->loop_end_sample = read_32bitBE(0x06,streamFile)*2;
|
||||
}
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x1;
|
||||
vgmstream->meta_type = meta_SCD_PCM;
|
||||
vgmstream->sample_rate = 32500; /* looks correct compared to emu/recordings */
|
||||
vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count, 8);
|
||||
vgmstream->loop_start_sample = read_32bitBE(0x02,streamFile)*0x400*2;
|
||||
vgmstream->loop_end_sample = read_32bitBE(0x06,streamFile)*2;
|
||||
|
||||
/* open the file for reading */
|
||||
{
|
||||
int i;
|
||||
STREAMFILE * file;
|
||||
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (!file) goto fail;
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].streamfile = file;
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
vgmstream->ch[i].offset=start_offset+
|
||||
vgmstream->interleave_block_size*i;
|
||||
}
|
||||
}
|
||||
vgmstream->coding_type = coding_PCM8_SB;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x800;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
fail:
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1054,10 +1054,10 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
||||
case coding_PCM16BE:
|
||||
case coding_PCM16_int:
|
||||
case coding_PCM8:
|
||||
case coding_PCM8_U:
|
||||
case coding_PCM8_int:
|
||||
case coding_PCM8_SB_int:
|
||||
case coding_PCM8_U:
|
||||
case coding_PCM8_U_int:
|
||||
case coding_PCM8_SB:
|
||||
case coding_ULAW:
|
||||
case coding_ULAW_int:
|
||||
case coding_ALAW:
|
||||
@ -1238,10 +1238,10 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
|
||||
case coding_PCM16_int:
|
||||
return 0x02;
|
||||
case coding_PCM8:
|
||||
case coding_PCM8_U:
|
||||
case coding_PCM8_int:
|
||||
case coding_PCM8_SB_int:
|
||||
case coding_PCM8_U:
|
||||
case coding_PCM8_U_int:
|
||||
case coding_PCM8_SB:
|
||||
case coding_ULAW:
|
||||
case coding_ULAW_int:
|
||||
case coding_ALAW:
|
||||
@ -1446,16 +1446,17 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
chan, vgmstream->interleave_block_size);
|
||||
}
|
||||
break;
|
||||
|
||||
case coding_PCM16LE:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm16LE(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
decode_pcm16le(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_PCM16BE:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm16BE(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
decode_pcm16be(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do);
|
||||
}
|
||||
@ -1475,13 +1476,6 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_PCM8_U:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm8_unsigned(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_PCM8_int:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm8_int(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
@ -1489,9 +1483,9 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_PCM8_SB_int:
|
||||
case coding_PCM8_U:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm8_sb_int(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
decode_pcm8_unsigned(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do);
|
||||
}
|
||||
@ -1503,6 +1497,14 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
case coding_PCM8_SB:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_pcm8_sb(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do);
|
||||
}
|
||||
break;
|
||||
|
||||
case coding_ULAW:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_ulaw(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
|
||||
|
@ -77,7 +77,7 @@ typedef enum {
|
||||
coding_PCM8_int, /* 8-bit PCM with sample-level interleave (for blocks) */
|
||||
coding_PCM8_U, /* 8-bit PCM, unsigned (0x80 = 0) */
|
||||
coding_PCM8_U_int, /* 8-bit PCM, unsigned (0x80 = 0) with sample-level interleave (for blocks) */
|
||||
coding_PCM8_SB_int, /* 8-bit PCM, sign bit (others are 2's complement) with sample-level interleave (for blocks) */
|
||||
coding_PCM8_SB, /* 8-bit PCM, sign bit (others are 2's complement) */
|
||||
|
||||
coding_ULAW, /* 8-bit u-Law (non-linear PCM) */
|
||||
coding_ULAW_int, /* 8-bit u-Law (non-linear PCM) with sample-level interleave (for blocks) */
|
||||
|
Loading…
Reference in New Issue
Block a user