clean up flailing

master
zetaPRIME 2022-03-19 16:43:31 -04:00
parent 6fcc6db4e6
commit 58826188c6
3 changed files with 8 additions and 39 deletions

2
notes
View File

@ -43,8 +43,6 @@ TODO {
filter cutoff preset for knobgadget
force at least 1hz in svfilter for normalization
x retool audio engine for active push
revert-to-saved menu action
distortion effect

View File

@ -109,7 +109,7 @@ void AudioEngine::initAudio(bool startNow) {
output->setObjectName("Xybrid"); // if Qt ever implements naming the stream this way, WE'LL BE READY
//output->setBufferSize(static_cast<int>(sampleRate*4*( 64.0 )/1000.0)); // 64ms seems to be a sweet spot now
connect(output.get(), &QAudioOutput::notify, this, &AudioEngine::processActive);
//
}
if (startNow) startOutput();
@ -128,19 +128,11 @@ void AudioEngine::deinitAudio() {
void AudioEngine::startOutput() {
if (!output) return;
if (activeBuffering) {
outBuf.resize(static_cast<size_t>(4*5*sampleRate/1000));
output->setBufferSize(sampleRate*4*(bufferMs+250)/1000); // allocate extra buffer for safety
output->setNotifyInterval(std::max(1, bufferMs/2));
outStream = output->start();
bufferFill = output->notifyInterval();
assert(bufferFill > 0);
} else {
outBuf.resize(0);
output->setNotifyInterval(0); // don't need this here
output->setBufferSize(sampleRate*4*bufferMs/1000); // set canonical buffer size
output->start(this); // set output to take the active role
}
//outBuf.resize(0);
output->setNotifyInterval(0); // don't need this here
output->setBufferSize(sampleRate*4*bufferMs/1000); // set canonical buffer size
output->start(this); // set output to take the active role
}
void AudioEngine::play(std::shared_ptr<Project> p, int fromPos) {
@ -370,23 +362,6 @@ void AudioEngine::buildQueue() {
queueValid = true;
}
void AudioEngine::processActive() {
if (!output || !activeBuffering) return;
bufferFill -= output->notifyInterval();
qint64 needed = (bufferMs - bufferFill) * sampleRate/1000 * 4;
while (needed > 0) {
auto r = readData(&outBuf[0], std::min(needed, static_cast<qint64>(outBuf.size())));
outStream->write(&outBuf[0], r);
needed -= r;
//enc.write(&dat[0], readData(&dat[0], 1024));
}
bufferFill = bufferMs;
//
}
qint64 AudioEngine::readData(char *data, qint64 maxlen) {
const constexpr qint64 smp = 2;
const constexpr qint64 stride = smp*2;

View File

@ -55,20 +55,17 @@ namespace Xybrid::Audio {
std::unique_ptr<QAudioOutput> output;
QIODevice* outStream;
int sampleRate = 48000;
int bufferMs = 64;
std::vector<float> buffer[2];
size_t bufPos = 0;
//std::vector<char> outBuf;
static const constexpr size_t tickBufSize = (1024*1024*5); // 5mb should be enough
std::unique_ptr<size_t[]> tickBuf;
std::atomic<size_t*> tickBufPtr;
size_t* tickBufEnd;
static const constexpr bool activeBuffering = false;//true;
int bufferMs = 64;
int bufferFill = 0;
std::vector<char> outBuf;
PlaybackMode mode = Stopped;
size_t tickId = 0;
std::shared_ptr<Data::Project> project;
@ -133,7 +130,6 @@ namespace Xybrid::Audio {
void playbackModeChanged();
public slots:
void processActive();
};
class AudioWorker : public QObject, private AudioWorkerCore {