Exemplo n.º 1
0
        public VirtualFlacCreator(string file, string flacImageFileName, ITrackInfo [] tracksInfo)
        {
            tracksInfo_ = tracksInfo;

            string xml = String.Format("<virtualFlac><flacImage uri=\"{0}\"><tracks></tracks><frames></frames></flacImage></virtualFlac>", flacImageFileName);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            inStream_ = new FlacStream(file, FlacStream.StreamMode.OpenExisting, FlacStream.StreamAccessMode.Read);
            inStream_.BeforeFrameDataRead += new FrameCallback(inStream__BeforeFrameDataRead);

            outStream_ = new FlacStream(Path.GetTempFileName(), FlacStream.StreamMode.CreateNew, FlacStream.StreamAccessMode.Write);
            inStream_.Decode();
            outStream_.Close();

            XmlNode tracks = doc.SelectSingleNode("/virtualFlac/flacImage/tracks");
            foreach (VirtualTrack vt in virtualTracks_)
            {
                XmlNode track = doc.CreateElement("track");
                vt.SaveToXml(track);

                tracks.AppendChild(track);
            }

            string virtualFlacFile = file.Remove(file.Length - ".flac".Length) + ".virtualflac";
            doc.Save(virtualFlacFile);
        }
Exemplo n.º 2
0
        public ExtractTrack(string file, long startSample, long endSample)
            : base(file)
        {
            startSample_ = startSample;
            endSample_ = endSample;

            string destFile = file + "." + startSample + ".flac";

            Console.Write("Extracting...");
            outStream_ = new FlacStream(destFile, FlacStream.StreamMode.CreateNew, FlacStream.StreamAccessMode.Both);
            outStream_.Encode();

            stream_.Decode();

            stream_.Close();
            outStream_.Close();

            outStream_ = new FlacStream(destFile, FlacStream.StreamMode.OpenExisting, FlacStream.StreamAccessMode.Both);

            outStream_.Encode();

            streamInfo_.Header.IsLastMetadataBlock = true;
            streamInfo_.TotalSamples = sampleCount_;
            streamInfo_.Checksum[0] = 0;
            streamInfo_.Checksum[1] = 0;
            streamInfo_.Checksum[2] = 0;
            streamInfo_.Checksum[3] = 0;
            streamInfo_.Write(outStream_);

            outStream_.Close();

            Done();
        }