2022-12-16 18:20:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
namespace CUETools.Codecs;
|
|
|
|
|
|
|
|
|
|
|
|
public interface IAudioSource
|
2022-12-16 18:20:23 +00:00
|
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
|
IAudioDecoderSettings Settings { get; }
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
AudioPCMConfig PCM { get; }
|
|
|
|
|
|
string Path { get; }
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
TimeSpan Duration { get; }
|
|
|
|
|
|
long Length { get; }
|
|
|
|
|
|
long Position { get; set; }
|
|
|
|
|
|
long Remaining { get; }
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
int Read(AudioBuffer buffer, int maxLength);
|
|
|
|
|
|
void Close();
|
|
|
|
|
|
}
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
public interface IAudioTitle
|
|
|
|
|
|
{
|
|
|
|
|
|
List<TimeSpan> Chapters { get; }
|
|
|
|
|
|
AudioPCMConfig PCM { get; }
|
|
|
|
|
|
string Codec { get; }
|
|
|
|
|
|
string Language { get; }
|
|
|
|
|
|
int StreamId { get; }
|
|
|
|
|
|
|
|
|
|
|
|
//IAudioSource Open { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface IAudioTitleSet
|
|
|
|
|
|
{
|
|
|
|
|
|
List<IAudioTitle> AudioTitles { get; }
|
|
|
|
|
|
}
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
public static class IAudioTitleExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static TimeSpan GetDuration(this IAudioTitle title)
|
2022-12-16 18:20:23 +00:00
|
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
|
List<TimeSpan> chapters = title.Chapters;
|
|
|
|
|
|
|
|
|
|
|
|
return chapters[chapters.Count - 1];
|
2022-12-16 18:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
|
|
|
|
|
|
public static string GetRateString(this IAudioTitle title)
|
2022-12-16 18:20:23 +00:00
|
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
|
int sr = title.PCM.SampleRate;
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
if(sr % 1000 == 0) return $"{sr / 1000}KHz";
|
|
|
|
|
|
if(sr % 100 == 0) return $"{sr / 100}.{sr / 100 % 10}KHz";
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
return $"{sr}Hz";
|
|
|
|
|
|
}
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
public static string GetFormatString(this IAudioTitle title)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(title.PCM.ChannelCount)
|
2022-12-16 18:20:23 +00:00
|
|
|
|
{
|
2024-05-01 04:39:38 +01:00
|
|
|
|
case 1:
|
|
|
|
|
|
return "mono";
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
return "stereo";
|
|
|
|
|
|
default:
|
|
|
|
|
|
return "multi-channel";
|
2022-12-16 18:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-01 04:39:38 +01:00
|
|
|
|
}
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
public class SingleAudioTitle : IAudioTitle
|
|
|
|
|
|
{
|
|
|
|
|
|
readonly IAudioSource source;
|
|
|
|
|
|
public SingleAudioTitle(IAudioSource source) => this.source = source;
|
2022-12-16 18:20:23 +00:00
|
|
|
|
|
2024-05-01 04:39:38 +01:00
|
|
|
|
#region IAudioTitle Members
|
|
|
|
|
|
|
|
|
|
|
|
public List<TimeSpan> Chapters => [TimeSpan.Zero, source.Duration];
|
|
|
|
|
|
public AudioPCMConfig PCM => source.PCM;
|
|
|
|
|
|
public string Codec => source.Settings.Extension;
|
|
|
|
|
|
public string Language => "";
|
|
|
|
|
|
public int StreamId => 0;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2022-12-16 18:20:23 +00:00
|
|
|
|
}
|
2024-05-01 04:39:38 +01:00
|
|
|
|
|
|
|
|
|
|
public class SingleAudioTitleSet : IAudioTitleSet
|
|
|
|
|
|
{
|
|
|
|
|
|
readonly IAudioSource source;
|
|
|
|
|
|
public SingleAudioTitleSet(IAudioSource source) => this.source = source;
|
|
|
|
|
|
|
|
|
|
|
|
#region IAudioTitleSet Members
|
|
|
|
|
|
|
|
|
|
|
|
public List<IAudioTitle> AudioTitles => [new SingleAudioTitle(source)];
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|