File: signpr_exper.c

package info (click to toggle)
gramofile 1.6-11
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,436 kB
  • ctags: 1,125
  • sloc: ansic: 11,252; makefile: 60
file content (93 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* Experimenting Filter

 * Copyright (C) 1998 J.A. Bezemer
 *
 * Licensed under the terms of the GNU General Public License.
 * ABSOLUTELY NO WARRANTY.
 * See the file `COPYING' in this directory.
 */

/* You can experiment with this filter to your hearts desire. Currently,
   samples x[t-100] through x[t+100] are accessible. An example
   smoothing filter is presented below, so you can get an idea how
   to program things. */

#include "signpr_exper.h"
#include "signpr_general.h"
#include "errorwindow.h"
#include <math.h>


void
experiment_param_defaults (parampointer_t parampointer)
{
}

void
experiment_param_screen (parampointer_t parampointer)
{
  error_window ("This is a filter with which you can experiment. The \
source code is in signpr_exper.c");
}

void
init_experiment_filter (int filterno, parampointer_t parampointer)
{
  parampointer->buffer = init_buffer (100, 100);

  parampointer->filterno = filterno;
}

void
delete_experiment_filter (parampointer_t parampointer)
{
  delete_buffer (&parampointer->buffer);
}


sample_t
experiment_filter (parampointer_t parampointer)
{
  sample_t sample;
  longsample_t longsample;
/* doublesample_t doublesample; */

  advance_current_pos (&parampointer->buffer, parampointer->filterno);

/* Example: a smoothing filter (lowpass, that is):

   y[t] = { x[t-2] + 5*x[t-1] + 13*x[t] + 5*x[t+1] + x[t+2] } / 25
 */

  /* zero totals */
  longsample.left = 0;
  longsample.right = 0;

  /* compute the weighted sum */
  sample = get_from_buffer (&parampointer->buffer, -2);
  longsample.left += sample.left;
  longsample.right += sample.right;

  sample = get_from_buffer (&parampointer->buffer, -1);
  longsample.left += 5 * sample.left;
  longsample.right += 5 * sample.right;

  sample = get_from_buffer (&parampointer->buffer, 0);
  longsample.left += 13 * sample.left;
  longsample.right += 13 * sample.right;

  sample = get_from_buffer (&parampointer->buffer, 1);
  longsample.left += 5 * sample.left;
  longsample.right += 5 * sample.right;

  sample = get_from_buffer (&parampointer->buffer, 2);
  longsample.left += sample.left;
  longsample.right += sample.right;

  /* devide by the total weight */
  sample.left = longsample.left / 25;
  sample.right = longsample.right / 25;

  /* return the computed sample */
  return sample;
}