Switchboard Extension SDK
Loading...
Searching...
No Matches
SwitchboardCore.hpp
1//
2// SwitchboardCore.hpp
3// SwitchboardSDK
4//
5// Created by Balázs Kiss on 2022. 02. 22..
6// Copyright © 2022. Synervoz Inc. All rights reserved.
7//
8
9#pragma once
10
11#include "SwitchboardVersion.hpp"
12
13#include <algorithm>
14#include <atomic>
15#include <cassert>
16#include <cstdio>
17#include <cstdlib>
18#include <cstring>
19#include <memory>
20#include <platform/Nonblocking.hpp>
21#include <platform/Platform.hpp>
22#include <string>
23
24// MARK: - Types
25
26// Check if data sizes are standard
27static_assert(sizeof(char) == 1);
28static_assert(sizeof(short) == 2);
29static_assert(sizeof(int) == 4);
30static_assert(sizeof(long long) == 8);
31
32// Define fixed-size data types
33using int8 = char;
34using uint8 = unsigned char;
35using int16 = int16_t;
36using uint16 = uint16_t;
37using int64 = int64_t;
38using uint64 = uint64_t;
39using uint = uint32_t;
40
41// MARK: - Constants
42
43namespace switchboard::constants {
44
45static constexpr uint DEFAULT_SAMPLERATE = 44100;
46static constexpr uint MAX_SAMPLERATE = 48000;
47static constexpr uint MAX_BUFFER_DURATION_MS = 1000;
48static constexpr uint MAX_NUMBER_OF_FRAMES = MAX_SAMPLERATE * MAX_BUFFER_DURATION_MS / 1000;
49// ~85ms@48kHz or ~93ms@44.1kHz
50static constexpr uint LEGACY_MAX_NUMBER_OF_FRAMES = 4096;
51
52static constexpr uint NUM_CHANNELS_UNDEFINED = 0;
53static constexpr uint MONO = 1;
54static constexpr uint STEREO = 2;
55static constexpr uint QUAD = 4;
56
57static constexpr uint LEFT = 0;
58static constexpr uint RIGHT = 1;
59
60static constexpr uint SAMPLE_RATE_UNDEFINED = 0;
61static constexpr uint SAMPLE_RATE_8KHz = 8000;
62static constexpr uint SAMPLE_RATE_10KHz = 10000;
63static constexpr uint SAMPLE_RATE_16KHz = 16000;
64static constexpr uint SAMPLE_RATE_24KHz = 24000;
65static constexpr uint SAMPLE_RATE_44_1KHz = 44100;
66static constexpr uint SAMPLE_RATE_48KHz = 48000;
67
68}
69
70// MARK: - Preprocessor directives
71
72// Web-specific defines
73#if defined(SWITCHBOARD_WEB)
74#include <emscripten.h>
75#else
76#endif
77
78#if NETWORKING_ENABLED && SWITCHBOARD_LICENSE_VALIDATION_ENABLED
79#define LICENSE_VALIDATION_ENABLED true
80#else
81#define LICENSE_VALIDATION_ENABLED false
82#endif
83
84#if !defined(M_PI)
85#define M_PI 3.1415926535897932384626433832
86#endif
87
88#if !defined(M_PI_2)
89#define M_PI_2 (M_PI / 2)
90#endif