2008-04-03 15:40:36 +02:00
|
|
|
#ifdef _MSC_VER
|
2008-04-03 15:56:50 +02:00
|
|
|
#define _CRT_SECURE_NO_DEPRECATE
|
2008-04-03 15:40:36 +02:00
|
|
|
#endif
|
|
|
|
|
2008-03-11 02:27:59 +01:00
|
|
|
#include <stdio.h>
|
2008-03-25 08:30:04 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2008-01-31 07:04:26 +01:00
|
|
|
#include "vgmstream.h"
|
2008-05-06 05:35:37 +02:00
|
|
|
#include "meta/meta.h"
|
|
|
|
#include "layout/layout.h"
|
|
|
|
#include "coding/coding.h"
|
2019-03-09 20:50:58 +01:00
|
|
|
#include "mixing.h"
|
2008-05-04 22:36:40 +02:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
static void try_dual_file_stereo(VGMSTREAM * opened_vgmstream, STREAMFILE *streamFile, VGMSTREAM* (*init_vgmstream_function)(STREAMFILE*));
|
2017-04-22 13:31:12 +02:00
|
|
|
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* list of metadata parser functions that will recognize files, used on init */
|
2017-11-24 20:15:23 +01:00
|
|
|
VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_adx,
|
|
|
|
init_vgmstream_brstm,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_bfwav,
|
|
|
|
init_vgmstream_bfstm,
|
|
|
|
init_vgmstream_mca,
|
|
|
|
init_vgmstream_btsnd,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_nds_strm,
|
|
|
|
init_vgmstream_agsc,
|
|
|
|
init_vgmstream_ngc_adpdtk,
|
|
|
|
init_vgmstream_rsf,
|
|
|
|
init_vgmstream_afc,
|
|
|
|
init_vgmstream_ast,
|
|
|
|
init_vgmstream_halpst,
|
|
|
|
init_vgmstream_rs03,
|
|
|
|
init_vgmstream_ngc_dsp_std,
|
2018-03-29 23:28:02 +02:00
|
|
|
init_vgmstream_ngc_dsp_std_le,
|
2017-05-14 02:35:20 +02:00
|
|
|
init_vgmstream_ngc_mdsp_std,
|
2018-08-26 18:55:57 +02:00
|
|
|
init_vgmstream_csmp,
|
2018-08-26 19:16:24 +02:00
|
|
|
init_vgmstream_rfrm,
|
2017-11-25 00:43:18 +01:00
|
|
|
init_vgmstream_cstr,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_gcsw,
|
|
|
|
init_vgmstream_ps2_ads,
|
2019-03-11 14:49:29 +01:00
|
|
|
init_vgmstream_nps,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_rwsd,
|
2018-12-08 02:50:54 +01:00
|
|
|
init_vgmstream_xa,
|
2017-05-13 23:54:09 +02:00
|
|
|
init_vgmstream_ps2_rxws,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_ps2_rxw,
|
2017-08-28 17:47:19 +02:00
|
|
|
init_vgmstream_ngc_dsp_stm,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_ps2_exst,
|
|
|
|
init_vgmstream_ps2_svag,
|
2018-08-22 20:10:31 +02:00
|
|
|
init_vgmstream_mib_mih,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_ngc_mpdsp,
|
|
|
|
init_vgmstream_ps2_mic,
|
|
|
|
init_vgmstream_ngc_dsp_std_int,
|
2018-08-21 22:16:56 +02:00
|
|
|
init_vgmstream_vag,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_psx_gms,
|
|
|
|
init_vgmstream_ps2_ild,
|
|
|
|
init_vgmstream_ps2_pnb,
|
|
|
|
init_vgmstream_xbox_wavm,
|
|
|
|
init_vgmstream_ngc_str,
|
2017-07-01 23:02:24 +02:00
|
|
|
init_vgmstream_ea_schl,
|
2008-06-09 02:20:08 +02:00
|
|
|
init_vgmstream_caf,
|
|
|
|
init_vgmstream_ps2_vpk,
|
2008-06-10 03:20:54 +02:00
|
|
|
init_vgmstream_genh,
|
2008-06-15 09:59:43 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2008-06-15 06:01:03 +02:00
|
|
|
init_vgmstream_ogg_vorbis,
|
2008-06-15 09:59:43 +02:00
|
|
|
#endif
|
2018-08-26 02:26:38 +02:00
|
|
|
init_vgmstream_sli_ogg,
|
|
|
|
init_vgmstream_sfl_ogg,
|
2012-08-30 14:35:12 +02:00
|
|
|
#if 0
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_mp4_aac,
|
2012-08-30 14:35:12 +02:00
|
|
|
#endif
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2018-03-24 14:22:37 +01:00
|
|
|
init_vgmstream_akb_mp4,
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2008-06-15 11:23:34 +02:00
|
|
|
init_vgmstream_sadb,
|
2008-06-25 20:04:39 +02:00
|
|
|
init_vgmstream_ps2_bmdx,
|
2008-06-29 03:30:13 +02:00
|
|
|
init_vgmstream_wsi,
|
2008-07-01 05:23:44 +02:00
|
|
|
init_vgmstream_aifc,
|
2008-07-02 15:39:51 +02:00
|
|
|
init_vgmstream_str_snds,
|
2008-07-03 04:20:52 +02:00
|
|
|
init_vgmstream_ws_aud,
|
2008-07-05 13:49:29 +02:00
|
|
|
init_vgmstream_ahx,
|
2008-07-06 10:59:14 +02:00
|
|
|
init_vgmstream_ivb,
|
2008-07-06 14:23:37 +02:00
|
|
|
init_vgmstream_svs,
|
2008-07-06 20:05:04 +02:00
|
|
|
init_vgmstream_riff,
|
2009-05-25 22:59:50 +02:00
|
|
|
init_vgmstream_rifx,
|
2008-07-06 20:05:04 +02:00
|
|
|
init_vgmstream_pos,
|
2008-07-11 02:41:21 +02:00
|
|
|
init_vgmstream_nwa,
|
2017-11-18 02:20:52 +01:00
|
|
|
init_vgmstream_ea_1snh,
|
2019-01-02 17:17:14 +01:00
|
|
|
init_vgmstream_ea_eacs,
|
2008-07-12 17:20:39 +02:00
|
|
|
init_vgmstream_xss,
|
|
|
|
init_vgmstream_sl3,
|
|
|
|
init_vgmstream_hgc1,
|
|
|
|
init_vgmstream_aus,
|
|
|
|
init_vgmstream_rws,
|
2016-12-29 14:06:57 +01:00
|
|
|
init_vgmstream_fsb,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_fsb4_wav,
|
2014-04-24 06:31:04 +02:00
|
|
|
init_vgmstream_fsb5,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_rwx,
|
|
|
|
init_vgmstream_xwb,
|
2017-06-24 23:33:49 +02:00
|
|
|
init_vgmstream_ps2_xa30,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_musc,
|
2019-08-03 23:35:10 +02:00
|
|
|
init_vgmstream_musx,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_leg,
|
|
|
|
init_vgmstream_filp,
|
2019-03-22 21:12:33 +01:00
|
|
|
init_vgmstream_ikm_ps2,
|
|
|
|
init_vgmstream_ikm_pc,
|
|
|
|
init_vgmstream_ikm_psp,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_sfs,
|
|
|
|
init_vgmstream_bg00,
|
2017-11-15 23:26:38 +01:00
|
|
|
init_vgmstream_sat_dvi,
|
|
|
|
init_vgmstream_dc_kcey,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_ps2_rstm,
|
2008-07-20 07:41:41 +02:00
|
|
|
init_vgmstream_acm,
|
2008-07-21 01:28:16 +02:00
|
|
|
init_vgmstream_mus_acm,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_ps2_kces,
|
|
|
|
init_vgmstream_ps2_dxh,
|
2019-01-05 20:20:08 +01:00
|
|
|
init_vgmstream_vsv,
|
2017-11-16 00:41:06 +01:00
|
|
|
init_vgmstream_scd_pcm,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps2_pcm,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_ps2_rkv,
|
|
|
|
init_vgmstream_ps2_vas,
|
|
|
|
init_vgmstream_ps2_tec,
|
|
|
|
init_vgmstream_ps2_enth,
|
|
|
|
init_vgmstream_sdt,
|
2008-08-02 12:24:28 +02:00
|
|
|
init_vgmstream_aix,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_ngc_tydsp,
|
|
|
|
init_vgmstream_ngc_swd,
|
2008-12-20 22:26:01 +01:00
|
|
|
init_vgmstream_capdsp,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_xbox_wvs,
|
2009-08-25 05:21:28 +02:00
|
|
|
init_vgmstream_ngc_wvs,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_dc_str,
|
2009-01-23 15:06:14 +01:00
|
|
|
init_vgmstream_dc_str_v2,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_xbox_matx,
|
2017-11-23 22:48:11 +01:00
|
|
|
init_vgmstream_dec,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_vs,
|
2008-08-13 08:11:05 +02:00
|
|
|
init_vgmstream_dc_str,
|
2009-01-23 15:06:14 +01:00
|
|
|
init_vgmstream_dc_str_v2,
|
2008-08-22 02:24:15 +02:00
|
|
|
init_vgmstream_xbox_xmu,
|
|
|
|
init_vgmstream_xbox_xvas,
|
|
|
|
init_vgmstream_ngc_bh2pcm,
|
|
|
|
init_vgmstream_sat_sap,
|
|
|
|
init_vgmstream_dc_idvi,
|
|
|
|
init_vgmstream_ps2_rnd,
|
2018-08-12 18:04:19 +02:00
|
|
|
init_vgmstream_idsp_tt,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_kraw,
|
|
|
|
init_vgmstream_ps2_omu,
|
|
|
|
init_vgmstream_ps2_xa2,
|
2018-08-12 18:04:19 +02:00
|
|
|
init_vgmstream_nub_idsp,
|
|
|
|
init_vgmstream_idsp_nl,
|
|
|
|
init_vgmstream_idsp_ie,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ngc_ymf,
|
2008-09-23 13:07:41 +02:00
|
|
|
init_vgmstream_sadl,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ps2_ccc,
|
2018-12-08 02:45:19 +01:00
|
|
|
init_vgmstream_fag,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ps2_mihb,
|
2018-03-31 20:42:02 +02:00
|
|
|
init_vgmstream_ngc_pdt_split,
|
2018-04-01 02:15:10 +02:00
|
|
|
init_vgmstream_ngc_pdt,
|
2008-10-11 06:00:57 +02:00
|
|
|
init_vgmstream_wii_mus,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_dc_asd,
|
|
|
|
init_vgmstream_naomi_spsd,
|
2019-08-10 17:24:06 +02:00
|
|
|
init_vgmstream_rsd,
|
2008-11-07 00:30:33 +01:00
|
|
|
init_vgmstream_bgw,
|
2008-11-07 02:47:39 +01:00
|
|
|
init_vgmstream_spw,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ps2_ass,
|
2018-04-06 20:48:24 +02:00
|
|
|
init_vgmstream_ubi_jade,
|
|
|
|
init_vgmstream_ubi_jade_container,
|
2011-01-22 03:31:52 +01:00
|
|
|
init_vgmstream_seg,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_nds_strm_ffta2,
|
|
|
|
init_vgmstream_str_asr,
|
|
|
|
init_vgmstream_zwdsp,
|
|
|
|
init_vgmstream_gca,
|
|
|
|
init_vgmstream_spt_spd,
|
|
|
|
init_vgmstream_ish_isd,
|
|
|
|
init_vgmstream_gsp_gsb,
|
|
|
|
init_vgmstream_ydsp,
|
|
|
|
init_vgmstream_msvp,
|
|
|
|
init_vgmstream_ngc_ssm,
|
|
|
|
init_vgmstream_ps2_joe,
|
|
|
|
init_vgmstream_vgs,
|
2019-03-04 20:08:33 +01:00
|
|
|
init_vgmstream_dcs_wav,
|
2018-12-22 19:47:17 +01:00
|
|
|
init_vgmstream_mul,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_thp,
|
|
|
|
init_vgmstream_wii_sts,
|
|
|
|
init_vgmstream_ps2_p2bt,
|
|
|
|
init_vgmstream_ps2_gbts,
|
2008-12-24 01:00:10 +01:00
|
|
|
init_vgmstream_wii_sng,
|
2010-09-16 13:53:36 +02:00
|
|
|
init_vgmstream_ngc_dsp_iadp,
|
2009-01-03 12:08:44 +01:00
|
|
|
init_vgmstream_aax,
|
2011-01-04 15:20:49 +01:00
|
|
|
init_vgmstream_utf_dsp,
|
2009-01-08 15:29:40 +01:00
|
|
|
init_vgmstream_ngc_ffcc_str,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_sat_baka,
|
|
|
|
init_vgmstream_nds_swav,
|
2009-02-08 09:36:33 +01:00
|
|
|
init_vgmstream_ps2_vsf,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_nds_rrds,
|
|
|
|
init_vgmstream_ps2_tk5,
|
|
|
|
init_vgmstream_ps2_vsf_tta,
|
|
|
|
init_vgmstream_ads,
|
|
|
|
init_vgmstream_ps2_mcg,
|
2009-03-13 00:42:56 +01:00
|
|
|
init_vgmstream_zsd,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ps2_vgs,
|
2018-12-23 13:39:50 +01:00
|
|
|
init_vgmstream_redspark,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_ivaud,
|
2009-03-26 00:25:30 +01:00
|
|
|
init_vgmstream_wii_wsd,
|
2009-04-19 11:49:08 +02:00
|
|
|
init_vgmstream_wii_ndp,
|
|
|
|
init_vgmstream_ps2_sps,
|
|
|
|
init_vgmstream_ps2_xa2_rrp,
|
|
|
|
init_vgmstream_nds_hwas,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ngc_lps,
|
2009-05-01 17:03:51 +02:00
|
|
|
init_vgmstream_ps2_snd,
|
2009-05-10 09:14:29 +02:00
|
|
|
init_vgmstream_naomi_adpcm,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_sd9,
|
|
|
|
init_vgmstream_2dx9,
|
|
|
|
init_vgmstream_dsp_ygo,
|
2009-07-11 13:28:36 +02:00
|
|
|
init_vgmstream_ps2_vgv,
|
2009-08-23 10:42:14 +02:00
|
|
|
init_vgmstream_ngc_gcub,
|
2009-08-25 19:50:43 +02:00
|
|
|
init_vgmstream_maxis_xa,
|
|
|
|
init_vgmstream_ngc_sck_dsp,
|
2009-08-30 04:16:54 +02:00
|
|
|
init_vgmstream_apple_caff,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_pc_mxst,
|
|
|
|
init_vgmstream_sab,
|
2009-09-04 06:19:39 +02:00
|
|
|
init_vgmstream_exakt_sc,
|
2009-09-05 14:18:34 +02:00
|
|
|
init_vgmstream_wii_bns,
|
2009-09-11 20:40:26 +02:00
|
|
|
init_vgmstream_wii_was,
|
2010-02-19 12:28:29 +01:00
|
|
|
init_vgmstream_pona_3do,
|
|
|
|
init_vgmstream_pona_psx,
|
2009-10-15 11:24:04 +02:00
|
|
|
init_vgmstream_xbox_hlwav,
|
2009-11-18 01:46:36 +01:00
|
|
|
init_vgmstream_stx,
|
2010-01-10 22:22:20 +01:00
|
|
|
init_vgmstream_myspd,
|
2010-01-19 20:40:41 +01:00
|
|
|
init_vgmstream_his,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps2_ast,
|
|
|
|
init_vgmstream_dmsg,
|
2010-05-02 21:16:35 +02:00
|
|
|
init_vgmstream_ngc_dsp_aaap,
|
|
|
|
init_vgmstream_ngc_dsp_konami,
|
2010-04-20 22:26:10 +02:00
|
|
|
init_vgmstream_ps2_ster,
|
|
|
|
init_vgmstream_ps2_wb,
|
2010-03-23 21:57:12 +01:00
|
|
|
init_vgmstream_bnsf,
|
2010-03-29 22:06:08 +02:00
|
|
|
init_vgmstream_ps2_gcm,
|
2010-04-20 22:26:10 +02:00
|
|
|
init_vgmstream_ps2_smpl,
|
|
|
|
init_vgmstream_ps2_msa,
|
|
|
|
init_vgmstream_ps2_voi,
|
2018-03-25 11:08:36 +02:00
|
|
|
init_vgmstream_ngc_rkv,
|
2010-04-20 22:26:10 +02:00
|
|
|
init_vgmstream_dsp_ddsp,
|
2010-04-10 14:06:25 +02:00
|
|
|
init_vgmstream_p3d,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps2_tk1,
|
2010-04-20 22:26:10 +02:00
|
|
|
init_vgmstream_ngc_dsp_mpds,
|
|
|
|
init_vgmstream_dsp_str_ig,
|
2018-02-17 21:15:21 +01:00
|
|
|
init_vgmstream_ea_swvr,
|
2010-05-02 21:16:35 +02:00
|
|
|
init_vgmstream_ps2_b1s,
|
|
|
|
init_vgmstream_ps2_wad,
|
|
|
|
init_vgmstream_dsp_xiii,
|
|
|
|
init_vgmstream_dsp_cabelas,
|
|
|
|
init_vgmstream_ps2_adm,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps2_lpcm,
|
2010-05-10 10:02:22 +02:00
|
|
|
init_vgmstream_dsp_bdsp,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps2_vms,
|
|
|
|
init_vgmstream_xau,
|
2017-12-06 15:32:52 +01:00
|
|
|
init_vgmstream_bar,
|
2010-07-27 21:45:59 +02:00
|
|
|
init_vgmstream_ffw,
|
2010-08-04 11:12:08 +02:00
|
|
|
init_vgmstream_dsp_dspw,
|
2019-07-28 15:11:17 +02:00
|
|
|
init_vgmstream_jstm,
|
2017-09-29 23:37:20 +02:00
|
|
|
init_vgmstream_xvag,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ps3_cps,
|
2011-02-08 13:56:16 +01:00
|
|
|
init_vgmstream_sqex_scd,
|
2010-09-11 19:53:33 +02:00
|
|
|
init_vgmstream_ngc_nst_dsp,
|
2010-09-11 22:57:39 +02:00
|
|
|
init_vgmstream_baf,
|
2019-01-12 18:01:19 +01:00
|
|
|
init_vgmstream_baf_badrip,
|
2019-03-11 14:49:29 +01:00
|
|
|
init_vgmstream_msf,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_nub_vag,
|
|
|
|
init_vgmstream_ps3_past,
|
2017-03-18 15:07:58 +01:00
|
|
|
init_vgmstream_sgxd,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ngca,
|
|
|
|
init_vgmstream_wii_ras,
|
|
|
|
init_vgmstream_ps2_spm,
|
|
|
|
init_vgmstream_x360_tra,
|
|
|
|
init_vgmstream_ps2_iab,
|
2018-12-22 20:09:01 +01:00
|
|
|
init_vgmstream_vs_str,
|
2011-01-13 09:11:58 +01:00
|
|
|
init_vgmstream_lsf_n1nj4n,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_vawx,
|
|
|
|
init_vgmstream_ps2_wmus,
|
|
|
|
init_vgmstream_hyperscan_kvag,
|
|
|
|
init_vgmstream_ios_psnd,
|
|
|
|
init_vgmstream_pc_adp_bos,
|
|
|
|
init_vgmstream_pc_adp_otns,
|
2011-03-03 10:03:18 +01:00
|
|
|
init_vgmstream_eb_sfx,
|
|
|
|
init_vgmstream_eb_sf0,
|
2019-03-11 11:58:57 +01:00
|
|
|
init_vgmstream_mtaf,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_tun,
|
|
|
|
init_vgmstream_wpd,
|
|
|
|
init_vgmstream_mn_str,
|
|
|
|
init_vgmstream_mss,
|
|
|
|
init_vgmstream_ps2_hsf,
|
|
|
|
init_vgmstream_ps3_ivag,
|
|
|
|
init_vgmstream_ps2_2pfs,
|
2017-12-26 18:17:59 +01:00
|
|
|
init_vgmstream_xnb,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_ubi_ckd,
|
|
|
|
init_vgmstream_ps2_vbk,
|
|
|
|
init_vgmstream_otm,
|
|
|
|
init_vgmstream_bcstm,
|
2018-08-15 19:59:10 +02:00
|
|
|
init_vgmstream_idsp_nus3,
|
2017-01-18 21:28:14 +01:00
|
|
|
init_vgmstream_kt_g1l,
|
|
|
|
init_vgmstream_kt_wiibgm,
|
2017-12-27 06:14:50 +01:00
|
|
|
init_vgmstream_ktss,
|
2016-06-28 09:20:37 +02:00
|
|
|
init_vgmstream_hca,
|
2016-10-27 23:21:12 +02:00
|
|
|
init_vgmstream_ps2_svag_snk,
|
2017-01-08 12:59:04 +01:00
|
|
|
init_vgmstream_ps2_vds_vdm,
|
2017-01-08 14:19:32 +01:00
|
|
|
init_vgmstream_x360_cxs,
|
2017-01-25 22:23:45 +01:00
|
|
|
init_vgmstream_dsp_adx,
|
2018-03-24 14:22:37 +01:00
|
|
|
init_vgmstream_akb,
|
|
|
|
init_vgmstream_akb2,
|
2017-07-15 11:49:28 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
init_vgmstream_mp4_aac_ffmpeg,
|
|
|
|
#endif
|
2017-08-18 19:24:19 +02:00
|
|
|
init_vgmstream_bik,
|
2017-03-19 00:44:58 +01:00
|
|
|
init_vgmstream_x360_ast,
|
2017-04-02 12:27:21 +02:00
|
|
|
init_vgmstream_wwise,
|
2017-04-07 18:01:04 +02:00
|
|
|
init_vgmstream_ubi_raki,
|
2017-04-22 12:09:43 +02:00
|
|
|
init_vgmstream_x360_pasx,
|
2017-09-29 23:37:20 +02:00
|
|
|
init_vgmstream_nub_xma,
|
2017-04-22 13:12:01 +02:00
|
|
|
init_vgmstream_xma,
|
2017-04-22 15:00:22 +02:00
|
|
|
init_vgmstream_sxd,
|
2017-04-22 19:25:54 +02:00
|
|
|
init_vgmstream_ogl,
|
2017-04-28 17:26:25 +02:00
|
|
|
init_vgmstream_mc3,
|
2017-05-13 01:55:31 +02:00
|
|
|
init_vgmstream_gtd,
|
2017-05-13 02:22:15 +02:00
|
|
|
init_vgmstream_ta_aac_x360,
|
|
|
|
init_vgmstream_ta_aac_ps3,
|
2017-12-27 06:14:50 +01:00
|
|
|
init_vgmstream_ta_aac_mobile,
|
2018-03-24 12:17:04 +01:00
|
|
|
init_vgmstream_ta_aac_mobile_vorbis,
|
2018-05-12 13:53:58 +02:00
|
|
|
init_vgmstream_ta_aac_vita,
|
2018-10-10 00:48:24 +02:00
|
|
|
init_vgmstream_va3,
|
2019-03-11 11:58:57 +01:00
|
|
|
init_vgmstream_mta2,
|
|
|
|
init_vgmstream_mta2_container,
|
2017-06-09 22:26:09 +02:00
|
|
|
init_vgmstream_ngc_ulw,
|
2019-07-28 15:11:17 +02:00
|
|
|
init_vgmstream_xa_xa30,
|
|
|
|
init_vgmstream_xa_04sw,
|
2017-07-23 03:46:55 +02:00
|
|
|
init_vgmstream_ea_bnk,
|
2018-07-17 23:14:28 +02:00
|
|
|
init_vgmstream_ea_abk,
|
2018-07-21 20:57:35 +02:00
|
|
|
init_vgmstream_ea_hdr_dat,
|
2018-12-27 18:27:03 +01:00
|
|
|
init_vgmstream_ea_map_mus,
|
2018-12-27 18:01:36 +01:00
|
|
|
init_vgmstream_ea_mpf_mus,
|
2017-07-23 17:09:55 +02:00
|
|
|
init_vgmstream_ea_schl_fixed,
|
2017-07-29 11:46:53 +02:00
|
|
|
init_vgmstream_sk_aud,
|
2017-08-12 18:42:38 +02:00
|
|
|
init_vgmstream_stm,
|
2017-08-20 02:18:48 +02:00
|
|
|
init_vgmstream_ea_snu,
|
2017-08-28 15:14:24 +02:00
|
|
|
init_vgmstream_awc,
|
2018-04-21 21:52:30 +02:00
|
|
|
init_vgmstream_opus_std,
|
|
|
|
init_vgmstream_opus_n1,
|
|
|
|
init_vgmstream_opus_capcom,
|
|
|
|
init_vgmstream_opus_nop,
|
2018-05-05 23:01:49 +02:00
|
|
|
init_vgmstream_opus_shinen,
|
2018-07-15 08:37:15 +02:00
|
|
|
init_vgmstream_opus_nus3,
|
2018-10-07 23:59:42 +02:00
|
|
|
init_vgmstream_opus_sps_n1,
|
2018-08-01 07:24:26 +02:00
|
|
|
init_vgmstream_opus_nxa,
|
2017-10-08 17:51:54 +02:00
|
|
|
init_vgmstream_pc_al2,
|
2017-11-05 17:06:40 +01:00
|
|
|
init_vgmstream_pc_ast,
|
2017-11-23 22:32:31 +01:00
|
|
|
init_vgmstream_naac,
|
2017-11-05 17:06:40 +01:00
|
|
|
init_vgmstream_ubi_sb,
|
2018-12-22 22:47:24 +01:00
|
|
|
init_vgmstream_ubi_sm,
|
2019-03-17 19:30:02 +01:00
|
|
|
init_vgmstream_ubi_bnm,
|
2017-11-27 20:22:10 +01:00
|
|
|
init_vgmstream_ezw,
|
|
|
|
init_vgmstream_vxn,
|
2017-12-01 17:27:49 +01:00
|
|
|
init_vgmstream_ea_snr_sns,
|
|
|
|
init_vgmstream_ea_sps,
|
2019-01-13 03:15:18 +01:00
|
|
|
init_vgmstream_ea_abk_eaac,
|
2018-07-21 20:58:01 +02:00
|
|
|
init_vgmstream_ea_hdr_sth_dat,
|
2019-01-13 03:15:18 +01:00
|
|
|
init_vgmstream_ea_mpf_mus_eaac,
|
2019-02-11 10:37:11 +01:00
|
|
|
init_vgmstream_ea_tmx,
|
2019-01-13 00:42:54 +01:00
|
|
|
init_vgmstream_ea_sbr,
|
2019-01-13 19:53:57 +01:00
|
|
|
init_vgmstream_ea_sbr_harmony,
|
2017-12-02 16:33:43 +01:00
|
|
|
init_vgmstream_ngc_vid1,
|
2017-12-03 01:41:25 +01:00
|
|
|
init_vgmstream_flx,
|
2018-01-04 23:38:22 +01:00
|
|
|
init_vgmstream_mogg,
|
2018-01-13 17:47:40 +01:00
|
|
|
init_vgmstream_kma9,
|
2018-01-21 01:46:33 +01:00
|
|
|
init_vgmstream_fsb_encrypted,
|
2018-01-27 11:00:21 +01:00
|
|
|
init_vgmstream_xwc,
|
2018-03-03 02:03:53 +01:00
|
|
|
init_vgmstream_atsl,
|
2018-01-27 12:21:25 +01:00
|
|
|
init_vgmstream_sps_n1,
|
2018-01-27 14:00:31 +01:00
|
|
|
init_vgmstream_atx,
|
2018-01-27 22:34:48 +01:00
|
|
|
init_vgmstream_sqex_sead,
|
2018-03-03 18:46:12 +01:00
|
|
|
init_vgmstream_waf,
|
2018-03-11 19:24:06 +01:00
|
|
|
init_vgmstream_wave,
|
|
|
|
init_vgmstream_wave_segmented,
|
2018-03-23 22:41:42 +01:00
|
|
|
init_vgmstream_smv,
|
2018-03-25 19:59:58 +02:00
|
|
|
init_vgmstream_nxap,
|
2018-03-29 15:39:33 +02:00
|
|
|
init_vgmstream_ea_wve_au00,
|
|
|
|
init_vgmstream_ea_wve_ad10,
|
2018-03-29 17:01:46 +02:00
|
|
|
init_vgmstream_sthd,
|
2018-03-31 13:10:57 +02:00
|
|
|
init_vgmstream_pcm_sre,
|
2018-03-31 13:28:30 +02:00
|
|
|
init_vgmstream_dsp_mcadpcm,
|
2018-04-07 11:31:43 +02:00
|
|
|
init_vgmstream_ubi_lyn,
|
|
|
|
init_vgmstream_ubi_lyn_container,
|
2018-04-07 13:35:33 +02:00
|
|
|
init_vgmstream_msb_msh,
|
2018-04-15 00:48:37 +02:00
|
|
|
init_vgmstream_txtp,
|
2018-04-15 01:08:27 +02:00
|
|
|
init_vgmstream_smc_smh,
|
2018-04-20 18:27:08 +02:00
|
|
|
init_vgmstream_ppst,
|
2018-10-07 23:59:42 +02:00
|
|
|
init_vgmstream_opus_sps_n1_segmented,
|
2018-04-29 20:28:27 +02:00
|
|
|
init_vgmstream_ubi_bao_pk,
|
2019-02-03 01:47:59 +01:00
|
|
|
init_vgmstream_ubi_bao_atomic,
|
2018-04-29 21:04:55 +02:00
|
|
|
init_vgmstream_dsp_switch_audio,
|
2018-08-28 18:47:56 +02:00
|
|
|
init_vgmstream_sadf,
|
2018-06-03 13:08:41 +02:00
|
|
|
init_vgmstream_h4m,
|
2018-06-17 01:08:52 +02:00
|
|
|
init_vgmstream_ps2_ads_container,
|
2018-07-18 00:52:24 +02:00
|
|
|
init_vgmstream_asf,
|
2018-07-27 17:11:11 +02:00
|
|
|
init_vgmstream_xmd,
|
2018-08-02 17:15:09 +02:00
|
|
|
init_vgmstream_cks,
|
|
|
|
init_vgmstream_ckb,
|
2018-08-02 18:22:01 +02:00
|
|
|
init_vgmstream_wv6,
|
2018-08-04 21:02:10 +02:00
|
|
|
init_vgmstream_str_wav,
|
2018-08-13 23:03:39 +02:00
|
|
|
init_vgmstream_wavebatch,
|
2018-08-14 00:28:15 +02:00
|
|
|
init_vgmstream_hd3_bd3,
|
2018-08-15 17:34:17 +02:00
|
|
|
init_vgmstream_bnk_sony,
|
2018-08-15 19:59:10 +02:00
|
|
|
init_vgmstream_nus3bank,
|
2018-08-19 16:42:39 +02:00
|
|
|
init_vgmstream_scd_sscf,
|
2018-10-07 23:59:42 +02:00
|
|
|
init_vgmstream_dsp_sps_n1,
|
2018-08-28 18:47:56 +02:00
|
|
|
init_vgmstream_dsp_itl_ch,
|
|
|
|
init_vgmstream_a2m,
|
|
|
|
init_vgmstream_ahv,
|
|
|
|
init_vgmstream_msv,
|
2019-01-26 17:04:43 +01:00
|
|
|
init_vgmstream_sdf,
|
2018-08-28 18:47:56 +02:00
|
|
|
init_vgmstream_svg,
|
|
|
|
init_vgmstream_vis,
|
|
|
|
init_vgmstream_vai,
|
|
|
|
init_vgmstream_aif_asobo,
|
|
|
|
init_vgmstream_ao,
|
|
|
|
init_vgmstream_apc,
|
|
|
|
init_vgmstream_wv2,
|
|
|
|
init_vgmstream_xau_konami,
|
2018-09-06 17:45:34 +02:00
|
|
|
init_vgmstream_derf,
|
2018-09-09 15:29:34 +02:00
|
|
|
init_vgmstream_utk,
|
2018-09-22 17:45:02 +02:00
|
|
|
init_vgmstream_adpcm_capcom,
|
2018-09-23 04:26:11 +02:00
|
|
|
init_vgmstream_ue4opus,
|
2018-10-07 23:27:31 +02:00
|
|
|
init_vgmstream_xwma,
|
2018-10-13 21:01:58 +02:00
|
|
|
init_vgmstream_xopus,
|
2018-12-22 20:09:01 +01:00
|
|
|
init_vgmstream_vs_square,
|
2018-10-27 23:10:03 +02:00
|
|
|
init_vgmstream_msf_banpresto_wmsf,
|
|
|
|
init_vgmstream_msf_banpresto_2msf,
|
2018-11-09 21:23:31 +01:00
|
|
|
init_vgmstream_nwav,
|
2018-11-09 22:57:35 +01:00
|
|
|
init_vgmstream_xpcm,
|
2018-11-17 17:52:07 +01:00
|
|
|
init_vgmstream_msf_tamasoft,
|
2018-12-01 14:01:52 +01:00
|
|
|
init_vgmstream_xps_dat,
|
|
|
|
init_vgmstream_xps,
|
2018-12-08 00:10:44 +01:00
|
|
|
init_vgmstream_zsnd,
|
2018-12-09 01:23:40 +01:00
|
|
|
init_vgmstream_opus_opusx,
|
2019-08-03 12:22:09 +02:00
|
|
|
init_vgmstream_dsp_adpy,
|
|
|
|
init_vgmstream_dsp_adpx,
|
2018-12-09 02:00:47 +01:00
|
|
|
init_vgmstream_ogg_opus,
|
2018-12-15 12:37:01 +01:00
|
|
|
init_vgmstream_nus3audio,
|
2018-12-23 13:38:18 +01:00
|
|
|
init_vgmstream_imc,
|
|
|
|
init_vgmstream_imc_container,
|
2019-01-05 04:36:20 +01:00
|
|
|
init_vgmstream_smp,
|
2019-01-12 02:26:38 +01:00
|
|
|
init_vgmstream_gin,
|
2019-02-10 01:36:05 +01:00
|
|
|
init_vgmstream_dsf,
|
|
|
|
init_vgmstream_208,
|
2019-02-17 23:17:14 +01:00
|
|
|
init_vgmstream_dsp_ds2,
|
2019-02-23 23:10:58 +01:00
|
|
|
init_vgmstream_ffdl,
|
2019-02-24 11:34:09 +01:00
|
|
|
init_vgmstream_mus_vc,
|
2019-03-09 23:27:28 +01:00
|
|
|
init_vgmstream_strm_abylight,
|
2019-03-10 00:59:59 +01:00
|
|
|
init_vgmstream_sfh,
|
2019-03-10 11:11:27 +01:00
|
|
|
init_vgmstream_ea_schl_video,
|
2019-03-12 00:41:20 +01:00
|
|
|
init_vgmstream_msf_konami,
|
|
|
|
init_vgmstream_xwma_konami,
|
2019-03-16 00:10:28 +01:00
|
|
|
init_vgmstream_9tav,
|
2019-05-26 22:55:37 +02:00
|
|
|
init_vgmstream_fsb5_fev_bank,
|
2019-06-26 08:26:44 +02:00
|
|
|
init_vgmstream_bwav,
|
2019-07-07 04:30:11 +02:00
|
|
|
init_vgmstream_opus_prototype,
|
2019-07-07 20:46:14 +02:00
|
|
|
init_vgmstream_awb,
|
2019-07-14 21:24:28 +02:00
|
|
|
init_vgmstream_acb,
|
2019-07-12 12:14:39 +02:00
|
|
|
init_vgmstream_rad,
|
2019-07-21 15:08:39 +02:00
|
|
|
init_vgmstream_smk,
|
2019-08-02 21:11:55 +02:00
|
|
|
init_vgmstream_mzrt,
|
2019-08-04 11:57:48 +02:00
|
|
|
init_vgmstream_xavs,
|
2018-08-28 18:47:56 +02:00
|
|
|
|
|
|
|
/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */
|
2018-08-22 20:39:31 +02:00
|
|
|
init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */
|
|
|
|
init_vgmstream_ps2_int, /* .int raw PS-ADPCM */
|
|
|
|
init_vgmstream_ps_headerless, /* tries to detect a bunch of PS-ADPCM formats */
|
2018-08-22 21:16:25 +02:00
|
|
|
init_vgmstream_pc_snds, /* .snds PC, after ps_headerless */
|
2019-03-10 00:28:16 +01:00
|
|
|
init_vgmstream_s14_sss, /* .raw siren14 */
|
2018-08-22 20:39:31 +02:00
|
|
|
init_vgmstream_raw, /* .raw PCM */
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2018-08-22 20:39:31 +02:00
|
|
|
init_vgmstream_ffmpeg, /* may play anything incorrectly, since FFmpeg doesn't check extensions */
|
2016-07-17 08:02:27 +02:00
|
|
|
#endif
|
2008-01-31 07:04:26 +01:00
|
|
|
};
|
|
|
|
|
2008-06-09 02:20:08 +02:00
|
|
|
|
2008-03-25 08:30:04 +01:00
|
|
|
/* internal version with all parameters */
|
2017-11-24 20:15:23 +01:00
|
|
|
static VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile) {
|
2017-01-08 01:09:20 +01:00
|
|
|
int i, fcns_size;
|
2008-05-20 17:18:38 +02:00
|
|
|
|
|
|
|
if (!streamFile)
|
|
|
|
return NULL;
|
2008-01-31 07:04:26 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
fcns_size = (sizeof(init_vgmstream_functions)/sizeof(init_vgmstream_functions[0]));
|
2008-01-31 07:04:26 +01:00
|
|
|
/* try a series of formats, see which works */
|
2019-02-15 22:28:20 +01:00
|
|
|
for (i =0; i < fcns_size; i++) {
|
2017-01-08 01:09:20 +01:00
|
|
|
/* call init function and see if valid VGMSTREAM was returned */
|
2017-11-24 20:15:23 +01:00
|
|
|
VGMSTREAM * vgmstream = (init_vgmstream_functions[i])(streamFile);
|
|
|
|
if (!vgmstream)
|
|
|
|
continue;
|
|
|
|
|
2017-11-25 00:43:18 +01:00
|
|
|
/* fail if there is nothing to play (without this check vgmstream can generate empty files) */
|
|
|
|
if (vgmstream->num_samples <= 0) {
|
2019-03-02 19:23:37 +01:00
|
|
|
VGM_LOG("VGMSTREAM: wrong num_samples %i\n", vgmstream->num_samples);
|
2017-11-25 00:43:18 +01:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-11 23:36:12 +01:00
|
|
|
|
2019-03-02 19:23:37 +01:00
|
|
|
/* everything should have a reasonable sample rate */
|
|
|
|
if (vgmstream->sample_rate < VGMSTREAM_MIN_SAMPLE_RATE || vgmstream->sample_rate > VGMSTREAM_MAX_SAMPLE_RATE) {
|
|
|
|
VGM_LOG("VGMSTREAM: wrong sample_rate %i\n", vgmstream->sample_rate);
|
2017-11-25 00:43:18 +01:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-15 23:46:21 +01:00
|
|
|
|
|
|
|
/* sanify loops and remove bad metadata */
|
2017-11-25 00:43:18 +01:00
|
|
|
if (vgmstream->loop_flag) {
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->loop_end_sample <= vgmstream->loop_start_sample
|
|
|
|
|| vgmstream->loop_end_sample > vgmstream->num_samples
|
|
|
|
|| vgmstream->loop_start_sample < 0) {
|
|
|
|
VGM_LOG("VGMSTREAM: wrong loops ignored (lss=%i, lse=%i, ns=%i)\n",
|
|
|
|
vgmstream->loop_start_sample, vgmstream->loop_end_sample, vgmstream->num_samples);
|
2019-02-15 23:46:21 +01:00
|
|
|
vgmstream->loop_flag = 0;
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = 0;
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
2017-11-25 00:43:18 +01:00
|
|
|
}
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-25 00:43:18 +01:00
|
|
|
/* test if candidate for dual stereo */
|
2018-08-23 18:00:34 +02:00
|
|
|
if (vgmstream->channels == 1 && vgmstream->allow_dual_stereo == 1) {
|
2017-11-25 00:43:18 +01:00
|
|
|
try_dual_file_stereo(vgmstream, streamFile, init_vgmstream_functions[i]);
|
|
|
|
}
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2019-02-17 23:53:37 +01:00
|
|
|
/* clean as loops are readable metadata but loop fields may contain garbage
|
|
|
|
* (done *after* dual stereo as it needs loop fields to match) */
|
|
|
|
if (!vgmstream->loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-04 02:05:07 +01:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2017-11-25 00:43:18 +01:00
|
|
|
/* check FFmpeg streams here, for lack of a better place */
|
|
|
|
if (vgmstream->coding_type == coding_FFmpeg) {
|
|
|
|
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
2018-03-31 20:11:21 +02:00
|
|
|
if (data && data->streamCount && !vgmstream->num_streams) {
|
2017-11-25 00:43:18 +01:00
|
|
|
vgmstream->num_streams = data->streamCount;
|
2017-03-04 02:05:07 +01:00
|
|
|
}
|
2017-11-25 00:43:18 +01:00
|
|
|
}
|
2017-03-04 02:05:07 +01:00
|
|
|
#endif
|
|
|
|
|
2019-03-09 21:31:15 +01:00
|
|
|
/* some players are picky with incorrect channel layouts */
|
|
|
|
if (vgmstream->channel_layout > 0) {
|
|
|
|
int output_channels = vgmstream->channels;
|
|
|
|
int ch, count = 0, max_ch = 32;
|
|
|
|
for (ch = 0; ch < max_ch; ch++) {
|
|
|
|
int bit = (vgmstream->channel_layout >> ch) & 1;
|
|
|
|
if (ch > 17 && bit) {
|
|
|
|
VGM_LOG("VGMSTREAM: wrong bit %i in channel_layout %x\n", ch, vgmstream->channel_layout);
|
|
|
|
vgmstream->channel_layout = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count += bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > output_channels) {
|
|
|
|
VGM_LOG("VGMSTREAM: wrong totals %i in channel_layout %x\n", count, vgmstream->channel_layout);
|
|
|
|
vgmstream->channel_layout = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 20:05:53 +02:00
|
|
|
/* files can have thousands subsongs, but let's put a limit */
|
2019-03-09 23:27:28 +01:00
|
|
|
if (vgmstream->num_streams < 0 || vgmstream->num_streams > VGMSTREAM_MAX_SUBSONGS) {
|
2018-08-16 20:05:53 +02:00
|
|
|
VGM_LOG("VGMSTREAM: wrong num_streams (ns=%i)\n", vgmstream->num_streams);
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-25 00:43:18 +01:00
|
|
|
/* save info */
|
2018-04-15 00:48:37 +02:00
|
|
|
/* stream_index 0 may be used by plugins to signal "vgmstream default" (IOW don't force to 1) */
|
2019-02-15 23:46:21 +01:00
|
|
|
if (vgmstream->stream_index == 0) {
|
2018-04-15 00:48:37 +02:00
|
|
|
vgmstream->stream_index = streamFile->stream_index;
|
2019-02-15 23:46:21 +01:00
|
|
|
}
|
2017-08-12 11:27:10 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
|
|
|
|
setup_vgmstream(vgmstream); /* final setup */
|
2008-05-19 05:58:15 +02:00
|
|
|
|
2017-11-25 00:43:18 +01:00
|
|
|
return vgmstream;
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
|
|
|
|
2017-11-25 00:43:18 +01:00
|
|
|
/* not supported */
|
2008-01-31 07:04:26 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
void setup_vgmstream(VGMSTREAM * vgmstream) {
|
2019-02-25 00:38:35 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* save start things so we can restart when seeking */
|
|
|
|
memcpy(vgmstream->start_ch, vgmstream->ch, sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
|
|
|
memcpy(vgmstream->start_vgmstream, vgmstream, sizeof(VGMSTREAM));
|
|
|
|
|
|
|
|
/* layout's sub-VGMSTREAM are expected to setup externally and maybe call this,
|
|
|
|
* as they can be created using init_vgmstream or manually */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
/* format detection and VGMSTREAM setup, uses default parameters */
|
|
|
|
VGMSTREAM * init_vgmstream(const char * const filename) {
|
|
|
|
VGMSTREAM *vgmstream = NULL;
|
|
|
|
STREAMFILE *streamFile = open_stdio_streamfile(filename);
|
|
|
|
if (streamFile) {
|
|
|
|
vgmstream = init_vgmstream_from_STREAMFILE(streamFile);
|
|
|
|
close_streamfile(streamFile);
|
|
|
|
}
|
|
|
|
return vgmstream;
|
|
|
|
}
|
|
|
|
|
|
|
|
VGMSTREAM * init_vgmstream_from_STREAMFILE(STREAMFILE *streamFile) {
|
2017-11-24 20:15:23 +01:00
|
|
|
return init_vgmstream_internal(streamFile);
|
2008-05-20 17:18:38 +02:00
|
|
|
}
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* Reset a VGMSTREAM to its state at the start of playback (when a plugin seeks back to zero). */
|
2008-05-19 05:58:15 +02:00
|
|
|
void reset_vgmstream(VGMSTREAM * vgmstream) {
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* reset the VGMSTREAM and channels back to their original state */
|
|
|
|
memcpy(vgmstream, vgmstream->start_vgmstream, sizeof(VGMSTREAM));
|
|
|
|
memcpy(vgmstream->ch, vgmstream->start_ch, sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
|
|
|
/* loop_ch is not reset here because there is a possibility of the
|
2008-05-19 05:58:15 +02:00
|
|
|
* init_vgmstream_* function doing something tricky and precomputing it.
|
|
|
|
* Otherwise hit_loop will be 0 and it will be copied over anyway when we
|
|
|
|
* really hit the loop start. */
|
2008-06-15 06:01:03 +02:00
|
|
|
|
2019-02-23 16:17:29 +01:00
|
|
|
/* reset custom codec */
|
2008-06-15 06:01:03 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_OGG_VORBIS) {
|
2017-04-29 22:37:15 +02:00
|
|
|
reset_ogg_vorbis(vgmstream);
|
2008-06-15 06:01:03 +02:00
|
|
|
}
|
2017-03-25 14:57:44 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_VORBIS_custom) {
|
2017-07-28 23:26:58 +02:00
|
|
|
reset_vorbis_custom(vgmstream);
|
2017-04-22 19:25:54 +02:00
|
|
|
}
|
2008-06-15 06:01:03 +02:00
|
|
|
#endif
|
2017-04-29 22:37:15 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CRI_HCA) {
|
2018-08-29 23:42:47 +02:00
|
|
|
reset_hca(vgmstream->codec_data);
|
2016-06-28 09:20:37 +02:00
|
|
|
}
|
2017-04-29 22:37:15 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_EA_MT) {
|
2017-12-03 13:44:55 +01:00
|
|
|
reset_ea_mt(vgmstream);
|
|
|
|
}
|
|
|
|
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MP4_AAC) {
|
2018-01-04 23:38:22 +01:00
|
|
|
reset_mp4_aac(vgmstream);
|
|
|
|
}
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2017-04-29 22:37:15 +02:00
|
|
|
|
2008-07-05 13:49:29 +02:00
|
|
|
#ifdef VGM_USE_MPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MPEG_custom ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_ealayer3 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer1 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer2 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer3) {
|
2017-02-17 17:20:40 +01:00
|
|
|
reset_mpeg(vgmstream);
|
2008-07-05 13:49:29 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-04-29 22:37:15 +02:00
|
|
|
|
2010-03-23 21:57:12 +01:00
|
|
|
#ifdef VGM_USE_G7221
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_G7221C) {
|
2017-04-29 22:37:15 +02:00
|
|
|
reset_g7221(vgmstream);
|
2010-03-23 21:57:12 +01:00
|
|
|
}
|
|
|
|
#endif
|
2008-07-20 07:41:41 +02:00
|
|
|
|
2015-01-25 06:08:25 +01:00
|
|
|
#ifdef VGM_USE_G719
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_G719) {
|
2018-09-09 12:24:08 +02:00
|
|
|
reset_g719(vgmstream->codec_data, vgmstream->channels);
|
2015-01-25 06:08:25 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-26 11:54:15 +02:00
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_AT3plus) {
|
2018-01-04 23:38:22 +01:00
|
|
|
reset_at3plus(vgmstream);
|
|
|
|
}
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2017-12-29 00:29:33 +01:00
|
|
|
|
|
|
|
#ifdef VGM_USE_ATRAC9
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_ATRAC9) {
|
2017-12-29 00:29:33 +01:00
|
|
|
reset_atrac9(vgmstream);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-12 00:58:20 +02:00
|
|
|
#ifdef VGM_USE_CELT
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CELT_FSB) {
|
2018-08-12 00:58:20 +02:00
|
|
|
reset_celt_fsb(vgmstream);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_FFmpeg) {
|
2016-12-01 19:58:51 +01:00
|
|
|
reset_ffmpeg(vgmstream);
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-26 11:54:15 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_ACM) {
|
2018-09-04 18:37:51 +02:00
|
|
|
reset_acm(vgmstream->codec_data);
|
2008-07-20 09:28:17 +02:00
|
|
|
}
|
2008-08-02 12:24:28 +02:00
|
|
|
|
2018-03-16 18:35:21 +01:00
|
|
|
if (vgmstream->coding_type == coding_NWA) {
|
2017-12-06 15:32:52 +01:00
|
|
|
nwa_codec_data *data = vgmstream->codec_data;
|
2019-02-23 16:17:29 +01:00
|
|
|
if (data) reset_nwa(data->nwa);
|
2008-08-02 12:24:28 +02:00
|
|
|
}
|
2008-08-03 16:58:03 +02:00
|
|
|
|
2019-02-23 16:17:29 +01:00
|
|
|
/* reset custom layouts */
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->layout_type == layout_segmented) {
|
2018-03-10 20:25:57 +01:00
|
|
|
reset_layout_segmented(vgmstream->layout_data);
|
2009-01-03 12:08:44 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
2018-03-30 21:28:32 +02:00
|
|
|
reset_layout_layered(vgmstream->layout_data);
|
2012-08-24 19:36:40 +02:00
|
|
|
}
|
2019-02-15 22:28:20 +01:00
|
|
|
|
|
|
|
/* note that this does not reset the constituent STREAMFILES
|
2019-02-23 16:17:29 +01:00
|
|
|
* (vgmstream->ch[N].streamfiles' internal state, though shouldn't matter) */
|
2008-05-19 05:58:15 +02:00
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Allocate memory and setup a VGMSTREAM */
|
2019-02-15 22:28:20 +01:00
|
|
|
VGMSTREAM * allocate_vgmstream(int channel_count, int loop_flag) {
|
2008-01-31 07:04:26 +01:00
|
|
|
VGMSTREAM * vgmstream;
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* up to ~16-24 aren't too rare for multilayered files, more is probably a bug */
|
2019-02-23 23:38:53 +01:00
|
|
|
if (channel_count <= 0 || channel_count > VGMSTREAM_MAX_CHANNELS) {
|
2018-08-15 17:36:20 +02:00
|
|
|
VGM_LOG("VGMSTREAM: error allocating %i channels\n", channel_count);
|
2018-02-25 12:17:51 +01:00
|
|
|
return NULL;
|
2018-08-15 17:36:20 +02:00
|
|
|
}
|
2008-04-02 19:50:50 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* VGMSTREAM's alloc'ed internals work as follows:
|
|
|
|
* - vgmstream: main struct (config+state) modified by metas, layouts and codings as needed
|
|
|
|
* - ch: config+state per channel, also modified by those
|
|
|
|
* - start_vgmstream: vgmstream clone copied on init_vgmstream and restored on reset_vgmstream
|
|
|
|
* - start_ch: ch clone copied on init_vgmstream and restored on reset_vgmstream
|
|
|
|
* - loop_ch: ch clone copied on loop start and restored on loop end (vgmstream_do_loop)
|
|
|
|
* - codec/layout_data: custom state for complex codecs or layouts, handled externally
|
|
|
|
*
|
|
|
|
* Here we only create the basic structs to be filled, and only after init_vgmstream it
|
|
|
|
* can be considered ready. Clones are shallow copies, in that they share alloc'ed struts
|
|
|
|
* (like, vgmstream->ch and start_vgmstream->ch will be the same after init_vgmstream, or
|
|
|
|
* start_vgmstream->start_vgmstream will end up pointing to itself)
|
|
|
|
*
|
|
|
|
* This is all a bit too brittle, so code alloc'ing or changing anything sensitive should
|
|
|
|
* take care clones are properly synced.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* create vgmstream + main structs (other data is 0'ed) */
|
2008-01-31 07:04:26 +01:00
|
|
|
vgmstream = calloc(1,sizeof(VGMSTREAM));
|
|
|
|
if (!vgmstream) return NULL;
|
2008-08-03 16:58:03 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
vgmstream->start_vgmstream = calloc(1,sizeof(VGMSTREAM));
|
|
|
|
if (!vgmstream->start_vgmstream) goto fail;
|
2008-05-19 05:58:15 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
vgmstream->ch = calloc(channel_count,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!vgmstream->ch) goto fail;
|
2008-01-31 07:04:26 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
vgmstream->start_ch = calloc(channel_count,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!vgmstream->start_ch) goto fail;
|
2008-01-31 07:04:26 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_ch = calloc(channel_count,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!vgmstream->loop_ch) goto fail;
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->loop_flag = loop_flag;
|
2008-01-31 07:04:26 +01:00
|
|
|
|
2019-03-09 20:50:58 +01:00
|
|
|
mixing_init(vgmstream); /* pre-init */
|
2019-03-24 01:21:09 +01:00
|
|
|
|
2019-02-25 00:38:35 +01:00
|
|
|
//vgmstream->stream_name_size = STREAM_NAME_SIZE;
|
2008-01-31 07:04:26 +01:00
|
|
|
return vgmstream;
|
2019-02-15 22:28:20 +01:00
|
|
|
fail:
|
|
|
|
if (vgmstream) {
|
2019-03-24 01:21:09 +01:00
|
|
|
mixing_close(vgmstream);
|
2019-02-15 22:28:20 +01:00
|
|
|
free(vgmstream->ch);
|
|
|
|
free(vgmstream->start_ch);
|
|
|
|
free(vgmstream->loop_ch);
|
|
|
|
free(vgmstream->start_vgmstream);
|
|
|
|
}
|
|
|
|
free(vgmstream);
|
|
|
|
return NULL;
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void close_vgmstream(VGMSTREAM * vgmstream) {
|
2017-04-29 22:37:15 +02:00
|
|
|
if (!vgmstream)
|
|
|
|
return;
|
2008-01-31 07:04:26 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* free custom codecs */
|
2008-06-15 06:01:03 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_OGG_VORBIS) {
|
2017-04-29 22:37:15 +02:00
|
|
|
free_ogg_vorbis(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
2008-06-15 06:01:03 +02:00
|
|
|
}
|
2017-03-25 14:57:44 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_VORBIS_custom) {
|
2017-07-28 23:26:58 +02:00
|
|
|
free_vorbis_custom(vgmstream->codec_data);
|
2017-04-22 19:25:54 +02:00
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
2008-06-15 06:01:03 +02:00
|
|
|
#endif
|
2016-06-29 04:27:30 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CRI_HCA) {
|
2017-04-29 22:37:15 +02:00
|
|
|
free_hca(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
2016-06-28 09:20:37 +02:00
|
|
|
}
|
2017-12-06 15:32:52 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_EA_MT) {
|
2018-09-08 19:22:56 +02:00
|
|
|
free_ea_mt(vgmstream->codec_data, vgmstream->channels);
|
2017-12-03 13:44:55 +01:00
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_FFmpeg) {
|
2017-04-29 22:37:15 +02:00
|
|
|
free_ffmpeg(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
2008-06-15 06:01:03 +02:00
|
|
|
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MP4_AAC) {
|
2018-01-04 23:38:22 +01:00
|
|
|
free_mp4_aac(vgmstream->codec_data);
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->codec_data = NULL;
|
2018-01-04 23:38:22 +01:00
|
|
|
}
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2012-08-30 14:35:12 +02:00
|
|
|
|
2008-07-05 13:49:29 +02:00
|
|
|
#ifdef VGM_USE_MPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MPEG_custom ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_ealayer3 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer1 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer2 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer3) {
|
2017-04-29 22:37:15 +02:00
|
|
|
free_mpeg(vgmstream->codec_data);
|
2017-02-17 17:20:40 +01:00
|
|
|
vgmstream->codec_data = NULL;
|
2008-07-05 13:49:29 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-23 21:57:12 +01:00
|
|
|
#ifdef VGM_USE_G7221
|
2018-09-22 16:32:21 +02:00
|
|
|
if (vgmstream->coding_type == coding_G7221C) {
|
2017-04-29 22:37:15 +02:00
|
|
|
free_g7221(vgmstream);
|
2010-03-23 21:57:12 +01:00
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-25 06:08:25 +01:00
|
|
|
#ifdef VGM_USE_G719
|
|
|
|
if (vgmstream->coding_type == coding_G719) {
|
2018-09-09 12:24:08 +02:00
|
|
|
free_g719(vgmstream->codec_data, vgmstream->channels);
|
2015-01-25 06:08:25 +01:00
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-26 11:54:15 +02:00
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2018-01-04 23:38:22 +01:00
|
|
|
if (vgmstream->coding_type == coding_AT3plus) {
|
|
|
|
free_at3plus(vgmstream->codec_data);
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->codec_data = NULL;
|
2018-01-04 23:38:22 +01:00
|
|
|
}
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
|
|
|
|
2017-12-29 00:29:33 +01:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
if (vgmstream->coding_type == coding_ATRAC9) {
|
|
|
|
free_atrac9(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-12 00:58:20 +02:00
|
|
|
#ifdef VGM_USE_CELT
|
|
|
|
if (vgmstream->coding_type == coding_CELT_FSB) {
|
|
|
|
free_celt_fsb(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_ACM) {
|
2018-03-16 15:42:01 +01:00
|
|
|
free_acm(vgmstream->codec_data);
|
|
|
|
vgmstream->codec_data = NULL;
|
2008-07-20 07:41:41 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 18:35:21 +01:00
|
|
|
if (vgmstream->coding_type == coding_NWA) {
|
2018-04-19 22:44:05 +02:00
|
|
|
if (vgmstream->codec_data) {
|
|
|
|
nwa_codec_data *data = (nwa_codec_data *) vgmstream->codec_data;
|
|
|
|
if (data->nwa)
|
|
|
|
close_nwa(data->nwa);
|
|
|
|
free(data);
|
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
}
|
2017-12-06 15:32:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
/* free custom layouts */
|
|
|
|
if (vgmstream->layout_type == layout_segmented) {
|
2018-03-10 20:25:57 +01:00
|
|
|
free_layout_segmented(vgmstream->layout_data);
|
2018-03-30 21:28:32 +02:00
|
|
|
vgmstream->layout_data = NULL;
|
2009-01-03 12:08:44 +01:00
|
|
|
}
|
2008-08-03 16:58:03 +02:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
2018-03-30 21:28:32 +02:00
|
|
|
free_layout_layered(vgmstream->layout_data);
|
|
|
|
vgmstream->layout_data = NULL;
|
2012-08-24 19:36:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
|
2008-08-02 12:24:28 +02:00
|
|
|
/* now that the special cases have had their chance, clean up the standard items */
|
2017-10-28 01:34:32 +02:00
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
for (i = 0; i < vgmstream->channels; i++) {
|
2017-10-28 01:34:32 +02:00
|
|
|
if (vgmstream->ch[i].streamfile) {
|
|
|
|
close_streamfile(vgmstream->ch[i].streamfile);
|
|
|
|
/* Multiple channels might have the same streamfile. Find the others
|
2019-02-15 22:28:20 +01:00
|
|
|
* that are the same as this and clear them so they won't be closed again. */
|
|
|
|
for (j = 0; j < vgmstream->channels; j++) {
|
|
|
|
if (i != j && vgmstream->ch[j].streamfile == vgmstream->ch[i].streamfile) {
|
2017-10-28 01:34:32 +02:00
|
|
|
vgmstream->ch[j].streamfile = NULL;
|
|
|
|
}
|
2008-08-02 12:24:28 +02:00
|
|
|
}
|
2017-10-28 01:34:32 +02:00
|
|
|
vgmstream->ch[i].streamfile = NULL;
|
2008-08-02 12:24:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 01:21:09 +01:00
|
|
|
|
2019-03-09 20:50:58 +01:00
|
|
|
mixing_close(vgmstream);
|
2019-02-15 22:28:20 +01:00
|
|
|
free(vgmstream->ch);
|
|
|
|
free(vgmstream->start_ch);
|
|
|
|
free(vgmstream->loop_ch);
|
|
|
|
free(vgmstream->start_vgmstream);
|
2008-01-31 07:04:26 +01:00
|
|
|
free(vgmstream);
|
|
|
|
}
|
|
|
|
|
2017-05-18 19:55:00 +02:00
|
|
|
/* calculate samples based on player's config */
|
2008-05-16 22:28:36 +02:00
|
|
|
int32_t get_vgmstream_play_samples(double looptimes, double fadeseconds, double fadedelayseconds, VGMSTREAM * vgmstream) {
|
2008-01-31 07:04:26 +01:00
|
|
|
if (vgmstream->loop_flag) {
|
2018-09-07 19:34:31 +02:00
|
|
|
if (vgmstream->loop_target == (int)looptimes) { /* set externally, as this function is info-only */
|
2017-05-18 19:55:00 +02:00
|
|
|
/* Continue playing the file normally after looping, instead of fading.
|
|
|
|
* Most files cut abruply after the loop, but some do have proper endings.
|
|
|
|
* With looptimes = 1 this option should give the same output vs loop disabled */
|
|
|
|
int loop_count = (int)looptimes; /* no half loops allowed */
|
|
|
|
return vgmstream->loop_start_sample
|
|
|
|
+ (vgmstream->loop_end_sample - vgmstream->loop_start_sample) * loop_count
|
|
|
|
+ (vgmstream->num_samples - vgmstream->loop_end_sample);
|
|
|
|
}
|
|
|
|
else {
|
2018-09-07 19:34:31 +02:00
|
|
|
return vgmstream->loop_start_sample
|
2017-05-18 19:55:00 +02:00
|
|
|
+ (vgmstream->loop_end_sample - vgmstream->loop_start_sample) * looptimes
|
2018-09-07 19:34:31 +02:00
|
|
|
+ (fadedelayseconds + fadeseconds) * vgmstream->sample_rate;
|
2017-05-18 19:55:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return vgmstream->num_samples;
|
|
|
|
}
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
|
|
|
|
2017-12-06 16:55:41 +01:00
|
|
|
void vgmstream_force_loop(VGMSTREAM* vgmstream, int loop_flag, int loop_start_sample, int loop_end_sample) {
|
|
|
|
if (!vgmstream) return;
|
|
|
|
|
|
|
|
/* this requires a bit more messing with the VGMSTREAM than I'm comfortable with... */
|
|
|
|
if (loop_flag && !vgmstream->loop_flag && !vgmstream->loop_ch) {
|
|
|
|
vgmstream->loop_ch = calloc(vgmstream->channels,sizeof(VGMSTREAMCHANNEL));
|
2019-02-15 22:28:20 +01:00
|
|
|
if (!vgmstream->loop_ch) loop_flag = 0; /* ??? */
|
2017-12-06 16:55:41 +01:00
|
|
|
}
|
2018-09-06 16:44:42 +02:00
|
|
|
else if (!loop_flag && vgmstream->loop_flag) {
|
2019-02-15 22:28:20 +01:00
|
|
|
free(vgmstream->loop_ch); /* not important though */
|
2018-08-19 00:43:06 +02:00
|
|
|
vgmstream->loop_ch = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-06 16:55:41 +01:00
|
|
|
vgmstream->loop_flag = loop_flag;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = loop_start_sample;
|
|
|
|
vgmstream->loop_end_sample = loop_end_sample;
|
2019-02-15 23:46:21 +01:00
|
|
|
}
|
|
|
|
#if 0 /* keep metadata as it's may be shown (with 'loop disabled' info) */
|
|
|
|
else {
|
2018-08-19 00:43:06 +02:00
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = 0;
|
|
|
|
}
|
2019-02-15 23:46:21 +01:00
|
|
|
#endif
|
2019-02-15 22:28:20 +01:00
|
|
|
|
2018-08-19 00:43:06 +02:00
|
|
|
/* propagate changes to layouts that need them */
|
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
|
|
|
int i;
|
|
|
|
layered_layout_data *data = vgmstream->layout_data;
|
|
|
|
for (i = 0; i < data->layer_count; i++) {
|
|
|
|
vgmstream_force_loop(data->layers[i], loop_flag, loop_start_sample, loop_end_sample);
|
2019-02-15 22:28:20 +01:00
|
|
|
/* layer's force_loop also calls setup_vgmstream, no need to do it here */
|
2018-08-19 00:43:06 +02:00
|
|
|
}
|
2017-12-06 16:55:41 +01:00
|
|
|
}
|
2019-02-15 22:28:20 +01:00
|
|
|
|
|
|
|
/* segmented layout loops with standard loop start/end values and works ok */
|
|
|
|
|
|
|
|
/* notify of new initial state */
|
|
|
|
setup_vgmstream(vgmstream);
|
2017-12-06 16:55:41 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 19:34:31 +02:00
|
|
|
void vgmstream_set_loop_target(VGMSTREAM* vgmstream, int loop_target) {
|
|
|
|
if (!vgmstream) return;
|
|
|
|
|
|
|
|
vgmstream->loop_target = loop_target; /* loop count must be rounded (int) as otherwise target is meaningless */
|
|
|
|
|
|
|
|
/* propagate changes to layouts that need them */
|
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
|
|
|
int i;
|
|
|
|
layered_layout_data *data = vgmstream->layout_data;
|
|
|
|
for (i = 0; i < data->layer_count; i++) {
|
|
|
|
vgmstream_set_loop_target(data->layers[i], loop_target);
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 00:38:35 +01:00
|
|
|
|
|
|
|
/* notify of new initial state */
|
|
|
|
setup_vgmstream(vgmstream);
|
2018-09-07 19:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-06 16:55:41 +01:00
|
|
|
/* Decode data into sample buffer */
|
2019-07-28 15:11:17 +02:00
|
|
|
void render_vgmstream(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
|
2008-01-31 07:04:26 +01:00
|
|
|
switch (vgmstream->layout_type) {
|
|
|
|
case layout_interleave:
|
|
|
|
render_vgmstream_interleave(buffer,sample_count,vgmstream);
|
|
|
|
break;
|
2008-02-05 01:03:39 +01:00
|
|
|
case layout_none:
|
2018-08-24 19:37:02 +02:00
|
|
|
render_vgmstream_flat(buffer,sample_count,vgmstream);
|
2008-02-05 01:03:39 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_mxch:
|
|
|
|
case layout_blocked_ast:
|
|
|
|
case layout_blocked_halpst:
|
|
|
|
case layout_blocked_xa:
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ea_schl:
|
2017-11-18 02:20:52 +01:00
|
|
|
case layout_blocked_ea_1snh:
|
2018-03-08 23:26:10 +01:00
|
|
|
case layout_blocked_caf:
|
2018-03-23 18:34:37 +01:00
|
|
|
case layout_blocked_wsi:
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_str_snds:
|
|
|
|
case layout_blocked_ws_aud:
|
|
|
|
case layout_blocked_matx:
|
2017-11-23 22:48:11 +01:00
|
|
|
case layout_blocked_dec:
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_vs:
|
2018-12-22 19:47:17 +01:00
|
|
|
case layout_blocked_mul:
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_gsb:
|
|
|
|
case layout_blocked_xvas:
|
|
|
|
case layout_blocked_thp:
|
|
|
|
case layout_blocked_filp:
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ivaud:
|
2018-02-17 21:15:21 +01:00
|
|
|
case layout_blocked_ea_swvr:
|
2018-02-25 16:52:57 +01:00
|
|
|
case layout_blocked_adm:
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_bdsp:
|
|
|
|
case layout_blocked_tra:
|
|
|
|
case layout_blocked_ps2_iab:
|
2018-12-22 20:09:01 +01:00
|
|
|
case layout_blocked_vs_str:
|
2018-02-25 16:52:57 +01:00
|
|
|
case layout_blocked_rws:
|
|
|
|
case layout_blocked_hwas:
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ea_sns:
|
2017-08-28 16:07:09 +02:00
|
|
|
case layout_blocked_awc:
|
2017-08-28 20:05:03 +02:00
|
|
|
case layout_blocked_vgs:
|
2017-12-09 19:01:36 +01:00
|
|
|
case layout_blocked_vawx:
|
2018-01-13 11:36:35 +01:00
|
|
|
case layout_blocked_xvag_subsong:
|
2018-03-29 15:39:33 +02:00
|
|
|
case layout_blocked_ea_wve_au00:
|
|
|
|
case layout_blocked_ea_wve_ad10:
|
2018-03-29 17:01:46 +02:00
|
|
|
case layout_blocked_sthd:
|
2018-06-03 13:08:41 +02:00
|
|
|
case layout_blocked_h4m:
|
2018-07-22 23:13:03 +02:00
|
|
|
case layout_blocked_xa_aiff:
|
2018-12-22 20:09:01 +01:00
|
|
|
case layout_blocked_vs_square:
|
2008-03-04 08:15:25 +01:00
|
|
|
render_vgmstream_blocked(buffer,sample_count,vgmstream);
|
2010-11-24 05:27:59 +01:00
|
|
|
break;
|
2018-03-10 20:25:57 +01:00
|
|
|
case layout_segmented:
|
|
|
|
render_vgmstream_segmented(buffer,sample_count,vgmstream);
|
2008-08-02 12:24:28 +02:00
|
|
|
break;
|
2018-03-30 21:28:32 +02:00
|
|
|
case layout_layered:
|
|
|
|
render_vgmstream_layered(buffer,sample_count,vgmstream);
|
2012-08-24 19:36:40 +02:00
|
|
|
break;
|
2017-10-28 01:34:32 +02:00
|
|
|
default:
|
|
|
|
break;
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
2018-04-15 00:48:37 +02:00
|
|
|
|
2019-02-25 00:38:35 +01:00
|
|
|
mix_vgmstream(buffer, sample_count, vgmstream);
|
2008-01-31 07:04:26 +01:00
|
|
|
}
|
2008-02-05 03:17:35 +01:00
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Get the number of samples of a single frame (smallest self-contained sample group, 1/N channels) */
|
2008-02-05 03:17:35 +01:00
|
|
|
int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_CRI_ADX:
|
2017-05-13 23:04:30 +02:00
|
|
|
case coding_CRI_ADX_fixed:
|
2017-05-14 00:37:24 +02:00
|
|
|
case coding_CRI_ADX_exp:
|
2011-08-20 14:00:01 +02:00
|
|
|
case coding_CRI_ADX_enc_8:
|
|
|
|
case coding_CRI_ADX_enc_9:
|
2018-01-04 23:38:22 +01:00
|
|
|
return (vgmstream->interleave_block_size - 2) * 2;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_NGC_DSP:
|
2017-12-06 21:04:04 +01:00
|
|
|
case coding_NGC_DSP_subint:
|
2008-02-05 03:17:35 +01:00
|
|
|
return 14;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_NGC_AFC:
|
|
|
|
return 16;
|
|
|
|
case coding_NGC_DTK:
|
|
|
|
return 28;
|
|
|
|
case coding_G721:
|
|
|
|
return 1;
|
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM16LE:
|
|
|
|
case coding_PCM16BE:
|
2017-08-27 22:17:13 +02:00
|
|
|
case coding_PCM16_int:
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM8:
|
2009-04-19 11:49:08 +02:00
|
|
|
case coding_PCM8_int:
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_U:
|
2008-11-23 13:21:36 +01:00
|
|
|
case coding_PCM8_U_int:
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_SB:
|
2017-06-09 22:26:09 +02:00
|
|
|
case coding_ULAW:
|
2017-12-24 01:39:24 +01:00
|
|
|
case coding_ULAW_int:
|
2017-10-08 17:51:54 +02:00
|
|
|
case coding_ALAW:
|
2017-08-18 18:54:21 +02:00
|
|
|
case coding_PCMFLOAT:
|
|
|
|
return 1;
|
2008-06-15 09:59:43 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2018-03-08 23:32:58 +01:00
|
|
|
case coding_OGG_VORBIS:
|
2017-07-28 23:26:58 +02:00
|
|
|
case coding_VORBIS_custom:
|
2008-07-05 13:49:29 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_MPEG
|
2017-07-29 13:05:23 +02:00
|
|
|
case coding_MPEG_custom:
|
2017-08-05 17:54:50 +02:00
|
|
|
case coding_MPEG_ealayer3:
|
2017-07-29 13:05:23 +02:00
|
|
|
case coding_MPEG_layer1:
|
|
|
|
case coding_MPEG_layer2:
|
|
|
|
case coding_MPEG_layer3:
|
2008-06-15 09:59:43 +02:00
|
|
|
#endif
|
2008-07-01 05:23:44 +02:00
|
|
|
case coding_SDX2:
|
2008-07-14 22:42:49 +02:00
|
|
|
case coding_SDX2_int:
|
2010-07-27 14:24:03 +02:00
|
|
|
case coding_CBD2:
|
2008-07-20 07:41:41 +02:00
|
|
|
case coding_ACM:
|
2018-09-06 17:45:34 +02:00
|
|
|
case coding_DERF:
|
2018-03-16 18:35:21 +01:00
|
|
|
case coding_NWA:
|
2009-09-04 06:19:39 +02:00
|
|
|
case coding_SASSC:
|
2018-11-10 00:09:03 +01:00
|
|
|
case coding_CIRCUS_ADPCM:
|
2008-02-05 03:17:35 +01:00
|
|
|
return 1;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2017-11-19 03:32:21 +01:00
|
|
|
case coding_IMA:
|
2008-07-02 03:41:20 +02:00
|
|
|
case coding_DVI_IMA:
|
2011-02-06 10:49:57 +01:00
|
|
|
case coding_SNDS_IMA:
|
2017-01-25 20:25:39 +01:00
|
|
|
case coding_OTNS_IMA:
|
2017-11-05 17:06:40 +01:00
|
|
|
case coding_UBI_IMA:
|
2019-01-12 13:02:08 +01:00
|
|
|
case coding_OKI16:
|
2008-02-14 23:10:08 +01:00
|
|
|
return 1;
|
2019-02-02 21:19:06 +01:00
|
|
|
case coding_PCM4:
|
|
|
|
case coding_PCM4_U:
|
2017-04-29 02:53:36 +02:00
|
|
|
case coding_IMA_int:
|
|
|
|
case coding_DVI_IMA_int:
|
2017-11-18 22:25:44 +01:00
|
|
|
case coding_3DS_IMA:
|
2018-08-02 18:22:01 +02:00
|
|
|
case coding_WV6_IMA:
|
2018-09-06 20:25:04 +02:00
|
|
|
case coding_ALP_IMA:
|
2018-10-04 19:43:37 +02:00
|
|
|
case coding_FFTA2_IMA:
|
2019-02-23 00:12:58 +01:00
|
|
|
case coding_BLITZ_IMA:
|
2018-12-27 16:14:59 +01:00
|
|
|
case coding_PCFX:
|
2009-04-19 11:49:08 +02:00
|
|
|
return 2;
|
2018-02-17 12:30:14 +01:00
|
|
|
case coding_XBOX_IMA:
|
2018-03-23 21:21:44 +01:00
|
|
|
case coding_XBOX_IMA_mch:
|
2018-02-17 12:30:14 +01:00
|
|
|
case coding_XBOX_IMA_int:
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_FSB_IMA:
|
2018-02-23 23:01:44 +01:00
|
|
|
case coding_WWISE_IMA:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 64;
|
|
|
|
case coding_APPLE_IMA4:
|
|
|
|
return 64;
|
|
|
|
case coding_MS_IMA:
|
2018-02-17 18:19:28 +01:00
|
|
|
case coding_REF_IMA:
|
|
|
|
return ((vgmstream->interleave_block_size - 0x04*vgmstream->channels) * 2 / vgmstream->channels) + 1;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_RAD_IMA:
|
2018-02-17 18:19:28 +01:00
|
|
|
return (vgmstream->interleave_block_size - 0x04*vgmstream->channels) * 2 / vgmstream->channels;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_NDS_IMA:
|
|
|
|
case coding_DAT4_IMA:
|
2018-02-17 18:19:28 +01:00
|
|
|
return (vgmstream->interleave_block_size - 0x04) * 2;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_AWC_IMA:
|
2018-02-17 18:19:28 +01:00
|
|
|
return (0x800 - 0x04) * 2;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_RAD_IMA_mono:
|
|
|
|
return 32;
|
2018-08-19 00:38:08 +02:00
|
|
|
case coding_H4M_IMA:
|
|
|
|
return 0; /* variable (block-controlled) */
|
2018-02-17 04:00:04 +01:00
|
|
|
|
|
|
|
case coding_XA:
|
2018-07-22 23:08:09 +02:00
|
|
|
return 28*8 / vgmstream->channels; /* 8 subframes per frame, mono/stereo */
|
2008-05-05 00:10:30 +02:00
|
|
|
case coding_PSX:
|
2008-07-25 21:02:29 +02:00
|
|
|
case coding_PSX_badflags:
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_HEVAG:
|
2009-04-19 11:49:08 +02:00
|
|
|
return 28;
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_PSX_cfg:
|
2016-12-29 23:34:21 +01:00
|
|
|
return (vgmstream->interleave_block_size - 1) * 2; /* decodes 1 byte into 2 bytes */
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_EA_XA:
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA_int:
|
|
|
|
case coding_EA_XA_V2:
|
2017-12-03 01:37:56 +01:00
|
|
|
case coding_MAXIS_XA:
|
2018-01-04 23:38:22 +01:00
|
|
|
return 28;
|
2019-01-12 02:26:38 +01:00
|
|
|
case coding_EA_XAS_V0:
|
|
|
|
return 32;
|
|
|
|
case coding_EA_XAS_V1:
|
2017-08-20 02:18:48 +02:00
|
|
|
return 128;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2008-08-11 09:19:44 +02:00
|
|
|
case coding_MSADPCM:
|
2018-08-02 17:15:09 +02:00
|
|
|
return (vgmstream->interleave_block_size - 0x07*vgmstream->channels)*2 / vgmstream->channels + 2;
|
2019-01-19 23:08:26 +01:00
|
|
|
case coding_MSADPCM_int:
|
2018-08-02 17:15:09 +02:00
|
|
|
case coding_MSADPCM_ck:
|
|
|
|
return (vgmstream->interleave_block_size - 0x07)*2 + 2;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_WS: /* only works if output sample size is 8 bit, which always is for WS ADPCM */
|
|
|
|
return vgmstream->ws_output_size;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_YAMAHA:
|
2018-03-28 00:30:59 +02:00
|
|
|
return 1;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_YAMAHA_int:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 2;
|
2019-03-02 21:12:00 +01:00
|
|
|
case coding_ASKA:
|
2018-03-24 12:08:16 +01:00
|
|
|
return (0x40-0x04*vgmstream->channels) * 2 / vgmstream->channels;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_NXAP:
|
2018-03-24 12:08:16 +01:00
|
|
|
return (0x40-0x04) * 2;
|
2008-12-28 07:29:43 +01:00
|
|
|
case coding_NDS_PROCYON:
|
|
|
|
return 30;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_L5_555:
|
|
|
|
return 32;
|
|
|
|
case coding_LSF:
|
|
|
|
return 54;
|
|
|
|
|
2010-03-21 05:23:18 +01:00
|
|
|
#ifdef VGM_USE_G7221
|
|
|
|
case coding_G7221C:
|
2018-09-22 16:32:21 +02:00
|
|
|
return 32000/50; /* Siren7: 16000/50 */
|
2015-01-25 06:08:25 +01:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_G719
|
|
|
|
case coding_G719:
|
|
|
|
return 48000/50;
|
2016-07-17 08:02:27 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case coding_FFmpeg:
|
2018-02-17 04:00:04 +01:00
|
|
|
if (vgmstream->codec_data) {
|
|
|
|
ffmpeg_codec_data *data = (ffmpeg_codec_data*)vgmstream->codec_data;
|
|
|
|
return data->sampleBufferBlock; /* must know the full block size for edge loops */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-03-21 05:23:18 +01:00
|
|
|
#endif
|
2011-05-07 13:05:05 +02:00
|
|
|
case coding_MTAF:
|
2017-12-03 13:44:55 +01:00
|
|
|
return 128*2;
|
2017-05-18 19:16:44 +02:00
|
|
|
case coding_MTA2:
|
2017-12-03 13:44:55 +01:00
|
|
|
return 128*2;
|
2017-04-28 17:26:25 +02:00
|
|
|
case coding_MC3:
|
|
|
|
return 10;
|
2018-02-25 10:05:28 +01:00
|
|
|
case coding_FADPCM:
|
|
|
|
return 256; /* (0x8c - 0xc) * 2 */
|
2018-07-18 00:52:24 +02:00
|
|
|
case coding_ASF:
|
|
|
|
return 32; /* (0x11 - 0x1) * 2 */
|
2019-02-10 01:36:05 +01:00
|
|
|
case coding_DSA:
|
|
|
|
return 14; /* (0x08 - 0x1) * 2 */
|
2018-07-27 17:11:11 +02:00
|
|
|
case coding_XMD:
|
|
|
|
return (vgmstream->interleave_block_size - 0x06)*2 + 2;
|
2017-12-03 13:44:55 +01:00
|
|
|
case coding_EA_MT:
|
2018-09-08 19:22:56 +02:00
|
|
|
return 0; /* 432, but variable in looped files */
|
2016-06-28 09:20:37 +02:00
|
|
|
case coding_CRI_HCA:
|
2018-08-29 23:42:47 +02:00
|
|
|
return 0; /* 1024 - delay/padding (which can be bigger than 1024) */
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2018-01-04 23:38:22 +01:00
|
|
|
case coding_MP4_AAC:
|
|
|
|
return ((mp4_aac_codec_data*)vgmstream->codec_data)->samples_per_frame;
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2018-01-04 23:38:22 +01:00
|
|
|
case coding_AT3plus:
|
|
|
|
return 2048 - ((maiatrac3plus_codec_data*)vgmstream->codec_data)->samples_discard;
|
2017-12-29 00:29:33 +01:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case coding_ATRAC9:
|
|
|
|
return 0; /* varies with config data, usually 256 or 1024 */
|
2018-08-12 00:58:20 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_CELT
|
|
|
|
case coding_CELT_FSB:
|
|
|
|
return 0; /* 512? */
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2008-02-05 03:17:35 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Get the number of bytes of a single frame (smallest self-contained byte group, 1/N channels) */
|
2008-02-05 03:17:35 +01:00
|
|
|
int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_CRI_ADX:
|
2017-05-13 23:04:30 +02:00
|
|
|
case coding_CRI_ADX_fixed:
|
2017-05-14 00:37:24 +02:00
|
|
|
case coding_CRI_ADX_exp:
|
2011-08-20 14:00:01 +02:00
|
|
|
case coding_CRI_ADX_enc_8:
|
|
|
|
case coding_CRI_ADX_enc_9:
|
2017-05-13 23:04:30 +02:00
|
|
|
return vgmstream->interleave_block_size;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_NGC_DSP:
|
2017-12-06 21:04:04 +01:00
|
|
|
return 0x08;
|
|
|
|
case coding_NGC_DSP_subint:
|
|
|
|
return 0x08 * vgmstream->channels;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_NGC_AFC:
|
|
|
|
return 0x09;
|
|
|
|
case coding_NGC_DTK:
|
|
|
|
return 0x20;
|
|
|
|
case coding_G721:
|
|
|
|
return 0;
|
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM16LE:
|
|
|
|
case coding_PCM16BE:
|
2017-08-27 22:17:13 +02:00
|
|
|
case coding_PCM16_int:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x02;
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM8:
|
2009-04-19 11:49:08 +02:00
|
|
|
case coding_PCM8_int:
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_U:
|
2008-11-23 13:21:36 +01:00
|
|
|
case coding_PCM8_U_int:
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_SB:
|
2017-06-09 22:26:09 +02:00
|
|
|
case coding_ULAW:
|
2017-12-24 01:39:24 +01:00
|
|
|
case coding_ULAW_int:
|
2017-10-08 17:51:54 +02:00
|
|
|
case coding_ALAW:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x01;
|
2017-08-18 18:54:21 +02:00
|
|
|
case coding_PCMFLOAT:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x04;
|
|
|
|
|
2008-07-01 05:23:44 +02:00
|
|
|
case coding_SDX2:
|
2008-07-14 22:42:49 +02:00
|
|
|
case coding_SDX2_int:
|
2010-07-27 14:24:03 +02:00
|
|
|
case coding_CBD2:
|
2018-09-06 17:45:34 +02:00
|
|
|
case coding_DERF:
|
2018-03-16 18:35:21 +01:00
|
|
|
case coding_NWA:
|
2009-09-04 06:19:39 +02:00
|
|
|
case coding_SASSC:
|
2018-11-10 00:09:03 +01:00
|
|
|
case coding_CIRCUS_ADPCM:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x01;
|
|
|
|
|
2019-02-02 21:19:06 +01:00
|
|
|
case coding_PCM4:
|
|
|
|
case coding_PCM4_U:
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_IMA:
|
|
|
|
case coding_IMA_int:
|
|
|
|
case coding_DVI_IMA:
|
|
|
|
case coding_DVI_IMA_int:
|
|
|
|
case coding_3DS_IMA:
|
2018-08-02 18:22:01 +02:00
|
|
|
case coding_WV6_IMA:
|
2018-09-06 20:25:04 +02:00
|
|
|
case coding_ALP_IMA:
|
2018-10-04 19:43:37 +02:00
|
|
|
case coding_FFTA2_IMA:
|
2019-02-23 00:12:58 +01:00
|
|
|
case coding_BLITZ_IMA:
|
2018-12-27 16:14:59 +01:00
|
|
|
case coding_PCFX:
|
2019-01-12 13:02:08 +01:00
|
|
|
case coding_OKI16:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x01;
|
2009-03-09 13:48:53 +01:00
|
|
|
case coding_MS_IMA:
|
2009-09-12 06:51:39 +02:00
|
|
|
case coding_RAD_IMA:
|
2008-02-05 10:21:20 +01:00
|
|
|
case coding_NDS_IMA:
|
2009-12-16 07:12:53 +01:00
|
|
|
case coding_DAT4_IMA:
|
2017-06-24 23:30:10 +02:00
|
|
|
case coding_REF_IMA:
|
2008-02-05 10:21:20 +01:00
|
|
|
return vgmstream->interleave_block_size;
|
2017-08-28 16:07:09 +02:00
|
|
|
case coding_AWC_IMA:
|
|
|
|
return 0x800;
|
2010-04-10 14:06:25 +02:00
|
|
|
case coding_RAD_IMA_mono:
|
|
|
|
return 0x14;
|
2011-02-06 10:49:57 +01:00
|
|
|
case coding_SNDS_IMA:
|
2017-01-25 20:25:39 +01:00
|
|
|
case coding_OTNS_IMA:
|
2018-08-02 18:22:01 +02:00
|
|
|
return 0; //todo: 0x01?
|
2017-11-05 17:06:40 +01:00
|
|
|
case coding_UBI_IMA: /* variable (PCM then IMA) */
|
2008-02-14 23:10:08 +01:00
|
|
|
return 0;
|
2018-02-24 22:30:17 +01:00
|
|
|
case coding_XBOX_IMA:
|
|
|
|
//todo should be 0x48 when stereo, but blocked/interleave layout don't understand stereo codecs
|
|
|
|
return 0x24; //vgmstream->channels==1 ? 0x24 : 0x48;
|
2018-02-17 12:30:14 +01:00
|
|
|
case coding_XBOX_IMA_int:
|
2018-02-23 23:01:44 +01:00
|
|
|
case coding_WWISE_IMA:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x24;
|
2018-03-23 21:21:44 +01:00
|
|
|
case coding_XBOX_IMA_mch:
|
|
|
|
case coding_FSB_IMA:
|
|
|
|
return 0x24 * vgmstream->channels;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_APPLE_IMA4:
|
|
|
|
return 0x22;
|
2018-08-19 00:38:08 +02:00
|
|
|
case coding_H4M_IMA:
|
|
|
|
return 0x00; /* variable (block-controlled) */
|
2018-02-17 04:00:04 +01:00
|
|
|
|
|
|
|
case coding_XA:
|
2018-07-22 23:08:09 +02:00
|
|
|
return 0x80;
|
2008-05-05 00:10:30 +02:00
|
|
|
case coding_PSX:
|
2008-07-25 21:02:29 +02:00
|
|
|
case coding_PSX_badflags:
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_HEVAG:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x10;
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_PSX_cfg:
|
2016-12-29 23:34:21 +01:00
|
|
|
return vgmstream->interleave_block_size;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA:
|
2017-07-08 00:27:36 +02:00
|
|
|
return 0x1E;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA_int:
|
2017-07-08 00:27:36 +02:00
|
|
|
return 0x0F;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_MAXIS_XA:
|
2017-07-08 00:27:36 +02:00
|
|
|
return 0x0F*vgmstream->channels;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA_V2:
|
2017-12-03 13:44:55 +01:00
|
|
|
return 0; /* variable (ADPCM frames of 0x0f or PCM frames of 0x3d) */
|
2019-01-12 02:26:38 +01:00
|
|
|
case coding_EA_XAS_V0:
|
|
|
|
return 0xF+0x02+0x02;
|
|
|
|
case coding_EA_XAS_V1:
|
2017-08-20 02:18:48 +02:00
|
|
|
return 0x4c*vgmstream->channels;
|
2018-02-17 04:00:04 +01:00
|
|
|
|
|
|
|
case coding_MSADPCM:
|
2019-01-19 23:08:26 +01:00
|
|
|
case coding_MSADPCM_int:
|
2018-08-02 17:15:09 +02:00
|
|
|
case coding_MSADPCM_ck:
|
2018-02-17 04:00:04 +01:00
|
|
|
return vgmstream->interleave_block_size;
|
2008-07-03 23:21:01 +02:00
|
|
|
case coding_WS:
|
|
|
|
return vgmstream->current_block_size;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_YAMAHA:
|
|
|
|
case coding_YAMAHA_int:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x01;
|
2019-03-02 21:12:00 +01:00
|
|
|
case coding_ASKA:
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_NXAP:
|
2018-03-24 12:08:16 +01:00
|
|
|
return 0x40;
|
2018-02-17 04:00:04 +01:00
|
|
|
case coding_NDS_PROCYON:
|
|
|
|
return 0x10;
|
|
|
|
case coding_L5_555:
|
|
|
|
return 0x12;
|
2011-01-13 09:11:58 +01:00
|
|
|
case coding_LSF:
|
2018-02-17 04:00:04 +01:00
|
|
|
return 0x1C;
|
|
|
|
|
2010-03-21 05:23:18 +01:00
|
|
|
#ifdef VGM_USE_G7221
|
|
|
|
case coding_G7221C:
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2015-08-13 01:09:10 +02:00
|
|
|
#ifdef VGM_USE_G719
|
2015-01-25 06:08:25 +01:00
|
|
|
case coding_G719:
|
|
|
|
#endif
|
2013-06-26 11:54:15 +02:00
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2018-01-04 23:38:22 +01:00
|
|
|
case coding_AT3plus:
|
2016-07-17 08:02:27 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case coding_FFmpeg:
|
2010-03-21 05:23:18 +01:00
|
|
|
#endif
|
2011-05-07 13:05:05 +02:00
|
|
|
case coding_MTAF:
|
2008-08-11 09:19:44 +02:00
|
|
|
return vgmstream->interleave_block_size;
|
2017-05-18 19:16:44 +02:00
|
|
|
case coding_MTA2:
|
|
|
|
return 0x90;
|
2017-04-28 17:26:25 +02:00
|
|
|
case coding_MC3:
|
2017-12-03 13:44:55 +01:00
|
|
|
return 0x04;
|
2018-02-25 10:05:28 +01:00
|
|
|
case coding_FADPCM:
|
|
|
|
return 0x8c;
|
2018-07-18 00:52:24 +02:00
|
|
|
case coding_ASF:
|
|
|
|
return 0x11;
|
2019-02-10 01:36:05 +01:00
|
|
|
case coding_DSA:
|
|
|
|
return 0x08;
|
2018-07-27 17:11:11 +02:00
|
|
|
case coding_XMD:
|
|
|
|
return vgmstream->interleave_block_size;
|
2017-12-03 13:44:55 +01:00
|
|
|
case coding_EA_MT:
|
|
|
|
return 0; /* variable (frames of bit counts or PCM frames) */
|
2017-12-29 00:29:33 +01:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case coding_ATRAC9:
|
|
|
|
return 0; /* varies with config data, usually 0x100-200 */
|
2018-08-12 00:58:20 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_CELT
|
|
|
|
case coding_CELT_FSB:
|
|
|
|
return 0; /* varies, usually 0x80-100 */
|
2017-12-29 00:29:33 +01:00
|
|
|
#endif
|
2018-02-17 04:00:04 +01:00
|
|
|
default: /* Vorbis, MPEG, ACM, etc */
|
2008-02-05 03:17:35 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* In NDS IMA the frame size is the block size, so the last one is short */
|
|
|
|
int get_vgmstream_samples_per_shortframe(VGMSTREAM * vgmstream) {
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_NDS_IMA:
|
2018-03-24 19:27:24 +01:00
|
|
|
return (vgmstream->interleave_last_block_size-4)*2;
|
2017-12-06 15:32:52 +01:00
|
|
|
default:
|
|
|
|
return get_vgmstream_samples_per_frame(vgmstream);
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 10:21:20 +01:00
|
|
|
int get_vgmstream_shortframe_size(VGMSTREAM * vgmstream) {
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_NDS_IMA:
|
2018-03-24 19:27:24 +01:00
|
|
|
return vgmstream->interleave_last_block_size;
|
2008-02-05 10:21:20 +01:00
|
|
|
default:
|
|
|
|
return get_vgmstream_frame_size(vgmstream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Decode samples into the buffer. Assume that we have written samples_written into the
|
|
|
|
* buffer already, and we have samples_to_do consecutive samples ahead of us. */
|
2019-02-23 02:54:23 +01:00
|
|
|
void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample_t * buffer) {
|
2018-08-26 17:07:33 +02:00
|
|
|
int ch;
|
2008-02-05 03:17:35 +01:00
|
|
|
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_CRI_ADX:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_adx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-05-13 22:17:27 +02:00
|
|
|
vgmstream->interleave_block_size);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
|
2017-05-14 00:37:24 +02:00
|
|
|
break;
|
|
|
|
case coding_CRI_ADX_exp:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_adx_exp(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-05-14 00:37:24 +02:00
|
|
|
vgmstream->interleave_block_size);
|
|
|
|
}
|
|
|
|
|
2017-05-13 23:04:30 +02:00
|
|
|
break;
|
|
|
|
case coding_CRI_ADX_fixed:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_adx_fixed(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-05-13 23:04:30 +02:00
|
|
|
vgmstream->interleave_block_size);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
|
2008-12-24 08:19:15 +01:00
|
|
|
break;
|
2011-08-20 14:00:01 +02:00
|
|
|
case coding_CRI_ADX_enc_8:
|
|
|
|
case coding_CRI_ADX_enc_9:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_adx_enc(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-05-13 22:17:27 +02:00
|
|
|
vgmstream->interleave_block_size);
|
2008-12-24 08:19:15 +01:00
|
|
|
}
|
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
break;
|
|
|
|
case coding_NGC_DSP:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ngc_dsp(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-12-06 21:04:04 +01:00
|
|
|
case coding_NGC_DSP_subint:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ngc_dsp_subint(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
|
|
|
ch, vgmstream->interleave_block_size);
|
2017-12-06 21:04:04 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM16LE:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm16le(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_PCM16BE:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm16be(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-08-27 22:17:13 +02:00
|
|
|
case coding_PCM16_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm16_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-08-27 22:17:13 +02:00
|
|
|
vgmstream->codec_endian);
|
|
|
|
}
|
|
|
|
break;
|
2008-02-05 03:17:35 +01:00
|
|
|
case coding_PCM8:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm8(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm8_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2009-04-28 18:52:49 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_U:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm8_unsigned(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-07-14 21:21:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_U_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm8_unsigned_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-07-30 22:58:50 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
case coding_PCM8_SB:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm8_sb(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-11-23 13:21:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-01-09 20:30:15 +01:00
|
|
|
case coding_PCM4:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm4(vgmstream,&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,ch);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_PCM4_U:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcm4_unsigned(vgmstream, &vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,ch);
|
|
|
|
}
|
|
|
|
break;
|
2018-08-26 16:36:08 +02:00
|
|
|
|
2017-06-09 22:26:09 +02:00
|
|
|
case coding_ULAW:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ulaw(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2017-06-09 22:26:09 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-24 01:39:24 +01:00
|
|
|
case coding_ULAW_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ulaw_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2017-12-24 01:39:24 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-10-08 17:51:54 +02:00
|
|
|
case coding_ALAW:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_alaw(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2017-10-08 17:51:54 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-08-18 18:54:21 +02:00
|
|
|
case coding_PCMFLOAT:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcmfloat(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
2017-08-27 22:17:13 +02:00
|
|
|
vgmstream->codec_endian);
|
2017-08-18 18:54:21 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-02-05 10:21:20 +01:00
|
|
|
case coding_NDS_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_nds_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-05 10:21:20 +01:00
|
|
|
}
|
2008-05-24 00:52:02 +02:00
|
|
|
break;
|
2009-12-16 07:12:53 +01:00
|
|
|
case coding_DAT4_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_dat4_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2009-12-16 07:12:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-02-17 12:30:14 +01:00
|
|
|
case coding_XBOX_IMA:
|
2018-09-04 17:10:41 +02:00
|
|
|
case coding_XBOX_IMA_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2018-09-04 17:10:41 +02:00
|
|
|
int is_stereo = (vgmstream->channels > 1 && vgmstream->coding_type == coding_XBOX_IMA);
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_xbox_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-09-04 17:10:41 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch,
|
|
|
|
is_stereo);
|
2018-03-23 21:21:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_XBOX_IMA_mch:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_xbox_ima_mch(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2008-05-24 00:52:02 +02:00
|
|
|
}
|
2009-03-09 13:48:53 +01:00
|
|
|
break;
|
2009-04-19 11:49:08 +02:00
|
|
|
case coding_MS_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ms_ima(vgmstream,&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2009-03-09 13:48:53 +01:00
|
|
|
}
|
2008-02-05 10:21:20 +01:00
|
|
|
break;
|
2009-09-12 06:51:39 +02:00
|
|
|
case coding_RAD_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_rad_ima(vgmstream,&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2009-09-12 06:51:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-04-10 14:06:25 +02:00
|
|
|
case coding_RAD_IMA_mono:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_rad_ima_mono(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2010-04-10 14:06:25 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-02-13 15:31:21 +01:00
|
|
|
case coding_NGC_DTK:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ngc_dtk(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2008-02-13 15:31:21 +01:00
|
|
|
}
|
|
|
|
break;
|
2008-02-14 23:10:08 +01:00
|
|
|
case coding_G721:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_g721(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-02-14 23:10:08 +01:00
|
|
|
}
|
|
|
|
break;
|
2008-03-03 22:38:11 +01:00
|
|
|
case coding_NGC_AFC:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ngc_afc(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-03-03 22:38:11 +01:00
|
|
|
}
|
|
|
|
break;
|
2008-05-04 22:36:40 +02:00
|
|
|
case coding_PSX:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 0);
|
2008-05-04 22:36:40 +02:00
|
|
|
}
|
2008-06-25 22:39:15 +02:00
|
|
|
break;
|
2008-07-25 21:02:29 +02:00
|
|
|
case coding_PSX_badflags:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 1);
|
2008-07-25 21:02:29 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-07-21 20:15:07 +02:00
|
|
|
case coding_PSX_cfg:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_psx_configurable(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->interleave_block_size);
|
2016-12-21 20:44:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-07-21 20:15:07 +02:00
|
|
|
case coding_HEVAG:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_hevag(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2016-12-21 23:00:34 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-04-19 11:49:08 +02:00
|
|
|
case coding_XA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_xa(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2008-05-10 21:59:29 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-08 01:09:20 +01:00
|
|
|
case coding_EA_XA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ea_xa(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2008-06-02 19:58:08 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ea_xa_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-07-08 00:27:36 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_EA_XA_V2:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ea_xa_v2(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2008-07-14 21:21:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-21 19:19:58 +02:00
|
|
|
case coding_MAXIS_XA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_maxis_xa(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-08-20 02:18:48 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-01-12 02:26:38 +01:00
|
|
|
case coding_EA_XAS_V0:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ea_xas_v0(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_EA_XAS_V1:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2019-01-12 02:26:38 +01:00
|
|
|
decode_ea_xas_v1(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2009-09-01 23:28:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-15 06:01:03 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2018-03-08 23:32:58 +01:00
|
|
|
case coding_OGG_VORBIS:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_ogg_vorbis(vgmstream->codec_data, buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2008-06-15 06:01:03 +02:00
|
|
|
break;
|
2017-03-25 14:57:44 +01:00
|
|
|
|
2017-07-28 23:26:58 +02:00
|
|
|
case coding_VORBIS_custom:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_vorbis_custom(vgmstream, buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2017-04-22 19:25:54 +02:00
|
|
|
break;
|
2008-06-15 06:01:03 +02:00
|
|
|
#endif
|
2016-06-28 09:20:37 +02:00
|
|
|
case coding_CRI_HCA:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_hca(vgmstream->codec_data, buffer+samples_written*vgmstream->channels,
|
2018-08-29 20:05:31 +02:00
|
|
|
samples_to_do);
|
2016-06-28 09:20:37 +02:00
|
|
|
break;
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case coding_FFmpeg:
|
|
|
|
decode_ffmpeg(vgmstream,
|
2018-08-26 17:07:33 +02:00
|
|
|
buffer+samples_written*vgmstream->channels,samples_to_do,vgmstream->channels);
|
2016-07-17 08:02:27 +02:00
|
|
|
break;
|
|
|
|
#endif
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2018-01-04 23:38:22 +01:00
|
|
|
case coding_MP4_AAC:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_mp4_aac(vgmstream->codec_data, buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2018-01-04 23:38:22 +01:00
|
|
|
break;
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2008-07-01 05:23:44 +02:00
|
|
|
case coding_SDX2:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_sdx2(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-07-01 05:23:44 +02:00
|
|
|
}
|
2008-07-14 22:42:49 +02:00
|
|
|
break;
|
|
|
|
case coding_SDX2_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_sdx2_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-07-14 22:42:49 +02:00
|
|
|
}
|
2008-07-01 05:23:44 +02:00
|
|
|
break;
|
2010-07-27 14:24:03 +02:00
|
|
|
case coding_CBD2:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_cbd2(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2010-07-27 14:24:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_CBD2_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_cbd2_int(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2010-07-27 14:24:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-09-06 17:45:34 +02:00
|
|
|
case coding_DERF:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_derf(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-11-10 00:09:03 +01:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_CIRCUS_ADPCM:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_circus_adpcm(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-09-06 17:45:34 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-11-19 03:32:21 +01:00
|
|
|
case coding_IMA:
|
|
|
|
case coding_IMA_int:
|
2009-04-19 11:49:08 +02:00
|
|
|
case coding_DVI_IMA:
|
2017-04-29 02:53:36 +02:00
|
|
|
case coding_DVI_IMA_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2017-11-19 03:32:21 +01:00
|
|
|
int is_stereo = (vgmstream->channels > 1 && vgmstream->coding_type == coding_IMA)
|
|
|
|
|| (vgmstream->channels > 1 && vgmstream->coding_type == coding_DVI_IMA);
|
2017-11-17 17:18:17 +01:00
|
|
|
int is_high_first = vgmstream->coding_type == coding_DVI_IMA || vgmstream->coding_type == coding_DVI_IMA_int;
|
|
|
|
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_standard_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch,
|
|
|
|
is_stereo, is_high_first);
|
2008-07-14 21:21:45 +02:00
|
|
|
}
|
2008-07-02 03:41:20 +02:00
|
|
|
break;
|
2017-11-18 22:25:44 +01:00
|
|
|
case coding_3DS_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_3ds_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2018-08-02 18:22:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_WV6_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_wv6_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2017-11-18 22:25:44 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-09-06 20:25:04 +02:00
|
|
|
case coding_ALP_IMA:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_alp_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-10-04 19:43:37 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_FFTA2_IMA:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ffta2_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-09-06 20:25:04 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
2019-02-23 00:12:58 +01:00
|
|
|
case coding_BLITZ_IMA:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_blitz_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
2018-09-06 20:25:04 +02:00
|
|
|
|
2009-08-30 04:16:54 +02:00
|
|
|
case coding_APPLE_IMA4:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_apple_ima4(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2009-08-30 04:16:54 +02:00
|
|
|
}
|
|
|
|
break;
|
2011-02-06 10:49:57 +01:00
|
|
|
case coding_SNDS_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_snds_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2011-02-06 10:49:57 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-01-25 20:25:39 +01:00
|
|
|
case coding_OTNS_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_otns_ima(vgmstream, &vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-02-04 19:19:51 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case coding_FSB_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_fsb_ima(vgmstream, &vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-01-25 20:25:39 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-04-11 19:59:29 +02:00
|
|
|
case coding_WWISE_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_wwise_ima(vgmstream,&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-04-11 19:59:29 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-24 23:30:10 +02:00
|
|
|
case coding_REF_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ref_ima(vgmstream,&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-06-24 23:30:10 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-08-28 16:07:09 +02:00
|
|
|
case coding_AWC_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_awc_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2017-08-28 16:07:09 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-11-05 17:06:40 +01:00
|
|
|
case coding_UBI_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ubi_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2017-11-05 17:06:40 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-08-19 00:38:08 +02:00
|
|
|
case coding_H4M_IMA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2018-08-23 18:07:45 +02:00
|
|
|
uint16_t frame_format = (uint16_t)((vgmstream->codec_config >> 8) & 0xFFFF);
|
2018-08-19 00:38:08 +02:00
|
|
|
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_h4m_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch,
|
|
|
|
frame_format);
|
2018-08-19 00:38:08 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-25 20:25:39 +01:00
|
|
|
|
2008-07-03 23:21:01 +02:00
|
|
|
case coding_WS:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ws(vgmstream,ch,buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-07-03 23:21:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-08 01:09:20 +01:00
|
|
|
|
2008-07-05 13:49:29 +02:00
|
|
|
#ifdef VGM_USE_MPEG
|
2017-07-29 13:05:23 +02:00
|
|
|
case coding_MPEG_custom:
|
2017-08-05 17:54:50 +02:00
|
|
|
case coding_MPEG_ealayer3:
|
2017-07-29 13:05:23 +02:00
|
|
|
case coding_MPEG_layer1:
|
|
|
|
case coding_MPEG_layer2:
|
|
|
|
case coding_MPEG_layer3:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_mpeg(vgmstream,buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2008-07-05 13:49:29 +02:00
|
|
|
break;
|
2010-03-21 05:23:18 +01:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_G7221
|
|
|
|
case coding_G7221C:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_g7221(vgmstream, buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,samples_to_do, ch);
|
2010-03-21 05:23:18 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2015-01-25 06:08:25 +01:00
|
|
|
#ifdef VGM_USE_G719
|
|
|
|
case coding_G719:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_g719(vgmstream, buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,samples_to_do, ch);
|
2015-01-25 06:08:25 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2013-06-26 11:54:15 +02:00
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2018-01-04 23:38:22 +01:00
|
|
|
case coding_AT3plus:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_at3plus(vgmstream, buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,samples_to_do, ch);
|
2018-01-04 23:38:22 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-12-29 00:29:33 +01:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case coding_ATRAC9:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_atrac9(vgmstream, buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2017-12-29 00:29:33 +01:00
|
|
|
break;
|
2018-08-12 00:58:20 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_CELT
|
|
|
|
case coding_CELT_FSB:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_celt_fsb(vgmstream, buffer+samples_written*vgmstream->channels,
|
|
|
|
samples_to_do,vgmstream->channels);
|
2018-08-12 00:58:20 +02:00
|
|
|
break;
|
2008-08-02 12:24:28 +02:00
|
|
|
#endif
|
2018-03-16 18:02:17 +01:00
|
|
|
case coding_ACM:
|
2018-08-26 17:07:33 +02:00
|
|
|
decode_acm(vgmstream->codec_data, buffer+samples_written*vgmstream->channels,
|
2018-03-16 13:03:39 +01:00
|
|
|
samples_to_do, vgmstream->channels);
|
2008-07-20 07:41:41 +02:00
|
|
|
break;
|
2018-03-16 18:35:21 +01:00
|
|
|
case coding_NWA:
|
2008-08-03 16:58:03 +02:00
|
|
|
decode_nwa(((nwa_codec_data*)vgmstream->codec_data)->nwa,
|
2018-08-26 17:07:33 +02:00
|
|
|
buffer+samples_written*vgmstream->channels, samples_to_do);
|
2008-08-03 16:58:03 +02:00
|
|
|
break;
|
2008-08-11 09:19:44 +02:00
|
|
|
case coding_MSADPCM:
|
2019-01-19 23:08:26 +01:00
|
|
|
case coding_MSADPCM_int:
|
|
|
|
if (vgmstream->channels == 1 || vgmstream->coding_type == coding_MSADPCM_int) {
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_msadpcm_mono(vgmstream,buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block, samples_to_do, ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vgmstream->channels == 2) {
|
2018-08-02 17:15:09 +02:00
|
|
|
decode_msadpcm_stereo(vgmstream,buffer+samples_written*vgmstream->channels,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->samples_into_block,samples_to_do);
|
2008-08-11 09:19:44 +02:00
|
|
|
}
|
2018-08-02 17:15:09 +02:00
|
|
|
break;
|
|
|
|
case coding_MSADPCM_ck:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_msadpcm_ck(vgmstream,buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block, samples_to_do, ch);
|
2010-04-12 05:35:58 +02:00
|
|
|
}
|
2008-08-11 10:10:59 +02:00
|
|
|
break;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_YAMAHA:
|
|
|
|
case coding_YAMAHA_int:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2019-03-03 02:30:52 +01:00
|
|
|
int is_stereo = (vgmstream->channels > 1 && vgmstream->coding_type == coding_YAMAHA);
|
2018-03-28 00:30:59 +02:00
|
|
|
|
2019-03-03 02:30:52 +01:00
|
|
|
decode_yamaha(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch,
|
|
|
|
is_stereo);
|
2018-03-24 12:08:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-03-02 21:12:00 +01:00
|
|
|
case coding_ASKA:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2019-03-02 21:12:00 +01:00
|
|
|
decode_aska(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
2018-03-24 12:08:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-03-03 02:30:52 +01:00
|
|
|
case coding_NXAP:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2019-03-03 02:30:52 +01:00
|
|
|
decode_nxap(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-08-13 08:11:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-12-28 07:29:43 +01:00
|
|
|
case coding_NDS_PROCYON:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_nds_procyon(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2008-12-28 07:29:43 +01:00
|
|
|
}
|
2009-01-04 16:36:06 +01:00
|
|
|
break;
|
|
|
|
case coding_L5_555:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_l5_555(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2009-01-04 16:36:06 +01:00
|
|
|
}
|
2009-09-04 06:19:39 +02:00
|
|
|
break;
|
|
|
|
case coding_SASSC:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2018-09-02 21:11:15 +02:00
|
|
|
decode_sassc(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
2018-08-26 17:07:33 +02:00
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2009-09-04 06:19:39 +02:00
|
|
|
}
|
|
|
|
|
2011-01-13 09:11:58 +01:00
|
|
|
break;
|
|
|
|
case coding_LSF:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_lsf(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2011-01-13 09:11:58 +01:00
|
|
|
}
|
2008-12-28 07:29:43 +01:00
|
|
|
break;
|
2011-05-07 13:05:05 +02:00
|
|
|
case coding_MTAF:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_mtaf(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels, vgmstream->samples_into_block, samples_to_do, ch);
|
2011-05-07 13:05:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-05-18 19:16:44 +02:00
|
|
|
case coding_MTA2:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_mta2(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels, vgmstream->samples_into_block, samples_to_do, ch);
|
2017-05-18 19:16:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-04-28 17:26:25 +02:00
|
|
|
case coding_MC3:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_mc3(vgmstream, &vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels, vgmstream->samples_into_block, samples_to_do, ch);
|
2017-04-28 17:26:25 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-02-25 10:05:28 +01:00
|
|
|
case coding_FADPCM:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_fadpcm(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2018-02-25 10:05:28 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-07-18 00:52:24 +02:00
|
|
|
case coding_ASF:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_asf(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
2018-07-18 00:52:24 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-02-10 01:36:05 +01:00
|
|
|
case coding_DSA:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_dsa(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
|
|
|
|
}
|
|
|
|
break;
|
2018-07-27 17:11:11 +02:00
|
|
|
case coding_XMD:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_xmd(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do,
|
|
|
|
vgmstream->interleave_block_size);
|
2018-07-27 17:11:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-27 16:14:59 +01:00
|
|
|
case coding_PCFX:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_pcfx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->codec_config);
|
|
|
|
}
|
|
|
|
break;
|
2019-01-12 13:02:08 +01:00
|
|
|
case coding_OKI16:
|
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_oki16(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
|
|
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
|
|
|
}
|
|
|
|
break;
|
2018-12-27 16:14:59 +01:00
|
|
|
|
2017-12-03 13:44:55 +01:00
|
|
|
case coding_EA_MT:
|
2018-08-26 17:07:33 +02:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
decode_ea_mt(vgmstream, buffer+samples_written*vgmstream->channels+ch,
|
2018-09-08 19:22:56 +02:00
|
|
|
vgmstream->channels, samples_to_do, ch);
|
2017-12-03 13:44:55 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-10-28 01:34:32 +02:00
|
|
|
default:
|
|
|
|
break;
|
2008-02-05 03:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 07:21:57 +01:00
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Calculate number of consecutive samples to do (taking into account stopping for loop start and end) */
|
2008-02-05 07:21:57 +01:00
|
|
|
int vgmstream_samples_to_do(int samples_this_block, int samples_per_frame, VGMSTREAM * vgmstream) {
|
|
|
|
int samples_to_do;
|
|
|
|
int samples_left_this_block;
|
|
|
|
|
|
|
|
samples_left_this_block = samples_this_block - vgmstream->samples_into_block;
|
|
|
|
samples_to_do = samples_left_this_block;
|
|
|
|
|
|
|
|
/* fun loopy crap */
|
|
|
|
/* Why did I think this would be any simpler? */
|
|
|
|
if (vgmstream->loop_flag) {
|
|
|
|
/* are we going to hit the loop end during this block? */
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->current_sample + samples_left_this_block > vgmstream->loop_end_sample) {
|
2008-02-05 07:21:57 +01:00
|
|
|
/* only do to just before it */
|
2019-02-15 22:28:20 +01:00
|
|
|
samples_to_do = vgmstream->loop_end_sample - vgmstream->current_sample;
|
2008-02-05 07:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* are we going to hit the loop start during this block? */
|
2019-02-15 22:28:20 +01:00
|
|
|
if (!vgmstream->hit_loop && vgmstream->current_sample + samples_left_this_block > vgmstream->loop_start_sample) {
|
2008-02-05 07:21:57 +01:00
|
|
|
/* only do to just before it */
|
2019-02-15 22:28:20 +01:00
|
|
|
samples_to_do = vgmstream->loop_start_sample - vgmstream->current_sample;
|
2008-02-05 07:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if it's a framed encoding don't do more than one frame */
|
2019-02-15 22:28:20 +01:00
|
|
|
if (samples_per_frame > 1 && (vgmstream->samples_into_block % samples_per_frame) + samples_to_do > samples_per_frame)
|
|
|
|
samples_to_do = samples_per_frame - (vgmstream->samples_into_block % samples_per_frame);
|
2008-02-05 07:21:57 +01:00
|
|
|
|
|
|
|
return samples_to_do;
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Detect loop start and save values, or detect loop end and restore (loop back). Returns 1 if loop was done. */
|
2008-02-05 07:21:57 +01:00
|
|
|
int vgmstream_do_loop(VGMSTREAM * vgmstream) {
|
2017-05-18 19:55:00 +02:00
|
|
|
/*if (!vgmstream->loop_flag) return 0;*/
|
2017-04-29 22:37:15 +02:00
|
|
|
|
2017-05-18 19:55:00 +02:00
|
|
|
/* is this the loop end? = new loop, continue from loop_start_sample */
|
2017-04-29 22:37:15 +02:00
|
|
|
if (vgmstream->current_sample==vgmstream->loop_end_sample) {
|
|
|
|
|
2017-05-18 19:55:00 +02:00
|
|
|
/* disable looping if target count reached and continue normally
|
|
|
|
* (only needed with the "play stream end after looping N times" option enabled) */
|
|
|
|
vgmstream->loop_count++;
|
|
|
|
if (vgmstream->loop_target && vgmstream->loop_target == vgmstream->loop_count) {
|
2019-02-15 22:28:20 +01:00
|
|
|
vgmstream->loop_flag = 0; /* could be improved but works ok, will be restored on resets */
|
2017-05-18 19:55:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
/* against everything I hold sacred, preserve adpcm
|
|
|
|
* 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->coding_type == coding_PSX ||
|
|
|
|
vgmstream->coding_type == coding_PSX_badflags) {
|
|
|
|
int i;
|
2019-02-15 22:28:20 +01:00
|
|
|
for (i = 0; i < vgmstream->channels; i++) {
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->loop_ch[i].adpcm_history1_16 = vgmstream->ch[i].adpcm_history1_16;
|
|
|
|
vgmstream->loop_ch[i].adpcm_history2_16 = vgmstream->ch[i].adpcm_history2_16;
|
|
|
|
vgmstream->loop_ch[i].adpcm_history1_32 = vgmstream->ch[i].adpcm_history1_32;
|
|
|
|
vgmstream->loop_ch[i].adpcm_history2_32 = vgmstream->ch[i].adpcm_history2_32;
|
2008-03-25 08:30:04 +01:00
|
|
|
}
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2016-12-21 20:44:16 +01:00
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
/* prepare certain codecs' internal state for looping */
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CRI_HCA) {
|
2019-05-23 23:47:53 +02:00
|
|
|
loop_hca(vgmstream->codec_data, vgmstream->loop_sample);
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2017-01-08 01:09:20 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_EA_MT) {
|
|
|
|
seek_ea_mt(vgmstream, vgmstream->loop_sample);
|
2017-12-03 13:44:55 +01:00
|
|
|
}
|
|
|
|
|
2008-06-15 06:01:03 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_OGG_VORBIS) {
|
2017-04-29 22:37:15 +02:00
|
|
|
seek_ogg_vorbis(vgmstream, vgmstream->loop_sample);
|
|
|
|
}
|
2017-03-25 14:57:44 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_VORBIS_custom) {
|
|
|
|
seek_vorbis_custom(vgmstream, vgmstream->loop_sample);
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2008-07-06 17:33:38 +02:00
|
|
|
#endif
|
2017-01-08 01:09:20 +01:00
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_FFmpeg) {
|
|
|
|
seek_ffmpeg(vgmstream, vgmstream->loop_sample);
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2017-01-08 01:09:20 +01:00
|
|
|
#endif
|
|
|
|
|
2013-06-14 02:42:24 +02:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MP4_AAC) {
|
2017-04-29 22:37:15 +02:00
|
|
|
seek_mp4_aac(vgmstream, vgmstream->loop_sample);
|
|
|
|
}
|
2013-06-14 02:42:24 +02:00
|
|
|
#endif
|
2017-01-08 01:09:20 +01:00
|
|
|
|
2013-06-26 11:54:15 +02:00
|
|
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_AT3plus) {
|
2017-04-29 22:37:15 +02:00
|
|
|
seek_at3plus(vgmstream, vgmstream->loop_sample);
|
|
|
|
}
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2017-01-08 01:09:20 +01:00
|
|
|
|
2017-12-29 00:29:33 +01:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_ATRAC9) {
|
2017-12-29 00:29:33 +01:00
|
|
|
seek_atrac9(vgmstream, vgmstream->loop_sample);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-12 00:58:20 +02:00
|
|
|
#ifdef VGM_USE_CELT
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CELT_FSB) {
|
2018-08-12 00:58:20 +02:00
|
|
|
seek_celt_fsb(vgmstream, vgmstream->loop_sample);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-06 17:33:38 +02:00
|
|
|
#ifdef VGM_USE_MPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MPEG_custom ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_ealayer3 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer1 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer2 ||
|
|
|
|
vgmstream->coding_type == coding_MPEG_layer3) {
|
2017-07-29 13:05:23 +02:00
|
|
|
seek_mpeg(vgmstream, vgmstream->loop_sample);
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2008-06-15 06:01:03 +02:00
|
|
|
#endif
|
2008-08-03 17:21:05 +02:00
|
|
|
|
2018-03-16 18:35:21 +01:00
|
|
|
if (vgmstream->coding_type == coding_NWA) {
|
2017-04-29 22:37:15 +02:00
|
|
|
nwa_codec_data *data = vgmstream->codec_data;
|
2018-03-10 17:33:48 +01:00
|
|
|
if (data)
|
|
|
|
seek_nwa(data->nwa, vgmstream->loop_sample);
|
2017-04-29 22:37:15 +02:00
|
|
|
}
|
2008-08-03 17:21:05 +02:00
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
/* restore! */
|
2019-02-15 22:28:20 +01:00
|
|
|
memcpy(vgmstream->ch, vgmstream->loop_ch, sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->current_sample = vgmstream->loop_sample;
|
|
|
|
vgmstream->samples_into_block = vgmstream->loop_samples_into_block;
|
|
|
|
vgmstream->current_block_size = vgmstream->loop_block_size;
|
2017-11-26 01:25:27 +01:00
|
|
|
vgmstream->current_block_samples = vgmstream->loop_block_samples;
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->current_block_offset = vgmstream->loop_block_offset;
|
|
|
|
vgmstream->next_block_offset = vgmstream->loop_next_block_offset;
|
2008-08-03 17:21:05 +02:00
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
return 1; /* looped */
|
|
|
|
}
|
2008-02-05 07:21:57 +01:00
|
|
|
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
/* is this the loop start? */
|
2019-02-15 22:28:20 +01:00
|
|
|
if (!vgmstream->hit_loop && vgmstream->current_sample == vgmstream->loop_start_sample) {
|
2017-04-29 22:37:15 +02:00
|
|
|
/* save! */
|
2019-02-15 22:28:20 +01:00
|
|
|
memcpy(vgmstream->loop_ch, vgmstream->ch, sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->loop_sample = vgmstream->current_sample;
|
|
|
|
vgmstream->loop_samples_into_block = vgmstream->samples_into_block;
|
|
|
|
vgmstream->loop_block_size = vgmstream->current_block_size;
|
2017-11-26 01:25:27 +01:00
|
|
|
vgmstream->loop_block_samples = vgmstream->current_block_samples;
|
2017-04-29 22:37:15 +02:00
|
|
|
vgmstream->loop_block_offset = vgmstream->current_block_offset;
|
|
|
|
vgmstream->loop_next_block_offset = vgmstream->next_block_offset;
|
|
|
|
vgmstream->hit_loop = 1;
|
|
|
|
}
|
2008-02-05 07:21:57 +01:00
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
return 0; /* not looped */
|
2008-02-05 07:21:57 +01:00
|
|
|
}
|
2008-02-05 07:44:44 +01:00
|
|
|
|
2017-12-06 15:32:52 +01:00
|
|
|
/* Write a description of the stream into array pointed by desc, which must be length bytes long.
|
|
|
|
* Will always be null-terminated if length > 0 */
|
2008-03-11 02:27:59 +01:00
|
|
|
void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
|
2018-12-08 00:33:07 +01:00
|
|
|
#define TEMPSIZE (256+32)
|
2008-03-11 02:27:59 +01:00
|
|
|
char temp[TEMPSIZE];
|
2017-01-08 02:27:35 +01:00
|
|
|
const char* description;
|
2019-03-03 22:24:29 +01:00
|
|
|
double time_mm, time_ss, seconds;
|
2008-03-11 02:27:59 +01:00
|
|
|
|
2008-02-05 07:44:44 +01:00
|
|
|
if (!vgmstream) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "NULL VGMSTREAM");
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2008-02-05 07:44:44 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-03-11 02:27:59 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "sample rate: %d Hz\n", vgmstream->sample_rate);
|
2019-02-17 20:28:27 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "channels: %d\n", vgmstream->channels);
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
2019-03-18 00:05:44 +01:00
|
|
|
{
|
|
|
|
int output_channels = 0;
|
|
|
|
mixing_info(vgmstream, NULL, &output_channels);
|
|
|
|
|
|
|
|
if (output_channels != vgmstream->channels) {
|
2019-03-23 22:42:07 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "input channels: %d\n", vgmstream->channels); /* repeated but mainly for plugins */
|
|
|
|
concatn(length,desc,temp);
|
2019-03-18 00:05:44 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "output channels: %d\n", output_channels);
|
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
if (vgmstream->channel_layout) {
|
|
|
|
int cl = vgmstream->channel_layout;
|
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
/* not "channel layout: " to avoid mixups with "layout: " */
|
|
|
|
snprintf(temp,TEMPSIZE, "channel mask: 0x%x /", vgmstream->channel_layout);
|
2019-03-02 15:57:41 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
if (cl & speaker_FL) concatn(length,desc," FL");
|
|
|
|
if (cl & speaker_FR) concatn(length,desc," FR");
|
|
|
|
if (cl & speaker_FC) concatn(length,desc," FC");
|
|
|
|
if (cl & speaker_LFE) concatn(length,desc," LFE");
|
|
|
|
if (cl & speaker_BL) concatn(length,desc," BL");
|
|
|
|
if (cl & speaker_BR) concatn(length,desc," BR");
|
|
|
|
if (cl & speaker_FLC) concatn(length,desc," FLC");
|
|
|
|
if (cl & speaker_FRC) concatn(length,desc," FRC");
|
|
|
|
if (cl & speaker_BC) concatn(length,desc," BC");
|
|
|
|
if (cl & speaker_SL) concatn(length,desc," SL");
|
|
|
|
if (cl & speaker_SR) concatn(length,desc," SR");
|
|
|
|
if (cl & speaker_TC) concatn(length,desc," TC");
|
|
|
|
if (cl & speaker_TFL) concatn(length,desc," TFL");
|
|
|
|
if (cl & speaker_TFC) concatn(length,desc," TFC");
|
|
|
|
if (cl & speaker_TFR) concatn(length,desc," TFR");
|
|
|
|
if (cl & speaker_TBL) concatn(length,desc," TBL");
|
|
|
|
if (cl & speaker_TBC) concatn(length,desc," TBC");
|
|
|
|
if (cl & speaker_TBR) concatn(length,desc," TBR");
|
|
|
|
concatn(length,desc,"\n");
|
|
|
|
}
|
|
|
|
|
2019-02-15 23:46:21 +01:00
|
|
|
if (vgmstream->loop_start_sample >= 0 && vgmstream->loop_end_sample > vgmstream->loop_start_sample) {
|
2019-03-03 22:24:29 +01:00
|
|
|
if (!vgmstream->loop_flag) {
|
|
|
|
concatn(length,desc,"looping: disabled\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
seconds = (double)vgmstream->loop_start_sample / vgmstream->sample_rate;
|
|
|
|
time_mm = (int)(seconds / 60.0);
|
|
|
|
time_ss = seconds - time_mm * 60.0f;
|
2019-03-16 00:10:28 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "loop start: %d samples (%1.0f:%06.3f seconds)\n", vgmstream->loop_start_sample, time_mm, time_ss);
|
2019-03-03 22:24:29 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
|
|
|
seconds = (double)vgmstream->loop_end_sample / vgmstream->sample_rate;
|
|
|
|
time_mm = (int)(seconds / 60.0);
|
|
|
|
time_ss = seconds - time_mm * 60.0f;
|
2019-03-16 00:10:28 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "loop end: %d samples (%1.0f:%06.3f seconds)\n", vgmstream->loop_end_sample, time_mm, time_ss);
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2008-02-05 07:44:44 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
seconds = (double)vgmstream->num_samples / vgmstream->sample_rate;
|
|
|
|
time_mm = (int)(seconds / 60.0);
|
|
|
|
time_ss = seconds - time_mm * 60.0;
|
2019-03-16 00:10:28 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "stream total samples: %d (%1.0f:%06.3f seconds)\n", vgmstream->num_samples, time_mm, time_ss);
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "encoding: ");
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2008-02-05 07:44:44 +01:00
|
|
|
switch (vgmstream->coding_type) {
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-03-03 22:24:29 +01:00
|
|
|
|
2017-01-08 02:27:35 +01:00
|
|
|
case coding_FFmpeg: {
|
2019-03-03 22:24:29 +01:00
|
|
|
//todo codec bugs with layout inside layouts (ex. TXTP)
|
2019-01-27 23:40:50 +01:00
|
|
|
ffmpeg_codec_data *data = NULL;
|
|
|
|
|
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
2018-08-25 12:22:40 +02:00
|
|
|
layered_layout_data* layout_data = vgmstream->layout_data;
|
|
|
|
if (layout_data->layers[0]->coding_type == coding_FFmpeg)
|
|
|
|
data = layout_data->layers[0]->codec_data;
|
|
|
|
}
|
2019-01-27 23:40:50 +01:00
|
|
|
else if (vgmstream->layout_type == layout_segmented) {
|
|
|
|
segmented_layout_data* layout_data = vgmstream->layout_data;
|
|
|
|
if (layout_data->segments[0]->coding_type == coding_FFmpeg)
|
|
|
|
data = layout_data->segments[0]->codec_data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data = vgmstream->codec_data;
|
|
|
|
}
|
2018-08-25 12:22:40 +02:00
|
|
|
|
|
|
|
if (data) {
|
2017-01-08 02:27:35 +01:00
|
|
|
if (data->codec && data->codec->long_name) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "%s",data->codec->long_name);
|
2017-01-08 02:27:35 +01:00
|
|
|
} else if (data->codec && data->codec->name) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "%s",data->codec->name);
|
2017-01-08 02:27:35 +01:00
|
|
|
} else {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "FFmpeg (unknown codec)");
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
2017-01-08 02:27:35 +01:00
|
|
|
} else {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "FFmpeg");
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-08 02:27:35 +01:00
|
|
|
}
|
2016-07-17 08:02:27 +02:00
|
|
|
#endif
|
2008-02-05 07:44:44 +01:00
|
|
|
default:
|
2017-01-08 02:27:35 +01:00
|
|
|
description = get_vgmstream_coding_description(vgmstream->coding_type);
|
2019-03-03 22:24:29 +01:00
|
|
|
if (!description) description = "CANNOT DECODE";
|
|
|
|
snprintf(temp,TEMPSIZE, "%s",description);
|
2017-01-08 02:27:35 +01:00
|
|
|
break;
|
2008-02-05 07:44:44 +01:00
|
|
|
}
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2019-03-03 22:24:29 +01:00
|
|
|
concatn(length,desc,"\n");
|
2008-03-11 02:27:59 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "layout: ");
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2019-03-03 22:24:29 +01:00
|
|
|
{
|
|
|
|
VGMSTREAM* vgmstreamsub = NULL;
|
2019-01-20 00:39:32 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
description = get_vgmstream_layout_description(vgmstream->layout_type);
|
|
|
|
if (!description) description = "INCONCEIVABLE";
|
2008-03-11 02:27:59 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
if (vgmstream->layout_type == layout_layered) {
|
|
|
|
vgmstreamsub = ((layered_layout_data*)vgmstream->layout_data)->layers[0];
|
|
|
|
snprintf(temp,TEMPSIZE, "%s (%i layers)", description, ((layered_layout_data*)vgmstream->layout_data)->layer_count);
|
|
|
|
}
|
|
|
|
else if (vgmstream->layout_type == layout_segmented) {
|
|
|
|
snprintf(temp,TEMPSIZE, "%s (%i segments)", description, ((segmented_layout_data*)vgmstream->layout_data)->segment_count);
|
|
|
|
vgmstreamsub = ((segmented_layout_data*)vgmstream->layout_data)->segments[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
snprintf(temp,TEMPSIZE, "%s",description);
|
|
|
|
}
|
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
|
|
|
/* layouts can contain layouts infinitely let's leave it at one level deep (most common) */
|
|
|
|
if (vgmstreamsub && vgmstreamsub->layout_type == layout_layered) {
|
|
|
|
description = get_vgmstream_layout_description(vgmstreamsub->layout_type);
|
|
|
|
snprintf(temp,TEMPSIZE, " + %s (%i layers)",description, ((layered_layout_data*)vgmstreamsub->layout_data)->layer_count);
|
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
|
|
|
else if (vgmstreamsub && vgmstreamsub->layout_type == layout_segmented) {
|
|
|
|
description = get_vgmstream_layout_description(vgmstreamsub->layout_type);
|
|
|
|
snprintf(temp,TEMPSIZE, " + %s (%i segments)",description, ((segmented_layout_data*)vgmstream->layout_data)->segment_count);
|
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
concatn(length,desc,"\n");
|
2008-02-05 07:44:44 +01:00
|
|
|
|
2018-08-25 12:22:40 +02:00
|
|
|
if (vgmstream->layout_type == layout_interleave && vgmstream->channels > 1) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "interleave: %#x bytes\n", (int32_t)vgmstream->interleave_block_size);
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (vgmstream->interleave_last_block_size) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "interleave last block: %#x bytes\n", (int32_t)vgmstream->interleave_last_block_size);
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2008-02-05 07:44:44 +01:00
|
|
|
}
|
|
|
|
}
|
2008-03-03 22:38:11 +01:00
|
|
|
|
2018-08-25 12:22:40 +02:00
|
|
|
/* codecs with configurable frame size */
|
2017-04-29 02:19:27 +02:00
|
|
|
if (vgmstream->layout_type == layout_none && vgmstream->interleave_block_size > 0) {
|
|
|
|
switch (vgmstream->coding_type) {
|
|
|
|
case coding_MSADPCM:
|
2019-01-19 23:08:26 +01:00
|
|
|
case coding_MSADPCM_int:
|
2018-08-02 17:15:09 +02:00
|
|
|
case coding_MSADPCM_ck:
|
2017-04-29 02:19:27 +02:00
|
|
|
case coding_MS_IMA:
|
|
|
|
case coding_MC3:
|
|
|
|
case coding_WWISE_IMA:
|
2017-06-24 23:30:10 +02:00
|
|
|
case coding_REF_IMA:
|
2018-08-25 12:22:40 +02:00
|
|
|
case coding_PSX_cfg:
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "frame size: %#x bytes\n", (int32_t)vgmstream->interleave_block_size);
|
2017-04-29 02:19:27 +02:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-11 02:27:59 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "metadata from: ");
|
2017-04-29 02:19:27 +02:00
|
|
|
concatn(length,desc,temp);
|
2008-03-03 22:38:11 +01:00
|
|
|
switch (vgmstream->meta_type) {
|
2017-01-08 02:27:35 +01:00
|
|
|
default:
|
|
|
|
description = get_vgmstream_meta_description(vgmstream->meta_type);
|
2019-03-03 22:24:29 +01:00
|
|
|
if (!description) description = "THEY SHOULD HAVE SENT A POET";
|
|
|
|
snprintf(temp,TEMPSIZE, "%s", description);
|
2008-03-03 22:38:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-11 02:27:59 +01:00
|
|
|
concatn(length,desc,temp);
|
2019-03-03 22:24:29 +01:00
|
|
|
concatn(length,desc,"\n");
|
2017-03-04 02:05:07 +01:00
|
|
|
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "bitrate: %d kbps\n", get_vgmstream_average_bitrate(vgmstream) / 1000); //todo \n?
|
2018-01-28 00:31:12 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
|
2017-03-04 02:05:07 +01:00
|
|
|
/* only interesting if more than one */
|
|
|
|
if (vgmstream->num_streams > 1) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "stream count: %d\n", vgmstream->num_streams);
|
2017-03-04 02:05:07 +01:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
2017-08-12 11:27:10 +02:00
|
|
|
|
2018-11-04 00:37:33 +01:00
|
|
|
if (vgmstream->num_streams > 1) {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "stream index: %d\n", vgmstream->stream_index == 0 ? 1 : vgmstream->stream_index);
|
2017-08-12 11:27:10 +02:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
2018-11-04 00:37:33 +01:00
|
|
|
|
2017-08-12 11:27:10 +02:00
|
|
|
if (vgmstream->stream_name[0] != '\0') {
|
2019-03-03 22:24:29 +01:00
|
|
|
snprintf(temp,TEMPSIZE, "stream name: %s\n", vgmstream->stream_name);
|
2017-08-12 11:27:10 +02:00
|
|
|
concatn(length,desc,temp);
|
|
|
|
}
|
2008-02-05 07:44:44 +01:00
|
|
|
}
|
2008-03-25 08:30:04 +01:00
|
|
|
|
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
/* See if there is a second file which may be the second channel, given an already opened mono vgmstream.
|
|
|
|
* If a suitable file is found, open it and change opened_vgmstream to a stereo vgmstream. */
|
|
|
|
static void try_dual_file_stereo(VGMSTREAM * opened_vgmstream, STREAMFILE *streamFile, VGMSTREAM*(*init_vgmstream_function)(STREAMFILE *)) {
|
|
|
|
/* filename search pairs for dual file stereo */
|
|
|
|
static const char * const dfs_pairs[][2] = {
|
|
|
|
{"L","R"},
|
|
|
|
{"l","r"},
|
|
|
|
{"left","right"},
|
|
|
|
{"Left","Right"},
|
2018-03-24 19:43:17 +01:00
|
|
|
{".V0",".V1"}, /* Homura (PS2) */
|
2018-08-21 22:16:56 +02:00
|
|
|
{".L",".R"}, /* Crash Nitro Racing (PS2), Gradius V (PS2) */
|
2019-07-28 14:47:33 +02:00
|
|
|
{"_0","_1"}, /* fake for Homura/unneeded? */
|
|
|
|
{".adpcm","_NxEncoderOut_.adpcm"}, /* Kill la Kill: IF (Switch) */ //todo can't match R>L
|
2017-11-24 20:15:23 +01:00
|
|
|
};
|
|
|
|
char new_filename[PATH_LIMIT];
|
2019-07-28 14:47:33 +02:00
|
|
|
char * extension;
|
2017-11-24 20:15:23 +01:00
|
|
|
int dfs_pair = -1; /* -1=no stereo, 0=opened_vgmstream is left, 1=opened_vgmstream is right */
|
|
|
|
VGMSTREAM *new_vgmstream = NULL;
|
|
|
|
STREAMFILE *dual_streamFile = NULL;
|
2019-07-28 14:47:33 +02:00
|
|
|
int i,j, dfs_pair_count, extension_len, filename_len;
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
if (opened_vgmstream->channels != 1)
|
|
|
|
return;
|
2008-05-20 17:18:38 +02:00
|
|
|
|
2019-03-10 00:28:16 +01:00
|
|
|
/* custom codec/layouts aren't designed for this (should never get here anyway) */
|
|
|
|
if (opened_vgmstream->codec_data || opened_vgmstream->layout_data)
|
|
|
|
return;
|
|
|
|
|
2019-07-28 14:47:33 +02:00
|
|
|
//todo other layouts work but some stereo codecs do weird things
|
2017-11-24 20:15:23 +01:00
|
|
|
//if (opened_vgmstream->layout != layout_none) return;
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2019-03-10 00:28:16 +01:00
|
|
|
get_streamfile_name(streamFile,new_filename,sizeof(new_filename));
|
2019-07-28 14:47:33 +02:00
|
|
|
filename_len = strlen(new_filename);
|
|
|
|
if (filename_len < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
extension = (char *)filename_extension(new_filename);
|
|
|
|
if (extension - new_filename >= 1 && extension[-1] == '.')
|
|
|
|
extension--; /* must include "." */
|
|
|
|
extension_len = strlen(extension);
|
2019-03-10 00:28:16 +01:00
|
|
|
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2019-07-28 14:47:33 +02:00
|
|
|
/* find pair from base name and modify new_filename with the opposite (tries L>R then R>L) */
|
2017-11-24 20:15:23 +01:00
|
|
|
dfs_pair_count = (sizeof(dfs_pairs)/sizeof(dfs_pairs[0]));
|
2019-02-15 22:28:20 +01:00
|
|
|
for (i = 0; dfs_pair == -1 && i < dfs_pair_count; i++) {
|
|
|
|
for (j = 0; dfs_pair == -1 && j < 2; j++) {
|
2017-11-24 20:15:23 +01:00
|
|
|
const char * this_suffix = dfs_pairs[i][j];
|
2019-07-28 14:47:33 +02:00
|
|
|
const char * that_suffix = dfs_pairs[i][j^1];
|
2017-11-24 20:15:23 +01:00
|
|
|
size_t this_suffix_len = strlen(dfs_pairs[i][j]);
|
2019-07-28 14:47:33 +02:00
|
|
|
size_t that_suffix_len = strlen(dfs_pairs[i][j^1]);
|
|
|
|
|
|
|
|
//;VGM_LOG("DFS: l=%s, r=%s\n", this_suffix,that_suffix);
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2019-07-28 14:47:33 +02:00
|
|
|
/* is suffix matches paste opposite suffix (+ terminator) to extension pointer, thus to new_filename */
|
|
|
|
if (this_suffix[0] == '.' && extension_len == this_suffix_len) { /* same extension */
|
|
|
|
//;VGM_LOG("DFS: same ext %s vs %s len %i\n", extension, this_suffix, this_suffix_len);
|
|
|
|
if (memcmp(extension,this_suffix,this_suffix_len) == 0) {
|
2017-11-26 01:54:33 +01:00
|
|
|
dfs_pair = j;
|
2019-07-28 14:47:33 +02:00
|
|
|
memcpy (extension, that_suffix,that_suffix_len+1);
|
2017-11-26 01:54:33 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-28 14:47:33 +02:00
|
|
|
else if (filename_len > this_suffix_len) { /* same suffix (without extension) */
|
|
|
|
//;VGM_LOG("DFS: same suf %s vs %s len %i\n", extension - this_suffix_len, this_suffix, this_suffix_len);
|
|
|
|
if (memcmp(extension - this_suffix_len, this_suffix,this_suffix_len) == 0) {
|
2017-11-26 01:54:33 +01:00
|
|
|
dfs_pair = j;
|
2019-07-28 14:47:33 +02:00
|
|
|
memmove(extension + that_suffix_len - this_suffix_len, extension,extension_len+1); /* move old extension to end */
|
|
|
|
memcpy (extension - this_suffix_len, that_suffix,that_suffix_len); /* overwrite with new suffix */
|
2017-11-26 01:54:33 +01:00
|
|
|
}
|
2008-03-25 08:30:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
/* see if the filename had a suitable L/R-pair name */
|
|
|
|
if (dfs_pair == -1)
|
|
|
|
goto fail;
|
2019-07-28 14:47:33 +02:00
|
|
|
//;VGM_LOG("DFS: match %i filename=%s\n", dfs_pair, new_filename);
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
/* try to init other channel (new_filename now has the opposite name) */
|
2019-03-10 00:28:16 +01:00
|
|
|
dual_streamFile = open_streamfile(streamFile,new_filename);
|
2017-11-24 20:15:23 +01:00
|
|
|
if (!dual_streamFile) goto fail;
|
2008-06-26 04:08:26 +02:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
new_vgmstream = init_vgmstream_function(dual_streamFile); /* use the init that just worked, no other should work */
|
|
|
|
close_streamfile(dual_streamFile);
|
2008-03-25 08:30:04 +01:00
|
|
|
|
|
|
|
/* see if we were able to open the file, and if everything matched nicely */
|
2017-11-26 01:54:33 +01:00
|
|
|
if (!(new_vgmstream &&
|
2017-11-24 20:15:23 +01:00
|
|
|
new_vgmstream->channels == 1 &&
|
|
|
|
/* we have seen legitimate pairs where these are off by one...
|
|
|
|
* but leaving it commented out until I can find those and recheck */
|
|
|
|
/* abs(new_vgmstream->num_samples-opened_vgmstream->num_samples <= 1) && */
|
|
|
|
new_vgmstream->num_samples == opened_vgmstream->num_samples &&
|
|
|
|
new_vgmstream->sample_rate == opened_vgmstream->sample_rate &&
|
|
|
|
new_vgmstream->meta_type == opened_vgmstream->meta_type &&
|
|
|
|
new_vgmstream->coding_type == opened_vgmstream->coding_type &&
|
|
|
|
new_vgmstream->layout_type == opened_vgmstream->layout_type &&
|
2008-03-25 08:30:04 +01:00
|
|
|
/* check even if the layout doesn't use them, because it is
|
2017-11-24 20:15:23 +01:00
|
|
|
* difficult to determine when it does, and they should be zero otherwise, anyway */
|
|
|
|
new_vgmstream->interleave_block_size == opened_vgmstream->interleave_block_size &&
|
2018-03-24 19:27:24 +01:00
|
|
|
new_vgmstream->interleave_last_block_size == opened_vgmstream->interleave_last_block_size)) {
|
2017-11-26 01:54:33 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check these even if there is no loop, because they should then be zero in both
|
2019-02-25 00:38:35 +01:00
|
|
|
* (Homura PS2 right channel doesn't have loop points so this check is ignored) */
|
2017-11-26 01:54:33 +01:00
|
|
|
if (new_vgmstream->meta_type != meta_PS2_SMPL &&
|
|
|
|
!(new_vgmstream->loop_flag == opened_vgmstream->loop_flag &&
|
|
|
|
new_vgmstream->loop_start_sample== opened_vgmstream->loop_start_sample &&
|
|
|
|
new_vgmstream->loop_end_sample == opened_vgmstream->loop_end_sample)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We seem to have a usable, matching file. Merge in the second channel. */
|
|
|
|
{
|
2008-03-25 08:30:04 +01:00
|
|
|
VGMSTREAMCHANNEL * new_chans;
|
|
|
|
VGMSTREAMCHANNEL * new_loop_chans = NULL;
|
|
|
|
VGMSTREAMCHANNEL * new_start_chans = NULL;
|
|
|
|
|
|
|
|
/* build the channels */
|
|
|
|
new_chans = calloc(2,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!new_chans) goto fail;
|
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
memcpy(&new_chans[dfs_pair],&opened_vgmstream->ch[0],sizeof(VGMSTREAMCHANNEL));
|
|
|
|
memcpy(&new_chans[dfs_pair^1],&new_vgmstream->ch[0],sizeof(VGMSTREAMCHANNEL));
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
/* loop and start will be initialized later, we just need to allocate them here */
|
2008-03-25 08:30:04 +01:00
|
|
|
new_start_chans = calloc(2,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!new_start_chans) {
|
|
|
|
free(new_chans);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
if (opened_vgmstream->loop_ch) {
|
2008-03-25 08:30:04 +01:00
|
|
|
new_loop_chans = calloc(2,sizeof(VGMSTREAMCHANNEL));
|
|
|
|
if (!new_loop_chans) {
|
|
|
|
free(new_chans);
|
|
|
|
free(new_start_chans);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the existing structures */
|
|
|
|
/* not using close_vgmstream as that would close the file */
|
2017-11-24 20:15:23 +01:00
|
|
|
free(opened_vgmstream->ch);
|
|
|
|
free(new_vgmstream->ch);
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
free(opened_vgmstream->start_ch);
|
|
|
|
free(new_vgmstream->start_ch);
|
2008-03-25 08:30:04 +01:00
|
|
|
|
2017-11-24 20:15:23 +01:00
|
|
|
if (opened_vgmstream->loop_ch) {
|
|
|
|
free(opened_vgmstream->loop_ch);
|
|
|
|
free(new_vgmstream->loop_ch);
|
2008-03-25 08:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the new structures */
|
2017-11-24 20:15:23 +01:00
|
|
|
opened_vgmstream->ch = new_chans;
|
|
|
|
opened_vgmstream->start_ch = new_start_chans;
|
|
|
|
opened_vgmstream->loop_ch = new_loop_chans;
|
2008-03-25 08:30:04 +01:00
|
|
|
|
|
|
|
/* stereo! */
|
2017-11-24 20:15:23 +01:00
|
|
|
opened_vgmstream->channels = 2;
|
2008-03-25 08:30:04 +01:00
|
|
|
|
|
|
|
/* discard the second VGMSTREAM */
|
2017-11-24 20:15:23 +01:00
|
|
|
free(new_vgmstream);
|
2019-03-10 00:28:16 +01:00
|
|
|
|
|
|
|
mixing_update_channel(opened_vgmstream); /* notify of new channel hacked-in */
|
2008-03-25 08:30:04 +01:00
|
|
|
}
|
2017-11-26 01:54:33 +01:00
|
|
|
|
2019-04-07 02:10:44 +02:00
|
|
|
return;
|
2008-03-25 08:30:04 +01:00
|
|
|
fail:
|
2019-04-07 02:10:44 +02:00
|
|
|
close_vgmstream(new_vgmstream);
|
2008-05-20 17:18:38 +02:00
|
|
|
return;
|
2009-07-30 06:10:16 +02:00
|
|
|
}
|
2015-02-09 04:01:26 +01:00
|
|
|
|
2018-09-09 16:28:39 +02:00
|
|
|
/* average bitrate helper to get STREAMFILE for a channel, since some codecs may use their own */
|
|
|
|
static STREAMFILE * get_vgmstream_average_bitrate_channel_streamfile(VGMSTREAM * vgmstream, int channel) {
|
2017-12-06 15:32:52 +01:00
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_NWA) {
|
2018-09-09 16:28:39 +02:00
|
|
|
nwa_codec_data *data = vgmstream->codec_data;
|
|
|
|
return (data && data->nwa) ? data->nwa->file : NULL;
|
2018-03-16 18:41:30 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_ACM) {
|
2018-09-09 16:28:39 +02:00
|
|
|
acm_codec_data *data = vgmstream->codec_data;
|
|
|
|
return (data && data->handle) ? data->streamfile : NULL;
|
2018-03-16 18:41:30 +01:00
|
|
|
}
|
|
|
|
|
2015-02-14 01:47:59 +01:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_OGG_VORBIS) {
|
2018-09-09 16:28:39 +02:00
|
|
|
ogg_vorbis_codec_data *data = vgmstream->codec_data;
|
|
|
|
return data ? data->ov_streamfile.streamfile : NULL;
|
2015-02-14 01:47:59 +01:00
|
|
|
}
|
|
|
|
#endif
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_CRI_HCA) {
|
2018-09-09 16:28:39 +02:00
|
|
|
hca_codec_data *data = vgmstream->codec_data;
|
|
|
|
return data ? data->streamfile : NULL;
|
2016-06-28 09:20:37 +02:00
|
|
|
}
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_FFmpeg) {
|
2018-09-09 16:28:39 +02:00
|
|
|
ffmpeg_codec_data *data = vgmstream->codec_data;
|
|
|
|
return data ? data->streamfile : NULL;
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
2015-02-14 01:47:59 +01:00
|
|
|
#if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC)
|
2019-02-15 22:28:20 +01:00
|
|
|
if (vgmstream->coding_type == coding_MP4_AAC) {
|
2018-09-09 16:28:39 +02:00
|
|
|
mp4_aac_codec_data *data = vgmstream->codec_data;
|
|
|
|
return data ? data->if_file.streamfile : NULL;
|
2015-02-14 01:47:59 +01:00
|
|
|
}
|
|
|
|
#endif
|
2018-09-09 16:28:39 +02:00
|
|
|
|
2015-02-14 01:47:59 +01:00
|
|
|
return vgmstream->ch[channel].streamfile;
|
|
|
|
}
|
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
static int get_vgmstream_file_bitrate_from_size(size_t size, int sample_rate, int length_samples) {
|
|
|
|
if (sample_rate == 0 || length_samples == 0) return 0;
|
|
|
|
if (length_samples < 100) return 0; /* ignore stupid bitrates caused by some segments */
|
2018-01-28 00:31:12 +01:00
|
|
|
return (int)((int64_t)size * 8 * sample_rate / length_samples);
|
|
|
|
}
|
2019-02-24 09:51:10 +01:00
|
|
|
static int get_vgmstream_file_bitrate_from_streamfile(STREAMFILE * streamfile, int sample_rate, int length_samples) {
|
|
|
|
if (streamfile == NULL) return 0;
|
|
|
|
return get_vgmstream_file_bitrate_from_size(get_streamfile_size(streamfile), sample_rate, length_samples);
|
2015-02-09 04:01:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
static int get_vgmstream_file_bitrate_main(VGMSTREAM * vgmstream, STREAMFILE **streamfile_pointers, int *pointers_count, int pointers_max) {
|
|
|
|
int sub, ch;
|
2015-02-09 04:01:26 +01:00
|
|
|
int bitrate = 0;
|
2015-08-24 01:44:23 +02:00
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
/* Recursively get bitrate and fill the list of streamfiles if needed (to filter),
|
|
|
|
* since layouts can include further vgmstreams that may also share streamfiles.
|
|
|
|
*
|
|
|
|
* Because of how data, layers and segments can be combined it's possible to
|
|
|
|
* fool this in various ways; metas should report stream_size in complex cases
|
|
|
|
* to get accurate bitrates (particularly for subsongs). */
|
2017-12-06 15:32:52 +01:00
|
|
|
|
2018-01-28 00:31:12 +01:00
|
|
|
if (vgmstream->stream_size) {
|
2019-02-24 09:51:10 +01:00
|
|
|
bitrate = get_vgmstream_file_bitrate_from_size(vgmstream->stream_size, vgmstream->sample_rate, vgmstream->num_samples);
|
2018-01-28 00:31:12 +01:00
|
|
|
}
|
2019-02-24 09:51:10 +01:00
|
|
|
else if (vgmstream->layout_type == layout_segmented) {
|
2018-03-10 20:25:57 +01:00
|
|
|
segmented_layout_data *data = (segmented_layout_data *) vgmstream->layout_data;
|
2018-09-09 19:22:32 +02:00
|
|
|
for (sub = 0; sub < data->segment_count; sub++) {
|
2019-02-24 09:51:10 +01:00
|
|
|
bitrate += get_vgmstream_file_bitrate_main(data->segments[sub], streamfile_pointers, pointers_count, pointers_max);
|
2018-09-09 19:22:32 +02:00
|
|
|
}
|
2019-02-24 09:51:10 +01:00
|
|
|
bitrate = bitrate / data->segment_count;
|
2018-03-10 17:33:48 +01:00
|
|
|
}
|
2019-02-15 22:28:20 +01:00
|
|
|
else if (vgmstream->layout_type == layout_layered) {
|
2018-09-09 19:22:32 +02:00
|
|
|
layered_layout_data *data = vgmstream->layout_data;
|
|
|
|
for (sub = 0; sub < data->layer_count; sub++) {
|
2019-02-24 09:51:10 +01:00
|
|
|
bitrate += get_vgmstream_file_bitrate_main(data->layers[sub], streamfile_pointers, pointers_count, pointers_max);
|
2018-09-09 19:22:32 +02:00
|
|
|
}
|
2019-02-24 09:51:10 +01:00
|
|
|
bitrate = bitrate / data->layer_count;
|
2018-09-09 19:22:32 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-24 09:51:10 +01:00
|
|
|
/* Add channel bitrate if streamfile hasn't been used before (comparing files
|
|
|
|
* by absolute paths), so bitrate doesn't multiply when the same STREAMFILE is
|
|
|
|
* reopened per channel, also skipping repeated pointers. */
|
2018-09-09 19:22:32 +02:00
|
|
|
char path_current[PATH_LIMIT];
|
|
|
|
char path_compare[PATH_LIMIT];
|
2019-02-24 09:51:10 +01:00
|
|
|
int is_unique = 1;
|
2018-03-10 17:33:48 +01:00
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
|
|
|
STREAMFILE * currentFile = get_vgmstream_average_bitrate_channel_streamfile(vgmstream, ch);
|
2018-09-09 19:22:32 +02:00
|
|
|
if (!currentFile) continue;
|
|
|
|
get_streamfile_name(currentFile, path_current, sizeof(path_current));
|
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
for (sub = 0; sub < *pointers_count; sub++) {
|
|
|
|
STREAMFILE * compareFile = streamfile_pointers[sub];
|
2018-09-09 19:22:32 +02:00
|
|
|
if (!compareFile) continue;
|
2019-02-24 09:51:10 +01:00
|
|
|
if (currentFile == compareFile) {
|
|
|
|
is_unique = 0;
|
2018-09-09 19:22:32 +02:00
|
|
|
break;
|
2019-02-24 09:51:10 +01:00
|
|
|
}
|
2018-09-09 19:22:32 +02:00
|
|
|
get_streamfile_name(compareFile, path_compare, sizeof(path_compare));
|
2019-02-24 09:51:10 +01:00
|
|
|
if (strcmp(path_current, path_compare) == 0) {
|
|
|
|
is_unique = 0;
|
2018-09-09 19:22:32 +02:00
|
|
|
break;
|
2019-02-24 09:51:10 +01:00
|
|
|
}
|
2018-09-09 19:22:32 +02:00
|
|
|
}
|
2015-02-09 04:01:26 +01:00
|
|
|
|
2019-02-24 09:51:10 +01:00
|
|
|
if (is_unique) {
|
|
|
|
if (*pointers_count >= pointers_max) goto fail;
|
|
|
|
streamfile_pointers[*pointers_count] = currentFile;
|
|
|
|
(*pointers_count)++;
|
|
|
|
|
|
|
|
bitrate += get_vgmstream_file_bitrate_from_streamfile(currentFile, vgmstream->sample_rate, vgmstream->num_samples);
|
2018-09-09 19:22:32 +02:00
|
|
|
}
|
2015-02-09 04:01:26 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-06 15:32:52 +01:00
|
|
|
|
2015-02-09 04:01:26 +01:00
|
|
|
return bitrate;
|
2019-02-24 09:51:10 +01:00
|
|
|
fail:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the average bitrate in bps of all unique data contained within this stream.
|
|
|
|
* This is the bitrate of the *file*, as opposed to the bitrate of the *codec*, meaning
|
|
|
|
* it counts extra data like block headers and padding. While this can be surprising
|
|
|
|
* sometimes (as it's often higher than common codec bitrates) it isn't wrong per se. */
|
|
|
|
int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream) {
|
|
|
|
const size_t pointers_max = 128; /* arbitrary max, but +100 segments have been observed */
|
|
|
|
STREAMFILE *streamfile_pointers[128]; /* list already used streamfiles */
|
|
|
|
int pointers_count = 0;
|
|
|
|
|
|
|
|
return get_vgmstream_file_bitrate_main(vgmstream, streamfile_pointers, &pointers_count, pointers_max);
|
2015-02-09 04:01:26 +01:00
|
|
|
}
|
2017-01-14 00:59:54 +01:00
|
|
|
|
|
|
|
|
2017-03-09 20:38:52 +01:00
|
|
|
/**
|
2018-04-19 22:44:05 +02:00
|
|
|
* Inits vgmstream, doing two things:
|
2017-03-09 20:38:52 +01:00
|
|
|
* - sets the starting offset per channel (depending on the layout)
|
|
|
|
* - opens its own streamfile from on a base one. One streamfile per channel may be open (to improve read/seeks).
|
2018-02-24 22:30:17 +01:00
|
|
|
* Should be called in metas before returning the VGMSTREAM.
|
2017-03-09 20:38:52 +01:00
|
|
|
*/
|
2017-01-14 00:59:54 +01:00
|
|
|
int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t start_offset) {
|
2018-08-20 20:05:44 +02:00
|
|
|
STREAMFILE * file = NULL;
|
2017-01-14 00:59:54 +01:00
|
|
|
char filename[PATH_LIMIT];
|
|
|
|
int ch;
|
2017-01-15 21:02:01 +01:00
|
|
|
int use_streamfile_per_channel = 0;
|
|
|
|
int use_same_offset_per_channel = 0;
|
2018-09-04 17:10:41 +02:00
|
|
|
int is_stereo_codec = 0;
|
2017-01-14 00:59:54 +01:00
|
|
|
|
2017-03-09 20:38:52 +01:00
|
|
|
|
2019-03-24 01:21:09 +01:00
|
|
|
if (vgmstream == NULL) {
|
|
|
|
VGM_LOG("VGMSTREAM: buggy code (null vgmstream)\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-19 22:44:05 +02:00
|
|
|
/* stream/offsets not needed, managed by layout */
|
2019-02-23 16:17:29 +01:00
|
|
|
if (vgmstream->layout_type == layout_segmented ||
|
2018-03-30 21:28:32 +02:00
|
|
|
vgmstream->layout_type == layout_layered)
|
2017-03-09 20:38:52 +01:00
|
|
|
return 1;
|
|
|
|
|
2018-04-19 22:44:05 +02:00
|
|
|
/* stream/offsets not needed, managed by decoder */
|
2018-09-04 17:51:34 +02:00
|
|
|
if (vgmstream->coding_type == coding_NWA ||
|
|
|
|
vgmstream->coding_type == coding_ACM ||
|
|
|
|
vgmstream->coding_type == coding_CRI_HCA)
|
2018-04-19 22:44:05 +02:00
|
|
|
return 1;
|
|
|
|
|
2017-01-14 00:59:54 +01:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2018-04-19 22:44:05 +02:00
|
|
|
/* stream/offsets not needed, managed by decoder */
|
2017-03-09 20:38:52 +01:00
|
|
|
if (vgmstream->coding_type == coding_FFmpeg)
|
2017-01-14 00:59:54 +01:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
|
2017-01-15 21:02:01 +01:00
|
|
|
/* if interleave is big enough keep a buffer per channel */
|
2017-06-24 22:53:17 +02:00
|
|
|
if (vgmstream->interleave_block_size * vgmstream->channels >= STREAMFILE_DEFAULT_BUFFER_SIZE) {
|
2017-01-15 21:02:01 +01:00
|
|
|
use_streamfile_per_channel = 1;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 20:21:55 +02:00
|
|
|
/* if blocked layout (implicit) use multiple streamfiles; using only one leads to
|
|
|
|
* lots of buffer-trashing, with all the jumping around in the block layout */
|
|
|
|
if (vgmstream->layout_type != layout_none && vgmstream->layout_type != layout_interleave) {
|
|
|
|
use_streamfile_per_channel = 1;
|
|
|
|
}
|
|
|
|
|
2017-03-09 20:38:52 +01:00
|
|
|
/* for mono or codecs like IMA (XBOX, MS IMA, MS ADPCM) where channels work with the same bytes */
|
2017-02-18 18:27:21 +01:00
|
|
|
if (vgmstream->layout_type == layout_none) {
|
2017-01-15 21:02:01 +01:00
|
|
|
use_same_offset_per_channel = 1;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|
|
|
|
|
2018-09-04 17:10:41 +02:00
|
|
|
/* stereo codecs interleave in 2ch pairs (interleave size should still be: full_block_size / channels) */
|
2019-03-11 11:58:57 +01:00
|
|
|
if (vgmstream->layout_type == layout_interleave &&
|
|
|
|
(vgmstream->coding_type == coding_XBOX_IMA || vgmstream->coding_type == coding_MTAF)) {
|
2018-09-04 17:10:41 +02:00
|
|
|
is_stereo_codec = 1;
|
|
|
|
}
|
2017-01-14 00:59:54 +01:00
|
|
|
|
2019-03-24 01:21:09 +01:00
|
|
|
if (streamFile == NULL || start_offset < 0) {
|
|
|
|
VGM_LOG("VGMSTREAM: buggy code (null streamfile / wrong start_offset)\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-10 00:28:16 +01:00
|
|
|
get_streamfile_name(streamFile,filename,sizeof(filename));
|
2017-01-14 00:59:54 +01:00
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
2017-01-15 21:02:01 +01:00
|
|
|
if (!use_streamfile_per_channel) {
|
2019-03-10 00:28:16 +01:00
|
|
|
file = open_streamfile(streamFile,filename);
|
2017-01-15 21:02:01 +01:00
|
|
|
if (!file) goto fail;
|
|
|
|
}
|
2017-01-14 00:59:54 +01:00
|
|
|
|
2019-01-19 23:08:26 +01:00
|
|
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
2017-01-15 21:02:01 +01:00
|
|
|
off_t offset;
|
|
|
|
if (use_same_offset_per_channel) {
|
|
|
|
offset = start_offset;
|
2018-09-04 17:10:41 +02:00
|
|
|
} else if (is_stereo_codec) {
|
|
|
|
int ch_mod = (ch & 1) ? ch - 1 : ch; /* adjust odd channels (ch 0,1,2,3,4,5 > ch 0,0,2,2,4,4) */
|
|
|
|
offset = start_offset + vgmstream->interleave_block_size*ch_mod;
|
2017-01-15 21:02:01 +01:00
|
|
|
} else {
|
|
|
|
offset = start_offset + vgmstream->interleave_block_size*ch;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|
2017-01-15 21:02:01 +01:00
|
|
|
|
|
|
|
/* open new one if needed */
|
|
|
|
if (use_streamfile_per_channel) {
|
2019-03-10 00:28:16 +01:00
|
|
|
file = open_streamfile(streamFile,filename);
|
2017-01-15 21:02:01 +01:00
|
|
|
if (!file) goto fail;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|
2017-01-15 21:02:01 +01:00
|
|
|
|
|
|
|
vgmstream->ch[ch].streamfile = file;
|
|
|
|
vgmstream->ch[ch].channel_start_offset =
|
|
|
|
vgmstream->ch[ch].offset = offset;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 13:46:07 +02:00
|
|
|
/* init first block for blocked layout (if not blocked this will do nothing) */
|
|
|
|
block_update(start_offset, vgmstream);
|
|
|
|
|
2017-12-03 13:44:55 +01:00
|
|
|
/* EA-MT decoder is a bit finicky and needs this when channel offsets change */
|
|
|
|
if (vgmstream->coding_type == coding_EA_MT) {
|
|
|
|
flush_ea_mt(vgmstream);
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:59:54 +01:00
|
|
|
return 1;
|
2017-01-15 21:02:01 +01:00
|
|
|
|
|
|
|
fail:
|
2017-01-25 22:31:28 +01:00
|
|
|
/* open streams will be closed in close_vgmstream(), hopefully called by the meta */
|
2017-01-15 21:02:01 +01:00
|
|
|
return 0;
|
2017-01-14 00:59:54 +01:00
|
|
|
}
|