summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -143,139 +143,137 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
// (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels
(*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels
(*hdr).sampleRate = wavSampleRate; //samples per second
(*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second
(*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align
(*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16
strncpy((*hdr).dataID, "data", 4);
write( fd,hdr, sizeof(*hdr));
- odebug << "writing header: bitrate " << wavResolution
- << ", samplerate " << wavSampleRate
- << ", channels " << wavChannels << oendl;
+ odebug << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl;
return true;
}
bool WavFile::adjustHeaders(int fd, int total) {
lseek(fd, 4, SEEK_SET);
int i = total + 36;
write( fd, &i, sizeof(i));
lseek( fd, 40, SEEK_SET);
write( fd, &total, sizeof(total));
odebug << "adjusting header " << total << "" << oendl;
return true;
}
int WavFile::parseWavHeader(int fd) {
odebug << "Parsing wav header" << oendl;
char string[4];
int found;
short fmt;
unsigned short ch, bitrate;
unsigned long samplerrate, longdata;
if (read(fd, string, 4) < 4) {
- odebug << " Could not read from sound file.\n" << oendl;
+ odebug << " Could not read from sound file." << oendl;
return -1;
}
if (strncmp(string, "RIFF", 4)) {
- odebug << " not a valid WAV file.\n" << oendl;
+ odebug << " not a valid WAV file." << oendl;
return -1;
}
lseek(fd, 4, SEEK_CUR);
if (read(fd, string, 4) < 4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
}
if (strncmp(string, "WAVE", 4)) {
- odebug << "not a valid WAV file.\n" << oendl;
+ odebug << "not a valid WAV file." << oendl;
return -1;
}
found = 0;
while (!found) {
if (read(fd, string, 4) < 4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
}
if (strncmp(string, "fmt ", 4)) {
if (read(fd, &longdata, 4) < 4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
}
lseek(fd, longdata, SEEK_CUR);
} else {
lseek(fd, 4, SEEK_CUR);
if (read(fd, &fmt, 2) < 2) {
- odebug << "Could not read format chunk.\n" << oendl;
+ odebug << "Could not read format chunk." << oendl;
return -1;
}
if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) {
- odebug << "Wave file contains unknown format. Unable to continue.\n" << oendl;
+ odebug << "Wave file contains unknown format. Unable to continue." << oendl;
return -1;
}
wavFormat = fmt;
// compressionFormat=fmt;
odebug << "compressionFormat is " << fmt << "" << oendl;
if (read(fd, &ch, 2) < 2) {
- odebug << "Could not read format chunk.\n" << oendl;
+ odebug << "Could not read format chunk." << oendl;
return -1;
} else {
wavChannels = ch;
odebug << "File has " << ch << " channels" << oendl;
}
if (read(fd, &samplerrate, 4) < 4) {
- odebug << "Could not read from format chunk.\n" << oendl;
+ odebug << "Could not read from format chunk." << oendl;
return -1;
} else {
wavSampleRate = samplerrate;
// sampleRate = samplerrate;
odebug << "File has samplerate of " << (int) samplerrate << "" << oendl;
}
lseek(fd, 6, SEEK_CUR);
if (read(fd, &bitrate, 2) < 2) {
- odebug << "Could not read format chunk.\n" << oendl;
+ odebug << "Could not read format chunk." << oendl;
return -1;
} else {
wavResolution=bitrate;
// resolution = bitrate;
odebug << "File has bitrate of " << bitrate << "" << oendl;
}
found++;
}
}
found = 0;
while (!found) {
if (read(fd, string, 4) < 4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
}
if (strncmp(string, "data", 4)) {
if (read(fd, &longdata, 4)<4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
}
lseek(fd, longdata, SEEK_CUR);
} else {
if (read(fd, &longdata, 4) < 4) {
- odebug << "Could not read from sound file.\n" << oendl;
+ odebug << "Could not read from sound file." << oendl;
return -1;
} else {
wavNumberSamples = longdata;
- odebug << "file hase length of " << (int)longdata << "\n"
+ odebug << "file hase length of " << (int)longdata << ""
<< "lasting "
<< (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8))
<< " seconds" << oendl;
// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8));
return longdata;
}
}
}
lseek(fd, 0, SEEK_SET);