|
| 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 |
0 commit comments