Skip to content

Commit

Permalink
Reuse buffers between function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Jan 6, 2024
1 parent 4c56687 commit 71790e7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/mumble/AudioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static void inMixerFloatMask(float *RESTRICT buffer, const void *RESTRICT ipt, u
const float *RESTRICT input = reinterpret_cast< const float * >(ipt);

unsigned int chancount = 0;
std::vector< unsigned int > chanindex;
static std::vector< unsigned int > chanindex;
chanindex.resize(N);
for (unsigned int j = 0; j < N; ++j) {
if ((mask & (1ULL << j)) == 0) {
Expand All @@ -382,7 +382,7 @@ static void inMixerShortMask(float *RESTRICT buffer, const void *RESTRICT ipt, u
const short *RESTRICT input = reinterpret_cast< const short * >(ipt);

unsigned int chancount = 0;
std::vector< unsigned int > chanindex;
static std::vector< unsigned int > chanindex;
chanindex.resize(N);
for (unsigned int j = 0; j < N; ++j) {
if ((mask & (1ULL << j)) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/mumble/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,16 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) {

// If the audio backend uses a float-array we can sample and mix the audio sources directly into the output.
// Otherwise we'll have to use an intermediate buffer which we will convert to an array of shorts later
std::vector< float > fOutput;
static std::vector< float > fOutput;
fOutput.resize(iChannels * frameCount);
float *output = (eSampleFormat == SampleFloat) ? reinterpret_cast< float * >(outbuff) : fOutput.data();
memset(output, 0, sizeof(float) * frameCount * iChannels);

if (!qlMix.isEmpty()) {
// There are audio sources available -> mix those sources together and feed them into the audio backend
std::vector< float > speaker;
static std::vector< float > speaker;
speaker.resize(iChannels * 3);
std::vector< float > svol;
static std::vector< float > svol;
svol.resize(iChannels);

bool validListener = false;
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/AudioOutputSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool AudioOutputSample::prepareSampleBuffer(unsigned int frameCount) {
/ static_cast< float >(iOutSampleRate)));
unsigned int iInputSamples = iInputFrames * channels;

std::vector< float > fOut;
static std::vector< float > fOut;
fOut.resize(iInputSamples);

bool eof = false;
Expand Down
12 changes: 6 additions & 6 deletions src/mumble/AudioStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ void AudioEchoWidget::paintEvent(QPaintEvent *) {
spx_int32_t sz;
speex_echo_ctl(ai->sesEcho, SPEEX_ECHO_GET_IMPULSE_RESPONSE_SIZE, &sz);

std::vector< spx_int32_t > w;
static std::vector< spx_int32_t > w;
w.resize(static_cast< std::size_t >(sz));
std::vector< float > W;
static std::vector< float > W;
W.resize(static_cast< std::size_t >(sz));

speex_echo_ctl(ai->sesEcho, SPEEX_ECHO_GET_IMPULSE_RESPONSE, w.data());
Expand Down Expand Up @@ -226,9 +226,9 @@ void AudioNoiseWidget::paintEvent(QPaintEvent *) {
spx_int32_t ps_size = 0;
speex_preprocess_ctl(ai->sppPreprocess, SPEEX_PREPROCESS_GET_PSD_SIZE, &ps_size);

std::vector< spx_int32_t > noise;
static std::vector< spx_int32_t > noise;
noise.resize(static_cast< std::size_t >(ps_size));
std::vector< spx_int32_t > ps;
static std::vector< spx_int32_t > ps;
ps.resize(static_cast< std::size_t >(ps_size));

speex_preprocess_ctl(ai->sppPreprocess, SPEEX_PREPROCESS_GET_PSD, ps.data());
Expand Down Expand Up @@ -339,9 +339,9 @@ void AudioStats::on_Tick_timeout() {
spx_int32_t ps_size = 0;
speex_preprocess_ctl(ai->sppPreprocess, SPEEX_PREPROCESS_GET_PSD_SIZE, &ps_size);

std::vector< spx_int32_t > noise;
static std::vector< spx_int32_t > noise;
noise.resize(static_cast< std::size_t >(ps_size));
std::vector< spx_int32_t > ps;
static std::vector< spx_int32_t > ps;
ps.resize(static_cast< std::size_t >(ps_size));

speex_preprocess_ctl(ai->sppPreprocess, SPEEX_PREPROCESS_GET_PSD, ps.data());
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/OSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void OSSOutput::run() {
qWarning("OSSOutput: Starting audio playback to %s", device.constData());

std::size_t blocklen = iOutputBlock * iChannels * sizeof(short);
std::vector< short > mbuffer;
static std::vector< short > mbuffer;
mbuffer.resize(iOutputBlock * iChannels);

while (bRunning) {
Expand Down
4 changes: 2 additions & 2 deletions src/mumble/PulseAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata
pao->eSampleFormat = PulseAudioOutput::SampleShort;
pao->iMixerFreq = pss->rate;
pao->iChannels = pss->channels;
std::vector< unsigned int > chanmasks;
static std::vector< unsigned int > chanmasks;
chanmasks.resize(pss->channels);
for (int i = 0; i < pss->channels; ++i) {
unsigned int cm = 0;
Expand Down Expand Up @@ -652,7 +652,7 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata
const unsigned int samples = static_cast< unsigned int >(bytes) / iSampleSize;
bool oldAttenuation = pas->bAttenuating;

std::vector< unsigned char > buffer;
static std::vector< unsigned char > buffer;
buffer.resize(bytes);
// do we have some mixed output?
if (pao->mix(buffer.data(), samples)) {
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/ServerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void ServerHandler::handleVoicePacket(const Mumble::Protocol::AudioData &audioDa
}

void ServerHandler::sendMessage(const unsigned char *data, int len, bool force) {
std::vector< unsigned char > crypto;
static std::vector< unsigned char > crypto;
crypto.resize(static_cast< std::size_t >(len + 4));

QMutexLocker qml(&qmUdp);
Expand Down
2 changes: 1 addition & 1 deletion src/murmur/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ void Server::sendMessage(ServerUser &u, const unsigned char *data, int len, QByt
if ((u.aiUdpFlag.load() == 1 || force) && (u.sUdpSocket != INVALID_SOCKET)) {
#endif
#if defined(__LP64__)
std::vector< char > ebuffer;
static std::vector< char > ebuffer;
ebuffer.resize(static_cast< std::size_t >(len + 4 + 16));
char *buffer = reinterpret_cast< char * >(
((reinterpret_cast< quint64 >(ebuffer.data()) + 8) & static_cast< quint64 >(~7)) + 4);
Expand Down

0 comments on commit 71790e7

Please sign in to comment.