Click here to Skip to main content
11,501,561 members (79,291 online)
Click here to Skip to main content
Add your own
alternative version

Compose sounds from frequencies and visualize them

, 17 Apr 2006 CPOL 141.3K 2.3K 160
What you never wanted to know about PCM.
/* This class has been written by
 * Corinna John (Hannover, Germany)
 * cj@binary-universe.net
 * 
 * You may do with this code whatever you like,
 * except selling it or claiming any rights/ownership.
 * 
 * Please send me a little feedback about what you're
 * using this code for and what changes you'd like to
 * see in later versions.
 */

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace WaveMixer {

    /// <summary>Format header information of a RIFF Wave file.</summary>
	[StructLayout(LayoutKind.Sequential)]
	public class WaveFormat {
        private short wFormatTag;
        private short nChannels;
        private int nSamplesPerSec;
        private int nAvgBytesPerSec;
        private short nBlockAlign;
        private short wBitsPerSample;
        private short cbSize;

        /// <summary>wFormatTag header field.</summary>
        public short FormatTag
        {
            get { return wFormatTag; }
            set { wFormatTag = value; }
        }

        /// <summary>nChannels header field.</summary>
        public short Channels
        {
            get { return nChannels; }
            set { nChannels = value; }
        }

        /// <summary>nSamplesPerSec header field.</summary>
        public int SamplesPerSec
        {
            get { return nSamplesPerSec; }
            set { nSamplesPerSec = value; }
        }

        /// <summary>nAvgBytesPerSec header field.</summary>
        public int AvgBytesPerSec
        {
            get { return nAvgBytesPerSec; }
            set { nAvgBytesPerSec = value; }
        }

        /// <summary>nBlockAlign header field.</summary>
        public short BlockAlign
        {
            get{ return nBlockAlign; }
            set { nBlockAlign = value; }
        }

        /// <summary>wBitsPerSample header field.</summary>
        public short BitsPerSample
        {
            get { return wBitsPerSample; }
            set { wBitsPerSample = value; }
        }

        /// <summary>cbSize header field.</summary>
        public short Size
		{
			get { return cbSize; }
			set { cbSize = value; }
		}

        /// <summary>Constructor.</summary>
		public WaveFormat()
		{
			//default constructor
		}

        /// <summary>Constructor.</summary>
        /// <param name="samplesPerSec">Number of samples per second.</param>
        /// <param name="bitsPerSample">Number of bits per sample.</param>
        /// <param name="channels">Number of channels.</param>
		public WaveFormat(int samplesPerSec, short bitsPerSample, short channels)
		{
			wFormatTag = (short)WaveFormats.Pcm;
			nChannels = channels;
			nSamplesPerSec = samplesPerSec;
			wBitsPerSample = bitsPerSample;
			cbSize = 0;

			nBlockAlign = (short)(channels * (bitsPerSample / 8));
			nAvgBytesPerSec = samplesPerSec * nBlockAlign;
		}
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Corinna John
Software Developer
Germany Germany
Corinna lives in Hannover/Germany (CeBIT City) and works as a Delphi developer, though her favorite language is C#.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 17 Apr 2006
Article Copyright 2005 by Corinna John
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid