Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: ['**']
pull_request:
branches: ['**']

jobs:
build:
name: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install deps (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cmake ninja-build pkg-config \
qt6-base-dev libsndfile1-dev

- name: Install deps (macOS)
if: runner.os == 'macOS'
run: |
brew update
brew install cmake ninja qt6 libsndfile

- name: Configure
run: |
cmake -G Ninja -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH="$(brew --prefix qt6 2>/dev/null || echo /usr)"

- name: Build
run: cmake --build build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/build/
2 changes: 1 addition & 1 deletion OpenAudioNetwork
48 changes: 10 additions & 38 deletions engine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,7 @@

#include "OpenAudioNetwork/common/AudioRouter.h"
#include "OpenAudioNetwork/common/ClockMaster.h"

#include "linux/sched.h"

void set_thread_realtime(uint8_t prio) {
sched_param sparams{};
sparams.sched_priority = prio;

if (sched_setscheduler(0, SCHED_FIFO, &sparams) == -1) {
std::cerr << "Failed to set thread realtime..." << std::endl;
}
}

void set_running_cpu(int cpu_id) {
cpu_set_t cs{};
CPU_ZERO(&cs);
CPU_SET(cpu_id, &cs);

if (sched_setaffinity(0, sizeof(cpu_set_t), &cs) != 0) {
std::cerr << "Failed to set affinity..." << std::endl;
}
}
#include <OpenAudioNetwork/netutils/rt.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: OAN is a "local" library, not a system one, so it should use quotes instead of brackets

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, understood. Is this a project preference or a general C++ thing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More a general cpp thing. But it is just styling, it doesn't change anything regarding functionality


int main(int argc, char* argv[]) {

Expand Down Expand Up @@ -121,30 +101,26 @@ int main(int argc, char* argv[]) {
load_plugins(ploader, &plumber, &router, nman.get_net_mapper());

std::thread audiopoll_thread = std::thread([&router]() {
set_thread_realtime(25);
set_running_cpu(1);
oals::rt::set_thread_realtime(25);
oals::rt::set_running_cpu(1);

while (true) {
router.poll_audio_data(false);
}
});

std::thread controlpoll_thread = std::thread([&router]() {
set_thread_realtime(20);
set_running_cpu(1);
oals::rt::set_thread_realtime(20);
oals::rt::set_running_cpu(1);

while (true) {
router.poll_control_packets(false);
}
});

std::thread pipe_updater = std::thread([&audio_engine, &router]() {
set_thread_realtime(80);
set_running_cpu(2);

timespec thread_wait_time{};
thread_wait_time.tv_sec = 0;
thread_wait_time.tv_nsec = 100;
oals::rt::set_thread_realtime(80);
oals::rt::set_running_cpu(2);

while (true) {
router.poll_local_audio_buffer();
Expand All @@ -153,20 +129,16 @@ int main(int argc, char* argv[]) {
// This process is a high-priority realtime process
// It is a blocking task, to let the other threads run
// I must add a small wait here
clock_nanosleep(CLOCK_MONOTONIC, 0, &thread_wait_time, nullptr);
oals::rt::precise_sleep(100);
}
});

std::thread clock_syncer = std::thread([&nman]() {
set_running_cpu(3);

timespec thread_wait_time{};
thread_wait_time.tv_sec = 0;
thread_wait_time.tv_nsec = 10000;
oals::rt::set_running_cpu(3);

while (true) {
nman.clock_master_process();
clock_nanosleep(CLOCK_MONOTONIC, 0, &thread_wait_time, nullptr);
oals::rt::precise_sleep(10000);
}
});

Expand Down
23 changes: 5 additions & 18 deletions io_sim/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@
#include <cmath>
#include <chrono>
#include <queue>
#include <ctime>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I missed the line, but I can't see where this header is used.
In C++ we prefer to use the std::chrono library. (Btw that library is a great example of how annoying deep namespaces are)


#include <alsa/asoundlib.h>
#include <sndfile.h>

#include <OpenAudioNetwork/common/NetworkMapper.h>
#include <OpenAudioNetwork/common/packet_structs.h>
#include <OpenAudioNetwork/common/ClockSlave.h>

#include <linux/sched.h>

void set_thread_realtime(uint8_t prio) {
sched_param sparams{};
sparams.sched_priority = prio;

if (sched_setscheduler(0, SCHED_FIFO, &sparams) != 0) {
std::cerr << "Failed to set thread realtime..." << std::endl;
}
}
#include <OpenAudioNetwork/netutils/rt.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in engine/main.cpp


float sig_gen(float f, float gain, int n) {
constexpr float T = 1.0f / 96000.0f;
Expand Down Expand Up @@ -237,11 +228,7 @@ int main(int argc, char* argv[]) {
playback_thread.detach();
*/

sched_param params{};
params.sched_priority = 99;
if (sched_setscheduler(0, SCHED_RR, &params) != 0) {
std::cerr << "FAILED TO SET SCHED" << std::endl;
}
oals::rt::set_process_scheduler_rr(99);

auto wait_base = (long)((AUDIO_DATA_SAMPLES_PER_PACKETS * (1.0f / 96000.0f)) * 1e9);

Expand Down Expand Up @@ -277,7 +264,7 @@ int main(int argc, char* argv[]) {
chann++;
}

set_thread_realtime(50);
oals::rt::set_thread_realtime(50);

std::cout << "START" << std::endl;

Expand All @@ -301,7 +288,7 @@ int main(int argc, char* argv[]) {

//last_stamp = now;

clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, nullptr);
oals::rt::precise_sleep(ts.tv_nsec);
ts.tv_nsec = wait_base;
}

Expand Down
Loading