Страница: 1 |
|
Вопрос: две звуковухи
|
Добавлено: 15.09.08 15:07
|
|
Автор вопроса: litzter
|
Привет. Суть проблемы следующая: имеется две звуковушки(одна интегрированная), нужно посредством скрипта отправить на одну 1.wav, на другую 2.wav. Т.е. в реальности это выглядит как две, скажем, кнопки. И две пары наушников. Нажимая на одну, одна мелодия идет на одни наушники. Нажимая на другую - соответственно на вторые и уже другая мелодия. Я как человек незнакомый с VBA в принципе, научился только проигрываться wav'ы посредством winmm.lib и PlaySound'а. Буду рад любому совету.
Ответить
|
Номер ответа: 2 Автор ответа: litzter
Вопросов: 1 Ответов: 6
|
Профиль | | #2
|
Добавлено: 18.09.08 11:42
|
Причем тут железо. Есть АПИ, есть дескрипторы устройств. Значит к ним можно обратиться, используя функции мультимедийных библиотек. Я все еще мучаюсь с VBA, как с языком, но вот например есть функция - waveOutOpen. The waveOutOpen function opens the given waveform-audio output device for playback.
MMRESULT waveOutOpen(
LPHWAVEOUT phwo,
UINT_PTR uDeviceID,
LPWAVEFORMATEX pwfx,
 WORD_PTR dwCallback,
 WORD_PTR dwCallbackInstance,
 WORD fdwOpen
);
uDeviceID
Identifier of the waveform-audio output device to open. It can be either a device identifier or a handle of an open waveform-audio input device. You can use the following flag instead of a device identifier.
Т.е. это же дескриптор устройства, я правильно понял? Так ведь можно тогда не указывать автовыбор WAVE_MAPPER, а явно, какой девайс нужен. Разные кнопки - разные значения аргументов.
Ответить
|
Номер ответа: 9 Автор ответа: litzter
Вопросов: 1 Ответов: 6
|
Профиль | | #9
|
Добавлено: 19.09.08 15:34
|
-
- Private Type mmioinfo
- dwFlags As Long
- fccIOProc As Long
- pIOProc As Long
- wErrorRet As Long
- htask As Long
- cchBuffer As Long
- pchBuffer As String
- pchNext As String
- pchEndRead As String
- pchEndWrite As String
- lBufOffset As Long
- lDiskOffset As Long
- adwInfo(4) As Long
- dwReserved1 As Long
- dwReserved2 As Long
- hmmio As Long
- End Type
-
- Private Type MMCKINFO
- ckid As Long
- ckSize As Long
- fccType As Long
- dwDataOffset As Long
- dwFlags As Long
- End Type
-
- Private Type WAVEFORMAT
- wFormatTag As Integer
- nChannels As Integer
- nSamplesPerSec As Long
- nAvgBytesPerSec As Long
- nBlockAlign As Integer
- wBitsPerSample As Integer
- cbSize As Integer
- End Type
-
- Private Type WAVEHDR
- lpData As Long
- dwBufferLength As Long
- dwBytesRecorded As Long
- dwUser As Long
- dwFlags As Long
- dwLoops As Long
- lpNext As Long
- Reserved As Long
- End Type
-
-
- Private Declare Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, lpmmioinfo As mmioinfo, ByVal dwOpenFlags As Long) As Long
- Private Declare Function mmioStringToFOURCC Lib "winmm.dll" Alias "mmioStringToFOURCCA" (ByVal sz As String, ByVal uFlags As Long) As Long
- Private Declare Function mmioDescendParent Lib "winmm.dll" Alias "mmioDescend" (ByVal hmmio As Long, lpck As MMCKINFO, ByVal x As Long, ByVal uFlags As Long) As Long
- Private Declare Function mmioDescend Lib "winmm.dll" (ByVal hmmio As Long, lpck As MMCKINFO, lpckParent As MMCKINFO, ByVal uFlags As Long) As Long
- Private Declare Function mmioAscend Lib "winmm.dll" (ByVal hmmio As Long, lpck As MMCKINFO, ByVal uFlags As Long) As Long
- Private Declare Function mmioSeek Lib "winmm.dll" (ByVal hmmio As Long, ByVal lOffset As Long, ByVal iOrigin As Long) As Long
- Private Declare Function mmioRead Lib "winmm.dll" (ByVal hmmio As Long, ByVal pch As Long, ByVal cch As Long) As Long
- Private Declare Function mmioReadString Lib "winmm.dll" Alias "mmioRead" (ByVal hmmio As Long, ByVal pch As String, ByVal cch As Long) As Long
- Private Declare Function waveOutOpen Lib "winmm.dll" (hWaveOut As Long, ByVal uDeviceID As Long, ByVal format As String, ByVal dwCallback As Long, ByRef fPlaying As Boolean, ByVal dwFlags As Long) As Long
- Private Declare Function waveOutGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
- Private Declare Function waveOutPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
- Private Declare Function waveOutUnprepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
- Private Declare Function waveOutWrite Lib "winmm.dll" (ByVal hWaveOut As Long, lpWaveOutHdr As WAVEHDR, ByVal uSize As Long) As Long
- Private Declare Function waveOutClose Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
- Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
- Private Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Long) As Long
- Private Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Long) As Long
- Private Declare Sub CopyStructFromString Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal source As String, ByVal cb As Long)
-
-
-
- Const BUFFER_SECONDS = 0.1
- Const NUM_BUFFERS = 5
- Const MMIO_READ = &H0
- Const MMIO_FINDCHUNK = &H10
- Const CALLBACK_WINDOW = &H10000
- Const MMSYSERR_NOERROR = 0
- Const SEEK_CUR = 1
- Const SEEK_END = 2
- Const SEEK_SET = 0
-
- Dim rc As Long
- Dim hWaveOut As Long
- Dim hmmioIn As Long
- Dim mmioinf As mmioinfo
- Dim mmckinfoParentIn As MMCKINFO
- Dim mmckinfoSubchunkIn As MMCKINFO
- Dim formatBuffer As String * 50
- Dim format As WAVEFORMAT
- Dim dataOffset As Long
- Dim audioLength As Long
- Dim bufferSize As Long
- Dim fPlaying As Boolean
- Dim startPos As Long
- Dim msg As String * 250
- Dim hmem(1 To NUM_BUFFERS) As Long
- Dim pmem(1 To NUM_BUFFERS) As Long
- Dim hdr(1 To NUM_BUFFERS) As WAVEHDR
-
-
- Public Function Play(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByRef wavhdr As WAVEHDR) As Long
-
- Static dataRemaining As Long
-
- If (uMsg = MM_WOM_DONE) Then
- If (fPlaying = True) Then
-
- dataRemaining = (dataOffset + audioLength - mmioSeek(hmmioIn, 0, SEEK_CUR))
-
- If (bufferSize < dataRemaining) Then
- rc = mmioRead(hmmioIn, wavhdr.lpData, bufferSize)
- Else
- rc = mmioRead(hmmioIn, wavhdr.lpData, dataRemaining)
- fPlaying = False
- End If
-
- wavhdr.dwBufferLength = rc
- rc = waveOutWrite(hWaveOut, wavhdr, Len(wavhdr))
- Else
- For i = 1 To NUM_BUFFERS
- waveOutUnprepareHeader hWaveOut, hdr(i), Len(hdr(i))
- Next
-
-
- waveOutClose hWaveOut
- End If
- End If
-
- End Function
-
- Public Function Init(ByVal deviceID As Long)
-
- fPlaying = False
- startPos = 0
-
-
- hmmioIn = mmioOpen("D:\Program Files\QIP\Sounds\sndMsgSent.wav", mmioinf, MMIO_READ)
- If (hmmioIn = Null) Then
- Exit Function
- End If
-
-
- mmckinfoParentIn.fccType = mmioStringToFOURCC("WAVE", 0)
- rc = mmioDescendParent(hmmioIn, mmckinfoParentIn, 0, MMIO_FINDRIFF)
- If (rc <> MMSYSERR_NOERROR) Then
- Exit Function
- End If
-
-
- mmckinfoSubchunkIn.ckid = mmioStringToFOURCC("fmt", 0)
- rc = mmioDescend(hmmioIn, mmckinfoSubchunkIn, mmckinfoParentIn, MMIO_FINDCHUNK)
- If (rc <> MMSYSERR_NOERROR) Then
- Exit Function
- End If
-
- rc = mmioReadString(hmmioIn, formatBuffer, mmckinfoSubchunkIn.ckSize)
- If (rc = -1) Then
- Exit Function
- End If
-
- rc = mmioAscend(hmmioIn, mmckinfoSubchunkIn, 0)
- CopyStructFromString format, formatBuffer, Len(format)
-
-
- mmckinfoSubchunkIn.ckid = mmioStringToFOURCC("data", 0)
- rc = mmioDescend(hmmioIn, mmckinfoSubchunkIn, mmckinfoParentIn, MMIO_FINDCHUNK)
- If (rc <> MMSYSERR_NOERROR) Then
- Exit Function
- End If
-
- dataOffset = mmioSeek(hmmioIn, 0, SEEK_SET)
-
-
- audioLength = mmckinfoSubchunkIn.ckSize
-
-
- bufferSize = format.nSamplesPerSec * format.nBlockAlign * format.nChannels * BUFFER_SECONDS
- bufferSize = bufferSize - (bufferSize Mod format.nBlockAlign)
-
- For i = 1 To (NUM_BUFFERS)
- GlobalFree hmem(i)
- hmem(i) = GlobalAlloc(0, bufferSize)
- pmem(i) = GlobalLock(hmem(i))
- Next
-
-
- rc = waveOutOpen(hWaveOut, deviceID, formatBuffer, hwnd, True, CALLBACK_WINDOW)
- If (rc <> MMSYSERR_NOERROR) Then
- waveOutGetErrorText rc, msg, Len(msg)
- Exit Function
- End If
-
- For i = 1 To NUM_BUFFERS
- hdr(i).lpData = pmem(i)
- hdr(i).dwBufferLength = bufferSize
- hdr(i).dwFlags = 0
- hdr(i).dwLoops = 0
-
- rc = waveOutPrepareHeader(hWaveOut, hdr(i), Len(hdr(i)))
- If (rc <> MMSYSERR_NOERROR) Then
- waveOutGetErrorText rc, msg, Len(msg)
- End If
- Next
-
- fPlaying = True
-
-
- startPos = mmioSeek(hmmioIn, 0, SEEK_CUR) - dataOffset
-
-
- For i = 1 To NUM_BUFFERS
- Play hwnd, MM_WOM_DONE, 0, hdr(i)
- Next
-
- End Function
Вызывать соответственно через Init deviceID. Нумерация с 0. Если звуковухи две штуки, то соответственно диапазон значений 0-1. Комментарии побились, извиняюсь, нет времени поправить, возможно попозже. Как определить, какой идентификатор соответствует какому устройству, незнаю, не стояло такой задачи. Я отловил опытным путем.
Ответить
|
Страница: 1 |
Поиск по форуму