1 /* libSoX file format: null (c) 2006-8 SoX contributors
2 * Based on an original idea by Carsten Borchardt
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or (at
7 * your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "sox_i.h"
20 #include <string.h>
21
startread(sox_format_t * ft)22 static int startread(sox_format_t * ft)
23 {
24 if (!ft->signal.rate) {
25 ft->signal.rate = SOX_DEFAULT_RATE;
26 lsx_report("sample rate not specified; using %g", ft->signal.rate);
27 }
28 ft->signal.precision = ft->encoding.bits_per_sample?
29 ft->encoding.bits_per_sample: SOX_SAMPLE_PRECISION;
30 /* Default number of channels is application-dependent */
31 return SOX_SUCCESS;
32 }
33
read_samples(sox_format_t * ft,sox_sample_t * buf,size_t len)34 static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len)
35 {
36 /* Reading from null generates silence i.e. (sox_sample_t)0. */
37 (void)ft;
38 memset(buf, 0, sizeof(sox_sample_t) * len);
39 return len; /* Return number of samples "read". */
40 }
41
write_samples(sox_format_t * ft,sox_sample_t const * buf,size_t len)42 static size_t write_samples(
43 sox_format_t * ft, sox_sample_t const * buf, size_t len)
44 {
45 /* Writing to null just discards the samples */
46 (void)ft, (void)buf;
47 return len; /* Return number of samples "written". */
48 }
49
LSX_FORMAT_HANDLER(nul)50 LSX_FORMAT_HANDLER(nul)
51 {
52 static const char * const names[] = {"null", NULL};
53 static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
54 NULL, names, SOX_FILE_DEVICE | SOX_FILE_PHONY | SOX_FILE_NOSTDIO,
55 startread, read_samples,NULL,NULL, write_samples,NULL,NULL, NULL, NULL, 0
56 };
57 return &handler;
58 }
59