diff --git a/CUETools.Codecs/WAVReader.cs b/CUETools.Codecs/WAVReader.cs index 903e947..2615fb7 100644 --- a/CUETools.Codecs/WAVReader.cs +++ b/CUETools.Codecs/WAVReader.cs @@ -202,7 +202,7 @@ namespace CUETools.Codecs _dataOffset = pos; if (!_IO.CanSeek || _IO.Length <= maxFileSize) { - if (ckSize >= 0x7fffffff) + if (ckSize == 0 || ckSize >= 0x7fffffff) _dataLen = -1; else _dataLen = (long)ckSize; diff --git a/CUETools.Processor/CUEConfig.cs b/CUETools.Processor/CUEConfig.cs index 4010b28..2ca52a2 100644 --- a/CUETools.Processor/CUEConfig.cs +++ b/CUETools.Processor/CUEConfig.cs @@ -161,6 +161,7 @@ namespace CUETools.Processor { encoders.Add(new CUEToolsUDC("flake", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11 12", "8", "flake.exe", "-%M - -o %O -p %P")); encoders.Add(new CUEToolsUDC("takc", "tak", true, "0 1 2 2e 2m 3 3e 3m 4 4e 4m", "2", "takc.exe", "-e -p%M -overwrite - %O")); + encoders.Add(new CUEToolsUDC("WMAEncode", "wma", true, "", "", "WMAEncode.exe", "-i -c lossless - %O")); encoders.Add(new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "-i - -f ipod -acodec alac -y %O")); encoders.Add(new CUEToolsUDC("VBR (lame.exe)", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", "lame.exe", "--vbr-new -%M - %O")); encoders.Add(new CUEToolsUDC("CBR (lame.exe)", "mp3", false, "96 128 192 256 320", "256", "lame.exe", "-m s -q 0 -b %M --noreplaygain - %O")); @@ -169,7 +170,8 @@ namespace CUETools.Processor encoders.Add(new CUEToolsUDC("qaac tvbr", "m4a", false, "10 20 30 40 50 60 70 80 90 100 110 127", "80", "qaac.exe", "-s -V %M -q 2 - -o %O")); decoders.Add("takc", new CUEToolsUDC("takc", "tak", true, "", "", "takc.exe", "-d %I -")); - decoders.Add("ffmpeg alac", new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "%I -f wav -")); + decoders.Add("ffmpeg alac", new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "-v 0 -i %I -f wav -")); + decoders.Add("wma2wav", new CUEToolsUDC("wma2wav", "wma", true, "", "", "ffmpeg.exe", "-v 0 -i %I -f wav -")); } else { @@ -184,6 +186,7 @@ namespace CUETools.Processor formats.Add("wav", new CUEToolsFormat("wav", CUEToolsTagger.TagLibSharp, true, false, true, false, true, encoders.GetDefault("wav", true), null, GetDefaultDecoder("wav"))); formats.Add("m4a", new CUEToolsFormat("m4a", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("m4a", true), encoders.GetDefault("m4a", false), GetDefaultDecoder("m4a"))); formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, true, encoders.GetDefault("tak", true), null, "takc")); + formats.Add("wma", new CUEToolsFormat("wma", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("wma", true), null, "wma2wav")); formats.Add("mp3", new CUEToolsFormat("mp3", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("mp3", false), null)); formats.Add("ogg", new CUEToolsFormat("ogg", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("ogg", false), null)); diff --git a/CUETools.Processor/CUESheet.cs b/CUETools.Processor/CUESheet.cs index 827af74..36ee889 100644 --- a/CUETools.Processor/CUESheet.cs +++ b/CUETools.Processor/CUESheet.cs @@ -2180,15 +2180,24 @@ namespace CUETools.Processor ? (TagLib.File.IFileAbstraction)new ArchiveFileAbstraction(this, path) : (TagLib.File.IFileAbstraction)new TagLib.File.LocalFileAbstraction(path); fileInfo = TagLib.File.Create(file); + if (fileInfo.Properties.AudioSampleCount > 0) + return (int)fileInfo.Properties.AudioSampleCount; } IAudioSource audioSource = AudioReadWrite.GetAudioSource(path, _isArchive ? OpenArchive(path, true) : null, _config); try { - if (!audioSource.PCM.IsRedBook || - audioSource.Length <= 0 || + if (!audioSource.PCM.IsRedBook) + throw new Exception("Audio format is not Red Book PCM."); + if (audioSource.Length <= 0) + { + AudioBuffer buff = new AudioBuffer(audioSource, 0x10000); + while (audioSource.Read(buff, -1) != 0) + CheckStop(); + } + if (audioSource.Length <= 0 || audioSource.Length >= Int32.MaxValue) - throw new Exception("Audio format is invalid."); + throw new Exception("Audio file length is unknown or invalid."); return (int)audioSource.Length; } finally diff --git a/taglib-sharp/src/TagLib/Aac/AudioHeader.cs b/taglib-sharp/src/TagLib/Aac/AudioHeader.cs index 336fe8d..962e6a4 100644 --- a/taglib-sharp/src/TagLib/Aac/AudioHeader.cs +++ b/taglib-sharp/src/TagLib/Aac/AudioHeader.cs @@ -210,7 +210,23 @@ namespace TagLib.Aac { return audiobitrate; } - } + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } /// /// Gets the sample rate of the audio represented by the diff --git a/taglib-sharp/src/TagLib/Aiff/StreamHeader.cs b/taglib-sharp/src/TagLib/Aiff/StreamHeader.cs index c7d32b7..e3a51b2 100644 --- a/taglib-sharp/src/TagLib/Aiff/StreamHeader.cs +++ b/taglib-sharp/src/TagLib/Aiff/StreamHeader.cs @@ -276,9 +276,25 @@ namespace TagLib.Aiff return (int) ((stream_length*8L)/ d.TotalSeconds)/1000; } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Ape/StreamHeader.cs b/taglib-sharp/src/TagLib/Ape/StreamHeader.cs index 4481853..ba954ec 100644 --- a/taglib-sharp/src/TagLib/Ape/StreamHeader.cs +++ b/taglib-sharp/src/TagLib/Ape/StreamHeader.cs @@ -303,9 +303,25 @@ namespace TagLib.Ape { return (int) ((stream_length * 8L) / d.TotalSeconds) / 1000; } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Flac/StreamHeader.cs b/taglib-sharp/src/TagLib/Flac/StreamHeader.cs index 658c91d..56d41eb 100644 --- a/taglib-sharp/src/TagLib/Flac/StreamHeader.cs +++ b/taglib-sharp/src/TagLib/Flac/StreamHeader.cs @@ -131,9 +131,25 @@ namespace TagLib.Flac ((stream_length * 8L) / Duration.TotalSeconds) / 1000 : 0); } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/ICodec.cs b/taglib-sharp/src/TagLib/ICodec.cs index f2b8490..b16b205 100644 --- a/taglib-sharp/src/TagLib/ICodec.cs +++ b/taglib-sharp/src/TagLib/ICodec.cs @@ -123,8 +123,18 @@ namespace TagLib { /// A value containing a bitrate of the /// audio represented by the current instance. /// - int AudioBitrate {get;} - + int AudioBitrate {get;} + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + long AudioSampleCount {get;} + /// /// Gets the sample rate of the audio represented by the /// current instance. diff --git a/taglib-sharp/src/TagLib/Matroska/AudioTrack.cs b/taglib-sharp/src/TagLib/Matroska/AudioTrack.cs index 071a398..c731cef 100644 --- a/taglib-sharp/src/TagLib/Matroska/AudioTrack.cs +++ b/taglib-sharp/src/TagLib/Matroska/AudioTrack.cs @@ -133,8 +133,23 @@ namespace TagLib.Matroska public int AudioBitrate { get { return 0; } - } - + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } /// /// Audio track sampling rate. /// diff --git a/taglib-sharp/src/TagLib/Mpc/StreamHeader.cs b/taglib-sharp/src/TagLib/Mpc/StreamHeader.cs index 8895cdb..62b317f 100644 --- a/taglib-sharp/src/TagLib/Mpc/StreamHeader.cs +++ b/taglib-sharp/src/TagLib/Mpc/StreamHeader.cs @@ -214,9 +214,25 @@ namespace TagLib.MusePack { ((stream_length * 8L) / Duration.TotalSeconds) / 1000 : 0); } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Mpeg/AudioHeader.cs b/taglib-sharp/src/TagLib/Mpeg/AudioHeader.cs index 09eed4e..dbe0a68 100644 --- a/taglib-sharp/src/TagLib/Mpeg/AudioHeader.cs +++ b/taglib-sharp/src/TagLib/Mpeg/AudioHeader.cs @@ -359,9 +359,25 @@ namespace TagLib.Mpeg { AudioLayer > 0 ? AudioLayer - 1 : 0, (int) (flags >> 12) & 0x0F]; } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Mpeg4/Boxes/IsoAudioSampleEntry.cs b/taglib-sharp/src/TagLib/Mpeg4/Boxes/IsoAudioSampleEntry.cs index 273fa10..cd2241a 100644 --- a/taglib-sharp/src/TagLib/Mpeg4/Boxes/IsoAudioSampleEntry.cs +++ b/taglib-sharp/src/TagLib/Mpeg4/Boxes/IsoAudioSampleEntry.cs @@ -193,9 +193,25 @@ namespace TagLib.Mpeg4 { // Return from the elementary stream descriptor. return (int) esds.AverageBitrate; } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Ogg/Codecs/Vorbis.cs b/taglib-sharp/src/TagLib/Ogg/Codecs/Vorbis.cs index c38d1b5..cb6da64 100644 --- a/taglib-sharp/src/TagLib/Ogg/Codecs/Vorbis.cs +++ b/taglib-sharp/src/TagLib/Ogg/Codecs/Vorbis.cs @@ -213,9 +213,25 @@ namespace TagLib.Ogg.Codecs return (int) ((float)header.bitrate_nominal / 1000f + 0.5); } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Properties.cs b/taglib-sharp/src/TagLib/Properties.cs index bc7cad4..040d896 100644 --- a/taglib-sharp/src/TagLib/Properties.cs +++ b/taglib-sharp/src/TagLib/Properties.cs @@ -244,9 +244,37 @@ namespace TagLib { return 0; } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + foreach (ICodec codec in codecs) + { + if (codec == null || + (codec.MediaTypes & MediaTypes.Audio) == 0) + continue; + + IAudioCodec audio = codec as IAudioCodec; + + if (audio != null && audio.AudioSampleCount != 0) + return audio.AudioSampleCount; + } + + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs b/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs index 9ea07ce..b103981 100644 --- a/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs +++ b/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs @@ -203,9 +203,25 @@ namespace TagLib.Riff { return (int) Math.Round ( average_bytes_per_second * 8d / 1000d); } - } - - /// + } + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the sample rate of the audio represented by the /// current instance. /// diff --git a/taglib-sharp/src/TagLib/WavPack/StreamHeader.cs b/taglib-sharp/src/TagLib/WavPack/StreamHeader.cs index 2cb7d55..ed58d9d 100644 --- a/taglib-sharp/src/TagLib/WavPack/StreamHeader.cs +++ b/taglib-sharp/src/TagLib/WavPack/StreamHeader.cs @@ -148,9 +148,25 @@ namespace TagLib.WavPack { - #region Public Properties - - /// + #region Public Properties + + /// + /// Gets the sample count of the audio represented by the + /// current instance. + /// + /// + /// A value containing the sample count + /// of the audio represented by the current instance. + /// + public long AudioSampleCount + { + get + { + return 0; + } + } + + /// /// Gets the duration of the media represented by the current /// instance. ///