File: dyn.c

package info (click to toggle)
sox 12.16-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,180 kB
  • ctags: 1,466
  • sloc: ansic: 16,658; sh: 2,071; makefile: 126
file content (111 lines) | stat: -rw-r--r-- 1,914 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifdef USE_DYN
/*
 * July 5, 1991
 * Copyright 1991 Lance Norskog And Sundry Contributors
 * This source code is freely redistributable and may be used for
 * any purpose.  This copyright notice must be maintained. 
 * Lance Norskog And Sundry Contributors are not responsible for 
 * the consequences of using this software.
 */

/*
 * Sound Tools dynamic compander effect file.
 *
 * Compresses or expands dynamic range, i.e. range between
 * soft and loud sounds.  U-law compression basically does this.
 *
 * Doesn't work.  Giving up for now.
 */

#include <math.h>
#include "st.h"

/* Private data for DYN.C file */
typedef struct dyn{
	int	rest;			/* bytes remaining in current block */
} *dyn_t;

/*
 * Process options
 */
void dyn_getopts(effp, n, argv) 
eff_t effp;
int n;
char **argv;
{
	if (n)
		fail("Copy effect takes no options.");
}

/*
 * Prepare processing.
 */
void dyn_start(effp)
eff_t effp;
{
	/* nothing to do */
	/* stuff data into delaying effects here */
}

/*
 * Processed signed long samples from ibuf to obuf.
 * Return number of samples processed.
 */

void dyn_flow(effp, ibuf, obuf, isamp, osamp)
eff_t effp;
LONG *ibuf, *obuf;
int *isamp, *osamp;
{
	int len, done;
	
	LONG l;
	double d, tmp;
	int sign;

#define NORMIT (65536.0)

	len = ((*isamp > *osamp) ? *osamp : *isamp);
	for(done = 0; done < len; done++) {

		d = *ibuf++;
		if (d == 0.0)
			l = 0;
		else {
			if (d < 0.0) {
				d *= -1.0;
				sign = -1;
			} else
				sign = 1;
			d /= NORMIT;
			tmp = log10(d);
			tmp = pow(8.0, tmp);
			tmp = tmp * NORMIT;
			l = tmp * sign;
		}
		*obuf++ = l;
	}
}

/*
 * Drain out remaining samples if the effect generates any.
 */

void dyn_drain(effp, obuf, osamp)
LONG *obuf;
int *osamp;
{
	*osamp = 0;
}

/*
 * Do anything required when you stop reading samples.  
 *	(free allocated memory, etc.)
 */
void dyn_stop(effp)
eff_t effp;
{
	/* nothing to do */
}

#endif /* USE_DYN */