Skip to content

Commit 5bdb09e

Browse files
committed
Implemented multithreading class and corresponding render function, since python threading module doesn't lead to improved runtime
1 parent 0fe3a45 commit 5bdb09e

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

Builds/VisualStudio2019/DawDreamer_DynamicLibrary.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,7 @@ copy "..\..\thirdparty\libfaust\win-x64\Release\bin\faust.dll" "$(pythonLocation
24832483
<ClCompile Include="..\..\JuceLibraryCode\include_juce_gui_extra.cpp" />
24842484
<ClCompile Include="..\..\JuceLibraryCode\include_juce_opengl.cpp" />
24852485
<ClCompile Include="..\..\JuceLibraryCode\include_juce_video.cpp" />
2486+
<ClCompile Include="MultiThread.cpp" />
24862487
</ItemGroup>
24872488
<ItemGroup>
24882489
<ClInclude Include="..\..\thirdparty\libsamplerate\include\samplerate.h" />
@@ -3535,6 +3536,7 @@ copy "..\..\thirdparty\libfaust\win-x64\Release\bin\faust.dll" "$(pythonLocation
35353536
<ClInclude Include="..\..\JuceLibraryCode\AppConfig.h" />
35363537
<ClInclude Include="..\..\JuceLibraryCode\BinaryData.h" />
35373538
<ClInclude Include="..\..\JuceLibraryCode\JuceHeader.h" />
3539+
<ClInclude Include="MultiThread.h" />
35383540
</ItemGroup>
35393541
<ItemGroup>
35403542
<None Include="..\..\thirdparty\rubberband\src\kissfft\COPYING" />

Builds/VisualStudio2019/DawDreamer_DynamicLibrary.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,9 @@
30903090
<ClCompile Include="..\..\JuceLibraryCode\include_juce_video.cpp">
30913091
<Filter>JUCE Library Code</Filter>
30923092
</ClCompile>
3093+
<ClCompile Include="MultiThread.cpp">
3094+
<Filter>DawDreamer</Filter>
3095+
</ClCompile>
30933096
</ItemGroup>
30943097
<ItemGroup>
30953098
<ClInclude Include="..\..\thirdparty\libsamplerate\include\samplerate.h">
@@ -6242,6 +6245,9 @@
62426245
<ClInclude Include="..\..\JuceLibraryCode\JuceHeader.h">
62436246
<Filter>JUCE Library Code</Filter>
62446247
</ClInclude>
6248+
<ClInclude Include="MultiThread.h">
6249+
<Filter>DawDreamer</Filter>
6250+
</ClInclude>
62456251
</ItemGroup>
62466252
<ItemGroup>
62476253
<None Include="..\..\thirdparty\rubberband\src\kissfft\COPYING">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "MultiThread.h"
2+
3+
py::list MultiThread::render(float duration, py::list engineList) {
4+
auto func = static_cast<bool (RenderEngine::*)(double, bool)>(&RenderEngine::render);
5+
6+
std::vector<RenderEngine*> engines;
7+
std::vector<std::thread> threads;
8+
for (size_t i = 0; i < py::len(engineList); i++) {
9+
engines.push_back(engineList[i].cast<RenderEngine*>());
10+
threads.push_back(std::thread(func, engines.back(), duration, false));
11+
}
12+
13+
for (auto& thread : threads) {
14+
thread.join();
15+
}
16+
17+
py::list audios;
18+
for (auto& engine : engines) {
19+
audios.append(engine->getAudioFrames());
20+
}
21+
22+
return audios;
23+
}

Builds/VisualStudio2019/MultiThread.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "../../../Source/RenderEngine.h"
4+
5+
class MultiThread {
6+
public:
7+
MultiThread() {}
8+
9+
py::list render(float duration, py::list engines);
10+
};

Source/source.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "FaustBoxAPI.h"
22
#include "FaustSignalAPI.h"
3-
#include "RenderEngine.h"
3+
#include "../Builds/VisualStudio2019/MultiThread.h"
44

55
PYBIND11_MODULE(dawdreamer, m) {
66
using arg = py::arg;
@@ -485,6 +485,12 @@ Unlike a VST, the parameters don't need to be between 0 and 1. For example, you
485485

486486
py::return_value_policy returnPolicy = py::return_value_policy::reference;
487487

488+
py::class_<MultiThread>(
489+
m, "MultiThread",
490+
"The multithread class manages multithreaded processes.")
491+
.def(py::init<>())
492+
.def("render", &MultiThread::render, arg("duration"), arg("engines"), "Render for multiple engines synchronously.");
493+
488494
py::class_<RenderEngine>(
489495
m, "RenderEngine",
490496
"A Render Engine loads and runs a graph of audio processors.")

0 commit comments

Comments
 (0)