Represents a PCM sound discrete signal (measured in time). A real discrete-time signal is defined as any real-valued function of the integers.

In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A common example is the conversion of a sound wave (a continuous-time signal) to a sequence of samples (a discrete-time signal).

A sample refers to a value or set of values at a point in time and/or space.

Inheritance: IDisposable
Beispiel #1
0
        /// <summary>
        ///   Processes the filter.
        /// </summary>
        protected override void ProcessFilter(Signal sourceData, Signal destinationData)
        {
            SampleFormat format = sourceData.SampleFormat;
            int channels = sourceData.Channels;
            int length = sourceData.Length;
            int samples = sourceData.Samples;

            if (format == SampleFormat.Format32BitIeeeFloat)
            {
                unsafe
                {
                    float* src = (float*)sourceData.Data.ToPointer();
                    float* dst = (float*)destinationData.Data.ToPointer();

                    for (int i = 0; i < channels; i++, src++, dst++)
                        *dst = System.Math.Abs(*src);

                    for (int i = channels; i < length; i++)
                    {
                        float abs = System.Math.Abs(*src);
                        *dst = dst[-channels] + Alpha * (abs - dst[-channels]);
                    }

                }
            }
        }
 private double[] getWholeSignal()
 {
     TempSignal = this.decoder.Decode(this.frames);
     double[] wholeSignal = new double[this.frames];
     TempSignal.CopyTo(wholeSignal);
     return wholeSignal;
 }
Beispiel #3
0
        /// <summary>
        ///   Create multichannel complex signal from floating-point matrix.
        /// </summary>
        /// 
        /// <param name="signal">Source multichannel float array (matrix).</param>
        /// 
        /// <returns>Returns an instance of complex signal.</returns>
        /// 
        public static ComplexSignal FromSignal(Signal signal)
        {
            if (signal.SampleFormat == SampleFormat.Format32BitIeeeFloat)
            {
                float[] buffer = new float[signal.Samples];
                Marshal.Copy(signal.Data, buffer, 0, buffer.Length);

                float[,] data = new float[signal.Length, signal.Channels];
                Buffer.BlockCopy(buffer, 0, data, 0, signal.Samples * sizeof(float));

                return FromArray(data, signal.SampleRate);
            }
            else if (signal.SampleFormat == SampleFormat.Format128BitComplex)
            {
                return new ComplexSignal(signal.RawData, signal.Channels,
                    signal.Length, signal.SampleRate);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Notifies client about new block of frames.
        /// </summary>
        /// 
        /// <param name="frame">New frame's audio.</param>
        /// 
        protected void OnNewFrame(Signal frame)
        {
            framesReceived++;

            if (NewFrame != null)
                NewFrame(this, new NewFrameEventArgs(frame));
        }
Beispiel #5
0
        private void initialize(Signal signal)
        {
            this.channels = signal.Channels;
            this.sampleRate = signal.SampleRate;
            this.sampleFormat = signal.SampleFormat;
            this.bitsPerSample = Signal.GetSampleSize(signal.SampleFormat);
            this.blockAlign = (bitsPerSample / 8) * channels;
            this.averageBitsPerSecond = sampleRate * blockAlign;

            this.initialized = true;
        }
Beispiel #6
0
        /// <summary>
        ///   Encodes the Wave stream into a Signal object.
        /// </summary>
        /// 
        public void Encode(Signal signal)
        {
            if (!initialized)
            {
                initialize(signal);
                firstWriteHeaders();
            }

            // Update counters
            numberOfSamples += signal.Samples;
            numberOfFrames += signal.Length;
            bytes += signal.RawData.Length;
            duration += signal.Duration;

            // Navigate to start position
            waveStream.Seek(0, SeekOrigin.Begin);

            // Update headers
            updateHeaders();

            // Go back to previous position
            waveStream.Seek(0, SeekOrigin.End);

            // Write the current signal data
            waveStream.Write(signal.RawData, 0, signal.RawData.Length);
        }
Beispiel #7
0
 /// <summary>
 ///   Displays a Wavechart with the specified signal.
 /// </summary>
 /// 
 /// <param name="signal">The signal object to display.</param>
 /// <param name="channel">The channel to be displayed.</param>
 /// <param name="nonBlocking">If set to <c>true</c>, the caller will continue
 /// executing while the form is shown on screen. If set to <c>false</c>,
 /// the caller will be blocked until the user closes the form. Default
 /// is <c>false</c>.</param>
 /// <param name="title">The title for the data window.</param>
 /// 
 /// <returns>The Data Grid Box being shown.</returns>
 /// 
 public static WavechartBox Show(Signal signal, int channel = 0,
     string title = "Wavechart", bool nonBlocking = false)
 {
     var tuple = Tuple.Create(signal, channel);
     return show(title, nonBlocking, tuple);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NewFrameEventArgs"/> class.
 /// </summary>
 ///
 /// <param name="signal">New signal frame.</param>
 ///
 public NewFrameEventArgs(Signal signal)
 {
     this.signal = signal;
 }
Beispiel #9
0
        private void initialize(Signal signal)
        {
            this.channels = signal.Channels;
            this.sampleRate = signal.SampleRate;
            this.bitsPerSample = sizeof(float) * 8;
            this.blockAlign = bitsPerSample / 8 * channels;
            this.averageBitsPerSecond = sampleRate * blockAlign;

            this.initialized = true;
        }
Beispiel #10
0
        void source_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            current = eventArgs.Signal;


            detector.Detect(current);

            if (initializing)
            {
                initializing = false;
                lbStatus.Invoke((MethodInvoker)delegate()
                {
                    label1.Text = "Frame duration (ms): " + current.Duration;
                    lbStatus.Text = "Ready";
                });
            } 
        }
        public void addNewFrame(Signal signal)
        {
            // Save current frame
            signal.CopyTo(current);

            // Save to memory
            this.encoder.Encode(signal);

            // Update counters
            this.duration += signal.Duration;
            this.samples += signal.Samples;
            this.frames += signal.Length;
        }