Beispiel #1
0
        public void SaveCueSheetWithoutTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    cueSheet.Tracks.Clear();

                    // The save should not allow this since we must have at least a lead-out track.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #2
0
        public void SaveCueSheetWithoutCorrectLeadOutTrack()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack  = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.TrackNumber   = (byte)(55); // a non-lead-out track

                    flac.CueSheet.Tracks.Add(newTrack);  // Add the track as last track ...

                    // The save should not allow this.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #3
0
        public void CueSheetVorbisCommentShouldBeInProperty()
        {
            var cueSheetPath = Path.Combine("Data", "cuesheet.txt");
            var cueSheetData = File.ReadAllText(cueSheetPath);

            string origFile = Path.Combine("Data", "testfile5.flac");
            string newFile  = Path.Combine("Data", "testfile5_temp.flac");

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac")))
            {
                var vorbisComment = new VorbisComment();

                vorbisComment["CUESHEET"] = new VorbisCommentValues(cueSheetData);

                file.Metadata.Add(vorbisComment);

                file.Save();
            }

            using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac")))
            {
                var cueSheetDataFromFile = file.VorbisComment.CueSheet;
                Assert.AreEqual(cueSheetData, cueSheetDataFromFile.Value);
            }
        }
Beispiel #4
0
        public void WritingTwoArtistsShouldResultInTwoArtistsRead()
        {
            string origFile = Path.Combine("Data", "testfile5.flac");
            string newFile  = Path.Combine("Data", "testfile5_temp.flac");

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac")))
            {
                var vorbisComment = new VorbisComment();

                vorbisComment["ARTIST"] = new VorbisCommentValues(new string[] { "Artist A", "Artist B" });

                file.Metadata.Add(vorbisComment);

                file.Save();
            }

            using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac")))
            {
                Assert.IsNotNull(file.VorbisComment);
                var artistValues = file.VorbisComment["ARTIST"];
                Assert.AreEqual(2, artistValues.Count);
                Assert.AreEqual("Artist A", artistValues[0]);
                Assert.AreEqual("Artist B", artistValues[1]);
            }
        }
        public void SaveShouldNotClearAccessRights()
        {
            using (var file = new FlacFile(testFile))
            {
                file.Save();
            }

            Assert.IsTrue(EveryoneHasReadAccess(testFile), "Test file lost Everyone Read access after save.");
        }
Beispiel #6
0
        public void AddMultipleVorbisFields()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile  = @"Data\testfile1_temp.flac";

            // Tests if we can load up a flac file, update the artist and title in the vorbis comments
            // save the file and then reload the file and see the changes.
            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    flac.VorbisComment["ARTIST"] = new VorbisCommentValues();
                    flac.VorbisComment["ARTIST"].Add("Aaron");
                    flac.VorbisComment["ARTIST"].Add("dgadelha");

                    flac.VorbisComment["TITLE"] = new VorbisCommentValues(new string[] { "Title A", "Title B", "Title C" });

                    flac.VorbisComment["ALBUM"] = new VorbisCommentValues("Album");

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var values = flac.VorbisComment["ARTIST"];
                    Assert.AreEqual(2, values.Count);
                    Assert.AreEqual("Aaron", values[0]);
                    Assert.AreEqual("dgadelha", values[1]);

                    values = flac.VorbisComment["TITLE"];
                    Assert.AreEqual(3, values.Count);
                    Assert.AreEqual("Title A", values[0]);
                    Assert.AreEqual("Title B", values[1]);
                    Assert.AreEqual("Title C", values[2]);

                    var value = flac.VorbisComment["TITLE"].Value;
                    Assert.AreEqual("Title A", value);

                    values = flac.VorbisComment["ALBUM"];
                    Assert.AreEqual(1, values.Count);
                    Assert.AreEqual("Album", values[0]);

                    value = flac.VorbisComment["ALBUM"].Value;
                    Assert.AreEqual("Album", value);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #7
0
        public void AddMultipleVorbisFields()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile = @"Data\testfile1_temp.flac";
            // Tests if we can load up a flac file, update the artist and title in the vorbis comments
            // save the file and then reload the file and see the changes.
            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    flac.VorbisComment["ARTIST"] = new VorbisCommentValues();
                    flac.VorbisComment["ARTIST"].Add("Aaron");
                    flac.VorbisComment["ARTIST"].Add("dgadelha");

                    flac.VorbisComment["TITLE"] = new VorbisCommentValues(new string[] { "Title A", "Title B", "Title C" });

                    flac.VorbisComment["ALBUM"] = new VorbisCommentValues("Album");

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var values = flac.VorbisComment["ARTIST"];
                    Assert.AreEqual(2, values.Count);
                    Assert.AreEqual("Aaron", values[0]);
                    Assert.AreEqual("dgadelha", values[1]);

                    values = flac.VorbisComment["TITLE"];
                    Assert.AreEqual(3, values.Count);
                    Assert.AreEqual("Title A", values[0]);
                    Assert.AreEqual("Title B", values[1]);
                    Assert.AreEqual("Title C", values[2]);

                    var value = flac.VorbisComment["TITLE"].Value;
                    Assert.AreEqual("Title A", value);

                    values = flac.VorbisComment["ALBUM"];
                    Assert.AreEqual(1, values.Count);
                    Assert.AreEqual("Album", values[0]);

                    value = flac.VorbisComment["ALBUM"].Value;
                    Assert.AreEqual("Album", value);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #8
0
        public void CreateSeekTable()
        {
            ulong expectedNumberOfSamples; // Will be set while creating a new seekpoint
            ulong expectedByteOffset;      // Will be set while creating a new seekpoint

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                SeekTable seekTable = new SeekTable();
                flac.Metadata.Add(seekTable);

                // Create a new Seekpoint, a little further
                SeekPoint newSeekpoint = new SeekPoint();
                newSeekpoint.FirstSampleNumber = 1000;
                newSeekpoint.NumberOfSamples   = (ushort)1000;
                expectedNumberOfSamples        = newSeekpoint.NumberOfSamples;
                newSeekpoint.ByteOffset        = 0;
                expectedByteOffset             = newSeekpoint.ByteOffset;
                seekTable.SeekPoints.Add(newSeekpoint);

                // Create a placeholder seekpoint
                SeekPoint placeHolder = new SeekPoint();
                placeHolder.FirstSampleNumber = ulong.MaxValue;
                // The other two values are "undefined"
                Assert.IsTrue(placeHolder.IsPlaceHolder); // Already assert that the object itself handles this flac correctly.
                seekTable.SeekPoints.Add(placeHolder);

                // This should actually be allowed according to the FLAC format (multiple placeHolders are ok, but they must occur at the end of the seektable)
                seekTable.SeekPoints.Add(placeHolder);

                // Check if we actually get "2" placeholders ...
                Assert.AreEqual <int>(2, seekTable.SeekPoints.Placeholders);

                flac.Save();
            }
            using (FlacFile flac = new FlacFile(newFile))
            {
                // Now we want to try and find our new SeekPoint
                Assert.IsNotNull(flac.SeekTable);

                Assert.IsTrue(flac.SeekTable.SeekPoints.ContainsKey(1000));
                SeekPoint newSeekpoint = flac.SeekTable.SeekPoints[1000];

                Assert.AreEqual <ulong>(expectedNumberOfSamples, newSeekpoint.NumberOfSamples);
                Assert.AreEqual <ulong>(expectedByteOffset, newSeekpoint.ByteOffset);

                Assert.IsFalse(newSeekpoint.IsPlaceHolder);

                // Check if we actually get "2" placeholders ...
                Assert.AreEqual <int>(2, flac.SeekTable.SeekPoints.Placeholders);
            }
        }
Beispiel #9
0
        public void CreateInvalidCueSheet()
        {
            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet sheet = new CueSheet();

                flac.Metadata.Add(sheet);

                flac.Save();
            }
        }
Beispiel #10
0
        public void CreateInvalidCueSheet()
        {
            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet sheet = new CueSheet();

                flac.Metadata.Add(sheet);

                flac.Save();
            }
        }
Beispiel #11
0
        public void CopyOpenEditAndSavePadding()
        {
            UInt32 newPaddingSize = 8 * 2; // 2 bytes of padding

            string origFile = @"Data\testfile1.flac";
            string newFile  = @"Data\testfile1_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Padding paddingBlock = null;
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            paddingBlock = (Padding)block;
                        }
                    }

                    paddingBlock.EmptyBitCount = newPaddingSize; // Set empty bytes to 2

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Padding paddingBlock = null;
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            paddingBlock = (Padding)block;
                        }
                    }

                    Assert.IsNotNull(paddingBlock);

                    Assert.AreEqual <UInt32>(newPaddingSize, paddingBlock.EmptyBitCount);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #12
0
        public void OpenFlacFileAndCreateMultipleApplicationInfo()
        {
            int    appInfoCount = 0;
            string origFile     = @"Data\testfile3.flac";
            string newFile      = @"Data\testfile3_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.ApplicationInfo != null)
                    {
                        appInfoCount = 1;
                    }

                    ApplicationInfo appInfo = new ApplicationInfo();
                    appInfo.ApplicationID   = 10;
                    appInfo.ApplicationData = new byte[] { 10, 20, 30 };

                    flac.Metadata.Add(appInfo);

                    appInfo = new ApplicationInfo();
                    appInfo.ApplicationID   = 20;
                    appInfo.ApplicationData = new byte[] { 40, 50, 60 };

                    flac.Metadata.Add(appInfo);

                    appInfoCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    IEnumerable <ApplicationInfo> appInfo = flac.GetAllApplicationInfo();

                    Assert.AreEqual <int>(appInfoCount, appInfo.Count());

                    Assert.AreEqual <uint>(10, appInfo.ElementAt(appInfoCount - 2).ApplicationID);
                    Assert.AreEqual <uint>(20, appInfo.ElementAt(appInfoCount - 1).ApplicationID);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #13
0
        public void OpenFlacFileAndCreateMultipleCueSheets()
        {
            int    cueSheetCount = 0;
            string origFile      = @"Data\testfile4.flac";
            string newFile       = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.CueSheet != null)
                    {
                        cueSheetCount = 1;
                    }

                    // Add a second (empty) cuesheet
                    CueSheet newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack()
                    {
                        TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA
                    });
                    flac.Metadata.Add(newCueSheet);
                    // Add a third (empty) cuesheet
                    newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack()
                    {
                        TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA
                    });
                    flac.Metadata.Add(newCueSheet);

                    cueSheetCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual <int>(cueSheetCount, flac.GetAllCueSheets().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #14
0
        public void OpenFlacFileAndCreateMultiplePadding()
        {
            int    paddingCount = 0;
            string origFile     = @"Data\testfile4.flac";
            string newFile      = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.Padding != null)
                    {
                        paddingCount = 1;
                    }

                    Padding newPadding = new Padding()
                    {
                        EmptyBitCount = 8
                    };
                    flac.Metadata.Add(newPadding);
                    newPadding = new Padding()
                    {
                        EmptyBitCount = 8
                    };
                    flac.Metadata.Add(newPadding);

                    paddingCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual <int>(paddingCount, flac.GetAllPadding().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #15
0
        public void CopyOpenAndSaveStreamInfo()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile  = @"Data\testfile1_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle  = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // This will check whether the save did correctly write back the streaminfo
                    Assert.IsNotNull(flac.StreamInfo);
                    var    info   = flac.StreamInfo;
                    string md5sum = Helpers.ByteHelper.ByteArrayToString(info.MD5Signature);
                    Assert.AreEqual("1d2e54a059ea776787ef66f1f93d3e34", md5sum);
                    Assert.AreEqual(4096, info.MinimumBlockSize);
                    Assert.AreEqual(4096, info.MaximumBlockSize);
                    Assert.AreEqual((uint)1427, info.MinimumFrameSize);
                    Assert.AreEqual((uint)7211, info.MaximumFrameSize);
                    Assert.AreEqual((uint)44100, info.SampleRateHz);
                    Assert.AreEqual(1, info.Channels);
                    Assert.AreEqual(16, info.BitsPerSample);
                    Assert.AreEqual(1703592, info.Samples);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #16
0
        public void CreateVorbisComment()
        {
            string artist          = "Some Artist";
            string albumName       = "Test Album";
            string customTag       = "PROJECT";
            string customTagValue  = "FlacLibSharp";
            string customTag2      = "Author";
            string customTag2Value = "Aaron";
            string title           = "Test Track";
            string title2          = "Title modified";
            string titleTag        = "Title";

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                VorbisComment vorbisComment = new VorbisComment();

                vorbisComment.Album.Value       = albumName;
                vorbisComment.Artist.Value      = artist;
                vorbisComment[customTag].Value  = customTagValue;
                vorbisComment[customTag2].Value = customTag2Value;
                vorbisComment.Title.Value       = title;
                vorbisComment[titleTag].Value   = title2;

                flac.Metadata.Add(vorbisComment);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                VorbisComment vorbisComment = flac.VorbisComment;

                Assert.AreEqual <string>(albumName, vorbisComment.Album.Value);
                Assert.AreEqual <string>(artist, vorbisComment.Artist.Value);
                Assert.AreEqual <string>(customTagValue, vorbisComment[customTag].Value);
                Assert.AreEqual <string>(customTag2Value, vorbisComment[customTag2.ToUpper()].Value);
                Assert.AreEqual <string>(title2, vorbisComment.Title.Value);
                Assert.AreEqual <string>(title2, vorbisComment[titleTag].Value);
            }
        }
Beispiel #17
0
        public void CopyOpenEditAndSaveVorbisComments()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile  = @"Data\testfile1_temp.flac";

            // Tests if we can load up a flac file, update the artist and title in the vorbis comments
            // save the file and then reload the file and see the changes.
            FileHelper.GetNewFile(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle  = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.VorbisComment);
                    string artist = flac.VorbisComment["ARTIST"].Value;
                    string title  = flac.VorbisComment.Title.Value;
                    newArtist = String.Format("{0}_Edited", artist);
                    newTitle  = String.Format("{0}_Edited", title);
                    flac.VorbisComment["ARTIST"].Value = newArtist;
                    flac.VorbisComment.Title.Value     = newTitle;

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.VorbisComment);
                    Assert.AreEqual(newTitle, flac.VorbisComment.Title.Value);
                    Assert.AreEqual(newArtist, flac.VorbisComment.Artist.Value);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #18
0
        public void CopyOpenEditAndSaveCueSheet()
        {
            string  newMediaCatalog      = "test";
            Boolean newIsCDCueSheet      = false;
            ulong   newLeadInSampleCount = 100;

            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    cueSheet.MediaCatalog      = newMediaCatalog;
                    cueSheet.IsCDCueSheet      = newIsCDCueSheet;
                    cueSheet.LeadInSampleCount = newLeadInSampleCount;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);
                    Assert.AreEqual(newMediaCatalog, flac.CueSheet.MediaCatalog);
                    Assert.AreEqual(newIsCDCueSheet, flac.CueSheet.IsCDCueSheet);
                    Assert.AreEqual(newLeadInSampleCount, flac.CueSheet.LeadInSampleCount);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #19
0
        public void CreatePadding()
        {
            uint emptyBitCount = 256;

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                // Adding some bits of padding
                Padding paddingBlock = new Padding();
                paddingBlock.EmptyBitCount = emptyBitCount;
                flac.Metadata.Add(paddingBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                Padding padding = flac.Padding;
                Assert.AreEqual <uint>(emptyBitCount, padding.EmptyBitCount);
            }
        }
Beispiel #20
0
        public void CreateApplicationInfo()
        {
            uint applicationID = 10;

            byte[] data = { 10, 20, 30, 40, 45 };

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                // Adding some bits of padding
                ApplicationInfo appInfoBlock = new ApplicationInfo();
                appInfoBlock.ApplicationID   = 10;
                appInfoBlock.ApplicationData = data;
                flac.Metadata.Add(appInfoBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                ApplicationInfo appInfoBlock = flac.ApplicationInfo;
                Assert.IsNotNull(appInfoBlock);
                Assert.AreEqual <uint>(applicationID, appInfoBlock.ApplicationID);

                bool dataIsSame = true;
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] != appInfoBlock.ApplicationData[i])
                    {
                        dataIsSame = false;
                        break;
                    }
                }

                Assert.IsTrue(dataIsSame);
            }
        }
Beispiel #21
0
        public void CreateApplicationInfo()
        {
            uint applicationID = 10;
            byte[] data = { 10, 20, 30, 40, 45 };

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                // Adding some bits of padding
                ApplicationInfo appInfoBlock = new ApplicationInfo();
                appInfoBlock.ApplicationID = 10;
                appInfoBlock.ApplicationData = data;
                flac.Metadata.Add(appInfoBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                ApplicationInfo appInfoBlock = flac.ApplicationInfo;
                Assert.IsNotNull(appInfoBlock);
                Assert.AreEqual<uint>(applicationID, appInfoBlock.ApplicationID);

                bool dataIsSame = true;
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] != appInfoBlock.ApplicationData[i])
                    {
                        dataIsSame = false;
                        break;
                    }
                }

                Assert.IsTrue(dataIsSame);

            }
        }
Beispiel #22
0
        public void CopyOpenEditAndSavePadding()
        {
            UInt32 newPaddingSize = 8 * 2; // 2 bytes of padding

            string origFile = @"Data\testfile1.flac";
            string newFile = @"Data\testfile1_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Padding paddingBlock = null;
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            paddingBlock = (Padding)block;
                        }
                    }

                    paddingBlock.EmptyBitCount = newPaddingSize; // Set empty bytes to 2

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Padding paddingBlock = null;
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            paddingBlock = (Padding)block;
                        }
                    }

                    Assert.IsNotNull(paddingBlock);

                    Assert.AreEqual<UInt32>(newPaddingSize, paddingBlock.EmptyBitCount);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #23
0
        public void OpenFlacFileAndCreateMultiplePadding()
        {
            int paddingCount = 0;
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.Padding != null)
                    {
                        paddingCount = 1;
                    }

                    Padding newPadding = new Padding() { EmptyBitCount = 8 };
                    flac.Metadata.Add(newPadding);
                     newPadding = new Padding() { EmptyBitCount = 8 };
                    flac.Metadata.Add(newPadding);

                    paddingCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual<int>(paddingCount, flac.GetAllPadding().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #24
0
        public void CreateValidCueSheet()
        {
            string anISRC = "JMK401400212";

            byte  firstIndexPointNr      = 4;
            ulong firstIndexPointOffset  = 356;
            byte  secondIndexPointNr     = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = new CueSheet();

                CueSheetTrack newTrack = new CueSheetTrack();
                newTrack.IsAudioTrack  = true;
                newTrack.IsPreEmphasis = false;
                newTrack.ISRC          = anISRC;
                newTrack.TrackNumber   = 1;
                newTrack.TrackOffset   = 0;

                CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = firstIndexPointNr;
                indexPoint.Offset           = firstIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);
                indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = secondIndexPointNr;
                indexPoint.Offset           = secondIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);

                cueSheet.Tracks.Add(newTrack);

                // Create the lead-out track

                CueSheetTrack leadOut = new CueSheetTrack();
                leadOut.IsAudioTrack = false;
                leadOut.TrackNumber  = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA;
                cueSheet.Tracks.Add(leadOut);

                flac.Metadata.Add(cueSheet);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = flac.CueSheet;
                Assert.IsNotNull(cueSheet);

                Assert.AreEqual <byte>(2, cueSheet.TrackCount);

                CueSheetTrack track = cueSheet.Tracks[0];

                Assert.AreEqual <bool>(true, track.IsAudioTrack);
                Assert.AreEqual <bool>(false, track.IsPreEmphasis);
                Assert.AreEqual <string>(anISRC, track.ISRC);
                Assert.AreEqual <byte>(1, track.TrackNumber);
                Assert.AreEqual <ulong>(0, track.TrackOffset);

                Assert.AreEqual <byte>(2, track.IndexPointCount);
                Assert.AreEqual <byte>(firstIndexPointNr, track.IndexPoints[0].IndexPointNumber);
                Assert.AreEqual <ulong>(firstIndexPointOffset, track.IndexPoints[0].Offset);
                Assert.AreEqual <byte>(secondIndexPointNr, track.IndexPoints[1].IndexPointNumber);
                Assert.AreEqual <ulong>(secondIndexPointOffset, track.IndexPoints[1].Offset);
            }
        }
Beispiel #25
0
        public static void CopyOpenAndSaveStreamInfo()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile  = @"Data\testfile1_temp.flac";

            if (File.Exists(newFile))
            {
                File.Delete(newFile);
            }
            File.Copy(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle  = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("Before Modif: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                            ((Padding)block).EmptyBitCount = 8; // Remove some padding ...
                        }
                    }

                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("After Modif: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                        }
                    }

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // This will check whether the save did correctly write back the streaminfo
                    var    info   = flac.StreamInfo;
                    string md5sum = ByteArrayToString(info.MD5Signature);

                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("After Save: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                        }
                    }

                    //Assert.AreEqual(md5sum, "1d2e54a059ea776787ef66f1f93d3e34");
                    //Assert.AreEqual(info.MinimumBlockSize, 4096);
                    //Assert.AreEqual(info.MaximumBlockSize, 4096);
                    //Assert.AreEqual(info.MinimumFrameSize, (uint)1427);
                    //Assert.AreEqual(info.MaximumFrameSize, (uint)7211);
                    //Assert.AreEqual(info.SampleRateHz, (uint)44100);
                    //Assert.AreEqual(info.Channels, 1);
                    //Assert.AreEqual(info.BitsPerSample, 16);
                    //Assert.AreEqual(info.Samples, 1703592);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #26
0
        public void CopyOpenEditAndSaveVorbisComments()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile = @"Data\testfile1_temp.flac";
            // Tests if we can load up a flac file, update the artist and title in the vorbis comments
            // save the file and then reload the file and see the changes.
            FileHelper.GetNewFile(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.VorbisComment);
                    string artist = flac.VorbisComment["ARTIST"].Value;
                    string title = flac.VorbisComment.Title.Value;
                    newArtist = String.Format("{0}_Edited", artist);
                    newTitle = String.Format("{0}_Edited", title);
                    flac.VorbisComment["ARTIST"].Value = newArtist;
                    flac.VorbisComment.Title.Value = newTitle;

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.VorbisComment);
                    Assert.AreEqual(newTitle, flac.VorbisComment.Title.Value);
                    Assert.AreEqual(newArtist, flac.VorbisComment.Artist.Value);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #27
0
        public void CreateValidCueSheet()
        {
            string anISRC = "JMK401400212";

            byte firstIndexPointNr = 4;
            ulong firstIndexPointOffset = 356;
            byte secondIndexPointNr = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = new CueSheet();

                CueSheetTrack newTrack = new CueSheetTrack();
                newTrack.IsAudioTrack = true;
                newTrack.IsPreEmphasis = false;
                newTrack.ISRC = anISRC;
                newTrack.TrackNumber = 1;
                newTrack.TrackOffset = 0;

                CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = firstIndexPointNr;
                indexPoint.Offset = firstIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);
                indexPoint = new CueSheetTrackIndex();
                indexPoint.IndexPointNumber = secondIndexPointNr;
                indexPoint.Offset = secondIndexPointOffset;
                newTrack.IndexPoints.Add(indexPoint);

                cueSheet.Tracks.Add(newTrack);

                // Create the lead-out track

                CueSheetTrack leadOut = new CueSheetTrack();
                leadOut.IsAudioTrack = false;
                leadOut.TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA;
                cueSheet.Tracks.Add(leadOut);

                flac.Metadata.Add(cueSheet);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                CueSheet cueSheet = flac.CueSheet;
                Assert.IsNotNull(cueSheet);

                Assert.AreEqual<byte>(2, cueSheet.TrackCount);

                CueSheetTrack track = cueSheet.Tracks[0];

                Assert.AreEqual<bool>(true, track.IsAudioTrack);
                Assert.AreEqual<bool>(false, track.IsPreEmphasis);
                Assert.AreEqual<string>(anISRC, track.ISRC);
                Assert.AreEqual<byte>(1, track.TrackNumber);
                Assert.AreEqual<ulong>(0, track.TrackOffset);

                Assert.AreEqual<byte>(2, track.IndexPointCount);
                Assert.AreEqual<byte>(firstIndexPointNr, track.IndexPoints[0].IndexPointNumber);
                Assert.AreEqual<ulong>(firstIndexPointOffset, track.IndexPoints[0].Offset);
                Assert.AreEqual<byte>(secondIndexPointNr, track.IndexPoints[1].IndexPointNumber);
                Assert.AreEqual<ulong>(secondIndexPointOffset, track.IndexPoints[1].Offset);
            }
        }
Beispiel #28
0
        public void OpenFlacFileAndCreateMultipleApplicationInfo()
        {
            int appInfoCount = 0;
            string origFile = @"Data\testfile3.flac";
            string newFile = @"Data\testfile3_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.ApplicationInfo != null)
                    {
                        appInfoCount = 1;
                    }

                    ApplicationInfo appInfo = new ApplicationInfo();
                    appInfo.ApplicationID = 10;
                    appInfo.ApplicationData = new byte[] { 10, 20, 30 };

                    flac.Metadata.Add(appInfo);

                    appInfo = new ApplicationInfo();
                    appInfo.ApplicationID = 20;
                    appInfo.ApplicationData = new byte[] { 40, 50, 60 };

                    flac.Metadata.Add(appInfo);

                    appInfoCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    IEnumerable<ApplicationInfo> appInfo = flac.GetAllApplicationInfo();

                    Assert.AreEqual<int>(appInfoCount, appInfo.Count());

                    Assert.AreEqual<uint>(10, appInfo.ElementAt(appInfoCount - 2).ApplicationID);
                    Assert.AreEqual<uint>(20, appInfo.ElementAt(appInfoCount - 1).ApplicationID);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #29
0
        public void CreateSeekTable()
        {
            ulong expectedNumberOfSamples; // Will be set while creating a new seekpoint
            ulong expectedByteOffset; // Will be set while creating a new seekpoint

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                SeekTable seekTable = new SeekTable();
                flac.Metadata.Add(seekTable);

                // Create a new Seekpoint, a little further
                SeekPoint newSeekpoint = new SeekPoint();
                newSeekpoint.FirstSampleNumber = 1000;
                newSeekpoint.NumberOfSamples = (ushort)1000;
                expectedNumberOfSamples = newSeekpoint.NumberOfSamples;
                newSeekpoint.ByteOffset = 0;
                expectedByteOffset = newSeekpoint.ByteOffset;
                seekTable.SeekPoints.Add(newSeekpoint);

                // Create a placeholder seekpoint
                SeekPoint placeHolder = new SeekPoint();
                placeHolder.FirstSampleNumber = ulong.MaxValue;
                // The other two values are "undefined"
                Assert.IsTrue(placeHolder.IsPlaceHolder); // Already assert that the object itself handles this flac correctly.
                seekTable.SeekPoints.Add(placeHolder);

                // This should actually be allowed according to the FLAC format (multiple placeHolders are ok, but they must occur at the end of the seektable)
                seekTable.SeekPoints.Add(placeHolder);

                // Check if we actually get "2" placeholders ...
                Assert.AreEqual<int>(2, seekTable.SeekPoints.Placeholders);

                flac.Save();
            }
            using (FlacFile flac = new FlacFile(newFile))
            {
                // Now we want to try and find our new SeekPoint
                Assert.IsNotNull(flac.SeekTable);

                Assert.IsTrue(flac.SeekTable.SeekPoints.ContainsKey(1000));
                SeekPoint newSeekpoint = flac.SeekTable.SeekPoints[1000];

                Assert.AreEqual<ulong>(expectedNumberOfSamples, newSeekpoint.NumberOfSamples);
                Assert.AreEqual<ulong>(expectedByteOffset, newSeekpoint.ByteOffset);

                Assert.IsFalse(newSeekpoint.IsPlaceHolder);

                // Check if we actually get "2" placeholders ...
                Assert.AreEqual<int>(2, flac.SeekTable.SeekPoints.Placeholders);
            }
        }
Beispiel #30
0
        public void CopyOpenAddAndSaveCueSheetTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            byte oldTrackCount = 0;
            ulong oldOffset = 0;
            ulong newOffset = 1000;
            string anISRC = "JMK401400212";

            byte firstIndexPointNr = 4;
            ulong firstIndexPointOffset = 356;
            byte secondIndexPointNr = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    oldTrackCount = cueSheet.TrackCount;

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.ISRC = anISRC;
                    newTrack.TrackNumber = (byte)(oldTrackCount + 1);
                    oldOffset = cueSheet.Tracks[cueSheet.Tracks.Count - 2].TrackOffset;
                    newOffset += oldOffset;
                    newTrack.TrackOffset = newOffset;

                    CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = firstIndexPointNr;
                    indexPoint.Offset = firstIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);
                    indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = secondIndexPointNr;
                    indexPoint.Offset = secondIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);

                    // Insert the track just before the lead-out track ...
                    flac.CueSheet.Tracks.Insert(flac.CueSheet.Tracks.Count - 1, newTrack);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);

                    // first verify that the last track is our track (ignoring the lead-out track ...)
                    var lastTrack = flac.CueSheet.Tracks[flac.CueSheet.TrackCount - 2];

                    Assert.AreEqual<bool>(true, lastTrack.IsAudioTrack);
                    Assert.AreEqual<bool>(false, lastTrack.IsPreEmphasis);
                    Assert.AreEqual<string>(anISRC, lastTrack.ISRC);
                    Assert.AreEqual<byte>(flac.CueSheet.TrackCount, lastTrack.TrackNumber);
                    Assert.AreEqual<ulong>(newOffset, lastTrack.TrackOffset);

                    // Now check if our two index points are still there as well
                    Assert.AreEqual<byte>(2, lastTrack.IndexPointCount);
                    Assert.AreEqual<byte>(firstIndexPointNr, lastTrack.IndexPoints[0].IndexPointNumber);
                    Assert.AreEqual<ulong>(firstIndexPointOffset, lastTrack.IndexPoints[0].Offset);
                    Assert.AreEqual<byte>(secondIndexPointNr, lastTrack.IndexPoints[1].IndexPointNumber);
                    Assert.AreEqual<ulong>(secondIndexPointOffset, lastTrack.IndexPoints[1].Offset);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #31
0
        public void SaveCueSheetWithoutTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    cueSheet.Tracks.Clear();

                    // The save should not allow this since we must have at least a lead-out track.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #32
0
        public void SaveCueSheetWithoutCorrectLeadOutTrack()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.TrackNumber = (byte)(55); // a non-lead-out track

                    flac.CueSheet.Tracks.Add(newTrack); // Add the track as last track ...

                    // The save should not allow this.
                    flac.Save();
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #33
0
        public void CopyOpenEditAndSaveCueSheet()
        {
            string newMediaCatalog = "test";
            Boolean newIsCDCueSheet = false;
            ulong newLeadInSampleCount = 100;

            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    cueSheet.MediaCatalog = newMediaCatalog;
                    cueSheet.IsCDCueSheet = newIsCDCueSheet;
                    cueSheet.LeadInSampleCount = newLeadInSampleCount;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);
                    Assert.AreEqual(newMediaCatalog, flac.CueSheet.MediaCatalog);
                    Assert.AreEqual(newIsCDCueSheet, flac.CueSheet.IsCDCueSheet);
                    Assert.AreEqual(newLeadInSampleCount, flac.CueSheet.LeadInSampleCount);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #34
0
        // just in case i find a way to get the album cover working in taglib

        /*private bool WriteFlacMetadata()
         * {
         *  using (TagLib.File file = TagLib.File.Create(_filepath, "taglib/flac", ReadStyle.Average))
         *  {
         *      var tags = (TagLib.Ogg.XiphComment) file.GetTag(TagTypes.Xiph);
         *
         *      if (_trackInfo.TrackTags != null)
         *      {
         *          tags.Title = _trackInfo.TrackTags.Title;
         *          tags.Performers = _trackInfo.TrackTags.Artists.Select(x => x.Name).ToArray();
         *          tags.Composers = _trackInfo.TrackTags.Contributors.Composers;
         *          tags.SetField("LENGTH", _trackInfo.TrackTags.Length);
         *          tags.SetField("ISRC", _trackInfo.TrackTags.Isrc);
         *          tags.SetField("EXPLICIT", _trackInfo.TrackTags.ExplicitLyrics ?? "0");
         *          tags.SetField("REPLAYGAIN_TRACK_GAIN", _trackInfo.TrackTags.Gain);
         *          tags.SetField("PRODUCER", _trackInfo.TrackTags.Contributors.Producers);
         *          tags.SetField("ENGINEER", _trackInfo.TrackTags.Contributors.Engineers);
         *          tags.SetField("MIXER", _trackInfo.TrackTags.Contributors.Mixers);
         *          tags.SetField("WRITER", _trackInfo.TrackTags.Contributors.Writers);
         *          tags.SetField("AUTHOR", _trackInfo.TrackTags.Contributors.Authors);
         *          tags.SetField("PUBLISHER", _trackInfo.TrackTags.Contributors.Publishers);
         *
         *
         *          if (_trackInfo.TrackTags.TrackNumber != null &&
         *              uint.TryParse(_trackInfo.TrackTags.TrackNumber, out uint trackNumber))
         *          {
         *              tags.Track = trackNumber;
         *          }
         *
         *          if (_trackInfo.TrackTags.DiscNumber != null &&
         *              uint.TryParse(_trackInfo.TrackTags.DiscNumber, out uint discNumber))
         *          {
         *              tags.Disc = discNumber;
         *          }
         *
         *          if (_trackInfo.TrackTags.Bpm != null &&
         *              uint.TryParse(_trackInfo.TrackTags.Bpm, out uint bpm))
         *          {
         *              tags.BeatsPerMinute = bpm;
         *          }
         *      }
         *
         *      if (_albumInfo.AlbumTags != null)
         *      {
         *          tags.Album = _albumInfo.AlbumTags.Title;
         *          tags.AlbumArtists = _albumInfo.AlbumTags.Artists.Select(x => x.Name).ToArray();
         *          tags.Genres = _albumInfo.AlbumTags.Genres.GenreData.Select(x => x.Name).ToArray();
         *
         *          string year = _albumInfo.AlbumTags.ReleaseDate;
         *
         *          if (!string.IsNullOrWhiteSpace(year))
         *          {
         *              string[] yearSplit = year.Split("-");
         *
         *              if (yearSplit[0].Length == 4 && uint.TryParse(yearSplit[0], out uint yearParsed))
         *              {
         *                  tags.Year = yearParsed;
         *              }
         *          }
         *
         *          tags.Copyright = _albumInfo.AlbumTags.Copyright;
         *          tags.SetField("MEDIA", "Digital Media");
         *          tags.SetField("ORIGINALDATE", _albumInfo.AlbumTags.ReleaseDate);
         *          tags.SetField("UPC", _albumInfo.AlbumTags.Upc);
         *          tags.SetField("LABEL", _albumInfo.AlbumTags.Label);
         *
         *          if (_albumInfo.AlbumTags.NumberOfTracks != null &&
         *              uint.TryParse(_albumInfo.AlbumTags.NumberOfTracks, out uint numberOfTracks))
         *          {
         *              tags.TrackCount = numberOfTracks;
         *          }
         *
         *          if (_albumInfo.AlbumTags.NumberOfDiscs != null &&
         *              uint.TryParse(_albumInfo.AlbumTags.NumberOfDiscs, out uint numberOfDiscs))
         *          {
         *              tags.DiscCount = numberOfDiscs;
         *          }
         *      }
         *
         *      if (_trackInfo.Lyrics != null)
         *      {
         *          tags.Lyrics = _trackInfo.Lyrics.UnSyncedLyrics;
         *          WriteLyricsFile();
         *      }
         *
         *      try
         *      {
         *          file.Save();
         *      }
         *      catch (IOException ex)
         *      {
         *          Console.WriteLine(ex.Message);
         *          return false;
         *      }
         *  }
         *
         *  // this takes 800-900ms... why can't you just work taglib
         *  using (var file = new FlacFile(_filepath))
         *  {
         *      if (_coverBytes.Length > 0)
         *      {
         *          var coverArt = new FlacLibSharp.Picture()
         *          {
         *              Description = "Cover",
         *              ColorDepth = 8,
         *              Data = _coverBytes,
         *              Height = 1400,
         *              Width = 1400,
         *              MIMEType = MediaTypeNames.Image.Jpeg,
         *              PictureType = FlacLibSharp.PictureType.CoverFront
         *          };
         *
         *          file.Metadata.Add(coverArt);
         *      }
         *
         *      try
         *      {
         *          file.Save();
         *      }
         *      catch (Exception ex)
         *      {
         *          Console.WriteLine(ex.Message);
         *          return false;
         *      }
         *  }
         *
         *  return true;
         * }*/

        private bool WriteFlacMetadata()
        {
            using (var file = new FlacFile(_filepath))
            {
                var comments = new VorbisComment();

                if (_coverBytes.Length > 0)
                {
                    var coverArt = new FlacLibSharp.Picture
                    {
                        Description = "Cover",
                        ColorDepth  = 8,
                        Data        = _coverBytes,
                        Height      = 1400,
                        Width       = 1400,
                        MIMEType    = MediaTypeNames.Image.Jpeg,
                        PictureType = FlacLibSharp.PictureType.CoverFront
                    };

                    file.Metadata.Add(coverArt);
                }

                comments["Media"] = new VorbisCommentValues("Digital Media");

                if (_albumInfo?.AlbumTags != null)
                {
                    comments.Album = new VorbisCommentValues(_albumInfo.AlbumTags.Title ?? "");

                    if (_albumInfo.AlbumTags?.Genres?.GenreData != null)
                    {
                        comments.Genre = new VorbisCommentValues(_albumInfo.AlbumTags.Genres.GenreData.Select(x => x.Name));
                    }

                    string year = _albumInfo.AlbumTags.ReleaseDate ?? "";

                    if (!string.IsNullOrWhiteSpace(year))
                    {
                        var yearSplit = year.Split("-");

                        if (yearSplit[0].Length == 4)
                        {
                            year = yearSplit[0];
                        }
                    }

                    if (_albumInfo.AlbumTags.Type == "Compilation" || _albumInfo.AlbumTags.Type == "Playlist")
                    {
                        comments["COMPILATION"] = new VorbisCommentValues("1");
                    }

                    comments.Date            = new VorbisCommentValues(year ?? "");
                    comments["ORIGINALDATE"] = new VorbisCommentValues(_albumInfo.AlbumTags.ReleaseDate ?? "");
                    comments["TRACKTOTAL"]   = new VorbisCommentValues(_albumInfo.AlbumTags.NumberOfTracks ?? "");
                    comments["DISCTOTAL"]    = new VorbisCommentValues(_albumInfo.AlbumTags.NumberOfDiscs ?? "");
                    comments["COPYRIGHT"]    = new VorbisCommentValues(_albumInfo.AlbumTags.Copyright ?? "");
                    comments["UPC"]          = new VorbisCommentValues(_albumInfo.AlbumTags.Upc ?? "");
                    comments["LABEL"]        = new VorbisCommentValues(_albumInfo.AlbumTags.Label ?? "");
                    comments["ALBUMARTIST"]  = new VorbisCommentValues(_albumInfo.AlbumTags.Artists.Select(x => x.Name));
                }

                if (_trackInfo?.TrackTags != null)
                {
                    comments.Title                    = new VorbisCommentValues(_trackInfo.TrackTags.Title ?? "");
                    comments.Artist                   = new VorbisCommentValues(_trackInfo.TrackTags.Artists.Select(x => x.Name));
                    comments["DISCNUMBER"]            = new VorbisCommentValues(_trackInfo.TrackTags.DiscNumber ?? "");
                    comments["TRACKNUMBER"]           = new VorbisCommentValues(_trackInfo.TrackTags.TrackNumber ?? "");
                    comments["BPM"]                   = new VorbisCommentValues(_trackInfo.TrackTags.Bpm ?? "");
                    comments["LENGTH"]                = new VorbisCommentValues(_trackInfo.TrackTags.Length ?? "");
                    comments["ISRC"]                  = new VorbisCommentValues(_trackInfo.TrackTags.Isrc ?? "");
                    comments["EXPLICIT"]              = new VorbisCommentValues(_trackInfo.TrackTags.ExplicitLyrics ?? "0");
                    comments["REPLAYGAIN_TRACK_GAIN"] = new VorbisCommentValues(_trackInfo.TrackTags.Gain ?? "");

                    MetadataHelpers.AddTagIfNotNull(comments, "COMPOSER", _trackInfo.TrackTags.Contributors.Composers);
                    MetadataHelpers.AddTagIfNotNull(comments, "PUBLISHER", _trackInfo.TrackTags.Contributors.Publishers);
                    MetadataHelpers.AddTagIfNotNull(comments, "PRODUCER", _trackInfo.TrackTags.Contributors.Producers);
                    MetadataHelpers.AddTagIfNotNull(comments, "ENGINEER", _trackInfo.TrackTags.Contributors.Engineers);
                    MetadataHelpers.AddTagIfNotNull(comments, "WRITER", _trackInfo.TrackTags.Contributors.Writers);
                    MetadataHelpers.AddTagIfNotNull(comments, "MIXER", _trackInfo.TrackTags.Contributors.Mixers);
                    MetadataHelpers.AddTagIfNotNull(comments, "AUTHOR", _trackInfo.TrackTags.Contributors.Authors);
                }

                if (_trackInfo?.Lyrics != null)
                {
                    comments["Lyrics"] = new VorbisCommentValues(_trackInfo.Lyrics.UnSyncedLyrics ?? "");
                    WriteLyricsFile();
                }

                file.Metadata.Add(comments);

                try
                {
                    file.Save();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }

            return(true);
        }
Beispiel #35
0
        public void CopyOpenAndSaveStreamInfo()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile = @"Data\testfile1_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // This will check whether the save did correctly write back the streaminfo
                    Assert.IsNotNull(flac.StreamInfo);
                    var info = flac.StreamInfo;
                    string md5sum = Helpers.ByteHelper.ByteArrayToString(info.MD5Signature);
                    Assert.AreEqual("1d2e54a059ea776787ef66f1f93d3e34", md5sum);
                    Assert.AreEqual(4096, info.MinimumBlockSize);
                    Assert.AreEqual(4096, info.MaximumBlockSize);
                    Assert.AreEqual((uint)1427, info.MinimumFrameSize);
                    Assert.AreEqual((uint)7211, info.MaximumFrameSize);
                    Assert.AreEqual((uint)44100, info.SampleRateHz);
                    Assert.AreEqual(1, info.Channels);
                    Assert.AreEqual(16, info.BitsPerSample);
                    Assert.AreEqual(1703592, info.Samples);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #36
0
        public void CreateVorbisComment()
        {
            string artist = "Some Artist";
            string albumName = "Test Album";
            string customTag = "PROJECT";
            string customTagValue = "FlacLibSharp";
            string customTag2 = "Author";
            string customTag2Value = "Aaron";
            string title = "Test Track";
            string title2 = "Title modified";
            string titleTag = "Title";

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                VorbisComment vorbisComment = new VorbisComment();

                vorbisComment.Album.Value = albumName;
                vorbisComment.Artist.Value = artist;
                vorbisComment[customTag].Value = customTagValue;
                vorbisComment[customTag2].Value = customTag2Value;
                vorbisComment.Title.Value = title;
                vorbisComment[titleTag].Value = title2;

                flac.Metadata.Add(vorbisComment);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                VorbisComment vorbisComment = flac.VorbisComment;

                Assert.AreEqual<string>(albumName, vorbisComment.Album.Value);
                Assert.AreEqual<string>(artist, vorbisComment.Artist.Value);
                Assert.AreEqual<string>(customTagValue, vorbisComment[customTag].Value);
                Assert.AreEqual<string>(customTag2Value, vorbisComment[customTag2.ToUpper()].Value);
                Assert.AreEqual<string>(title2, vorbisComment.Title.Value);
                Assert.AreEqual<string>(title2, vorbisComment[titleTag].Value);
            }
        }
Beispiel #37
0
        public static void DuplicateMetadata()
        {
            File.Copy(@"Data\testfile4.flac", @"Data\testfile4_tmp.flac", true);
            using (FlacFile file = new FlacFile(@"Data\testfile4_tmp.flac"))
            {
                /* Appinfo is fine! */

                /*
                 * var appInfo = file.ApplicationInfo;
                 * if (appInfo == null)
                 * {
                 *  appInfo = new ApplicationInfo();
                 *  appInfo.ApplicationID = 10;
                 *  appInfo.ApplicationData = new byte[] { 10, 20, 30 };
                 *  file.Metadata.Add(appInfo);
                 *  file.Metadata.Add(appInfo);
                 * }
                 */

                /* Cuesheet is fine ?*/

                /*
                 * var cueSheet = file.CueSheet;
                 * file.Metadata.Add(cueSheet);
                 */

                /* Vorbis also fine! */

                /*
                 * var vorbis = file.VorbisComment;
                 * if (vorbis == null)
                 * {
                 *  vorbis = new VorbisComment();
                 *
                 *  vorbis.Album = "My Test Album";
                 *
                 *  file.Metadata.Add(vorbis);
                 *
                 *  file.Metadata.Add(vorbis);
                 * }
                 *
                 * file.Metadata.Add(vorbis);
                 */

                /* Metadata not fine! */

                /*
                 * var streaminfo = file.StreamInfo;
                 * file.Metadata.Add(streaminfo);
                 */

                /* SeekTable is fine */

                /*
                 * var seekTable = new SeekTable();
                 * seekTable.SeekPoints.Add(new SeekPoint() { ByteOffset = 0, FirstSampleNumber = 0, IsPlaceHolder = false, NumberOfSamples = 100 });
                 * file.Metadata.Add(seekTable);
                 * file.Metadata.Add(seekTable);
                 */

                /* We know picture is fine */

                /* Padding is fine */

                /* So everything fine, except StreamInfo */

                file.Save();
            }
        }
Beispiel #38
0
        public void CopyOpenAddAndSaveCueSheetTracks()
        {
            string origFile = @"Data\testfile4.flac";
            string newFile  = @"Data\testfile4_temp.flac";

            byte   oldTrackCount = 0;
            ulong  oldOffset     = 0;
            ulong  newOffset     = 1000;
            string anISRC        = "JMK401400212";

            byte  firstIndexPointNr      = 4;
            ulong firstIndexPointOffset  = 356;
            byte  secondIndexPointNr     = 5;
            ulong secondIndexPointOffset = 1000;

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    var cueSheet = flac.CueSheet;
                    Assert.IsNotNull(cueSheet);

                    oldTrackCount = cueSheet.TrackCount;

                    CueSheetTrack newTrack = new CueSheetTrack();
                    newTrack.IsAudioTrack  = true;
                    newTrack.IsPreEmphasis = false;
                    newTrack.ISRC          = anISRC;
                    newTrack.TrackNumber   = (byte)(oldTrackCount + 1);
                    oldOffset            = cueSheet.Tracks[cueSheet.Tracks.Count - 2].TrackOffset;
                    newOffset           += oldOffset;
                    newTrack.TrackOffset = newOffset;

                    CueSheetTrackIndex indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = firstIndexPointNr;
                    indexPoint.Offset           = firstIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);
                    indexPoint = new CueSheetTrackIndex();
                    indexPoint.IndexPointNumber = secondIndexPointNr;
                    indexPoint.Offset           = secondIndexPointOffset;
                    newTrack.IndexPoints.Add(indexPoint);

                    // Insert the track just before the lead-out track ...
                    flac.CueSheet.Tracks.Insert(flac.CueSheet.Tracks.Count - 1, newTrack);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.CueSheet);

                    // first verify that the last track is our track (ignoring the lead-out track ...)
                    var lastTrack = flac.CueSheet.Tracks[flac.CueSheet.TrackCount - 2];

                    Assert.AreEqual <bool>(true, lastTrack.IsAudioTrack);
                    Assert.AreEqual <bool>(false, lastTrack.IsPreEmphasis);
                    Assert.AreEqual <string>(anISRC, lastTrack.ISRC);
                    Assert.AreEqual <byte>(flac.CueSheet.TrackCount, lastTrack.TrackNumber);
                    Assert.AreEqual <ulong>(newOffset, lastTrack.TrackOffset);

                    // Now check if our two index points are still there as well
                    Assert.AreEqual <byte>(2, lastTrack.IndexPointCount);
                    Assert.AreEqual <byte>(firstIndexPointNr, lastTrack.IndexPoints[0].IndexPointNumber);
                    Assert.AreEqual <ulong>(firstIndexPointOffset, lastTrack.IndexPoints[0].Offset);
                    Assert.AreEqual <byte>(secondIndexPointNr, lastTrack.IndexPoints[1].IndexPointNumber);
                    Assert.AreEqual <ulong>(secondIndexPointOffset, lastTrack.IndexPoints[1].Offset);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #39
0
        public void CopyOpenAddAndSavePicture()
        {
            string origFile = @"Data\testfile2.flac";
            string newFile = @"Data\testfile2_temp.flac";
            byte[] imageData = File.ReadAllBytes(@"Data\testimage.png");

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Picture pict = null;

                    pict = new FlacLibSharp.Picture();
                    pict.ColorDepth = 24;
                    pict.Data = imageData;
                    pict.Description = "Small picture test ...";
                    pict.Height = 420;
                    pict.Width = 410;
                    pict.MIMEType = "image/png";
                    pict.PictureType = PictureType.ArtistLogotype;

                    flac.Metadata.Add(pict);

                    pict = new FlacLibSharp.Picture();
                    pict.ColorDepth = 24;
                    pict.Description = "Small URL picture test ...";
                    pict.Height = 768;
                    pict.Width = 1024;
                    pict.MIMEType = "-->";
                    pict.PictureType = PictureType.BrightColouredFish;
                    pict.URL = "http://38.media.tumblr.com/0e954b0469c281a9a09eb1378daada3e/tumblr_mh0cpm19zR1s3yrubo1_1280.jpg";

                    flac.Metadata.Add(pict);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    List<Picture> pictures = flac.GetAllPictures();
                    Assert.IsTrue(pictures.Count > 0);

                    bool foundOurImage = false;
                    bool foundOurURL = false;
                    foreach (var pict in pictures)
                    {
                        if (pict.Description == "Small picture test ...")
                        {
                            Assert.AreEqual<uint>(24, pict.ColorDepth);
                            Assert.AreEqual<string>("Small picture test ...", pict.Description);
                            Assert.AreEqual<uint>(420, pict.Height);
                            Assert.AreEqual<uint>(410, pict.Width);
                            Assert.AreEqual<string>("image/png", pict.MIMEType);
                            Assert.AreEqual<PictureType>(PictureType.ArtistLogotype, pict.PictureType);

                            Assert.IsNotNull(pict.Data.Length);
                            Assert.AreEqual<int>(imageData.Length, pict.Data.Length);
                            for (int i = 0; i < imageData.Length; i++)
                            {
                                Assert.AreEqual<byte>(imageData[i], pict.Data[i], "Written picture data does not match read picture data.");
                            }

                            foundOurImage = true;
                        }

                        if (pict.Description == "Small URL picture test ...")
                        {
                            Assert.AreEqual<uint>(24, pict.ColorDepth);
                            Assert.AreEqual<string>("Small URL picture test ...", pict.Description);
                            Assert.AreEqual<uint>(768, pict.Height);
                            Assert.AreEqual<uint>(1024, pict.Width);
                            Assert.AreEqual<string>("-->", pict.MIMEType);
                            Assert.AreEqual<PictureType>(PictureType.BrightColouredFish, pict.PictureType);
                            Assert.AreEqual<string>("http://38.media.tumblr.com/0e954b0469c281a9a09eb1378daada3e/tumblr_mh0cpm19zR1s3yrubo1_1280.jpg", pict.URL);
                            foundOurURL = true;
                        }
                    }

                    Assert.IsTrue(foundOurImage);
                    Assert.IsTrue(foundOurURL);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #40
0
        public void CopyOpenAddAndSavePicture()
        {
            string origFile = @"Data\testfile2.flac";
            string newFile  = @"Data\testfile2_temp.flac";

            byte[] imageData = File.ReadAllBytes(@"Data\testimage.png");

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Picture pict = null;

                    pict             = new FlacLibSharp.Picture();
                    pict.ColorDepth  = 24;
                    pict.Data        = imageData;
                    pict.Description = "Small picture test ...";
                    pict.Height      = 420;
                    pict.Width       = 410;
                    pict.MIMEType    = "image/png";
                    pict.PictureType = PictureType.ArtistLogotype;

                    flac.Metadata.Add(pict);

                    pict             = new FlacLibSharp.Picture();
                    pict.ColorDepth  = 24;
                    pict.Description = "Small URL picture test ...";
                    pict.Height      = 768;
                    pict.Width       = 1024;
                    pict.MIMEType    = "-->";
                    pict.PictureType = PictureType.BrightColouredFish;
                    pict.URL         = "http://38.media.tumblr.com/0e954b0469c281a9a09eb1378daada3e/tumblr_mh0cpm19zR1s3yrubo1_1280.jpg";

                    flac.Metadata.Add(pict);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    List <Picture> pictures = flac.GetAllPictures();
                    Assert.IsTrue(pictures.Count > 0);

                    bool foundOurImage = false;
                    bool foundOurURL   = false;
                    foreach (var pict in pictures)
                    {
                        if (pict.Description == "Small picture test ...")
                        {
                            Assert.AreEqual <uint>(24, pict.ColorDepth);
                            Assert.AreEqual <string>("Small picture test ...", pict.Description);
                            Assert.AreEqual <uint>(420, pict.Height);
                            Assert.AreEqual <uint>(410, pict.Width);
                            Assert.AreEqual <string>("image/png", pict.MIMEType);
                            Assert.AreEqual <PictureType>(PictureType.ArtistLogotype, pict.PictureType);

                            Assert.IsNotNull(pict.Data.Length);
                            Assert.AreEqual <int>(imageData.Length, pict.Data.Length);
                            for (int i = 0; i < imageData.Length; i++)
                            {
                                Assert.AreEqual <byte>(imageData[i], pict.Data[i], "Written picture data does not match read picture data.");
                            }

                            foundOurImage = true;
                        }

                        if (pict.Description == "Small URL picture test ...")
                        {
                            Assert.AreEqual <uint>(24, pict.ColorDepth);
                            Assert.AreEqual <string>("Small URL picture test ...", pict.Description);
                            Assert.AreEqual <uint>(768, pict.Height);
                            Assert.AreEqual <uint>(1024, pict.Width);
                            Assert.AreEqual <string>("-->", pict.MIMEType);
                            Assert.AreEqual <PictureType>(PictureType.BrightColouredFish, pict.PictureType);
                            Assert.AreEqual <string>("http://38.media.tumblr.com/0e954b0469c281a9a09eb1378daada3e/tumblr_mh0cpm19zR1s3yrubo1_1280.jpg", pict.URL);
                            foundOurURL = true;
                        }
                    }

                    Assert.IsTrue(foundOurImage);
                    Assert.IsTrue(foundOurURL);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #41
0
        public static void CopyOpenAndSaveStreamInfo()
        {
            string origFile = @"Data\testfile1.flac";
            string newFile = @"Data\testfile1_temp.flac";
            if (File.Exists(newFile))
            {
                File.Delete(newFile);
            }
            File.Copy(origFile, newFile);

            string newArtist = String.Empty;
            string newTitle = String.Empty;

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("Before Modif: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                            ((Padding)block).EmptyBitCount = 8; // Remove some padding ...
                        }
                    }

                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("After Modif: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                        }
                    }

                    // Save flac file
                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // This will check whether the save did correctly write back the streaminfo
                    var info = flac.StreamInfo;
                    string md5sum = ByteArrayToString(info.MD5Signature);

                    foreach (var block in flac.Metadata)
                    {
                        if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding)
                        {
                            Console.WriteLine("After Save: Padding length in bit: {0}", ((Padding)block).EmptyBitCount);
                        }
                    }

                    //Assert.AreEqual(md5sum, "1d2e54a059ea776787ef66f1f93d3e34");
                    //Assert.AreEqual(info.MinimumBlockSize, 4096);
                    //Assert.AreEqual(info.MaximumBlockSize, 4096);
                    //Assert.AreEqual(info.MinimumFrameSize, (uint)1427);
                    //Assert.AreEqual(info.MaximumFrameSize, (uint)7211);
                    //Assert.AreEqual(info.SampleRateHz, (uint)44100);
                    //Assert.AreEqual(info.Channels, 1);
                    //Assert.AreEqual(info.BitsPerSample, 16);
                    //Assert.AreEqual(info.Samples, 1703592);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #42
0
        public void CopyOpenEditAndSaveSeekTable()
        {
            ulong targetSampleNumber = 704512; // Will remove the seekpoint for this sample number ...
            ulong expectedNumberOfSamples;     // Will be set while creating a new seekpoint
            ulong expectedByteOffset;          // Will be set while creating a new seekpoint

            string origFile = @"Data\testfile3.flac";
            string newFile  = @"Data\testfile3_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.SeekTable);

                    // Will remove the at the given sample number ...
                    SeekPoint oldSeekpoint = flac.SeekTable.SeekPoints[targetSampleNumber];
                    flac.SeekTable.SeekPoints.Remove(targetSampleNumber);

                    // Create a new Seekpoint, a little further
                    SeekPoint newSeekpoint = new SeekPoint();
                    newSeekpoint.FirstSampleNumber = targetSampleNumber + 1000;                             // Put it a 1000 samples further ...
                    newSeekpoint.NumberOfSamples   = (ushort)(oldSeekpoint.NumberOfSamples - (ushort)1000); // Since we are a 1000 further, we contain a 1000 less samples
                    expectedNumberOfSamples        = newSeekpoint.NumberOfSamples;
                    newSeekpoint.ByteOffset        = oldSeekpoint.ByteOffset;
                    expectedByteOffset             = newSeekpoint.ByteOffset;
                    flac.SeekTable.SeekPoints.Add(newSeekpoint);

                    // Create a placeholder seekpoint
                    SeekPoint placeHolder = new SeekPoint();
                    placeHolder.FirstSampleNumber = ulong.MaxValue;
                    // The other two values are "undefined"
                    Assert.IsTrue(placeHolder.IsPlaceHolder); // Already assert that the object itself handles this flac correctly.
                    flac.SeekTable.SeekPoints.Add(placeHolder);

                    // This should actually be allowed according to the FLAC format (multiple placeHolders are ok, but they must occur at the end of the seektable)
                    flac.SeekTable.SeekPoints.Add(placeHolder);

                    // Check if we actually get "2" placeholders ...
                    Assert.AreEqual <int>(2, flac.SeekTable.SeekPoints.Placeholders);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // Now we want to try and find our new SeekPoint
                    Assert.IsNotNull(flac.SeekTable);

                    Assert.IsFalse(flac.SeekTable.SeekPoints.ContainsKey(targetSampleNumber));
                    Assert.IsTrue(flac.SeekTable.SeekPoints.ContainsKey(targetSampleNumber + 1000));
                    SeekPoint newSeekpoint = flac.SeekTable.SeekPoints[targetSampleNumber + 1000];

                    Assert.AreEqual <ulong>(expectedNumberOfSamples, newSeekpoint.NumberOfSamples);
                    Assert.AreEqual <ulong>(expectedByteOffset, newSeekpoint.ByteOffset);

                    Assert.IsFalse(newSeekpoint.IsPlaceHolder);

                    // Check if we actually get "2" placeholders ...
                    Assert.AreEqual <int>(2, flac.SeekTable.SeekPoints.Placeholders);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #43
0
        public static void DuplicateMetadata()
        {
            File.Copy(@"Data\testfile4.flac", @"Data\testfile4_tmp.flac", true);
            using (FlacFile file = new FlacFile(@"Data\testfile4_tmp.flac"))
            {
                /* Appinfo is fine! */
                /*
                var appInfo = file.ApplicationInfo;
                if (appInfo == null)
                {
                    appInfo = new ApplicationInfo();
                    appInfo.ApplicationID = 10;
                    appInfo.ApplicationData = new byte[] { 10, 20, 30 };
                    file.Metadata.Add(appInfo);
                    file.Metadata.Add(appInfo);
                }
                */

                /* Cuesheet is fine ?*/
                /*
                var cueSheet = file.CueSheet;
                file.Metadata.Add(cueSheet);
                */

                /* Vorbis also fine! */
                /*
                var vorbis = file.VorbisComment;
                if (vorbis == null)
                {
                    vorbis = new VorbisComment();

                    vorbis.Album = "My Test Album";

                    file.Metadata.Add(vorbis);

                    file.Metadata.Add(vorbis);
                }

                file.Metadata.Add(vorbis);
                */

                /* Metadata not fine! */
                /*
                var streaminfo = file.StreamInfo;
                file.Metadata.Add(streaminfo);
                */

                /* SeekTable is fine */
                /*
                var seekTable = new SeekTable();
                seekTable.SeekPoints.Add(new SeekPoint() { ByteOffset = 0, FirstSampleNumber = 0, IsPlaceHolder = false, NumberOfSamples = 100 });
                file.Metadata.Add(seekTable);
                file.Metadata.Add(seekTable);
                */

                /* We know picture is fine */

                /* Padding is fine */

                /* So everything fine, except StreamInfo */

                file.Save();
            }
        }
Beispiel #44
0
        public void CopyOpenEditAndSaveSeekTable()
        {
            ulong targetSampleNumber = 704512; // Will remove the seekpoint for this sample number ...
            ulong expectedNumberOfSamples; // Will be set while creating a new seekpoint
            ulong expectedByteOffset; // Will be set while creating a new seekpoint

            string origFile = @"Data\testfile3.flac";
            string newFile = @"Data\testfile3_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.IsNotNull(flac.SeekTable);

                    // Will remove the at the given sample number ...
                    SeekPoint oldSeekpoint = flac.SeekTable.SeekPoints[targetSampleNumber];
                    flac.SeekTable.SeekPoints.Remove(targetSampleNumber);

                    // Create a new Seekpoint, a little further
                    SeekPoint newSeekpoint = new SeekPoint();
                    newSeekpoint.FirstSampleNumber = targetSampleNumber + 1000; // Put it a 1000 samples further ...
                    newSeekpoint.NumberOfSamples = (ushort)(oldSeekpoint.NumberOfSamples - (ushort)1000); // Since we are a 1000 further, we contain a 1000 less samples
                    expectedNumberOfSamples = newSeekpoint.NumberOfSamples;
                    newSeekpoint.ByteOffset = oldSeekpoint.ByteOffset;
                    expectedByteOffset = newSeekpoint.ByteOffset;
                    flac.SeekTable.SeekPoints.Add(newSeekpoint);

                    // Create a placeholder seekpoint
                    SeekPoint placeHolder = new SeekPoint();
                    placeHolder.FirstSampleNumber = ulong.MaxValue;
                    // The other two values are "undefined"
                    Assert.IsTrue(placeHolder.IsPlaceHolder); // Already assert that the object itself handles this flac correctly.
                    flac.SeekTable.SeekPoints.Add(placeHolder);

                    // This should actually be allowed according to the FLAC format (multiple placeHolders are ok, but they must occur at the end of the seektable)
                    flac.SeekTable.SeekPoints.Add(placeHolder);

                    // Check if we actually get "2" placeholders ...
                    Assert.AreEqual<int>(2, flac.SeekTable.SeekPoints.Placeholders);

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    // Now we want to try and find our new SeekPoint
                    Assert.IsNotNull(flac.SeekTable);

                    Assert.IsFalse(flac.SeekTable.SeekPoints.ContainsKey(targetSampleNumber));
                    Assert.IsTrue(flac.SeekTable.SeekPoints.ContainsKey(targetSampleNumber + 1000));
                    SeekPoint newSeekpoint = flac.SeekTable.SeekPoints[targetSampleNumber + 1000];

                    Assert.AreEqual<ulong>(expectedNumberOfSamples, newSeekpoint.NumberOfSamples);
                    Assert.AreEqual<ulong>(expectedByteOffset, newSeekpoint.ByteOffset);

                    Assert.IsFalse(newSeekpoint.IsPlaceHolder);

                    // Check if we actually get "2" placeholders ...
                    Assert.AreEqual<int>(2, flac.SeekTable.SeekPoints.Placeholders);
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #45
0
        public void CreatePicture()
        {
            uint colorDepth = 24;
            uint colors     = 256;

            byte[]      data        = System.IO.File.ReadAllBytes(Path.Combine("Data", "testimage.png"));
            string      description = "Test Picture";
            uint        height      = 213;
            uint        width       = 400;
            PictureType pictureType = PictureType.LeadArtist;
            string      mimeType    = "image/jpeg";

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                Picture pictureBlock = new Picture();

                pictureBlock.ColorDepth  = colorDepth;
                pictureBlock.Colors      = colors;
                pictureBlock.Data        = data;
                pictureBlock.Description = description;
                pictureBlock.Height      = height;
                pictureBlock.Width       = width;
                pictureBlock.PictureType = pictureType;
                pictureBlock.MIMEType    = mimeType;

                flac.Metadata.Add(pictureBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                foreach (MetadataBlock block in flac.Metadata)
                {
                    if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Picture)
                    {
                        Picture pictureBlock = (Picture)block;

                        Assert.IsNotNull(pictureBlock);

                        Assert.AreEqual <uint>(colorDepth, pictureBlock.ColorDepth);
                        Assert.AreEqual <uint>(colors, pictureBlock.Colors);
                        Assert.AreEqual <string>(description, pictureBlock.Description);
                        Assert.AreEqual <uint>(height, pictureBlock.Height);
                        Assert.AreEqual <uint>(width, pictureBlock.Width);
                        Assert.AreEqual <PictureType>(pictureType, pictureBlock.PictureType);
                        Assert.AreEqual <string>(mimeType, pictureBlock.MIMEType);

                        bool dataIsSame = true;
                        for (int i = 0; i < data.Length; i++)
                        {
                            if (data[i] != pictureBlock.Data[i])
                            {
                                dataIsSame = false;
                                break;
                            }
                        }

                        Assert.IsTrue(dataIsSame);
                    }
                }
            }
        }
Beispiel #46
0
        public void OpenFlacFileAndCreateMultipleCueSheets()
        {
            int cueSheetCount = 0;
            string origFile = @"Data\testfile4.flac";
            string newFile = @"Data\testfile4_temp.flac";

            FileHelper.GetNewFile(origFile, newFile);

            try
            {
                using (FlacFile flac = new FlacFile(newFile))
                {
                    if (flac.CueSheet != null)
                    {
                        cueSheetCount = 1;
                    }

                    // Add a second (empty) cuesheet
                    CueSheet newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack() { TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA });
                    flac.Metadata.Add(newCueSheet);
                    // Add a third (empty) cuesheet
                    newCueSheet = new CueSheet();
                    newCueSheet.Tracks.Add(new CueSheetTrack() { TrackNumber = CueSheet.CUESHEET_LEADOUT_TRACK_NUMBER_CDDA });
                    flac.Metadata.Add(newCueSheet);

                    cueSheetCount += 2;

                    flac.Save();
                }
                using (FlacFile flac = new FlacFile(newFile))
                {
                    Assert.AreEqual<int>(cueSheetCount, flac.GetAllCueSheets().Count());
                }
            }
            finally
            {
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
Beispiel #47
0
        public void CreatePicture()
        {
            uint colorDepth = 24;
            uint colors = 256;
            byte[] data = System.IO.File.ReadAllBytes(@"Data\testimage.png");
            string description = "Test Picture";
            uint height = 213;
            uint width = 400;
            PictureType pictureType = PictureType.LeadArtist;
            string mimeType = "image/jpeg";

            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                Picture pictureBlock = new Picture();

                pictureBlock.ColorDepth = colorDepth;
                pictureBlock.Colors = colors;
                pictureBlock.Data = data;
                pictureBlock.Description = description;
                pictureBlock.Height = height;
                pictureBlock.Width = width;
                pictureBlock.PictureType = pictureType;
                pictureBlock.MIMEType = mimeType;

                flac.Metadata.Add(pictureBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                foreach (MetadataBlock block in flac.Metadata)
                {
                    if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Picture)
                    {
                        Picture pictureBlock = (Picture)block;

                        Assert.IsNotNull(pictureBlock);

                        Assert.AreEqual<uint>(colorDepth, pictureBlock.ColorDepth);
                        Assert.AreEqual<uint>(colors, pictureBlock.Colors);
                        Assert.AreEqual<string>(description, pictureBlock.Description);
                        Assert.AreEqual<uint>(height, pictureBlock.Height);
                        Assert.AreEqual<uint>(width, pictureBlock.Width);
                        Assert.AreEqual<PictureType>(pictureType, pictureBlock.PictureType);
                        Assert.AreEqual<string>(mimeType, pictureBlock.MIMEType);

                        bool dataIsSame = true;
                        for (int i = 0; i < data.Length; i++)
                        {
                            if (data[i] != pictureBlock.Data[i])
                            {
                                dataIsSame = false;
                                break;
                            }
                        }

                        Assert.IsTrue(dataIsSame);

                    }
                }
            }
        }
Beispiel #48
0
        public void CreatePadding()
        {
            uint emptyBitCount = 256;
            FileHelper.GetNewFile(origFile, newFile);

            using (FlacFile flac = new FlacFile(newFile))
            {
                // Adding some bits of padding
                Padding paddingBlock = new Padding();
                paddingBlock.EmptyBitCount = emptyBitCount;
                flac.Metadata.Add(paddingBlock);

                flac.Save();
            }

            using (FlacFile flac = new FlacFile(newFile))
            {
                Padding padding = flac.Padding;
                Assert.AreEqual<uint>(emptyBitCount, padding.EmptyBitCount);
            }
        }