Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace minimp3 with dr_mp3 #96547

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ doc_classes/* @godotengine/documentation
# Modules

## Audio (+ video)
/modules/minimp3/ @godotengine/audio
/modules/mp3/ @godotengine/audio
/modules/ogg/ @godotengine/audio
/modules/opus/ @godotengine/audio
/modules/theora/ @godotengine/audio
Expand Down
10 changes: 5 additions & 5 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ Comment: doctest
Copyright: 2016-2023, Viktor Kirilov
License: Expat

Files: ./thirdparty/dr_libs/
Comment: dr_libs
Copyright: 2024 David Reid
License: public-domain or Unlicense or Expat

Files: ./thirdparty/embree/
Comment: Embree
Copyright: 2009-2021 Intel Corporation
Expand Down Expand Up @@ -349,11 +354,6 @@ Comment: mingw-std-threads
Copyright: 2016, Mega Limited
License: BSD-2-clause

Files: ./thirdparty/minimp3/
Comment: MiniMP3
Copyright: lieff
License: CC0-1.0

Files: ./thirdparty/miniupnpc/
Comment: MiniUPnP Project
Copyright: 2005-2024, Thomas Bernard
Expand Down
20 changes: 0 additions & 20 deletions modules/minimp3/SCsub

This file was deleted.

12 changes: 12 additions & 0 deletions modules/mp3/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python

Import("env")
Import("env_modules")

env_mp3 = env_modules.Clone()

if not env["mp3_extra_formats"]:
env_mp3.Append(CPPDEFINES=["DR_MP3_ONLY_MP3"])

# Godot source files
env_mp3.add_source_files(env.modules_sources, "*.cpp")
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#define MINIMP3_FLOAT_OUTPUT
#define MINIMP3_IMPLEMENTATION
#define MINIMP3_NO_STDIO
#define DR_MP3_FLOAT_OUTPUT
#define DRMP3_IMPLEMENTATION
#define DR_MP3_NO_STDIO
#define DRMP3_MALLOC(sz) memalloc(sz)
#define DRMP3_REALLOC(p, sz) memrealloc(p, sz)
#define DRMP3_FREE(p) memfree(p)

#include "audio_stream_mp3.h"

Expand All @@ -54,13 +57,12 @@ int AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) {
}

while (todo && active) {
mp3dec_frame_info_t frame_info;
mp3d_sample_t *buf_frame = nullptr;
drmp3d_sample_t buf_frame[2];

int samples_mixed = mp3dec_ex_read_frame(&mp3d, &buf_frame, &frame_info, mp3_stream->channels);
int samples_mixed = drmp3_read_pcm_frames_f32(&mp3d, 1, buf_frame);

if (samples_mixed) {
p_buffer[p_frames - todo] = AudioFrame(buf_frame[0], buf_frame[samples_mixed - 1]);
p_buffer[p_frames - todo] = AudioFrame(buf_frame[0], buf_frame[mp3_stream->channels - 1]);
if (loop_fade_remaining < FADE_SIZE) {
p_buffer[p_frames - todo] += loop_fade[loop_fade_remaining] * (float(FADE_SIZE - loop_fade_remaining) / float(FADE_SIZE));
loop_fade_remaining++;
Expand All @@ -70,8 +72,8 @@ int AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) {

if (beat_loop && (int)frames_mixed >= beat_length_frames) {
for (int i = 0; i < FADE_SIZE; i++) {
samples_mixed = mp3dec_ex_read_frame(&mp3d, &buf_frame, &frame_info, mp3_stream->channels);
loop_fade[i] = AudioFrame(buf_frame[0], buf_frame[samples_mixed - 1]);
samples_mixed = drmp3_read_pcm_frames_f32(&mp3d, 1, buf_frame);
loop_fade[i] = AudioFrame(buf_frame[0], buf_frame[mp3_stream->channels - 1]);
if (!samples_mixed) {
break;
}
Expand Down Expand Up @@ -138,7 +140,7 @@ void AudioStreamPlaybackMP3::seek(double p_time) {
}

frames_mixed = uint32_t(mp3_stream->sample_rate * p_time);
mp3dec_ex_seek(&mp3d, (uint64_t)frames_mixed * mp3_stream->channels);
drmp3_seek_to_pcm_frame(&mp3d, frames_mixed);
}

void AudioStreamPlaybackMP3::tag_used_streams() {
Expand Down Expand Up @@ -181,7 +183,7 @@ Variant AudioStreamPlaybackMP3::get_parameter(const StringName &p_name) const {
}

AudioStreamPlaybackMP3::~AudioStreamPlaybackMP3() {
mp3dec_ex_close(&mp3d);
drmp3_uninit(&mp3d);
}

Ref<AudioStreamPlayback> AudioStreamMP3::instantiate_playback() {
Expand All @@ -195,14 +197,14 @@ Ref<AudioStreamPlayback> AudioStreamMP3::instantiate_playback() {
mp3s.instantiate();
mp3s->mp3_stream = Ref<AudioStreamMP3>(this);

int errorcode = mp3dec_ex_open_buf(&mp3s->mp3d, data.ptr(), data_len, MP3D_SEEK_TO_SAMPLE);
int success = drmp3_init_memory(&mp3s->mp3d, data.ptr(), data_len, nullptr);

mp3s->frames_mixed = 0;
mp3s->active = false;
mp3s->loops = 0;

if (errorcode) {
ERR_FAIL_COND_V(errorcode, Ref<AudioStreamPlaybackMP3>());
if (!success) {
ERR_FAIL_COND_V(!success, Ref<AudioStreamPlaybackMP3>());
}

return mp3s;
Expand All @@ -220,18 +222,18 @@ void AudioStreamMP3::set_data(const Vector<uint8_t> &p_data) {
int src_data_len = p_data.size();
const uint8_t *src_datar = p_data.ptr();

mp3dec_ex_t *mp3d = memnew(mp3dec_ex_t);
int err = mp3dec_ex_open_buf(mp3d, src_datar, src_data_len, MP3D_SEEK_TO_SAMPLE);
if (err || mp3d->info.hz == 0) {
drmp3 *mp3d = memnew(drmp3);
int success = drmp3_init_memory(mp3d, src_datar, src_data_len, nullptr);
if (!success || mp3d->sampleRate == 0) {
memdelete(mp3d);
ERR_FAIL_MSG("Failed to decode mp3 file. Make sure it is a valid mp3 audio file.");
}

channels = mp3d->info.channels;
sample_rate = mp3d->info.hz;
length = float(mp3d->samples) / (sample_rate * float(channels));
channels = mp3d->channels;
sample_rate = mp3d->sampleRate;
length = drmp3_get_pcm_frame_count(mp3d) / sample_rate;

mp3dec_ex_close(mp3d);
drmp3_uninit(mp3d);
memdelete(mp3d);

clear_data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "core/io/resource_loader.h"
#include "servers/audio/audio_stream.h"

#include <minimp3_ex.h>
#include "thirdparty/dr_libs/dr_mp3.h"

class AudioStreamMP3;

Expand All @@ -49,7 +49,7 @@ class AudioStreamPlaybackMP3 : public AudioStreamPlaybackResampled {

bool looping_override = false;
bool looping = false;
mp3dec_ex_t mp3d = {};
drmp3 mp3d = {};
uint32_t frames_mixed = 0;
bool active = false;
int loops = 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/minimp3/config.py → modules/mp3/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def get_opts(platform):
from SCons.Variables import BoolVariable

return [
BoolVariable("minimp3_extra_formats", "Build minimp3 with MP1/MP2 decoding support", False),
BoolVariable("mp3_extra_formats", "Build mp3 module with MP1/MP2 decoding support", False),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "core/config/engine.h"
#endif

void initialize_minimp3_module(ModuleInitializationLevel p_level) {
void initialize_mp3_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
Expand All @@ -64,7 +64,7 @@ void initialize_minimp3_module(ModuleInitializationLevel p_level) {
GDREGISTER_CLASS(AudioStreamMP3);
}

void uninitialize_minimp3_module(ModuleInitializationLevel p_level) {
void uninitialize_mp3_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef MINIMP3_REGISTER_TYPES_H
#define MINIMP3_REGISTER_TYPES_H
#ifndef MP3_REGISTER_TYPES_H
#define MP3_REGISTER_TYPES_H

#include "modules/register_module_types.h"

void initialize_minimp3_module(ModuleInitializationLevel p_level);
void uninitialize_minimp3_module(ModuleInitializationLevel p_level);
void initialize_mp3_module(ModuleInitializationLevel p_level);
void uninitialize_mp3_module(ModuleInitializationLevel p_level);

#endif // MINIMP3_REGISTER_TYPES_H
#endif // MP3_REGISTER_TYPES_H
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ String ResourceImporterMP3::get_visible_name() const {
}

void ResourceImporterMP3::get_recognized_extensions(List<String> *p_extensions) const {
#ifndef MINIMP3_ONLY_MP3
#ifndef DR_MP3_ONLY_MP3
p_extensions->push_back("mp1");
p_extensions->push_back("mp2");
#endif
Expand Down
27 changes: 11 additions & 16 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ Files extracted from upstream source:
- `doctest/doctest.h` as `doctest.h`
- `LICENSE.txt`

## dr_libs

- Upstream: https://github.com/mackron/dr_libs
- Version: git (da35f9d6c7374a95353fd1df1d394d44ab66cf01, 2024)
- License: Public Domain or Unlicense or MIT

Files extracted from upstream source:

- `dr_mp3.h`
- `LICENSE`


## embree

Expand Down Expand Up @@ -595,22 +606,6 @@ Once copied, apply `godot.patch` (needed because Godot is built without exceptio
and to avoid std:: replacements leak in Clang builds).


## minimp3

- Upstream: https://github.com/lieff/minimp3
- Version: git (afb604c06bc8beb145fecd42c0ceb5bda8795144, 2021)
- License: CC0 1.0

Files extracted from upstream repository:

- `minimp3.h`
- `minimp3_ex.h`
- `LICENSE`

Some changes have been made in order to fix Windows on ARM build errors, and
to solve some MSVC warnings. See the patches in the `patches` directory.


## miniupnpc

- Upstream: https://github.com/miniupnp/miniupnp
Expand Down
47 changes: 47 additions & 0 deletions thirdparty/dr_libs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
This software is available as a choice of the following licenses. Choose
whichever you prefer.

===============================================================================
ALTERNATIVE 1 - Public Domain (www.unlicense.org)
===============================================================================
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>

===============================================================================
ALTERNATIVE 2 - MIT No Attribution
===============================================================================
Copyright 2020 David Reid

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading