我正在尝试在Win10下使用XAudio2制作音乐播放器,这是当前代码:
from ctypes import Structure, POINTER, windll, byref, memset, sizeof, pointer, wintypes
from ctypes import c_void_p, c_uint, c_char, c_long
from ctypes.wintypes import DWORD, WORD, BYTE
XAUDIO2_DEFAULT_PROCESSOR = 1
def init():
class XAUDIO2_EFFECT_DESCRIPTOR(Structure):
_fields_ = ( ( 'pEffect', c_void_p),
( 'InitialState', BYTE),
( 'OutputChannels', DWORD) )
class XAUDIO2_EFFECT_CHAIN(Structure):
_fields_ = ( ( 'EffectCount', DWORD),
( 'pEffectDescriptors', POINTER(XAUDIO2_EFFECT_DESCRIPTOR) ) )
lib = windll.LoadLibrary('XAudio2_9.dll')
print(lib)
func = lib['XAudio2Create']
print(func)
ppXAudio2 = c_void_p()
print(ppXAudio2)
res = lib.XAudio2Create(byref(ppXAudio2), 0, XAUDIO2_DEFAULT_PROCESSOR)
if res:
print("XAudio2Create err: ", res)
return
else:
print(ppXAudio2)
ppMasteringVoice = c_void_p()
InputChannels = 2
InputSampleRate = 44100
effect = XAUDIO2_EFFECT_DESCRIPTOR()
memset(byref(effect),0,sizeof(effect))
effect.pEffect = c_void_p()
effect.InitialState = 0
effect.OutputChannels = 1
pEffectChain = XAUDIO2_EFFECT_CHAIN()
memset(byref(pEffectChain),0,sizeof(pEffectChain))
pEffectChain.EffectCount = 0
pEffectChain.pEffectDescriptors = pointer(effect)
res = ppXAudio2.CreateMasteringVoice( byref(ppMasteringVoice), InputChannels, InputSampleRate,
0, 0, byref(pEffectChain), 0 )
下面是我得到的输出,我想我需要将ppXAudio2转换为XAudio2实例的类型,但是我不确定如何:
WinDLL'XAudio2_9.dll',在0x224b7068160处处理7fffcc620000
_FuncPtr对象位于0x00000224B5150C78
c_void_p(无)
c_void_p(2356714864784)
AttributeError:'c_void_p'对象没有属性'CreateMasteringVoice'