zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit a99bd918fccbbf15b43126a791d491bc7f331b0e
parent d97deef0132db03d554ecaf9bd974e8caa0a443d
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Sun, 27 Jun 2010 19:27:14 -0400

Alsa: Removing repeated allocation

Interleaving the samples is now done on an array around for the lifetime of the
driver

Diffstat:
Msrc/Nio/AlsaEngine.cpp | 8+++++---
Msrc/Nio/AlsaEngine.h | 5+++--
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/Nio/AlsaEngine.cpp b/src/Nio/AlsaEngine.cpp @@ -2,6 +2,7 @@ AlsaEngine.cpp Copyright 2009, Alan Calvert + 2010, Mark McCurry This file is part of ZynAddSubFX, which is free software: you can redistribute it and/or modify it under the terms of the GNU General @@ -31,6 +32,7 @@ using namespace std; AlsaEngine::AlsaEngine() :AudioOut() { + audio.buffer = new short[SOUND_BUFFER_SIZE*2]; name = "ALSA"; audio.handle = NULL; @@ -43,6 +45,7 @@ AlsaEngine::AlsaEngine() AlsaEngine::~AlsaEngine() { Stop(); + delete[] audio.buffer; } void *AlsaEngine::_AudioThread(void *arg) @@ -230,10 +233,10 @@ void AlsaEngine::stopMidi() snd_seq_close(handle); } -const short *AlsaEngine::interleave(const Stereo<REALTYPE *> smps)const +short *AlsaEngine::interleave(const Stereo<REALTYPE *> smps) { /**\todo TODO fix repeated allocation*/ - short *shortInterleaved = new short[bufferSize*2]; + short *shortInterleaved = audio.buffer; memset(shortInterleaved,0,bufferSize*2*sizeof(short)); int idx = 0;//possible off by one error here double scaled; @@ -340,7 +343,6 @@ void *AlsaEngine::processAudio() snd_pcm_t *handle = audio.handle; if(handle) rc = snd_pcm_writei(handle, audio.buffer, SOUND_BUFFER_SIZE); - delete[] audio.buffer; if (rc == -EPIPE) { /* EPIPE means underrun */ cerr << "underrun occurred" << endl; diff --git a/src/Nio/AlsaEngine.h b/src/Nio/AlsaEngine.h @@ -2,6 +2,7 @@ AlsaEngine.h Copyright 2009, Alan Calvert + 2010, Mark McCurry This file is part of ZynAddSubFX, which is free software: you can redistribute it and/or modify it under the terms of the GNU General @@ -56,7 +57,7 @@ class AlsaEngine : public AudioOut, MidiIn bool openAudio(); void stopAudio(); - const short *interleave(const Stereo<REALTYPE *> smps) const; + short *interleave(const Stereo<REALTYPE *> smps); struct { std::string device; @@ -71,7 +72,7 @@ class AlsaEngine : public AudioOut, MidiIn unsigned int sampleRate; snd_pcm_uframes_t frames; unsigned int periods; - const short *buffer; + short *buffer; pthread_t pThread; } audio;