Newsgroup: it.comp.lang.visual-basic
Titolo: [vb6 API] winmm.dll alcune delucidazione

Salve,
Prima di iniziare a postare codice e a parlare della winmm.dll e dei 
metodi waveInxxx
avrei qualche domanda in generale su come viene gestito l'audio su 
windows.
Che cos'è un device?
Una scheda audio o un dispositivo hardware esterno qualunque?
Ad esempio quando attacco lo spinotto esterno del mic come faccio a 
vederlo?
che cos'è una soundcard?
come spieghero dopo nel codice io ottengo come device "sb200" che credo
che stia per "sound blaster" .. che cos'è?
viene rappresentata dal quel mixer nell'applicazione "multimedia" nel 
pannello di controllo?
questa era la confusione che avevo al riguardo (in quanto newbie del 
mondo win come di vb)
Ora avrei alcune domande sui metodi waveInxxx della winmm:
--> waveInGetNumDevs
Ritorna il numero dei "dispositivi" waveIn disponibili
cosa vuol dire "dispositivi" in questo caso? una scheda audio o il mic 
esterno?
[vb]
Private Type WaveInCaps
   ManufacturerID As Integer
   ProductID As Integer
   DriverVersion As Long
   ProductName(1 To 32) As Byte
   Formats As Long
   Channels As Integer
   Reserved As Integer
End Type
Private Declare Function waveInGetNumDevs Lib "winmm" () As Long
Private Declare Function waveInGetDevCaps Lib "winmm" Alias 
"waveInGetDevCapsA" (ByVal uDeviceID As Long, Byval lpCaps As Long, 
ByVal uSize As Long) As Long
sub InitDevices()
   Dim Caps As WaveInCaps, Which As Long, testo As String
   For Which = 0 To waveInGetNumDevs - 1
      Call waveInGetDevCaps(Which, VarPtr(Caps), Len(Caps))
      testo = StrConv(Caps.ProductName, vbUnicode) & Which
      msgbox testo
   Next
 
   If Which = 0 Then
      MsgBox "You have no audio input devices!", vbCritical, "Ack!"
      End
   End If
 
End Sub
[/vb]
eseguendo questo codice ottengo SB200 che dovrebbe essere un valido 
waveIn ...
cos'altro avrei potuto ottenere? waveInGetNumDevs può essere maggiore di 
1?
Ora vi posto tutto il codice che ho messo insieme finora per catturare 
l'audio da mic esterno
anche se ancora non so come e in quale variabile (o descrittore) va a 
finire l'audio...
[vb]
[/vb]
Come ottengo fisicamente l'audio?
Se volessi salvarlo o redirigerlo ad un Socket di tipo server?
(o magari comprimerlo in MP3?)
Grazie a tutti!

scusate .. ecco il codice:
[vb]
'
' waveInGetNumDevs(): Determines the number of audio drivers available 
for input.
' waveInOpen(): Creates an instance of the specified audio device for 
input.
' waveInPrepareHeader(): Prepares a WAVEHDR and data block for input.
' waveInUnprepareHeader(): Releases a previously prepared WAVEHDR and 
data block.
' waveInClose(): Closes the specified instance of the audio device.
' waveInReset(): Stops recording and empties the queue.
' waveInStart(): Starts recording to the queued buffer.
' waveInStop(): Stops recording.
' waveInAddBuffer(): Adds a prepared buffer to the record queue.
' waveInGetDevCaps(): Gets the capabilities of the specified device
'
' WAVEINCAPS: Describes the capabilities of an input device.
'
Option Explicit
Private DevHandle As Long
Private InData(0 To 511) As Byte
Private Type WaveFormatEx
   FormatTag As Integer
   Channels As Integer
   SamplesPerSec As Long
   AvgBytesPerSec As Long
   BlockAlign As Integer
   BitsPerSample As Integer
   ExtraDataSize 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 Type WaveInCaps
   ManufacturerID As Integer
   ProductID As Integer
   DriverVersion As Long
   ProductName(1 To 32) As Byte
   Formats As Long
   Channels As Integer
   Reserved As Integer
End Type
Private Const WAVE_FORMAT_4M16 = &H400& '/* 44.1 kHz, Mono, 6-bit
Private Const WAVE_FORMAT_PCM = 1
Private Declare Function waveInGetNumDevs Lib "winmm" () As Long
Private Declare Function waveInGetDevCaps Lib "winmm" Alias 
"waveInGetDevCapsA" (ByVal uDeviceID As Long, Byval lpCaps As Long, 
ByVal uSize As Long) As Long
Private Declare Function waveInAddBuffer Lib "winmm" (ByVal 
InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal 
WaveHdrStructSize As Long) As Long
Private Declare Function waveInPrepareHeader Lib "winmm" (ByVal 
InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal 
WaveHdrStructSize As Long) As Long
Private Declare Function waveInUnprepareHeader Lib "winmm" (ByVal 
InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal 
WaveHdrStructSize As Long) As Long
Private Declare Function waveInOpen Lib "winmm" (WaveDeviceInputHandle 
As Long, ByVal WhichDevice As Long, ByVal WaveFormatExPointer As Long, 
ByVal CallBack As Long, ByVal CallBackInstance As Long, ByVal Flags As 
Long) As Long
Private Declare Function waveInClose Lib "winmm" (ByVal 
WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInStart Lib "winmm" (ByVal 
WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInReset Lib "winmm" (ByVal 
WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInStop Lib "winmm" (ByVal 
WaveDeviceInputHandle As Long) As Long
sub InitDevices()
   Dim Caps As WaveInCaps, Which As Long, testo As String
   For Which = 0 To waveInGetNumDevs - 1
      Call waveInGetDevCaps(Which, VarPtr(Caps), Len(Caps))
      testo = StrConv(Caps.ProductName, vbUnicode) & Which
      msgbox testo
   Next
 
   If Which = 0 Then
      MsgBox "You have no audio input devices!", vbCritical, "Ack!"
      End
   End If
 
End Sub
Private Sub Form_Load()
   Call InitDevices
End Sub
Private Sub StartButton_Click()
   Static WaveFormat As WaveFormatEx
 
   With WaveFormat
      .FormatTag = WAVE_FORMAT_PCM
      .Channels = 2
      .SamplesPerSec = 44100
      .BitsPerSample = 8
      .BlockAlign = (.Channels * .BitsPerSample) \ 8
      .AvgBytesPerSec = .BlockAlign * .SamplesPerSec
      .ExtraDataSize = 0
    End With
 
   Debug.Print "waveInOpen:"; waveInOpen(DevHandle, 0, 
VarPtr(WaveFormat), 0, 0, 0)
 
   If DevHandle = 0 Then
      Call MsgBox("Wave input device didn't open!", vbExclamation, 
"Ack!")
      Exit Sub
   End If
 
   Debug.Print " "; DevHandle
   Call waveInStart(DevHandle)
 
   Static Wave As WaveHdr
 
   Wave.lpData = VarPtr(InData(0))
   Wave.dwBufferLength = 512 'This is now 512 so there's still 256 
samples per channel
   Wave.dwFlags = 0
 
   '
   ' Call waveInPrepareHeader(DevHandle, VarPtr(Wave), Len(Wave))
   ' Call waveInAddBuffer(DevHandle, VarPtr(Wave), Len(Wave))
   '
   ' Arrivati a questo punto come prendo l'output dal microfono
   ' per poi redirigerlo ad una convertitore MP3
   ' o ad un Socket che lo trasmette ad un Client
   ' o per salvarlo su file ???
   '
   ' Call waveInUnprepareHeader(DevHandle, VarPtr(Wave), Len(Wave))
   '
 
End Sub
Private Sub StopButton_Click()
   Call waveInReset(DevHandle)
   Call waveInClose(DevHandle)
   DevHandle = 0
End Sub
[/vb]