Digitális hangminták
Gaga
Típusdefiníciók | Enumerációk | Függvények
delay.c fájlreferencia

Stereo PCM to PCM delay plugin. Részletek...

#include <stdio.h>
#include "binary_streams.h"

Ugrás a fájl forráskódjához.

Típusdefiníciók

typedef float sample_t
 type of a single sample
 

Enumerációk

enum  { SAMPLE_RATE = 44100, N = SAMPLE_RATE }
 

Függvények

int main (int argc, char **argv)
 the plugin main function Részletek...
 

Részletes leírás

Stereo PCM to PCM delay plugin.

Szerző
P. Fiala
Dátum
2020-12-07

Definíció a(z) delay.c fájlban.

Enumerációk dokumentációja

◆ anonymous enum

anonymous enum
Enumeráció-értékek
SAMPLE_RATE 

the sampe rate in Hz

size of the delay line in samples

Definíció a(z) delay.c fájl 13. sorában.

14 {
15  SAMPLE_RATE = 44100,
16  N = SAMPLE_RATE
17 };

Függvények dokumentációja

◆ main()

int main ( int  argc,
char **  argv 
)

the plugin main function

Paraméterek
argcnumber of command line arguments
argvargument vector
Visszatérési érték
int zero for success

Definíció a(z) delay.c fájl 25. sorában.

26 {
27  // delay time
28  double T = .2;
29  // delay attenuation
30  double alpha = .5;
31  if (argc >= 3)
32  {
33  sscanf(argv[1], "%lf", &T);
34  sscanf(argv[2], "%lf", &alpha);
35  }
36 
37  int K = SAMPLE_RATE * T;
38  sample_t circ_buffer[N][2] = {0};
39 
40  // reopen streams as binary
42 
43  int cnt = 0;
44  sample_t samples[2];
45  while (fread(samples, sizeof(sample_t), 2, stdin) == 2)
46  {
47  int c;
48  for (c = 0; c < 2; ++c)
49  {
50  circ_buffer[cnt][c] *= alpha; // attenuate past
51  circ_buffer[cnt][c] += samples[c]; // add present
52  }
53 
54  // write present + past
55  fwrite(circ_buffer[cnt], sizeof(sample_t), 2, stdout);
56 
57  cnt++; // circular indexing
58  cnt %= K;
59  }
60 
61  return 0;
62 }

Hivatkozások binary_streams, N és SAMPLE_RATE.

sample_t
float sample_t
type of a single sample
Definition: amplify.c:11
SAMPLE_RATE
@ SAMPLE_RATE
the sampe rate in Hz
Definition: delay.c:15
binary_streams
#define binary_streams()
reopen standard streams as binary
Definition: binary_streams.h:17
N
@ N
size of the delay line in samples
Definition: delay.c:16