Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

Commit d2cfbc0

Browse files
committed
inception
0 parents  commit d2cfbc0

14 files changed

Lines changed: 65305 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
cmake_minimum_required (VERSION 3.4)
3+
project(LabSoundCDemo)
4+
5+
# Don't report that sample file installation up to date
6+
set(CMAKE_INSTALL_MESSAGE LAZY)
7+
8+
set(LABSOUNDCDEMO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
9+
configure_file("${LABSOUNDCDEMO_ROOT}/LabSoundDemo.config.h" "${LABSOUNDCDEMO_ROOT}/LabSoundDemo.h" @ONLY)
10+
11+
find_package(LabSound)
12+
13+
if (APPLE)
14+
set(PLATFORM_LIBS
15+
"-framework AudioToolbox"
16+
"-framework AudioUnit"
17+
"-framework Accelerate"
18+
"-framework Cocoa"
19+
"-framework CoreAudio"
20+
"-framework Metal"
21+
"-framework MetalKit"
22+
"-framework QuartzCore"
23+
)
24+
endif()
25+
26+
add_executable(LabSoundCDemo
27+
labsound-c.h labsound-c.cpp
28+
tinycthread.h tinycthread.c
29+
LabSoundCDemo.c flecs.h flecs.c)
30+
set_property(TARGET LabSoundCDemo PROPERTY C_STANDARD 11)
31+
target_link_libraries(LabSoundCDemo Lab::Sound ${PLATFORM_LIBS})
32+
target_include_directories(LabSoundCDemo PRIVATE "${LABSOUNDDEMO_ROOT}")
33+
install(TARGETS LabSoundCDemo RUNTIME DESTINATION bin)

LabSoundCDemo.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
#include "labsound-c.h"
3+
#include <string.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <time.h>
7+
#include "tinycthread.h"
8+
9+
void demo_sleep(LabSoundAPI* ls, float seconds) {
10+
while (seconds > 1.f/60.f) {
11+
ls_idle(ls);
12+
thrd_sleep(&(struct timespec) {
13+
.tv_sec = 0,
14+
.tv_nsec = 1000000000 / 60 }, NULL);
15+
16+
seconds -= 1.f / 60.f;
17+
}
18+
if (seconds > 0.f) {
19+
thrd_sleep(&(struct timespec) {
20+
.tv_sec = 0,
21+
.tv_nsec = (long)(1000000000.f * seconds)
22+
}, NULL);
23+
}
24+
ls_idle(ls);
25+
}
26+
27+
28+
#define MAKE_SLICE(STR) \
29+
static const char* STR##_slicestr = #STR;\
30+
ls_StringSlice STR##_s = { STR##_slicestr, STR##_slicestr + sizeof(#STR) - 1 };
31+
32+
int main(int argc, char** argcv)
33+
{
34+
LabSoundAPI* ls = ls_create_api_1_0(ls_default_alloc);
35+
const ls_NameArray* node_names = ls->node_names(ls);
36+
if (!node_names)
37+
return 1;
38+
39+
MAKE_SLICE(amplitude);
40+
MAKE_SLICE(frequency);
41+
MAKE_SLICE(detune);
42+
MAKE_SLICE(Oscillator);
43+
44+
MAKE_SLICE(osc1);
45+
MAKE_SLICE(osc2);
46+
MAKE_SLICE(osc3);
47+
48+
//-------------------------------------------------------------------------
49+
printf("test: list the registered nodes\n");
50+
51+
for (int i = 0; i < node_names->count; ++i) {
52+
ls_StringSlice* s = &node_names->names[i];
53+
printf("%.*s\n", (int) (s->end - s->start), s->start);
54+
}
55+
56+
//-------------------------------------------------------------------------
57+
printf("test: playing a 440 hz tone\n");
58+
59+
ls_Node osc = ls->node_create(ls, osc1_s, Oscillator_s);
60+
ls_Node dest = ls->device_node(ls);
61+
62+
ls_Pin oscOut = ls->node_indexed_output(ls, osc, 0);
63+
ls_Pin destIn = ls->node_indexed_input(ls, dest, 0);
64+
ls_Connection connection1 = ls->connect_output_to_input(ls, destIn, oscOut);
65+
66+
ls->node_start(ls, osc, (ls_Seconds) { 0.f });
67+
68+
demo_sleep(ls, 0.5);
69+
//-------------------------------------------------------------------------
70+
printf("test: disconnect the oscillator (silence)\n");
71+
72+
ls->disconnect(ls, connection1);
73+
74+
demo_sleep(ls, 0.5f);
75+
//-------------------------------------------------------------------------
76+
printf("test: reconnect the oscillator, play at 220Hz\n");
77+
78+
ls_Pin frequency_osc1 = ls->node_parameter(ls, osc, frequency_s);
79+
ls->set_float(ls, frequency_osc1, 220.f);
80+
connection1 = ls->connect_output_to_input(ls, destIn, oscOut);
81+
82+
demo_sleep(ls, 0.5);
83+
//-------------------------------------------------------------------------
84+
printf("test: delete the oscillator while it's running (silence)\n");
85+
86+
ls->node_delete(ls, osc);
87+
88+
demo_sleep(ls, 0.5);
89+
//-------------------------------------------------------------------------
90+
printf("test: create and play an oscillator at 880\n");
91+
92+
osc = ls->node_create(ls, osc2_s, Oscillator_s);
93+
frequency_osc1 = ls->node_parameter(ls, osc, frequency_s);
94+
ls->set_float(ls, frequency_osc1, 880.f);
95+
oscOut = ls->node_indexed_output(ls, osc, 0);
96+
connection1 = ls->connect_output_to_input(ls, destIn, oscOut);
97+
ls->node_start(ls, osc, (ls_Seconds) { 0.f });
98+
99+
demo_sleep(ls, 1);
100+
//-------------------------------------------------------------------------
101+
printf("test: modulate the oscillator at 440\n");
102+
103+
ls_Node osc2 = ls->node_create(ls, osc3_s, Oscillator_s);
104+
ls_Pin frequency_osc2 = ls->node_parameter(ls, osc2, frequency_s);
105+
ls->set_float(ls, frequency_osc2, 4.f);
106+
ls_Pin amplitude_osc2 = ls->node_parameter(ls, osc2, amplitude_s);
107+
ls->set_float(ls, amplitude_osc2, 40.f);
108+
ls->set_float(ls, frequency_osc1, 440.f);
109+
110+
ls_Pin detune_osc1 = ls->node_parameter(ls, osc, detune_s);
111+
ls_Pin osc2Out = ls->node_indexed_output(ls, osc2, 0);
112+
ls_Connection connection2 = ls->connect_output_to_input(ls, detune_osc1, osc2Out);
113+
ls->node_start(ls, osc2, (ls_Seconds) { 0.f });
114+
115+
demo_sleep(ls, 1000);
116+
//-------------------------------------------------------------------------
117+
printf("test: all complete\n");
118+
return 0;
119+
}

LabSoundDemo.config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef LABSOUNDDEMOCONFIG_H
2+
#define LABSOUNDDEMOCONFIG_H
3+
4+
const char* asset_base = "@CMAKE_INSTALL_PREFIX@/share/LabSound/";
5+
6+
#endif

LabSoundDemo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef LABSOUNDDEMOCONFIG_H
2+
#define LABSOUNDDEMOCONFIG_H
3+
4+
const char* asset_base = "C:/Projects/LabSound/install-ls2/share/LabSound/";
5+
6+
#endif

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Experimental C binding for LabSound.
2+
3+
copyright (c) 2022 Nick Porcino
4+
MIT License
5+

flecs-LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Sander Mertens
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)