Most useful option to record and analyze audio?
I'm writting a code where a client program records sound from the audio input device, sends it to a server and the server analyzes some characteristics of that audio information.
Well, I started using the api mciSendString to record audio and create a *.wav file, but I think that way is quite slow because you've to wait until the recording is ended, send the wav file to the server, etc. So I thought about creating a buffer in the memory and send the audio information in real time to the server so I don't need to create the wave file and I don't need to wait until the recording has ended.
The question is that I don't know what model I should use to do that task. I thought about using wavein apis to perform that task. Is this a correct option or do I should use other technique?
Re: Most useful option to record and analyze audio?
For recording you can use a class clsTrickSound. It have the event which raised when an another piece of data is recorded.
Re: Most useful option to record and analyze audio?
Quote:
Originally Posted by
The trick
For recording you can use a class
clsTrickSound. It have the event which raised when an another piece of data is recorded.
Thanks The trick,
The code is complex to me to read because my programming level is low.
How should I use your class to record in a buffer?
1 Attachment(s)
Re: Most useful option to record and analyze audio?
Hello, it is a simple example:
Code:
Option Explicit
' Sorry my English.
Private Declare Sub memcpy Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
' This is a capture object.
Dim WithEvents recorder As clsTrickSound
' Temporary stereo buffer which will obtain the sound data.
Dim tempBuffer(1, 4096) As Integer
Private Sub Form_Load()
Me.ScaleMode = vbPixels
' Create a new recorder object
Set recorder = New clsTrickSound
' Handle errors from this object
On Error GoTo ErrorCapturing
' Initialize a capture sound
' Set the number of channels (mono/stereo), sample rate, bits per sample and size of internal capture buffer
' Don't need set the size internal buffer too small, because it will cause clicking sounds and noises.
' For capturing the sound we using a default capture device.
recorder.InitCapture UBound(tempBuffer, 1) + 1, 44100, 16, UBound(tempBuffer, 2) + 1
' Ok, the capture is success, start it.
recorder.StartProcess
Exit Sub
ErrorCapturing:
MsgBox "Error", vbCritical
Unload Me
End Sub
' // This events calling when a part of recorded sound is ready.
Private Sub recorder_NewData(ByVal DataPtr As Long, ByVal CountBytes As Long)
' Copy data to temporary buffer
memcpy tempBuffer(0, 0), ByVal DataPtr, CountBytes
' Just we draw this data on the form.
Dim dx As Single, dy As Single, oy1 As Long, oy2 As Long, i As Long, di As Long, o As Long
dx = Me.ScaleWidth / UBound(tempBuffer, 2)
dy = Me.ScaleHeight / 131072
oy1 = Me.ScaleHeight / 4
oy2 = oy1 + Me.ScaleHeight / 2
Me.cls
For i = 1 To Me.ScaleWidth
di = Int(i / dx)
' Both channels
Me.Line (i - 1, tempBuffer(0, o) * dy + oy1)-(i, tempBuffer(0, di) * dy + oy1)
Me.Line (i - 1, tempBuffer(1, o) * dy + oy2)-(i, tempBuffer(1, di) * dy + oy2)
o = di
Next
End Sub
ADDED: You also can use DirectSound to capture sound. Here is example.