Jump to content
  • Advertisement
Sign in to follow this  
xtomiii

C# Directsound VU Meter

This topic is 3608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I'm trying to implement simple VU Meter for stereo channels. I've found samples on how to di it .. but the result seems quite bad as the result are displayed with delay and not reflect the sound correctly. In this forumt i've found a hint on how to do this but i don't understand the code provided as it always returns 0 to me: http://www.gamedev.net/community/forums/topic.asp?topic_id=436242&whichpage=1� here is my code of how i do this: // initialization // SAMPLES = 8 public void Start() { // deviceindex is the index of currently use sound device if(deviceIndex != -1) { // initialize the capture buffer and start the animation thread Capture cap = new Capture(audioDevices[deviceIndex].DriverGuid); CaptureBufferDescription desc = new CaptureBufferDescription(); WaveFormat wf = new WaveFormat(); wf.BitsPerSample = 16; wf.SamplesPerSecond = 44100; wf.Channels = 2; wf.BlockAlign = (short)(wf.Channels * wf.BitsPerSample / 8); wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond; wf.FormatTag = WaveFormatTag.Pcm; desc.Format = wf; desc.BufferBytes = SAMPLES * wf.BlockAlign; buffer = new Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap); buffer.Start(true); liveVolumeThread = new Thread(new ThreadStart(updateProgress)); liveVolumeThread.Priority = ThreadPriority.Lowest; liveVolumeThread.Start(); } } // here is method updating values private void updateProgress() { while(true) { int tempSampleDelay = sampleDelay; Array samples = buffer.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY); // for each channel, determine the step size necessary for each iteration int leftGoal = 0; int rightGoal = 0; // average across all samples to get the goals for(int i = 0; i < SAMPLES; i++) { leftGoal += (Int16)samples.GetValue(i, 0, 0); rightGoal += (Int16)samples.GetValue(i, 1, 0); } leftGoal = (int)Math.Abs(leftGoal / SAMPLES); rightGoal = (int)Math.Abs(rightGoal / SAMPLES); } Any help is greatly appreciated Tomas

Share this post


Link to post
Share on other sites
Advertisement
You won't get a decent effect using volume as a display of sound. You need to split the signal up into frequency bands using FFT to get a decent looking VU or graphic equalizer. Take a look at Exocortex.DSP which is a managed library with FFT functions.

Share this post


Link to post
Share on other sites
Hello

I went through everything I've found in the link you've sent to me.
I guess without strong mathematical background I'm not able to continue. For me it's ok just to display the volume level and not the whole spectrum (It'd be nicer .. but i guess it's way too complicated)

There is no simpler way? Anyway I'll try to understand what's all the FFT about and I'll try to post my discoveries.

If you know how to help me to better understand it, please let me know.

Tomas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!