From 48159d2fe5a866552a25215a09be666571ff768a Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 14:28:03 +0000 Subject: [PATCH 01/15] Fix pan and IRateConverters --- sdl2-hyper-sonic-drivers/examples/pcm-example.cpp | 2 +- .../HyperSonicDrivers/audio/converters/CopyRateConverter.hpp | 4 ++-- .../audio/converters/LinearRateConverter.hpp | 4 ++-- .../audio/converters/SimpleRateConverter.hpp | 4 ++-- .../src/HyperSonicDrivers/audio/mixer/Channel.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp index d640781e..4ec2058c 100644 --- a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) for (int i = 0, sig = +1; i < 3; i++, sig *= -1) { cout << i << ". playing same sound again reversed balance" << endl; - delayMillis(200); + delayMillis(500); drv.play(wavSound, 150, 127 * sig); drv.play(vocSound, 255, -127 * sig); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp index 2a87bf3f..8d5af722 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp @@ -47,9 +47,9 @@ namespace HyperSonicDrivers::audio::converters int16_t out1 = (stereo ? *it++ : out0); // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp index 7ea2bac9..52f56d7f 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp @@ -117,9 +117,9 @@ namespace HyperSonicDrivers::audio::converters const int16_t out0 = interpolate(ilast0, icur0, opos); const int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0; // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; // Increment output position diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp index 4530f9a1..6b54fc32 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/SimpleRateConverter.hpp @@ -95,9 +95,9 @@ namespace HyperSonicDrivers::audio::converters opos += opos_inc; // output left channel - output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l); + output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l); // output right channel - output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r); + output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r); obuf += 2; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp index 814a9fb0..f0c87746 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp @@ -118,8 +118,8 @@ namespace HyperSonicDrivers::audio::mixer const float pan = (127.5f + m_pan) / 255.0f; // TODO: create different selectable pan laws // -3dB pan law - m_volL = static_cast(std::round(sqrt(pan) * vol / ch_max_vol)); - m_volR = static_cast(std::round(sqrt(1 - pan) * vol / ch_max_vol)); + m_volL = static_cast(std::round(sqrt(1 - pan) * vol / ch_max_vol)); + m_volR = static_cast(std::round(sqrt(pan) * vol / ch_max_vol)); // adjust for master volume const auto m_vol = m_mixer.getMasterVolume(); From 2f9bb2de8e8f837c75ec51a58834fd3214c84036 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 14:55:27 +0000 Subject: [PATCH 02/15] refactor IMixer --- .../src/HyperSonicDrivers/audio/IMixer.cpp | 14 +++++++++++- .../src/HyperSonicDrivers/audio/IMixer.hpp | 22 ++++++++++--------- .../HyperSonicDrivers/audio/mixer/Channel.cpp | 2 +- .../HyperSonicDrivers/audio/sdl2/Mixer.cpp | 18 +++++++-------- .../HyperSonicDrivers/audio/sdl2/Mixer.hpp | 6 +++-- .../HyperSonicDrivers/audio/sdl2/Renderer.cpp | 2 +- .../src/HyperSonicDrivers/files/IPCMFile.cpp | 6 ++--- .../src/HyperSonicDrivers/files/IPCMFile.hpp | 8 +++---- .../src/HyperSonicDrivers/files/VOCFile.cpp | 12 +++++----- .../src/HyperSonicDrivers/files/WAVFile.cpp | 4 ++-- .../HyperSonicDrivers/hardware/IHardware.cpp | 2 +- .../HyperSonicDrivers/hardware/mt32/MT32.cpp | 2 +- .../HyperSonicDrivers/hardware/opl/OPL.cpp | 2 +- .../hardware/opl/mame/MameOPL3.cpp | 4 ++-- .../hardware/opl/scummvm/dosbox/DosBoxOPL.cpp | 2 +- .../hardware/opl/scummvm/mame/MameOPL2.cpp | 2 +- .../hardware/opl/scummvm/nuked/NukedOPL3.cpp | 2 +- .../hardware/opl/woody/WoodyOPL.cpp | 4 ++-- .../HyperSonicDrivers/audio/IMixerMock.hpp | 4 +++- 19 files changed, 68 insertions(+), 50 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.cpp index b8cb70fe..123043ce 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.cpp @@ -8,7 +8,7 @@ namespace HyperSonicDrivers::audio IMixer::IMixer(const uint8_t max_channels, const uint32_t freq, const uint16_t buffer_size) : max_channels(max_channels), - m_sampleRate(freq), m_samples(buffer_size) + freq(freq), buffer_size(buffer_size) { } @@ -20,5 +20,17 @@ namespace HyperSonicDrivers::audio void IMixer::setChannelGroupVolume(const mixer::eChannelGroup group, const uint8_t volume) noexcept { m_group_settings.at(group2i(group)).volume = volume; + updateChannelsVolumePan_(); + } + + int8_t IMixer::getChannelGroupPan(const mixer::eChannelGroup group) const noexcept + { + return m_group_settings.at(group2i(group)).pan; + } + + void IMixer::setChannelGroupPan(const mixer::eChannelGroup group, const int8_t pan) noexcept + { + m_group_settings[group2i(group)].pan = pan; + updateChannelsVolumePan_(); } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp index 5ce9de82..a4495919 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp @@ -16,6 +16,11 @@ namespace HyperSonicDrivers::audio class IMixer { public: + const uint8_t max_channels; + const uint32_t freq; + const uint16_t buffer_size; + const uint8_t bitsDepth = 16; // forced to be 16-bits for now + IMixer(IMixer&) = delete; IMixer& operator=(IMixer&) = delete; @@ -47,7 +52,7 @@ namespace HyperSonicDrivers::audio virtual void unpause() noexcept = 0; virtual void unpause(const uint8_t id) noexcept = 0; - virtual bool isChannelActive(const uint8_t id) const noexcept = 0; + virtual bool isActive(const uint8_t id) const noexcept = 0; virtual bool isPaused(const uint8_t id) const noexcept = 0; virtual bool isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept = 0; @@ -66,27 +71,24 @@ namespace HyperSonicDrivers::audio uint8_t getChannelGroupVolume(const mixer::eChannelGroup group) const noexcept; void setChannelGroupVolume(const mixer::eChannelGroup group, const uint8_t volume) noexcept; - // TODO: these 3 methods are useless if those 3 vars are consts... - inline uint32_t getOutputRate() const noexcept { return m_sampleRate; }; - inline uint16_t getBufferSize() const noexcept { return m_samples; }; - inline uint8_t getBitsDepth() const noexcept { return m_bitsDepth; }; - inline uint8_t getMasterVolume() const noexcept { return m_master_volume; }; + int8_t getChannelGroupPan(const mixer::eChannelGroup group) const noexcept; + void setChannelGroupPan(const mixer::eChannelGroup group, const int8_t pan) noexcept; + inline uint8_t getMasterVolume() const noexcept { return m_master_volume; }; virtual void setMasterVolume(const uint8_t master_volume) noexcept = 0; inline void toggleReverseStereo() noexcept { m_reverseStereo = !m_reverseStereo; }; - const uint8_t max_channels; protected: + virtual void updateChannelsVolumePan_() noexcept = 0; + std::array m_group_settings; bool m_ready = false; // TODO: not really useful if not used anywhere else except init. // unless remove init method and do it in the constructor // and then check if it is ready before use the mixer // otherwise can just be removed. bool m_reverseStereo = false; - const uint32_t m_sampleRate; - const uint16_t m_samples; - const uint8_t m_bitsDepth = 16; // forced to be 16-bits for now + uint8_t m_master_volume = mixer::Mixer_max_volume; }; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp index f0c87746..d61ea116 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/mixer/Channel.cpp @@ -17,7 +17,7 @@ namespace HyperSonicDrivers::audio::mixer reset(); m_group = group; m_stream = stream; - m_converter = converters::makeIRateConverter(m_stream->getRate(), m_mixer.getOutputRate(), m_stream->isStereo(), reverseStereo); + m_converter = converters::makeIRateConverter(m_stream->getRate(), m_mixer.freq, m_stream->isStereo(), reverseStereo); } void Channel::setAudioStream(const mixer::eChannelGroup group, const std::shared_ptr& stream, diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp index c7c1515f..d17369c4 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp @@ -116,7 +116,7 @@ namespace HyperSonicDrivers::audio::sdl2 m_channels[id]->unpause(); } - bool Mixer::isChannelActive(const uint8_t id) const noexcept + bool Mixer::isActive(const uint8_t id) const noexcept { std::scoped_lock lck(m_mutex); @@ -195,6 +195,12 @@ namespace HyperSonicDrivers::audio::sdl2 updateChannelsVolumePan_(); } + void Mixer::updateChannelsVolumePan_() noexcept + { + for (const auto& ch : m_channels) + ch->updateVolumePan(); + } + bool Mixer::init_(SDL_AudioCallback callback, void* userdata) { m_ready = false; @@ -206,10 +212,10 @@ namespace HyperSonicDrivers::audio::sdl2 // Get the desired audio specs SDL_AudioSpec desired = { - .freq = static_cast(m_sampleRate), + .freq = static_cast(freq), .format = AUDIO_S16, .channels = 2, - .samples = m_samples, + .samples = buffer_size, .callback = callback, .userdata = userdata }; @@ -244,12 +250,6 @@ namespace HyperSonicDrivers::audio::sdl2 return true; } - void Mixer::updateChannelsVolumePan_() noexcept - { - for (const auto& ch : m_channels) - ch->updateVolumePan(); - } - size_t Mixer::callback(uint8_t* samples, unsigned int len) { const std::scoped_lock lck(m_mutex); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp index 899c8968..607dc13d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp @@ -39,7 +39,7 @@ namespace HyperSonicDrivers::audio::sdl2 void unpause() noexcept override; void unpause(const uint8_t id) noexcept override; - bool isChannelActive(const uint8_t id) const noexcept override; + bool isActive(const uint8_t id) const noexcept override; bool isPaused(const uint8_t id) const noexcept override; @@ -58,9 +58,11 @@ namespace HyperSonicDrivers::audio::sdl2 void setMasterVolume(const uint8_t master_volume) noexcept override; + protected: + void updateChannelsVolumePan_() noexcept override; + private: bool init_(SDL_AudioCallback callback, void* userdata); - void updateChannelsVolumePan_() noexcept; size_t callback(uint8_t* samples, unsigned int len); static void sdlCallback(void* this_, uint8_t* samples, int len); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp index f79ee2f2..4150a374 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Renderer.cpp @@ -26,7 +26,7 @@ namespace HyperSonicDrivers::audio::sdl2 if (m_buf.empty()) { m_out->save_prepare(stream->getRate(), stream->isStereo()); - m_buf.resize(m_mixer->getBufferSize()); + m_buf.resize(m_mixer->buffer_size); } const size_t read = stream->readBuffer(m_buf.data(), m_buf.size()); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp index e3ff017c..13fd04e5 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp @@ -13,7 +13,7 @@ namespace HyperSonicDrivers::files std::shared_ptr data; uint32_t size = m_dataSize; - switch (m_bitsDepth) + switch (bitsDepth) { case 8: data.reset(audio::converters::convert8to16(m_data.get(), size)); @@ -23,14 +23,14 @@ namespace HyperSonicDrivers::files size >>= 1; break; default: - utils::throwLogC(std::format("bitsDepth = {}, not supported/implemented", m_bitsDepth)); + utils::throwLogC(std::format("bitsDepth = {}, not supported/implemented", bitsDepth)); break; } m_sound = std::make_shared( group, m_channels == 2, - m_sampleRate, + freq, size, data ); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp index cd343b8e..d259899d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp @@ -18,16 +18,16 @@ namespace HyperSonicDrivers::files virtual ~IPCMFile() = default; inline int getChannels() const noexcept { return m_channels; }; - inline uint32_t getSampleRate() const noexcept { return m_sampleRate; }; - inline uint8_t getBitsDepth() const noexcept { return m_bitsDepth; }; + inline uint32_t getSampleRate() const noexcept { return freq; }; + inline uint8_t getBitsDepth() const noexcept { return bitsDepth; }; inline uint32_t getDataSize() const noexcept { return m_dataSize; }; inline std::shared_ptr getData() const noexcept { return m_data; }; inline std::shared_ptr getSound() const noexcept { return m_sound; }; protected: int m_channels = 0; - uint32_t m_sampleRate = 0; - uint8_t m_bitsDepth = 0; + uint32_t freq = 0; + uint8_t bitsDepth = 0; uint32_t m_dataSize = 0; std::shared_ptr m_data; std::shared_ptr m_sound; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp index 59abe0f2..db8b965d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp @@ -16,7 +16,7 @@ namespace HyperSonicDrivers::files m_version(0) { m_channels = 1; - m_bitsDepth = 8; + bitsDepth = 8; assertValid_(readHeader()); assertValid_(readDataBlockHeader()); @@ -74,9 +74,9 @@ namespace HyperSonicDrivers::files // channels default = 1 // timeConstant = 65536 - (256000000 / (channels * sampleRate); // sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels) - m_sampleRate = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); + freq = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); //m_sampleRate = 1000000 / (256 - timeConstant); - assertValid_(m_sampleRate == (1000000 / (256 - timeConstant))); + assertValid_(freq == (1000000 / (256 - timeConstant))); // pack Method switch (packMethod) { @@ -137,8 +137,8 @@ namespace HyperSonicDrivers::files case 9: // extended 2 { assertValid_(m_version >= 0x0114); - m_sampleRate = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); - m_bitsDepth = db.data[4]; + freq = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); + bitsDepth = db.data[4]; m_channels = db.data[5]; uint16_t format = db.data[6] + (db.data[7] << 8); for (int i = 0; i < 4; i++) @@ -179,7 +179,7 @@ namespace HyperSonicDrivers::files } int divisor = 1; - if (m_bitsDepth == 16) { + if (bitsDepth == 16) { divisor <<= 1; } if (m_channels == 2) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp index ace1ced6..45ebdc86 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp @@ -173,9 +173,9 @@ namespace HyperSonicDrivers::files // fmt always before data chunk m_expDataChunk = true; - m_bitsDepth = static_cast(m_fmt_chunk.bitsPerSample); + bitsDepth = static_cast(m_fmt_chunk.bitsPerSample); m_channels = m_fmt_chunk.channels; - m_sampleRate = m_fmt_chunk.samplesPerSec; + freq = m_fmt_chunk.samplesPerSec; return true; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp index d8145918..c3717d13 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp @@ -6,7 +6,7 @@ namespace HyperSonicDrivers::hardware { IHardware::IHardware(const std::shared_ptr& mixer) : - m_mixer(mixer), m_output_rate(m_mixer->getOutputRate()) + m_mixer(mixer), m_output_rate(m_mixer->freq) { if (m_mixer == nullptr) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/mt32/MT32.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/mt32/MT32.cpp index 28597f6f..8586828d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/mt32/MT32.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/mt32/MT32.cpp @@ -131,7 +131,7 @@ namespace HyperSonicDrivers::hardware::mt32 setAudioStream(std::make_shared( this, isStereo(), - m_mixer->getOutputRate(), + m_mixer->freq, setCallbackFrequency(timerFrequency) )); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/OPL.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/OPL.cpp index c6f324d3..2235e256 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/OPL.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/OPL.cpp @@ -33,7 +33,7 @@ namespace HyperSonicDrivers::hardware::opl setAudioStream(std::make_shared( this, isStereo(), - m_mixer->getOutputRate(), + m_mixer->freq, setCallbackFrequency(timerFrequency) )); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp index cba69114..7dace502 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/mame/MameOPL3.cpp @@ -38,9 +38,9 @@ namespace HyperSonicDrivers::hardware::opl::mame _opl = new ymfm::ymf262(_ymfm); auto rate = _opl->sample_rate(OPL3_INTERNAL_FREQ); - _opl->sample_rate(m_mixer->getOutputRate()); + _opl->sample_rate(m_mixer->freq); - _chip = ymf262_init(0, OPL3_INTERNAL_FREQ, m_mixer->getOutputRate()); + _chip = ymf262_init(0, OPL3_INTERNAL_FREQ, m_mixer->freq); //_init = _opl != nullptr; m_init = _chip != nullptr; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/dosbox/DosBoxOPL.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/dosbox/DosBoxOPL.cpp index 63214fbe..a618d638 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/dosbox/DosBoxOPL.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/dosbox/DosBoxOPL.cpp @@ -36,7 +36,7 @@ namespace HyperSonicDrivers::hardware::opl::scummvm::dosbox return false; dbopl::InitTables(); - m_rate = m_mixer->getOutputRate(); + m_rate = m_mixer->freq; m_emulator->Setup(m_rate); if (type == OplType::DUAL_OPL2) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/mame/MameOPL2.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/mame/MameOPL2.cpp index 03fb7051..166e7c05 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/mame/MameOPL2.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/mame/MameOPL2.cpp @@ -26,7 +26,7 @@ namespace HyperSonicDrivers::hardware::opl::scummvm::mame if (m_init) return true; - _opl = makeAdLibOPL(m_mixer->getOutputRate()); + _opl = makeAdLibOPL(m_mixer->freq); memset(&_reg, 0, sizeof(_reg)); m_init = (_opl != nullptr); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/nuked/NukedOPL3.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/nuked/NukedOPL3.cpp index 0ac69974..7b003298 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/nuked/NukedOPL3.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/scummvm/nuked/NukedOPL3.cpp @@ -17,7 +17,7 @@ namespace HyperSonicDrivers::hardware::opl::scummvm::nuked return true; memset(&_reg, 0, sizeof(_reg)); - _rate = m_mixer->getOutputRate(); + _rate = m_mixer->freq; OPL3_Reset(chip.get(), _rate); if (type == OplType::DUAL_OPL2) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/woody/WoodyOPL.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/woody/WoodyOPL.cpp index c69d1465..aa21e45b 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/woody/WoodyOPL.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/opl/woody/WoodyOPL.cpp @@ -20,9 +20,9 @@ namespace HyperSonicDrivers::hardware stop(); if (type == OplType::DUAL_OPL2) - _opl =std::make_unique(m_mixer->getOutputRate()); + _opl =std::make_unique(m_mixer->freq); else - _opl = std::make_unique(m_mixer->getOutputRate()); + _opl = std::make_unique(m_mixer->freq); m_init = _opl != nullptr; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp index d115b853..76a5f2e6 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp @@ -40,7 +40,7 @@ namespace HyperSonicDrivers::audio void unpause() noexcept override {}; void unpause(const uint8_t id) noexcept override {}; - bool isChannelActive(const uint8_t id) const noexcept override { return true; }; + bool isActive(const uint8_t id) const noexcept override { return true; }; bool isPaused(const uint8_t id) const noexcept override { return false; } bool isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept override { return false; }; void muteChannelGroup(const mixer::eChannelGroup group) noexcept override {}; @@ -56,5 +56,7 @@ namespace HyperSonicDrivers::audio void setChannelVolumePan(const uint8_t id, const uint8_t volume, const int8_t pan) noexcept override {}; void setMasterVolume(const uint8_t master_volume) noexcept override {}; + + void updateChannelsVolumePan_() noexcept override {}; }; } From 6e744e7fb1b13fbbe58d6eae7d87ef5a8b20319f Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:08:09 +0000 Subject: [PATCH 03/15] refactor IMixer --- .../examples/adl-example.cpp | 2 +- .../examples/mid-example.h | 2 +- .../examples/mt32-example.cpp | 2 +- .../examples/pcm-example.cpp | 6 ++-- .../sdl2-hyper-sonic-drivers.cpp | 6 ++-- .../src/HyperSonicDrivers/audio/IMixer.hpp | 3 ++ .../HyperSonicDrivers/audio/sdl2/Mixer.cpp | 22 +++++++++++++ .../HyperSonicDrivers/audio/sdl2/Mixer.hpp | 2 ++ .../drivers/IAudioDriver.hpp | 2 +- .../HyperSonicDrivers/drivers/MIDDriver.cpp | 2 +- .../HyperSonicDrivers/drivers/MIDDriver.hpp | 2 +- .../HyperSonicDrivers/drivers/PCMDriver.cpp | 4 +-- .../HyperSonicDrivers/drivers/PCMDriver.hpp | 4 +-- .../drivers/westwood/ADLDriver.cpp | 2 +- .../drivers/westwood/ADLDriver.hpp | 2 +- .../HyperSonicDrivers/hardware/PCSpeaker.cpp | 2 +- .../HyperSonicDrivers/hardware/PCSpeaker.hpp | 2 +- .../HyperSonicDrivers/audio/IMixerMock.hpp | 2 ++ .../audio/sdl2/TestRenderer.cpp | 2 +- .../drivers/TestIAudioDriver.cpp | 2 +- .../drivers/TestMIDDriver.cpp | 6 ++-- .../drivers/TestPCMDriver.cpp | 32 +++++++++---------- .../hardware/TestPCSpeaker.cpp | 6 ++-- 23 files changed, 73 insertions(+), 44 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/adl-example.cpp b/sdl2-hyper-sonic-drivers/examples/adl-example.cpp index eb84f565..f82e5800 100644 --- a/sdl2-hyper-sonic-drivers/examples/adl-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/adl-example.cpp @@ -62,7 +62,7 @@ void adl_test(const OplEmulator emu, const OplType type, std::shared_ptr auto start_time = std::chrono::system_clock::now(); midDrv.setMidi(midi); midDrv.play(0); - while (midDrv.isPlaying()) { + while (midDrv.isActive()) { utils::delayMillis(1000); } diff --git a/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp b/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp index 3c4733b7..5158284c 100644 --- a/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) drivers::MIDDriver middrv(mt32, eChannelGroup::Music); middrv.setMidi(midi); middrv.play(0); - while (middrv.isPlaying()) + while (middrv.isActive()) { utils::delayMillis(100); } diff --git a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp index 4ec2058c..0d008cd5 100644 --- a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp @@ -40,7 +40,7 @@ int main(int argc, char* argv[]) } drv.play(wavSound); - while(drv.isPlaying(wavSound)) + while(drv.isActive(wavSound)) { cout << "is playing" << endl; delayMillis(1000); @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) delayMillis(500); drv.play(vocSound); - while (drv.isPlaying(vocSound)) + while (drv.isActive(vocSound)) { cout << "is playing" << endl; delayMillis(1000); @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) drv.play(vocSound, 255, -127 * sig); } - while(drv.isPlaying()) + while(drv.isActive()) { cout << "is playing" << endl; delayMillis(1000); diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index b61e7fd9..5968e90f 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -62,9 +62,9 @@ void playNotes(hardware::PCSpeaker *pcSpeaker, const hardware::PCSpeaker::eWaveF { auto start = std::chrono::steady_clock::now(); pcSpeaker->play(waveForm, freq, length); - while (pcSpeaker->isPlaying()) { SDL_Delay(10); } + while (pcSpeaker->isActive()) { SDL_Delay(10); } pcSpeaker->play(waveForm, freq + 183, length * 2); - while (pcSpeaker->isPlaying()) { SDL_Delay(10); } + while (pcSpeaker->isActive()) { SDL_Delay(10); } auto end = std::chrono::steady_clock::now(); std::chrono::duration elapsed_seconds = end - start; std::cout << "Elapsed Time (s) = " << elapsed_seconds.count() << " --- Expected (s) ~=" << length + length * 2 << "\n"; @@ -404,7 +404,7 @@ void pcm_sound_append() drivers::PCMDriver drv(mixer); drv.play(s2); - while (drv.isPlaying()) + while (drv.isActive()) { utils::delayMillis(100); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp index a4495919..78093ca8 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp @@ -55,6 +55,9 @@ namespace HyperSonicDrivers::audio virtual bool isActive(const uint8_t id) const noexcept = 0; virtual bool isPaused(const uint8_t id) const noexcept = 0; + virtual bool isActive() const noexcept = 0; + virtual bool isActive(const mixer::eChannelGroup group) = 0; + virtual bool isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept = 0; virtual void muteChannelGroup(const mixer::eChannelGroup group) noexcept = 0; virtual void unmuteChannelGroup(const mixer::eChannelGroup group) noexcept = 0; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp index d17369c4..0697c99c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp @@ -130,6 +130,28 @@ namespace HyperSonicDrivers::audio::sdl2 return m_channels[id]->isPaused(); } + bool Mixer::isActive() const noexcept + { + std::scoped_lock lck(m_mutex); + + for (const auto& ch : m_channels) + if (!ch->isEnded()) + return true; + + return false; + } + + bool Mixer::isActive(const mixer::eChannelGroup group) + { + std::scoped_lock lck(m_mutex); + + for (const auto& ch : m_channels) + if (ch->getChannelGroup() == group && !ch->isEnded()) + return true; + + return false; + } + bool Mixer::isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept { return m_group_settings[group2i(group)].mute; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp index 607dc13d..bfaaa2a7 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp @@ -42,6 +42,8 @@ namespace HyperSonicDrivers::audio::sdl2 bool isActive(const uint8_t id) const noexcept override; bool isPaused(const uint8_t id) const noexcept override; + bool isActive() const noexcept override; + bool isActive(const mixer::eChannelGroup group) override; bool isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept override;; void muteChannelGroup(const mixer::eChannelGroup group) noexcept override; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp index 777c9980..72b497f7 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp @@ -30,7 +30,7 @@ namespace HyperSonicDrivers::drivers // TODO: it might not be required //virtual void resume() = 0; - virtual bool isPlaying() const noexcept = 0; + virtual bool isActive() const noexcept = 0; // TODO: it might not be required //virtual bool isPaused() const noexcept = 0; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp index e7074947..98c417d5 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp @@ -234,7 +234,7 @@ namespace HyperSonicDrivers::drivers m_paused = false; } - bool MIDDriver::isPlaying() const noexcept + bool MIDDriver::isActive() const noexcept { return m_isPlaying; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp index a0950016..b69ee69c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp @@ -43,7 +43,7 @@ namespace HyperSonicDrivers::drivers void pause() noexcept; void resume() noexcept; - bool isPlaying() const noexcept override; + bool isActive() const noexcept override; bool isPaused() const noexcept; inline bool isTempoChanged() const noexcept { return m_midiTempoChanged; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp index 37110ddc..b73f65cd 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp @@ -10,7 +10,7 @@ namespace HyperSonicDrivers::drivers { } - bool PCMDriver::isPlaying() const noexcept + bool PCMDriver::isActive() const noexcept { for (const auto& [stream, _] : m_PCMStreams_channels) { @@ -21,7 +21,7 @@ namespace HyperSonicDrivers::drivers return false; } - bool PCMDriver::isPlaying(const std::shared_ptr& sound) const noexcept + bool PCMDriver::isActive(const std::shared_ptr& sound) const noexcept { for (const auto& [stream, _] : m_PCMStreams_channels) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp index 0bcb4820..098a3735 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp @@ -23,8 +23,8 @@ namespace HyperSonicDrivers::drivers explicit PCMDriver(const std::shared_ptr& mixer, const uint8_t max_channels = 0xFF); ~PCMDriver() = default; - bool isPlaying() const noexcept; - bool isPlaying(const std::shared_ptr& sound) const noexcept; + bool isActive() const noexcept; + bool isActive(const std::shared_ptr& sound) const noexcept; std::optional play( const std::shared_ptr& sound, const uint8_t volume = audio::mixer::Channel_max_volume, diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp index 6451c4c9..fbf631e1 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp @@ -253,7 +253,7 @@ namespace HyperSonicDrivers::drivers::westwood stopAllChannels(); } - bool ADLDriver::isPlaying() const noexcept + bool ADLDriver::isActive() const noexcept { bool res = false; for (int i = 0; i <= NUM_CHANNELS; i++) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp index aba97f91..fa3fb28c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp @@ -56,7 +56,7 @@ namespace HyperSonicDrivers::drivers::westwood void play(const uint8_t track) noexcept override; void stop() noexcept override; - bool isPlaying() const noexcept override; + bool isActive() const noexcept override; private: void initDriver_(); void startSound_(const uint8_t track, const uint8_t volume); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp index 977ad085..3de27584 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp @@ -90,7 +90,7 @@ namespace HyperSonicDrivers::hardware _setRemainingSamples(delay); } - bool PCSpeaker::isPlaying() const noexcept + bool PCSpeaker::isActive() const noexcept { return _remainingSamples != 0; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp index de0f805d..fdbd9a4b 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp @@ -47,7 +47,7 @@ namespace HyperSonicDrivers::hardware void play(const eWaveForm waveForm, const int freq, const int32_t length); /** Stop the currently playing note after delay ms. */ void stop(const int32_t delay = 0); - bool isPlaying() const noexcept; + bool isActive() const noexcept; template uint32_t readBuffer(T* buffer, uint32_t numSamples); uint32_t getRate() const noexcept; uint8_t getChannels() const noexcept; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp index 76a5f2e6..cb1c07c4 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp @@ -42,6 +42,8 @@ namespace HyperSonicDrivers::audio bool isActive(const uint8_t id) const noexcept override { return true; }; bool isPaused(const uint8_t id) const noexcept override { return false; } + bool isActive() const noexcept override { return true; }; + bool isActive(const mixer::eChannelGroup group) override { return true; }; bool isChannelGroupMuted(const mixer::eChannelGroup group) const noexcept override { return false; }; void muteChannelGroup(const mixer::eChannelGroup group) noexcept override {}; void unmuteChannelGroup(const mixer::eChannelGroup group) noexcept override {}; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp index 0b8f4e95..013ffc73 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -63,7 +63,7 @@ namespace HyperSonicDrivers::audio::sdl2 drv1.setADLFile(af); drv1.play(4); - while (drv1.isPlaying()) + while (drv1.isActive()) r.renderBuffer(opl); r.closeOutputFile(); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp index 56213cd2..d442dcba 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp @@ -10,7 +10,7 @@ namespace HyperSonicDrivers::drivers IAudioDriverMock(const std::shared_ptr& device) : IAudioDriver(device) {} void play(const uint8_t track) noexcept override {}; void stop() noexcept override {}; - bool isPlaying() const noexcept override { return false; }; + bool isActive() const noexcept override { return false; }; }; TEST(IAudioDriver, cstor_nullptr) diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp index 8b55a7e5..7dffd269 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp @@ -88,14 +88,14 @@ namespace HyperSonicDrivers::drivers MIDDriverMock middrv(device); middrv.setMidi(midi); middrv.play(0); - ASSERT_TRUE(middrv.isPlaying()); + ASSERT_TRUE(middrv.isActive()); auto start = utils::getMillis(); utils::delayMillis(20); middrv.stop(); - EXPECT_FALSE(middrv.isPlaying()); + EXPECT_FALSE(middrv.isActive()); auto stop = utils::getMillis(); EXPECT_LE(stop - start, 1 * 1000); - EXPECT_FALSE(middrv.isPlaying()); + EXPECT_FALSE(middrv.isActive()); EXPECT_TRUE(device->isAcquired()); } EXPECT_FALSE(device->isAcquired()); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp index 6b714c19..eccafc7a 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp @@ -20,14 +20,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isPlaying(sound)); - ASSERT_TRUE(drv.isPlaying()); + ASSERT_TRUE(drv.isActive(sound)); + ASSERT_TRUE(drv.isActive()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(ch_id.value()); - EXPECT_FALSE(drv.isPlaying(sound)); - EXPECT_FALSE(drv.isPlaying()); + EXPECT_FALSE(drv.isActive(sound)); + EXPECT_FALSE(drv.isActive()); } TEST(PCMDriver, play_stop1) @@ -41,14 +41,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isPlaying(sound)); - ASSERT_TRUE(drv.isPlaying()); + ASSERT_TRUE(drv.isActive(sound)); + ASSERT_TRUE(drv.isActive()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(sound); - EXPECT_FALSE(drv.isPlaying(sound)); - EXPECT_FALSE(drv.isPlaying()); + EXPECT_FALSE(drv.isActive(sound)); + EXPECT_FALSE(drv.isActive()); } TEST(PCMDriver, play_stop2) @@ -62,14 +62,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isPlaying(sound)); - ASSERT_TRUE(drv.isPlaying()); + ASSERT_TRUE(drv.isActive(sound)); + ASSERT_TRUE(drv.isActive()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(); - EXPECT_FALSE(drv.isPlaying(sound)); - EXPECT_FALSE(drv.isPlaying()); + EXPECT_FALSE(drv.isActive(sound)); + EXPECT_FALSE(drv.isActive()); } TEST(PCMDriver, play_stop_complex) @@ -89,14 +89,14 @@ namespace HyperSonicDrivers::drivers EXPECT_TRUE(drv.play(sound2).has_value()); EXPECT_TRUE(drv.play(sound2).has_value()); - ASSERT_TRUE(drv.isPlaying(sound)); - ASSERT_TRUE(drv.isPlaying()); + ASSERT_TRUE(drv.isActive(sound)); + ASSERT_TRUE(drv.isActive()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(ch_id.value()); - EXPECT_FALSE(drv.isPlaying(sound)); - EXPECT_TRUE(drv.isPlaying()); + EXPECT_FALSE(drv.isActive(sound)); + EXPECT_TRUE(drv.isActive()); } } diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp index 0684fac0..4153e2dc 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp @@ -27,11 +27,11 @@ namespace HyperSonicDrivers::hardware FAIL(); } - TEST(PCSpeaker, isPlaying) + TEST(PCSpeaker, isActive) { PCSpeaker pcSpeaker(44100, 8); pcSpeaker.play(PCSpeaker::eWaveForm::SINE, 440, 1); - EXPECT_TRUE(pcSpeaker.isPlaying()); + EXPECT_TRUE(pcSpeaker.isActive()); } TEST(PCSpeaker, readBuffer) @@ -74,7 +74,7 @@ namespace HyperSonicDrivers::hardware double tsum = 0.0; uint32_t dsum = 0; - while (pcSpeaker->isPlaying()) + while (pcSpeaker->isActive()) { uint32_t d = this->readbuf(); dsum += d; From 2658b941c4f7c20025b27d013fd7e7fbe8e176de Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:10:40 +0000 Subject: [PATCH 04/15] IMixer add reset channel group (stop) --- .../src/HyperSonicDrivers/audio/IMixer.hpp | 1 + .../src/HyperSonicDrivers/audio/sdl2/Mixer.cpp | 11 +++++++++++ .../src/HyperSonicDrivers/audio/sdl2/Mixer.hpp | 1 + .../test/HyperSonicDrivers/audio/IMixerMock.hpp | 1 + 4 files changed, 14 insertions(+) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp index 78093ca8..4f1988b0 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/IMixer.hpp @@ -45,6 +45,7 @@ namespace HyperSonicDrivers::audio virtual void reset() noexcept = 0; virtual void reset(const uint8_t id) noexcept = 0; + virtual void reset(const mixer::eChannelGroup group) noexcept = 0; virtual void pause() noexcept = 0; virtual void pause(const uint8_t id) noexcept = 0; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp index 0697c99c..f6d98ca0 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp @@ -86,6 +86,17 @@ namespace HyperSonicDrivers::audio::sdl2 m_channels[id]->reset(); } + void Mixer::reset(const mixer::eChannelGroup group) noexcept + { + std::scoped_lock lck(m_mutex); + + for (const auto& ch : m_channels) + { + if (ch->getChannelGroup() == group) + ch->reset(); + } + } + void Mixer::pause() noexcept { std::scoped_lock lck(m_mutex); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp index bfaaa2a7..e8693568 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.hpp @@ -32,6 +32,7 @@ namespace HyperSonicDrivers::audio::sdl2 void reset() noexcept override; void reset(const uint8_t id) noexcept override; + void reset(const mixer::eChannelGroup group) noexcept override; void pause() noexcept override; void pause(const uint8_t id) noexcept override; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp index cb1c07c4..25f13482 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/IMixerMock.hpp @@ -33,6 +33,7 @@ namespace HyperSonicDrivers::audio void reset() noexcept override {}; void reset(const uint8_t id) noexcept override {}; + void reset(const mixer::eChannelGroup group) noexcept override {}; void pause() noexcept override {}; void pause(const uint8_t id) noexcept override {}; From 0fb30a77289efec8d362eead9f385efa6bd3f14a Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:11:18 +0000 Subject: [PATCH 05/15] update version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be58d284..c2bf284e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) endif() -project ("sdl2-hyper-sonic-drivers" VERSION 0.15.4 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") +project ("sdl2-hyper-sonic-drivers" VERSION 0.16.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards") include (TestBigEndian) TEST_BIG_ENDIAN(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) From 9890945f71cc18c9fa246bc6f6177830e9658099 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:13:29 +0000 Subject: [PATCH 06/15] restore sonarcloud ci bot comment on PR --- .github/workflows/sonarcloud.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 167cf656..54918cff 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -18,15 +18,15 @@ on: #branches: # - master - #pull_request: - ## branches: [ master ] - # paths-ignore: - # - 'doc/**' - # - '.gitignore' - # - '.gitattributes' - # - 'README.md' - # - 'LICENSE' - # - 'wave_generators.r' + pull_request: + # branches: [ master ] + paths-ignore: + - 'doc/**' + - '.gitignore' + - '.gitattributes' + - 'README.md' + - 'LICENSE' + - 'wave_generators.r' #permissions: read-all From 4767248605dae3847530340062f2be78c59f2a33 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:26:59 +0000 Subject: [PATCH 07/15] revert accidental refactor to isPlaying --- sdl2-hyper-sonic-drivers/examples/adl-example.cpp | 2 +- sdl2-hyper-sonic-drivers/examples/mid-example.h | 2 +- sdl2-hyper-sonic-drivers/examples/mt32-example.cpp | 2 +- .../src/HyperSonicDrivers/drivers/IAudioDriver.hpp | 2 +- .../src/HyperSonicDrivers/drivers/MIDDriver.cpp | 2 +- .../src/HyperSonicDrivers/drivers/MIDDriver.hpp | 2 +- .../src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp | 2 +- .../src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp | 2 +- .../test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp | 2 +- .../test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp | 2 +- .../test/HyperSonicDrivers/drivers/TestMIDDriver.cpp | 6 +++--- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/adl-example.cpp b/sdl2-hyper-sonic-drivers/examples/adl-example.cpp index f82e5800..eb84f565 100644 --- a/sdl2-hyper-sonic-drivers/examples/adl-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/adl-example.cpp @@ -62,7 +62,7 @@ void adl_test(const OplEmulator emu, const OplType type, std::shared_ptr auto start_time = std::chrono::system_clock::now(); midDrv.setMidi(midi); midDrv.play(0); - while (midDrv.isActive()) { + while (midDrv.isPlaying()) { utils::delayMillis(1000); } diff --git a/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp b/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp index 5158284c..3c4733b7 100644 --- a/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/mt32-example.cpp @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) drivers::MIDDriver middrv(mt32, eChannelGroup::Music); middrv.setMidi(midi); middrv.play(0); - while (middrv.isActive()) + while (middrv.isPlaying()) { utils::delayMillis(100); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp index 72b497f7..777c9980 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/IAudioDriver.hpp @@ -30,7 +30,7 @@ namespace HyperSonicDrivers::drivers // TODO: it might not be required //virtual void resume() = 0; - virtual bool isActive() const noexcept = 0; + virtual bool isPlaying() const noexcept = 0; // TODO: it might not be required //virtual bool isPaused() const noexcept = 0; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp index 98c417d5..e7074947 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.cpp @@ -234,7 +234,7 @@ namespace HyperSonicDrivers::drivers m_paused = false; } - bool MIDDriver::isActive() const noexcept + bool MIDDriver::isPlaying() const noexcept { return m_isPlaying; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp index b69ee69c..a0950016 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/MIDDriver.hpp @@ -43,7 +43,7 @@ namespace HyperSonicDrivers::drivers void pause() noexcept; void resume() noexcept; - bool isActive() const noexcept override; + bool isPlaying() const noexcept override; bool isPaused() const noexcept; inline bool isTempoChanged() const noexcept { return m_midiTempoChanged; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp index fbf631e1..6451c4c9 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp @@ -253,7 +253,7 @@ namespace HyperSonicDrivers::drivers::westwood stopAllChannels(); } - bool ADLDriver::isActive() const noexcept + bool ADLDriver::isPlaying() const noexcept { bool res = false; for (int i = 0; i <= NUM_CHANNELS; i++) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp index fa3fb28c..aba97f91 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/westwood/ADLDriver.hpp @@ -56,7 +56,7 @@ namespace HyperSonicDrivers::drivers::westwood void play(const uint8_t track) noexcept override; void stop() noexcept override; - bool isActive() const noexcept override; + bool isPlaying() const noexcept override; private: void initDriver_(); void startSound_(const uint8_t track, const uint8_t volume); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp index 013ffc73..0b8f4e95 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/audio/sdl2/TestRenderer.cpp @@ -63,7 +63,7 @@ namespace HyperSonicDrivers::audio::sdl2 drv1.setADLFile(af); drv1.play(4); - while (drv1.isActive()) + while (drv1.isPlaying()) r.renderBuffer(opl); r.closeOutputFile(); diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp index d442dcba..56213cd2 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestIAudioDriver.cpp @@ -10,7 +10,7 @@ namespace HyperSonicDrivers::drivers IAudioDriverMock(const std::shared_ptr& device) : IAudioDriver(device) {} void play(const uint8_t track) noexcept override {}; void stop() noexcept override {}; - bool isActive() const noexcept override { return false; }; + bool isPlaying() const noexcept override { return false; }; }; TEST(IAudioDriver, cstor_nullptr) diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp index 7dffd269..8b55a7e5 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestMIDDriver.cpp @@ -88,14 +88,14 @@ namespace HyperSonicDrivers::drivers MIDDriverMock middrv(device); middrv.setMidi(midi); middrv.play(0); - ASSERT_TRUE(middrv.isActive()); + ASSERT_TRUE(middrv.isPlaying()); auto start = utils::getMillis(); utils::delayMillis(20); middrv.stop(); - EXPECT_FALSE(middrv.isActive()); + EXPECT_FALSE(middrv.isPlaying()); auto stop = utils::getMillis(); EXPECT_LE(stop - start, 1 * 1000); - EXPECT_FALSE(middrv.isActive()); + EXPECT_FALSE(middrv.isPlaying()); EXPECT_TRUE(device->isAcquired()); } EXPECT_FALSE(device->isAcquired()); From 7d17db8cf7913b70e0d5653365fafdb988e8e298 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:28:13 +0000 Subject: [PATCH 08/15] revert accidental refactor to isPlaying --- .../examples/pcm-example.cpp | 6 ++-- .../sdl2-hyper-sonic-drivers.cpp | 2 +- .../HyperSonicDrivers/drivers/PCMDriver.cpp | 4 +-- .../HyperSonicDrivers/drivers/PCMDriver.hpp | 4 +-- .../drivers/TestPCMDriver.cpp | 32 +++++++++---------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp index 0d008cd5..4ec2058c 100644 --- a/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp +++ b/sdl2-hyper-sonic-drivers/examples/pcm-example.cpp @@ -40,7 +40,7 @@ int main(int argc, char* argv[]) } drv.play(wavSound); - while(drv.isActive(wavSound)) + while(drv.isPlaying(wavSound)) { cout << "is playing" << endl; delayMillis(1000); @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) delayMillis(500); drv.play(vocSound); - while (drv.isActive(vocSound)) + while (drv.isPlaying(vocSound)) { cout << "is playing" << endl; delayMillis(1000); @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) drv.play(vocSound, 255, -127 * sig); } - while(drv.isActive()) + while(drv.isPlaying()) { cout << "is playing" << endl; delayMillis(1000); diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index 5968e90f..c529c9af 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -404,7 +404,7 @@ void pcm_sound_append() drivers::PCMDriver drv(mixer); drv.play(s2); - while (drv.isActive()) + while (drv.isPlaying()) { utils::delayMillis(100); } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp index b73f65cd..37110ddc 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.cpp @@ -10,7 +10,7 @@ namespace HyperSonicDrivers::drivers { } - bool PCMDriver::isActive() const noexcept + bool PCMDriver::isPlaying() const noexcept { for (const auto& [stream, _] : m_PCMStreams_channels) { @@ -21,7 +21,7 @@ namespace HyperSonicDrivers::drivers return false; } - bool PCMDriver::isActive(const std::shared_ptr& sound) const noexcept + bool PCMDriver::isPlaying(const std::shared_ptr& sound) const noexcept { for (const auto& [stream, _] : m_PCMStreams_channels) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp index 098a3735..0bcb4820 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/PCMDriver.hpp @@ -23,8 +23,8 @@ namespace HyperSonicDrivers::drivers explicit PCMDriver(const std::shared_ptr& mixer, const uint8_t max_channels = 0xFF); ~PCMDriver() = default; - bool isActive() const noexcept; - bool isActive(const std::shared_ptr& sound) const noexcept; + bool isPlaying() const noexcept; + bool isPlaying(const std::shared_ptr& sound) const noexcept; std::optional play( const std::shared_ptr& sound, const uint8_t volume = audio::mixer::Channel_max_volume, diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp index eccafc7a..6b714c19 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/TestPCMDriver.cpp @@ -20,14 +20,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isActive(sound)); - ASSERT_TRUE(drv.isActive()); + ASSERT_TRUE(drv.isPlaying(sound)); + ASSERT_TRUE(drv.isPlaying()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(ch_id.value()); - EXPECT_FALSE(drv.isActive(sound)); - EXPECT_FALSE(drv.isActive()); + EXPECT_FALSE(drv.isPlaying(sound)); + EXPECT_FALSE(drv.isPlaying()); } TEST(PCMDriver, play_stop1) @@ -41,14 +41,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isActive(sound)); - ASSERT_TRUE(drv.isActive()); + ASSERT_TRUE(drv.isPlaying(sound)); + ASSERT_TRUE(drv.isPlaying()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(sound); - EXPECT_FALSE(drv.isActive(sound)); - EXPECT_FALSE(drv.isActive()); + EXPECT_FALSE(drv.isPlaying(sound)); + EXPECT_FALSE(drv.isPlaying()); } TEST(PCMDriver, play_stop2) @@ -62,14 +62,14 @@ namespace HyperSonicDrivers::drivers auto sound = std::make_shared(audio::mixer::eChannelGroup::Plain, true, 44100, 1, sound_data); auto ch_id = drv.play(sound); - ASSERT_TRUE(drv.isActive(sound)); - ASSERT_TRUE(drv.isActive()); + ASSERT_TRUE(drv.isPlaying(sound)); + ASSERT_TRUE(drv.isPlaying()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(); - EXPECT_FALSE(drv.isActive(sound)); - EXPECT_FALSE(drv.isActive()); + EXPECT_FALSE(drv.isPlaying(sound)); + EXPECT_FALSE(drv.isPlaying()); } TEST(PCMDriver, play_stop_complex) @@ -89,14 +89,14 @@ namespace HyperSonicDrivers::drivers EXPECT_TRUE(drv.play(sound2).has_value()); EXPECT_TRUE(drv.play(sound2).has_value()); - ASSERT_TRUE(drv.isActive(sound)); - ASSERT_TRUE(drv.isActive()); + ASSERT_TRUE(drv.isPlaying(sound)); + ASSERT_TRUE(drv.isPlaying()); ASSERT_TRUE(ch_id.has_value()); EXPECT_EQ(ch_id.value(), 0); drv.stop(ch_id.value()); - EXPECT_FALSE(drv.isActive(sound)); - EXPECT_TRUE(drv.isActive()); + EXPECT_FALSE(drv.isPlaying(sound)); + EXPECT_TRUE(drv.isPlaying()); } } From 5c1b38e4c16a4bfc690fc9911db5476eeadb60c3 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:29:00 +0000 Subject: [PATCH 09/15] revert accidental refactor to isPlaying --- sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp | 4 ++-- .../src/HyperSonicDrivers/hardware/PCSpeaker.cpp | 2 +- .../src/HyperSonicDrivers/hardware/PCSpeaker.hpp | 2 +- .../test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp index c529c9af..b61e7fd9 100644 --- a/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp +++ b/sdl2-hyper-sonic-drivers/sdl2-hyper-sonic-drivers.cpp @@ -62,9 +62,9 @@ void playNotes(hardware::PCSpeaker *pcSpeaker, const hardware::PCSpeaker::eWaveF { auto start = std::chrono::steady_clock::now(); pcSpeaker->play(waveForm, freq, length); - while (pcSpeaker->isActive()) { SDL_Delay(10); } + while (pcSpeaker->isPlaying()) { SDL_Delay(10); } pcSpeaker->play(waveForm, freq + 183, length * 2); - while (pcSpeaker->isActive()) { SDL_Delay(10); } + while (pcSpeaker->isPlaying()) { SDL_Delay(10); } auto end = std::chrono::steady_clock::now(); std::chrono::duration elapsed_seconds = end - start; std::cout << "Elapsed Time (s) = " << elapsed_seconds.count() << " --- Expected (s) ~=" << length + length * 2 << "\n"; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp index 3de27584..977ad085 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.cpp @@ -90,7 +90,7 @@ namespace HyperSonicDrivers::hardware _setRemainingSamples(delay); } - bool PCSpeaker::isActive() const noexcept + bool PCSpeaker::isPlaying() const noexcept { return _remainingSamples != 0; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp index fdbd9a4b..de0f805d 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/PCSpeaker.hpp @@ -47,7 +47,7 @@ namespace HyperSonicDrivers::hardware void play(const eWaveForm waveForm, const int freq, const int32_t length); /** Stop the currently playing note after delay ms. */ void stop(const int32_t delay = 0); - bool isActive() const noexcept; + bool isPlaying() const noexcept; template uint32_t readBuffer(T* buffer, uint32_t numSamples); uint32_t getRate() const noexcept; uint8_t getChannels() const noexcept; diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp index 4153e2dc..b89e8ad2 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp @@ -31,7 +31,7 @@ namespace HyperSonicDrivers::hardware { PCSpeaker pcSpeaker(44100, 8); pcSpeaker.play(PCSpeaker::eWaveForm::SINE, 440, 1); - EXPECT_TRUE(pcSpeaker.isActive()); + EXPECT_TRUE(pcSpeaker.isPlaying()); } TEST(PCSpeaker, readBuffer) @@ -74,7 +74,7 @@ namespace HyperSonicDrivers::hardware double tsum = 0.0; uint32_t dsum = 0; - while (pcSpeaker->isActive()) + while (pcSpeaker->isPlaying()) { uint32_t d = this->readbuf(); dsum += d; From b1ae500dc744339ccdca30255b4955bd072b08f3 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:32:02 +0000 Subject: [PATCH 10/15] revert accidental refactor --- .../src/HyperSonicDrivers/files/IPCMFile.cpp | 6 +++--- .../src/HyperSonicDrivers/files/IPCMFile.hpp | 8 ++++---- .../src/HyperSonicDrivers/files/VOCFile.cpp | 12 ++++++------ .../src/HyperSonicDrivers/files/WAVFile.cpp | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp index 13fd04e5..5c5fa78c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp @@ -13,7 +13,7 @@ namespace HyperSonicDrivers::files std::shared_ptr data; uint32_t size = m_dataSize; - switch (bitsDepth) + switch (m_bitsDepth) { case 8: data.reset(audio::converters::convert8to16(m_data.get(), size)); @@ -23,14 +23,14 @@ namespace HyperSonicDrivers::files size >>= 1; break; default: - utils::throwLogC(std::format("bitsDepth = {}, not supported/implemented", bitsDepth)); + utils::throwLogC(std::format("bitsDepth = {}, not supported/implemented", m_bitsDepth)); break; } m_sound = std::make_shared( group, m_channels == 2, - freq, + m_freq, size, data ); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp index d259899d..e464a879 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp @@ -18,16 +18,16 @@ namespace HyperSonicDrivers::files virtual ~IPCMFile() = default; inline int getChannels() const noexcept { return m_channels; }; - inline uint32_t getSampleRate() const noexcept { return freq; }; - inline uint8_t getBitsDepth() const noexcept { return bitsDepth; }; + inline uint32_t getSampleRate() const noexcept { return m_freq; }; + inline uint8_t getBitsDepth() const noexcept { return m_bitsDepth; }; inline uint32_t getDataSize() const noexcept { return m_dataSize; }; inline std::shared_ptr getData() const noexcept { return m_data; }; inline std::shared_ptr getSound() const noexcept { return m_sound; }; protected: int m_channels = 0; - uint32_t freq = 0; - uint8_t bitsDepth = 0; + uint32_t m_freq = 0; + uint8_t m_bitsDepth = 0; uint32_t m_dataSize = 0; std::shared_ptr m_data; std::shared_ptr m_sound; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp index db8b965d..b6b8f75a 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp @@ -16,7 +16,7 @@ namespace HyperSonicDrivers::files m_version(0) { m_channels = 1; - bitsDepth = 8; + m_bitsDepth = 8; assertValid_(readHeader()); assertValid_(readDataBlockHeader()); @@ -74,9 +74,9 @@ namespace HyperSonicDrivers::files // channels default = 1 // timeConstant = 65536 - (256000000 / (channels * sampleRate); // sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels) - freq = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); + m_freq = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); //m_sampleRate = 1000000 / (256 - timeConstant); - assertValid_(freq == (1000000 / (256 - timeConstant))); + assertValid_(m_freq == (1000000 / (256 - timeConstant))); // pack Method switch (packMethod) { @@ -137,8 +137,8 @@ namespace HyperSonicDrivers::files case 9: // extended 2 { assertValid_(m_version >= 0x0114); - freq = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); - bitsDepth = db.data[4]; + m_freq = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); + m_bitsDepth = db.data[4]; m_channels = db.data[5]; uint16_t format = db.data[6] + (db.data[7] << 8); for (int i = 0; i < 4; i++) @@ -179,7 +179,7 @@ namespace HyperSonicDrivers::files } int divisor = 1; - if (bitsDepth == 16) { + if (m_bitsDepth == 16) { divisor <<= 1; } if (m_channels == 2) { diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp index 45ebdc86..0215db78 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp @@ -173,9 +173,9 @@ namespace HyperSonicDrivers::files // fmt always before data chunk m_expDataChunk = true; - bitsDepth = static_cast(m_fmt_chunk.bitsPerSample); + m_bitsDepth = static_cast(m_fmt_chunk.bitsPerSample); m_channels = m_fmt_chunk.channels; - freq = m_fmt_chunk.samplesPerSec; + m_freq = m_fmt_chunk.samplesPerSec; return true; } From 303e4c271c80006f742da26cb47680e6c4a7214f Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:33:08 +0000 Subject: [PATCH 11/15] revert accidental refactor --- .../src/HyperSonicDrivers/files/IPCMFile.cpp | 2 +- .../src/HyperSonicDrivers/files/IPCMFile.hpp | 4 ++-- .../src/HyperSonicDrivers/files/VOCFile.cpp | 6 +++--- .../src/HyperSonicDrivers/files/WAVFile.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp index 5c5fa78c..e3ff017c 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp @@ -30,7 +30,7 @@ namespace HyperSonicDrivers::files m_sound = std::make_shared( group, m_channels == 2, - m_freq, + m_sampleRate, size, data ); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp index e464a879..cd343b8e 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.hpp @@ -18,7 +18,7 @@ namespace HyperSonicDrivers::files virtual ~IPCMFile() = default; inline int getChannels() const noexcept { return m_channels; }; - inline uint32_t getSampleRate() const noexcept { return m_freq; }; + inline uint32_t getSampleRate() const noexcept { return m_sampleRate; }; inline uint8_t getBitsDepth() const noexcept { return m_bitsDepth; }; inline uint32_t getDataSize() const noexcept { return m_dataSize; }; inline std::shared_ptr getData() const noexcept { return m_data; }; @@ -26,7 +26,7 @@ namespace HyperSonicDrivers::files protected: int m_channels = 0; - uint32_t m_freq = 0; + uint32_t m_sampleRate = 0; uint8_t m_bitsDepth = 0; uint32_t m_dataSize = 0; std::shared_ptr m_data; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp index b6b8f75a..59abe0f2 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp @@ -74,9 +74,9 @@ namespace HyperSonicDrivers::files // channels default = 1 // timeConstant = 65536 - (256000000 / (channels * sampleRate); // sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels) - m_freq = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); + m_sampleRate = 256000000L / ((65536 - (timeConstant << 8)) * m_channels); //m_sampleRate = 1000000 / (256 - timeConstant); - assertValid_(m_freq == (1000000 / (256 - timeConstant))); + assertValid_(m_sampleRate == (1000000 / (256 - timeConstant))); // pack Method switch (packMethod) { @@ -137,7 +137,7 @@ namespace HyperSonicDrivers::files case 9: // extended 2 { assertValid_(m_version >= 0x0114); - m_freq = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); + m_sampleRate = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24); m_bitsDepth = db.data[4]; m_channels = db.data[5]; uint16_t format = db.data[6] + (db.data[7] << 8); diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp index 0215db78..ace1ced6 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/WAVFile.cpp @@ -175,7 +175,7 @@ namespace HyperSonicDrivers::files m_expDataChunk = true; m_bitsDepth = static_cast(m_fmt_chunk.bitsPerSample); m_channels = m_fmt_chunk.channels; - m_freq = m_fmt_chunk.samplesPerSec; + m_sampleRate = m_fmt_chunk.samplesPerSec; return true; } From a10b0c422230df1ede751a722cf07a8c4bea61a8 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:35:09 +0000 Subject: [PATCH 12/15] revert accidental refactor --- .../test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp index b89e8ad2..0684fac0 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/hardware/TestPCSpeaker.cpp @@ -27,7 +27,7 @@ namespace HyperSonicDrivers::hardware FAIL(); } - TEST(PCSpeaker, isActive) + TEST(PCSpeaker, isPlaying) { PCSpeaker pcSpeaker(44100, 8); pcSpeaker.play(PCSpeaker::eWaveForm::SINE, 440, 1); From 321203eeabd49121f1a37d470a8cae91657180a7 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:37:00 +0000 Subject: [PATCH 13/15] code rev --- .../src/HyperSonicDrivers/hardware/IHardware.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp index c3717d13..1533a8c8 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/hardware/IHardware.cpp @@ -6,12 +6,14 @@ namespace HyperSonicDrivers::hardware { IHardware::IHardware(const std::shared_ptr& mixer) : - m_mixer(mixer), m_output_rate(m_mixer->freq) + m_mixer(mixer) { if (m_mixer == nullptr) { utils::throwLogC("mixer is null"); } + + m_output_rate = m_mixer->freq; } IHardware::~IHardware() From 7b5845c54dca71a4df07cdc3af18b426e06d1e77 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 15:44:18 +0000 Subject: [PATCH 14/15] sonarcloud ci rev --- .github/workflows/sonarcloud.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 54918cff..167cf656 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -18,15 +18,15 @@ on: #branches: # - master - pull_request: - # branches: [ master ] - paths-ignore: - - 'doc/**' - - '.gitignore' - - '.gitattributes' - - 'README.md' - - 'LICENSE' - - 'wave_generators.r' + #pull_request: + ## branches: [ master ] + # paths-ignore: + # - 'doc/**' + # - '.gitignore' + # - '.gitattributes' + # - 'README.md' + # - 'LICENSE' + # - 'wave_generators.r' #permissions: read-all From fe17e41d8f5abd8fe3cfc542c5971908dd665519 Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Sun, 12 Nov 2023 16:13:06 +0000 Subject: [PATCH 15/15] sonarcloud code rev --- .../src/HyperSonicDrivers/audio/sdl2/Mixer.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp index f6d98ca0..22a52037 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/sdl2/Mixer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -145,20 +146,16 @@ namespace HyperSonicDrivers::audio::sdl2 { std::scoped_lock lck(m_mutex); - for (const auto& ch : m_channels) - if (!ch->isEnded()) - return true; - - return false; + return std::ranges::any_of(m_channels, [](const auto& ch) + { return !ch->isEnded(); }); } bool Mixer::isActive(const mixer::eChannelGroup group) { std::scoped_lock lck(m_mutex); - for (const auto& ch : m_channels) - if (ch->getChannelGroup() == group && !ch->isEnded()) - return true; + return std::ranges::any_of(m_channels, [group](const auto& ch) + { return ch->getChannelGroup() == group && !ch->isEnded(); }); return false; }