Skip to content

Commit

Permalink
fix rounding in audio engine, fix optimization bug in scheduler (#2310)
Browse files Browse the repository at this point in the history
* fix rounding in audio engine, fix optimization bug in scheduler

* fix test build

* fix test build for latest gcc

* init to valid value

* fix format

* remove debug prints
  • Loading branch information
m-m-adams authored Jul 20, 2024
1 parent 4f36e03 commit 9a7a623
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/OSLikeStuff/task_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <algorithm>
#include <iostream>

#if !IN_UNIT_TESTS
#include "memory/general_memory_allocator.h"
#endif

extern "C" {
#include "RZA1/ostm/ostm.h"
}
Expand Down Expand Up @@ -145,12 +149,13 @@ struct TaskManager {
double getLastRunTimeforCurrentTask();

private:
TaskID currentID;
TaskID currentID{0};
// for time tracking with rollover
double lastTime{0};
double runningTime{0};
void resetStats();
bool countThisTask{true};
// needs to be volatile, GCC misses that the handle call can call ignoreForStats and optimizes the check away
volatile bool countThisTask{true};
void startClock();
};

Expand Down Expand Up @@ -339,6 +344,9 @@ bool TaskManager::yield(RunCondition until, double timeout) {
if (!running) [[unlikely]] {
startClock();
}
#if !IN_UNIT_TESTS
GeneralMemoryAllocator::get().checkStack("ensure resizeable space");
#endif
auto yieldingTask = &list[currentID];
auto yieldingID = currentID;
bool taskRemoved = false;
Expand Down Expand Up @@ -380,10 +388,9 @@ bool TaskManager::yield(RunCondition until, double timeout) {
} while (!until() && (skipTimeout || getSecondsFromStart() < timeNow + timeout));
if (!taskRemoved) {

auto timeNow = getSecondsFromStart();
yieldingTask->lastCallTime = timeNow; // hack so the time spent yielding doesn't get counted
auto finishTime = getSecondsFromStart();
yieldingTask->lastCallTime = finishTime; // hack so it won't get called again immediately
}

return (getSecondsFromStart() < timeNow + timeout);
}

Expand Down
4 changes: 2 additions & 2 deletions src/deluge/memory/general_memory_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void GeneralMemoryAllocator::checkStack(char const* caller) {
int32_t distance = (int32_t)&a - (uint32_t)&program_stack_start;
if (distance < closestDistance) {
closestDistance = distance;
D_PRINT("%d bytes in stack %d free bytes in stack at %x", (uint32_t)&program_stack_end - (int32_t)&a, distance,
caller);
D_PRINTLN("%d bytes in stack %d free bytes in stack at %s", (uint32_t)&program_stack_end - (int32_t)&a,
distance, caller);

if (distance < 200) {
FREEZE_WITH_ERROR("E338");
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/processing/engines/audio_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ inline void cullVoices(size_t numSamples, int32_t numAudio, int32_t numVoice) {
/// set the direness level and cull any voices
inline void setDireness(size_t numSamples) { // Consider direness and culling - before increasing the number of samples
// number of samples it took to do the last render
auto dspTime = (size_t)(getLastRunTimeforCurrentTask() * 44100.);
auto dspTime = (int32_t)(getLastRunTimeforCurrentTask() * 44100.);
size_t nonDSP = numSamples - dspTime;
// we don't care about the number that were rendered in the last go, only the ones taken by the first routine call
numSamples = dspTime - numRoutines * numSamples;
numSamples = std::max<int32_t>(dspTime - (int32_t)(numRoutines * numSamples), 0);

// don't smooth this - used for other decisions as well
if (numSamples >= direnessThreshold) {
Expand Down
1 change: 1 addition & 0 deletions src/deluge/util/container/static_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
//
//===----------------------------------------------------------------------===//
//
#include <algorithm>
#include <array>
#include <cstddef> // for size_t
#include <cstdint> // for fixed-width integer types
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ if (WIN32 AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Gcc")
set(CPPUTEST_PLATFORM VisualCpp)
endif()

set(DELUGE_C_STANDARD 23)
set(DELUGE_CXX_STANDARD 23)

enable_testing()
#needs to support -m32 since the memory tests assume a 32 bit architecture
if (UNIX AND NOT APPLE)
Expand Down

0 comments on commit 9a7a623

Please sign in to comment.