Click here to Skip to main content
15,885,782 members
Articles / Programming Languages / C#

Audio DSP with C#

Rate me:
Please Sign up or sign in to vote.
4.55/5 (23 votes)
6 Sep 20032 min read 219.6K   8.7K   92  
A .NET class library for audio processing.
using System;

namespace Garbe.Sound
{
	/// <summary> Calculate the mixing signal from a collection of source signals </summary>
	public sealed class Mixer : SoundObj
	{
		private ushort      _numChannels;
		private SoundObj[]  _inputs;
		private int			_counter;

		/// <summary> Calculate the mixing signal from a collection of source signals </summary>
		/// <param name="c">Number of channels</param>
		public Mixer(ushort c) : base()
		{
			_numChannels = c;
			_inputs = new SoundObj[c];
		}

		/// <summary> Do the signal processing </summary>
		public override void DoProcess()
		{
			_output = 0;

			for(_counter = 0; _counter < _numChannels; _counter++)
				_output += _inputs[_counter].Output;
		}
		
		/// <summary> Number of interations expected to do the signal processing </summary>
		public override int Interations
		{
			get
			{
				int max = 0;
				for(_counter = 1; _counter < _numChannels; _counter++)
				{
					if(_inputs[_counter - 1].Interations > _inputs[_counter].Interations)
						max = _inputs[_counter - 1].Interations;
					else
						max = _inputs[_counter].Interations;
				}

				return(max);
			}
		}

		/// <summary> Gets the number of channels of the signal </summary>
		public override ushort NumChannels
		{
			get{return(this._numChannels);}
		}

		/// <summary> Gets or Sets the source signals of each channel </summary>
		public SoundObj this[int index]
		{
			get 
			{
				if(index <= _numChannels)
					return(_inputs[index]);
				else
					throw new Exception("Out of Range!!!");
			}
			set 
			{
				if(index <= _numChannels)
					_inputs[index] = value;
				else
					throw new Exception("Out of Range!!!");
			}
		}


	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions