• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1271
  • Last Modified:

Setting recording properties in MMControl

I am using MMControl object vb5 to record speech.  I want to be able to set recording properties to 16 bits, 16,000 Hz sampling, mono.  How can I do this?
0
Venkatagiri
Asked:
Venkatagiri
  • 3
  • 2
1 Solution
 
OHDev2004Commented:
you want the whole code for recording or just the command that will set that setting ?

if you want the command that will set that setting use this :

dim RetLng as long
RetLng = mciSendString("set recwav time format ms bitspersample 16 channels 1 samplespersec 16000", 0, 0, 0)
0
 
VenkatagiriAuthor Commented:
I am using the MMControl command "Record" to record speech.  It appears to me, after having played with MCISendString as suggested by you, that if I use MCISendString to set bits per sample, etc, then I would have to use another MCISendString to record and another one to save instead of the MMControl commands "Record" and "Save."  Is there a way to set the recording parameters when using MMControl to record and save?  MMControl appears to use the Windows default for recording.  MCISendString does not appear to affect recording parameters set in Windows (in my case XP).  Thanks for your help.
0
 
OHDev2004Commented:
when you use the string i posted it's for intializing the MMControl so this does the trick ,,
this also affects the save command ,,
i dont know what problem you encouter here :) if you want the whole code for recording i can post it to you
0
 
VenkatagiriAuthor Commented:
First, let me explain what I am doing.  Am I right in assuming that the code you provided would work only with the following declaration because without it I received an error?
       Private Declare Function mciSendString Lib "winmm.dll" _
    Alias "mciSendStringA" (ByVal lpstrCommand As String, _
    ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
    ByVal hwndCallback As Long) As Long

Next I included your code in the Form_Load sub in the form that has the MMControl object.  Later I recorded and saved a wav file using the MMControl commands "Record" and "Save".  When I checked the recording properties of this file, it was Windows default of 8-bit, 11025 Hz, mono.

If I am doing something wrong here, please post the entire code and I will try it.  Thanks for your help.
0
 
OHDev2004Commented:
i only posted that line of code assuming you already have the full code and you'll replace the existing one with the one i posted ,,

ok here is the Full Code (by the way it's a modification of 2 other coders) :)
but i combined it to be a one working function

============================================================
'In a Module
Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Function RecordWave(DurationInSeconds As Long, BitRate As Single, Channels As Single, SamplesPerSeconds As Long, OutputFile As String)
    Dim lRes As Long, sRes As String * 255, sErr As String * 255
    Dim Alignment As Long
    Dim RBuffer As String
    RBuffer = Space$(260)
    Alignment = Channels * BitRate / 8
    i = mciSendString("close all", RBuffer, Len(RBuffer), 0)
    lRes = mciSendString("open new type waveaudio alias capture", RBuffer, Len(RBuffer), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("set capture alignment " & Alignment & " bitspersample " & BitRate & " samplespersec " & SamplesPerSeconds & " channels " & CStr(Channels) & " bytespersec " & (Alignment * SamplesPerSeconds), sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("record capture", sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    Pause DurationInSeconds
    lRes = mciSendString("stop capture", sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("save capture " & OutputFile, sRes, Len(sRes), 0)
    If lRes <> 0 Then GoTo MCIError
    lRes = mciSendString("close capture", 0, 0, 0)
    If lRes <> 0 Then GoTo MCIError
    MsgBox "Finito"
    Exit Function
MCIError:
    mciSendString "stop recwav", 0, 0, 0
    mciSendString "close recwav", 0, 0, 0
    mciGetErrorString lRes, sErr, Len(sErr)
    MsgBox Replace(sErr, vbNullChar, vbNullString)

End Function


Public Sub Pause(ByVal lMilleseconds As Long)
    Dim lCurr As Long
    lCurr = Timer + (lMilleseconds / 1000)
    Do Until lCurr <= Timer
        DoEvents
    Loop
End Sub
===========================================

here is a sample :

Dim RecDuration As Long
Dim RecFile As String
RecFile = "C:\Record-Test.wav"
RecDuration = 5 * 1000

'Use only the followong samplerates:
'11025 - 22050 - 44100
Call RecordWave(RecDuration, 8, 1, 22050, RecFile)


Hope that this works ,, i've tested it :)
OHDev2004
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now