Implement IAudioSource.Duration property and IAudioDecoderSettings.Open extension method.

This commit is contained in:
Grigory Chudov
2018-04-07 23:02:01 -04:00
parent be881945ac
commit deb3448a55
27 changed files with 817 additions and 75 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using Newtonsoft.Json;
using System.IO;
namespace CUETools.Codecs
{
@@ -44,5 +45,10 @@ namespace CUETools.Codecs
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(settings))
property.ResetValue(settings);
}
public static IAudioSource Open(this IAudioDecoderSettings settings, string path, Stream IO = null)
{
return Activator.CreateInstance(settings.DecoderType, settings, path, IO) as IAudioSource;
}
}
}

View File

@@ -54,6 +54,8 @@ namespace CUETools.Codecs
}
}
public TimeSpan Duration => Length < 0 ? TimeSpan.Zero : TimeSpan.FromSeconds((double)Length / PCM.SampleRate);
public long Length
{
get

View File

@@ -27,6 +27,15 @@ namespace CUETools.Codecs.CommandLine
}
}
public TimeSpan Duration
{
get
{
Initialize();
return rdr.Duration;
}
}
public long Length
{
get

View File

@@ -1,4 +1,6 @@
namespace CUETools.Codecs
using System;
namespace CUETools.Codecs
{
public interface IAudioSource
{
@@ -7,7 +9,8 @@
AudioPCMConfig PCM { get; }
string Path { get; }
long Length { get; }
TimeSpan Duration { get; }
long Length { get; }
long Position { get; set; }
long Remaining { get; }

View File

@@ -1,4 +1,6 @@
namespace CUETools.Codecs.NULL
using System;
namespace CUETools.Codecs.NULL
{
public class AudioDecoder : IAudioSource
{
@@ -8,6 +10,8 @@
public IAudioDecoderSettings Settings => null;
public TimeSpan Duration => TimeSpan.FromSeconds((double)Length / PCM.SampleRate);
public long Length
{
get { return _sampleCount; }

View File

@@ -55,6 +55,8 @@ namespace CUETools.Codecs.WAV
}
}
public TimeSpan Duration => Length < 0 ? TimeSpan.Zero : TimeSpan.FromSeconds((double)Length / PCM.SampleRate);
public long Length
{
get