* mp3支持完成

This commit is contained in:
2025-01-05 00:14:31 +08:00
parent dcdd8ab7aa
commit a0e6b1a7dd
4 changed files with 1412 additions and 20 deletions
+10 -18
View File
@@ -9,7 +9,7 @@
#include <FLAC++/decoder.h>
#define MINIMP3_IMPLEMENTATION
#include <minimp3.h>
#include <minimp3_ex.h>
#include "system/dl_platform.h"
#include "io/dl_file.h"
@@ -183,7 +183,7 @@ bool AudioLoader::ReadOgg(std::string_view path_name, PCM& pcm)
//只需要填充Foramt这一个结构,其他被截断了
pcm._numChannel = vi->channels;
pcm._freq = vi->rate;
pcm._bitPerSample = pcm._numChannel * 8;
pcm._bitPerSample = 16;
}
@@ -316,6 +316,7 @@ bool AudioLoader::ReadFlac(std::string_view path_name, PCM& pcm)
mp3dec_t* g_mp3dec = nullptr;
bool AudioLoader::ReadMp3(std::string_view path_name, PCM& pcm)
{
Buffer buf = File::GetBuffer(path_name);
@@ -327,25 +328,16 @@ bool AudioLoader::ReadMp3(std::string_view path_name, PCM& pcm)
g_mp3dec = new mp3dec_t;
mp3dec_init(g_mp3dec);
}
mp3dec_frame_info_t info;
short buf_out[MINIMP3_MAX_SAMPLES_PER_FRAME];
int mp3len = 0;
//逐帧解码并且播放MP3
int out_size = mp3dec_decode_frame(g_mp3dec, (uint8_t*)buf.data(), buf.size(), buf_out, &info);
mp3dec_file_info_t info;
mp3dec_load_buf(g_mp3dec, (uint8_t*)buf.data(), buf.size(), &info, nullptr, nullptr);
pcm._buf = CreateBuffer(CreateBufferView(
(uint8_t*)info.buffer,
info.samples * sizeof(mp3d_sample_t)));
pcm._bitPerSample = 16;
pcm._freq = info.hz;
pcm._numChannel = info.channels;
pcm._bitPerSample = pcm._numChannel * 8;
while (out_size) {
BufferAppend(pcm._buf, CreateBufferView((unsigned char*)buf_out, (size_t)out_size));
mp3len += info.frame_bytes;
out_size = mp3dec_decode_frame(g_mp3dec, (uint8_t*)buf.data() + mp3len, buf.size() - mp3len, buf_out, &info);
}
}
AudioLoader g_audioLoader;
AudioLoader::~AudioLoader()
{
delete g_mp3dec;
+4 -1
View File
@@ -38,7 +38,9 @@ public:
{
if (g_input->ClickDouble())
{
snd_play(_edt->GetSelectClickDouble().ToString());
if (_snd)
_snd->Stop();
_snd = snd_play(_edt->GetSelectClickDouble().ToString());
}
}
~UIAudio()
@@ -48,4 +50,5 @@ private:
std::vector<std::string> _allSound;
UI::ListBox* _edt;
gcSound _snd;
};
File diff suppressed because it is too large Load Diff