Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-13
3
Medium Priority
?
3,059 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
[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
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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