Solved

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

Posted on 2007-03-28
4
2,198 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
The viewer will learn how to search for and apply Apple Loops, as well as create their own in Logic Pro X. Record a region in the tracks area: Select the region: Go to File > Export > Region to Loop Library: Select the appropriate search terms…
Viewers will learn the basics of creating custom device Racks in Ableton Live. Place instrument(s) and effects onto a track, and select them all by holding the Shift key and clicking on the device title bars: Group them by typing Command-G (Ctrl-G…

839 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