研究了xaudio的sdk包,发现vb6能很方便的调用它,所以写了这个例程,只使用了xaudio.dll的一部分函数,同理可以使用其它的。调用dsound控制发声。
以下代码,原c代码部分保留用以对照。
frmmain.frm
version 5.00
begin vb.form frmmain
caption = “form1”
clientheight = 3675
clientleft = 60
clienttop = 345
clientwidth = 4680
linktopic = “form1”
scaleheight = 3675
scalewidth = 4680
startupposition = 2 centerscreen
begin vb.commandbutton cmdgetinfo
caption = “getinfo”
height = 495
left = 360
tabindex = 5
top = 3060
width = 1215
end
begin vb.commandbutton cmdgettag
caption = “gettag”
height = 495
left = 1740
tabindex = 4
top = 3060
width = 1215
end
begin vb.commandbutton cmdenum
caption = “enum”
height = 495
left = 3120
tabindex = 3
top = 2400
width = 1215
end
begin vb.commandbutton cmdplay
caption = “play”
height = 495
left = 1740
tabindex = 2
top = 2400
width = 1215
end
begin vb.textbox txtlog
height = 1995
left = 240
multiline = -1 true
scrollbars = 2 vertical
tabindex = 1
top = 180
width = 4215
end
begin vb.commandbutton cmdok
caption = “ok”
height = 495
left = 360
tabindex = 0
top = 2400
width = 1215
end
end
attribute vb_name = “frmmain”
attribute vb_globalnamespace = false
attribute vb_creatable = false
attribute vb_predeclaredid = true
attribute vb_exposed = false
option explicit
dim dx as new directx7
dim ds as directsound
dim dsb as directsoundbuffer
dim dsbd as dsbufferdesc
dim wf as waveformatex
dim bplaying as boolean
dim bcontinue as boolean
dim endevent as long
implements directxevent
private sub cmdenum_click()
dim de as directsoundenum
dim i as integer
set de = dx.getdsenum
for i = 1 to de.getcount
txtlog.text = txtlog.text & de.getguid(i) & ” ” & de.getname(i) & ” ” & de.getdescription(i) & vbcrlf
next
set de = nothing
end sub
private sub cmdgetinfo_click()
dim s as string
dim l as long
dim status as integer
dim t as xa_inputmodule
dim d as xa_decoderinfo
dim dp as long
dim opbi as xa_outputbufferinfo
dim i as long
dp = varptr(d)
status = decoder_new(varptr(dp))
if status <> xa_success then
msgbox “can not create decoder!”
exit sub
end if
copymemory varptr(d), dp, 60
status = file_input_module_register(t)
status = decoder_input_module_register(d, t)
if status <> xa_success then msgbox xaudio_error_string(status)
status = decoder_input_new(d, app.path & “\3.mp3”, xa_decoder_input_autoselect)
if status <> xa_success then
msgbox “can not create input!” & status & vbcrlf & xaudio_error_string(status)
exit sub
end if
status = decoder_input_open(d)
if status <> xa_success then
msgbox “can not open input!” & vbcrlf & xaudio_error_string(status)
exit sub
end if
dim mp3info as mp3infotype
dim l1 as long, l2 as long
dim l3 as single
do
doevents
status = decoder_decode(d, 0)
copymemory varptr(opbi), d.addr06, len(opbi)
with mp3info.waveformat
.bitspersample = opbi.bytes_per_sample * 8
.channels = 2 ^ opbi.stereo
.samplespersec = opbi.sample_rate
end with
l1 = l1 + 1
l2 = l2 + opbi.size
l3 = l3 + opbi.size / (opbi.sample_rate * ((2 ^ opbi.stereo) * opbi.bytes_per_sample))
loop while status = xa_success or status = xa_error_timeout or status = xa_error_invalid_frame
with mp3info
.frames = l1
.bytelength = l2
.secondlength = l3
end with
msgbox “frames: ” & mp3info.frames & vbcrlf & “bytes: ” & mp3info.bytelength & vbcrlf & “seconds: ” & mp3info.secondlength
l = xaudio_get_api_version(xa_api_id_sync)
msgbox “xaudio dll version: ” & ((l \ (2 ^ 16)) and &h255) & “.” & ((l \ (2 ^ 8)) and &h255) & “.” & (l and &h255)
end sub
private sub cmdgettag_click()
dim fp as integer
dim mp3tag as id3v1
dim songtype() as string
songtype = split(loadresstring(1001), “;”)
fp = freefile
open app.path & “\4.mp3” for binary as #fp
seek #fp, filelen(app.path & “\4.mp3”) – 127
get #fp, , mp3tag
close #fp
msgbox rtrim(mp3tag.title) & vbcrlf & rtrim(mp3tag.artist) & vbcrlf & rtrim(mp3tag.album) & _
vbcrlf & rtrim(mp3tag.year) & vbcrlf & rtrim(mp3tag.comment)
end sub
private sub cmdok_click()
dim s as string
dim l as long
dim status as integer
dim t as xa_inputmodule
dim d as xa_decoderinfo
dim dp as long
dim opbi as xa_outputbufferinfo
dim i as long
dp = varptr(d)
status = decoder_new(varptr(dp))
if status <> xa_success then
msgbox “can not create decoder!”
exit sub
end if
copymemory varptr(d), dp, 60
status = file_input_module_register(t)
status = decoder_input_module_register(d, t)
if status <> xa_success then msgbox xaudio_error_string(status)
status = decoder_input_new(d, app.path & “\3.mp3”, xa_decoder_input_autoselect)
if status <> xa_success then
msgbox “can not create input!” & status & vbcrlf & xaudio_error_string(status)
exit sub
end if
status = decoder_input_open(d)
if status <> xa_success then
msgbox “can not open input!” & vbcrlf & xaudio_error_string(status)
exit sub
end if
set ds = dx.directsoundcreate(vbnullstring)
ds.setcooperativelevel me.hwnd, dsscl_priority
dim sb(100000000) as byte
dim psa(0) as dsbpositionnotify
redim sb(0)
do
doevents
status = decoder_decode(d, 0)
copymemory varptr(opbi), d.addr06, len(opbi)
redim preserve sb(i + opbi.size)
copymemory varptr(ubound(sb) – opbi.size), opbi.pcm_samples, opbi.size
copymemory varptr(sb(i)), opbi.pcm_samples, opbi.size
i = i + opbi.size
loop while status = xa_success or status = xa_error_timeout or status = xa_error_invalid_frame
dsbd.lflags = dsbcaps_ctrlvolume or dsbcaps_static or dsbcaps_ctrlpositionnotify
dsbd.lbufferbytes = i
wf = makewaveex(opbi.sample_rate, 2 ^ opbi.stereo, opbi.bytes_per_sample * 8)
set dsb = ds.createsoundbuffer(dsbd, wf)
dsb.writebuffer 0, i, sb(0), dsblock_default
dsb.setvolume 0
dx.setevent endevent
psa(0).heventnotify = endevent
psa(0).loffset = i – 1
dsb.setnotificationpositions 1, psa()
dsb.play dsbplay_default
bcontinue = true
l = xaudio_get_api_version(xa_api_id_sync)
msgbox “xaudio dll version: ” & ((l \ (2 ^ 16)) and &h255) & “.” & ((l \ (2 ^ 8)) and &h255) & “.” & (l and &h255)
end sub
private sub cmdplay_click()
dim s as string
dim l as long
dim status as integer
dim t as xa_inputmodule
dim d as xa_decoderinfo
dim dp as long
dim opbi as xa_outputbufferinfo
dim i as long
dp = varptr(d)
status = decoder_new(varptr(dp))
if status <> xa_success then
msgbox “can not create decoder!”
exit sub
end if
copymemory varptr(d), dp, 60
status = file_input_module_register(t)
status = decoder_input_module_register(d, t)
if status <> xa_success then msgbox xaudio_error_string(status)
status = decoder_input_new(d, app.path & “\4.mp3”, xa_decoder_input_autoselect)
if status <> xa_success then
msgbox “can not create input!” & status & vbcrlf & xaudio_error_string(status)
exit sub
end if
status = decoder_input_open(d)
if status <> xa_success then
msgbox “can not open input!” & vbcrlf & xaudio_error_string(status)
exit sub
end if
set ds = dx.directsoundcreate(vbnullstring)
ds.setcooperativelevel me.hwnd, dsscl_priority
dim sb(5000000) as byte
dim psa(0) as dsbpositionnotify
bplaying = false
do
doevents
status = decoder_decode(d, 0)
copymemory varptr(opbi), d.addr06, len(opbi)
if i + opbi.size > 5000000 then
do while bplaying
doevents
loop
dsbd.lflags = dsbcaps_ctrlvolume or dsbcaps_static or dsbcaps_ctrlpositionnotify or dsbcaps_globalfocus
dsbd.lbufferbytes = i
wf = makewaveex(opbi.sample_rate, 2 ^ opbi.stereo, opbi.bytes_per_sample * 8)
set dsb = ds.createsoundbuffer(dsbd, wf)
dsb.writebuffer 0, i, sb(0), dsblock_default
dsb.setvolume 0
dx.setevent endevent
psa(0).heventnotify = endevent
psa(0).loffset = i – 1
dsb.setnotificationpositions 1, psa()
dsb.play dsbplay_default
bcontinue = true
bplaying = true
i = 0
end if
copymemory varptr(sb(i)), opbi.pcm_samples, opbi.size
i = i + opbi.size
loop while status = xa_success or status = xa_error_timeout or status = xa_error_invalid_frame
dsbd.lflags = dsbcaps_ctrlvolume or dsbcaps_static or dsbcaps_ctrlpositionnotify or dsbcaps_globalfocus
dsbd.lbufferbytes = i
wf = makewaveex(opbi.sample_rate, 2 ^ opbi.stereo, opbi.bytes_per_sample * 8)
set dsb = ds.createsoundbuffer(dsbd, wf)
dsb.writebuffer 0, i, sb(0), dsblock_default
dsb.setvolume 0
dx.setevent endevent
psa(0).heventnotify = endevent
psa(0).loffset = i – 1
dsb.setnotificationpositions 1, psa()
dsb.play dsbplay_default
bcontinue = true
bplaying = true
end sub
private sub form_load()
endevent = dx.createevent(me)
end sub
private sub form_queryunload(cancel as integer, unloadmode as integer)
if endevent then dx.destroyevent endevent
if not dsb is nothing then dsb.stop
bplaying = false
set dsb = nothing
set ds = nothing
set dx = nothing
end
end sub
private function makewaveex(hz as long, channels as integer, bits as integer) as waveformatex
makewaveex.lsamplespersec = hz
makewaveex.lextra = 0
makewaveex.nsize = 0
makewaveex.nbitspersample = bits
makewaveex.nchannels = channels
makewaveex.nformattag = wave_format_pcm
makewaveex.nblockalign = channels * bits \ 8
makewaveex.lavgbytespersec = hz * (channels * bits \ 8)
end function
private sub directxevent_dxcallback(byval eventid as long)
if bcontinue then bcontinue = false: exit sub
bplaying = false
end sub
modxaudio.bas
attribute vb_name = “modxaudio”
option explicit
/*****************************************************************
|
| xaudio general definitions
|
| (c) 1996-1998 mpegtv, llc
| author: gilles boccon-gibod (gilles@mpegtv.com)
|
****************************************************************/
/*———————————————————————-
| types
+———————————————————————*/
typedef void (*xa_progressnotificationfunction)(void *client,
int source,
int code,
long value,
const char *message);
typedef void (*xa_debugnotificationfunction)(void *client,
int source,
int level,
const char *message,
const char *reason);
typedef void (*xa_errornotificationfunction)(void *client,
int source,
int code,
const char *message,
const char *reason);
public type xa_notificationclient
void *client;
xa_progressnotificationfunction notify_progress;
xa_debugnotificationfunction notify_debug;
xa_errornotificationfunction notify_error;
addr01 as long
addr02 as long
addr03 as long
addr04 as long
end type
#define xa_notify_progress(_client, _source, _code, _value, _message) \
if ((_client) && (_client)->notify_progress) \
(*(_client)->notify_progress)((_client)->client, \
_source, _code, _value, _message)
#define xa_notify_debug(_client, _source, _level, _message, _reason) \
if ((_client) && (_client)->notify_debug) \
(*(_client)->notify_debug)((_client)->client, \
_source, _level, _message, _reason)
#define xa_notify_error(_client, _source, _code, _message, _reason) \
if ((_client) && (_client)->notify_error) \
(*(_client)->notify_error)((_client)->client, \
_source, _code, _message, _reason)
/*———————————————————————-
| apis
+———————————————————————*/
public const xa_api_id_sync = 1
public const xa_api_id_async = 2
/*———————————————————————-
| error codes
+———————————————————————*/
public const xa_success = (0)
public const xa_failure = (-1)
/* general error codes */
public const xa_error_base_general = (-100)
public const xa_error_out_of_memory = (xa_error_base_general – 0)
public const xa_error_invalid_parameters = (xa_error_base_general – 1)
public const xa_error_internal = (xa_error_base_general – 2)
public const xa_error_timeout = (xa_error_base_general – 3)
public const xa_error_version_expired = (xa_error_base_general – 4)
/* network error codes */
public const xa_error_base_network = (-200)
public const xa_error_connect_timeout = (xa_error_base_network – 0)
public const xa_error_connect_failed = (xa_error_base_network – 1)
public const xa_error_connection_refused = (xa_error_base_network – 2)
public const xa_error_accept_failed = (xa_error_base_network – 3)
public const xa_error_listen_failed = (xa_error_base_network – 4)
public const xa_error_socket_failed = (xa_error_base_network – 5)
public const xa_error_socket_closed = (xa_error_base_network – 6)
public const xa_error_bind_failed = (xa_error_base_network – 7)
public const xa_error_host_unknown = (xa_error_base_network – 8)
public const xa_error_http_invalid_reply = (xa_error_base_network – 9)
public const xa_error_http_error_reply = (xa_error_base_network – 10)
public const xa_error_http_failure = (xa_error_base_network – 11)
public const xa_error_ftp_invalid_reply = (xa_error_base_network – 12)
public const xa_error_ftp_error_reply = (xa_error_base_network – 13)
public const xa_error_ftp_failure = (xa_error_base_network – 14)
/* control error codes */
public const xa_error_base_control = (-300)
public const xa_error_pipe_failed = (xa_error_base_control – 0)
public const xa_error_fork_failed = (xa_error_base_control – 1)
public const xa_error_select_failed = (xa_error_base_control – 2)
public const xa_error_pipe_closed = (xa_error_base_control – 3)
public const xa_error_pipe_read_failed = (xa_error_base_control – 4)
public const xa_error_pipe_write_failed = (xa_error_base_control – 5)
public const xa_error_invalid_message = (xa_error_base_control – 6)
public const xa_error_cirq_full = (xa_error_base_control – 7)
public const xa_error_post_failed = (xa_error_base_control – 8)
/* url error codes */
public const xa_error_base_url = (-400)
public const xa_error_url_unsupported_scheme = (xa_error_base_url – 0)
public const xa_error_url_invalid_syntax = (xa_error_base_url – 1)
/* i/o error codes */
public const xa_error_base_io = (-500)
public const xa_error_open_failed = (xa_error_base_io – 0)
public const xa_error_close_failed = (xa_error_base_io – 1)
public const xa_error_read_failed = (xa_error_base_io – 2)
public const xa_error_write_failed = (xa_error_base_io – 3)
public const xa_error_permission_denied = (xa_error_base_io – 4)
public const xa_error_no_device = (xa_error_base_io – 5)
public const xa_error_ioctl_failed = (xa_error_base_io – 6)
public const xa_error_module_not_found = (xa_error_base_io – 7)
public const xa_error_unsupported_input = (xa_error_base_io – 8)
public const xa_error_unsupported_output = (xa_error_base_io – 9)
public const xa_error_unsupported_format = (xa_error_base_io – 10)
public const xa_error_device_busy = (xa_error_base_io – 11)
public const xa_error_no_such_device = (xa_error_base_io – 12)
public const xa_error_no_such_file = (xa_error_base_io – 13)
public const xa_error_input_eof = (xa_error_base_io – 14)
/* bitstream error codes */
public const xa_error_base_bitstream = (-600)
public const xa_error_invalid_frame = (xa_error_base_bitstream – 0)
/* dynamic linking error codes */
public const xa_error_base_dynlink = (-700)
public const xa_error_dll_not_found = (xa_error_base_dynlink – 0)
public const xa_error_symbol_not_found = (xa_error_base_dynlink – 1)
/* environment variables error codes */
public const xa_error_base_environment = (-800)
public const xa_error_no_such_environment = (xa_error_base_environment – 0)
public const xa_error_environment_type_mismatch = (xa_error_base_environment – 1)
moddecoder.bas
attribute vb_name = “moddecoder”
option explicit
public const xa_decoder_input_seekable = &h1
public const xa_decoder_device_has_master_level_control = &h1
public const xa_decoder_device_has_pcm_level_control = &h2
public const xa_decoder_device_has_balance_control = &h4
public const xa_decoder_device_has_line_out = &h8
public const xa_decoder_device_has_speaker_out = &h10
public const xa_decoder_device_has_headphone_out = &h20
public const xa_decoder_device_has_08_000_khz = &h40
public const xa_decoder_device_has_11_025_khz = &h80
public const xa_decoder_device_has_12_000_khz = &h100
public const xa_decoder_device_has_16_000_khz = &h200
public const xa_decoder_device_has_22_050_khz = &h400
public const xa_decoder_device_has_24_000_khz = &h800
public const xa_decoder_device_has_32_000_khz = &h1000
public const xa_decoder_device_has_44_100_khz = &h2000
public const xa_decoder_device_has_48_000_khz = &h4000
public const xa_decoder_device_has_8_bits = &h8000
public const xa_decoder_device_has_mu_law = &h10000
public const xa_decoder_device_has_16_bits = &h20000
public const xa_decoder_device_has_mute = &h40000
public const xa_decoder_device_has_reset = &h80000
public const xa_decoder_device_has_pause = &h100000
public const xa_decoder_device_has_drain = &h200000
public const xa_decoder_device_has_buffer_status = &h400000
public const xa_decoder_device_frequencies_offset = 6
public const xa_decoder_device_frequencies_mask = &h1ff
public const xa_decoder_control_bps = &h1
public const xa_decoder_control_stereo = &h2
public const xa_decoder_control_sample_rate = &h4
public const xa_decoder_control_master_level = &h8
public const xa_decoder_control_pcm_level = &h10
public const xa_decoder_control_balance = &h20
public const xa_decoder_control_ports = &h40
public const xa_decoder_control_all_info = &h7f
public const xa_decoder_control_mute = &h80
public const xa_decoder_control_unmute = &h100
public const xa_decoder_control_reset = &h200
public const xa_decoder_control_pause = &h400
public const xa_decoder_control_restart = &h800
public const xa_decoder_control_drain = &h1000
public const xa_decoder_control_output_line = &h1
public const xa_decoder_control_output_speaker = &h2
public const xa_decoder_control_output_headphone = &h4
public const xa_decoder_environment_max_name_length = 256
public const xa_decoder_environment_max_string_length = 1024
public const xa_decoder_input_query_module_name = &h1
public const xa_decoder_input_query_nb_devices = &h2
public const xa_decoder_input_query_device_name = &h4
public const xa_decoder_input_query_name_is_generic = &h1
public const xa_decoder_input_query_device_is_default = &h2
public const xa_decoder_output_query_module_name = &h1
public const xa_decoder_output_query_nb_devices = &h2
public const xa_decoder_output_query_device_name = &h4
public const xa_decoder_output_query_name_is_generic = &h1
public const xa_decoder_output_query_device_is_default = &h2
public const xa_decoder_output_query_device_is_shareable = &h4
public const xa_decoder_max_name_length = 255
public const xa_decoder_max_description_length = 255
public const xa_decoder_input_autoselect = -1
public const xa_decoder_output_autoselect = -1
public const xa_decoder_input_filter_first = -1
public const xa_decoder_input_filter_last = 0
public const xa_decoder_input_filter_by_name = -2
public const xa_decoder_output_filter_first = -1
public const xa_decoder_output_filter_last = 0
public const xa_decoder_output_filter_by_name = -2
public const xa_timecode_fractions_per_second = 100
public const xa_timecode_fractions_per_minute = (100 * 60)
public const xa_timecode_fractions_per_hour = 360000
public const xa_decoder_codec_quality_high = 0
public const xa_decoder_codec_quality_medium = 1
public const xa_decoder_codec_quality_low = 2
public const xa_decoder_equalizer_nb_bands = 32
public const xa_decoder_feedback_nb_bands = 32
/*———————————————————————-
| types
+———————————————————————*/
typedef void (*xa_environmentcallback)(void *listener,
const char *name,
void *value);
public type xa_timecode
h as integer
m as integer
s as integer
f as integer
end type
public type xa_absolutetime
seconds as long
microseconds as long
end type
public enum xa_iostate
xa_io_state_closed = 0
xa_io_state_open
end enum
public type xa_inputstreaminfo
changed as integer
level as integer
layer as integer
bitrate as integer
frequency as integer
mode as integer
end type
public type xa_inputmodulequery
index as integer
flags as long
name as string * xa_decoder_max_name_length
description as string * xa_decoder_max_description_length
end type
public type xa_inputmoduleclassinfo
id as integer
void *global;
addr01 as long
end type
struct xa_decoderinfo;
public type xa_inputmodule
int (*input_module_probe)(const char *name);
int (*input_module_query)(xa_inputmodulequery *query,
unsigned long query_mask);
int (*input_new)(void **input, const char *name,
xa_inputmoduleclassinfo *class_info,
struct xa_decoderinfo *decoder);
int (*input_delete)(void *input);
int (*input_open)(void *input);
int (*input_close)(void *input);
int (*input_read)(void *input, void *buffer, unsigned long n);
int (*input_seek)(void *input, unsigned long offset);
long (*input_get_caps)(void *input);
long (*input_get_size)(void *input);
int (*input_send_message)(void *input, int type,
const void *data, unsigned int size);
addr01 as long
addr02 as long
addr03 as long
addr04 as long
addr05 as long
addr06 as long
addr07 as long
addr08 as long
addr09 as long
addr10 as long
addr11 as long
end type
struct xa_inputfilternode;
public type xa_inputfilter
const char *(*filter_get_name)(void);
int (*filter_new)(void **filter, int id,
struct xa_decoderinfo *decoder);
int (*filter_delete)(void *filter);
int (*input_open)(struct xa_inputfilternode *node);
int (*input_close)(struct xa_inputfilternode *node);
int (*input_read)(struct xa_inputfilternode *node,
void *buffer, unsigned long n);
int (*input_seek)(struct xa_inputfilternode *node,
unsigned long offset);
long (*input_get_caps)(struct xa_inputfilternode *node);
long (*input_get_size)(struct xa_inputfilternode *node);
int (*input_send_message)(struct xa_inputfilternode *node,
int type, const void *data, unsigned int size);
addr01 as long
addr02 as long
addr03 as long
addr04 as long
addr05 as long
addr06 as long
addr07 as long
addr08 as long
addr09 as long
addr10 as long
end type
public type xa_inputfilternode
id as integer
void *instance;
addr01 as long
vtable as xa_inputfilter
struct xa_inputfilternode *next;
addr02 as long
struct xa_inputfilternode *prev;
addr03 as long
end type
public type xa_inputinfo
state as xa_iostate
caps as long
position as long
size as long
duration as long
void *device;
addr01 as long
const xa_inputmodule *module;
addr02 as long
const char *name;
addr03 as long
end type
public enum xa_outputchannelsmode
xa_output_stereo
xa_output_mono_left
xa_output_mono_right
xa_output_mono_mix
end enum
public type xa_outputfeedbackbands
short left[xa_decoder_feedback_nb_bands];
leftleft(xa_decoder_feedback_nb_bands) as integer
short right[xa_decoder_feedback_nb_bands];
rightright(xa_decoder_feedback_nb_bands) as integer
end type
public type xa_outputbufferinfo
changed as long
short *pcm_samples;
pcm_samples as long
size as long
bytes_per_sample as long
stereo as long
sample_rate as long
delay as long
/*xa_outputfeedbackbands *feedback;*/
end type
public type xa_outputstatus
delay as long
end type
public type xa_outputcontrol
bytes_per_sample as integer
sample_rate as integer
stereo as integer
master_level as integer
pcm_level as integer
balance as integer
ports as integer
end type
public type xa_outputmodulequery
index as integer
flags as long
name as string * xa_decoder_max_name_length
description as string * xa_decoder_max_description_length
end type
public type xa_outputmoduleclassinfo
id as integer
void *global;
addr01 as long
end type
public type xa_outputmodule
int (*output_module_probe)(const char *name);
int (*output_module_query)(xa_outputmodulequery *query,
unsigned long query_mask);
int (*output_new)(void **output, const char *name,
xa_outputmoduleclassinfo *class_info,
struct xa_decoderinfo *decoder);
int (*output_delete)(void *output);
int (*output_open)(void *output);
int (*output_close)(void *output);
int (*output_write)(void *output, void *buffer,
unsigned long size, int bytes_per_sample,
int stereo, int sample_rate);
void* (*output_get_buffer)(void *output, unsigned long size);
int (*output_set_control)(void *output,
xa_outputcontrol *control,
unsigned long flags);
int (*output_get_control)(void *output,
xa_outputcontrol *control,
unsigned long control_mask);
int (*output_get_status)(void *output,
xa_outputstatus *status);
long (*output_get_caps)(void *output);
int (*output_send_message)(void *output, int type,
const void *data, unsigned int size);
addr01 as long
addr02 as long
addr03 as long
addr04 as long
addr05 as long
addr06 as long
addr07 as long
addr08 as long
addr09 as long
addr10 as long
addr11 as long
addr12 as long
addr13 as long
end type
struct xa_outputfilternode;
public type xa_outputfilter
const char *(*filter_get_name)(void);
int (*filter_new)(void **filter, int id,
struct xa_decoderinfo *decoder);
int (*filter_delete)(void *filter);
int (*output_open)(struct xa_outputfilternode *node);
int (*output_close)(struct xa_outputfilternode *node);
int (*output_write)(struct xa_outputfilternode *node,
void *buffer,
unsigned long size, int bytes_per_sample,
int stereo, int sample_rate);
void* (*output_get_buffer)(struct xa_outputfilternode *node,
unsigned long size);
int (*output_set_control)(struct xa_outputfilternode *node,
xa_outputcontrol *control,
unsigned long flags);
int (*output_get_control)(struct xa_outputfilternode *node,
xa_outputcontrol *control,
unsigned long control_mask);
int (*output_get_status)(struct xa_outputfilternode *node,
xa_outputstatus *status);
long (*output_get_caps)(struct xa_outputfilternode *node);
int (*output_send_message)(struct xa_outputfilternode *node,
int type, const void *data, unsigned int size);
addr01 as long
addr02 as long
addr03 as long
addr04 as long
addr05 as long
addr06 as long
addr07 as long
addr08 as long
addr09 as long
addr10 as long
addr11 as long
addr12 as long
end type
public type xa_outputfilternode
id as integer
void *instance;
addr01 as long
vtable as xa_outputfilter
struct xa_outputfilternode *next;
addr02 as long
struct xa_outputfilternode *prev;
addr03 as long
end type
public type xa_outputinfo
state as xa_iostate
caps as long
void *device;
const xa_outputmodule *module;
const char *name;
addr01 as long
addr02 as long
addr03 as long
end type
public type xa_equalizerinfo
signed char left[xa_decoder_equalizer_nb_bands];
signed char right[xa_decoder_equalizer_nb_bands];
leftleft(xa_decoder_equalizer_nb_bands) as integer
rightright(xa_decoder_equalizer_nb_bands) as integer
end type
public type xa_modulesinfo
nb_input_modules as integer
nb_output_modules as integer
end type
public type xa_statusinfo
frame as long
position as single
info as xa_inputstreaminfo
timecode as xa_timecode
end type
struct xa_decoderprivateinfo;
struct xa_decoderinfo;
public type xa_decodercallbacktable
int (xa_export *get_environment_integer)(struct xa_decoderinfo *decoder,
const char *name,
long *value);
int (xa_export *get_environment_string)(struct xa_decoderinfo *decoder,
const char *name,
char *value);
int (xa_export *add_environment_listener)(struct xa_decoderinfo *decoder,
const char *name,
void *client,
xa_environmentcallback callback,
void **handle);
int (xa_export *remove_environment_listener)(struct xa_decoderinfo *decoder,
void *handle);
addr01 as long
addr02 as long
addr03 as long
addr04 as long
end type
public type xa_decoderinfo
const char *name;
xa_inputinfo *input;
xa_outputinfo *output;
xa_modulesinfo *modules;
xa_statusinfo *status;
xa_outputbufferinfo *output_buffer;
addr01 as long
addr02 as long
addr03 as long
addr04 as long
addr05 as long
addr06 as long
notification_client as xa_notificationclient
callbacks as xa_decodercallbacktable
struct xa_decoderprivateinfo *hidden;
addr07 as long
end type
moddeclare.bas
attribute vb_name = “moddeclare”
option explicit
xaudio.h
public declare function xaudio_error_string lib “xaudio.dll” (byval code as integer) as string
public declare function xaudio_get_api_version lib “xaudio.dll” (byval api_id as long) as long
audio_output.h
public declare function audio_output_module_register lib “xaudio.dll” (module as xa_outputmodule) as integer
public declare function dsound_output_module_register lib “xaudio.dll” (module as xa_outputmodule) as integer
file_input.h
public declare function file_input_module_register lib “xaudio.dll” (module as xa_inputmodule) as integer
file_output.h
public declare function file_output_module_register lib “xaudio.dll” (module as xa_outputmodule) as integer
memory_input.h
public declare function memory_input_feed lib “xaudio.dll” (byval devicepointer as long, byval datapointer as long, byval nb_bytes as long) as integer
public declare function memory_input_flush lib “xaudio.dll” (byval devicepointer as long) as integer
public declare function memory_input_module_register lib “xaudio.dll” (module as xa_inputmodule) as integer
stream_input.h
public declare function stream_input_module_register lib “xaudio.dll” (module as xa_inputmodule) as integer
decoder.h
char* xa_export decoder_version(char **major, char **minor, char **state);
public declare function decoder_new lib “xaudio.dll” (byval decoderpp as long) as integer
public declare function decoder_delete lib “xaudio.dll” (decoder as xa_decoderinfo) as integer
public declare function decoder_input_module_register lib “xaudio.dll” (decoder as xa_decoderinfo, module as xa_inputmodule) as integer
int xa_export decoder_input_module_query(xa_decoderinfo *decoder,
int module,
xa_inputmodulequery *query,
unsigned long query_flags);
int xa_export decoder_input_add_filter(xa_decoderinfo *decoder,
const xa_inputfilter *filter,
int where);
int xa_export decoder_input_remove_filter(xa_decoderinfo *decoder,
const char *name, int id);
int xa_export decoder_input_filters_list(xa_decoderinfo *decoder,
void *client,
void (*callback)
(void *client,
xa_inputfilternode *node));
public declare function decoder_input_new lib “xaudio.dll” (decoder as xa_decoderinfo, byval name as string, byval module as integer) as integer
int xa_export decoder_input_delete(xa_decoderinfo *decoder);
public declare function decoder_input_open lib “xaudio.dll” (decoder as xa_decoderinfo) as integer
int xa_export decoder_input_close(xa_decoderinfo *decoder);
int xa_export decoder_input_read(xa_decoderinfo *decoder,
void *buffer, int size);
int xa_export decoder_input_seek_to_offset(xa_decoderinfo *decoder,
unsigned long offset);
int xa_export decoder_input_seek_to_position(xa_decoderinfo *decoder,
float position);
int xa_export decoder_input_seek_to_time(xa_decoderinfo *decoder,
float seconds);
int xa_export decoder_input_seek_to_timecode(xa_decoderinfo *decoder,
const xa_timecode *timecode);
int xa_export decoder_input_send_message(xa_decoderinfo *decoder,
int type,
const void *data,
unsigned int size);
int xa_export decoder_output_module_register(xa_decoderinfo *decoder,
const xa_outputmodule *module);
int xa_export decoder_output_module_query(xa_decoderinfo *decoder,
int module,
xa_outputmodulequery *query,
unsigned long query_flags);
int xa_export decoder_output_add_filter(xa_decoderinfo *decoder,
const xa_outputfilter *filter,
int where);
int xa_export decoder_output_remove_filter(xa_decoderinfo *decoder,
const char *name, int id);
int xa_export decoder_output_filters_list(xa_decoderinfo *decoder,
void *client,
void (*callback)
(void *client,
xa_outputfilternode *node));
int xa_export decoder_output_new(xa_decoderinfo *decoder,
const char *name, int module);
int xa_export decoder_output_delete(xa_decoderinfo *decoder);
int xa_export decoder_output_open(xa_decoderinfo *decoder);
int xa_export decoder_output_close(xa_decoderinfo *decoder);
int xa_export decoder_output_write(xa_decoderinfo *decoder, void *buffer,
unsigned long size,
int bytes_per_sample,
int stereo, int sample_rate);
int xa_export decoder_output_set_control(xa_decoderinfo *decoder,
xa_outputcontrol *control,
unsigned long control_flags);
int xa_export decoder_output_get_control(xa_decoderinfo *decoder,
xa_outputcontrol *control,
unsigned long control_flags);
int xa_export decoder_output_send_message(xa_decoderinfo *decoder,
int type,
const void *data,
unsigned int size);
int xa_export decoder_codec_set_channels(xa_decoderinfo *decoder,
xa_outputchannelsmode channels);
int xa_export decoder_codec_get_channels(xa_decoderinfo *decoder);
int xa_export decoder_codec_set_quality(xa_decoderinfo *decoder,
unsigned int quality);
int xa_export decoder_codec_get_quality(xa_decoderinfo *decoder);
int xa_export decoder_codec_set_equalizer(xa_decoderinfo *decoder,
xa_equalizerinfo *equalizer);
int xa_export decoder_codec_get_equalizer(xa_decoderinfo *decoder,
xa_equalizerinfo *equalizer);
int xa_export decoder_codec_enable_feedback(xa_decoderinfo *decoder);
int xa_export decoder_codec_disable_feedback(xa_decoderinfo *decoder);
int xa_export decoder_set_environment_integer(xa_decoderinfo *decoder,
const char *name,
long value);
int xa_export decoder_get_environment_integer(xa_decoderinfo *decoder,
const char *name,
long *value);
int xa_export decoder_set_environment_string(xa_decoderinfo *decoder,
const char *name,
const char *value);
int xa_export decoder_get_environment_string(xa_decoderinfo *decoder,
const char *name,
char *value);
int xa_export decoder_unset_environment(xa_decoderinfo *decoder,
const char *name);
int xa_export decoder_add_environment_listener(xa_decoderinfo *decoder,
const char *name,
void *client,
xa_environmentcallback callback,
void **handle);
int xa_export decoder_remove_environment_listener(xa_decoderinfo *decoder,
void *handle);
public declare function decoder_decode lib “xaudio.dll” (decoder as xa_decoderinfo, byval output_buffer_pointer as long) as integer
public declare function decoder_play lib “xaudio.dll” (decoder as xa_decoderinfo) as integer
public declare sub copymemory lib “kernel32” alias “rtlmovememory” (byval hpvdest as long, byval hpvsource as long, byval cbcopy as long)
public declare function globalalloc lib “kernel32” (byval wflags as long, byval dwbytes as long) as long
public declare function globalfree lib “kernel32” (byval hmem as long) as long
public declare sub fillmemory lib “kernel32.dll” alias “rtlfillmemory” (byval destination as long, byval length as long, byval fill as byte)
public const gmem_fixed = &h0
public type id3v1
header as string * 3 /*标签头必须是”tag”否则认为没有标签*/
title as string * 30 /*标题*/
artist as string * 30 /*作者*/
album as string * 30 /*专集*/
year as string * 4 /*出品年代*/
comment as string * 30 /*备注*/
genre as byte
end type
public type waveformattype
samplespersec as long
bitspersample as long
channels as long
end type
public type mp3infotype
frames as long
bytelength as long
secondlength as long
waveformat as waveformattype
end type