File: nulfile.c

package info (click to toggle)
sox 12.17.3-4woody2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,048 kB
  • ctags: 2,183
  • sloc: ansic: 24,796; sh: 3,005; makefile: 228; perl: 133
file content (128 lines) | stat: -rw-r--r-- 2,455 bytes parent folder | download | duplicates (3)
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
/*
 * 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 nul file format driver.
 * Written by Carsten Borchardt 
 * The author is not responsible for the consequences 
 * of using this software
 *
 */

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

/* Private data for nul file */
typedef struct nulstuff {
	int	rest;			/* bytes remaining in current block */
    unsigned long readsamples;
    unsigned long writesamples;
} *nul_t;

/*
 * Do anything required before you start reading samples.
 * Read file header. 
 *	Find out sampling rate, 
 *	size and encoding of samples, 
 *	mono/stereo/quad.
 */
int st_nulstartread(ft_t ft) 
{
	nul_t sk = (nul_t) ft->priv;
	/* no samples read yet */
	sk->readsamples=0;

	/* if no input rate is given as parameter, switch to 
	 * default parameter
	 */
	if(ft->info.rate == 0){
	    /* input rate not set, switch to default */
	    ft->info.rate = 44100;
	    ft->info.size = ST_SIZE_WORD;
	    ft->info.encoding = ST_ENCODING_SIGN2;
	    ft->info.channels = 2;
	}
	ft->comment = "nul file";
	
	/* only SIGINT will stop us from reading nul data.. 
	 *
	 */
	sigintreg(ft);	/* Prepare to catch SIGINT */

	return (ST_SUCCESS);
}

/*
 * Read up to len samples, we read always '0'
 * Convert to signed longs.
 * Place in buf[].
 * Return number of samples read.
 */

st_ssize_t st_nulread(ft_t ft, st_sample_t *buf, st_ssize_t len) 
{
	nul_t sk = (nul_t) ft->priv;
	int done = 0;
	st_sample_t l;
	for(; done < len; done++) {
	    if (ft->file.eof)
		break;
	    l = 0; /* nul samples are always 0 */
	    sk->readsamples++;
	    *buf++ = l;
	}
	return done;
}

/*
 * Do anything required when you stop reading samples.  
 * Don't close input file! 
 * .. nothing to be done
 */
int st_nulstopread(ft_t ft) 
{ 
    return (ST_SUCCESS);
}

int st_nulstartwrite(ft_t ft) 
{
	nul_t sk = (nul_t) ft->priv;
	sk->writesamples=0;
	return(ST_SUCCESS);
	
}

st_ssize_t st_nulwrite(ft_t ft, st_sample_t *buf, st_ssize_t len) 
{
	nul_t sk = (nul_t) ft->priv;
	while(len--)
	    sk->writesamples++;
	st_writeb(ft, (*buf++ >> 24) ^ 0x80);
	return (ST_SUCCESS);
	
}

int st_nulstopwrite(ft_t ft) 
{
    /* nothing to do */
    return (ST_SUCCESS);
}