Skip to content

Commit fe9b09f

Browse files
committed
Started the work on the audio converter library
This library should simplify a lot of stuff regarding the audio conversion, it should replace the SoX use in the Maintainer, and it should allow more various things.
1 parent 67b2d9d commit fe9b09f

12 files changed

Lines changed: 516 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Moondust, a free game engine for platform game making
3+
* Copyright (c) 2014-2025 Vitaly Novichkov <admin@wohlnet.ru>
4+
*
5+
* This software is licensed under a dual license system (MIT or GPL version 3 or later).
6+
* This means you are free to choose with which of both licenses (MIT or GPL version 3 or later)
7+
* you want to use this software.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* You can see text of MIT license in the LICENSE.mit file you can see in Engine folder,
14+
* or see https://mit-license.org/.
15+
*
16+
* You can see text of GPLv3 license in the LICENSE.gpl3 file you can see in Engine folder,
17+
* or see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "audio_file.h"
21+
22+
MDAudioFile::MDAudioFile() {}
23+
24+
MDAudioFile::~MDAudioFile()
25+
{}
26+
27+
std::string MDAudioFile::getLastError()
28+
{
29+
return m_lastError;
30+
}
31+
32+
const MDAudioFileSpec &MDAudioFile::getSpec() const
33+
{
34+
return m_spec;
35+
}
36+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Moondust, a free game engine for platform game making
3+
* Copyright (c) 2014-2025 Vitaly Novichkov <admin@wohlnet.ru>
4+
*
5+
* This software is licensed under a dual license system (MIT or GPL version 3 or later).
6+
* This means you are free to choose with which of both licenses (MIT or GPL version 3 or later)
7+
* you want to use this software.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* You can see text of MIT license in the LICENSE.mit file you can see in Engine folder,
14+
* or see https://mit-license.org/.
15+
*
16+
* You can see text of GPLv3 license in the LICENSE.gpl3 file you can see in Engine folder,
17+
* or see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef AUDIO_FILE_H
21+
#define AUDIO_FILE_H
22+
23+
#include <stdint.h>
24+
#include <string>
25+
26+
struct SDL_RWops;
27+
28+
struct MDAudioFileSpec
29+
{
30+
uint64_t m_total_length = 0;
31+
uint64_t m_loop_start = 0;
32+
uint64_t m_loop_end = 0;
33+
34+
int m_sample_format = 0;
35+
int m_sample_rate = 0;
36+
37+
std::string m_meta_title;
38+
std::string m_meta_artist;
39+
std::string m_meta_album;
40+
std::string m_meta_copyright;
41+
};
42+
43+
class MDAudioFile
44+
{
45+
protected:
46+
SDL_RWops *m_file = nullptr;
47+
uint64_t m_position = 0;
48+
MDAudioFileSpec m_spec;
49+
std::string m_lastError;
50+
51+
public:
52+
MDAudioFile();
53+
virtual ~MDAudioFile();
54+
55+
virtual std::string getLastError();
56+
57+
virtual bool openRead(SDL_RWops *file) = 0;
58+
virtual bool openWrite(SDL_RWops *file, const MDAudioFileSpec &dstSpec) = 0;
59+
60+
virtual bool close() = 0;
61+
62+
virtual size_t readChunk(uint8_t *out, size_t outSize) = 0;
63+
virtual size_t writeChunk(uint8_t *in, size_t inSize) = 0;
64+
65+
const MDAudioFileSpec &getSpec() const;
66+
};
67+
68+
#endif // AUDIO_FILE_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Moondust, a free game engine for platform game making
3+
* Copyright (c) 2014-2025 Vitaly Novichkov <admin@wohlnet.ru>
4+
*
5+
* This software is licensed under a dual license system (MIT or GPL version 3 or later).
6+
* This means you are free to choose with which of both licenses (MIT or GPL version 3 or later)
7+
* you want to use this software.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* You can see text of MIT license in the LICENSE.mit file you can see in Engine folder,
14+
* or see https://mit-license.org/.
15+
*
16+
* You can see text of GPLv3 license in the LICENSE.gpl3 file you can see in Engine folder,
17+
* or see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef AUDIO_FORMAT_H
21+
#define AUDIO_FORMAT_H
22+
23+
enum AudioFormats
24+
{
25+
FORMAT_UNKNOWN = 0,
26+
FORMAT_WAV,
27+
FORMAT_AIFF,
28+
FORMAT_OGG_VORBIS,
29+
FORMAT_OPUS,
30+
FORMAT_FLAC,
31+
FORMAT_MP3,
32+
FORMAT_WAVPACK,
33+
FORMAT_TRACKER,
34+
FORMAT_MIDI,
35+
FORMAT_GME,
36+
FORMAT_QOA,
37+
FORMAT_XQOA,
38+
};
39+
40+
#endif // AUDIO_FORMAT_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
set(AUDIO_PROCESSOR_SRC
3+
${CMAKE_CURRENT_LIST_DIR}/audio_processor.cpp
4+
${CMAKE_CURRENT_LIST_DIR}/audio_processor.h
5+
${CMAKE_CURRENT_LIST_DIR}/audio_file.cpp
6+
${CMAKE_CURRENT_LIST_DIR}/audio_file.h
7+
${CMAKE_CURRENT_LIST_DIR}/audio_format.h
8+
)
9+
10+
set(AUDIO_PROCESSOR_LIBS)
11+
set(AUDIO_PROCESSOR_INCLUDES ${CMAKE_CURRENT_LIST_DIR})
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Moondust, a free game engine for platform game making
3+
* Copyright (c) 2014-2025 Vitaly Novichkov <admin@wohlnet.ru>
4+
*
5+
* This software is licensed under a dual license system (MIT or GPL version 3 or later).
6+
* This means you are free to choose with which of both licenses (MIT or GPL version 3 or later)
7+
* you want to use this software.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* You can see text of MIT license in the LICENSE.mit file you can see in Engine folder,
14+
* or see https://mit-license.org/.
15+
*
16+
* You can see text of GPLv3 license in the LICENSE.gpl3 file you can see in Engine folder,
17+
* or see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "audio_processor.h"
21+
#include <SDL2/SDL.h>
22+
23+
24+
MoondustAudioProcessor::MoondustAudioProcessor()
25+
{}
26+
27+
MoondustAudioProcessor::~MoondustAudioProcessor()
28+
{}
29+
30+
std::string MoondustAudioProcessor::getLastError() const
31+
{
32+
return m_lastError;
33+
}
34+
35+
const MDAudioFileSpec &MoondustAudioProcessor::getInSpec() const
36+
{
37+
return m_in_file->getSpec();
38+
}
39+
40+
bool MoondustAudioProcessor::openInFile(const std::string &file)
41+
{
42+
return false;
43+
}
44+
45+
bool MoondustAudioProcessor::openOutFile(const std::string &file, const MDAudioFileSpec &dstSpec)
46+
{
47+
return false;
48+
}
49+
50+
uint32_t MoondustAudioProcessor::numChunks() const
51+
{
52+
return m_numChunks;
53+
}
54+
55+
uint32_t MoondustAudioProcessor::curChunk() const
56+
{
57+
return m_curChunk;
58+
}
59+
60+
bool MoondustAudioProcessor::runChunk()
61+
{
62+
return false;
63+
}
64+
65+
bool MoondustAudioProcessor::done() const
66+
{
67+
return m_done;
68+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Moondust, a free game engine for platform game making
3+
* Copyright (c) 2014-2025 Vitaly Novichkov <admin@wohlnet.ru>
4+
*
5+
* This software is licensed under a dual license system (MIT or GPL version 3 or later).
6+
* This means you are free to choose with which of both licenses (MIT or GPL version 3 or later)
7+
* you want to use this software.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
*
13+
* You can see text of MIT license in the LICENSE.mit file you can see in Engine folder,
14+
* or see https://mit-license.org/.
15+
*
16+
* You can see text of GPLv3 license in the LICENSE.gpl3 file you can see in Engine folder,
17+
* or see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
#ifndef AUDIO_PROCESSOR_H
22+
#define AUDIO_PROCESSOR_H
23+
24+
#include <string>
25+
#include <vector>
26+
#include <memory>
27+
#include "audio_format.h"
28+
#include "audio_file.h"
29+
30+
struct SDL_RWops;
31+
struct _SDL_AudioStream;
32+
typedef struct _SDL_AudioStream SDL_AudioStream;
33+
34+
#define MD_AUDIO_CHUNK_SIZE 4096
35+
36+
class MoondustAudioProcessor
37+
{
38+
std::string m_lastError;
39+
std::vector<uint8_t> m_in_buffer;
40+
std::vector<uint8_t> m_out_buffer;
41+
42+
std::unique_ptr<MDAudioFile> m_in_file;
43+
std::unique_ptr<MDAudioFile> m_out_file;
44+
45+
SDL_AudioStream *m_cvt_stream;
46+
47+
uint32_t m_curChunk = 0;
48+
uint32_t m_numChunks = 0;
49+
50+
bool m_done = false;
51+
52+
std::string m_in_filePath;
53+
std::string m_out_filePath;
54+
55+
public:
56+
MoondustAudioProcessor();
57+
~MoondustAudioProcessor();
58+
59+
std::string getLastError() const;
60+
61+
const MDAudioFileSpec &getInSpec() const;
62+
63+
bool openInFile(const std::string &file);
64+
bool openOutFile(const std::string &file, const MDAudioFileSpec &dstSpec);
65+
66+
uint32_t numChunks() const;
67+
uint32_t curChunk() const;
68+
69+
bool runChunk();
70+
71+
bool done() const;
72+
73+
};
74+
75+
#endif // AUDIO_PROCESSOR_H
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This file is used to ignore files which are generated
2+
# ----------------------------------------------------------------------------
3+
4+
*~
5+
*.autosave
6+
*.a
7+
*.core
8+
*.moc
9+
*.o
10+
*.obj
11+
*.orig
12+
*.rej
13+
*.so
14+
*.so.*
15+
*_pch.h.cpp
16+
*_resource.rc
17+
*.qm
18+
.#*
19+
*.*#
20+
core
21+
!core/
22+
tags
23+
.DS_Store
24+
.directory
25+
*.debug
26+
Makefile*
27+
*.prl
28+
*.app
29+
moc_*.cpp
30+
ui_*.h
31+
qrc_*.cpp
32+
Thumbs.db
33+
*.res
34+
*.rc
35+
/.qmake.cache
36+
/.qmake.stash
37+
38+
# qtcreator generated files
39+
*.pro.user*
40+
41+
# xemacs temporary files
42+
*.flc
43+
44+
# Vim temporary files
45+
.*.swp
46+
47+
# Visual Studio generated files
48+
*.ib_pdb_index
49+
*.idb
50+
*.ilk
51+
*.pdb
52+
*.sln
53+
*.suo
54+
*.vcproj
55+
*vcproj.*.*.user
56+
*.ncb
57+
*.sdf
58+
*.opensdf
59+
*.vcxproj
60+
*vcxproj.*
61+
62+
# MinGW generated files
63+
*.Debug
64+
*.Release
65+
66+
# Python byte code
67+
*.pyc
68+
69+
# Binaries
70+
# --------
71+
*.dll
72+
*.exe
73+
74+
/build/*
75+
/build-*/

0 commit comments

Comments
 (0)