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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 | /*-*- Mode: C; c-basic-offset: 8 -*-*/
/***
This file is part of libkanberra.
Copyright 2008 Lennart Poettering
libkanberra is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 2.1 of the
License, or (at your option) any later version.
libkanberra is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libkanberra. If not, see
<http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include "read-sound-file.h"
#include "read-wav.h"
#include "read-vorbis.h"
#include "macro.h"
#include "malloc.h"
#include "kanberra.h"
struct ka_sound_file {
ka_wav *wav;
ka_vorbis *vorbis;
char *filename;
unsigned nchannels;
unsigned rate;
ka_sample_type_t type;
};
int ka_sound_file_open(ka_sound_file **_f, const char *fn) {
FILE *file;
ka_sound_file *f;
int ret;
ka_return_val_if_fail(_f, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(fn, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (!(f = ka_new0(ka_sound_file, 1)))
return KA_ERROR_OOM;
if (!(f->filename = ka_strdup(fn))) {
ret = KA_ERROR_OOM;
goto fail;
}
if (!(file = fopen(fn, "r"))) {
ret = errno == ENOENT ? KA_ERROR_NOTFOUND : KA_ERROR_SYSTEM;
goto fail;
}
if ((ret = ka_wav_open(&f->wav, file)) == KA_SUCCESS) {
f->nchannels = ka_wav_get_nchannels(f->wav);
f->rate = ka_wav_get_rate(f->wav);
f->type = ka_wav_get_sample_type(f->wav);
*_f = f;
return KA_SUCCESS;
}
if (ret == KA_ERROR_CORRUPT) {
if (fseek(file, 0, SEEK_SET) < 0) {
ret = KA_ERROR_SYSTEM;
goto fail;
}
if ((ret = ka_vorbis_open(&f->vorbis, file)) == KA_SUCCESS) {
f->nchannels = ka_vorbis_get_nchannels(f->vorbis);
f->rate = ka_vorbis_get_rate(f->vorbis);
f->type = KA_SAMPLE_S16NE;
*_f = f;
return KA_SUCCESS;
}
}
fail:
ka_free(f->filename);
ka_free(f);
return ret;
}
void ka_sound_file_close(ka_sound_file *f) {
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (f->wav)
ka_wav_close(f->wav);
if (f->vorbis)
ka_vorbis_close(f->vorbis);
ka_free(f->filename);
ka_free(f);
}
unsigned ka_sound_file_get_nchannels(ka_sound_file *f) {<--- Parameter 'f' can be declared as pointer to const
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
return f->nchannels;
}
unsigned ka_sound_file_get_rate(ka_sound_file *f) {<--- Parameter 'f' can be declared as pointer to const
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
return f->rate;
}
ka_sample_type_t ka_sound_file_get_sample_type(ka_sound_file *f) {<--- Parameter 'f' can be declared as pointer to const
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
return f->type;
}
const ka_channel_position_t* ka_sound_file_get_channel_map(ka_sound_file *f) {
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (f->wav)
return ka_wav_get_channel_map(f->wav);
else
return ka_vorbis_get_channel_map(f->vorbis);
}
int ka_sound_file_read_int16(ka_sound_file *f, int16_t *d, size_t *n) {
ka_return_val_if_fail(f, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(d, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(n, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(f->wav || f->vorbis, KA_ERROR_STATE);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(f->type == KA_SAMPLE_S16NE || f->type == KA_SAMPLE_S16RE, KA_ERROR_STATE);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (f->wav)
return ka_wav_read_s16le(f->wav, d, n);
else
return ka_vorbis_read_s16ne(f->vorbis, d, n);
}
int ka_sound_file_read_uint8(ka_sound_file *f, uint8_t *d, size_t *n) {
ka_return_val_if_fail(f, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(d, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(n, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(f->wav && !f->vorbis, KA_ERROR_STATE);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(f->type == KA_SAMPLE_U8, KA_ERROR_STATE);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (f->wav)<--- Condition 'f->wav' is always true
return ka_wav_read_u8(f->wav, d, n);
return KA_ERROR_STATE;
}
int ka_sound_file_read_arbitrary(ka_sound_file *f, void *d, size_t *n) {
int ret;
ka_return_val_if_fail(f, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(d, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(n, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
ka_return_val_if_fail(*n > 0, KA_ERROR_INVALID);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
switch (f->type) {
case KA_SAMPLE_S16NE:
case KA_SAMPLE_S16RE: {
size_t k;
k = *n / sizeof(int16_t);
if ((ret = ka_sound_file_read_int16(f, d, &k)) == KA_SUCCESS)
*n = k * sizeof(int16_t);
break;
}
case KA_SAMPLE_U8: {
size_t k;
k = *n;
if ((ret = ka_sound_file_read_uint8(f, d, &k)) == KA_SUCCESS)
*n = k;
break;
}
default:
ka_assert_not_reached();<--- %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.
}
return ret;
}
off_t ka_sound_file_get_size(ka_sound_file *f) {
ka_return_val_if_fail(f, (off_t) -1);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
if (f->wav)
return ka_wav_get_size(f->wav);
else
return ka_vorbis_get_size(f->vorbis);
}
size_t ka_sound_file_frame_size(ka_sound_file *f) {
unsigned c;
ka_assert(f);<--- %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.
c = ka_sound_file_get_nchannels(f);
return c * (ka_sound_file_get_sample_type(f) == KA_SAMPLE_U8 ? 1U : 2U);<--- int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information. [+]int result is returned as long value. If the return value is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'return a*b;' => 'return (long)a*b'.
}
|