Skip to content

Commit

Permalink
code rev
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Nov 11, 2023
1 parent df426cf commit 9a59385
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 10 additions & 10 deletions sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ namespace HyperSonicDrivers::files
{
void IPCMFile::make_pcm_sound_(const audio::mixer::eChannelGroup group)
{
if (m_channels > 2)
utils::throwLogC<std::runtime_error>(std::format("only mono or stereo PCM files are supported (num_channels = {})", m_channels));

std::shared_ptr<int16_t[]> data;
uint32_t size = getDataSize();
uint32_t size = m_dataSize;

switch (getBitsDepth())
switch (m_bitsDepth)
{
case 8:
data.reset(audio::converters::convert8to16(getData().get(), size));
data.reset(audio::converters::convert8to16(m_data.get(), size));
break;
case 16:
data = std::reinterpret_pointer_cast<int16_t[]>(getData());
data = std::reinterpret_pointer_cast<int16_t[]>(m_data);
size >>= 1;
break;
default:
utils::throwLogC<std::invalid_argument>(std::format("bitsDepth = {}, not supported/implemented", getBitsDepth()));
utils::throwLogC<std::invalid_argument>(std::format("bitsDepth = {}, not supported/implemented", m_bitsDepth));
break;
}

if (getChannels() > 2)
utils::throwLogC<std::runtime_error>(std::format("only mono or stereo PCM files are supported (num_channels = {})", getChannels()));

m_sound = std::make_shared<audio::PCMSound>(
group,
getChannels() == 2,
getSampleRate(),
m_channels == 2,
m_sampleRate,
size,
data
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ namespace HyperSonicDrivers::files

int divisor = 1;
if (m_bitsDepth == 16) {
divisor *= 2;
divisor << 1;
}
if (m_channels == 2) {
divisor *= 2;
divisor << 1;
}

const int d = buf.size() % divisor;
for (int i = 0; i < d; i++)
buf.push_back(0);

if (buf.size() % 2 == 1)
buf.push_back(0);

m_dataSize = static_cast<uint32_t>(buf.size());
m_data = std::make_shared<uint8_t[]>(m_dataSize);
std::memcpy(m_data.get(), buf.data(), sizeof(uint8_t)* m_dataSize);
Expand Down

0 comments on commit 9a59385

Please sign in to comment.