Remove/simplify formats.h and move to vgmstream.h for simpler API

This commit is contained in:
bnnm 2017-11-10 20:26:44 +01:00
parent 1c373753b9
commit 82b1f235de
11 changed files with 28 additions and 66 deletions

View File

@ -15,7 +15,6 @@
extern "C" { extern "C" {
#include "../src/formats.h"
#include "../src/vgmstream.h" #include "../src/vgmstream.h"
} }
#include "plugin.h" #include "plugin.h"
@ -95,8 +94,8 @@ bool VgmstreamPlugin::is_our_file(const char *filename, VFSFile &file) {
else else
ext = ext+1; /* skip the dot */ ext = ext+1; /* skip the dot */
const char ** ext_list = vgmstream_get_formats(); size_t ext_list_len = 0;
int ext_list_len = vgmstream_get_formats_length(); const char ** ext_list = vgmstream_get_formats(&ext_list_len);
for (int i=0; i < ext_list_len; i++) { for (int i=0; i < ext_list_len; i++) {
if (!strcasecmp(ext, ext_list[i])) if (!strcasecmp(ext, ext_list[i]))

View File

@ -16,7 +16,6 @@
#include <shared.h> #include <shared.h>
extern "C" { extern "C" {
#include "../src/formats.h"
#include "../src/vgmstream.h" #include "../src/vgmstream.h"
} }
#include "foo_vgmstream.h" #include "foo_vgmstream.h"
@ -184,19 +183,19 @@ void input_vgmstream::decode_initialize(t_uint32 p_subsong, unsigned p_flags, ab
bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort) { bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort) {
if (!decoding) return false; if (!decoding) return false;
if (!vgmstream) return false;
int max_buffer_samples = sizeof(sample_buffer)/sizeof(sample_buffer[0])/vgmstream->channels; int max_buffer_samples = sizeof(sample_buffer)/sizeof(sample_buffer[0])/vgmstream->channels;
int l = 0, samples_to_do = max_buffer_samples; int samples_to_do = max_buffer_samples;
t_size bytes;
if(vgmstream) { {
bool loop_okay = loop_forever && vgmstream->loop_flag && !ignore_loop && !force_ignore_loop; bool loop_okay = loop_forever && vgmstream->loop_flag && !ignore_loop && !force_ignore_loop;
if (decode_pos_samples+max_buffer_samples>stream_length_samples && !loop_okay) if (decode_pos_samples+max_buffer_samples>stream_length_samples && !loop_okay)
samples_to_do=stream_length_samples-decode_pos_samples; samples_to_do=stream_length_samples-decode_pos_samples;
else else
samples_to_do=max_buffer_samples; samples_to_do=max_buffer_samples;
l = (samples_to_do*vgmstream->channels * sizeof(sample_buffer[0]));
if (samples_to_do /*< DECODE_SIZE*/ == 0) { if (samples_to_do /*< DECODE_SIZE*/ == 0) {
decoding = false; decoding = false;
return false; return false;
@ -222,15 +221,14 @@ bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort)
} }
} }
p_chunk.set_data_fixedpoint((char*)sample_buffer, l, vgmstream->sample_rate, vgmstream->channels, 16, audio_chunk::g_guess_channel_config(vgmstream->channels)); bytes = (samples_to_do*vgmstream->channels * sizeof(sample_buffer[0]));
p_chunk.set_data_fixedpoint((char*)sample_buffer, bytes, vgmstream->sample_rate, vgmstream->channels, 16, audio_chunk::g_guess_channel_config(vgmstream->channels));
decode_pos_samples+=samples_to_do; decode_pos_samples+=samples_to_do;
decode_pos_ms=decode_pos_samples*1000LL/vgmstream->sample_rate; decode_pos_ms=decode_pos_samples*1000LL/vgmstream->sample_rate;
return samples_to_do==max_buffer_samples; return samples_to_do==max_buffer_samples;
} }
return false;
} }
void input_vgmstream::decode_seek(double p_seconds,abort_callback & p_abort) { void input_vgmstream::decode_seek(double p_seconds,abort_callback & p_abort) {
@ -295,11 +293,10 @@ void input_vgmstream::retag_commit(abort_callback & p_abort) { /*throw exception
bool input_vgmstream::g_is_our_content_type(const char * p_content_type) {return false;} bool input_vgmstream::g_is_our_content_type(const char * p_content_type) {return false;}
bool input_vgmstream::g_is_our_path(const char * p_path,const char * p_extension) { bool input_vgmstream::g_is_our_path(const char * p_path,const char * p_extension) {
const char ** ext_list; const char ** ext_list;
int ext_list_len; size_t ext_list_len;
int i; int i;
ext_list = vgmstream_get_formats(); ext_list = vgmstream_get_formats(&ext_list_len);
ext_list_len = vgmstream_get_formats_length();
for (i=0; i < ext_list_len; i++) { for (i=0; i < ext_list_len; i++) {
if (!stricmp_utf8(p_extension, ext_list[i])) if (!stricmp_utf8(p_extension, ext_list[i]))

View File

@ -1,4 +1,4 @@
#include "formats.h" #include "vgmstream.h"
//#define VGM_REGISTER_TYPE(extension) ... //#define VGM_REGISTER_TYPE(extension) ...
//#define VGM_REGISTER_TYPE_COMMON(extension) ... /* for common extensions like aiff */ //#define VGM_REGISTER_TYPE_COMMON(extension) ... /* for common extensions like aiff */
@ -375,22 +375,11 @@ static const char* extension_list[] = {
//, NULL //end mark //, NULL //end mark
}; };
/** const char ** vgmstream_get_formats(size_t * size) {
* List of supported formats. *size = sizeof(extension_list) / sizeof(char*);
*
* For plugins that need to know (test.exe doesn't use it)
*/
const char ** vgmstream_get_formats() {
return extension_list; return extension_list;
} }
/**
* Number of elements in the list.
*/
int vgmstream_get_formats_length() {
return sizeof(extension_list) / sizeof(char*);
}
/* internal description info */ /* internal description info */

View File

@ -1,19 +0,0 @@
/*
* formats.h - utils to parse supported formats
*/
#ifndef _FORMATS_H_
#define _FORMATS_H_
#include "vgmstream.h"
/* rough number of chars counting all extensions (actually <1500 and extra space) */
#define VGM_EXTENSION_LIST_CHAR_SIZE 2000
const char ** vgmstream_get_formats();
int vgmstream_get_formats_length();
const char * get_vgmstream_coding_description(coding_t coding_type);
const char * get_vgmstream_layout_description(layout_t layout_type);
const char * get_vgmstream_meta_description(meta_t meta_type);
#endif /* _FORMATS_H_ */

View File

@ -147,10 +147,6 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd" Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
> >
<File
RelativePath=".\formats.h"
>
</File>
<File <File
RelativePath=".\streamfile.h" RelativePath=".\streamfile.h"
> >

View File

@ -113,7 +113,6 @@
<ClInclude Include="coding\vorbis_custom_data_fsb.h" /> <ClInclude Include="coding\vorbis_custom_data_fsb.h" />
<ClInclude Include="coding\vorbis_custom_data_wwise.h" /> <ClInclude Include="coding\vorbis_custom_data_wwise.h" />
<ClInclude Include="coding\vorbis_custom_decoder.h" /> <ClInclude Include="coding\vorbis_custom_decoder.h" />
<ClInclude Include="formats.h" />
<ClInclude Include="streamfile.h" /> <ClInclude Include="streamfile.h" />
<ClInclude Include="streamtypes.h" /> <ClInclude Include="streamtypes.h" />
<ClInclude Include="util.h" /> <ClInclude Include="util.h" />

View File

@ -47,9 +47,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="formats.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="streamfile.h"> <ClInclude Include="streamfile.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>

View File

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include "formats.h"
#include "vgmstream.h" #include "vgmstream.h"
#include "meta/meta.h" #include "meta/meta.h"
#include "layout/layout.h" #include "layout/layout.h"

View File

@ -1147,6 +1147,7 @@ typedef struct {
/* do format detection, return pointer to a usable VGMSTREAM, or NULL on failure */ /* do format detection, return pointer to a usable VGMSTREAM, or NULL on failure */
VGMSTREAM * init_vgmstream(const char * const filename); VGMSTREAM * init_vgmstream(const char * const filename);
/* init with custom IO via streamfile */
VGMSTREAM * init_vgmstream_from_STREAMFILE(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_from_STREAMFILE(STREAMFILE *streamFile);
/* reset a VGMSTREAM to start of stream */ /* reset a VGMSTREAM to start of stream */
@ -1169,6 +1170,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length);
* stream. Compares files by absolute paths. */ * stream. Compares files by absolute paths. */
int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream); int get_vgmstream_average_bitrate(VGMSTREAM * vgmstream);
/* List of supported formats and elements in the list, for plugins that need to know. */
const char ** vgmstream_get_formats(size_t * size);
/* -------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------*/
/* vgmstream "private" API */ /* vgmstream "private" API */
/* -------------------------------------------------------------------------*/ /* -------------------------------------------------------------------------*/
@ -1203,4 +1207,9 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream);
* returns 0 on failure */ * returns 0 on failure */
int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t start_offset); int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t start_offset);
/* get description info */
const char * get_vgmstream_coding_description(coding_t coding_type);
const char * get_vgmstream_layout_description(layout_t layout_type);
const char * get_vgmstream_meta_description(meta_t meta_type);
#endif #endif

View File

@ -19,7 +19,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "../src/formats.h"
#include "../src/vgmstream.h" #include "../src/vgmstream.h"
#include "in2.h" #include "in2.h"
#include "wa_ipc.h" #include "wa_ipc.h"
@ -68,7 +67,7 @@ In_Module input_module;
DWORD WINAPI __stdcall decode(void *arg); DWORD WINAPI __stdcall decode(void *arg);
/* Winamp Play extension list, needed to accept/play and associate extensions in Windows */ /* Winamp Play extension list, needed to accept/play and associate extensions in Windows */
#define EXTENSION_LIST_SIZE VGM_EXTENSION_LIST_CHAR_SIZE * 6 #define EXTENSION_LIST_SIZE (0x2000 * 6)
#define EXT_BUFFER_SIZE 200 #define EXT_BUFFER_SIZE 200
char working_extension_list[EXTENSION_LIST_SIZE] = {0}; char working_extension_list[EXTENSION_LIST_SIZE] = {0};
@ -463,14 +462,13 @@ static void add_extension(int length, char * dst, const char * ext) {
* Each extension must be in this format: "extension\0Description\0" */ * Each extension must be in this format: "extension\0Description\0" */
static void build_extension_list() { static void build_extension_list() {
const char ** ext_list; const char ** ext_list;
int ext_list_len; size_t ext_list_len;
int i; int i;
working_extension_list[0]='\0'; working_extension_list[0]='\0';
working_extension_list[1]='\0'; working_extension_list[1]='\0';
ext_list = vgmstream_get_formats(); ext_list = vgmstream_get_formats(&ext_list_len);
ext_list_len = vgmstream_get_formats_length();
for (i=0; i < ext_list_len; i++) { for (i=0; i < ext_list_len; i++) {
add_extension(EXTENSION_LIST_SIZE, working_extension_list, ext_list[i]); add_extension(EXTENSION_LIST_SIZE, working_extension_list, ext_list[i]);

View File

@ -11,7 +11,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "../src/formats.h"
#include "../src/vgmstream.h" #include "../src/vgmstream.h"
#include "xmpin.h" #include "xmpin.h"
@ -27,7 +26,7 @@
/* XMPlay extension list, only needed to associate extensions in Windows */ /* XMPlay extension list, only needed to associate extensions in Windows */
/* todo: as of v3.8.2.17, any more than ~1000 will crash XMplay's file list screen (but not using the non-native Winamp plugin...) */ /* todo: as of v3.8.2.17, any more than ~1000 will crash XMplay's file list screen (but not using the non-native Winamp plugin...) */
#define EXTENSION_LIST_SIZE 1000 /*VGM_EXTENSION_LIST_CHAR_SIZE * 2*/ #define EXTENSION_LIST_SIZE 1000 /* (0x2000 * 2) */
#define XMPLAY_MAX_PATH 32768 #define XMPLAY_MAX_PATH 32768
/* XMPlay function library */ /* XMPlay function library */
@ -205,13 +204,12 @@ static int add_extension(int length, char * dst, const char * ext) {
* Extensions must be in this format: "Description\0extension1/.../extensionN" */ * Extensions must be in this format: "Description\0extension1/.../extensionN" */
static void build_extension_list() { static void build_extension_list() {
const char ** ext_list; const char ** ext_list;
int ext_list_len; size_t ext_list_len;
int i, written; int i, written;
written = sprintf(working_extension_list, "%s%c", "vgmstream files",'\0'); written = sprintf(working_extension_list, "%s%c", "vgmstream files",'\0');
ext_list = vgmstream_get_formats(); ext_list = vgmstream_get_formats(&ext_list_len);
ext_list_len = vgmstream_get_formats_length();
for (i=0; i < ext_list_len; i++) { for (i=0; i < ext_list_len; i++) {
written += add_extension(EXTENSION_LIST_SIZE-written, working_extension_list + written, ext_list[i]); written += add_extension(EXTENSION_LIST_SIZE-written, working_extension_list + written, ext_list[i]);