Recording WAV audio using MCI via mciSendString API results in garbled audio - sometimes

Posted on 2004-08-13
Last Modified: 2013-12-03
I have an application released that records WAV audio at CD standard - 44.1 KHz, 16 bit, 2 channel. I am doing it using the mciSendString API from within VB6. It works perfectly 99% of the time - however, I have several users reporting that it records garbled audio, and I have had a couple users send me samples. One of the samples (1.7 meg) is here:

I am sending the following MCI commands:

open new type waveaudio alias capture
set capture bitspersample 16
set capture samplespersec 44100
set capture channels 2
set capture input 0   (or whatever device they have selected to use)
set capture time format milliseconds
record capture

(time goes by)

stop capture
save capture filename.wav
delete capture
close capture

In virtually every case, this works perfectly. In a few cases it doesn't. There seems to be no common factor as to what is causing it - some are running W2K, some XP, some XP SP2. Sound cards range from some on-board card to Creative Audigy to Soundblaster 32. PCs are all fast, over 2GHz.

I've found no reference to this sort of problem anywhere on the web. Anyone have a clue as to what might be causing the problem?
Question by:ScottNero
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

Author Comment

ID: 11798033
After much investigation, I discovered that the "bytes per second" field in the WAV header was being written incorrectly as 22050 rather than 176400. I tried including the mci bytespersec and alignment values, but this made no difference. I then found this web page:

Apparently, MCI is sensitive to the order in which the commands are sent, and does not want them sent as separate commands. I changed my commands as such:

open new type waveaudio alias capture
set capture alignment 4 bitspersample 16 samplespersec 44100 channels 2 bytespersec 176400 time format milliseconds format tag pcm

set capture input 0   (or whatever device they have selected to use)
record capture

(time goes by)

stop capture
save capture filename.wav
delete capture
close capture

This solved the problem. Why it occurred with some sound cards and not with others, who knows. However, the WAV files were always being written with incorrect headers regardless of the sound card in use. Some players would play them fine (winamp), some players would crash hard when trying to play them (Media Player 9 - go figure).

Moderator, I suspect this information might be useful to others who have this same problem. I found it in only one other place on the web, and that took a lot of searching.

Accepted Solution

DarthMod earned 0 total points
ID: 12086826
Submitted to PAQ with points refunded (500)

Community Support Moderator

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

751 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