File: cut.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 (116 lines) | stat: -rw-r--r-- 2,192 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
112
113
114
115
116

/*
 * 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 cut effect file.
 *
 * Pull loop #n from a looped sound file.
 * Not finished, don't use it yet.
 */

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

/* Private data for SKEL file */
typedef struct cutstuff {
	int	which;			/* Loop # to pull */
	int	where;			/* current sample # */
	ULONG start;			/* first wanted sample */
	ULONG end;			/* last wanted sample + 1 */
} *cut_t;

/*
 * Process options
 */
void cut_getopts(effp, n, argv) 
eff_t effp;
int n;
char **argv;
{
	cut_t cut = (cut_t) effp->priv;

	/* parse it */
	cut->which = 0;	/* for now */
}

/*
 * Prepare processing.
 */
void cut_start(effp)
eff_t effp;
{
	cut_t cut = (cut_t) effp->priv;
	/* nothing to do */

	cut->where = 0;
	cut->start = effp->loops[0].start;
	cut->end = effp->loops[0].start + effp->loops[0].length;
}

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

void cut_flow(effp, ibuf, obuf, isamp, osamp)
eff_t effp;
LONG *ibuf, *obuf;
int *isamp, *osamp;
{
	cut_t cut = (cut_t) effp->priv;
	int len, done;
	
	len = ((*isamp > *osamp) ? *osamp : *isamp);
	if ((cut->where + len <= cut->start) ||
			(cut->where >= cut->end)) {
		*isamp = len;
		*osamp = 0;
		cut->where += len;
		return;
	}
	*isamp = len;		/* We will have processed all inputs */
	if (cut->where < cut->start) {
		/* skip */
		ibuf += cut->start - cut->where;
		len -= cut->start - cut->where;
	}
	if (cut->where + len >= cut->end) {
		/* shorten */
		len = cut->end - cut->where;
	}
	for(done = 0; done < len; done++) {
		*obuf++ = *ibuf++;
	}
	*osamp = len;
}

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

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

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