Skip to content

Commit

Permalink
Add support for QOA encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Piolat committed Apr 16, 2023
1 parent 19a1c74 commit 5362167
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 130 deletions.
6 changes: 3 additions & 3 deletions dub.json
Expand Up @@ -6,17 +6,17 @@
"configurations": [
{
"name": "boost",
"versions": ["decodeWAV", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeMOD", "decodeXM",
"versions": ["decodeWAV", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeMOD", "decodeXM",
"encodeWAV"]
},
{
"name": "mit",
"versions": ["decodeWAV", "decodeQOA", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeMOD", "decodeXM",
"versions": ["decodeWAV", "decodeQOA", "encodeQOA", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeMOD", "decodeXM",
"encodeWAV" ]
},
{
"name": "lgpl",
"versions": ["decodeWAV", "decodeQOA", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeOPUS", "decodeMOD", "decodeXM",
"versions": ["decodeWAV", "decodeQOA", "encodeQOA", "decodeMP3", "decodeFLAC", "decodeOGG", "decodeOPUS", "decodeMOD", "decodeXM",
"encodeWAV"]
}
]
Expand Down
7 changes: 6 additions & 1 deletion examples/transcode/dub.json
@@ -1,10 +1,15 @@
{
"name": "transcode",
"description": "Decode MP3/WAV input, output a WAV.",
"license": "BSL-1.0",
"license": "LGPL-2.1+BSL-1.0+MIT",

"dependencies":
{
"audio-formats": { "path": "../.." }
},

"subConfigurations":
{
"audio-formats": "lgpl"
}
}
11 changes: 9 additions & 2 deletions examples/transcode/source/main.d
Expand Up @@ -12,7 +12,7 @@ import core.stdc.stdlib;
void main(string[] args)
{
if (args.length != 3)
throw new Exception("usage: transcode input.{mp3|wav|flac|ogg|opus|qoa|mod|xm} output.wav");
throw new Exception("usage: transcode input.{mp3|wav|flac|ogg|opus|qoa|mod|xm} output.{wav|qoa}");

string inputPath = args[1];
string outputPath = args[2];
Expand Down Expand Up @@ -49,7 +49,14 @@ void main(string[] args)
options.sampleFormat = AudioSampleFormat.s24;
options.enableDither = true;

output.openToFile(outputPath, AudioFileFormat.wav, sampleRate, channels, options);
bool isQOA = outputPath.length > 4 && outputPath[$-4..$] == ".qoa";
AudioFileFormat outFormat = AudioFileFormat.wav;
if (isQOA)
{
outFormat = AudioFileFormat.qoa;
}

output.openToFile(outputPath, outFormat, sampleRate, channels, options);

// Chunked encode/decode
int totalFrames = 0;
Expand Down
25 changes: 25 additions & 0 deletions source/audioformats/io.d
Expand Up @@ -370,6 +370,31 @@ nothrow @nogc:
return 8 == write(v.ptr, 8, userData);
}

/// Write a Little Endian 64-bit unsigned integer to stream and advance cursor.
/// Returns: `true` on success, else stream is invalid.
bool write_ulong_BE(void* userData, ulong value)
{
ubyte[8] v;
*cast(ulong*)(v.ptr) = value;
version(LittleEndian)
{
ubyte v0 = v[0];
v[0] = v[7];
v[7] = v0;
ubyte v1 = v[1];
v[1] = v[6];
v[6] = v1;
ubyte v2 = v[2];
v[2] = v[5];
v[5] = v2;
ubyte v3 = v[3];
v[3] = v[4];
v[4] = v3;
}

return 8 == write(v.ptr, 8, userData);
}

/// Write a Little Endian 32-bit unsigned integer to stream and advance cursor.
/// Returns: `true` on success, else stream is invalid.
bool write_uint_LE(void* userData, uint value)
Expand Down

0 comments on commit 5362167

Please sign in to comment.