Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Viewers will learn how to create a new project within Adobe Encore and the basic layout of the software.
Viewers will learn how to create and use Simpler instruments in Ableton Live. Load new Simpler into an empty MIDI track: Select a sample and drop it into sample window in Simpler: If sample is not pitched at C3, adjust tuning with Transpose para…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now