public void InverseFft(Gst.FFT.FFTF32Complex freqdata, float timedata) { IntPtr native_freqdata = GLib.Marshaller.StructureToPtrAlloc(freqdata); gst_fft_f32_inverse_fft(Handle, native_freqdata, timedata); Marshal.FreeHGlobal(native_freqdata); }
private void PCMHandoff(object o, GLib.SignalArgs args) { byte[] data; uint wanted_size; if (OnDataAvailable == null) { return; } if (vis_thawing) { // Flush our buffers out. vis_buffer.Clear(); System.Array.Clear(vis_fft_sample_buffer, 0, vis_fft_sample_buffer.Length); vis_thawing = false; } Caps caps = ((Gst.Pad)args.Args [1]).CurrentCaps; Structure structure = caps [0]; int channels = (int)structure.GetValue("channels").Val; wanted_size = (uint)(channels * SLICE_SIZE * sizeof(float)); //TODO see if buffer need a copy or not //but copy is no available in gst# ;( vis_buffer.Push((Gst.Buffer)args.Args[0]); int i, j; while ((data = vis_buffer.Map()) != null) { float[] buff = new float[data.Length]; float[] deinterlaced = new float [channels * SLICE_SIZE]; float[] specbuf = new float [SLICE_SIZE * 2]; System.Array.Copy(specbuf, vis_fft_sample_buffer, SLICE_SIZE); for (i = 0; i < SLICE_SIZE; i++) { float avg = 0.0f; for (j = 0; j < channels; j++) { float sample = buff[i * channels + j]; deinterlaced[j * SLICE_SIZE + i] = sample; avg += sample; } avg /= channels; specbuf[i + SLICE_SIZE] = avg; } System.Array.Copy(vis_fft_sample_buffer, 0, specbuf, SLICE_SIZE, SLICE_SIZE); vis_fft.Window(specbuf, Gst.FFT.FFTWindow.Hamming); vis_fft.Fft(specbuf, vis_fft_buffer); for (i = 0; i < SLICE_SIZE; i++) { float val; Gst.FFT.FFTF32Complex cplx = vis_fft_buffer[i]; val = cplx.R * cplx.R + cplx.I * cplx.I; val /= SLICE_SIZE * SLICE_SIZE; val = (float)(10.0f * System.Math.Log10((double)val)); val = (val + 60.0f) / 60.0f; if (val < 0.0f) { val = 0.0f; } specbuf[i] = val; } float [] flat = new float[channels * SLICE_SIZE]; System.Array.Copy(deinterlaced, flat, flat.Length); float [][] cbd = new float[channels][]; for (int k = 0; k < channels; k++) { float [] channel = new float[SLICE_SIZE]; System.Array.Copy(flat, k * SLICE_SIZE, channel, 0, SLICE_SIZE); cbd [k] = channel; } float [] spec = new float [SLICE_SIZE]; System.Array.Copy(specbuf, spec, SLICE_SIZE); try { OnDataAvailable(cbd, new float[][] { spec }); } catch (System.Exception e) { Log.Error("Uncaught exception during visualization data post.", e); } vis_buffer.Flush((uint)wanted_size); } }