Debian Codegraph @

test/sixteen-to-eight.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 Audio File Library
3
4 Copyright 2000, Silicon Graphics, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 /*
22 sixteen-to-eight.c
23
24 This program tests the conversion from 16-bit integers to 8-bit
25 integers.
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include <stdint.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <limits.h>
38
39 #include <audiofile.h>
40
41 #include "TestUtilities.h"
42
43 int main (int argc, char **argv)
44 {
45 AFfilehandle file;
46 AFfilesetup setup;
47 int16_t frames16[] = {14298, 392, 3923, -683, 958, -1921};
48 int8_t frames8[] = {55, 1, 15, -3, 3, -8};
49 int i, frameCount = 6;
50 int8_t byte;
51 AFframecount result;
52
53 setup = afNewFileSetup();
54
55 afInitFileFormat(setup, AF_FILE_WAVE);
56
57 afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_UNSIGNED, 8);
58 afInitChannels(setup, AF_DEFAULT_TRACK, 1);
59
60 char testFileName[PATH_MAX];
61 if (!createTemporaryFile("sixteen-to-eight", testFileName))
62 {
63 fprintf(stderr, "Could not create temporary file.\n");
64 exit(EXIT_FAILURE);
65 }
66
67 file = afOpenFile(testFileName, "w", setup);
68 if (file == AF_NULL_FILEHANDLE)
69 {
70 fprintf(stderr, "could not open file for writing\n");
71 exit(EXIT_FAILURE);
72 }
73
74 afFreeFileSetup(setup);
75
76 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
77
78 afWriteFrames(file, AF_DEFAULT_TRACK, frames16, frameCount);
79
80 afCloseFile(file);
81
82 file = afOpenFile(testFileName, "r", AF_NULL_FILESETUP);
83 if (file == AF_NULL_FILEHANDLE)
84 {
85 fprintf(stderr, "could not open file for reading\n");
86 exit(EXIT_FAILURE);
87 }
88
89 afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 8);
90
91 for (i=0; i<frameCount; i++)
92 {
93 /* Read one frame. */
94 result = afReadFrames(file, AF_DEFAULT_TRACK, &byte, 1);
95
96 if (result != 1)
97 break;
98
99 /* Compare the byte read with its precalculated value. */
100 if (memcmp(&byte, &frames8[i], 1) != 0)
101 {
102 printf("error\n");
103 printf("expected %d, got %d\n", frames8[i], byte);
104 exit(EXIT_FAILURE);
105 }
106 else
107 {
108 #ifdef DEBUG
109 printf("got what was expected: %d\n", byte);
110 #endif
111 }
112 }
113
114 afCloseFile(file);
115 unlink(testFileName);
116
117 exit(EXIT_SUCCESS);
118 }