Exemple #1
0
        /// <summary>
        /// Constructor for creating new audioprovider including
        /// mixer, oscillators and envelope
        /// </summary>
        /// <param name="oscNum">Number of oscillators</param>
        public AudioProvider(int oscNum)
        {
            // Fill mixer with oscillators
            List<MySignalGenerator> samples = new List<MySignalGenerator>();
            for (int i = 0; i < oscNum; i++)
            {
                oscs.Add(new MySignalGenerator());
                samples.Add(oscs[i]);
            }
            mixer = new MyMixingSampleProvider(samples);

            // Default envelope
            mixer.env.AttackRate = (44100f);
            mixer.env.DecayRate = (44100f);
            mixer.env.SustainLevel = (.6f);
            mixer.env.ReleaseRate = (44100f);
            envOn = false;

            // Set buffers and latency
            waveOut.NumberOfBuffers = 2;
            waveOut.DesiredLatency = 150;

            // Pass mixer into waveOut
            waveOut.Init(mixer);
            if (oscNum <=0 )
            {
                throw new ArgumentException("Constructor must take at least one oscillator");
            }
        }
Exemple #2
0
        /// <summary>
        /// Constructor for assigning latency and buffers
        /// </summary>
        /// <param name="oscNum">Number of oscillators</param>
        /// <param name="buffers">Number of buffers</param>
        /// <param name="latency">Desired latency in ms</param>
        public AudioProvider(int oscNum, int buffers, int latency)
        {
            if (oscNum <= 0)
            {
                throw new ArgumentException("Constructor must take at least one oscillator");
            }

            // Fill mixer with oscillators
            List<MySignalGenerator> samples = new List<MySignalGenerator>();
            for (int i = 0; i < oscNum; i++)
            {
                oscs.Add(new MySignalGenerator());
                samples.Add(oscs[i]);
            }
            mixer = new MyMixingSampleProvider(samples);

            // Set default envelope values
            mixer.env.AttackRate = (44100f);
            mixer.env.DecayRate = (44100f);
            mixer.env.SustainLevel = (.6f);
            mixer.env.ReleaseRate = (44100);
            envOn = false;

            if (buffers < 0 || buffers > 8)
            {
                throw new ArgumentException("Buffer size must be between 0 and 8");
            }
            if (latency < 0)
            {
                throw new ArgumentException("Latency must be postive");
            }
            // Set number of buffers and latency
            waveOut.NumberOfBuffers = buffers;
            waveOut.DesiredLatency = latency;
            // Pass mixer into waveOut
            waveOut.Init(mixer);
        }