コード例 #1
0
ファイル: AudioOut.cs プロジェクト: codefather-labs/JackSharp
        void ProcessAudio(ProcessBuffer processingChunk)
        {
            if (_playbackState != PlaybackState.Playing)
            {
                return;
            }
            int bufferCount = processingChunk.AudioOut.Length;

            if (bufferCount == 0)
            {
                return;
            }
            int bufferSize  = processingChunk.Frames;
            int floatsCount = bufferCount * bufferSize;
            int bytesCount  = floatsCount * sizeof(float);

            byte[] fromWave = new byte[bytesCount];

            _waveStream.Read(fromWave, 0, bytesCount);

            float[] interlacedSamples = new float[floatsCount];
            Buffer.BlockCopy(fromWave, 0, interlacedSamples, 0, bytesCount);
            for (int i = 0; i < floatsCount; i++)
            {
                interlacedSamples [i] = interlacedSamples [i] * _volume;
            }
            BufferOperations.DeinterlaceAudio(interlacedSamples, processingChunk.AudioOut, bufferSize, bufferCount);
        }
コード例 #2
0
ファイル: AudioOut.cs プロジェクト: codefather-labs/JackSharp
        void ProcessAudio(ProcessBuffer processingChunk)
        {
            if (_playbackState != PlaybackState.Playing)
            {
                return;
            }
            int bufferCount = processingChunk.AudioOut.Length;

            if (bufferCount == 0)
            {
                return;
            }
            int bufferSize  = processingChunk.Frames;
            int floatsCount = bufferCount * bufferSize;

            float[] interlacedSamples = new float[floatsCount];

            _sampleSource.Read(interlacedSamples, 0, floatsCount);

            for (int i = 0; i < floatsCount; i++)
            {
                interlacedSamples [i] = interlacedSamples [i] * _volume;
            }
            BufferOperations.DeinterlaceAudio(interlacedSamples, processingChunk.AudioOut, bufferSize, bufferCount);
        }
コード例 #3
0
        public void StringEvenLengthRoundTripTest(
            [RandomStrings(Count = 10, Pattern = "([0-9a-fA-F][0-9a-fA-F]){1,16}")] string byteString,
            [EnumData(typeof(Endianness))] Endianness endianness)
        {
            var bytes     = BufferOperations.FromByteString(byteString, endianness);
            var roundTrip = BufferOperations.ToByteString(bytes, endianness);

            Assert.AreEqual(byteString, roundTrip, StringComparison.OrdinalIgnoreCase);
        }
コード例 #4
0
        public static Hash256 Parse(string hashString)
        {
            ContractsCommon.NotNull(hashString, "hashString");
            Contract.Requires <FormatException>(hashString.Trim().Length == HASH_LEN * 2, "Hash string not of expected length.");
            ContractsCommon.ResultIsNonNull <Hash256>();

            var bytes = BufferOperations.FromByteString(hashString.Trim(), Endianness.LittleEndian);

            return(new Hash256(bytes));
        }
コード例 #5
0
        public static string FormatByteArray(byte[] array)
        {
            var byteStr = BufferOperations.ToByteString(array, Endianness.BigEndian);

            if (byteStr.Length > 30)
            {
                byteStr = byteStr.Substring(0, 28) + "...";
            }
            return(byteStr);
        }
コード例 #6
0
 public static byte[] ConvertStringToByteArray(string s)
 {
     if (s.StartsWith("0x"))
     {
         return(BufferOperations.FromByteString(s.Substring(2), Endianness.BigEndian));
     }
     else
     {
         return(BufferOperations.FromByteString(s, Endianness.LittleEndian));
     }
 }
コード例 #7
0
        void ProcessAudio(ProcessBuffer processingChunk)
        {
            int bufferCount = processingChunk.AudioIn.Length;

            if (bufferCount == 0)
            {
                return;
            }
            int bufferSize  = processingChunk.AudioIn [0].BufferSize;
            int floatsCount = bufferCount * bufferSize;
            int bytesCount  = floatsCount * sizeof(float);

            float[] interlacedSamples = BufferOperations.InterlaceAudio(processingChunk.AudioIn, bufferSize, bufferCount);
            byte[]  waveInData        = new byte[bytesCount];
            Buffer.BlockCopy(interlacedSamples, 0, waveInData, 0, bytesCount);
            if (DataAvailable != null)
            {
                DataAvailable(this, new WaveInEventArgs(waveInData, bytesCount));
            }
        }
コード例 #8
0
ファイル: Script.cs プロジェクト: neoeinstein/xpdm.Bitcoin
        public static Script Parse(string scriptString)
        {
            var           atoms    = scriptString.Split(' ');
            var           script   = new Script();
            StringBuilder valueStr = null;

            foreach (var atom in atoms)
            {
                IScriptAtom newAtom = null;
                if (valueStr != null)
                {
                    valueStr.Append(" ");
                    if (atom.EndsWith("'"))
                    {
                        if (atom.EndsWith(@"\''"))
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 3));
                            valueStr.Append("'");
                            var valueBytes = Encoding.ASCII.GetBytes(valueStr.ToString());
                            newAtom = new ValueAtom(valueBytes);
                            script.Atoms.Add(newAtom);
                            valueStr = null;
                        }
                        else if (atom.EndsWith(@"\'"))
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 2));
                            valueStr.Append("'");
                        }
                        else
                        {
                            valueStr.Append(atom.Substring(0, atom.Length - 1));
                            var valueBytes = Encoding.ASCII.GetBytes(valueStr.ToString());
                            newAtom = new ValueAtom(valueBytes);
                            script.Atoms.Add(newAtom);
                            valueStr = null;
                        }
                    }
                    else
                    {
                        valueStr.Append(atom);
                    }
                    continue;
                }
                if (atom.StartsWith("OP_"))
                {
                    var opcode = (ScriptOpCode)Enum.Parse(typeof(ScriptOpCode), atom, false);
                    newAtom = ScriptAtomFactory.GetOpAtom(opcode);
                }
                else if (atom.StartsWith("'"))
                {
                    if (atom.EndsWith("'"))
                    {
                        if (atom.EndsWith(@"\''"))
                        {
                            var valueBytes = Encoding.ASCII.GetBytes(atom.Substring(1, atom.Length - 4) + "'");
                            newAtom = new ValueAtom(valueBytes);
                        }
                        else if (atom.EndsWith(@"\'"))
                        {
                            valueStr = new StringBuilder();
                            valueStr.Append(atom.Substring(1, atom.Length - 3));
                            valueStr.Append("'");
                        }
                        else if (atom.Length > 1)
                        {
                            if (atom.Length > 2)
                            {
                                var valueBytes = Encoding.ASCII.GetBytes(atom.Substring(1, atom.Length - 2));
                                newAtom = new ValueAtom(valueBytes);
                            }
                        }
                        else
                        {
                            valueStr = new StringBuilder();
                        }
                    }
                    else
                    {
                        valueStr = new StringBuilder();
                        valueStr.Append(atom.Substring(1, atom.Length - 1));
                    }
                }
                else if (atom.Length > 0)
                {
                    var valueBytes = BufferOperations.FromByteString(atom, Endianness.BigEndian);
                    newAtom = new ValueAtom(valueBytes);
                }
                if (newAtom != null)
                {
                    script.Atoms.Add(newAtom);
                }
            }
            if (valueStr != null)
            {
                throw new FormatException("Unclosed script string found");
            }
            script.Freeze();
            return(script);
        }