Solved

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

Posted on 2004-08-13
3
2,818 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nest Related files not working in Visual Studio 4 76
Dir function fails on mapped drives 28 123
Trouble with References... 5 44
Please explain "Multi-Tenant Services" 5 64
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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