Files
cuetools.net/CUETools.Codecs/IAudioSource.cs

83 lines
2.3 KiB
C#
Raw Permalink Normal View History

using System;
2018-04-29 16:53:55 -04:00
using System.Collections.Generic;
namespace CUETools.Codecs
2011-10-24 00:13:35 +00:00
{
public interface IAudioSource
{
IAudioDecoderSettings Settings { get; }
2011-10-24 00:13:35 +00:00
AudioPCMConfig PCM { get; }
string Path { get; }
TimeSpan Duration { get; }
long Length { get; }
2011-10-24 00:13:35 +00:00
long Position { get; set; }
long Remaining { get; }
int Read(AudioBuffer buffer, int maxLength);
void Close();
}
2018-04-29 16:53:55 -04:00
public interface IAudioTitle
{
List<TimeSpan> Chapters { get; }
2018-04-30 22:32:49 -04:00
AudioPCMConfig PCM { get; }
string Codec { get; }
string Language { get; }
int StreamId { get; }
2018-04-29 16:53:55 -04:00
//IAudioSource Open { get; }
}
2018-04-30 22:32:49 -04:00
public interface IAudioTitleSet
2018-04-29 16:53:55 -04:00
{
List<IAudioTitle> AudioTitles { get; }
}
2018-04-30 22:32:49 -04:00
public static class IAudioTitleExtensions
2018-04-29 16:53:55 -04:00
{
2018-04-30 22:32:49 -04:00
public static TimeSpan GetDuration(this IAudioTitle title)
{
var chapters = title.Chapters;
return chapters[chapters.Count - 1];
}
public static string GetRateString(this IAudioTitle title)
{
var sr = title.PCM.SampleRate;
if (sr % 1000 == 0) return $"{sr / 1000}KHz";
if (sr % 100 == 0) return $"{sr / 100}.{(sr / 100) % 10}KHz";
return $"{sr}Hz";
}
public static string GetFormatString(this IAudioTitle title)
{
switch (title.PCM.ChannelCount)
{
case 1: return "mono";
case 2: return "stereo";
default: return "multi-channel";
}
}
}
public class SingleAudioTitle : IAudioTitle
{
public SingleAudioTitle(IAudioSource source) { this.source = source; }
2018-04-29 16:53:55 -04:00
public List<TimeSpan> Chapters => new List<TimeSpan> { TimeSpan.Zero, source.Duration };
2018-04-30 22:32:49 -04:00
public AudioPCMConfig PCM => source.PCM;
public string Codec => source.Settings.Extension;
public string Language => "";
public int StreamId => 0;
2018-04-29 16:53:55 -04:00
IAudioSource source;
}
2018-04-30 22:32:49 -04:00
public class SingleAudioTitleSet : IAudioTitleSet
2018-04-29 16:53:55 -04:00
{
2018-04-30 22:32:49 -04:00
public SingleAudioTitleSet(IAudioSource source) { this.source = source; }
public List<IAudioTitle> AudioTitles => new List<IAudioTitle> { new SingleAudioTitle(source) };
2018-04-29 16:53:55 -04:00
IAudioSource source;
}
2011-10-24 00:13:35 +00:00
}