drop usage of std::deque, part 1
use FixedQueue instead
This commit is contained in:
parent
f9c67460ce
commit
8b565ed284
6 changed files with 84 additions and 19 deletions
|
|
@ -37,7 +37,7 @@
|
|||
#include <mutex>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <deque>
|
||||
#include "fixedQueue.h"
|
||||
|
||||
class DivWorkPool;
|
||||
|
||||
|
|
@ -176,14 +176,28 @@ struct DivChannelState {
|
|||
};
|
||||
|
||||
struct DivNoteEvent {
|
||||
int channel, ins, note, volume;
|
||||
bool on;
|
||||
signed char channel;
|
||||
unsigned char ins;
|
||||
signed char note, volume;
|
||||
bool on, nop, pad1, pad2;
|
||||
DivNoteEvent(int c, int i, int n, int v, bool o):
|
||||
channel(c),
|
||||
ins(i),
|
||||
note(n),
|
||||
volume(v),
|
||||
on(o) {}
|
||||
on(o),
|
||||
nop(false),
|
||||
pad1(false),
|
||||
pad2(false) {}
|
||||
DivNoteEvent():
|
||||
channel(-1),
|
||||
ins(0),
|
||||
note(0),
|
||||
volume(0),
|
||||
on(false),
|
||||
nop(true),
|
||||
pad1(false),
|
||||
pad2(false) {}
|
||||
};
|
||||
|
||||
struct DivDispatchContainer {
|
||||
|
|
@ -428,7 +442,7 @@ class DivEngine {
|
|||
DivAudioExportModes exportMode;
|
||||
double exportFadeOut;
|
||||
DivConfig conf;
|
||||
std::deque<DivNoteEvent> pendingNotes;
|
||||
FixedQueue<DivNoteEvent,8192> pendingNotes;
|
||||
// bitfield
|
||||
unsigned char walked[8192];
|
||||
bool isMuted[DIV_MAX_CHANS];
|
||||
|
|
|
|||
|
|
@ -27,11 +27,14 @@ template<typename T, size_t items> struct FixedQueue {
|
|||
size_t readPos, writePos;
|
||||
T data[items];
|
||||
|
||||
T& operator[](size_t pos);
|
||||
T& front();
|
||||
T& back();
|
||||
bool pop();
|
||||
bool push(const T& item);
|
||||
|
||||
bool erase(size_t pos);
|
||||
|
||||
bool pop_front();
|
||||
bool pop_back();
|
||||
bool push_front(const T& item);
|
||||
|
|
@ -44,6 +47,13 @@ template<typename T, size_t items> struct FixedQueue {
|
|||
writePos(0) {}
|
||||
};
|
||||
|
||||
template <typename T, size_t items> T& FixedQueue<T,items>::operator[](size_t pos) {
|
||||
if (pos>=size()) {
|
||||
logW("accessing invalid position. bug!");
|
||||
}
|
||||
return data[(readPos+pos)%items];
|
||||
}
|
||||
|
||||
template <typename T, size_t items> T& FixedQueue<T,items>::front() {
|
||||
return data[readPos];
|
||||
}
|
||||
|
|
@ -53,6 +63,36 @@ template <typename T, size_t items> T& FixedQueue<T,items>::back() {
|
|||
return data[writePos-1];
|
||||
}
|
||||
|
||||
template <typename T, size_t items> bool FixedQueue<T,items>::erase(size_t pos) {
|
||||
size_t curSize=size();
|
||||
if (pos>=curSize) {
|
||||
logW("accessing invalid position. bug!");
|
||||
return false;
|
||||
}
|
||||
if (pos==0) {
|
||||
return pop_front();
|
||||
}
|
||||
if (pos==curSize-1) {
|
||||
return pop_back();
|
||||
}
|
||||
|
||||
for (size_t i=0, p=(readPos+pos)%items, p1=(readPos+pos+1)%items; i<=curSize; i++) {
|
||||
if (p>=items) p-=items;
|
||||
if (p1>=items) p1-=items;
|
||||
data[p]=data[p1];
|
||||
p++;
|
||||
p1++;
|
||||
}
|
||||
|
||||
if (writePos>0) {
|
||||
writePos--;
|
||||
} else {
|
||||
writePos=items-1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, size_t items> bool FixedQueue<T,items>::pop() {
|
||||
if (readPos==writePos) return false;
|
||||
if (++readPos>=items) readPos=0;
|
||||
|
|
|
|||
|
|
@ -1346,8 +1346,8 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
|||
isOn[pendingNotes[i].channel]=true;
|
||||
} else {
|
||||
if (isOn[pendingNotes[i].channel]) {
|
||||
logV("erasing off -> on sequence in %d",pendingNotes[i].channel);
|
||||
pendingNotes.erase(pendingNotes.begin()+i);
|
||||
//logV("erasing off -> on sequence in %d",pendingNotes[i].channel);
|
||||
pendingNotes[i].nop=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1355,7 +1355,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
|||
|
||||
while (!pendingNotes.empty()) {
|
||||
DivNoteEvent& note=pendingNotes.front();
|
||||
if (note.channel<0 || note.channel>=chans) {
|
||||
if (note.nop || note.channel<0 || note.channel>=chans) {
|
||||
pendingNotes.pop_front();
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1847,7 +1847,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
}
|
||||
}
|
||||
}
|
||||
logD("%.2x",msg.type);
|
||||
//logD("%.2x",msg.type);
|
||||
output->midiIn->queue.pop();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "defines.h"
|
||||
#include "safeWriter.h"
|
||||
#include "dataErrors.h"
|
||||
#include <deque>
|
||||
#include "fixedQueue.h"
|
||||
|
||||
enum DivSampleLoopMode: unsigned char {
|
||||
DIV_SAMPLE_LOOP_FORWARD=0,
|
||||
|
|
@ -144,8 +144,8 @@ struct DivSample {
|
|||
|
||||
unsigned int samples;
|
||||
|
||||
std::deque<DivSampleHistory*> undoHist;
|
||||
std::deque<DivSampleHistory*> redoHist;
|
||||
FixedQueue<DivSampleHistory*,128> undoHist;
|
||||
FixedQueue<DivSampleHistory*,128> redoHist;
|
||||
|
||||
/**
|
||||
* put sample data.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue