This project has moved and is read-only. For the latest updates, please go here.

Mosquito Tone Audibility Test

Aug 14, 2014 at 3:43 PM
I was trying to use the NAudio class to create a quick little Mosquito Tone generator 17kHz+ but I can hear the tone way up into the inaudible range (19,000 Hz). As such I must be doing something incorrect any could really use the help of the community. Any insight is greatly appreciated.

Tone generation code
                WaveTone tone = new WaveTone(19000, 0.1);
                stream = new BlockAlignReductionStream(tone);
                output = new DirectSoundOut();
                output.Init(stream);
                output.Play();
WaveTone Class
    public class WaveTone : WaveStream
    {
        private double frequency;
        private double amplitude;
        private double time;

        public WaveTone(double f, double a)
        {
            this.time = 0;
            this.frequency = f;
            this.amplitude = a;
        }

        public override long Position
        {
            get;
            set;
        }

        public override long Length
        {
            get { return long.MaxValue; }
        }

        public override WaveFormat WaveFormat
        {
            get { return new WaveFormat(44100, 16, 2); }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            int samples = count / 2;
            for (int i = 0; i < samples; i++)
            {
                double sine = amplitude * Math.Sin(Math.PI * 2 * frequency * time);
                time += .5 / 44100;
                short truncated = (short)Math.Round(sine * (Math.Pow(2, 15) - 1));
                buffer[i * 2] = (byte)(truncated & 0x00ff);
                buffer[i * 2 + 1] = (byte)((truncated & 0xff00) >> 8);
            }

            return count;
        }
    }
Aug 20, 2014 at 2:24 PM
Have you tried using NAudio's SignalGenerator class and see if that is audible at 19kHz?