?
Solved

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

Posted on 2007-03-28
4
Medium Priority
?
2,298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

I have a Synology DS212+ NAS.  These are not only great for backup and normal NAS stuff, but also for delivering media throughout your home or LAN via DLNA.  I copied my whole audio collection from iTunes over to the box, but couldn't figure out how…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn how to turn a Live Set into a compressed Live Pack file, and how to install Live Packs. Make: File > Collect All And Save: File > Manage Files: Click Manage Project: Click Create Pack: Select save location: Install: Doub…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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