Digitális hangminták
Gaga
sound_file
chorus.c
Ugrás a fájl dokumentációjához.
1
7
#include <stdio.h>
8
#include <math.h>
9
#include "
binary_streams.h
"
10
12
typedef
float
sample_t
;
13
14
enum
15
{
16
SAMPLE_RATE
= 44100,
17
N
=
SAMPLE_RATE
/ 10
18
};
19
26
int
main
(
void
)
27
{
28
double
const
f_vib = 2.0;
29
int
const
depth = 60;
31
long
long
int
cnt = 0;
32
int
write = 0, read =
N
/ 2;
33
34
// reopen streams as binary
35
binary_streams
();
36
37
sample_t
circ_buffer[
N
][2] = {0};
38
39
// read samples while possible
40
while
(fread(circ_buffer[write],
sizeof
(
sample_t
), 2, stdin) == 2)
41
{
42
// update read index with harmonically varying offset
43
int
r = read + sin(2.0 * M_PI * f_vib /
SAMPLE_RATE
* cnt++) * depth;
44
if
(r < 0)
45
r +=
N
;
46
47
// read FIFO content and add to dry signal
48
sample_t
output[2];
49
for
(
int
c = 0; c < 2; ++c)
50
output[c] = circ_buffer[r %
N
][c] + circ_buffer[read][c];
51
52
// write to output
53
fwrite(output,
sizeof
(
sample_t
), 2, stdout);
54
55
// cyclic indexing
56
write = (write + 1) %
N
;
57
read = (read + 1) %
N
;
58
}
59
60
return
0;
61
}
binary_streams.h
open standard streams in binary mode
sample_t
float sample_t
type of a single sample
Definition:
amplify.c:11
N
@ N
Definition:
chorus.c:17
main
int main(void)
the plugin main function
Definition:
chorus.c:26
binary_streams
#define binary_streams()
reopen standard streams as binary
Definition:
binary_streams.h:17
SAMPLE_RATE
@ SAMPLE_RATE
Definition:
chorus.c:16
sample_t
float sample_t
type of a single sample
Definition:
chorus.c:12
Projekt: Digitális hangminták Készült: Hétfő December 7 2020 23:31:11 Készítette:
1.8.17