Better type choices, comment improvements, adding missing braces, removal of dead code.
This commit is contained in:
@@ -13,7 +13,7 @@ RageSoundMixBuffer::~RageSoundMixBuffer() {}
|
|||||||
* measured in samples, not frames, so if the data is stereo, multiply by two. */
|
* measured in samples, not frames, so if the data is stereo, multiply by two. */
|
||||||
void RageSoundMixBuffer::SetWriteOffset( int iOffset )
|
void RageSoundMixBuffer::SetWriteOffset( int iOffset )
|
||||||
{
|
{
|
||||||
m_iOffset = iOffset;
|
m_iOffset = static_cast<int>(iOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundMixBuffer::Extend(unsigned iSamples)
|
void RageSoundMixBuffer::Extend(unsigned iSamples)
|
||||||
@@ -33,7 +33,7 @@ void RageSoundMixBuffer::write( const float *pBuf, unsigned iSize, int iSourceSt
|
|||||||
// iSize = 3, iDestStride = 2 uses 4 frames. Don't allocate the stride of the last sample.
|
// iSize = 3, iDestStride = 2 uses 4 frames. Don't allocate the stride of the last sample.
|
||||||
Extend( iSize * iDestStride - (iDestStride-1) );
|
Extend( iSize * iDestStride - (iDestStride-1) );
|
||||||
|
|
||||||
// Scale volume and add.
|
// Load the audio at m_iOffset into the buffer.
|
||||||
float *pDestBuf = &m_pMixbuf[m_iOffset];
|
float *pDestBuf = &m_pMixbuf[m_iOffset];
|
||||||
|
|
||||||
while( iSize )
|
while( iSize )
|
||||||
@@ -49,9 +49,12 @@ void RageSoundMixBuffer::read( int16_t *pBuf )
|
|||||||
{
|
{
|
||||||
for (unsigned iPos = 0; iPos < m_pMixbuf.size(); ++iPos)
|
for (unsigned iPos = 0; iPos < m_pMixbuf.size(); ++iPos)
|
||||||
{
|
{
|
||||||
|
// do the read
|
||||||
float iOut = m_pMixbuf[iPos];
|
float iOut = m_pMixbuf[iPos];
|
||||||
|
// ensure volume is within expected levels to prevent clipping
|
||||||
iOut = std::clamp( iOut, -1.0f, +1.0f );
|
iOut = std::clamp( iOut, -1.0f, +1.0f );
|
||||||
pBuf[iPos] = static_cast<int16_t>(iOut * INT16_MAX);
|
// round rather than truncate to minimize distortion
|
||||||
|
pBuf[iPos] = static_cast<int16_t>(std::round(iOut * INT16_MAX));
|
||||||
}
|
}
|
||||||
m_pMixbuf.clear();
|
m_pMixbuf.clear();
|
||||||
}
|
}
|
||||||
@@ -65,8 +68,12 @@ void RageSoundMixBuffer::read( float *pBuf )
|
|||||||
void RageSoundMixBuffer::read_deinterlace( float **pBufs, int channels )
|
void RageSoundMixBuffer::read_deinterlace( float **pBufs, int channels )
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < m_pMixbuf.size() / channels; ++i)
|
for (unsigned i = 0; i < m_pMixbuf.size() / channels; ++i)
|
||||||
|
{
|
||||||
for (int ch = 0; ch < channels; ++ch)
|
for (int ch = 0; ch < channels; ++ch)
|
||||||
|
{
|
||||||
pBufs[ch][i] = m_pMixbuf[channels * i + ch];
|
pBufs[ch][i] = m_pMixbuf[channels * i + ch];
|
||||||
|
}
|
||||||
|
}
|
||||||
m_pMixbuf.clear();
|
m_pMixbuf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ public:
|
|||||||
void read(int16_t* pBuf);
|
void read(int16_t* pBuf);
|
||||||
void read(float* pBuf);
|
void read(float* pBuf);
|
||||||
void read_deinterlace(float** pBufs, int channels);
|
void read_deinterlace(float** pBufs, int channels);
|
||||||
inline int64_t size() const { return m_iBufUsed; }
|
inline size_t size() const { return m_pMixbuf.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<float> m_pMixbuf;
|
std::vector<float> m_pMixbuf;
|
||||||
int64_t m_iBufSize;
|
unsigned m_iOffset;
|
||||||
int64_t m_iBufUsed;
|
|
||||||
int64_t m_iOffset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RAGESOUNDMIXBUFFER_H
|
#endif // RAGESOUNDMIXBUFFER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user