Simppeli ääninauhuri-luokka äänikortin mixeriltä nauhoittamista varten.
Esimerkissä on
button 1..3 : nauhoitus, seis, talletus
progressbar1: ajan näyttö
timer1
textbox1: tiedostopolku
moduulissa
Module NauhuriModule
Public Nauhuri1 As Nauhuri
Class Nauhuri
'Simppeli ääninauhuri äänikortilta nauhoittamiseen
'Käyttäjä asetelkoon äänenvoimakkuuden käsin
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal _
fdwError As Integer, ByVal lpszErrorText As String, ByVal cchErrorText As Integer) As Integer
'
'
Public Sub Nauhoita()
Dim i, cb As Integer
Dim RS As String
i = mciSendString("open new type waveaudio alias capture", RS, 128, cb)
i = mciSendString("set capture format tag pcm", RS, 128, cb)
i = mciSendString("set capture channels 2", RS, 128, cb) 'stereo
i = mciSendString("set capture bitspersample 16", RS, 128, cb) ' 16 bit
i = mciSendString("set capture samplespersec 44100", RS, 128, cb) ' CD laatu
i = mciSendString("set capture alignment 4", RS, 128, cb)
i = mciSendString("set capture bytespersec 176400", RS, 128, cb)
i = mciSendString("set capture time format ms", RS, 128, cb)
' record
i = mciSendString("record capture", RS, 128, cb)
End Sub
'
'
Public Sub Seis()
Dim i, cb As Integer
Dim RS As String
i = mciSendString("stop capture", RS, 128, cb)
End Sub
'
'
Public Sub Talleta(ByVal filepath As String)
Dim i, cb As Integer
Dim RS, asa As String
asa = "save capture " + filepath
i = mciSendString(asa, RS, 128, cb)
i = mciSendString("close capture", RS, 128, cb)
End Sub
End Class
End ModuleKäyttöesimerkki
'nauhoitus
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Nauhuri1.nauhoita()
ProgressBar1.Value = 0 : ProgressBar1.Step = 1 : ProgressBar1.Maximum = 200
Timer1.Interval = 1000 : Timer1.Start()
End Sub
'
' Alustus
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "C:\koe.wav"
Nauhuri1 = New Nauhuri
End Sub
'
' Nauhoitus seis
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Nauhuri1.seis()
Timer1.Stop()
End Sub
'
'Talletus
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Nauhuri1.talleta(TextBox1.Text)
End Sub
'
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If ProgressBar1.Value < ProgressBar1.Maximum Then ProgressBar1.Value = ProgressBar1.Value + 1
End SubTäähän on kätevä!!! :D
Tuli heti käyttöön.....
No, näitä ääninauhureita pyörii netissä pilvin pimein. Ei siinä muuta kun vaan hallitsee mciSendStringin. MSDN:ään siis.
Kieltämättä joissakin tilanteissa ihan hyödyllinen.
mikä ihmeen progressbar
Jos nykyinen Windows media player ei pysty soittamaan syntynyttä wav tiedostoa, korjaus ohje:
Public Sub Nauhoita()
Dim i, cb As Integer
Dim RS As String = New String("*"c, 128)
i = mciSendString("open new type waveaudio alias capture", RS, 128, cb)
i = mciSendString("set capture format tag pcm", RS, 128, cb)
i = mciSendString("set capture alignment 4 bitspersample 16 samplespersec 44100 channels 2 bytespersec 176400", RS, 128, cb)
i = mciSendString("set capture time format ms", RS, 128, cb)
' record
i = mciSendString("record capture", RS, 128, cb)
End Subeli osa asetuksista täytyy antaa samalla rivillä!!!
Aihe on jo aika vanha, joten et voi enää vastata siihen.