Solved

Trying to get a VU level from the sound card.

Posted on 1999-01-06
14
926 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
  • 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 150 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
 
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
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.

 

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

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
Duplicates in Aggregate Query 3 33
How To Display a Conditional Image in a Microsoft Access Report 23 87
Windows Process running 3 47
Using MS Code on my Mac 6 64
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now