Example #1
0
    /// <summary>
    /// Filter out silence or noise from start and end of wave file. 
    /// </summary>
    /// <param name="strPath">Source wave file</param>
    /// <param name="noiceLevel">Absolute value for noice threshold</param>
    /// <returns>True/False</returns>
    public bool StripSilence(string strPath, int noiceLevel)
    {
        if ((strPath == null) || (strPath == ""))
            return false;

        // Read from file 
        wavProcessor wain = new wavProcessor();
        if (!wain.WaveHeaderIN(@strPath)) return false;
        byte[] arrfile = GetWAVEData(strPath);

        int startpos = 0;
        int endpos = arrfile.Length - 1;

        // Check for silence at start
        for (int j = 0; isSilence(arrfile, j, noiceLevel); j += 20)
            startpos = j;

        // Allow room for tone-in buffer
        int buffer = wain.SampleRate * (wain.BitsPerSample / 8) / 32; // 1/32 seconds lead time
        startpos = startpos - buffer;
        if (startpos < 0)
            startpos = 0;

        // Check for silence at end. No need to check tone out buffer
        for (int k = arrfile.Length - buffer; (k >= 0) && (isSilence(arrfile, k, noiceLevel)); k -= 20)
            endpos = k;

        // Allow room for tone-out buffer
        endpos = endpos + buffer;
        if (endpos > arrfile.Length)
            endpos = arrfile.Length - 2;

        if (startpos >= endpos)
            return false;

        byte[] newarr = new byte[endpos - startpos];
        for (int ni = 0, m = startpos; ni < newarr.Length; m++, ni++)
            newarr[ni] = arrfile[m];

        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);
        writer.Write(newarr, newarr.Length);
        writer.Close();

        return true;
    }
Example #2
0
        public unsafe void WriteAudio(float *left, float *right, int count)
        {
            //Write to file
            test.Write(left, right, count);

            //Copy and zipper
            for (int i = 0; i < count; i++)
            {
                audioOutputPtr[(i * 2)]     = *left * audioVolume;
                audioOutputPtr[(i * 2) + 1] = *right * audioVolume;
                left++;
                right++;
            }

            //Write
            audioProvider.AddSamples(audioOutputBuffer, 0, count * 2 * sizeof(float));
        }
Example #3
0
    /// <summary>
    /// Speed up wav file to mimic Donald Duck
    /// </summary>
    /// <param name="strPath">Source wave</param>
    /// <param name="speed">Speed between 0 and 19 </param>
    /// <returns>True/False</returns>
    public bool SpeedUp(string strPath, int speed)
    {
        if ((strPath == null) || (strPath == ""))
        {
            return(false);
        }

        if ((speed < 0) || (speed > 19))
        {
            return(false);
        }

        // Read from file
        wavProcessor wain = new wavProcessor();

        if (!wain.WaveHeaderIN(@strPath))
        {
            return(false);
        }
        byte[] arrfile = GetWAVEData(strPath);
        byte[] newfile = new byte[arrfile.Length];

        int skip = 21 - speed;
        int j    = 0;

        for (int i = 0; i < arrfile.Length; i += 2)
        {
            if (skip > 20 || (((i / 2) % skip) != 0))
            {
                newfile[j]     = arrfile[i];
                newfile[j + 1] = arrfile[i + 1];
                j += 2;
            }
        }
        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);

        writer.Write(newfile, j);
        writer.Close();
        return(true);
    }
Example #4
0
        static void Main(string[] args)
        {
            LibUSBProvider provider = new LibUSBProvider();
            var            testd    = provider.FindDevices(0x1d50, 0x60a1)[0];

            testd.OpenDevice();

            var b     = new LibSDR.Components.IO.USB.UsbBuffer(512);
            int testr = testd.BulkTransfer(LibSDR.Components.IO.USB.UsbTransferDirection.READ, 0x01, b, 1000);


            AirSpyDevice device = AirSpyDevice.OpenDevice(provider);

            device.StartRx();
            device.SampleRate = 10000000;
            //device.SampleRate = 3000000;

            if (true)
            {
                device.CenterFrequency = 93700000;
                device.SetLinearGain(6 / 21f);
            }
            else
            {
                device.CenterFrequency = 144430000;
                device.SetLinearGain(2 / 21f);
            }

            test = new WavFileWriter(new FileStream("F:\\test.wav", FileMode.Create), (int)device.SampleRate, 2, LibSDR.Components.IO.SampleFormat.Short16, 1 << 16);

            UnsafeBuffer buffer = UnsafeBuffer.Create(1 << 16, out Complex * bufferPtr);

            while (true)
            {
                int read = device.Read(bufferPtr, 1 << 16, 1000);
                test.Write(bufferPtr, read);
                test.FinalizeFile();
            }
        }
Example #5
0
    /// <summary>
    /// Tone out wav file
    /// </summary>
    /// <param name="strPath">Source wave</param>
    /// <returns>True/False</returns>
    public bool ToneOut(string strPath)
    {
        if ((strPath == null) || (strPath == ""))
        {
            return(false);
        }

        // Read from file
        wavProcessor wain = new wavProcessor();

        if (!wain.WaveHeaderIN(@strPath))
        {
            return(false);
        }
        byte[] arrfile = GetWAVEData(strPath);

        // Calculate constants
        int end   = wain.Length;
        int start = end - (wain.SampleRate * (wain.BitsPerSample / 8) / 16); // 1/16 seconds from end
        int span  = end - start;

        //change volume
        for (int j = start; j < arrfile.Length; j += 2)
        {
            short snd = ComplementToSigned(ref arrfile, j);
            snd = Convert.ToInt16(snd * (end - j) / span);

            byte[] newval = SignedToComplement(snd);
            arrfile[j]     = newval[0];
            arrfile[j + 1] = newval[1];
        }
        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);

        writer.Write(arrfile, arrfile.Length);
        writer.Close();

        return(true);
    }
            public unsafe void Write(byte *ptr, int read)
            {
                //Convert
                float *fPtr = (float *)ptr;

                read /= sizeof(float);

                //Clamp
                for (int i = 0; i < read; i++)
                {
                    if (fPtr[i] > 1)
                    {
                        fPtr[i] = 1;
                    }
                    if (fPtr[i] < -1)
                    {
                        fPtr[i] = -1;
                    }
                }

                //Write
                wav.Write(fPtr, read);
            }
Example #7
0
 public unsafe void WriteAudio(float *left, float *right, int count)
 {
     test.Write(left, right, count);
 }
Example #8
0
 private static void Device_OnSamples(LibSDR.Components.Interfaces.IRadioDevice device, Complex *ptr, int count)
 {
     test.Write(ptr, count);
     test.FinalizeFile();
 }
Example #9
0
    /// <summary>
    /// Filter out silence or noise from start and end of wave file.
    /// </summary>
    /// <param name="strPath">Source wave file</param>
    /// <param name="noiceLevel">Absolute value for noice threshold</param>
    /// <returns>True/False</returns>
    public bool StripSilence(string strPath, int noiceLevel)
    {
        if ((strPath == null) || (strPath == ""))
        {
            return(false);
        }

        // Read from file
        wavProcessor wain = new wavProcessor();

        if (!wain.WaveHeaderIN(@strPath))
        {
            return(false);
        }
        byte[] arrfile = GetWAVEData(strPath);

        int startpos = 0;
        int endpos   = arrfile.Length - 1;

        // Check for silence at start
        for (int j = 0; isSilence(arrfile, j, noiceLevel); j += 20)
        {
            startpos = j;
        }

        // Allow room for tone-in buffer
        int buffer = wain.SampleRate * (wain.BitsPerSample / 8) / 32; // 1/32 seconds lead time

        startpos = startpos - buffer;
        if (startpos < 0)
        {
            startpos = 0;
        }

        // Check for silence at end. No need to check tone out buffer
        for (int k = arrfile.Length - buffer; (k >= 0) && (isSilence(arrfile, k, noiceLevel)); k -= 20)
        {
            endpos = k;
        }

        // Allow room for tone-out buffer
        endpos = endpos + buffer;
        if (endpos > arrfile.Length)
        {
            endpos = arrfile.Length - 2;
        }

        if (startpos >= endpos)
        {
            return(false);
        }

        byte[] newarr = new byte[endpos - startpos];
        for (int ni = 0, m = startpos; ni < newarr.Length; m++, ni++)
        {
            newarr[ni] = arrfile[m];
        }

        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);

        writer.Write(newarr, newarr.Length);
        writer.Close();

        return(true);
    }
Example #10
0
 private void DataArrived(IntPtr data, int size)
 {
     Marshal.Copy(data, recordingBuffer, 0, size);
     filewriter.Write(recordingBuffer, size);
 }
Example #11
0
    /// <summary>
    /// Tone in wav file
    /// </summary>
    /// <param name="strPath">Source wave</param>
    /// <returns>True/False</returns>
    public bool ToneIn(string strPath)
    {
        if ((strPath == null) || (strPath == ""))
            return false;

        // Read from file
        wavProcessor wain = new wavProcessor();
        if (!wain.WaveHeaderIN(@strPath)) return false;
        byte[] arrfile = GetWAVEData(strPath);

        // Calculate constants
        int start = 0;
        int end = wain.SampleRate * (wain.BitsPerSample / 8) / 16; // 1/16 seconds
        int span = end - start;

        //change volume
        for (int j = start; j < end; j += 2)
        {
            short snd = ComplementToSigned(ref arrfile, j);
            snd = Convert.ToInt16(snd * (j / span));
            byte[] newval = SignedToComplement(snd);
            arrfile[j] = newval[0];
            arrfile[j + 1] = newval[1];
        }
        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);
        writer.Write(arrfile, arrfile.Length);
        writer.Close();

        return true;
    }
Example #12
0
    /// <summary>
    /// Speed up wav file to mimic Donald Duck
    /// </summary>
    /// <param name="strPath">Source wave</param>
    /// <param name="speed">Speed between 0 and 19 </param>
    /// <returns>True/False</returns>
    public bool SpeedUp(string strPath, int speed)
    {
        if ((strPath == null) || (strPath == ""))
            return false;

        if ((speed < 0) || (speed > 19))
            return false;

        // Read from file
        wavProcessor wain = new wavProcessor();
        if (!wain.WaveHeaderIN(@strPath)) return false;
        byte[] arrfile = GetWAVEData(strPath);
        byte[] newfile = new byte[arrfile.Length];

        int skip = 21-speed;
        int j = 0;
        for (int i = 0; i < arrfile.Length; i += 2)
        {
            if (skip > 20 || (((i/2) % skip) != 0))
            {
                newfile[j] = arrfile[i];
                newfile[j + 1] = arrfile[i + 1];
                j += 2;
            }
        }
        // write file back
        WavFileWriter writer = new WavFileWriter(@strPath, wain.SampleRate, wain.BitsPerSample, wain.Channels);
        writer.Write(newfile, j);
        writer.Close();
        return true;
    }