Skip to content

Commit c5739a6

Browse files
committed
test4
1 parent 2a6fd95 commit c5739a6

23 files changed

+467
-9
lines changed

Makefile.am

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ bin_PROGRAMS = cava
66
cavadir = $(top_srcdir)
77
cava_SOURCES = src/cava.c src/cavacore.c src/config.c src/input/common.c \
88
src/input/fifo.c src/input/shmem.c src/output/terminal_noncurses.c \
9-
src/output/raw.c src/output/noritake.c include/cava/cavacore.h \
10-
include/cava/config.h include/cava/input/common.h \
11-
include/cava/input/fifo.h include/cava/input/shmem.h \
12-
include/cava/output/terminal_noncurses.h include/cava/output/raw.h \
13-
include/cava/output/noritake.h include/cava/debug.h \
14-
include/cava/util.h third_party/incbin.h
9+
src/output/raw.c src/output/noritake.c third_party/incbin.h
1510
cava_CPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" \
1611
-D_POSIX_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE_EXTENDED \
1712
-DFONTDIR=\"@FONT_DIR@\" -DFONTFILE=\"@FONT_FILE@\" \
@@ -71,15 +66,15 @@ if PULSE
7166
endif
7267

7368
if SNDIO
74-
cava_SOURCES += src/input/sndio.c include/cava/input/sndio.h
69+
cava_SOURCES += src/input/sndio.c #include/cava/input/sndio.h
7570
endif
7671

7772
if OSS
78-
cava_SOURCES += src/input/oss.c include/cava/input/oss.h
73+
cava_SOURCES += src/input/oss.c #include/cava/input/oss.h
7974
endif
8075

8176
if JACK
82-
cava_SOURCES += src/input/jack.c include/cava/input/jack.h
77+
cava_SOURCES += src/input/jack.c #include/cava/input/jack.h
8378
endif
8479

8580
if NCURSES

include/cava/cavacore.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Copyright (c) 2022 Karl Stavestrand <karl@stavestrand.no>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
#pragma once
26+
#include <stdint.h>
27+
28+
#include <fftw3.h>
29+
30+
// cava_plan, parameters used internally by cavacore, do not modify these directly
31+
// only the cut off frequencies is of any potential interest to read out,
32+
// the rest should most likley be hidden somehow
33+
struct cava_plan {
34+
int FFTbassbufferSize;
35+
int FFTbufferSize;
36+
int number_of_bars;
37+
int audio_channels;
38+
int input_buffer_size;
39+
int rate;
40+
int bass_cut_off_bar;
41+
int sens_init;
42+
int autosens;
43+
int frame_skip;
44+
int status;
45+
char error_message[1024];
46+
47+
double sens;
48+
double framerate;
49+
double noise_reduction;
50+
51+
fftw_plan p_bass_l, p_bass_r;
52+
fftw_plan p_l, p_r;
53+
54+
fftw_complex *out_bass_l, *out_bass_r;
55+
fftw_complex *out_l, *out_r;
56+
57+
double *bass_multiplier;
58+
double *multiplier;
59+
60+
double *in_bass_r_raw, *in_bass_l_raw;
61+
double *in_r_raw, *in_l_raw;
62+
double *in_bass_r, *in_bass_l;
63+
double *in_r, *in_l;
64+
double *prev_cava_out, *cava_mem;
65+
double *input_buffer, *cava_peak;
66+
67+
double *eq;
68+
69+
float *cut_off_frequency;
70+
int *FFTbuffer_lower_cut_off;
71+
int *FFTbuffer_upper_cut_off;
72+
double *cava_fall;
73+
};
74+
75+
// cava_init, initialize visualization, takes the following parameters:
76+
77+
// number_of_bars, number of wanted bars per channel
78+
79+
// rate, sample rate of input signal
80+
81+
// channels, number of interleaved channels in input
82+
83+
// autosens, toggle automatic sensitivity adjustment 1 = on, 0 = off
84+
// on, gives a dynamically adjusted output signal from 0 to 1
85+
// the output is continously adjusted to use the entire range
86+
// off, will pass the raw values from cava directly to the output
87+
// the max values will then be dependent on the input
88+
89+
// noise_reduction, adjust noise reduciton filters. 0 - 1, recomended 0.77
90+
// the raw visualization is very noisy, this factor adjusts the integral
91+
// and gravity filters inside cavacore to keep the signal smooth
92+
// 1 will be very slow and smooth, 0 will be fast but noisy.
93+
94+
// low_cut_off, high_cut_off cut off frequencies for visualization in Hz
95+
// recomended: 50, 10000
96+
97+
// returns a cava_plan to be used by cava_execute. If cava_plan.status is 0 all is OK.
98+
// If cava_plan.status is -1, cava_init was called with an illegal paramater, see error string in
99+
// cava_plan.error_message
100+
extern struct cava_plan *cava_init(int number_of_bars, unsigned int rate, int channels,
101+
int autosens, double noise_reduction, int low_cut_off,
102+
int high_cut_off);
103+
104+
// cava_execute, executes visualization
105+
106+
// cava_in, input buffer can be any size. internal buffers in cavacore is
107+
// 4096 * number of channels at 44100 samples rate, if new_samples is greater
108+
// then samples will be discarded. However it is recomended to use less
109+
// new samples per execution as this determines your framerate.
110+
// 512 samples at 44100 sample rate mono, gives about 86 frames per second.
111+
112+
// new_samples, the number of samples in cava_in to be processed per execution
113+
// in case of async reading of data this number is allowed to vary from execution to execution
114+
115+
// cava_out, output buffer. Size must be number of bars * number of channels. Bars will
116+
// be sorted from lowest to highest frequency. If stereo input channels are configured
117+
// then all left channel bars will be first then the right.
118+
119+
// plan, the cava_plan struct returned from cava_init
120+
121+
// cava_execute assumes cava_in samples to be interleaved if more than one channel
122+
// only up to two channels are supported.
123+
extern void cava_execute(double *cava_in, int new_samples, double *cava_out,
124+
struct cava_plan *plan);
125+
126+
// cava_destroy, destroys the plan, frees up memory
127+
extern void cava_destroy(struct cava_plan *plan);
128+
129+
#ifdef __cplusplus
130+
}
131+
#endif

include/cava/config.h

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#pragma once
2+
3+
#include <limits.h>
4+
#include <stdbool.h>
5+
#include <stdio.h>
6+
#include <string.h>
7+
8+
#define MAX_ERROR_LEN 1024
9+
10+
#ifdef PORTAUDIO
11+
#define HAS_PORTAUDIO true
12+
#else
13+
#define HAS_PORTAUDIO false
14+
#endif
15+
16+
#ifdef ALSA
17+
#define HAS_ALSA true
18+
#else
19+
#define HAS_ALSA false
20+
#endif
21+
22+
#ifdef PULSE
23+
#define HAS_PULSE true
24+
#else
25+
#define HAS_PULSE false
26+
#endif
27+
28+
#ifdef PIPEWIRE
29+
#define HAS_PIPEWIRE true
30+
#else
31+
#define HAS_PIPEWIRE false
32+
#endif
33+
34+
#ifdef SNDIO
35+
#define HAS_SNDIO true
36+
#else
37+
#define HAS_SNDIO false
38+
#endif
39+
40+
#ifdef OSS
41+
#define HAS_OSS true
42+
#else
43+
#define HAS_OSS false
44+
#endif
45+
46+
#ifdef JACK
47+
#define HAS_JACK true
48+
#else
49+
#define HAS_JACK false
50+
#endif
51+
52+
#ifdef _WIN32
53+
#define HAS_WINSCAP true
54+
#define SDL true
55+
#define HAS_FIFO false
56+
#define HAS_SHMEM false
57+
#define PATH_MAX 260
58+
#else
59+
#define HAS_WINSCAP false
60+
#define HAS_FIFO true
61+
#define HAS_SHMEM true
62+
63+
#endif
64+
65+
// These are in order of least-favourable to most-favourable choices, in case
66+
// multiple are supported and configured.
67+
enum input_method {
68+
INPUT_FIFO,
69+
INPUT_PORTAUDIO,
70+
INPUT_PIPEWIRE,
71+
INPUT_ALSA,
72+
INPUT_PULSE,
73+
INPUT_SNDIO,
74+
INPUT_OSS,
75+
INPUT_JACK,
76+
INPUT_SHMEM,
77+
INPUT_WINSCAP,
78+
INPUT_MAX,
79+
};
80+
81+
enum output_method {
82+
OUTPUT_NCURSES,
83+
OUTPUT_NONCURSES,
84+
OUTPUT_RAW,
85+
OUTPUT_SDL,
86+
OUTPUT_SDL_GLSL,
87+
OUTPUT_NORITAKE,
88+
OUTPUT_NOT_SUPORTED
89+
};
90+
91+
enum mono_option { LEFT, RIGHT, AVERAGE };
92+
enum data_format { FORMAT_ASCII = 0, FORMAT_BINARY = 1, FORMAT_NTK3000 = 2 };
93+
94+
enum xaxis_scale { NONE, FREQUENCY, NOTE };
95+
96+
enum orientation {
97+
ORIENT_BOTTOM,
98+
ORIENT_TOP,
99+
ORIENT_LEFT,
100+
ORIENT_RIGHT,
101+
ORIENT_SPLIT_H,
102+
ORIENT_SPLIT_V
103+
};
104+
105+
struct config_params {
106+
char *color, *bcolor, *raw_target, *audio_source, **gradient_colors,
107+
**horizontal_gradient_colors, *data_format, *vertex_shader, *fragment_shader, *theme;
108+
109+
char bar_delim, frame_delim;
110+
double monstercat, integral, gravity, ignore, sens, noise_reduction, max_height;
111+
112+
unsigned int lower_cut_off, upper_cut_off;
113+
double *userEQ;
114+
enum input_method input;
115+
enum output_method output;
116+
enum xaxis_scale xaxis;
117+
enum mono_option mono_opt;
118+
enum orientation orientation;
119+
enum orientation blendDirection;
120+
int userEQ_keys, userEQ_enabled, col, bgcol, autobars, stereo, raw_format, ascii_range,
121+
bit_format, gradient, gradient_count, horizontal_gradient, horizontal_gradient_count,
122+
fixedbars, framerate, bar_width, bar_spacing, bar_height, autosens, overshoot, waves,
123+
active, remix, virtual_node, samplerate, samplebits, channels, autoconnect, sleep_timer,
124+
sdl_width, sdl_height, sdl_x, sdl_y, sdl_full_screen, draw_and_quit, zero_test,
125+
non_zero_test, reverse, sync_updates, continuous_rendering, disable_blanking,
126+
show_idle_bar_heads, waveform, center_align;
127+
};
128+
129+
struct error_s {
130+
char message[MAX_ERROR_LEN];
131+
int length;
132+
};
133+
134+
bool load_config(char configPath[PATH_MAX], struct config_params *p, struct error_s *error);
135+
bool load_colors(char *themeFile, struct config_params *p, struct error_s *error);
136+
void free_config(struct config_params *p);
137+
bool get_themeFile(char configPath[PATH_MAX], struct config_params *p, char *cava_config_home,
138+
struct error_s *error, char **themeFile);

include/cava/debug.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
3+
#ifdef NDEBUG
4+
#define debug(...) \
5+
do { \
6+
} while (0)
7+
#else
8+
#define debug(...) fprintf(stderr, __VA_ARGS__)
9+
#endif

include/cava/input/alsa.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// header file for alsa, part of cava.
2+
3+
#pragma once
4+
5+
void *input_alsa(void *data);

include/cava/input/common.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#include <errno.h>
4+
#include <fcntl.h>
5+
#include <inttypes.h>
6+
#include <pthread.h>
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <string.h>
10+
11+
#ifndef _WIN32
12+
#include <unistd.h>
13+
#endif
14+
15+
// number of samples to read from audio source per channel
16+
#define BUFFER_SIZE 512
17+
18+
struct audio_data {
19+
double *cava_in;
20+
21+
int input_buffer_size;
22+
int cava_buffer_size;
23+
24+
int format;
25+
unsigned int rate;
26+
unsigned int channels;
27+
int threadparams; // shared variable used to prevent main thread from cava_init before input
28+
// threads have finalized parameters (0=allow cava_init, 1=disallow)
29+
char *source; // alsa device, fifo path or pulse source
30+
int im; // input mode alsa, fifo, pulse, portaudio, shmem or sndio
31+
int terminate; // shared variable used to terminate audio thread
32+
char error_message[1024];
33+
int samples_counter;
34+
int IEEE_FLOAT; // format for 32bit (0=int, 1=float)
35+
int autoconnect; // auto connect to audio source (0=off, 1=once at startup, 2=regularly)
36+
int active; // actively monitor sources when the graph is idle
37+
int remix; // remix the incoming stream to this many channels
38+
int virtual_node; // set node.virtual to avoid recording notifications
39+
pthread_mutex_t lock;
40+
};
41+
42+
void reset_output_buffers(struct audio_data *data);
43+
void signal_threadparams(struct audio_data *data);
44+
void signal_terminate(struct audio_data *data);
45+
46+
int write_to_cava_input_buffers(int16_t size, unsigned char *buf, void *data);
47+
48+
extern pthread_mutex_t lock;

include/cava/input/fifo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// header files for fifo, part of cava
2+
3+
#pragma once
4+
5+
void *input_fifo(void *data);

include/cava/input/jack.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// header file for jack, part of cava.
2+
3+
#pragma once
4+
5+
void *input_jack(void *data);

include/cava/input/oss.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// header file for oss, part of cava.
2+
3+
#pragma once
4+
5+
void *input_oss(void *data);

include/cava/input/pipewire.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// header file for pipewire, part of cava.
2+
3+
#pragma once
4+
5+
void *input_pipewire(void *data);

0 commit comments

Comments
 (0)