
/*
	OggVorbis decoder interface file

	This file is always generated by gen_wuvorbisfile_h.pl
*/

#include <windows.h>
#include "wuvorbisfile.h"

int  (_cdecl *wu_ov_clear)(wu_OggVorbis_File *vf) = NULL;
int  (_cdecl *wu_ov_open_callbacks)(void *datasource, wu_OggVorbis_File *vf,		char *initial, long ibytes, wu_ov_callbacks callbacks) = NULL;
int  (_cdecl *wu_ov_test_callbacks)(void *datasource, wu_OggVorbis_File *vf,		char *initial, long ibytes, wu_ov_callbacks callbacks) = NULL;
int  (_cdecl *wu_ov_test_open)(wu_OggVorbis_File *vf) = NULL;
long  (_cdecl *wu_ov_bitrate)(wu_OggVorbis_File *vf,int i) = NULL;
long  (_cdecl *wu_ov_bitrate_instant)(wu_OggVorbis_File *vf) = NULL;
long  (_cdecl *wu_ov_streams)(wu_OggVorbis_File *vf) = NULL;
long  (_cdecl *wu_ov_seekable)(wu_OggVorbis_File *vf) = NULL;
long  (_cdecl *wu_ov_serialnumber)(wu_OggVorbis_File *vf,int i) = NULL;
wu_ogg_int64_t  (_cdecl *wu_ov_raw_total)(wu_OggVorbis_File *vf,int i) = NULL;
wu_ogg_int64_t  (_cdecl *wu_ov_pcm_total)(wu_OggVorbis_File *vf,int i) = NULL;
double  (_cdecl *wu_ov_time_total)(wu_OggVorbis_File *vf,int i) = NULL;
int  (_cdecl *wu_ov_raw_seek)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_pcm_seek)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_pcm_seek_page)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_time_seek)(wu_OggVorbis_File *vf,double pos) = NULL;
int  (_cdecl *wu_ov_time_seek_page)(wu_OggVorbis_File *vf,double pos) = NULL;
int  (_cdecl *wu_ov_raw_seek_lap)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_pcm_seek_lap)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_pcm_seek_page_lap)(wu_OggVorbis_File *vf,wu_ogg_int64_t pos) = NULL;
int  (_cdecl *wu_ov_time_seek_lap)(wu_OggVorbis_File *vf,double pos) = NULL;
int  (_cdecl *wu_ov_time_seek_page_lap)(wu_OggVorbis_File *vf,double pos) = NULL;
wu_ogg_int64_t  (_cdecl *wu_ov_raw_tell)(wu_OggVorbis_File *vf) = NULL;
wu_ogg_int64_t  (_cdecl *wu_ov_pcm_tell)(wu_OggVorbis_File *vf) = NULL;
double  (_cdecl *wu_ov_time_tell)(wu_OggVorbis_File *vf) = NULL;
wu_vorbis_info * (_cdecl *wu_ov_info)(wu_OggVorbis_File *vf,int link) = NULL;
wu_vorbis_comment * (_cdecl *wu_ov_comment)(wu_OggVorbis_File *vf,int link) = NULL;
long  (_cdecl *wu_ov_read_float)(wu_OggVorbis_File *vf,float ***pcm_channels,int samples,			  int *bitstream) = NULL;
long  (_cdecl *wu_ov_read)(wu_OggVorbis_File *vf,char *buffer,int length,		    int bigendianp,int word,int sgned,int *bitstream) = NULL;
int  (_cdecl *wu_ov_crosslap)(wu_OggVorbis_File *vf1,wu_OggVorbis_File *vf2) = NULL;
int  (_cdecl *wu_ov_halfrate)(wu_OggVorbis_File *vf,int flag) = NULL;
int  (_cdecl *wu_ov_halfrate_p)(wu_OggVorbis_File *vf) = NULL;
void  (_cdecl *wu_SetCPUType)(unsigned __int32 type) = NULL;
unsigned __int32  (_cdecl *wu_DetectCPU)(void) = NULL;
void  (_cdecl *wu_ScaleOutput)(float scale) = NULL;
;

static HMODULE WuVorbisDLL = NULL;
int  (_stdcall* Query_sizeof_OggVorbis_File)(void) = NULL;
int WuVorbisUninit(void);

int WuVorbisInit(const char *dll_file_name_can_be_null)
{
	/*
	 initialize wuvorbis.dll and import functions
	 input:
		 dll_file_name_can_be_null:
		 	Path to the wuvorbis.dll. This can be NULL, then default
		 	name "wuvorbis.dll" is used.
	 return value:
		 0   success
		 1   failed (wuvorbis.dll not found or cannot be loaded)
		 2   failed (at least one of import functions is not found)
		 3   failed (incompatible version of wuvorbis.dll)
	*/
	typedef int  (_stdcall*t_Query_sizeof_OggVorbis_File)(void);

	if(WuVorbisDLL) return 0;

	WuVorbisDLL = LoadLibrary(dll_file_name_can_be_null ? dll_file_name_can_be_null : "wuvorbis.dll");
	if(!WuVorbisDLL) return 1;

	Query_sizeof_OggVorbis_File = (int  (_stdcall*)(void))
		GetProcAddress(WuVorbisDLL, "Query_sizeof_OggVorbis_File");
	if(!Query_sizeof_OggVorbis_File) goto fail;

	if(Query_sizeof_OggVorbis_File() > sizeof(wu_OggVorbis_File))
		goto fail_with_status_3;

	*(void**)&wu_ov_clear = GetProcAddress(WuVorbisDLL, "wu_ov_clear");
	if(!wu_ov_clear) goto fail;
	*(void**)&wu_ov_open_callbacks = GetProcAddress(WuVorbisDLL, "wu_ov_open_callbacks");
	if(!wu_ov_open_callbacks) goto fail;
	*(void**)&wu_ov_test_callbacks = GetProcAddress(WuVorbisDLL, "wu_ov_test_callbacks");
	if(!wu_ov_test_callbacks) goto fail;
	*(void**)&wu_ov_test_open = GetProcAddress(WuVorbisDLL, "wu_ov_test_open");
	if(!wu_ov_test_open) goto fail;
	*(void**)&wu_ov_bitrate = GetProcAddress(WuVorbisDLL, "wu_ov_bitrate");
	if(!wu_ov_bitrate) goto fail;
	*(void**)&wu_ov_bitrate_instant = GetProcAddress(WuVorbisDLL, "wu_ov_bitrate_instant");
	if(!wu_ov_bitrate_instant) goto fail;
	*(void**)&wu_ov_streams = GetProcAddress(WuVorbisDLL, "wu_ov_streams");
	if(!wu_ov_streams) goto fail;
	*(void**)&wu_ov_seekable = GetProcAddress(WuVorbisDLL, "wu_ov_seekable");
	if(!wu_ov_seekable) goto fail;
	*(void**)&wu_ov_serialnumber = GetProcAddress(WuVorbisDLL, "wu_ov_serialnumber");
	if(!wu_ov_serialnumber) goto fail;
	*(void**)&wu_ov_raw_total = GetProcAddress(WuVorbisDLL, "wu_ov_raw_total");
	if(!wu_ov_raw_total) goto fail;
	*(void**)&wu_ov_pcm_total = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_total");
	if(!wu_ov_pcm_total) goto fail;
	*(void**)&wu_ov_time_total = GetProcAddress(WuVorbisDLL, "wu_ov_time_total");
	if(!wu_ov_time_total) goto fail;
	*(void**)&wu_ov_raw_seek = GetProcAddress(WuVorbisDLL, "wu_ov_raw_seek");
	if(!wu_ov_raw_seek) goto fail;
	*(void**)&wu_ov_pcm_seek = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_seek");
	if(!wu_ov_pcm_seek) goto fail;
	*(void**)&wu_ov_pcm_seek_page = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_seek_page");
	if(!wu_ov_pcm_seek_page) goto fail;
	*(void**)&wu_ov_time_seek = GetProcAddress(WuVorbisDLL, "wu_ov_time_seek");
	if(!wu_ov_time_seek) goto fail;
	*(void**)&wu_ov_time_seek_page = GetProcAddress(WuVorbisDLL, "wu_ov_time_seek_page");
	if(!wu_ov_time_seek_page) goto fail;
	*(void**)&wu_ov_raw_seek_lap = GetProcAddress(WuVorbisDLL, "wu_ov_raw_seek_lap");
	if(!wu_ov_raw_seek_lap) goto fail;
	*(void**)&wu_ov_pcm_seek_lap = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_seek_lap");
	if(!wu_ov_pcm_seek_lap) goto fail;
	*(void**)&wu_ov_pcm_seek_page_lap = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_seek_page_lap");
	if(!wu_ov_pcm_seek_page_lap) goto fail;
	*(void**)&wu_ov_time_seek_lap = GetProcAddress(WuVorbisDLL, "wu_ov_time_seek_lap");
	if(!wu_ov_time_seek_lap) goto fail;
	*(void**)&wu_ov_time_seek_page_lap = GetProcAddress(WuVorbisDLL, "wu_ov_time_seek_page_lap");
	if(!wu_ov_time_seek_page_lap) goto fail;
	*(void**)&wu_ov_raw_tell = GetProcAddress(WuVorbisDLL, "wu_ov_raw_tell");
	if(!wu_ov_raw_tell) goto fail;
	*(void**)&wu_ov_pcm_tell = GetProcAddress(WuVorbisDLL, "wu_ov_pcm_tell");
	if(!wu_ov_pcm_tell) goto fail;
	*(void**)&wu_ov_time_tell = GetProcAddress(WuVorbisDLL, "wu_ov_time_tell");
	if(!wu_ov_time_tell) goto fail;
	*(void**)&wu_ov_info = GetProcAddress(WuVorbisDLL, "wu_ov_info");
	if(!wu_ov_info) goto fail;
	*(void**)&wu_ov_comment = GetProcAddress(WuVorbisDLL, "wu_ov_comment");
	if(!wu_ov_comment) goto fail;
	*(void**)&wu_ov_read_float = GetProcAddress(WuVorbisDLL, "wu_ov_read_float");
	if(!wu_ov_read_float) goto fail;
	*(void**)&wu_ov_read = GetProcAddress(WuVorbisDLL, "wu_ov_read");
	if(!wu_ov_read) goto fail;
	*(void**)&wu_ov_crosslap = GetProcAddress(WuVorbisDLL, "wu_ov_crosslap");
	if(!wu_ov_crosslap) goto fail;
	*(void**)&wu_ov_halfrate = GetProcAddress(WuVorbisDLL, "wu_ov_halfrate");
	if(!wu_ov_halfrate) goto fail;
	*(void**)&wu_ov_halfrate_p = GetProcAddress(WuVorbisDLL, "wu_ov_halfrate_p");
	if(!wu_ov_halfrate_p) goto fail;
	*(void**)&wu_SetCPUType = GetProcAddress(WuVorbisDLL, "wu_SetCPUType");
	if(!wu_SetCPUType) goto fail;
	*(void**)&wu_DetectCPU = GetProcAddress(WuVorbisDLL, "wu_DetectCPU");
	if(!wu_DetectCPU) goto fail;
	*(void**)&wu_ScaleOutput = GetProcAddress(WuVorbisDLL, "wu_ScaleOutput");
	if(!wu_ScaleOutput) goto fail;
	return 0;

fail:
	WuVorbisUninit();
	return 2;

fail_with_status_3:
	WuVorbisUninit();
	return 3;
}

int WuVorbisUninit(void)
{
	/*
	 uninitialize wuvorbis.dll
	 return value:
	 0   success
	 1   unloading failed
	*/

	if(!WuVorbisDLL) return 0;

	Query_sizeof_OggVorbis_File = NULL;

	wu_ov_clear = NULL;
	wu_ov_open_callbacks = NULL;
	wu_ov_test_callbacks = NULL;
	wu_ov_test_open = NULL;
	wu_ov_bitrate = NULL;
	wu_ov_bitrate_instant = NULL;
	wu_ov_streams = NULL;
	wu_ov_seekable = NULL;
	wu_ov_serialnumber = NULL;
	wu_ov_raw_total = NULL;
	wu_ov_pcm_total = NULL;
	wu_ov_time_total = NULL;
	wu_ov_raw_seek = NULL;
	wu_ov_pcm_seek = NULL;
	wu_ov_pcm_seek_page = NULL;
	wu_ov_time_seek = NULL;
	wu_ov_time_seek_page = NULL;
	wu_ov_raw_seek_lap = NULL;
	wu_ov_pcm_seek_lap = NULL;
	wu_ov_pcm_seek_page_lap = NULL;
	wu_ov_time_seek_lap = NULL;
	wu_ov_time_seek_page_lap = NULL;
	wu_ov_raw_tell = NULL;
	wu_ov_pcm_tell = NULL;
	wu_ov_time_tell = NULL;
	wu_ov_info = NULL;
	wu_ov_comment = NULL;
	wu_ov_read_float = NULL;
	wu_ov_read = NULL;
	wu_ov_crosslap = NULL;
	wu_ov_halfrate = NULL;
	wu_ov_halfrate_p = NULL;
	wu_SetCPUType = NULL;
	wu_DetectCPU = NULL;
	wu_ScaleOutput = NULL;

	FreeLibrary(WuVorbisDLL);
	WuVorbisDLL = NULL;

	return 0;
}


