Skip to content

Commit

Permalink
Implement a high-level emulation of the MP2K audio mixer. (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux authored Aug 1, 2021
1 parent 1bdff3f commit 823cc5a
Show file tree
Hide file tree
Showing 14 changed files with 719 additions and 282 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(SOURCES
emulator/core/hw/apu/channel/noise_channel.cpp
emulator/core/hw/apu/channel/quad_channel.cpp
emulator/core/hw/apu/channel/wave_channel.cpp
emulator/core/hw/apu/hle/mp2k.cpp
emulator/core/hw/apu/apu.cpp
emulator/core/hw/apu/callback.cpp
emulator/core/hw/apu/registers.cpp
Expand Down Expand Up @@ -49,6 +50,7 @@ set(HEADERS
common/dsp/resampler/windowed-sinc.hpp
common/dsp/resampler.hpp
common/compiler.hpp
common/crc32.hpp
common/integer.hpp
common/compiler.hpp
common/log.hpp
Expand Down Expand Up @@ -89,6 +91,7 @@ set(HEADERS
emulator/core/hw/apu/channel/quad_channel.hpp
emulator/core/hw/apu/channel/sweep.hpp
emulator/core/hw/apu/channel/wave_channel.hpp
emulator/core/hw/apu/hle/mp2k.hpp
emulator/core/hw/apu/apu.hpp
emulator/core/hw/apu/registers.hpp
emulator/core/hw/ppu/helper.inl
Expand Down
28 changes: 28 additions & 0 deletions src/common/crc32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2021 fleroviux
*
* Licensed under GPLv3 or any later version.
* Refer to the included LICENSE file.
*/

#include <common/integer.hpp>

inline u32 crc32(u8 const* data, int length) {
u32 crc32 = 0xFFFFFFFF;

while (length-- != 0) {
u8 byte = *data++;

// TODO: speed this up using a lookup table.
for (int i = 0; i < 8; i++) {
if ((crc32 ^ byte) & 1) {
crc32 = (crc32 >> 1) ^ 0xEDB88320;
} else {
crc32 >>= 1;
}
byte >>= 1;
}
}

return ~crc32;
}
2 changes: 1 addition & 1 deletion src/common/dsp/resampler/windowed-sinc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SincResampler : Resampler<T> {
Resampler<T>::SetSampleRates(samplerate_in, samplerate_out);

float kernelSum = 0.0;
float cutoff = 1.0;//0.9;
float cutoff = 0.9;

if (this->resample_phase_shift > 1.0) {
cutoff /= this->resample_phase_shift;
Expand Down
73 changes: 0 additions & 73 deletions src/common/m4a.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion src/emulator/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ struct Config {
Sinc_256
} interpolation = Interpolation::Cosine;
bool interpolate_fifo = true;
bool m4a_xq_enable = false;
bool mp2k_hle_enable = false;
bool mp2k_hle_cubic = false;
} audio;

std::shared_ptr<AudioDevice> audio_dev = std::make_shared<NullAudioDevice>();
Expand Down
6 changes: 4 additions & 2 deletions src/emulator/config/config_toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void config_toml_read(Config& config, std::string const& path) {
}

config.audio.interpolate_fifo = toml::find_or<toml::boolean>(audio, "interpolate_fifo", true);
config.audio.m4a_xq_enable = toml::find_or<toml::boolean>(audio, "m4a_xq_enable", false);
config.audio.mp2k_hle_enable = toml::find_or<toml::boolean>(audio, "mp2k_hle_enable", false);
config.audio.mp2k_hle_cubic = toml::find_or<toml::boolean>(audio, "mp2k_hle_cubic", false);
}
}
}
Expand Down Expand Up @@ -163,7 +164,8 @@ void config_toml_write(Config& config, std::string const& path) {
}
data["audio"]["resampler"] = resampler;
data["audio"]["interpolate_fifo"] = config.audio.interpolate_fifo;
data["audio"]["m4a_xq_enable"] = config.audio.m4a_xq_enable;
data["audio"]["mp2k_hle_enable"] = config.audio.mp2k_hle_enable;
data["audio"]["mp2k_hle_cubic"] = config.audio.mp2k_hle_cubic;

std::ofstream file{ path, std::ios::out };
file << data;
Expand Down
Loading

0 comments on commit 823cc5a

Please sign in to comment.