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);
        }
Beispiel #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();
        }
Beispiel #3
0
        // dump whole file
        public CopyFile(string file)
            : base(file)
        {
            Console.Write("Copying...");
            outStream_ = new FlacStream(file + ".copy.flac", FlacStream.StreamMode.CreateNew, FlacStream.StreamAccessMode.Both);
            outStream_.Encode();

            stream_.Decode();

            Done();
        }
        public VirtualFlacTrack(string flacImage, VirtualTrack track)
        {
            track_ = track;

            inStream_ = new FlacStream(flacImage, FlacStream.StreamMode.OpenExisting, FlacStream.StreamAccessMode.Read);
            inStream_.BeforeFrameDataRead += new FrameCallback(inStream__BeforeFrameDataRead);
            inStream_.Decode();
            outStream_ = new FlacStream(Path.GetTempFileName(), FlacStream.StreamMode.CreateNew, FlacStream.StreamAccessMode.Both);

            ReadHeader();
        }
Beispiel #5
0
        protected ProcessFile(string file, bool noCallback)
        {
            watch_.Start();
            stream_ = new FlacStream(file, FlacStream.StreamMode.OpenExisting, FlacStream.StreamAccessMode.Read);

            length_ = new System.IO.FileInfo(file).Length;

            if (noCallback)
            {
            }
            else
            {
                stream_.MetadataRead += new MetadataCallback(stream__MetadataRead);
                stream_.BeforeFrameDataRead += new FrameCallback(stream__BeforeFrameDataRead);
            }
        }
        private void ProcessFrame(FlacStream inStream, Frame frame, long offset)
        {
            long startSample = frame.Header.StartingSampleNumber;
            long endSample = startSample + frame.Header.BlockSize;
            int frameSize = (int)(inStream.Reader.Debug_BytesRead - offset);

            if (blockingStrategy_ == -1)
            {
                blockingStrategy_ = frame.Header.BlockingStrategy;
            }
            else
            {
                // whole stream must have the same blocking strategy
                Debug.Assert(frame.Header.BlockingStrategy == blockingStrategy_);
            }

            if (currentTrack_ != null)
            {
                long start = startSample;
                long end = endSample;

                if (start <= currentTrack_.EndSample && currentTrack_.EndSample <= end)
                {
                    end = currentTrack_.EndSample;
                    WriteFrame(frame, currentTrack_, start, end, frameSize, startSample, offset);
                    currentTrack_.TotalSamples = sampleCount_;

                    currentTrack_.Frames.Values[0].CalculateVirtualBlockSizeDifference(currentTrack_.StartSample, true);
                    currentTrack_.Frames.Values[currentTrack_.Frames.Count - 1].CalculateVirtualBlockSizeDifference(currentTrack_.EndSample, false);

                    RefreshFrame(inStream, ref frame, offset);
                    currentTrack_ = null;
                    goto loop;
                }
                else
                {
                    WriteFrame(frame, currentTrack_, start, end, frameSize, startSample, offset);
                    goto done;
                }
            }
            else
            {
                goto loop;
            }

            loop:
            foreach (ITrackInfo file in tracksInfo_)
            {
                long start = startSample;
                long end = endSample;
                if (start <= file.StartSample && file.StartSample <= end)
                {
                    VirtualTrack lastTrack = null;
                    if (virtualTracks_.Count > 0)
                    {
                        lastTrack = virtualTracks_[virtualTracks_.Count - 1];
                    }
                    if (lastTrack != null)
                    {
                        Debug.Assert(lastTrack.Frames.Values[lastTrack.Frames.Count - 1].imageEndSample == endSample);
                    }

                    currentTrack_ = new VirtualTrack();
                    currentTrack_.StartSample =file.StartSample;
                    currentTrack_.EndSample = file.EndSample;
                    currentTrack_.FileName = file.Name;
                    currentTrack_.Size = TRACK_HEADER_SIZE;
                    virtualTracks_.Add(currentTrack_);

                    sampleCount_ = 0;

                    start = file.StartSample;

                    bool next = false;
                    if (start <= file.EndSample && file.EndSample <= end)
                    {
                        // track ends in the same frame
                        end = file.EndSample;

                        // write (probably) partial first frame of track
                        WriteFrame(frame, currentTrack_, start, end, frameSize, startSample, offset);
                        RefreshFrame(inStream, ref frame, offset);
                        next = true;
                    }
                    else
                    {
                        // write (probably) partial first frame of track
                        WriteFrame(frame, currentTrack_, start, end, frameSize, startSample, offset);
                    }
                    if (next)
                    {
                        continue;
                    }
                    break;
                }
            }
            done:
            return;
        }
        private void RefreshFrame(FlacStream inStream, ref Frame frame, long offset)
        {
            inStream_.Reader.Seek(offset);

            frame = new Frame();
            frame.ReadHeader(inStream);
            frame.ReadData(inStream);
            frame.ReadFooter(inStream);
        }
 public FrameCallbackArgs(Frame frame, FlacStream stream)
 {
     frame_ = frame;
     stream_ = stream;
 }