Christian_Wiehl
asked on
WaveOut API
Hi, I'm working in VB4 / VB5 and want to make a program that will play WAV files to a specific sound card (i hopefully wanna have a combo box that'll let the user choose which card they want it to go to), and let you pause, seek, change the pitch and the volume, etc, you know, basically make use of the WaveOut API functions, but I have absolutely NO clue how to use them, and all the stuff from MS that I found on it was in C. Does anybody have any idea how to use these functions? Like WaveOutOpen and WaveOutPitch and stuff? If anybody has any VB specific docs on them, or any source code, could you PLEASE post it? I'm rippping my hair out trying to figure this stuff out!
All the declarations are in the Win32API as they are needed for VB. Basically, it looks like your biggest hurdle is getting the handle to the device. I don't see any function off hand to get that. However, you might get a better response to your question if you posted a few specific API calls that you need. I have the C documentation, and can translate them into VB, but that's quite a few calls, and I really don't have time to do them all.
ASKER
Thanks for responding dirtdart... here are the functions that I was interested in, if you translate them to VB and put them in an "answer," I'll give you the points. :-)
WaveOutOpen
WaveOutPitch
WaveOutWrite
WaveOutPause
WaveOutRestart
WaveOutGet/SetPosition
WaveOutClose
WaveOutGetID
WaveOutGetNumDevs
WaveOutPrepareHeader
WaveOutUnPrepareHeader
sorry it's so many... But thanks a lot!!!
WaveOutOpen
WaveOutPitch
WaveOutWrite
WaveOutPause
WaveOutRestart
WaveOutGet/SetPosition
WaveOutClose
WaveOutGetID
WaveOutGetNumDevs
WaveOutPrepareHeader
WaveOutUnPrepareHeader
sorry it's so many... But thanks a lot!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, I changed my mind. I can still send you the file if you need, but here it is:
Declare Function waveOutOpen Lib "winmm.dll" Alias "waveOutOpen" (lphWaveOut As Long, ByVal uDeviceID As Long, lpFormat As WAVEFORMAT, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Declare Function waveOutWrite Lib "winmm.dll" Alias "waveOutWrite" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveOutPause Lib "winmm.dll" Alias "waveOutPause" (ByVal hWaveOut As Long) As Long
Declare Function waveOutRestart Lib "winmm.dll" Alias "waveOutRestart" (ByVal hWaveOut As Long) As Long
Declare Function waveOutSetPitch Lib "winmm.dll" Alias "waveOutSetPitch" (ByVal hWaveOut As Long, ByVal dwPitch As Long) As Long
Declare Function waveOutGetPosition Lib "winmm.dll" Alias "waveOutGetPosition" (ByVal hWaveOut As Long, lpInfo As MMTIME, ByVal uSize As Long) As Long
Declare Function waveOutClose Lib "winmm.dll" Alias "waveOutClose" (ByVal hWaveOut As Long) As Long
Declare Function waveOutGetID Lib "winmm.dll" Alias "waveOutGetID" (ByVal hWaveOut As Long, lpuDeviceID As Long) As Long
Declare Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Long
Declare Function waveOutPrepareHeader Lib "winmm.dll" Alias "waveOutPrepareHeader" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveOutUnprepareHeader Lib "winmm.dll" Alias "waveOutUnprepareHeader" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
WaveOutOpen: lphWaveOut is a handle to a wave device. uDeviceID is the device ID of the device, or WAVE_MAPPER (Public Const WAVE_MAPPER = -1&) to let the function choose a device. lpFormat is a WAVEFORMAT structure (see below). dwCallBack specifies a callback function for use with this function. It is probably best to just set this to 0 and not mess with callbacks. They can get pretty complicated. dwInstance can also be left alone whether you are using callbacks or not. dwFlags tells how to open the device. It should be WAVE_ALLOWSYNC (Public Const WAVE_ALLOWSYNC = &H2) if you are opening a syncronous device, or WAVE_FORMAT_DIRECT (Public Const WAVE_FORMAT_DIRECT = &H8) if not.
Type WAVEFORMAT
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
End Type
wFormatTag is an integer value that specifies what format the wave is. This should probably be set to Public Const WAVE_FORMAT_PCM = 1 . If you use anything else, you are going to have to have a lot of manufactuer’s specifications to work with.
nChannels is the number of channels on the device. Mono is one, and setero is two.
nSamplesPerSec - Sample rate, in samples per second (hertz), that each channel should be played or recorded. If wFormatTag is WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz. For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag.
nAvgBytesPerSec - Required average data-transfer rate, in bytes per second, for the format tag. If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec should be equal to the product of nSamplesPerSec and nBlockAlign. For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag
nBlockAlign - Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, nBlockAlign should be equal to the product of nChannels and wBitsPerSample divided by 8 (bits per byte). For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag.
WaveOutPitch – This is not a call that I can find, even in the Win32SDK. However, I did find WaveOutSetPitch, and will provide the code for it.
WaveOutSetPitch – hWaveOut is the handle to the wave device. dwPitch is how much the pitch should be adjusted. This has to be a positive value.
WaveOutWrite – hWaveOut is the handle to the Wave Device. lpWaveOutHdr is a WAVEHDR structure that describes the wave buffer. uSize is the size of the WAVEHDR structure. You can get this by using Len(lpWaveOutHdr).
Type WAVEHDR
lpData As String
dwBufferLength As Long
dwBytesRecorded As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long
Reserved As Long
End Type
lpData is the buffer. This should be set large enough to hold a return value before the call. You can do this by lpData = Space(255). dwBufferLength is the length of the buffer. In this case, 255. dwBytesRecorded specifies how many bytes are in the buffer if the header is being used for input. dwUser is user data. I can’t find documentation on this, but I don’t think it’s actually used for anything by the call.
dwFlags - Flags supplying information about the buffer. The following values are defined:
WHDR_BEGINLOOP (Public Const WHDR_BEGINLOOP = &H4)
This buffer is the first buffer in a loop. This flag is used only with output buffers.
WHDR_DONE (Public Const WHDR_DONE = &H1)
Set by the device driver to indicate that it is finished with the buffer and is returning it to the application.
WHDR_ENDLOOP (Public Const WHDR_ENDLOOP = &H8)
This buffer is the last buffer in a loop. This flag is used only with output buffers.
WHDR_INQUEUE (Public Const WHDR_INQUEUE = &H10)
Set by Windows to indicate that the buffer is queued for playback.
WHDR_PREPARED (Public Const WHDR_INQUEUE = &H10)
Set by Windows to indicate that the buffer has been prepared with the waveInPrepareHeader or waveOutPrepareHeader function.
dwLoops is the number of times to play the loop. It is only used with output buffers. lpNext and Reserved are both reserved values and should be left alone.
WaveOutPause – is quite simple. hWaveOut is simply the handle to the waveform device.
WaveOutRestart – Same as WaveOutPause
WaveOutGetPosition – hWaveOut is the handle to the waveform device. lpInfo is a MMTIME structure, uSize is the size of the MMTIME structure, again, retrieved by Len(lpInfo).
Type MMTIME
wType As Long
u As Long
End Type
wType -
Time format. It can be one of the following values:
TIME_BYTES Current byte offset from beginning of the file.
TIME_MIDI MIDI time.
TIME_MS Time in milliseconds.
TIME_SAMPLES Number of waveform-audio samples.
TIME_SMPTE SMPTE (Society of Motion Picture and Television Engineers) time.
TIME_TICKS Ticks within a MIDI stream.
Public Const TIME_BYTES = &H4
Public Const TIME_MIDI = &H10
Public Const TIME_MS = &H1
Public Const TIME_SAMPLES = &H2
Public Const TIME_SMPTE = &H8
u is the number of counts in the type of time specified.
WaveOutSetPosition – is another call I can’t find any reference to. Nor can I find anything resembling it. Sorry.
WaveOutClose – another simple one requiring only the handle to the device.
WaveOutGetID – hWaveOut is the handle to the device, lpuDeviceID is a long buffer that will receive the device ID when the function returns.
WaveOutGetNumDevs – No parameters involved. Simply returns the number of devices on the machine.
WaveOutPrepareHeader – This gets a header ready for playback. hWaveOut is the handle to the device. lpWaveOutHdr is a WAVEHDR structure (as described above). uSize is the size of the structure (Len(lpWaveOutHdr))
WaveOutUnPrepareHeader – Just cleans up a header set by WaveOutPrepareHeader. Parameters are the same.
Hope this helps you out.
Declare Function waveOutOpen Lib "winmm.dll" Alias "waveOutOpen" (lphWaveOut As Long, ByVal uDeviceID As Long, lpFormat As WAVEFORMAT, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Declare Function waveOutWrite Lib "winmm.dll" Alias "waveOutWrite" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveOutPause Lib "winmm.dll" Alias "waveOutPause" (ByVal hWaveOut As Long) As Long
Declare Function waveOutRestart Lib "winmm.dll" Alias "waveOutRestart" (ByVal hWaveOut As Long) As Long
Declare Function waveOutSetPitch Lib "winmm.dll" Alias "waveOutSetPitch" (ByVal hWaveOut As Long, ByVal dwPitch As Long) As Long
Declare Function waveOutGetPosition Lib "winmm.dll" Alias "waveOutGetPosition" (ByVal hWaveOut As Long, lpInfo As MMTIME, ByVal uSize As Long) As Long
Declare Function waveOutClose Lib "winmm.dll" Alias "waveOutClose" (ByVal hWaveOut As Long) As Long
Declare Function waveOutGetID Lib "winmm.dll" Alias "waveOutGetID" (ByVal hWaveOut As Long, lpuDeviceID As Long) As Long
Declare Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Long
Declare Function waveOutPrepareHeader Lib "winmm.dll" Alias "waveOutPrepareHeader" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveOutUnprepareHeader Lib "winmm.dll" Alias "waveOutUnprepareHeader" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
WaveOutOpen: lphWaveOut is a handle to a wave device. uDeviceID is the device ID of the device, or WAVE_MAPPER (Public Const WAVE_MAPPER = -1&) to let the function choose a device. lpFormat is a WAVEFORMAT structure (see below). dwCallBack specifies a callback function for use with this function. It is probably best to just set this to 0 and not mess with callbacks. They can get pretty complicated. dwInstance can also be left alone whether you are using callbacks or not. dwFlags tells how to open the device. It should be WAVE_ALLOWSYNC (Public Const WAVE_ALLOWSYNC = &H2) if you are opening a syncronous device, or WAVE_FORMAT_DIRECT (Public Const WAVE_FORMAT_DIRECT = &H8) if not.
Type WAVEFORMAT
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
End Type
wFormatTag is an integer value that specifies what format the wave is. This should probably be set to Public Const WAVE_FORMAT_PCM = 1 . If you use anything else, you are going to have to have a lot of manufactuer’s specifications to work with.
nChannels is the number of channels on the device. Mono is one, and setero is two.
nSamplesPerSec - Sample rate, in samples per second (hertz), that each channel should be played or recorded. If wFormatTag is WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz. For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag.
nAvgBytesPerSec - Required average data-transfer rate, in bytes per second, for the format tag. If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec should be equal to the product of nSamplesPerSec and nBlockAlign. For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag
nBlockAlign - Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, nBlockAlign should be equal to the product of nChannels and wBitsPerSample divided by 8 (bits per byte). For non-PCM formats, this member must be computed according to the manufacturer’s specification of the format tag.
WaveOutPitch – This is not a call that I can find, even in the Win32SDK. However, I did find WaveOutSetPitch, and will provide the code for it.
WaveOutSetPitch – hWaveOut is the handle to the wave device. dwPitch is how much the pitch should be adjusted. This has to be a positive value.
WaveOutWrite – hWaveOut is the handle to the Wave Device. lpWaveOutHdr is a WAVEHDR structure that describes the wave buffer. uSize is the size of the WAVEHDR structure. You can get this by using Len(lpWaveOutHdr).
Type WAVEHDR
lpData As String
dwBufferLength As Long
dwBytesRecorded As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long
Reserved As Long
End Type
lpData is the buffer. This should be set large enough to hold a return value before the call. You can do this by lpData = Space(255). dwBufferLength is the length of the buffer. In this case, 255. dwBytesRecorded specifies how many bytes are in the buffer if the header is being used for input. dwUser is user data. I can’t find documentation on this, but I don’t think it’s actually used for anything by the call.
dwFlags - Flags supplying information about the buffer. The following values are defined:
WHDR_BEGINLOOP (Public Const WHDR_BEGINLOOP = &H4)
This buffer is the first buffer in a loop. This flag is used only with output buffers.
WHDR_DONE (Public Const WHDR_DONE = &H1)
Set by the device driver to indicate that it is finished with the buffer and is returning it to the application.
WHDR_ENDLOOP (Public Const WHDR_ENDLOOP = &H8)
This buffer is the last buffer in a loop. This flag is used only with output buffers.
WHDR_INQUEUE (Public Const WHDR_INQUEUE = &H10)
Set by Windows to indicate that the buffer is queued for playback.
WHDR_PREPARED (Public Const WHDR_INQUEUE = &H10)
Set by Windows to indicate that the buffer has been prepared with the waveInPrepareHeader or waveOutPrepareHeader function.
dwLoops is the number of times to play the loop. It is only used with output buffers. lpNext and Reserved are both reserved values and should be left alone.
WaveOutPause – is quite simple. hWaveOut is simply the handle to the waveform device.
WaveOutRestart – Same as WaveOutPause
WaveOutGetPosition – hWaveOut is the handle to the waveform device. lpInfo is a MMTIME structure, uSize is the size of the MMTIME structure, again, retrieved by Len(lpInfo).
Type MMTIME
wType As Long
u As Long
End Type
wType -
Time format. It can be one of the following values:
TIME_BYTES Current byte offset from beginning of the file.
TIME_MIDI MIDI time.
TIME_MS Time in milliseconds.
TIME_SAMPLES Number of waveform-audio samples.
TIME_SMPTE SMPTE (Society of Motion Picture and Television Engineers) time.
TIME_TICKS Ticks within a MIDI stream.
Public Const TIME_BYTES = &H4
Public Const TIME_MIDI = &H10
Public Const TIME_MS = &H1
Public Const TIME_SAMPLES = &H2
Public Const TIME_SMPTE = &H8
u is the number of counts in the type of time specified.
WaveOutSetPosition – is another call I can’t find any reference to. Nor can I find anything resembling it. Sorry.
WaveOutClose – another simple one requiring only the handle to the device.
WaveOutGetID – hWaveOut is the handle to the device, lpuDeviceID is a long buffer that will receive the device ID when the function returns.
WaveOutGetNumDevs – No parameters involved. Simply returns the number of devices on the machine.
WaveOutPrepareHeader – This gets a header ready for playback. hWaveOut is the handle to the device. lpWaveOutHdr is a WAVEHDR structure (as described above). uSize is the size of the structure (Len(lpWaveOutHdr))
WaveOutUnPrepareHeader – Just cleans up a header set by WaveOutPrepareHeader. Parameters are the same.
Hope this helps you out.
ASKER
Thanks a lot!!!! I've still got a couple more questions, but I'll email you on those... Here are your points, you earned em! :D