Commit db670fdd authored by phcoder's avatar phcoder
Browse files

Fix disabling sounds

parent 57f9f112
......@@ -173,6 +173,7 @@ void Loader::load(const std::vector<std::string>& lines, Machine& m)
++fy;
break;
}
#if SOUND_ENABLED
case State::SFX:
{
assert(line.length() == DIGITS_PER_SOUND);
......@@ -234,6 +235,7 @@ void Loader::load(const std::vector<std::string>& lines, Machine& m)
break;
}
#endif
}
}
......
......@@ -255,6 +255,7 @@ void Stegano::load(const PngData& data, Machine& m)
constexpr size_t SPRITE_SHEET_SIZE = gfx::SPRITE_SHEET_HEIGHT * gfx::SPRITE_SHEET_WIDTH / gfx::PIXEL_TO_BYTE_RATIO;
constexpr size_t TILE_MAP_SIZE = gfx::TILE_MAP_WIDTH * gfx::TILE_MAP_HEIGHT * sizeof(sprite_index_t) / 2;
constexpr size_t SPRITE_FLAGS_SIZE = gfx::SPRITE_COUNT * sizeof(sprite_flags_t);
#if SOUND_ENABLED
constexpr size_t MUSIC_SIZE = sfx::MUSIC_COUNT * sizeof(sfx::music_t);
constexpr size_t SOUND_SIZE = sfx::SOUND_COUNT * sizeof(sfx::sound_t);
......@@ -262,6 +263,7 @@ void Stegano::load(const PngData& data, Machine& m)
static_assert(sizeof(sfx::sound_t) == 68, "Must be 68 bytes");
static_assert(RAW_DATA_LENGTH == SPRITE_SHEET_SIZE + TILE_MAP_SIZE + SPRITE_FLAGS_SIZE + MUSIC_SIZE + SOUND_SIZE, "Must be equal");
#endif
assert(data.length == IMAGE_WIDTH * IMAGE_HEIGHT);
auto* d = data.data;
......
......@@ -249,7 +249,9 @@ extern "C"
//});
}
machine.sound().init();
#if SOUND_ENABLED
machine->sound().init();
#endif
env.frameCounter = 0;
......@@ -309,6 +311,7 @@ extern "C"
env.video(screen16->getBuffer(), r8::gfx::SCREEN_WIDTH, r8::gfx::SCREEN_HEIGHT, r8::gfx::SCREEN_WIDTH * sizeof(uint16_t));
++env.frameCounter;
#if SOUND_ENABLED
machine.sound().renderSounds(audioBuffer, SAMPLES_PER_FRAME);
/* duplicate channels */
......@@ -320,6 +323,10 @@ extern "C"
}
env.audioBatch(audioBuffer2, SAMPLES_PER_FRAME);
#else
memset(audioBuffer, 0, sizeof(audioBuffer[0]) * 2 * SAMPLES_PER_FRAME);
env.audioBatch(audioBuffer, SAMPLES_PER_FRAME);
#endif
/* manage input */
{
......
......@@ -682,23 +682,27 @@ namespace sound
{
int music(lua_State* L)
{
#if SOUND_ENABLED
sfx::music_index_t index = lua_tonumber(L, 1);
int32_t fadeMs = lua_to_or_default(L, number, 2, 1);
int32_t mask = lua_to_or_default(L, number, 3, 0);
machine.sound().music(index, fadeMs, mask);
#endif
return 0;
}
int sfx(lua_State* L)
{
#if SOUND_ENABLED
sfx::sound_index_t index = lua_tonumber(L, 1);
sfx::channel_index_t channel = lua_to_or_default(L, number, 2, -1);
int32_t start = lua_to_or_default(L, number, 3, 0);
int32_t end = lua_to_or_default(L, number, 3, machine.memory().sound(index)->length());
machine.sound().play(index, channel, start, end);
#endif
return 0;
}
......
......@@ -26,7 +26,9 @@ namespace retro8
private:
State _state;
Memory _memory;
#if SOUND_ENABLED
sfx::APU _sound;
#endif
gfx::Font _font;
lua::Code _code;
......@@ -36,7 +38,10 @@ namespace retro8
public:
Machine() : _sound(_memory)
Machine()
#if SOUND_ENABLED
: _sound(_memory)
#endif
{
}
......@@ -69,6 +74,8 @@ namespace retro8
Memory& memory() { return _memory; }
gfx::Font& font() { return _font; }
lua::Code& code() { return _code; }
#if SOUND_ENABLED
sfx::APU& sound() { return _sound; }
#endif
};
}
......@@ -76,8 +76,10 @@ namespace retro8
gfx::color_byte_t* screenData(coord_t x, coord_t y) { return screenData() + y * gfx::SCREEN_PITCH + x / gfx::PIXEL_TO_BYTE_RATIO; }
integral_t* cartData(index_t idx) { return as<integral_t>(address::CART_DATA + idx * sizeof(integral_t)); } //TODO: ENDIANNESS!!
#if SOUND_ENABLED
sfx::Sound* sound(sfx::sound_index_t i) { return as<sfx::Sound>(address::SOUNDS + sizeof(sfx::Sound)*i); }
sfx::Music* music(sfx::music_index_t i) { return as<sfx::Music>(address::MUSIC + sizeof(sfx::Music)*i); }
#endif
sprite_flags_t* spriteFlagsFor(sprite_index_t index)
{
......
......@@ -5,10 +5,11 @@
#include <random>
#include <cassert>
#if SOUND_ENABLED
using namespace retro8;
using namespace retro8::sfx;
inline void DSP::squareWave(uint32_t frequency, int16_t amplitude, int16_t offset, int32_t position, int16_t* dest, size_t samples)
{
const size_t periodLength = float(rate) / frequency;
......@@ -427,3 +428,5 @@ void APU::renderSounds(int16_t* dest, size_t totalSamples)
}
}
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment