Skip to content

Commit 20878c9

Browse files
committed
updated cavacore documentation
1 parent daf916b commit 20878c9

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

CAVACORE.md

+16-19
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,35 @@ the raw output data from fftw will not look very nice when used directly in a vi
1111
to improve the look of the visualization:
1212

1313

14-
* limit bandwith
14+
## adjustable bandwith
1515

16-
theoretically the human ear can hear frequencies up to 20kHz, but the information above 10k is hard to separate from eachother
17-
and does not give much feedback by itself when visualizing audio. Similarly audio below 50Hz can be heard but does not directly provide
18-
anything to the visualizing of the audio.
16+
Theoretically the human ear can hear frequencies up to 20kHz, but the information above 10k is hard to separate from eachother
17+
and does not give much feedback by itself when visualizing audio. Similarly audio down to 20Hz can be heard, but the frequencies
18+
below 50Hz does not directly provide anything to the visualizing of the audio.
1919

2020

21-
* spread the output logarithmically
21+
## spread the output logarithmically
2222

23-
the human ear hears different frequencies logarithmically, so notes that are 2x and 4x higher than eachother, will be preceived
24-
as beeing a fixed amount higher than eachother.
23+
The human ear hears different frequencies logarithmically, so notes that are 2x and 4x higher than eachother, will be preceived
24+
as beeing a fixed amount higher than eachother. Therefore cavacore outputs the frequencies logarithmically. Cavacore will also
25+
group the output in the desired number of samples.
2526

2627

27-
* limit number of buckets
28+
## noise reduction
2829

29-
fftw gives out (input samples / 2) + 1 number of ouput samples. cavacore can limit this to the desired needed "bars" in your application.
30+
the raw output of fftw is very noisy, cavacore processes the output signal in two ways to provide a smooth output:
3031

32+
* an integral filter calculates a weighted average of the last values
33+
* fall off filter, when values is lower than last value it uses a fall down effect instead of the new value
3134

32-
* noise reduction
35+
This feature can be adjusted.
3336

34-
the raw output of fftw is very jittery, cavacore processes the output signal in two ways to provide a smooth output:
3537

36-
a. an integral filter calculates a weighted average of the last values
38+
## real-time sensitivity adjustment
3739

38-
b. fall off filter, when values is lower than last value it uses a fall down effect instead of the new value
39-
40-
41-
* real-time sensitivity adjustment
42-
43-
the range of an input signal can vary a lot. cavacore will keep the output signal within the desired range in real-time.
40+
The range of an input signal can vary a lot. cavacore can keep the output signal within range in real-time. This feature can be disabled.
4441

4542

4643
# Usage
4744

48-
look in cavacore.h for documentation and the cavacore_test.c application for how to use.
45+
See cavacore.h for documentation and the cavacore_test.c application for how to use.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ $ pkill -USR2 cava
458458
Using cava in other applications
459459
--------------------------------
460460

461-
The core processing engine in cava has been split into a separate library `cavacore`. Look in CAVACORE.md for usage.
461+
The core processing engine in cava has been split into a separate library `cavacore`. See CAVACORE.md for details.
462462

463463

464464
Contribution

cavacore.h

+22-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#include <fftw3.h>
55

6+
// cava_plan, parameters used internally by cavacore, do not modify these directly
7+
// only the cut off frequencies is of any potential interest to read out,
8+
// the rest should most likley be hidden somehow
69
struct cava_plan {
710
int FFTbassbufferSize;
811
int FFTmidbufferSize;
@@ -53,48 +56,52 @@ struct cava_plan {
5356
int *cava_fall;
5457
};
5558

56-
// cava_init initialize cava, takes the following parameters:
59+
// cava_init, initialize visualization, takes the following parameters:
5760

58-
// number_of_bars is number of wanted bars per channel
61+
// number_of_bars, number of wanted bars per channel
5962

60-
// rate is sample rate of input signal
63+
// rate, sample rate of input signal
6164

62-
// channels is number of interleaved channels in input
65+
// channels, number of interleaved channels in input
6366

64-
// autosens toggle automatic sensitivity adjustment 1 = on, 2 = off
65-
// on gives a dynamically adjusted output signal from 0 to 1
67+
// autosens, toggle automatic sensitivity adjustment 1 = on, 0 = off
68+
// on, gives a dynamically adjusted output signal from 0 to 1
6669
// the output is continously adjusted to use the entire range
67-
// off will pass the raw values from cava directly to the output
68-
// the max values will depend on the input
70+
// off, will pass the raw values from cava directly to the output
71+
// the max values will then be dependent on the input
6972

70-
// noise_reduction 0 - 1, recomended 0.77
73+
// noise_reduction, adjust noise reduciton filters. 0 - 1, recomended 0.77
7174
// the raw visualization is very noisy, this factor adjusts the integral
7275
// and gravity filters inside cavacore to keep the signal smooth
7376
// 1 will be very slow and smooth, 0 will be fast but noisy.
7477

7578
// low_cut_off, high_cut_off cut off frequencies for visualization in Hz
79+
// recomended: 50, 10000
7680

7781
// returns a cava_plan to be used by cava_execute
7882
extern struct cava_plan *cava_init(int number_of_bars, unsigned int rate, int channels,
7983
int autosens, double noise_reduction, int low_cut_off,
8084
int high_cut_off);
8185

82-
// cava_execute executes cava
86+
// cava_execute, executes visualization
8387

84-
// cava_in size can be up to 4096 * number of channels, but it is recomended to only fill up some
88+
// cava_in, input buffer can be any size. internal buffers in cavacore is
89+
// 4096 * number of channels at 44100 samples rate, but it is recomended to use less
8590
// new samples per execution as this determines your framerate.
8691
// 512 samples at 44100 sample rate mono, gives about 86 frames per second.
8792

88-
// new_samples is the number of samples in cava_in
93+
// new_samples, the number of samples in cava_in to be processed
8994
// if you have async reading of data this number can vary from execution to execution
9095

91-
// cava_out size must be number of bars * number of channels, left + right
96+
// cava_out, output buffer. Size must be number of bars * number of channels. Bars will
97+
// be sorted from lowest to highest frequency. Feft channel first then right channel.
9298

93-
// plan is the struct returned from cava_init
99+
// plan, the cava_plan struct returned from cava_init
94100

95101
// cava_execute assumes cava_in samples to be interleaved if more than one channel
102+
// only up to two channels are supported.
96103
extern void cava_execute(double *cava_in, int new_samples, double *cava_out,
97104
struct cava_plan *plan);
98105

99-
// destroys the plan, frees up memory
106+
// cava_destroy, destroys the plan, frees up memory
100107
extern void cava_destroy(struct cava_plan *plan);

cavacore_test.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
void main() {
1313

14-
printf("welcome to cavalib standalone test app\n");
14+
printf("welcome to cavacore standalone test app\n");
1515

1616
int bars_per_channel = 10;
1717
int channels = 2;
@@ -21,7 +21,7 @@ void main() {
2121
double blueprint_200MHz[10] = {0, 0.002, 0.980, 0.049, 0.001, 0, 0, 0, 0, 0};
2222

2323
printf("planning visualization with 10 bars per channel, 44100 rate, 2 cahnnels, autosens, "
24-
"0.77 noise reduction, 50 - 10000 MHz.\n");
24+
"0.77 noise reduction, 50 - 10000 MHz bandwith.\n");
2525

2626
struct cava_plan *plan = cava_init(bars_per_channel, rate, channels, 1, 0.77, 50, 10000);
2727
printf("got lower cut off frequencies:\n");
@@ -46,11 +46,15 @@ void main() {
4646

4747
printf("running cava execute 300 times (simulating about 3.5 seconds run time)\n\n");
4848
for (int k = 0; k < 300; k++) {
49+
4950
// filling up 512*2 samples at a time, making sure the sinus wave is unbroken
51+
// 200MHz in right channel, 2000MHz in left
52+
// if we where using a proper audio source this would be replaced by a simple read function
5053
for (int n = 0; n < buffer_size / 2; n++) {
5154
cava_in[n * 2] = sin(2 * PI * 200 / rate * (n + (k * buffer_size / 2))) * 10000;
5255
cava_in[n * 2 + 1] = sin(2 * PI * 2000 / rate * (n + (k * buffer_size / 2))) * 10000;
5356
}
57+
5458
cava_execute(cava_in, buffer_size, cava_out, plan);
5559
}
5660

0 commit comments

Comments
 (0)