2008-10-13 19:25:11 +00:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using FLACDotNet;
|
|
|
|
|
using WavPackDotNet;
|
|
|
|
|
using APEDotNet;
|
2008-11-04 01:23:30 +00:00
|
|
|
using ALACDotNet;
|
|
|
|
|
using AudioCodecsDotNet;
|
2008-10-13 19:25:11 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
2008-10-17 20:23:33 +00:00
|
|
|
namespace CUEToolsLib {
|
2008-10-13 19:25:11 +00:00
|
|
|
public static class AudioReadWrite {
|
2008-11-10 08:42:42 +00:00
|
|
|
public static IAudioSource GetAudioSource(string path, Stream IO)
|
|
|
|
|
{
|
|
|
|
|
switch (Path.GetExtension(path).ToLower())
|
|
|
|
|
{
|
2008-11-10 09:31:14 +00:00
|
|
|
case ".wav":
|
|
|
|
|
return new WAVReader(path, IO);
|
2008-11-10 16:12:16 +00:00
|
|
|
case ".m4a":
|
|
|
|
|
return new ALACReader(path, IO);
|
2008-11-10 08:42:42 +00:00
|
|
|
#if !MONO
|
|
|
|
|
case ".flac":
|
|
|
|
|
return new FLACReader(path, IO);
|
2008-11-10 12:39:07 +00:00
|
|
|
case ".wv":
|
|
|
|
|
return new WavPackReader(path, IO, null);
|
2008-11-10 16:12:16 +00:00
|
|
|
case ".ape":
|
|
|
|
|
return new APEReader(path, IO);
|
2008-11-10 08:42:42 +00:00
|
|
|
#endif
|
|
|
|
|
default:
|
2008-11-10 16:12:16 +00:00
|
|
|
throw new Exception("Unsupported audio type.");
|
2008-11-10 08:42:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-10-13 19:25:11 +00:00
|
|
|
|
|
|
|
|
public static IAudioDest GetAudioDest(string path, int bitsPerSample, int channelCount, int sampleRate, long finalSampleCount) {
|
|
|
|
|
IAudioDest dest;
|
|
|
|
|
switch (Path.GetExtension(path).ToLower()) {
|
|
|
|
|
case ".wav":
|
|
|
|
|
dest = new WAVWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
2008-10-19 17:58:48 +00:00
|
|
|
#if !MONO
|
2008-10-13 19:25:11 +00:00
|
|
|
case ".flac":
|
|
|
|
|
dest = new FLACWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
|
|
|
|
case ".wv":
|
|
|
|
|
dest = new WavPackWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
2008-10-17 18:21:59 +00:00
|
|
|
case ".ape":
|
|
|
|
|
dest = new APEWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
2008-10-13 19:25:11 +00:00
|
|
|
case ".dummy":
|
|
|
|
|
dest = new DummyWriter(path, bitsPerSample, channelCount, sampleRate); break;
|
2008-10-19 17:58:48 +00:00
|
|
|
#endif
|
2008-10-13 19:25:11 +00:00
|
|
|
default:
|
|
|
|
|
throw new Exception("Unsupported audio type.");
|
|
|
|
|
}
|
|
|
|
|
dest.FinalSampleCount = finalSampleCount;
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|