2008-07-05 13:49:29 +02:00
|
|
|
#include "meta.h"
|
2017-02-17 18:18:06 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-07-05 13:49:29 +02:00
|
|
|
#include "../util.h"
|
|
|
|
|
2017-07-29 23:16:30 +02:00
|
|
|
/* AHX - CRI format mainly for voices, contains MPEG-2 Layer 2 audio with lying frame headers */
|
2008-07-05 13:49:29 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ahx(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2017-02-17 18:35:58 +01:00
|
|
|
off_t start_offset;
|
2017-07-29 23:16:30 +02:00
|
|
|
int channel_count = 1, loop_flag = 0;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-02-17 18:35:58 +01:00
|
|
|
if ( !check_extensions(streamFile, "ahx") ) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
/* check first 2 bytes */
|
|
|
|
if ((uint16_t)read_16bitBE(0,streamFile)!=0x8000) goto fail;
|
|
|
|
|
|
|
|
/* get stream offset, check for CRI signature just before */
|
2017-07-29 23:16:30 +02:00
|
|
|
start_offset = (uint16_t)read_16bitBE(0x02,streamFile) + 0x04;
|
|
|
|
|
|
|
|
if ((uint16_t)read_16bitBE(start_offset-0x06,streamFile)!=0x2863 || /* "(c" */
|
|
|
|
(uint32_t)read_32bitBE(start_offset-0x04,streamFile)!=0x29435249) /* ")CRI" */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check for encoding type (0x10 is AHX for DC with bigger frames, 0x11 is AHX, 0x0N are ADX) */
|
|
|
|
if (read_8bit(0x04,streamFile) != 0x10 &&
|
|
|
|
read_8bit(0x04,streamFile) != 0x11) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
/* check for frame size (0 for AHX) */
|
2017-07-29 23:16:30 +02:00
|
|
|
if (read_8bit(0x05,streamFile) != 0) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
/* check for bits per sample? (0 for AHX) */
|
2017-07-29 23:16:30 +02:00
|
|
|
if (read_8bit(0x06,streamFile) != 0) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
2017-07-29 23:16:30 +02:00
|
|
|
/* check channel count (only mono AHXs can be created by the encoder) */
|
|
|
|
if (read_8bit(0x07,streamFile) != 1) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
2017-07-29 23:16:30 +02:00
|
|
|
/* check version signature */
|
|
|
|
if (read_8bit(0x12,streamFile) != 0x06) goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
2017-07-29 23:16:30 +02:00
|
|
|
/* build the VGMSTREAM */
|
2008-07-05 13:49:29 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2017-07-29 23:16:30 +02:00
|
|
|
vgmstream->sample_rate = read_32bitBE(0x08,streamFile); /* real sample rate */
|
|
|
|
vgmstream->num_samples = read_32bitBE(0x0c,streamFile); /* doesn't include encoder_delay (handled in decoder) */
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_AHX;
|
2017-07-29 23:16:30 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
mpeg_custom_config cfg;
|
|
|
|
|
|
|
|
memset(&cfg, 0, sizeof(mpeg_custom_config));
|
|
|
|
cfg.encryption = read_8bit(0x13,streamFile); /* 0x08 = keyword encryption */
|
|
|
|
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->codec_data = init_mpeg_custom_codec_data(streamFile, start_offset, &vgmstream->coding_type, channel_count, MPEG_AHX, &cfg);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
#else
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-05 13:49:29 +02:00
|
|
|
|
2017-02-17 18:35:58 +01:00
|
|
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
|
|
|
goto fail;
|
2008-07-05 13:49:29 +02:00
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-02-17 18:18:06 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-07-05 13:49:29 +02:00
|
|
|
return NULL;
|
|
|
|
}
|