FromArray() public static method

Creates a new Signal from a float array.
public static FromArray ( Array signal, int sampleRate, SampleFormat format = SampleFormat.Format32BitIeeeFloat ) : Signal
signal System.Array
sampleRate int
format SampleFormat
return Signal
Ejemplo n.º 1
0
        /// <summary>
        ///   Notifies client about new block of frames.
        /// </summary>
        ///
        /// <param name="frame">New frame's audio.</param>
        ///
        protected void OnNewFrame(Array frame)
        {
            framesReceived++;

            if (NewFrame != null)
            {
                NewFrame(this, new NewFrameEventArgs(Signal.FromArray(frame,
                                                                      channels, sampleRate, SampleFormat.Format16Bit)));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Worker thread.
        /// </summary>
        ///
        private unsafe void WorkerThread()
        {
            try
            {
                needToStop = false;

                // Rearm the auto reset events
                for (int i = 0; i < inputReady.Length; i++)
                {
                    inputReady[i].Reset();
                }

                short[] buffer = new short[frameSize * channels];
                Signal  signal = Signal.FromArray(buffer, channels, sampleRate, SampleFormat.Format16Bit);

                // Multiple sources
                while (!needToStop)
                {
                    mix(buffer, signal);
                }
            }
            catch (Exception ex)
            {
                if (AudioSourceError != null)
                {
                    AudioSourceError(this, new AudioSourceErrorEventArgs(ex.Message));
                }
                else
                {
                    throw;
                }
            }
            finally
            {
            }
        }