1 /*
2     TiMidity++ -- MIDI to WAVE converter and player
3     Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 /***************************************************************
22  name: vorbisenc_dll  dll: vorbisenc.dll
23 ***************************************************************/
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif /* HAVE_CONFIG_H */
28 #include "interface.h"
29 
30 #ifdef AU_VORBIS_DLL
31 
32 #include <windows.h>
33 #include <vorbis/vorbisenc.h>
34 
35 extern int load_vorbisenc_dll(void);
36 extern void free_vorbisenc_dll(void);
37 
38 typedef int(*type_vorbis_encode_init)(vorbis_info *vi,long channels,long rate,long max_bitrate,long nominal_bitrate,long min_bitrate);
39 typedef int(*type_vorbis_encode_init_vbr)(vorbis_info *vi,long channels,long rate,float base_quality);
40 typedef int(*type_vorbis_encode_ctl)(vorbis_info *vi,int number,void *arg);
41 
42 static struct vorbisenc_dll_ {
43 	 type_vorbis_encode_init vorbis_encode_init;
44 	 type_vorbis_encode_init_vbr vorbis_encode_init_vbr;
45 	 type_vorbis_encode_ctl vorbis_encode_ctl;
46 } vorbisenc_dll;
47 
48 static volatile HANDLE h_vorbisenc_dll = NULL;
49 
free_vorbisenc_dll(void)50 void free_vorbisenc_dll(void)
51 {
52 	if(h_vorbisenc_dll){
53 		FreeLibrary(h_vorbisenc_dll);
54 		h_vorbisenc_dll = NULL;
55 	}
56 }
57 
load_vorbisenc_dll(void)58 int load_vorbisenc_dll(void)
59 {
60 	if(!h_vorbisenc_dll){
61 		h_vorbisenc_dll = LoadLibrary("vorbisenc.dll");
62 		if(!h_vorbisenc_dll) return -1;
63 	}
64 	vorbisenc_dll.vorbis_encode_init = (type_vorbis_encode_init)GetProcAddress(h_vorbisenc_dll,"vorbis_encode_init");
65 	if(!vorbisenc_dll.vorbis_encode_init){ free_vorbisenc_dll(); return -1; }
66 	vorbisenc_dll.vorbis_encode_init_vbr = (type_vorbis_encode_init_vbr)GetProcAddress(h_vorbisenc_dll,"vorbis_encode_init_vbr");
67 	if(!vorbisenc_dll.vorbis_encode_init_vbr){ free_vorbisenc_dll(); return -1; }
68 	vorbisenc_dll.vorbis_encode_ctl = (type_vorbis_encode_ctl)GetProcAddress(h_vorbisenc_dll,"vorbis_encode_ctl");
69 	if(!vorbisenc_dll.vorbis_encode_ctl){ free_vorbisenc_dll(); return -1; }
70 	return 0;
71 }
72 
vorbis_encode_init(vorbis_info * vi,long channels,long rate,long max_bitrate,long nominal_bitrate,long min_bitrate)73 int vorbis_encode_init(vorbis_info *vi,long channels,long rate,long max_bitrate,long nominal_bitrate,long min_bitrate)
74 {
75 	if(h_vorbisenc_dll){
76 		return vorbisenc_dll.vorbis_encode_init(vi,channels,rate,max_bitrate,nominal_bitrate,min_bitrate);
77 	}
78 	return (int)0;
79 }
80 
vorbis_encode_init_vbr(vorbis_info * vi,long channels,long rate,float base_quality)81 int vorbis_encode_init_vbr(vorbis_info *vi,long channels,long rate,float base_quality)
82 {
83 	if(h_vorbisenc_dll){
84 		return vorbisenc_dll.vorbis_encode_init_vbr(vi,channels,rate,base_quality);
85 	}
86 	return (int)0;
87 }
88 
vorbis_encode_ctl(vorbis_info * vi,int number,void * arg)89 int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg)
90 {
91 	if(h_vorbisenc_dll){
92 		return vorbisenc_dll.vorbis_encode_ctl(vi,number,arg);
93 	}
94 	return (int)0;
95 }
96 
97 /***************************************************************/
98 #endif /* AU_VORBIS_DLL */
99