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

New Post: How to generate wav with a specific length

$
0
0

Sorry for asking dummy questions but nothing has changed:

publicoverrideint Read(byte[] buffer, int offset, int count)
            {int samples = count / 2;for (int i = 0; i < samples && time < (44100 * 3); i++)
                {double sine = amplitude * Math.Sin(Math.PI * 2 * frequency * time);
                    time += 1.0 / 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;return (time < (44100 * 3)) ? count : 0;
            }
slinger

Viewing all articles
Browse latest Browse all 5831

Trending Articles