예제 #1
0
        public void XMLtoWav(string ruta, bool silencio = false)
        {
            Cancion song = new Cancion(ruta);
            int y = (Int32)Math.Round(song.duracion);
            int o = (Int32)Math.Ceiling( y * (44100 / 1000.0) + 6 * 44100.0);
            Canales main = new Canales(o);
            int Samplepos = 0;
            //Se agregan todas las notas al main
            foreach (Compas c in song.compases)
            {
                for (int i = 0; i < c.loop; i++)
                {
                    foreach (Nota n in c.notas)
                    {
                        var npos = Math.Round(((n.pos * 60 * (44100.0 / c.tempo)) + Samplepos));
                        main = incluirNota(main, n, (int)npos);
                    }
                    Samplepos += (int)Math.Round(c.duracion * (44100 / 1000.0));
                }
            }
            //Se normalizan los canales
            main.normalizar(silencio);

            List<short> leftSamples = new List<short>();
            List<short> rightSamples = new List<short>();
            for (int i = 0; i < main.left.Count; i++)
            {

                leftSamples.Add(Convert.ToInt16(main.left[i]));
                rightSamples.Add(Convert.ToInt16(main.right[i]));
            }
            SaveToWave(leftSamples, rightSamples, ruta.Slice(0,-3) + "wav", silencio);
        }
예제 #2
0
        public Canales incluirNota(Canales main, Nota nota, int pos)
        {
            string ruta = nota.ruta;

            List<short> lDataList = new List<short>();
            List<short> rDataList = new List<short>();

            using (FileStream fs = new FileStream(ruta, FileMode.Open, FileAccess.Read))
            using (BinaryReader br = new BinaryReader(fs))
            {
                br.ReadBytes(4);br.ReadUInt32();br.ReadBytes(4);br.ReadBytes(4); br.ReadUInt32();br.ReadUInt16(); br.ReadUInt16(); br.ReadUInt32(); br.ReadUInt32();
                var blockSize = br.ReadUInt16();
                br.ReadUInt16(); br.ReadBytes(4);
                var dataSize = br.ReadUInt32();

                for (int i = 0; i < dataSize / blockSize; i++)
                {
                    lDataList.Add((short)br.ReadUInt16());
                    rDataList.Add((short)br.ReadUInt16());
                }
                br.Close();
                fs.Close();
            }
            Canales channels = new Canales(lDataList, rDataList);

            for (int i = 0; i < channels.left.Count(); i++)
            {
                main.left[pos + i] += channels.left[i];
            }
            for (int i = 0; i < channels.right.Count(); i++)
            {
                main.right[pos + i] += channels.right[i];
            }

            return main;
        }