Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: MixingSampleProvider to Mix and Output Two Buffers

$
0
0
Ok that being stated, I'm trying to get a proof of concept before I expend much more time on development. Trying to write to Left and Right channels of DirectSoundOut stream, however, only one frequency (that of double sine) comes out both channels. Any way I can write two separate sinewaves to buffer?
       public override int Read(byte[] buffer, int offset, int count)
        {
            int samples = count / 2;
            int samplesPerWave = (int)(44100 / this.frequency * 2);
            int counter = 0;
            if (toneOutput == 0)//for sine wave tone generation
            {

                for (int i = 0; i < samples; i+=2)
                {
                    //sine wave
                    double sine = amplitude * Math.Sin(Math.PI * 2 * frequency * time);
                    double sine2 = amplitude * Math.Sin(Math.PI * 2 * (frequency*2) * time);
                    time += 1.0 / 44100;
                    short truncated = (short)Math.Round(sine * (Math.Pow(2, 15) - 1));
                    short truncated2 = (short)Math.Round(sine2 * (Math.Pow(2, 15) - 1));

                    buffer[i * 2] = (byte)(truncated & 0x00ff);
                    buffer[i * 2 + 1] = (byte)((truncated & 0xff00) >> 8);

                    buffer[(i+1) * 2] = (byte)(truncated2 & 0x00ff);
                    buffer[(i+1) * 2 + 1] = (byte)((truncated2 & 0xff00) >> 8);

Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>