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 OpenAndCloseFlacFileWithFilePath() { using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile1.flac"))) { // Doing nothing } }
public int GetVersionFromExportedTrackFile(string path) { if (path.EndsWith(".ogg")) { using (var vorbisReader = new VorbisReader(path)) { foreach (var comment in vorbisReader.Comments) { if (!comment.StartsWith("VERSION=", true, null)) { continue; } var value = comment.Split('=')[1]; var version = int.Parse(value); return(version); } } } else if (path.EndsWith(".flac")) { using (var flacFile = new FlacFile(path)) { if (flacFile.VorbisComment.ContainsField("VERSION")) { return(int.Parse(flacFile.VorbisComment["VERSION"].Value)); } } } throw new SoundtrackException("No version comment in specified file."); }
static void Main(string[] args) { DuplicateMetadata(); using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { // Access to the StreamInfo class (actually this should ALWAYS be there ...) var streamInfo = file.StreamInfo; if (streamInfo != null) { Console.WriteLine("Flac audio length in seconds: {0}", file.StreamInfo.Duration); } // Access to the VorbisComment IF it exists in the file var vorbisComment = file.VorbisComment; if (vorbisComment != null) { Console.WriteLine("Artist - Title: {0} - {1}", vorbisComment.Artist, vorbisComment.Title); } // Get all other types of metdata blocks: var metadata = file.Metadata; foreach (MetadataBlock block in metadata) { Console.WriteLine("{0} metadata block.", block.Header.Type); } } Console.ReadLine(); }
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); } } }
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); } }
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); } } }
public void OpenInvalidFlacFile() { using (FlacFile file = new FlacFile(@"Data\noflacfile.ogg")) { // Doing nothing } }
public void OpenFlacFileAndCheckMetadata() { using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { Assert.IsTrue(file.Metadata.Count > 0, "No metadata blocks were found for the test file, this is not correct!"); } }
public void OpenFlacFileAndCheckSeekTable() { using (FlacFile file = new FlacFile(@"Data\testfile3.flac")) { var seekTable = file.SeekTable; // There's a seekpoint every 2 seconds so there should be 20 seekpoints ... Assert.AreEqual(20, seekTable.SeekPoints.Count); // We know seekpoint 0 should start at sample number 0, with an offset of 0 and number of samples = 4096 Assert.AreEqual <ulong>(0, seekTable.SeekPoints.Values[0].FirstSampleNumber); Assert.AreEqual <ulong>(0, seekTable.SeekPoints.Values[0].ByteOffset); Assert.AreEqual <ulong>(4096, seekTable.SeekPoints.Values[0].NumberOfSamples); // We know seekpoint 2 should start at sample number 176128, with an offset of 121744 and number of samples = 4096 Assert.AreEqual <ulong>(176128, seekTable.SeekPoints.Values[2].FirstSampleNumber); Assert.AreEqual <ulong>(121744, seekTable.SeekPoints.Values[2].ByteOffset); Assert.AreEqual <ushort>(4096, seekTable.SeekPoints.Values[2].NumberOfSamples); // We know seekpoint 5 should start at sample number 438272, with an offset of 302152 and number of samples = 4096 Assert.AreEqual <ulong>(438272, seekTable.SeekPoints.Values[5].FirstSampleNumber); Assert.AreEqual <ulong>(302152, seekTable.SeekPoints.Values[5].ByteOffset); Assert.AreEqual <ushort>(4096, seekTable.SeekPoints.Values[5].NumberOfSamples); // We know seekpoint 19 should start at sample number 1675264, with an offset of 1451579 and number of samples = 4096 Assert.AreEqual <ulong>(1675264, seekTable.SeekPoints.Values[19].FirstSampleNumber); Assert.AreEqual <ulong>(1451579, seekTable.SeekPoints.Values[19].ByteOffset); Assert.AreEqual <ushort>(4096, seekTable.SeekPoints.Values[19].NumberOfSamples); // Not testing ALL seekpoints ... } }
public void OpenAndCloseFlacFileWithFilePath() { using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { // Doing nothing } }
public void OpenFlacFileAndCheckVorbisComment() { using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { //Assert.IsTrue(file.Metadata.Count > 0, "No metadata blocks were found for the test file, this is not correct!"); foreach (MetadataBlock block in file.Metadata) { if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.VorbisComment) { VorbisComment info = (VorbisComment)block; Assert.AreEqual("Ziggystar", info["ARTIST"].Value); Assert.AreEqual("Ziggystar", info.Artist.Value); Assert.AreEqual("Roland jx3p demo", info["TITLE"].Value); Assert.AreEqual("Roland jx3p demo", info.Title.Value); Assert.AreEqual("Wiki Commons", info["ALBUM"].Value); Assert.AreEqual("Wiki Commons", info.Album.Value); Assert.AreEqual("2005", info["DATE"].Value); Assert.AreEqual("2005", info.Date.Value); Assert.AreEqual("01", info["TRACKNUMBER"].Value); Assert.AreEqual("01", info.TrackNumber.Value); Assert.AreEqual("Electronic", info["GENRE"].Value); Assert.AreEqual("Electronic", info.Genre.Value); Assert.IsFalse(info.ContainsField("UNEXISTINGKEY")); } } } }
public void OpenInvalidFlacFile() { using (FlacFile file = new FlacFile(Path.Combine("Data", "noflacfile.ogg"))) { // Doing nothing } }
static void Main(string[] args) { DuplicateMetadata(); // Access to the StreamInfo class using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { Console.WriteLine("Flac audio length in seconds: {0}", file.StreamInfo.Duration); } // Access to the VorbisComment IF it exists in the file using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { var vorbisComment = file.VorbisComment; if (vorbisComment != null) { Console.WriteLine("Artist - Title: {0} - {1}", vorbisComment.Artist, vorbisComment.Title); } } // Access to the VorbisComment with multiple values for a single field using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { var vorbisComment = file.VorbisComment; if (vorbisComment != null) { foreach (var value in vorbisComment.Artist) { Console.WriteLine("Artist: {0}", value); } } } // Iterate through all VorbisComment tags using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { var vorbisComment = file.VorbisComment; if (vorbisComment != null) { foreach (var tag in vorbisComment) { Console.WriteLine("{0}: {1}", tag.Key, tag.Value); } } } // Get all other types of metdata blocks using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { var metadata = file.Metadata; foreach (MetadataBlock block in metadata) { Console.WriteLine("{0} metadata block.", block.Header.Type); } } Console.ReadLine(); }
public void SaveShouldNotClearAccessRights() { using (var file = new FlacFile(testFile)) { file.Save(); } Assert.IsTrue(EveryoneHasReadAccess(testFile), "Test file lost Everyone Read access after save."); }
private static void P(Track t, FlacFile file, string key, Action <Track, string> todo) { var item = file.VorbisComment[key]; if (item != null && !string.IsNullOrEmpty(item.Value)) { todo(t, item.Value); } }
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); } } }
public async Task ApplyMetadata(string filePath, string filename, Track metadata) { try { string fullPath = Path.Combine(filePath, filename); using (MemoryStream modifiedFlac = new MemoryStream()) { using (FileStream originalFile = File.Open(fullPath, FileMode.Open)) { FlacFile flac = new FlacFile(originalFile); string albumArtLocation = Path.Combine(filePath, $"{metadata.Album}{Path.GetExtension(metadata.AlbumArtUrl)}"); if (File.Exists(albumArtLocation)) { _logger.LogInformation("Album art was discovered. Adding it to the flac."); using (FileStream stream = File.Open(albumArtLocation, FileMode.Open)) { flac.AddPicture(stream); } } flac.VorbisComment.CommentList[VorbisCommentType.Title] = metadata?.Title; flac.VorbisComment.CommentList[VorbisCommentType.TrackNumber] = metadata.TrackNumber?.ToString(); flac.VorbisComment.CommentList[VorbisCommentType.TrackTotal] = metadata.TrackTotal?.ToString(); flac.VorbisComment.CommentList[VorbisCommentType.Year] = metadata.Year; flac.VorbisComment.CommentList[VorbisCommentType.Album] = metadata.Album; flac.VorbisComment.CommentList[VorbisCommentType.Artist] = metadata.Artist; flac.VorbisComment.CommentList[VorbisCommentType.Composer] = metadata.Composer; flac.VorbisComment.CommentList[VorbisCommentType.Copyright] = metadata.Copyright; flac.VorbisComment.CommentList[VorbisCommentType.DiscNumber] = metadata.DiscNumber?.ToString(); flac.VorbisComment.CommentList[VorbisCommentType.DiscTotal] = metadata.DiscTotal?.ToString(); flac.VorbisComment.CommentList[VorbisCommentType.Genre] = metadata.Genre; flac.VorbisComment.CommentList[VorbisCommentType.Lyricist] = metadata.Lyricist; flac.VorbisComment.CommentList[VorbisCommentType.Lyrics] = metadata.Lyrics; await flac.SaveAsync(modifiedFlac); } modifiedFlac.Position = 0; using (FileStream originalFile = File.Open(fullPath, FileMode.Create)) { await modifiedFlac.CopyToAsync(originalFile); } } } catch (Exception e) { _logger.LogError(e, $"Failed to apply metadata."); } return; }
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); } }
private static void PS(Track t, FlacFile file, string key, Action <Track, short> todo) { var item = file.VorbisComment[key]; if (item != null && !string.IsNullOrEmpty(item.Value)) { if (short.TryParse(item.Value, out var num)) { todo(t, num); } } }
public void IterateThroughVorbisCommentsShouldSeeAllVorbisComments() { using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile1.flac"))) { var counter = 0; foreach (var vorbisComment in file.VorbisComment) { counter++; } Assert.AreEqual(9, counter); } }
public void CreateInvalidCueSheet() { FileHelper.GetNewFile(origFile, newFile); using (FlacFile flac = new FlacFile(newFile)) { CueSheet sheet = new CueSheet(); flac.Metadata.Add(sheet); flac.Save(); } }
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); } } }
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); } } }
public void OpenFlacFileAndCheckPadding() { using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { //Assert.IsTrue(file.Metadata.Count > 0, "No metadata blocks were found for the test file, this is not correct!"); foreach (MetadataBlock block in file.Metadata) { if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.Padding) { Assert.AreEqual(block.Header.MetaDataBlockLength, ((Padding)block).EmptyBitCount / 8); } } } }
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); } } }
public async Task TestBasicFlacFileFromStream() { var stream = await KnownFolders.MusicLibrary.GetFileAsync("test1.flac"); var png = await KnownFolders.MusicLibrary.GetFileAsync("300367.png"); var stream2 = await KnownFolders.MusicLibrary.CreateFileAsync("test2.flac", CreationCollisionOption.ReplaceExisting); var file = new FlacFile(await stream.OpenStreamForWriteAsync()); file.AddPicture(PictureType.CoverFront, await png.OpenStreamForReadAsync()); file.VorbisComment.CommentList[VorbisCommentType.Album] = "test"; await file.SaveAsync(await stream2.OpenStreamForWriteAsync()); }
public void IterateThroughVorbisCommentsShouldSeeAllVorbisCommentsWithCorrectValues() { using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile1.flac"))) { foreach (var vorbisComment in file.VorbisComment) { if (vorbisComment.Key == "ARTIST") { Assert.AreEqual("Ziggystar", vorbisComment.Value.Value, "Artist did not have the expected value."); } if (vorbisComment.Key == "TITLE") { Assert.AreEqual("Roland jx3p demo", vorbisComment.Value.Value, "Title did not have the expected value."); } } } }
public void OverflowCueSheetTracks() { string flacFile = @"Data\testfile4.flac"; using (FlacFile file = new FlacFile(flacFile)) { CueSheet sheet = new CueSheet(); for (int i = 0; i < 100; i++) { sheet.Tracks.Add(new CueSheetTrack()); } // This guy should throw an exception ... sheet.Tracks.Add(new CueSheetTrack()); } }
public ISoundData Decode(Stream stream) { try { FlacFile file = new FlacFile(stream); byte[] buffer = new byte[stream.Length]; file.Read(buffer, 0, buffer.Length); return(new SoundData(file.WaveFormat.Channels, file.WaveFormat.BitsPerSample, file.WaveFormat.SampleRate, buffer, buffer.Length)); } catch (FlacException e) { Debug.WriteLine("Failed to parse flac file: " + e); return(null); } }
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); } }
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); } }
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); } } }
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); } }
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); } } }
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); } } } }
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(); } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } }
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); } } }
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); } }
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); } } }
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); } } }
static void Main(string[] args) { DuplicateMetadata(); using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { // Access to the StreamInfo class (actually this should ALWAYS be there ...) var streamInfo = file.StreamInfo; if (streamInfo != null) Console.WriteLine("Flac audio length in seconds: {0}", file.StreamInfo.Duration); // Access to the VorbisComment IF it exists in the file var vorbisComment = file.VorbisComment; if (vorbisComment != null) Console.WriteLine("Artist - Title: {0} - {1}", vorbisComment.Artist, vorbisComment.Title); // Get all other types of metdata blocks: var metadata = file.Metadata; foreach (MetadataBlock block in metadata) Console.WriteLine("{0} metadata block.", block.Header.Type); } Console.ReadLine(); }
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); } } }
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); } } }