Exemplo n.º 1
0
        /// <summary>
        /// DeSerialization method
        /// </summary>
        public override void Read(byte[] data)
        {
            // clear existing tape blocks
            _datacorder.DataBlocks.Clear();

            // check whether this is a valid pzx format file by looking at the identifier in the header block
            string ident = Encoding.ASCII.GetString(data, 8, 4);

            if (ident.ToUpper() != "WAVE")
            {
                // this is not a valid TZX format file
                throw new Exception(this.GetType().ToString() +
                                    "This is not a valid WAV format file");
            }

            //_position = 0;

            MemoryStream stream = new MemoryStream();

            stream.Write(data, 0, data.Length);
            stream.Position = 0;

            WavStreamReader reader = new WavStreamReader(stream);

            int rate       = (69888 * 50) / reader.Header.sampleRate;
            int smpCounter = 0;
            int state      = reader.ReadNext();

            // create the single tape block
            TapeDataBlock t = new TapeDataBlock();

            t.BlockDescription = BlockType.WAV_Recording;
            t.BlockID          = 0;
            t.DataPeriods      = new List <int>();

            for (int i = 0; i < reader.Count; i++)
            {
                int sample = reader.ReadNext();
                smpCounter++;
                if ((state < 0 && sample < 0) || (state >= 0 && sample >= 0))
                {
                    continue;
                }
                t.DataPeriods.Add(smpCounter * rate);
                smpCounter = 0;
                state      = sample;
            }

            // add closing period
            t.DataPeriods.Add((69888 * 50) / 10);

            // add to datacorder
            _datacorder.DataBlocks.Add(t);
        }
Exemplo n.º 2
0
        /// <summary>
        /// DeSerialization method
        /// </summary>
        public override void Read(byte[] data)
        {
            // clear existing tape blocks
            _datacorder.DataBlocks.Clear();

            // check whether this is a valid pzx format file by looking at the identifier in the header block
            string ident = Encoding.ASCII.GetString(data, 8, 4);

            if (ident.ToUpper() != "WAVE")
            {
                // this is not a valid TZX format file
                throw new Exception(this.GetType().ToString() +
                                    "This is not a valid WAV format file");
            }

            //_position = 0;

            MemoryStream stream = new MemoryStream();

            stream.Write(data, 0, data.Length);
            stream.Position = 0;

            WavStreamReader reader = new WavStreamReader(stream);

            const double d          = /*69888.0*/ 70000.0 * 50.0;
            int          rate       = (int)(d / reader.Header.sampleRate);
            int          smpCounter = 0;
            int          state      = reader.ReadNext();

            // create the single tape block
            TapeDataBlock t = new TapeDataBlock();

            t.BlockDescription = BlockType.WAV_Recording;
            t.BlockID          = 0;
            t.DataPeriods      = new List <int>();
            t.DataLevels       = new List <bool>();

            bool currLevel = false;

            for (int i = 0; i < reader.Count; i++)
            {
                int sample = reader.ReadNext();
                smpCounter++;
                if ((state < 0 && sample < 0) || (state >= 0 && sample >= 0))
                {
                    continue;
                }
                t.DataPeriods.Add((int)(((double)smpCounter * (double)rate) / (double)0.9838560885608856));
                currLevel = !currLevel;
                t.DataLevels.Add(currLevel);
                smpCounter = 0;
                state      = sample;
            }

            // add closing period
            t.DataPeriods.Add((69888 * 50) / 10);
            currLevel = false;
            t.DataLevels.Add(currLevel);

            // add to datacorder
            _datacorder.DataBlocks.Add(t);

            /* debug stuff
             *
             * StringBuilder export = new StringBuilder();
             * foreach (var b in _datacorder.DataBlocks)
             * {
             *      for (int i = 0; i < b.DataPeriods.Count(); i++)
             *      {
             *              export.Append(b.DataPeriods[i].ToString());
             *              export.Append("\t\t");
             *              export.AppendLine(b.DataLevels[i].ToString());
             *      }
             * }
             *
             * string o = export.ToString();
             */
        }