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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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.…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now