Solved

Can't record 8K 16Bit Mono wav file using mciSendString

Posted on 2007-03-28
4
2,164 Views
Last Modified: 2013-11-13
Hello,

First thank you for your time.  My goal is to record a wav file with properties 8KHz 16Bit Mono.  I've included a code snippet that demonstrates my problem.  The first thing to notice is that even though 8000hz was specified the samples per second that is being recorded is 11025 as show in the debug.print statement.  What is the reason 11025 is returned when 8000 was specified?  More importantly, please modify the code to make it work.

Thank you very much,
Michael  


Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal CommandString As String, ByVal ReturnBuffer As String, ByVal ReturnBufferSize As Long, ByVal hCallback As Long) As Long 'MCIERROR

Private Sub cmdStartRecording8K16BitMonoWav_Click()
    Dim i As Integer
    Dim sMsg As String * 255
    Dim sSamplesPerSec As String
   
    i = mciSendString("open new Type waveaudio Alias voice3", 0&, 0, 0)
    i = mciSendString("stop voice3", 0&, 0, 0)
   
    i = mciSendString("set voice3 bitspersample 16", 0&, 0, 0)
    i = mciSendString("set voice3 channels 1", 0&, 0, 0)
    i = mciSendString("set voice3 samplespersec 8000", 0&, 0, 0)
    i = mciSendString("record voice3 ", 0&, 0, 0)

    i = mciSendString("status voice3 samplespersec", sMsg, 255, 0)
    sSamplesPerSec = Left(sMsg, InStr(sMsg, Chr(0)) - 1)
    Debug.Print sSamplesPerSec
End Sub

Private Sub cmdStopRecording_Click()
    Dim i As Integer
    Dim sMsg As String * 255
   
    i = mciSendString("stop voice3", 0&, 0, 0)
    i = mciSendString("save voice3 d:\temp\test3.wav", 0&, 0, 0)
    i = mciSendString("close all ", 0&, 0, 0)
End Sub
0
Comment
Question by:mdcarr
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 18878477
You should check the return code from the set calls (the i value in the above code).  It's possible that mceSendString is rejecting the request (leaving the samplespersec at some default value).  

Also, it might be worth a try to use the "true" value of "8K" which is 8192

One other thing to check:  It's possible that the status command might be displaying something other than the actual samples-per-second rate.  If you have a good audio file utility program, take a look at the resulting file to verify exactly everything that there is to know about the recorded file.

-- Dan
0
 

Author Comment

by:mdcarr
ID: 18883646
Dear Dan,

First thank you for getting back to me.  

Taking your advice I displayed the error code from each mciSendString command that I called.  I am amazed that I missed it, but there was an error returned when I tried to set the samplespersec.  I tried both values for samplespersec: 8000 and 8192.  Both returned the same error code:  282.  Using mciGetErrorString and passing it a value of 282 gives an error text of: "The specified parameter is out of range for the specified command."

I did some internet searches trying to find the acceptable values for samplespersec, but I came up with nothing.  Do you happen to know these values, or at least do you know how I can find out?

Again, thank you for your help,
Michael
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 18894300
Looking at the lower-level function:

   waveInGetDevCaps
   http://msdn2.microsoft.com/en-us/library/ms713729.aspx

we see that it populates a structure:

   WAVEINCAPS
   http://msdn2.microsoft.com/en-us/library/ms713726.aspx

having a field named 'dwFormats' which lists a set of WAVE_FORMAT_* constants that are defined for audio input.  All of the ones listed are a 11025, 22050, 44100, or 96K.   The constants can be found in a file named MMSystem.h and I see nothing lower than 11025.  

That's not to say that other hardware devices and drivers might not support any number of variations of samples-per-second and sample size, but these seem to be the standard ones-- and I could find nothing (on google groups or elsewhere) that lists smaller values (such as 8K).

It is possible that the acceptable values are defined by whatever codecs are installed on the computer, but that's beyond my info and well into "guess space" :-)

If you want such poor quality audio, it might be possible to discard samples (say, discard every 2nd or 3rd sample); I believe the process is called "decimating."

-- Dan
0
 

Author Comment

by:mdcarr
ID: 18895110
This is the information that I have been looking for.  Thank you very much.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 70
vbModal 12 53
Error message and what and why? 15 37
Recommendation for Video Editing Software 6 20
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The advancements in today's technology are unparalleled. Much of the technology that we have could not have been imagined twenty years ago. One of the latest additions to the list of technological advances is virtual reality. Virtual reality has an …
This video will give a brief orientation and organization of Logic Pro X, and how to access different work spaces quickly with keyboard shortcuts.
Viewers will learn how to use LFOs to modulate the sound of their Sampler instruments. Click the Modulation tab in Sampler: Choose one (or more) of the three available LFOs, and click the respective button to turn it on: Select a waveform, an LF…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question