Click here to Skip to main content
Click here to Skip to main content

Simple Audio Out Oscilloscope and Spectrum Analyzer

, 26 Jul 2006
Rate this:
Please Sign up or sign in to vote.
An example of how to access the Audio Mix, sample audio output, and a simple DSP processing.

Sample Image

Introduction

This is a simple application I built to understand the basics of the Windows Audio WAVE API, and to get a basic grasp on Fast Fourier Transforms (FFTs). Features of the application are: double buffering graphics, sampling an audio source, selecting an audio recording source using the mixer, calculating the FFT spectrum array, and plotting sampled data.

Background

I won't discus the details of FFT here as the math is a little beyond me. Basically, it involves complex numbers (those number like sqrt(-1)) and calculating discrete Sin/Cos transformations on sampled date. Google for many and better explanations on FFT.

Using the code

If you look through the example, you will find it quite a simple affair that has not been touched by MFC. This means that the code is easy to follow and easy to transplant into your projects. The basic flow of the program is:

  • Load a dialog window and initialize it.
  • Select the recording device (which is harder than it should be!).
  • Initialize the WAVE structures.
  • Activate the sampling.
  • Determine the status of the sampling.
  • Process the sampled data using FFT.
  • Clean up.

In the FFT process, I load the sampled data into an iterator class for processing within the FFT class. This allow for selective processing of the sampled data. In this case, I sampled the recording source in stereo, and I can selectively process the left or the right channels within the FFT class, or both channels at once. Both classes are simple to follow and to implement.

Points of interest

The audio device API within Windows is far more complex than it should be. This is pretty common when dealing with Microsoft, they never seem to make things easy! A classic example is dealing with the Audio Mixer. It took some time to find some code that can do the most basic of tasks (select a recording device), and even that is not 100% perfect. Device drivers may incorrectly label a recording device as a WAVEOUT device and the program will return an error when trying to record from it, so look out for such errors (use the VC6 debugger to determine the fault in such occurrences).

In fact, I would not recommend using the WAVE API for anything too complex as it tends to be a bit tricky to use, instead look at the Simple Directmedia Layer library, and specifically the mixer lib, which is a good example of making things simple and useful to the programmer.

The FFT implementation probably isn't the fastest around. I originally converted the source from a Java class, and then optimized the Cos/Sin processing to implement a look up table to speed things up significantly, and added a few helper methods; otherwise it has remained unchanged.

History

  • Updated the spectrum graphics to be more equalised.
  • Fixed a number of small bugs.

License

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

Share

About the Author

Steven De Toni

New Zealand New Zealand
No Biography provided

Comments and Discussions

 
Generalsoftware osiloscope link Pinmembernejatkaraca29-Aug-08 22:32 
QuestionSource? PinmemberMember 254060511-Dec-07 10:54 
Questioncan u guide me i am new for mixer control Pinmemberrajneshmalik30-Aug-07 2:25 
AnswerRe: can u guide me i am new for mixer control Pinmemberzhanghwem22-May-08 18:35 
Use waveOutWrite and put the data(average of left and right channel) of first file in left channel, put the data of second file in right channel. Refer to MSDN for details.
QuestionError unable to set recording WAVEOUT device Pinmemberhanji_moti29-Aug-07 7:45 
AnswerRe: Error unable to set recording WAVEOUT device PinmemberSteven De Toni29-Aug-07 10:48 
AnswerRe: Error unable to set recording WAVEOUT device Pinmemberzhanghwem22-May-08 18:16 
GeneralRe: Error unable to set recording WAVEOUT device PinmemberAEN23-Dec-08 7:17 
Generaluse many cpu percenge Pinmembershallopquan13-Aug-07 21:08 
GeneralRe: use many cpu percenge PinmemberSteven De Toni15-Aug-07 18:40 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 27 Jul 2006
Article Copyright 2006 by Steven De Toni
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid