1 | /* |
---|
2 | Audio File Library |
---|
3 | |
---|
4 | Copyright (C) 2001, Silicon Graphics, Inc. |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU General Public License as |
---|
8 | published by the Free Software Foundation; either version 2 of |
---|
9 | the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be |
---|
12 | useful, but WITHOUT ANY WARRANTY; without even the implied |
---|
13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
14 | PURPOSE. See the GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public |
---|
17 | License along with this program; if not, write to the Free |
---|
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
19 | MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | /* |
---|
23 | pipe.c |
---|
24 | |
---|
25 | This program provides a simple test of Audio File Library |
---|
26 | operation on non-seekable file handles. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include <config.h> |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <audiofile.h> |
---|
34 | #include <stdio.h> |
---|
35 | #include <stdlib.h> |
---|
36 | |
---|
37 | #define SAMPLE_COUNT 12 |
---|
38 | #define FRAME_COUNT 6 |
---|
39 | |
---|
40 | void ensure (int condition, const char *message) |
---|
41 | { |
---|
42 | if (!condition) |
---|
43 | { |
---|
44 | printf("%s.\n", message); |
---|
45 | exit(EXIT_FAILURE); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | int main (int argc, char **argv) |
---|
50 | { |
---|
51 | AFfilesetup setup; |
---|
52 | AFfilehandle file; |
---|
53 | int16_t samples[SAMPLE_COUNT] = {-1,3,9,2,-5,4,8,-3,6,21,11,-2}; |
---|
54 | int output = 0; |
---|
55 | |
---|
56 | setup = afNewFileSetup(); |
---|
57 | |
---|
58 | afInitFileFormat(setup, AF_FILE_RAWDATA); |
---|
59 | afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); |
---|
60 | afInitChannels(setup, AF_DEFAULT_TRACK, 2); |
---|
61 | afInitRate(setup, AF_DEFAULT_TRACK, 44100); |
---|
62 | #ifdef WORDS_BIGENDIAN |
---|
63 | afInitByteOrder(setup, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN); |
---|
64 | #else |
---|
65 | afInitByteOrder(setup, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN); |
---|
66 | #endif |
---|
67 | |
---|
68 | if (argc > 1 && !strcmp(argv[1], "out")) |
---|
69 | output = 1; |
---|
70 | |
---|
71 | if (output) |
---|
72 | { |
---|
73 | AFframecount framesWritten; |
---|
74 | |
---|
75 | file = afOpenFD(1, "w", setup); |
---|
76 | |
---|
77 | afFreeFileSetup(setup); |
---|
78 | |
---|
79 | framesWritten = afWriteFrames(file, AF_DEFAULT_TRACK, samples, |
---|
80 | FRAME_COUNT); |
---|
81 | |
---|
82 | ensure(framesWritten == FRAME_COUNT, |
---|
83 | "incorrect number of frames written"); |
---|
84 | |
---|
85 | fprintf(stderr, "pipe write passed\n"); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | AFframecount framesRead; |
---|
90 | int16_t samplesRead[SAMPLE_COUNT]; |
---|
91 | |
---|
92 | file = afOpenFD(0, "r", setup); |
---|
93 | |
---|
94 | afFreeFileSetup(setup); |
---|
95 | |
---|
96 | framesRead = afReadFrames(file, AF_DEFAULT_TRACK, samplesRead, |
---|
97 | FRAME_COUNT); |
---|
98 | |
---|
99 | ensure(framesRead == FRAME_COUNT, |
---|
100 | "incorrect number of frames read"); |
---|
101 | |
---|
102 | ensure(memcmp(samplesRead, samples, |
---|
103 | SAMPLE_COUNT * sizeof (int16_t)) == 0, |
---|
104 | "samples read do not match samples written"); |
---|
105 | |
---|
106 | fprintf(stderr, "pipe read passed\n"); |
---|
107 | } |
---|
108 | |
---|
109 | afCloseFile(file); |
---|
110 | |
---|
111 | exit(EXIT_SUCCESS); |
---|
112 | } |
---|