summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp
index fc0130c..360b884 100644
--- a/noncore/multimedia/opierec/wavFile.cpp
+++ b/noncore/multimedia/opierec/wavFile.cpp
@@ -149,15 +149,13 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
149 (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align 149 (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align
150 (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 150 (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16
151 151
152 strncpy((*hdr).dataID, "data", 4); 152 strncpy((*hdr).dataID, "data", 4);
153 153
154 write( fd,hdr, sizeof(*hdr)); 154 write( fd,hdr, sizeof(*hdr));
155 odebug << "writing header: bitrate " << wavResolution 155 odebug << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl;
156 << ", samplerate " << wavSampleRate
157 << ", channels " << wavChannels << oendl;
158 return true; 156 return true;
159} 157}
160 158
161bool WavFile::adjustHeaders(int fd, int total) { 159bool WavFile::adjustHeaders(int fd, int total) {
162 lseek(fd, 4, SEEK_SET); 160 lseek(fd, 4, SEEK_SET);
163 int i = total + 36; 161 int i = total + 36;
@@ -174,102 +172,102 @@ int WavFile::parseWavHeader(int fd) {
174 int found; 172 int found;
175 short fmt; 173 short fmt;
176 unsigned short ch, bitrate; 174 unsigned short ch, bitrate;
177 unsigned long samplerrate, longdata; 175 unsigned long samplerrate, longdata;
178 176
179 if (read(fd, string, 4) < 4) { 177 if (read(fd, string, 4) < 4) {
180 odebug << " Could not read from sound file.\n" << oendl; 178 odebug << " Could not read from sound file." << oendl;
181 return -1; 179 return -1;
182 } 180 }
183 if (strncmp(string, "RIFF", 4)) { 181 if (strncmp(string, "RIFF", 4)) {
184 odebug << " not a valid WAV file.\n" << oendl; 182 odebug << " not a valid WAV file." << oendl;
185 return -1; 183 return -1;
186 } 184 }
187 lseek(fd, 4, SEEK_CUR); 185 lseek(fd, 4, SEEK_CUR);
188 if (read(fd, string, 4) < 4) { 186 if (read(fd, string, 4) < 4) {
189 odebug << "Could not read from sound file.\n" << oendl; 187 odebug << "Could not read from sound file." << oendl;
190 return -1; 188 return -1;
191 } 189 }
192 if (strncmp(string, "WAVE", 4)) { 190 if (strncmp(string, "WAVE", 4)) {
193 odebug << "not a valid WAV file.\n" << oendl; 191 odebug << "not a valid WAV file." << oendl;
194 return -1; 192 return -1;
195 } 193 }
196 found = 0; 194 found = 0;
197 195
198 while (!found) { 196 while (!found) {
199 if (read(fd, string, 4) < 4) { 197 if (read(fd, string, 4) < 4) {
200 odebug << "Could not read from sound file.\n" << oendl; 198 odebug << "Could not read from sound file." << oendl;
201 return -1; 199 return -1;
202 } 200 }
203 if (strncmp(string, "fmt ", 4)) { 201 if (strncmp(string, "fmt ", 4)) {
204 if (read(fd, &longdata, 4) < 4) { 202 if (read(fd, &longdata, 4) < 4) {
205 odebug << "Could not read from sound file.\n" << oendl; 203 odebug << "Could not read from sound file." << oendl;
206 return -1; 204 return -1;
207 } 205 }
208 lseek(fd, longdata, SEEK_CUR); 206 lseek(fd, longdata, SEEK_CUR);
209 } else { 207 } else {
210 lseek(fd, 4, SEEK_CUR); 208 lseek(fd, 4, SEEK_CUR);
211 if (read(fd, &fmt, 2) < 2) { 209 if (read(fd, &fmt, 2) < 2) {
212 odebug << "Could not read format chunk.\n" << oendl; 210 odebug << "Could not read format chunk." << oendl;
213 return -1; 211 return -1;
214 } 212 }
215 if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { 213 if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) {
216 odebug << "Wave file contains unknown format. Unable to continue.\n" << oendl; 214 odebug << "Wave file contains unknown format. Unable to continue." << oendl;
217 return -1; 215 return -1;
218 } 216 }
219 wavFormat = fmt; 217 wavFormat = fmt;
220 // compressionFormat=fmt; 218 // compressionFormat=fmt;
221 odebug << "compressionFormat is " << fmt << "" << oendl; 219 odebug << "compressionFormat is " << fmt << "" << oendl;
222 if (read(fd, &ch, 2) < 2) { 220 if (read(fd, &ch, 2) < 2) {
223 odebug << "Could not read format chunk.\n" << oendl; 221 odebug << "Could not read format chunk." << oendl;
224 return -1; 222 return -1;
225 } else { 223 } else {
226 wavChannels = ch; 224 wavChannels = ch;
227 odebug << "File has " << ch << " channels" << oendl; 225 odebug << "File has " << ch << " channels" << oendl;
228 } 226 }
229 if (read(fd, &samplerrate, 4) < 4) { 227 if (read(fd, &samplerrate, 4) < 4) {
230 odebug << "Could not read from format chunk.\n" << oendl; 228 odebug << "Could not read from format chunk." << oendl;
231 return -1; 229 return -1;
232 } else { 230 } else {
233 wavSampleRate = samplerrate; 231 wavSampleRate = samplerrate;
234 // sampleRate = samplerrate; 232 // sampleRate = samplerrate;
235 odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; 233 odebug << "File has samplerate of " << (int) samplerrate << "" << oendl;
236 } 234 }
237 lseek(fd, 6, SEEK_CUR); 235 lseek(fd, 6, SEEK_CUR);
238 if (read(fd, &bitrate, 2) < 2) { 236 if (read(fd, &bitrate, 2) < 2) {
239 odebug << "Could not read format chunk.\n" << oendl; 237 odebug << "Could not read format chunk." << oendl;
240 return -1; 238 return -1;
241 } else { 239 } else {
242 wavResolution=bitrate; 240 wavResolution=bitrate;
243 // resolution = bitrate; 241 // resolution = bitrate;
244 odebug << "File has bitrate of " << bitrate << "" << oendl; 242 odebug << "File has bitrate of " << bitrate << "" << oendl;
245 } 243 }
246 found++; 244 found++;
247 } 245 }
248 } 246 }
249 found = 0; 247 found = 0;
250 while (!found) { 248 while (!found) {
251 if (read(fd, string, 4) < 4) { 249 if (read(fd, string, 4) < 4) {
252 odebug << "Could not read from sound file.\n" << oendl; 250 odebug << "Could not read from sound file." << oendl;
253 return -1; 251 return -1;
254 } 252 }
255 253
256 if (strncmp(string, "data", 4)) { 254 if (strncmp(string, "data", 4)) {
257 if (read(fd, &longdata, 4)<4) { 255 if (read(fd, &longdata, 4)<4) {
258 odebug << "Could not read from sound file.\n" << oendl; 256 odebug << "Could not read from sound file." << oendl;
259 return -1; 257 return -1;
260 } 258 }
261 259
262 lseek(fd, longdata, SEEK_CUR); 260 lseek(fd, longdata, SEEK_CUR);
263 } else { 261 } else {
264 if (read(fd, &longdata, 4) < 4) { 262 if (read(fd, &longdata, 4) < 4) {
265 odebug << "Could not read from sound file.\n" << oendl; 263 odebug << "Could not read from sound file." << oendl;
266 return -1; 264 return -1;
267 } else { 265 } else {
268 wavNumberSamples = longdata; 266 wavNumberSamples = longdata;
269 odebug << "file hase length of " << (int)longdata << "\n" 267 odebug << "file hase length of " << (int)longdata << ""
270 << "lasting " 268 << "lasting "
271 << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) 269 << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8))
272 << " seconds" << oendl; 270 << " seconds" << oendl;
273// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); 271// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8));
274 272
275 return longdata; 273 return longdata;