From b4ad96fcffd424de01c66d2b2e5eff0e1107836d Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 7 May 2023 23:47:37 +0200 Subject: [PATCH] cleanup: move stuff --- src/api.h | 128 +++++++++++++++++++++++++++++++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 + src/plugins.h | 119 +--------------------------- 4 files changed, 133 insertions(+), 118 deletions(-) create mode 100644 src/api.h diff --git a/src/api.h b/src/api.h new file mode 100644 index 00000000..b9a9f69d --- /dev/null +++ b/src/api.h @@ -0,0 +1,128 @@ +//possible future public/opaque API +#ifndef _API_H_ +#define _API_H_ +#if 0 + +#include +#include "api_streamfile.h" + +/* Current API version (major=breaking API/ABI changes, minor=compatible ABI changes). + * Internal bug fixes or added formats don't change these (see commit revision). + * Regular vgmstream features or formats are stable and are rarely removed, while this API may change from time to time */ +#define LIBVGMSTREAM_API_VERSION_MAJOR 0 +#define LIBVGMSTREAM_API_VERSION_MINOR 0 + +/* define standard C param call and name mangling (to avoid __stdcall / .defs) */ +//#define LIBVGMSTREAM_CALL __cdecl //needed? + +/* define external function types (during compilation) */ +//LIBVGMSTREAM_API void LIBVGMSTREAM_CALL vgmstream_function(void); +#if defined(LIBVGMSTREAM_EXPORT) + #define LIBVGMSTREAM_API __declspec(dllexport) /* when exporting/creating vgmstream DLL */ +#elif defined(LIBVGMSTREAM_IMPORT) + #define LIBVGMSTREAM_API __declspec(dllimport) /* when importing/linking vgmstream DLL */ +#else + #define LIBVGMSTREAM_API /* nothing, internal/default */ +#endif + +/* opaque vgmstream context/handle */ +typedef struct libvgmstream_t libvgmstream_t; + +/* init base vgmstream context */ +libvgmstream_t* libvgmstream_init(void); + +typedef struct { + int downmix_max_channels; // max number of channels + //int upmix_min_channels; // adds channels until min +} libvgmstream_config_t; + +/* pass default config, that will be applied to song on open (some formats like TXTP may override + * these settings). + * May only be called without song loaded (before _open or after _close), otherwise ignored. */ +void libvgmstream_setup(libvgmstream_t* vctx, libvgmstream_config_t* vcfg); + +//void libvgmstream_buffer(libvgmstream_t* vctx, int samples, int max_samples); + +/* Opens a new STREAMFILE to play. Returns < 0 on error when the file isn't recogniced. + * If file has subsongs, first open usually loads first subsong. get_info then can be used to check + * whether file has more subsongs (total_subsongs > 1), and call others. + * */ +int libvgmstream_open(libvgmstream_t* vctx, STREAMFILE* sf); +int libvgmstream_open_subsong(libvgmstream_t* vctx, STREAMFILE* sf, int subsong); + +typedef struct { + const int channels; + const int sample_rate; + + const int sample_count; /* file's samples (not final duration) */ + const int loop_start_sample; + const int loop_end_sample; + const int loop_flag; + + const int current_subsong; /* 0=not set, N=loaded subsong N */ + const int total_subsongs; /* 0=format has no subsongs, N=has N subsongs */ + const int file_bitrate; /* file's average bitrate */ + //const int codec_bitrate; /* codec's average bitrate */ + + /* descriptions */ + //const char* codec; + //const char* layout; + //const char* metadata; + + //int type; /* 0=pcm16, 1=float32, always interleaved: [0]=ch0, [1]=ch1 ... */ +} libvgmstream_into_t; + +/* Get info from current song. */ +void libvgmstream_t_get_info(libvgmstream_t* vctx, libvgmstream_into_t* vinfo); + + +libvgmstream_sbuf_t* libgstream_get_sbuf(libvgmstream_t* vctx); + +/* Converts samples. returns number of rendered samples, or <=0 if no more + * samples left (will fill buffer with silence) */ +int libvgmstream_play(libvgmstream_t* vctx); + + + +/* Gets final time based on config and current song. If config is set to "play forever" + * this still returns final time based on config as a reference. Returns > 0 on success. */ +int32_t libvgmstream_get_total_time(libvgmstream_t* vctx); +double libvgmstream_get_total_samples(libvgmstream_t* vctx); + + +/* Gets current position within song. When "play forever" is set, it'll clamp results to total_time. */ +int32_t libvgmstream_get_current_time(libvgmstream_t* vctx); +double libvgmstream_get_current_samples(libvgmstream_t* vctx); + + +/* Seeks to position */ +libvgmstream_t* libvgmstream_seek_absolute_sample(libvgmstream_t* vctx, int32_t sample); +libvgmstream_t* libvgmstream_seek_absolute_time(libvgmstream_t* vctx, double time); +libvgmstream_t* libvgmstream_seek_current_sample(libvgmstream_t* vctx, int32_t sample); +libvgmstream_t* libvgmstream_seek_current_time(libvgmstream_t* vctx, double time); + + +/* Closes current song. */ +void libvgmstream_close(libvgmstream_t* vctx); + +/* Frees vgmstream context. */ +void libvgmstream_free(libvgmstream_t* vctx); + +#if 0 +void vgmstream_get_buffer(...); + +void vgmstream_format_check(...); +void vgmstream_set_format_whilelist(...); +void vgmstream_set_format_blacklist(...); + +const char* vgmstream_describe(...); + +const char* vgmstream_get_title(...); + +VGMSTREAM_TAGS* vgmstream_get_tagfile(...); +#endif + + + +#endif +#endif diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 62eb143c..19bf7900 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -80,6 +80,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 9dea499e..c89f2c33 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -65,6 +65,9 @@ + + Header Files + Header Files diff --git a/src/plugins.h b/src/plugins.h index e63c4aa9..b160e8d5 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -5,24 +5,7 @@ #define _PLUGINS_H_ #include "streamfile.h" -//todo rename to api.h once public enough - - -#if 0 -/* define standard C param call and name mangling (to avoid __stdcall / .defs) */ -//#define VGMSTREAM_CALL __cdecl //needed? - -/* define external function types (during compilation) */ -#if defined(VGMSTREAM_EXPORT) - #define VGMSTREAM_API __declspec(dllexport) /* when exporting/creating vgmstream DLL */ -#elif defined(VGMSTREAM_IMPORT) - #define VGMSTREAM_API __declspec(dllimport) /* when importing/linking vgmstream DLL */ -#else - #define VGMSTREAM_API /* nothing, internal/default */ -#endif - -//VGMSTREAM_API void VGMSTREAM_CALL vgmstream_function(void); -#endif +#include "vgmstream.h" /* ****************************************** */ @@ -88,106 +71,6 @@ void vgmstream_set_log_callback(int level, void* callback); void vgmstream_set_log_stdout(int level); -#if 0 -//possible future public/opaque API - -/* opaque player state */ -//#define VGMSTREAM_CTX_VERSION 1 -typedef struct VGMSTREAM_CTX VGMSTREAM_CTX; - - -/* Setups base vgmstream player context. */ -VGMSTREAM_CTX* vgmstream_init_ctx(void); - - -/* Sets default config, that will be applied to song on open (some formats like TXTP may override - * these settings). - * May only be called without song loaded (before _open or after _close), otherwise ignored. */ -void vgmstream_set_config(VGMSTREAM_CTX* vctx, VGMSTREAM_CFG* vcfg); - -void vgmstream_set_buffer(VGMSTREAM_CTX* vctx, int samples, int max_samples); - -/* Opens a new STREAMFILE to play. Returns < 0 on error when the file isn't recogniced. - * If file has subsongs, first open usually loads first subsong. get_info then can be used to check - * whether file has more subsongs (total_subsongs > 1), and call others. - * */ -int vgmstream_open(STREAMFILE* sf); -int vgmstream_open_subsong(STREAMFILE* sf, int subsong); - -typedef struct { - const int channels; - const int sample_rate; - - const int sample_count; /* file's samples (not final duration) */ - const int loop_start_sample; - const int loop_end_sample; - const int loop_flag; - - const int current_subsong; /* 0=not set, N=loaded subsong N */ - const int total_subsongs; /* 0=format has no subsongs, N=has N subsongs */ - const int file_bitrate; /* file's average bitrate */ - //const int codec_bitrate; /* codec's average bitrate */ - - /* descriptions */ - //const char* codec; - //const char* layout; - //const char* metadata; - - //int type; /* 0=pcm16, 1=float32, always interleaved: [0]=ch0, [1]=ch1 ... */ -} VGMSTREAM_INFO; - -/* Get info from current song. */ -void vgmstream_ctx_get_info(VGMSTREAM_CTX* vctx, VGMSTREAM_INFO* vinfo); - - -/* Gets final time based on config and current song. If config is set to "play forever" - * this still returns final time based on config as a reference. Returns > 0 on success. */ -int32_t vgmstream_get_total_time(VGMSTREAM_CTX* vctx); -double vgmstream_get_total_samples(VGMSTREAM_CTX* vctx); - - -/* Gets current position within song. When "play forever" is set, it'll clamp results to total_time. */ -int32_t vgmstream_get_current_time(VGMSTREAM_CTX* vctx); -double vgmstream_get_current_samples(VGMSTREAM_CTX* vctx); - - -/* Seeks to position */ -VGMSTREAM_CTX* vgmstream_seek_absolute_sample(VGMSTREAM_CTX* vctx, int32_t sample); -VGMSTREAM_CTX* vgmstream_seek_absolute_time(VGMSTREAM_CTX* vctx, double time); -VGMSTREAM_CTX* vgmstream_seek_current_sample(VGMSTREAM_CTX* vctx, int32_t sample); -VGMSTREAM_CTX* vgmstream_seek_current_time(VGMSTREAM_CTX* vctx, double time); - - -/* Closes current song. */ -void vgmstream_close(VGMSTREAM_CTX* vctx); - -/* Frees vgmstream context. */ -void vgmstream_free_ctx(VGMSTREAM_CTX* vctx); - - -/* Converts samples. returns number of rendered samples, or <=0 if no more - * samples left (will fill buffer with silence) */ -int vgmstream_play(VGMSTREAM_CTX* vctx); - - -#if 0 -void vgmstream_get_buffer(...); - -void vgmstream_format_check(...); -void vgmstream_set_format_whilelist(...); -void vgmstream_set_format_blacklist(...); - -const char* vgmstream_describe(...); - -const char* vgmstream_get_title(...); - -VGMSTREAM_TAGS* vgmstream_get_tagfile(...); -#endif - -#endif - - - /* ****************************************** */ /* TAGS: loads key=val tags from a file */ /* ****************************************** */