cleanup
This commit is contained in:
@@ -1,60 +1,58 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "RageSoundMixBuffer.h"
|
#include "RageSoundMixBuffer.h"
|
||||||
#include "RageSoundManager.h"
|
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
|
|
||||||
RageSoundMixBuffer::RageSoundMixBuffer()
|
RageSoundMixBuffer::RageSoundMixBuffer()
|
||||||
{
|
{
|
||||||
bufsize = used = 0;
|
m_iBufSize = m_iBufUsed = 0;
|
||||||
mixbuf = NULL;
|
m_pMixbuf = NULL;
|
||||||
if( SOUNDMAN != NULL )
|
m_iOffset = 0;
|
||||||
SetVolume( SOUNDMAN->GetMixVolume() );
|
|
||||||
else
|
|
||||||
SetVolume( 1.0f );
|
SetVolume( 1.0f );
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSoundMixBuffer::~RageSoundMixBuffer()
|
RageSoundMixBuffer::~RageSoundMixBuffer()
|
||||||
{
|
{
|
||||||
free(mixbuf);
|
free( m_pMixbuf );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundMixBuffer::SetVolume( float f )
|
void RageSoundMixBuffer::SetVolume( float f )
|
||||||
{
|
{
|
||||||
vol = int(256*f);
|
m_iVolumeFactor = int(256*f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundMixBuffer::write( const int16_t *buf, unsigned size, float volume, int offset )
|
void RageSoundMixBuffer::SetWriteOffset( int iOffset )
|
||||||
{
|
{
|
||||||
int factor = vol;
|
m_iOffset = iOffset;
|
||||||
if( volume != -1 )
|
|
||||||
factor = int( 256*volume );
|
|
||||||
|
|
||||||
const unsigned realsize = size+offset;
|
|
||||||
if( bufsize < realsize )
|
|
||||||
{
|
|
||||||
mixbuf = (int32_t *) realloc( mixbuf, sizeof(int32_t) * realsize );
|
|
||||||
bufsize = realsize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( used < realsize )
|
void RageSoundMixBuffer::write( const int16_t *buf, unsigned size )
|
||||||
{
|
{
|
||||||
memset( mixbuf + used, 0, (realsize - used) * sizeof(int32_t) );
|
const unsigned realsize = size+m_iOffset;
|
||||||
used = realsize;
|
if( m_iBufSize < realsize )
|
||||||
|
{
|
||||||
|
m_pMixbuf = (int32_t *) realloc( m_pMixbuf, sizeof(int32_t) * realsize );
|
||||||
|
m_iBufSize = realsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_iBufUsed < realsize )
|
||||||
|
{
|
||||||
|
memset( m_pMixbuf + m_iBufUsed, 0, (realsize - m_iBufUsed) * sizeof(int32_t) );
|
||||||
|
m_iBufUsed = realsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scale volume and add. */
|
/* Scale volume and add. */
|
||||||
for( unsigned pos = 0; pos < size; ++pos )
|
for( unsigned pos = 0; pos < size; ++pos )
|
||||||
mixbuf[pos+offset] += buf[pos] * factor;
|
m_pMixbuf[pos+m_iOffset] += buf[pos] * m_iVolumeFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundMixBuffer::read( int16_t *buf )
|
void RageSoundMixBuffer::read( int16_t *buf )
|
||||||
{
|
{
|
||||||
for( unsigned pos = 0; pos < used; ++pos )
|
for( unsigned pos = 0; pos < m_iBufUsed; ++pos )
|
||||||
{
|
{
|
||||||
int32_t out = (mixbuf[pos]) / 256;
|
int32_t out = (m_pMixbuf[pos]) / 256;
|
||||||
buf[pos] = (int16_t) clamp( out, -32768, 32767 );
|
buf[pos] = (int16_t) clamp( out, -32768, 32767 );
|
||||||
}
|
}
|
||||||
used = 0;
|
m_iBufUsed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundMixBuffer::read( float *buf )
|
void RageSoundMixBuffer::read( float *buf )
|
||||||
@@ -62,10 +60,10 @@ void RageSoundMixBuffer::read( float *buf )
|
|||||||
const int Minimum = -32768 * 256;
|
const int Minimum = -32768 * 256;
|
||||||
const int Maximum = 32767 * 256;
|
const int Maximum = 32767 * 256;
|
||||||
|
|
||||||
for( unsigned pos = 0; pos < used; ++pos )
|
for( unsigned pos = 0; pos < m_iBufUsed; ++pos )
|
||||||
buf[pos] = SCALE( (float)mixbuf[pos], Minimum, Maximum, -1.0f, 1.0f );
|
buf[pos] = SCALE( (float)m_pMixbuf[pos], Minimum, Maximum, -1.0f, 1.0f );
|
||||||
|
|
||||||
used = 0;
|
m_iBufUsed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -5,20 +5,23 @@
|
|||||||
|
|
||||||
class RageSoundMixBuffer
|
class RageSoundMixBuffer
|
||||||
{
|
{
|
||||||
int32_t *mixbuf;
|
|
||||||
unsigned bufsize; /* actual allocated samples */
|
|
||||||
unsigned used; /* used samples */
|
|
||||||
int vol; /* vol * 256 */
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void write( const int16_t *buf, unsigned size, float volume = -1, int offset = 0 );
|
void write( const int16_t *buf, unsigned size );
|
||||||
void read(int16_t *buf);
|
void read( int16_t *pBuf );
|
||||||
void read( float *buf );
|
void read( float *pBuf );
|
||||||
unsigned size() const { return used; }
|
unsigned size() const { return m_iBufUsed; }
|
||||||
void SetVolume( float f );
|
void SetVolume( float f );
|
||||||
|
void SetWriteOffset( int iOffset );
|
||||||
|
|
||||||
RageSoundMixBuffer();
|
RageSoundMixBuffer();
|
||||||
~RageSoundMixBuffer();
|
~RageSoundMixBuffer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int32_t *m_pMixbuf;
|
||||||
|
unsigned m_iBufSize; /* actual allocated samples */
|
||||||
|
unsigned m_iBufUsed; /* used samples */
|
||||||
|
int m_iVolumeFactor; /* vol * 256 */
|
||||||
|
int m_iOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user