Digitális hangminták
Gaga
vibrato.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(int argc, char **argv)
27 {
28  double const f_vib = 2.0;
29  int const depth = 60;
30  if (argc >= 3)
31  {
32  sscanf(argv[1], "%lf", &f_vib);
33  sscanf(argv[2], "%d", &depth);
34  }
35 
36  sample_t circ_buffer[N][2] = {0};
37 
38  // reopen streams as binary
40 
41  long long int cnt = 0;
42  int write = 0, read = N / 2;
43 
44  while (fread(circ_buffer[write], sizeof(sample_t), 2, stdin) == 2)
45  {
46  int r = read + sin(2.0 * M_PI * f_vib / SAMPLE_RATE * cnt++) * depth;
47  if (r < 0)
48  r += N;
49  fwrite(circ_buffer[r % N], sizeof(sample_t), 2, stdout);
50 
51  write = (write + 1) % N;
52  read = (read + 1) % N;
53  }
54 
55  return 0;
56 }
binary_streams.h
open standard streams in binary mode
sample_t
float sample_t
type of a single sample
Definition: vibrato.c:12
sample_t
float sample_t
type of a single sample
Definition: amplify.c:11
N
@ N
Definition: vibrato.c:17
SAMPLE_RATE
@ SAMPLE_RATE
Definition: vibrato.c:16
binary_streams
#define binary_streams()
reopen standard streams as binary
Definition: binary_streams.h:17
main
int main(int argc, char **argv)
the plugin main function
Definition: vibrato.c:26