summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/wavFile.cpp
authorllornkcor <llornkcor>2003-12-25 21:52:44 (UTC)
committer llornkcor <llornkcor>2003-12-25 21:52:44 (UTC)
commitf2805565b0d7edd2e72445f6d56e43eadcdac72d (patch) (side-by-side diff)
treeb9a74aec0c5616ae1976198c1f83945b697ed3d2 /noncore/multimedia/opierec/wavFile.cpp
parent34a7e0451c95e8a19735610553dba064b68823d9 (diff)
downloadopie-f2805565b0d7edd2e72445f6d56e43eadcdac72d.zip
opie-f2805565b0d7edd2e72445f6d56e43eadcdac72d.tar.gz
opie-f2805565b0d7edd2e72445f6d56e43eadcdac72d.tar.bz2
uhhh.. helps to commit to correct branch
Diffstat (limited to 'noncore/multimedia/opierec/wavFile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp
index b177c91..987fa32 100644
--- a/noncore/multimedia/opierec/wavFile.cpp
+++ b/noncore/multimedia/opierec/wavFile.cpp
@@ -104,113 +104,113 @@ void WavFile::closeFile() {
if(track.isOpen())
track.close();
}
int WavFile::openFile(const QString &currentFileName) {
// qDebug("open play file "+currentFileName);
closeFile();
track.setName(currentFileName);
if(!track.open(IO_ReadOnly)) {
QString errorMsg=(QString)strerror(errno);
qDebug("<<<<<<<<<<< "+errorMsg+currentFileName);
QMessageBox::message("Note", "Error opening file.\n" +errorMsg);
return -1;
} else {
parseWavHeader( track.handle());
}
return track.handle();
}
bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
strncpy((*hdr).riffID, "RIFF", 4); // RIFF
strncpy((*hdr).wavID, "WAVE", 4); //WAVE
strncpy((*hdr).fmtID, "fmt ", 4); // fmt
(*hdr).fmtLen = 16; // format length = 16
if( wavFormat == WAVE_FORMAT_PCM) {
(*hdr).fmtTag = 1; // PCM
// qDebug("set header WAVE_FORMAT_PCM");
}
else {
(*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM
// qDebug("set header WAVE_FORMAT_DVI_ADPCM");
}
// (*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));
-// qDebug("writing header: bitrate%d, samplerate %d, channels %d",
-// wavResolution, wavSampleRate, wavChannels);
+ qDebug("writing header: bitrate%d, samplerate %d, channels %d",
+ wavResolution, wavSampleRate, wavChannels);
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));
-// qDebug("adjusting header %d", total);
+ qDebug("adjusting header %d", total);
return true;
}
int WavFile::parseWavHeader(int fd) {
-// qDebug("Parsing wav header");
+ qDebug("Parsing wav header");
char string[4];
int found;
short fmt;
unsigned short ch, bitrate;
unsigned long samplerrate, longdata;
if (read(fd, string, 4) < 4) {
qDebug(" Could not read from sound file.\n");
return -1;
}
if (strncmp(string, "RIFF", 4)) {
qDebug(" not a valid WAV file.\n");
return -1;
}
lseek(fd, 4, SEEK_CUR);
if (read(fd, string, 4) < 4) {
qDebug("Could not read from sound file.\n");
return -1;
}
if (strncmp(string, "WAVE", 4)) {
qDebug("not a valid WAV file.\n");
return -1;
}
found = 0;
while (!found) {
if (read(fd, string, 4) < 4) {
qDebug("Could not read from sound file.\n");
return -1;
}
if (strncmp(string, "fmt ", 4)) {
if (read(fd, &longdata, 4) < 4) {
qDebug("Could not read from sound file.\n");
return -1;
}
lseek(fd, longdata, SEEK_CUR);
} else {
lseek(fd, 4, SEEK_CUR);
if (read(fd, &fmt, 2) < 2) {
qDebug("Could not read format chunk.\n");
return -1;
}
if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) {
qDebug("Wave file contains unknown format."
" Unable to continue.\n");
return -1;
}
wavFormat = fmt;
@@ -249,58 +249,63 @@ int WavFile::parseWavHeader(int fd) {
qDebug("Could not read from sound file.\n");
return -1;
}
if (strncmp(string, "data", 4)) {
if (read(fd, &longdata, 4)<4) {
qDebug("Could not read from sound file.\n");
return -1;
}
lseek(fd, longdata, SEEK_CUR);
} else {
if (read(fd, &longdata, 4) < 4) {
qDebug("Could not read from sound file.\n");
return -1;
} else {
wavNumberSamples = longdata;
qDebug("file has length of %d \nlasting %d seconds", (int)longdata,
(int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) );
// wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8));
return longdata;
}
}
}
lseek(fd, 0, SEEK_SET);
return 0;
}
QString WavFile::trackName() {
return track.name();
}
int WavFile::wavHandle(){
return track.handle();
}
int WavFile::getFormat() {
return wavFormat;
}
int WavFile::getResolution() {
return wavResolution;
}
int WavFile::getSampleRate() {
-return wavSampleRate;
+ return wavSampleRate;
}
int WavFile::getNumberSamples() {
-return wavNumberSamples;
+ return wavNumberSamples;
}
bool WavFile::isTempFile() {
return useTmpFile;
}
+
+int WavFile::getChannels() {
+
+ return wavChannels;
+}