Stop using basic_string for Sint32. We only use it in one place and it's
a bit of a performance hit there ...
This commit is contained in:
@@ -299,15 +299,27 @@ void RageSoundManager::SetPrefs(float MixVol)
|
|||||||
SoundMixBuffer::SoundMixBuffer()
|
SoundMixBuffer::SoundMixBuffer()
|
||||||
{
|
{
|
||||||
vol = SOUNDMAN->GetMixVolume();
|
vol = SOUNDMAN->GetMixVolume();
|
||||||
|
bufsize = used = 0;
|
||||||
|
mixbuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundMixBuffer::~SoundMixBuffer()
|
||||||
|
{
|
||||||
|
free(mixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundMixBuffer::write(const Sint16 *buf, unsigned size)
|
void SoundMixBuffer::write(const Sint16 *buf, unsigned size)
|
||||||
{
|
{
|
||||||
if(mixbuf.size() < size)
|
if(bufsize < size)
|
||||||
{
|
{
|
||||||
basic_string<Sint32, char_traits_Sint32> empty(size-mixbuf.size(), 0);
|
mixbuf = (Sint32 *) realloc(mixbuf, sizeof(Sint32) * size);
|
||||||
|
bufsize = size;
|
||||||
|
}
|
||||||
|
|
||||||
mixbuf.insert(mixbuf.end(), empty.begin(), empty.end());
|
if(used < size)
|
||||||
|
{
|
||||||
|
memset(mixbuf + used, 0, (size - used) * sizeof(Sint32));
|
||||||
|
used = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned pos = 0; pos < size; ++pos)
|
for(unsigned pos = 0; pos < size; ++pos)
|
||||||
@@ -330,7 +342,7 @@ void SoundMixBuffer::write(const Sint16 *buf, unsigned size)
|
|||||||
|
|
||||||
void SoundMixBuffer::read(Sint16 *buf)
|
void SoundMixBuffer::read(Sint16 *buf)
|
||||||
{
|
{
|
||||||
for(unsigned pos = 0; pos < mixbuf.size(); ++pos)
|
for(unsigned pos = 0; pos < used; ++pos)
|
||||||
{
|
{
|
||||||
/* XXX: dither */
|
/* XXX: dither */
|
||||||
Sint32 out = (mixbuf[pos]) / 32768;
|
Sint32 out = (mixbuf[pos]) / 32768;
|
||||||
@@ -338,5 +350,5 @@ void SoundMixBuffer::read(Sint16 *buf)
|
|||||||
buf[pos] = Sint16(out);
|
buf[pos] = Sint16(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
mixbuf.erase();
|
used = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,16 +68,19 @@ public:
|
|||||||
/* This inputs and outputs 16-bit 44khz stereo input. */
|
/* This inputs and outputs 16-bit 44khz stereo input. */
|
||||||
class SoundMixBuffer
|
class SoundMixBuffer
|
||||||
{
|
{
|
||||||
basic_string<Sint32, char_traits_Sint32> mixbuf;
|
Sint32 *mixbuf;
|
||||||
|
unsigned bufsize; /* actual allocated samples */
|
||||||
|
unsigned used; /* used samples */
|
||||||
float vol;
|
float vol;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void write(const Sint16 *buf, unsigned size);
|
void write(const Sint16 *buf, unsigned size);
|
||||||
void read(Sint16 *buf);
|
void read(Sint16 *buf);
|
||||||
unsigned size() const { return mixbuf.size(); }
|
unsigned size() const { return used; }
|
||||||
void SetVolume(float f);
|
void SetVolume(float f);
|
||||||
|
|
||||||
SoundMixBuffer();
|
SoundMixBuffer();
|
||||||
|
~SoundMixBuffer();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RageSoundManager *SOUNDMAN;
|
extern RageSoundManager *SOUNDMAN;
|
||||||
|
|||||||
@@ -46,28 +46,5 @@ bool SDL_GetEvent(SDL_Event &event, int mask);
|
|||||||
#define TRAIT_WHITE_ONLY 0x0004 /* 8alphaonly */
|
#define TRAIT_WHITE_ONLY 0x0004 /* 8alphaonly */
|
||||||
int FindSurfaceTraits(const SDL_Surface *img);
|
int FindSurfaceTraits(const SDL_Surface *img);
|
||||||
|
|
||||||
struct char_traits_Sint32: public char_traits<Sint32>
|
|
||||||
{
|
|
||||||
static Sint32 *copy(Sint32 *s, const Sint32 *p, size_t n)
|
|
||||||
{
|
|
||||||
memcpy(s, p, n * sizeof(Sint32));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
static Sint32 *move(Sint32 *s, const Sint32 *p, size_t n)
|
|
||||||
{
|
|
||||||
memmove(s, p, n * sizeof(Sint32));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
static Sint32 *assign(Sint32 *s, unsigned cnt, int n)
|
|
||||||
{
|
|
||||||
while(cnt--) *(s++) = n;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
static void assign(Sint32 &c1, Sint32 c2)
|
|
||||||
{
|
|
||||||
c1 = c2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user