Skip to content

Commit 0efc81c

Browse files
committed
AudioProcessor: Implemented DEcoding of QOA
But not yet ENcoding
1 parent ef3d76f commit 0efc81c

9 files changed

Lines changed: 1258 additions & 4 deletions

File tree

_common/AudioProcessor/audio_file.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ struct MDAudioFileSpec
3232
int64_t m_loop_end = 0;
3333
int64_t m_loop_len = 0;
3434

35+
uint32_t m_multitrack_chans = 0;
36+
uint32_t m_multitrack_tracks = 0;
37+
3538
int m_channels = 0;
3639
int m_sample_format = 0;
3740
int m_sample_rate = 0;
@@ -68,7 +71,10 @@ class MDAudioFile
6871
{
6972
SPEC_READ = 0x01,
7073
SPEC_WRITE = 0x02,
71-
SPEC_FIXED_SAMPLE_RATE = 0x04
74+
SPEC_FIXED_SAMPLE_RATE = 0x04,
75+
SPEC_LOOP_POINTS = 0x08,
76+
SPEC_META_TAGS = 0x10,
77+
SPEC_MULTI_TRACK = 0x20
7278
};
7379

7480
virtual uint32_t getCodecSpec() const = 0;

_common/AudioProcessor/audio_processor.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set(AUDIO_PROCESSOR_SRC
77
${CMAKE_CURRENT_LIST_DIR}/audio_format.h
88
${CMAKE_CURRENT_LIST_DIR}/codec/audio_vorbis.cpp
99
${CMAKE_CURRENT_LIST_DIR}/codec/audio_vorbis.h
10+
${CMAKE_CURRENT_LIST_DIR}/codec/audio_qoa.cpp
11+
${CMAKE_CURRENT_LIST_DIR}/codec/audio_qoa.h
12+
${CMAKE_CURRENT_LIST_DIR}/codec/qoa/qoa.h
1013
)
1114

1215
set(AUDIO_PROCESSOR_LIBS SDL2 SDL2main ogg opus opusfile FLAC vorbis vorbisfile vorbisenc mpg123 mp3lame)

_common/AudioProcessor/audio_processor.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "audio_processor.h"
2121
#include "codec/audio_vorbis.h"
22+
#include "codec/audio_qoa.h"
2223

2324
#include <SDL2/SDL.h>
2425

@@ -71,6 +72,9 @@ const MDAudioFileSpec &MoondustAudioProcessor::getInSpec() const
7172

7273
bool MoondustAudioProcessor::openInFile(const std::string &file, int *detectedFormat)
7374
{
75+
Uint8 magic[100];
76+
Uint8 submagic[4];
77+
7478
if(m_rw_in)
7579
SDL_RWclose(m_rw_in);
7680

@@ -82,16 +86,60 @@ bool MoondustAudioProcessor::openInFile(const std::string &file, int *detectedFo
8286
return false;
8387
}
8488

89+
SDL_memset(magic, 0, 100);
90+
if(SDL_RWread(m_rw_in, magic, 1, 99) < 24)
91+
{
92+
m_lastError = "Couldn't read any first 24 bytes of audio data";
93+
m_in_file.reset();
94+
SDL_RWclose(m_rw_in);
95+
m_rw_in = nullptr;
96+
return false;
97+
}
98+
SDL_RWseek(m_rw_in, 0, RW_SEEK_SET);
99+
85100
m_in_filePath = file;
101+
m_in_file.reset();
102+
103+
if(SDL_memcmp(magic, "OggS", 4) == 0)
104+
{
105+
SDL_RWseek(m_rw_in, 28, RW_SEEK_CUR);
106+
SDL_RWread(m_rw_in, magic, 1, 8);
107+
SDL_RWseek(m_rw_in,-36, RW_SEEK_CUR);
86108

109+
if (SDL_memcmp(magic, "OpusHead", 8) == 0)
110+
{
111+
// m_in_file.reset(new MDAudioOpus);
112+
}
113+
else if (magic[0] == 0x7F && SDL_memcmp(magic + 1, "FLAC", 4) == 0)
114+
{
115+
// m_in_file.reset(new MDAudioFLAC);
116+
}
117+
else
118+
{
119+
m_in_file.reset(new MDAudioVorbis);
120+
}
121+
}
122+
else if (SDL_memcmp(magic, "qoaf", 4) == 0)
123+
m_in_file.reset(new MDAudioQOA);
124+
else if (SDL_memcmp(magic, "XQOA", 4) == 0)
125+
m_in_file.reset(new MDAudioQOA(true));
87126

88-
m_in_file.reset(new MDAudioVorbis);
127+
SDL_RWseek(m_rw_in, 0, RW_SEEK_SET);
89128

129+
if(!m_in_file.get())
130+
{
131+
m_lastError = "Unknown or unsupported file format";
132+
SDL_RWclose(m_rw_in);
133+
m_rw_in = nullptr;
134+
return false;
135+
}
90136

91137
if(!m_in_file->openRead(m_rw_in))
92138
{
93139
m_lastError = m_in_file->getLastError();
94140
m_in_file.reset();
141+
SDL_RWclose(m_rw_in);
142+
m_rw_in = nullptr;
95143
return false;
96144
}
97145

@@ -115,6 +163,12 @@ bool MoondustAudioProcessor::openOutFile(const std::string &file, int dstFormat,
115163
case FORMAT_OGG_VORBIS:
116164
m_out_file.reset(new MDAudioVorbis);
117165
break;
166+
case FORMAT_QOA:
167+
m_out_file.reset(new MDAudioQOA);
168+
break;
169+
case FORMAT_XQOA:
170+
m_out_file.reset(new MDAudioQOA(true));
171+
break;
118172
default:
119173
m_lastError = "Incorrect or unsupported destination format";
120174
return false;

0 commit comments

Comments
 (0)