Skip to content

Commit 359a8cc

Browse files
committed
code revamp
1 parent 345fef3 commit 359a8cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2989
-994
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

-38
This file was deleted.

.github/ISSUE_TEMPLATE/feature_request.md

-20
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.kdev4/
22
tdaw.kdev4
3+
.vscode/

README.md

+53-79
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
2-
3-
4-
# PLEASE READ ME
5-
6-
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-
81
# TDAW
92

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.
116

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***
138

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>
1510

1611

1712
# Usage
@@ -21,106 +16,85 @@ Before including TDAW, you must first `#define TDAW_IMPLEMENTATION` in *one* C/C
2116
You then must select a backend, the following are:
2217

2318
- 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)
2521

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:
2723

2824
```c
2925
#define TDAW_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.
3226
#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.
27+
#define TDAW_MULTITHREAD // Enables multithreaded playback
3628
```
37-
3829
These are also detailed in the header itself.
3930
40-
**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
4832
33+
Your function must follow this format. `TDAW_CHANNEL` is a struct with 2 floats for both audio channels.
4934
```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+
}
5141
```
42+
If you have enabled `TDAW_USERDATA`, an extra `void* userdata` is required as an argument, allowing you to pass data in.
5243

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
6045

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 if your code fails to send out a buffer in time, and vice versa.
6247

6348
```c
64-
TDAW_render(&tdaw, &function); //live rendering
65-
TDAW_playPrerender(&dat); //prender playback
49+
TDAW_PIP tdaw;
50+
TDAW_initTDAW(&tdaw, 1024);
6651
```
6752
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
7354
7455
```c
75-
TDAW_PASSDATA data;
56+
TDAW_render(&tdaw, &function);
7657
```
7758

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()`.
9660

97-
If you are planning to prerender your audio, TDAW_openStream() is not needed, instead do the following:
61+
# Live rendering with multithreading
9862

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()`
10364

104-
To close a stream, run `TDAW_closeStream()` and to terminate a TDAW instance run `TDAW_terminate()`.
65+
# Dependencies
10566

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)
10769

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:
10972

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>
11175

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>
11378
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>
11581

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>
11891
119-
# Future
92+
<details>
93+
<summary>What backend should I use?</summary>
12094
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>
12397
12498
# 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))

demo/README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Building
2+
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***
11+
12+
## Sizes
13+
14+
15+
Compiled on Arch Linux with:
16+
- tcc (0.9.28rc)
17+
- gcc (13.2.1)
18+
- clang (16.0.6)
19+
20+
<details>
21+
<summary>No Multithreading</summary>
22+
<blockquote>
23+
<details>
24+
<summary>ALSA Backend</summary>
25+
26+
| Compiler | Compressed | Un-compresed |
27+
|----------|------------|--------------|
28+
| TCC | 1180 bytes | 5680 bytes |
29+
| GCC | 1749 bytes | 12448 bytes |
30+
| CLANG | 1722 bytes | 12448 bytes |
31+
32+
</details>
33+
</blockquote>
34+
<blockquote>
35+
<details>
36+
<summary>PortAudio Backend</summary>
37+
38+
| Compiler | Compressed | Un-compresed |
39+
|----------|------------|--------------|
40+
| TCC | 1570 bytes | 4056 bytes |
41+
| GCC | 1404 bytes | 12368 bytes |
42+
| CLANG | 1384 bytes | 12368 bytes |
43+
44+
</details>
45+
</blockquote>
46+
<blockquote>
47+
<details>
48+
<summary>aplay Backend</summary>
49+
50+
| Compiler | Compressed | Un-compresed |
51+
|----------|------------|--------------|
52+
| TCC | 1416 bytes | 3528 bytes |
53+
| GCC | 1300 bytes | 12336 bytes |
54+
| CLANG | 1278 bytes | 12336 bytes |
55+
56+
</details>
57+
</blockquote>
58+
<br>
59+
</details>
60+
<!-------------------------------------------------->
61+
<details>
62+
<summary>Multithreading</summary>
63+
<blockquote>
64+
<details>
65+
<summary>ALSA Backend</summary>
66+
67+
| Compiler | Compressed | Un-compresed |
68+
|----------|------------|--------------|
69+
| TCC | 2062 bytes | 6312 bytes |
70+
| GCC | 1960 bytes | 12472 bytes |
71+
| CLANG | 1931 bytes | 12472 bytes |
72+
73+
</details>
74+
</blockquote>
75+
<blockquote>
76+
<details>
77+
<summary>PortAudio Backend</summary>
78+
79+
| Compiler | Compressed | Un-compresed |
80+
|----------|------------|--------------|
81+
| TCC | 1769 bytes | 4720 bytes |
82+
| GCC | 1674 bytes | 12400 bytes |
83+
| CLANG | 1655 bytes | 12400 bytes |
84+
85+
</details>
86+
</blockquote>
87+
<blockquote>
88+
<details>
89+
<summary>aplay Backend</summary>
90+
91+
| Compiler | Compressed | Un-compresed |
92+
|----------|------------|--------------|
93+
| TCC | 1617 bytes | 4160 bytes |
94+
| GCC | 1578 bytes | 12368 bytes |
95+
| CLANG | 1553 bytes | 12368 bytes |
96+
97+
</details>
98+
</blockquote>
99+
<br>
100+
</details>

demo/linux/Makefile

-24
This file was deleted.

demo/linux/README.md

-5
This file was deleted.

0 commit comments

Comments
 (0)