File: sbdsp.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 (167 lines) | stat: -rw-r--r-- 3,549 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

char ansi_c_is_very_stupid_and_needs_a_variable_here;

#if	defined(BLASTER) || defined(SBLAST)
/*
 * Copyright 1992 Rick Richardson
 * 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. 
 * Rick Richardson, Lance Norskog And Sundry Contributors are not
 * responsible for the consequences of using this software.
 */

/*
 * Direct to Sound Blaster device driver.
 * SBLAST patches by John T. Kohl.
 */

#include <sys/types.h>
#ifdef SBLAST
#include <i386/isa/sblast.h>
#else
#include <sys/sb.h>
#endif
#include <signal.h>
#include "st.h"

/* Private data for SKEL file */
typedef struct sbdspstuff {
	int	samples;		/* bytes remaining in current block */
} *sbdsp_t;

static got_int = 0;

static void
sigint(s)
int s;
{
	if (s) got_int = 1;
	else signal(SIGINT, sigint);
}

/*
 * Do anything required before you start reading samples.
 * Read file header. 
 *	Find out sampling rate, 
 *	size and style of samples, 
 *	mono/stereo/quad.
 */
sbdspstartread(ft) 
ft_t ft;
{
	sbdsp_t sbdsp = (sbdsp_t) ft->priv;
#ifdef	SBLAST
	int off = 0;
#endif

	/* The following is needed to init block reads */
	rawstartread(ft);

	/* If you need to seek around the input file. */
	if (0 && ! ft->seekable)
		fail("SKEL input file must be a file, not a pipe");

	if (!ft->info.rate)
		ft->info.rate = 11000;
	ft->info.size = BYTE;
	ft->info.style = UNSIGNED;
	ft->info.channels = 1;
	ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
#ifdef SBLAST
	ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, &off);
	ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, &ft->info.rate);
#else
	ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 0);
	ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
#endif
	sigint(0);	/* Prepare to catch SIGINT */
}

/*
 * Read up to len samples from file.
 * Convert to signed longs.
 * Place in buf[].
 * Return number of samples read.
 */

sbdspread(ft, buf, len) 
ft_t ft;
LONG *buf, len;
{
	sbdsp_t sbdsp = (sbdsp_t) ft->priv;
	int		rc;

	if (got_int) return (0);
	rc = rawread(ft, buf, len);
	if (rc < 0) return 0;
	return (rc);
}

/*
 * Do anything required when you stop reading samples.  
 * Don't close input file! 
 */
sbdspstopread(ft) 
ft_t ft;
{
	rawstopread(ft);

#ifdef SBLAST
	ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
#endif
}

sbdspstartwrite(ft) 
ft_t ft;
{
	sbdsp_t sbdsp = (sbdsp_t) ft->priv;
#ifdef	SBLAST
	int on = 1;
#endif

	rawstartwrite(ft);

	/* If you have to seek around the output file */
	if (0 && ! ft->seekable)
		fail("Output .sbdsp file must be a file, not a pipe");

	if (!ft->info.rate)
		ft->info.rate = 11000;
	ft->info.size = BYTE;
	ft->info.style = UNSIGNED;
	ft->info.channels = 1;
	ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
#ifdef SBLAST
	ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
	ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, &on);
	ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, &ft->info.rate);
#else
	ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 1);
	ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
#endif
}

sbdspwrite(ft, buf, len) 
ft_t ft;
LONG *buf, len;
{
	sbdsp_t sbdsp = (sbdsp_t) ft->priv;

	if (len == 0) return 0;
	return (rawwrite(ft, buf, len));
}

sbdspstopwrite(ft) 
ft_t ft;
{
	/* This is needed to flush out block writes */
	rawstopwrite(ft);

	/* All samples are already written out. */
	/* If file header needs fixing up, for example it needs the */
 	/* the number of samples in a field, seek back and write them here. */
	fflush(ft->fp);
	ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
}
#endif