Compare commits
3 Commits
7a78ec1b60
...
2ca5856800
Author | SHA1 | Date |
---|---|---|
tildearrow | 2ca5856800 | |
tildearrow | 60df7e26f4 | |
tildearrow | ab7b26a2e7 |
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* Furnace Tracker - multi-system chiptune tracker
|
||||||
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "workPool.h"
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* Furnace Tracker - multi-system chiptune tracker
|
||||||
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WORKPOOL_H
|
||||||
|
#define _WORKPOOL_H
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <functional>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
struct DivWorkThread {
|
||||||
|
std::mutex lock;
|
||||||
|
std::thread* thread;
|
||||||
|
std::condition_variable notify;
|
||||||
|
bool busy, terminate;
|
||||||
|
|
||||||
|
void run();
|
||||||
|
DivWorkThread():
|
||||||
|
busy(false) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this class provides an implementation of a "thread pool" for executing tasks in parallel.
|
||||||
|
* it is highly recommended to use `new` when allocating a DivWorkPool.
|
||||||
|
*/
|
||||||
|
class DivWorkPool {
|
||||||
|
DivWorkThread* workThreads;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* push a new job to this work pool.
|
||||||
|
* if all work threads are busy, this will block until one is free.
|
||||||
|
*/
|
||||||
|
bool push();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether this work pool is busy.
|
||||||
|
*/
|
||||||
|
bool busy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wait for all work threads to finish.
|
||||||
|
*/
|
||||||
|
bool wait();
|
||||||
|
|
||||||
|
DivWorkPool(unsigned int threads=0);
|
||||||
|
~DivWorkPool();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -500,14 +500,20 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
fft->outBuf[1][1]=0;
|
fft->outBuf[1][1]=0;
|
||||||
fftw_execute(fft->planI);
|
fftw_execute(fft->planI);
|
||||||
|
|
||||||
|
// window
|
||||||
|
for (int j=0; j<(FURNACE_FFT_SIZE>>1); j++) {
|
||||||
|
fft->corrBuf[j]*=1.0-((double)j/(double)(FURNACE_FFT_SIZE<<1));
|
||||||
|
}
|
||||||
|
|
||||||
// find size of period
|
// find size of period
|
||||||
double waveLen=FURNACE_FFT_SIZE-1;
|
double waveLen=FURNACE_FFT_SIZE-1;
|
||||||
double waveLenCandL=DBL_MAX;
|
double waveLenCandL=DBL_MAX;
|
||||||
double waveLenCandH=DBL_MIN;
|
double waveLenCandH=DBL_MIN;
|
||||||
int waveLenBottom=0;
|
int waveLenBottom=0;
|
||||||
|
int waveLenTop=0;
|
||||||
|
|
||||||
// find lowest point
|
// find lowest point
|
||||||
for (int j=(FURNACE_FFT_SIZE>>1); j>2; j--) {
|
for (int j=(FURNACE_FFT_SIZE>>2); j>2; j--) {
|
||||||
if (fft->corrBuf[j]<waveLenCandL) {
|
if (fft->corrBuf[j]<waveLenCandL) {
|
||||||
waveLenCandL=fft->corrBuf[j];
|
waveLenCandL=fft->corrBuf[j];
|
||||||
waveLenBottom=j;
|
waveLenBottom=j;
|
||||||
|
@ -515,27 +521,28 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// find highest point
|
// find highest point
|
||||||
for (int j=(FURNACE_FFT_SIZE>>1); j>waveLenBottom; j--) {
|
for (int j=(FURNACE_FFT_SIZE>>1)-1; j>waveLenBottom; j--) {
|
||||||
if (fft->corrBuf[j]>waveLenCandH) {
|
if (fft->corrBuf[j]>waveLenCandH) {
|
||||||
waveLenCandH=fft->corrBuf[j];
|
waveLenCandH=fft->corrBuf[j];
|
||||||
waveLen=j;
|
waveLen=j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
waveLenTop=waveLen;
|
||||||
|
|
||||||
// did we find the period size?
|
// did we find the period size?
|
||||||
if (waveLen<(FURNACE_FFT_SIZE-32)) {
|
if (waveLen<(FURNACE_FFT_SIZE-32)) {
|
||||||
waveLen*=(double)displaySize*2.0/(double)FURNACE_FFT_SIZE;
|
|
||||||
|
|
||||||
// we got pitch
|
// we got pitch
|
||||||
chanOscPitch[ch]=1.0-pow(waveLen/(double)(FURNACE_FFT_SIZE>>1),2.0);
|
chanOscPitch[ch]=pow(1.0-(waveLen/(double)(FURNACE_FFT_SIZE>>1)),4.0);
|
||||||
|
|
||||||
|
waveLen*=(double)displaySize*2.0/(double)FURNACE_FFT_SIZE;
|
||||||
|
|
||||||
// DFT of one period (x_1)
|
// DFT of one period (x_1)
|
||||||
double dft[2];
|
double dft[2];
|
||||||
dft[0]=0.0;
|
dft[0]=0.0;
|
||||||
dft[1]=0.0;
|
dft[1]=0.0;
|
||||||
for (int j=0; j<waveLen; j++) {
|
for (int j=needlePos-1-(displaySize>>1)-(int)waveLen, k=0; k<waveLen; j++, k++) {
|
||||||
double one=((double)buf->data[(unsigned short)(needlePos-((int)waveLen)+j)&0xffff]/32768.0);
|
double one=((double)buf->data[j&0xffff]/32768.0);
|
||||||
double two=(double)j*(-2.0*M_PI)/waveLen;
|
double two=(double)k*(-2.0*M_PI)/waveLen;
|
||||||
dft[0]+=one*cos(two);
|
dft[0]+=one*cos(two);
|
||||||
dft[1]+=one*sin(two);
|
dft[1]+=one*sin(two);
|
||||||
}
|
}
|
||||||
|
@ -545,26 +552,66 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
|
|
||||||
if (chanOscWaveCorr) {
|
if (chanOscWaveCorr) {
|
||||||
needlePos-=phase*waveLen;
|
needlePos-=phase*waveLen;
|
||||||
needlePos-=(2*waveLen-fmod(displaySize,waveLen*2))*0.5;
|
//needlePos-=(2*waveLen-fmod(displaySize,waveLen*2))*0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FFT debug code!
|
||||||
|
if (debugFFT) {
|
||||||
|
double maxavg=0.0;
|
||||||
|
for (unsigned short j=0; j<(FURNACE_FFT_SIZE>>1); j++) {
|
||||||
|
if (fabs(fft->corrBuf[j]>maxavg)) {
|
||||||
|
maxavg=fabs(fft->corrBuf[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxavg>0.0000001) maxavg=0.5/maxavg;
|
||||||
|
|
||||||
|
for (unsigned short j=0; j<precision; j++) {
|
||||||
|
float x=(float)j/(float)precision;
|
||||||
|
float y=fft->corrBuf[(j*FURNACE_FFT_SIZE)/precision]*maxavg;
|
||||||
|
if (j>=precision/2) {
|
||||||
|
y=fft->inBuf[((j-(precision/2))*FURNACE_FFT_SIZE*2)/(precision)];
|
||||||
|
}
|
||||||
|
|
||||||
|
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
|
||||||
|
}
|
||||||
|
String cPhase=fmt::sprintf("\n%.1f (b: %d t: %d)",waveLen,waveLenBottom,waveLenTop);
|
||||||
|
dl->AddText(inRect.Min,0xffffffff,cPhase.c_str());
|
||||||
|
|
||||||
|
dl->AddLine(
|
||||||
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)waveLenBottom/(double)FURNACE_FFT_SIZE,0.0)),
|
||||||
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)waveLenBottom/(double)FURNACE_FFT_SIZE,1.0)),
|
||||||
|
0xffffff00
|
||||||
|
);
|
||||||
|
dl->AddLine(
|
||||||
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)waveLenTop/(double)FURNACE_FFT_SIZE,0.0)),
|
||||||
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)waveLenTop/(double)FURNACE_FFT_SIZE,1.0)),
|
||||||
|
0xff00ff00
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (debugFFT) {
|
||||||
|
dl->AddText(inRect.Min,0xffffffff,"\nquiet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
needlePos-=displaySize;
|
if (!debugFFT || !loudEnough) {
|
||||||
for (unsigned short j=0; j<precision; j++) {
|
needlePos-=displaySize;
|
||||||
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
|
for (unsigned short j=0; j<precision; j++) {
|
||||||
if (minLevel>y) minLevel=y;
|
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
|
||||||
if (maxLevel<y) maxLevel=y;
|
if (minLevel>y) minLevel=y;
|
||||||
}
|
if (maxLevel<y) maxLevel=y;
|
||||||
dcOff=(minLevel+maxLevel)*0.5f;
|
}
|
||||||
for (unsigned short j=0; j<precision; j++) {
|
dcOff=(minLevel+maxLevel)*0.5f;
|
||||||
float x=(float)j/(float)precision;
|
for (unsigned short j=0; j<precision; j++) {
|
||||||
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
|
float x=(float)j/(float)precision;
|
||||||
y-=dcOff;
|
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
|
||||||
if (y<-0.5f) y=-0.5f;
|
y-=dcOff;
|
||||||
if (y>0.5f) y=0.5f;
|
if (y<-0.5f) y=-0.5f;
|
||||||
y*=chanOscAmplify;
|
if (y>0.5f) y=0.5f;
|
||||||
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
|
y*=chanOscAmplify;
|
||||||
|
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImU32 color=ImGui::GetColorU32(chanOscColor);
|
ImU32 color=ImGui::GetColorU32(chanOscColor);
|
||||||
|
@ -693,9 +740,6 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||||
chanOscOptions=!chanOscOptions;
|
chanOscOptions=!chanOscOptions;
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
|
|
||||||
debugFFT=!debugFFT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,6 +212,7 @@ void FurnaceGUI::drawDebug() {
|
||||||
}
|
}
|
||||||
if (ImGui::TreeNode("Oscilloscope Debug")) {
|
if (ImGui::TreeNode("Oscilloscope Debug")) {
|
||||||
int c=0;
|
int c=0;
|
||||||
|
ImGui::Checkbox("FFT debug view",&debugFFT);
|
||||||
for (int i=0; i<e->song.systemLen; i++) {
|
for (int i=0; i<e->song.systemLen; i++) {
|
||||||
DivSystem system=e->song.system[i];
|
DivSystem system=e->song.system[i];
|
||||||
if (e->getChannelCount(system)>0) {
|
if (e->getChannelCount(system)>0) {
|
||||||
|
|
Loading…
Reference in New Issue