Skip to content

Commit

Permalink
Prepare for the further adding of the gaining setting
Browse files Browse the repository at this point in the history
(to adjust the general volume)
  • Loading branch information
Wohlstand committed Oct 16, 2024
1 parent a34c310 commit 8768173
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/opl/chips/opl_chip_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class OPLChipBase
virtual void nativePreGenerate() = 0;
virtual void nativePostGenerate() = 0;
virtual void nativeGenerate(int16_t *frame) = 0;
virtual void resampledGenerate(int32_t *frame) = 0;

virtual void generate(int16_t *output, size_t frames) = 0;
virtual void generateAndMix(int16_t *output, size_t frames) = 0;
Expand Down
30 changes: 28 additions & 2 deletions src/opl/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,9 +2009,35 @@ void Generator::updateChannelManager()
void Generator::generate(int16_t *frames, unsigned nframes)
{
chip->generate(frames, nframes);
// 2x Gain by default
// Gain by default
for(size_t i = 0; i < nframes * 2; ++i)
frames[i] *= 2;
frames[i] *= m_gain;
}

void Generator::generate(float* frames, unsigned int nframes)
{
int32_t out[2];

chip->nativePreGenerate();

for(unsigned int i = 0; i < nframes; ++i)
{
chip->resampledGenerate(out);
*frames++ = (out[1] / 32767.0f) * m_gain;
*frames++ = (out[2] / 32767.0f) * m_gain;
}

chip->nativePostGenerate();
}

void Generator::setGain(float gain)
{
m_gain = gain;
}

float Generator::getGain() const
{
return m_gain;
}

Generator::NotesManager::NotesManager()
Expand Down
7 changes: 7 additions & 0 deletions src/opl/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class Generator
void switchChip(OPL_Chips chipId);

void generate(int16_t *frames, unsigned nframes);
void generate(float *frames, unsigned nframes);

void setGain(float gain);
float getGain() const;

/**
* @brief Set the tone frequency on the chip channel and turn note on
Expand Down Expand Up @@ -243,6 +247,9 @@ class Generator

uint32_t m_rate = 44100;

//! Adjust the volume of the output to not be too quite
float m_gain = 2.0f;

struct OPLChipDelete { void operator()(OPLChipBase *); };
std::unique_ptr<OPLChipBase, OPLChipDelete> chip;
OPLChipBase::ChipType m_chipType = OPLChipBase::CHIPTYPE_OPL3;
Expand Down

0 comments on commit 8768173

Please sign in to comment.