Skip to content

Commit

Permalink
Merge pull request #2913 from Ghabry/fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
fdelapena authored Mar 15, 2023
2 parents dbcd100 + 6356529 commit 5d153f7
Show file tree
Hide file tree
Showing 55 changed files with 265 additions and 211 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.15.0")
endif()

# Source Files
add_library(${PROJECT_NAME} STATIC
add_library(${PROJECT_NAME} OBJECT
src/lcf_data.cpp
src/lcf/data.h
src/async_handler.cpp
Expand Down
2 changes: 2 additions & 0 deletions builds/flatpak/org.easyrpg.player.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ modules:
- name: player
buildsystem: cmake-ninja
config-opts:
# remove this line after switching to 22.08 or newer
- -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=OFF
- -DCMAKE_BUILD_TYPE=RelWithDebInfo
sources:
- type: git
Expand Down
2 changes: 1 addition & 1 deletion builds/libretro/libretro-common
Submodule libretro-common updated 131 files
4 changes: 2 additions & 2 deletions src/audio_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::unique_ptr<AudioDecoderBase> AudioDecoder::Create(Filesystem_Stream::InputS

// Try to use MIDI decoder, use fallback(s) if available
if (!strncmp(magic, "MThd", 4)) {
auto midi = MidiDecoder::Create(stream, resample);
auto midi = MidiDecoder::Create(resample);
if (midi) {
return midi;
}
Expand All @@ -84,7 +84,7 @@ std::unique_ptr<AudioDecoderBase> AudioDecoder::Create(Filesystem_Stream::InputS
stream.seekg(0, std::ios::ios_base::beg);

if (!strncmp(magic, "Opus", 4)) {
return add_resampler(std::make_unique<OpusDecoder>());
return add_resampler(std::make_unique<OpusAudioDecoder>());
}
#endif

Expand Down
8 changes: 5 additions & 3 deletions src/audio_decoder_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr int samples_per_play = 64 / sample_divider;
static const uint8_t midi_event_control_change = 0b1011;
static const uint8_t midi_control_volume = 7;
static const uint8_t midi_control_all_sound_off = 120;
static const uint8_t midi_control_all_note_off = 123;
//static const uint8_t midi_control_all_note_off = 123;
static const uint8_t midi_control_reset_all_controller = 121;

static uint32_t midimsg_make(uint8_t event_type, uint8_t channel, uint8_t value1, uint8_t value2) {
Expand All @@ -51,9 +51,9 @@ static uint32_t midimsg_make(uint8_t event_type, uint8_t channel, uint8_t value1
return msg;
}

static uint32_t midimsg_all_note_off(uint8_t channel) {
/*static uint32_t midimsg_all_note_off(uint8_t channel) {
return midimsg_make(midi_event_control_change, channel, midi_control_all_note_off, 0);
}
}*/

static uint32_t midimsg_all_sound_off(uint8_t channel) {
return midimsg_make(midi_event_control_change, channel, midi_control_all_sound_off, 0);
Expand Down Expand Up @@ -217,6 +217,8 @@ bool AudioDecoderMidi::IsFinished() const {
}

void AudioDecoderMidi::Update(std::chrono::microseconds delta) {
(void)delta; // FIXME: Why is delta unused?

if (paused) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions src/audio_decoder_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ class AudioDecoderMidi final : public AudioDecoderBase, public midisequencer::ou

int frequency = EP_MIDI_FREQ;

// What was the mtime when the last set of volume MIDI messages were sent out
std::chrono::microseconds last_fade_msg_sent;
std::array<uint8_t, 16> channel_volumes;

struct MidiTempoData {
Expand Down
2 changes: 1 addition & 1 deletion src/audio_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool GenericAudio::PlayOnChannel(BgmChannel& chan, Filesystem_Stream::InputStrea
// FIXME: Try Fluidsynth and WildMidi first
// If they work fallback to the normal AudioDecoder handler below
// There should be a way to configure the order
if (!MidiDecoder::CreateFluidsynth(filestream, true) && !MidiDecoder::CreateWildMidi(filestream, true)) {
if (!MidiDecoder::CreateFluidsynth(true) && !MidiDecoder::CreateWildMidi(true)) {
if (!midi_thread) {
midi_thread = std::make_unique<GenericAudioMidiOut>();
if (midi_thread->IsInitialized()) {
Expand Down
14 changes: 7 additions & 7 deletions src/audio_midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ static struct {
bool wildmidi = true;
} works;

std::unique_ptr<AudioDecoderBase> MidiDecoder::Create(Filesystem_Stream::InputStream& stream, bool resample) {
std::unique_ptr<AudioDecoderBase> MidiDecoder::Create(bool resample) {
std::unique_ptr<AudioDecoderBase> mididec;

mididec = CreateFluidsynth(stream, resample);
mididec = CreateFluidsynth(resample);
if (!mididec) {
mididec = CreateWildMidi(stream, resample);
mididec = CreateWildMidi(resample);
if (!mididec) {
mididec = CreateFmMidi(stream, resample);
mididec = CreateFmMidi(resample);
}
}

return mididec;
}

std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateFluidsynth(Filesystem_Stream::InputStream& stream, bool resample) {
std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateFluidsynth(bool resample) {
std::unique_ptr<AudioDecoderBase> mididec;

#if defined(HAVE_FLUIDSYNTH) || defined(HAVE_FLUIDLITE)
Expand All @@ -83,7 +83,7 @@ std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateFluidsynth(Filesystem_Strea
return mididec;
}

std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateWildMidi(Filesystem_Stream::InputStream& stream, bool resample) {
std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateWildMidi(bool resample) {
std::unique_ptr<AudioDecoderBase> mididec;

#ifdef HAVE_LIBWILDMIDI
Expand All @@ -107,7 +107,7 @@ std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateWildMidi(Filesystem_Stream:
return mididec;
}

std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateFmMidi(Filesystem_Stream::InputStream& stream, bool resample) {
std::unique_ptr<AudioDecoderBase> MidiDecoder::CreateFmMidi(bool resample) {
std::unique_ptr<AudioDecoderBase> mididec;

#if WANT_FMMIDI
Expand Down
9 changes: 4 additions & 5 deletions src/audio_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,16 @@ class MidiDecoder {
/**
* Attempts to initialize a Midi library for processing the Midi data.
*
* @param stream handle to parse
* @param resample Whether the decoder shall be wrapped into a resampler (if supported)
* @return A Midi decoder instance when the Midi data is supported, otherwise null
*/
static std::unique_ptr<AudioDecoderBase> Create(Filesystem_Stream::InputStream& stream, bool resample);
static std::unique_ptr<AudioDecoderBase> Create(bool resample);

static std::unique_ptr<AudioDecoderBase> CreateFluidsynth(Filesystem_Stream::InputStream& stream, bool resample);
static std::unique_ptr<AudioDecoderBase> CreateFluidsynth(bool resample);

static std::unique_ptr<AudioDecoderBase> CreateWildMidi(Filesystem_Stream::InputStream& stream, bool resample);
static std::unique_ptr<AudioDecoderBase> CreateWildMidi(bool resample);

static std::unique_ptr<AudioDecoderBase> CreateFmMidi(Filesystem_Stream::InputStream& stream, bool resample);
static std::unique_ptr<AudioDecoderBase> CreateFmMidi(bool resample);

protected:
int frequency = EP_MIDI_FREQ;
Expand Down
8 changes: 4 additions & 4 deletions src/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Background::Background(const std::string& name) : Drawable(Priority_Background)
if (!name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Backdrop", name);
request->SetGraphicFile(true);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
bg_request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();
}
}
Expand All @@ -56,7 +56,7 @@ Background::Background(int terrain_id) : Drawable(Priority_Background)
if (terrain->background_type == lcf::rpg::Terrain::BGAssociation_background && !terrain->background_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Backdrop", terrain->background_name);
request->SetGraphicFile(true);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
bg_request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();
return;
}
Expand All @@ -65,7 +65,7 @@ Background::Background(int terrain_id) : Drawable(Priority_Background)
if (!terrain->background_a_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain->background_a_name);
request->SetGraphicFile(true);
request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
bg_request_id = request->Bind(&Background::OnBackgroundGraphicReady, this);
request->Start();

bg_hscroll = terrain->background_a_scrollh ? terrain->background_a_scrollh_speed : 0;
Expand All @@ -75,7 +75,7 @@ Background::Background(int terrain_id) : Drawable(Priority_Background)
if (terrain->background_b && !terrain->background_b_name.empty()) {
FileRequestAsync* request = AsyncHandler::RequestFile("Frame", terrain->background_b_name);
request->SetGraphicFile(true);
request_id = request->Bind(&Background::OnForegroundFrameGraphicReady, this);
fg_request_id = request->Bind(&Background::OnForegroundFrameGraphicReady, this);
request->Start();

fg_hscroll = terrain->background_b_scrollh ? terrain->background_b_scrollh_speed : 0;
Expand Down
3 changes: 2 additions & 1 deletion src/background.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Background : public Drawable {
int fg_x = 0;
int fg_y = 0;

FileRequestBinding request_id;
FileRequestBinding fg_request_id;
FileRequestBinding bg_request_id;
};

inline Tone Background::GetTone() const {
Expand Down
4 changes: 3 additions & 1 deletion src/baseui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ BaseUi::BaseUi(const Game_Config& cfg)
}

BitmapRef BaseUi::CaptureScreen() {
return Bitmap::Create(*main_surface, main_surface->GetRect());
BitmapRef capture = Bitmap::Create(main_surface->width(), main_surface->height(), false);
capture->BlitFast(0, 0, *main_surface, main_surface->GetRect(), Opacity::Opaque());
return capture;
}

void BaseUi::CleanDisplay() {
Expand Down
1 change: 0 additions & 1 deletion src/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ Color Bitmap::GetColorAt(int x, int y) const {
}

Color color;
int pix = y * width();

const uint8_t* pos = &reinterpret_cast<const uint8_t*>(pixels())[y * pitch() + x * bpp()];
uint32_t pixel = *reinterpret_cast<const uint32_t*>(pos);
Expand Down
2 changes: 1 addition & 1 deletion src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace {
}

template<Material::Type T>
BitmapRef LoadDummyBitmap(StringView folder_name, StringView filename, bool transparent) {
BitmapRef LoadDummyBitmap(StringView, StringView, bool) {
static_assert(Material::REND < T && T < Material::END, "Invalid material.");
const Spec& s = spec[T];
return s.dummy_renderer();
Expand Down
2 changes: 1 addition & 1 deletion src/config_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class ConfigParamBase {
protected:
virtual bool vIsValid(const T& value) const = 0;

T _value = {};
StringView _name;
StringView _description;
T _value = {};

private:
bool _visible = true;
Expand Down
2 changes: 1 addition & 1 deletion src/decoder_drwav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int DrWavDecoder::FillBuffer(uint8_t* buffer, int length) {
return 0;
}

drwav_uint64 decoded = drwav_read_pcm_frames_s16(&handle, length / (handle.channels * 2), reinterpret_cast<drwav_int16*>(buffer));
int decoded = static_cast<int>(drwav_read_pcm_frames_s16(&handle, length / (handle.channels * 2), reinterpret_cast<drwav_int16*>(buffer)));
decoded_samples += decoded;
decoded *= handle.channels * 2;

Expand Down
1 change: 0 additions & 1 deletion src/decoder_drwav.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class DrWavDecoder : public AudioDecoder {
int decoded_samples = 0;
bool init = false;
drwav handle = {};
uint32_t bytes_per_frame = 0;
};

#endif
Expand Down
32 changes: 21 additions & 11 deletions src/decoder_fluidsynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,21 @@ static fluid_fileapi_t fluidlite_vio = {
#endif

namespace {
bool shutdown = false;
std::string preferred_soundfont;
}

struct FluidSettingsDeleter {
struct FluidSynthDeleter {
void operator()(fluid_settings_t* s) const {
delete_fluid_settings(s);
}
};

struct FluidSynthDeleter {
void operator()(fluid_synth_t* s) const {
delete_fluid_synth(s);
shutdown = true;
}
};

namespace {
std::unique_ptr<fluid_settings_t, FluidSettingsDeleter> global_settings;
std::unique_ptr<fluid_settings_t, FluidSynthDeleter> global_settings;
std::unique_ptr<fluid_synth_t, FluidSynthDeleter> global_synth;
#if defined(HAVE_FLUIDSYNTH) && FLUIDSYNTH_VERSION_MAJOR > 1
fluid_sfloader_t* global_loader; // owned by global_settings
Expand Down Expand Up @@ -191,13 +187,13 @@ FluidSynthDecoder::FluidSynthDecoder() {
// Sharing is only not possible when a Midi is played as a SE (unlikely)
if (instances > 1) {
std::string error_message;
instance_synth = create_synth(error_message);
if (!instance_synth) {
local_synth = create_synth(error_message);
if (!local_synth) {
// unlikely, the SF was already allocated once
Output::Debug("FluidSynth failed: {}", error_message);
}
} else {
instance_synth = global_synth.get();
use_global_synth = true;
fluid_synth_program_reset(global_synth.get());
}
}
Expand All @@ -206,8 +202,8 @@ FluidSynthDecoder::~FluidSynthDecoder() {
--instances;
assert(instances >= 0);

if (instance_synth != global_synth.get()) {
delete_fluid_synth(instance_synth);
if (!use_global_synth) {
delete_fluid_synth(local_synth);
}
}

Expand Down Expand Up @@ -270,6 +266,8 @@ void FluidSynthDecoder::SetSoundfont(StringView sf) {
}

int FluidSynthDecoder::FillBuffer(uint8_t* buffer, int length) {
auto* instance_synth = GetSynthInstance();

if (!instance_synth) {
return -1;
}
Expand All @@ -282,6 +280,8 @@ int FluidSynthDecoder::FillBuffer(uint8_t* buffer, int length) {
}

void FluidSynthDecoder::SendMidiMessage(uint32_t message) {
auto* instance_synth = GetSynthInstance();

if (!instance_synth) {
return;
}
Expand Down Expand Up @@ -329,8 +329,18 @@ void FluidSynthDecoder::SendSysExMessage(const uint8_t* data, std::size_t size)
return;
}

auto* instance_synth = GetSynthInstance();

fluid_synth_sysex(instance_synth, reinterpret_cast<const char*>(data + 1), static_cast<int>(size - 2),
nullptr, nullptr, nullptr, 0);
}

fluid_synth_t *FluidSynthDecoder::GetSynthInstance() {
if (use_global_synth) {
return global_synth.get();
} else {
return local_synth;
}
}

#endif
5 changes: 4 additions & 1 deletion src/decoder_fluidsynth.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class FluidSynthDecoder : public MidiDecoder {

private:
#if defined(HAVE_FLUIDSYNTH) || defined(HAVE_FLUIDLITE)
fluid_synth_t* instance_synth;
fluid_synth_t* GetSynthInstance();

fluid_synth_t* local_synth = nullptr;
bool use_global_synth = false;
#endif
};

Expand Down
Loading

0 comments on commit 5d153f7

Please sign in to comment.