PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/decoders/audio/all.d

http://github.com/wilkie/djehuty
D | 134 lines | 98 code | 24 blank | 12 comment | 16 complexity | 6931726ea5165e5469ad07b3153ea5cf MD5 | raw file
  1module decoders.audio.all;
  2
  3import io.audio;
  4import io.wavelet;
  5
  6import core.time;
  7import core.string;
  8import core.stream;
  9import core.definitions;
 10
 11import decoders.decoder;
 12import decoders.audio.decoder;
 13
 14version(NoWaveAudio) {
 15}
 16else {
 17	public import decoders.audio.wav : WAVDecoder;
 18}
 19
 20version(NoMp2Audio) {
 21}
 22else {
 23	public import decoders.audio.mp2 : MP2Decoder;
 24}
 25
 26version(NoMp3Audio) {
 27}
 28else {
 29	public import decoders.audio.mp3 : MP3Decoder;
 30}
 31
 32// MP1
 33// MP3
 34// MP4
 35// AUD
 36// SND
 37// XM
 38// IT
 39// RA
 40// WMA
 41// OGG
 42
 43template RunCodec(string codec) {
 44	const char[] RunCodec = `
 45		audioCodec = new ` ~ codec ~ `Decoder();
 46
 47		pos = stream.position;
 48
 49		if ((ret = audioCodec.decode(stream, buffer, wf)) != StreamData.Invalid) {
 50			return ret;
 51		}
 52
 53		stream.position = pos;
 54	`;
 55}
 56
 57template MixinType(string typename) {
 58	const char[] MixinType = "alias " ~ typename ~ " ToType;";
 59}
 60
 61template ToType(string typename) {
 62	mixin(MixinType!(typename));
 63}
 64
 65template TestCodec(string codec) {
 66	AudioDecoder TestCodec(string extension) {
 67		AudioDecoder ret = new ToType!(codec ~ "Decoder");
 68		if (ret.extension == extension) {
 69			return ret;
 70		}
 71		return null;
 72	}
 73}
 74
 75AudioDecoder findBestCodec(string extension) {
 76	AudioDecoder ret;
 77	version(NoWaveAudio) {
 78	}
 79	else {
 80		ret = TestCodec!("WAV")(extension);
 81		if (ret !is null) {
 82			return ret;
 83		}
 84	}
 85
 86	version(NoMp2Audio) {
 87	}
 88	else {
 89		ret = TestCodec!("MP2")(extension);
 90		if (ret !is null) {
 91			return ret;
 92		}
 93	}
 94
 95	version(NoMp3Audio) {
 96	}
 97	else {
 98		ret = TestCodec!("MP3")(extension);
 99		if (ret !is null) {
100			return ret;
101		}
102	}
103	return null;
104}
105
106StreamData runAllCodecs(ref AudioDecoder audioCodec, Stream stream, Wavelet buffer, ref AudioInfo wf) {
107	StreamData ret;
108	ulong pos;
109
110	version(NoWaveAudio) {
111	}
112	else {
113		mixin(RunCodec!("WAV"));
114	}
115
116	version(NoMp2Audio) {
117	}
118	else {
119		mixin(RunCodec!("MP2"));
120	}
121
122	version(NoMp3Audio) {
123	}
124	else {
125		mixin(RunCodec!("MP3"));
126	}
127
128	audioCodec = null;
129	return StreamData.Invalid;
130}
131
132// Codecs:
133//mixin(CreateCodecArray!());
134