Click here to Skip to main content
15,399,197 members
Articles / Multimedia / DirectX
Posted 14 Sep 2007


53 bookmarked

LED Style Volume Meter Using DirectX

Rate me:
Please Sign up or sign in to vote.
4.50/5 (13 votes)
21 Sep 2007CPOL5 min read
A DirectX based Audio Volume Meter, emulates LED panel on sound board.

Screenshot - AnalogSignalMeterSample.jpg


This article serves as a usage manual for a UserControl I created called AnalogSignalMeter. This control uses Direct3D to paint the control, and DirectSound to sample the audio signal.


I am a sound tech at my church, and I am currently developing some software. One of the items I needed was a signal level meter. I decided to create my own, and this is the result.


The demo program is a basic form that demonstrates the control. There are also controls that let you modify the properties of the control.

AnalogSignalMeter Public Properties

The following properties are available to you for modification:

  • BackgroundColor
  • LowLedColor
  • MidLedColor
  • HighLedColor
  • LowLedCount
  • MidLedCount
  • HighLedCount
  • LedHeight
  • LedWidth
  • LeftMargin
  • RightMargin
  • BottomMargin
  • TopMargin
  • LeftRightSeperation
  • UpDownSeperation
  • DisplayOrientation
  • AudioDisplayMode
  • MeterMode
  • SampleFrequencyMilliseconds
  • AutoStart
  • ClearMeterOnStop

BackgroundColor and the three LedColor properties are pretty straightforward. They control the colors of the meter. The three LedCount properties control the maximum number of each different LED level. LedHeight and LedWidth control the sizing of each individual LED. These properties are relative to the Orientation of the control. The four Margin properties control the spacing between the LEDs and the four edges of the control. They too are relative to the Orientation of the control. LeftRightSeperation and UpDownSeperation control the spacing between each LED. These properties are also relative to the Orientation of the control.

DisplayOrientation has four possibilities: Horizontal, HorizontalReverse, Vertical, and VerticalReverse. Horizontal draws the LEDs from least to greatest as left to right. HorizontalReverse is the opposite of this. Vertical draws the LEDs from least to greatest as top to bottom. VerticalReverse is the opposite of this. The orientation pictured at the top of the article is Horizontal. The most common arrangement to emulate a sound board meter is VerticalReverse.

AudioDisplayMode has two possibilities: Stereo and Mono. Stereo samples a unique level for the left and right channels. Mono samples the left channel for both left and right levels.

MeterMode has three possible values: AudioSignal, RandomLevels, and SpecificLevels. AudioSignal tells the meter to run in standard mode, capturing levels from the audio buffer. RandomLevels tells the meter to report randomly generated levels. SpecificLevels tells the meter to report the same level constantly.

SampleFrequencyMilliseconds controls how often the control samples the signal level, and is measured in milliseconds, thousandths of a second. The default, and probably the best value, is 100. However, feel free to experiment to your own liking.

AutoStart tells the control whether or not to start when the application loads. This is set to false, by default. This still needs a bit of tweaking on my part, and will be rectified in the next release.

ClearMeterOnStop tells the control whether or not to reset the meter to zero when stopped.

The following are read-only properties that you can access.

  • MeterRunning
  • TotalLedCount
  • LeftLevel
  • RightLevel

MeterRunning simply tells you whether or not the meter is running. TotalLedCount returns the total maximum number of LEDs. LeftLevel and RightLevel allow you to read the last sampled volume level.

AnalogSignalMeter Public Methods

There are four methods available for your use:

  • StartMeter()
  • StartRandomMeter()
  • StartSpecificMeter(int leftLevel, int rightLevel)
  • StopMeter()

StartMeter will start the meter and begin sampling the signal from the sound card. StartRandomMeter will start the meter, and begin feeding random levels to it. StartSpecificMeter will start the meter, and feed it a constant static level repeatedly. StopMeter will stop the meter, and if ClearMeterOnStop is true, then the levels will be reset to zero.

You may never need the last two start methods, but they are handy for troubleshooting the meters behavior if you start noticing odd behavior.

AnalogSignalMeter Events

There are three events that the control will trigger:

  • ReportLevel
  • LeftSignalPeak
  • RightSignalPeak

ReportLevel is triggered whenever a new sample is acquired. It has its own EventArgs, which contain both levels, args.LeftLevel, and args.RightLevel.

LeftSignalPeak and RightSignalPeak are triggered any time the sample level equals the total maximum LEDs. This is handy because this means that the audio signal is likely distorted, meaning a loss of quality, and it would be a signal to reduce the gain of the incoming signal. This event has its own EventArgs, which contains the Channel that peaked, args.Channel, and also a message, args.Message.

AnalogSignalMeter Tips

As mentioned above, AutoStart needs tweaking. If you wish for the meter to auto start, set AutoStart to true in the design stage, and then have your form check the property, and call the StartMeter method accordingly.

If you don't like the look of the meter but want the functionality, there is an alternative, which you can view in the demo application. You can set the control visibility to false, and in your ReportLevel handler, you can use the levels to set a progress bar value. Set the progress bar maximum to the TotalLedCount value, and then have the ReportLevel event handler set the progress bar value to the args.LeftLevel or args.RightLevel value. You can make a separate progress bar for each channel if you like. There is a nice gradient style progress bar available from someone on CodeProject. It can be used to mimic the separate color values for lower or higher signal levels.


September 21, 2007 - New Release Posted

I have uploaded a new release of both BuckSoft.DirectSound, and AnalogSignalMeterDemo.


  • Added a new public property, MeterMode, along with an enumeration of values for it. This property tells the meter to run in either audio signal mode, random levels mode, or specific levels mode. The lack of this property is why the meter would always restart back into random mode when changing other properties with the demo.


  • Fixed the "Always restarts in random mode" bug.
  • Progress bar updates and level labels updates on the demo were handled in an unsafe thread call, this has been fixed.
  • Fixed the bug that caused a crash when LedCounts were increased

September 17, 2007 - Complete Source Code Added

On my initial post, I neglected to post the complete source code for the control. Now it is available.

September 14, 2007 - Initial Posting

Feel free to make suggestions for additions or improvements. I am still fresh to C# and DirectX, and welcome any insight that anyone may have to offer.


This control is free to use and redistribute as you please. It is a work in progress. Use at your own risk.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Member 249972410-Dec-12 20:34
MemberMember 249972410-Dec-12 20:34 
Generalvu meter at playing Pin
steve234922-Nov-10 3:51
Membersteve234922-Nov-10 3:51 
GeneralMy vote of 4 Pin
mikkojay22-Oct-10 20:31
Membermikkojay22-Oct-10 20:31 
GeneralAwesome work! Pin
Jinx1013-Jan-10 11:54
MemberJinx1013-Jan-10 11:54 
GeneralRe: Awesome work! Pin
Jinx1016-Jan-10 6:28
MemberJinx1016-Jan-10 6:28 
GeneralQuestion Pin
alenet44413-Aug-09 3:35
Memberalenet44413-Aug-09 3:35 
GeneralWorks fine in XP but not on Vista x64 Pin
silviu2k723-Mar-08 7:31
Membersilviu2k723-Mar-08 7:31 
Generalit doesn work!! Pin
CARTAVIO11-Feb-08 11:53
MemberCARTAVIO11-Feb-08 11:53 
GeneralRe: it doesn work!! Pin
xtomiii28-Jul-08 12:17
Memberxtomiii28-Jul-08 12:17 
GeneralRe: it doesn work!! Pin
MikeCam27-May-09 0:51
MemberMikeCam27-May-09 0:51 
GeneralError in code Pin
Greg Osborne20-Nov-07 9:32
MemberGreg Osborne20-Nov-07 9:32 
QuestionOutOfVideoMemoryException Pin
isepise8-Nov-07 2:46
Memberisepise8-Nov-07 2:46 
GeneralInvalidCallException Pin
kgoodrich23-Oct-07 11:47
Memberkgoodrich23-Oct-07 11:47 
QuestionHow to use this? Pin
almere10918-Sep-07 11:39
Memberalmere10918-Sep-07 11:39 
AnswerRe: How to use this? Pin
stebo072818-Sep-07 16:55
Memberstebo072818-Sep-07 16:55 
GeneralRe: How to use this? Pin
almere10918-Sep-07 20:42
Memberalmere10918-Sep-07 20:42 
GeneralRe: How to use this? Pin
almere10919-Sep-07 11:43
Memberalmere10919-Sep-07 11:43 
GeneralRe: How to use this? Pin
sjcardinale20-Sep-07 10:48
Membersjcardinale20-Sep-07 10:48 
GeneralRe: How to use this? Pin
almere10920-Sep-07 20:36
Memberalmere10920-Sep-07 20:36 
GeneralRe: How to use this? Pin
stebo072821-Sep-07 3:17
Memberstebo072821-Sep-07 3:17 
GeneralGDI based control Pin
_elli_15-Sep-07 6:03
Member_elli_15-Sep-07 6:03 
GeneralRe: GDI based control Pin
stebo072815-Sep-07 10:27
Memberstebo072815-Sep-07 10:27 
GeneralRe: GDI based control Pin
_elli_16-Sep-07 2:56
Member_elli_16-Sep-07 2:56 
GeneralRe: GDI based control Pin
almere10919-Sep-07 11:45
Memberalmere10919-Sep-07 11:45 
GeneralRe: GDI based control Pin
stebo072821-Sep-07 3:14
Memberstebo072821-Sep-07 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.