You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have written a much more optimised version of the ALSA backend, which properly utilises multithreading and implements a circular buffer. Due to exams, I haven't found the time to implement inside of TDAW. I should be finished around July/August, so peek around then.
7
-
8
1
# TDAW
9
2
10
-
A tiny, header only, easy to use, cross-platform, portaudio/alsa wrapper, tailored for the demo scene.
3
+
A tiny, header only, easy to use, minimal overhead, cross-platform audio wrapper, tailored for the demo scene.
4
+
5
+
This header enables you to do shader-like sound programming (similar to that of [ShaderToy](https://shadertoy.com"ShaderToy")) inside of C/C++ incredibly easily.
11
6
12
-
This header enables you to do shader-like sound programming (similar to that of [ShaderToy](https://shadertoy.com"ShaderToy")) inside of C/C++ incredibly easy.
7
+
**Keep in mind that the demo projects sizes may vary on your machine, and additionally *if you incorporate them into your project, chances are it will be smaller due to compiler optimisations and better packing compression with larger files***
13
8
14
-
Currently the sine wave demo on Linux compiles to 1.6kb (Arch Linux, 1166 bytes, demo/linux compiled with gcc and packed with vondehi).
9
+
<ins>For actual sizes, refer to the table inside the demo folder's readme.</ins>
15
10
16
11
17
12
# Usage
@@ -21,106 +16,85 @@ Before including TDAW, you must first `#define TDAW_IMPLEMENTATION` in *one* C/C
21
16
You then must select a backend, the following are:
22
17
23
18
- PortAudio `#define TDAW_BACKEND_PORTAUDIO`
24
-
- ALSA `#define TDAW_BACKEND_ALSA`
19
+
- ALSA `#define TDAW_BACKEND_ALSA` (linux only)
20
+
- aplay `#define TDAW_BACKEND_APLAY` (linux only)
25
21
26
-
There are various features you can activate by defining the following lines:
22
+
There are also features you can activate by defining the following lines:
27
23
28
24
```c
29
25
#defineTDAW_USERDATA // Allow user data to be passed to your stream
30
-
#define TDAW_UTILS // Access to some utility functions.
31
-
#define TDAW_PESYNTH // Access basic example synthesizers.
32
26
#define TDAW_DEBUGTEXT // Output debug text to console
33
-
#define TDAW_DEBUGIMGUI // Create ImGui Windows for debugging (C++ only)
34
-
#define TDAW_PRERENDER [length in seconds] // Allows for functions to prerender your music/sounds to save lots of CPU (currently only works with the ALSA backend)
35
-
#define TDAW_MULTITHREADING // Enables multithreaded playback. Causes slight performance decrease and no time variable to access. Single threading only avalible on alsa.
**Note: Prerendering your audio could result in a massive performance increase if your computer struggles with playback.**
41
-
42
-
---
43
-
44
-
# Prerendering/Live rendering on a single threads
45
-
46
-
Initialise TDAW and open a stream for the sound to begin playing ().
47
-
Set a sample rate and a FPB. If your audio lags, try increasing the FPB:
31
+
## Creating a function to render
48
32
33
+
Your function must follow this format. `TDAW_CHANNEL` is a struct with 2 floats for both audio channels.
49
34
```c
50
-
TDAW_PIP tdaw = TDAW_initTDAW(44100, 512); //sample rate, frames per buffer
35
+
TDAW_CHANNEL test(float time, float samp)
36
+
{
37
+
TDAW_CHANNEL out;
38
+
//code here
39
+
return out;
40
+
}
51
41
```
42
+
If you have enabled `TDAW_USERDATA`, an extra `void* userdata` is required as an argument, allowing you to pass data in.
52
43
53
-
If you plan to prerender, place this outside of your game/application loop.
54
-
55
-
```c
56
-
TDAW_PASSDATA dat;
57
-
dat.ptr = &function;
58
-
TDAW_prerender(&tdaw, &dat); //prerenders sounds
59
-
```
44
+
# Live rendering on a single threads
60
45
61
-
Inside your game/application loop, run the following if you are prerendering or live rendering
46
+
Initialise TDAW with a refernce to a TDAW_PIP and your "frames per buffer" size (FPB). If your audio lags, try increasing the FPB. Lower FPB results in faster output at the cost of potential missing buffers ifyour code fails to send out a buffer in time, and vice versa.
62
47
63
48
```c
64
-
TDAW_render(&tdaw, &function); //live rendering
65
-
TDAW_playPrerender(&dat); //prender playback
49
+
TDAW_PIP tdaw;
50
+
TDAW_initTDAW(&tdaw, 1024);
66
51
```
67
52
68
-
To terminate a TDAW instance run `TDAW_terminate()`.
69
-
70
-
# Prerendering/Live rendering with multithreading
71
-
72
-
Create a `TDAW_PASSDATA` instance like so:
53
+
Inside your application/demo loop, run the following
73
54
74
55
```c
75
-
TDAW_PASSDATA data;
56
+
TDAW_render(&tdaw, &function);
76
57
```
77
58
78
-
From here you can put the pointer to your music code like so:
79
-
80
-
```c
81
-
data.ptr = &music;
82
-
```
83
-
84
-
Functions passed through `data.ptr` must return `TDAW_CHANNEL` (which is 2 floats making up the left and right audio channel).
85
-
They must also take `float time` and `float samp` (`void* userData` too if you have `TDAW_USERDATA` defined!)
86
-
87
-
And any userdata can be passed through `data.userData` (make sure `TDAW_USERDATA` is defined!)
88
-
89
-
Next you must initialise TDAW and open a stream for the sound to begin playing ().
90
-
Set a sample rate and a FPB. If your audio lags, try increasing the FPB:
91
-
92
-
```c
93
-
TDAW_PIP tdaw = TDAW_initTDAW(44100, 512); //sample rate, frames per buffer
94
-
TDAW_openStream(&tdaw, &dat);
95
-
```
59
+
To terminate a TDAW instance run `TDAW_terminate()`.
96
60
97
-
If you are planning to prerender your audio, TDAW_openStream() is not needed, instead do the following:
61
+
# Live rendering with multithreading
98
62
99
-
```c
100
-
TDAW_prerender(&tdaw, &dat); //prerenders sounds
101
-
TDAW_playPrerender(&dat); //plays sound
102
-
```
63
+
Same as live rendering, except instead of running `TDAW_render()` in a loop, you run `TDAW_mt_render()`**outside of the loop**, otherwise you will be constantly spawning new threads. It holds the same parameters as `TDAW_render()`
103
64
104
-
To close a stream, run `TDAW_closeStream()` and to terminate a TDAW instance run `TDAW_terminate()`.
65
+
# Dependencies
105
66
106
-
---
67
+
- PortAudio, ALSA or aplay depending on what backend you want to use
68
+
- For the demo, NASM and Python for vondehi and [Elfkickers for sstrip](https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html)
107
69
108
-
Take a look at the demo folder for a basic completed project containing a 'plucked' sine wave.
70
+
# QNA
71
+
Sure, here is the text organized into a dropdown with blockquotes:
109
72
110
-
The example folder contains some more projects.
73
+
<details>
74
+
<summary>Why are there so many preprocessor definitions in `TDAW.h`, it's painful to read!! I hate you!!</summary>
111
75
112
-
Documentation will come soon.
76
+
> Packaging this all in one header file while trying to save on binary size will result at messy code at some point haha
77
+
</details>
113
78
114
-
# Dependencies
79
+
<details>
80
+
<summary>Can I pass a single float[2] into TDAW_CHANNEL without having to apply left and right channels separately?</summary>
115
81
116
-
- PortAudio or ALSA depending on what backend you want to use
117
-
- NASM and Python for vondehi
82
+
> Yes, just do the following pointer magic
83
+
>
84
+
> ```c
85
+
> TDAW_CHANNEL out;
86
+
> float (*ptr)[2] = (float (*)[2])&out;
87
+
> float data[2] = {0.2, 0.2};
88
+
> *ptr = &data;
89
+
> ```
90
+
</details>
118
91
119
-
# Future
92
+
<details>
93
+
<summary>What backend should I use?</summary>
120
94
121
-
- PortAudio prerendering support
122
-
- A Windows build
95
+
> Portaudio if you want compatibility with other platforms, aplay if you want to save on size. ALSA is slightly worse in size but may offer better performance compared to aplay.
96
+
</details>
123
97
124
98
# Credits
125
-
126
-
-[PoroCYon for vondehi](VONDEHI-LICENSE)
99
+
- [pipe (creator)](https://github.com/ppekko)
100
+
- [PoroCYon for vondehi](VONDEHI-LICENSE) (original vondehi found [here](https://gitlab.com/PoroCYon/vondehi))
This demo plays the default sine ping code found on new shadertoy projects.
3
+
4
+
This has been structured so you can compare sizes between different compilers and backends, with or without compression.
5
+
All you need to do is go into no-multithread/ or multithread/, and run the `compileall.sh` script.
6
+
7
+
As for the Makefile hell, it works, and I don't want to touch it again. Just run the scripts
8
+
9
+
## Important!
10
+
As said in the main readme, these sizes may vary on your machine, and additionally ***if you incorporate them into your project, chances are it will be smaller due to compiler optimisations and better packing compression with larger files***
0 commit comments