Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trying to get a VU level from the sound card.

Posted on 1999-01-06
14
Medium Priority
?
944 Views
Last Modified: 2013-12-03
I'm trying to get a VU level from the sound card.  I'm using the MCI (Media Control Interface) and programming in C++.  I know how to start and stop recording or playing but I'm having trouble obtaining the level.  

I open the MCI Device like this:
 
  // open the wave device
  open_parms.lpstrDeviceType = "waveaudio";
  open_parms.lpstrElementName = "";

  mciSendCommand( 0, MCI_OPEN, MCI_OPEN_TYPE |
                     MCI_OPEN_ELEMENT,
                     (DWORD)(LPVOID) &open_parms);
  // set PCM format of recording
  set_parms.wFormatTag = WAVE_FORMAT_PCM;
  set_parms.wBitsPerSample = 16;
  set_parms.nChannels = 1;
  set_parms.nSamplesPerSec = 22050;
  set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample)/8)
                                *set_parms.nChannels
                                *set_parms.nSamplesPerSec;
    set_parms.nBlockAlign = ((set_parms.wBitsPerSample) /8)
                            *set_parms.nChannels;

  mciSendCommand(wave_device_id,MCI_SET, MCI_WAIT |
                                MCI_WAVE_SET_FORMATTAG |
                                MCI_WAVE_SET_BITSPERSAMPLE|
                                MCI_WAVE_SET_CHANNELS |
                                MCI_WAVE_SET_SAMPLESPERSEC |
                                MCI_WAVE_SET_AVGBYTESPERSEC|
                                MCI_WAVE_SET_BLOCKALIGN,
                               (DWORD) (LPVOID) &set_parms);

I try to sample the Level like this:
  status_parms.dwItem = MCI_WAVE_STATUS_LEVEL;
  mciSendCommand( wave_device_id,MCI_STATUS ,                                                MCI_STATUS_ITEM, (DWORD)                                  &status_parms);
From what I understand after this: stat_parms.dwReturn should contain the level from the MCI Device.  Instead the value is 0.

This will not give me any errors and if I send the MCI device an MCI SAVE and close the device a file of nothing will be created.  I don't know if I'm going about this in the wrong way or not but I need to obtain a level from the sound card.  I will appreciate the help.

Thanks.
0
Comment
Question by:ben_cochran
[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
  • 6
  • 4
  • 4
14 Comments
 

Expert Comment

by:overworked
ID: 1418178
You need to use wavein to record audio. You'll then need to examine each buffer of audio data as it comes in in real time. Your analyze buffer routine should make note of the highest sample within buffer. The highest sample in buffer is your active VU level. However, you may want to implement a VU fall-off rate or gravity effect so that your VU level will fall off at a steady rate unless a new 'highest sample reading' exceeds the current level.

When determining highest sample in buffer, be sure to differentiate between 8 and 16 bit audio data. 8bit audio is unsigned while 16bit is signed.

On another note, you can make an oscilloscope type display to go along w/ur VU meters. Simply graph each buffer of audio data onto a display using time as your X axis and the sample as your Y.
0
 

Author Comment

by:ben_cochran
ID: 1418179
I thought that I would have to look at a buffer of some sort, but how is that done?
0
 

Accepted Solution

by:
overworked earned 450 total points
ID: 1418180
Your gonna create the buffer yourself and turn it over to wavein for filling with recorded audio data (Look up wavein funcs in your winsdk). When it gives it back full, your gonna perform a loop looking at each sample within the buffer. If that sample is higher than the highest sample you have so far, you swap it with your highest.
0
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.

 
LVL 23

Expert Comment

by:chensu
ID: 1418181
Try combining MCI_WAIT with MCI_STATUS_ITEM. If it still does not work, I would recommend using Audio Mixers functions. See my article at http://www.codeguru.com/multimedia/ADMixer.shtml.
0
 

Expert Comment

by:overworked
ID: 1418182
chensu: the wave meter control will give you VU for wave playback but not record. Therefore, you can't get VU for any external audio sources.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1418183
The code at CodeGuru is for wave playback. However, there is a wave meter control for wave recording. You just need to change my code slightly to deal with the wavein audio line. To prove it, run the Volume Control application in Windows, choose menu Options/Properties and switch it to Recording. You will see the control.
0
 

Author Comment

by:ben_cochran
ID: 1418184
Thank You "chensu" you are the best.  After looking into the Mixer controls I found how to take the level of almost anything.
0
 

Expert Comment

by:overworked
ID: 1418185
If your app is to be run on all types of sound cards, I personally don't recommend that you use mixer api for getting VU readings since you'll be relying on the driver written by card manufacturer. In my experience from dealing with these drivers, I've noticed that there is no guarantee that the VU control will be present in the driver or the extent of its ability. This goes for line input controls as well. Unfortunately, there are some driver programmers who don't use the correct labeling with their controls. I've noticed that it's not always possible to find cd and external input line in controls and I've even had to substring search the control labels for words like "cd", "line", "ext" etc. to do so.
0
 

Author Comment

by:ben_cochran
ID: 1418186
Overworked:  You were right is saying, "there is no guarantee that the VU control will be present in the driver".  I still have trouble getting the buffer from the sound card.  Do you know of any good reference or web sites that have good documentation on retrieving the buffer from the sound card?    
0
 

Expert Comment

by:overworked
ID: 1418187
hmm, buffer from the sound card? Do you mean the RAM onboard sound card? If so, I think DirectX would be your best bet. I'm pretty sure dx sound will let you copy stuff to/from sound card RAM. However, I don't think it will give you a ptr address since the RAM isn't mapped into cpu mem space.
0
 

Author Comment

by:ben_cochran
ID: 1418188
As you said to me, "Your gonna create the buffer yourself and turn it over to wavein for filling with recorded audio data." Do you know of any good reference or web sites that have good documentation on how to do this?
0
 

Expert Comment

by:overworked
ID: 1418189
Hmm, not off hand. You can usually find sample source code to do almost anything at msdn (microsoft developer network) http://www.microsoft.com/msdn
0
 
LVL 23

Expert Comment

by:chensu
ID: 1418190
0
 
LVL 23

Expert Comment

by:chensu
ID: 1418191
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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