Solved

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

Posted on 2004-08-13
3
2,852 Views
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: http://www.nerosoft.com/Download/SoundProblem.wav

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?
0
Comment
Question by:ScottNero
3 Comments
 
LVL 1

Author Comment

by:ScottNero
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:

http://www.talkaboutprogramming.com/group/comp.lang.basic.visual.misc/messages/541256.html

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.
0
 
LVL 1

Accepted Solution

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

DarthMod
Community Support Moderator
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 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