Пример #1
0
        private static IEnumerable <int> LoadRleData(WavStreamReader reader)
        {
            var list       = new List <int>();
            var smpCounter = 0;
            var state      = reader.ReadNext();

            for (var i = 0; i < reader.Count; i++)
            {
                var sample = reader.ReadNext();
                smpCounter++;
                if ((state < 0 && sample < 0) ||
                    (state >= 0 && sample >= 0))
                {
                    continue;
                }
                list.Add(smpCounter);
                smpCounter = 0;
                state      = sample;
            }
            return(list);
        }
Пример #2
0
        private static IEnumerable <ITapeBlock> Load(Stream stream, int tactsPerSecond)
        {
            var reader = new WavStreamReader(stream);

            var ratio = tactsPerSecond / (double)reader.Header.FmtSampleRate; // usually 3.5mhz / 44khz

            var rleData = LoadRleData(reader);

            var list         = new List <TapeBlock>();
            var pulses       = new List <int>();
            var blockTime    = 0;
            var blockCounter = 0;

            foreach (var rle in rleData)
            {
                var len = (int)Math.Round(rle * ratio, MidpointRounding.AwayFromZero);
                pulses.Add(len);

                blockTime += len;
                if (blockTime >= tactsPerSecond * 2)
                {
                    var tb = new TapeBlock();
                    tb.Description = string.Format("WAV-{0:D3}", blockCounter++);
                    tb.Periods     = new List <int>(pulses);
                    list.Add(tb);
                    blockTime = 0;
                    pulses.Clear();
                }
            }
            if (pulses.Count > 0)
            {
                var tb = new TapeBlock();
                tb.Description = string.Format("WAV-{0:D3}", blockCounter++);
                tb.Periods     = new List <int>(pulses);
                list.Add(tb);
            }
            return(list);
        }
Пример #3
0
        public override void Deserialize(Stream stream)
        {
            m_tape.Blocks.Clear();
            List<int> pulses = new List<int>();

            WavStreamReader reader = new WavStreamReader(stream);
            int rate = m_tape.TactsPerSecond / reader.Header.sampleRate; // usually 3.5mhz / 44khz
            int smpCounter = 0;
            int state = reader.ReadNext();
            for (int i = 0; i < reader.Count; i++)
            {
                int sample = reader.ReadNext();
                smpCounter++;
                if ((state < 0 && sample < 0) || (state >= 0 && sample >= 0))
                    continue;
                pulses.Add(smpCounter * rate);
                smpCounter = 0;
                state = sample;
            }
            pulses.Add(m_tape.TactsPerSecond / 10);

            TapeBlock tb = new TapeBlock();
            tb.Description = "WAV tape image";
            tb.Periods = pulses;
            m_tape.Blocks.Add(tb);
            m_tape.Reset();
        }