File: silence.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 (112 lines) | stat: -rw-r--r-- 2,290 bytes parent folder | download
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
112
/*
 * silence - effect to detect periods of silence in audio data and
 *    use this to clip data before and after.
 *
 * Written by Chris Bagwell (cbagwell@sprynet.com) - January 10, 1999
 *
  * Copyright 1999 Chris Bagwell And Sundry Contributors
 * This source code is freely redistributable and may be used for
 * any purpose.  This copyright notice must be maintained. 
 * Chris Bagwell And Sundry Contributors are not responsible for 
 * the consequences of using this software.
 */


#include "st.h"

/* Private data for SKEL file */
typedef struct silencestuff {
        int     threshold;
        int     threshold_length;
        int     threshold_count;
        int     begin;
        int     begin_skip;
        int     begin_count;
        int     end;
        int     end_skip;
        int     end_count;
} *silenc_t;

/*
 * Process options
 *
 * Don't do initialization now.
 * The 'info' fields are not yet filled in.
 */
void silence_getopts(effp, n, argv) 
eff_t effp;
int n;
char **argv;
{
	if (n)
		fail("Silence effect takes no options.");
}

/*
 * Prepare processing.
 * Do all initializations.
 */
silence_start(effp)
eff_t effp;
{
    silence_t silence = (silence_t) effp->priv;

    silence.threshold = 5;
    silence.thres_length = 1000;
    silence.thres_count = 0;

    silence.begin = silence.end = 0;
    silence.begin_skip = silence.end_skip = 0;
    silence.begin_count = silence.end_count = 0;
}

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

void silence_flow(effp, ibuf, obuf, isamp, osamp)
eff_t effp;
LONG *ibuf, *obuf;
int *isamp, *osamp;
{
	silence_t silence = (silence_t) effp->priv;
	int len, done;
	
	len = ((*isamp > *osamp) ? *osamp : *isamp);
	for(done = 0; done < len; done++) {
	    if (silence.threshold_count >= silence.threshold_length) { 
	        
	        
		if no more samples
			break
		get a sample
		l = sample converted to signed long
		*buf++ = l;
	}
	*isamp = 
	*osamp = 
}

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

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

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