Diffstat (limited to 'noncore/multimedia/opierec/wavFile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 7e9b50f..fc0130c 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp | |||
@@ -29,3 +29,3 @@ WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int | |||
29 | { | 29 | { |
30 | //odebug << "new wave file" << oendl; | 30 | //odebug << "new wave file" << oendl; |
31 | bool b = makeNwFile; | 31 | bool b = makeNwFile; |
@@ -45,3 +45,3 @@ bool WavFile::newFile() { | |||
45 | 45 | ||
46 | // odebug << "Set up new file" << oendl; | 46 | // odebug << "Set up new file" << oendl; |
47 | Config cfg("OpieRec"); | 47 | Config cfg("OpieRec"); |
@@ -65,3 +65,3 @@ bool WavFile::newFile() { | |||
65 | 65 | ||
66 | // odebug << "set up file for recording: "+currentFileName << oendl; | 66 | // odebug << "set up file for recording: "+currentFileName << oendl; |
67 | char pointer[] = "/tmp/opierec-XXXXXX"; | 67 | char pointer[] = "/tmp/opierec-XXXXXX"; |
@@ -73,3 +73,3 @@ bool WavFile::newFile() { | |||
73 | // we have to write to a different filesystem first | 73 | // we have to write to a different filesystem first |
74 | 74 | ||
75 | useTmpFile = true; | 75 | useTmpFile = true; |
@@ -79,4 +79,4 @@ bool WavFile::newFile() { | |||
79 | } | 79 | } |
80 | 80 | ||
81 | // odebug << "Opening tmp file " << pointer << "" << oendl; | 81 | // odebug << "Opening tmp file " << pointer << "" << oendl; |
82 | track.setName( pointer); | 82 | track.setName( pointer); |
@@ -84,3 +84,3 @@ bool WavFile::newFile() { | |||
84 | } else { //just use regular file.. no moving | 84 | } else { //just use regular file.. no moving |
85 | 85 | ||
86 | useTmpFile = false; | 86 | useTmpFile = false; |
@@ -90,5 +90,5 @@ bool WavFile::newFile() { | |||
90 | QString errorMsg=(QString)strerror(errno); | 90 | QString errorMsg=(QString)strerror(errno); |
91 | odebug << errorMsg << oendl; | 91 | odebug << errorMsg << oendl; |
92 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | 92 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); |
93 | 93 | ||
94 | return false; | 94 | return false; |
@@ -106,3 +106,3 @@ WavFile::~WavFile() { | |||
106 | void WavFile::closeFile() { | 106 | void WavFile::closeFile() { |
107 | if(track.isOpen()) | 107 | if(track.isOpen()) |
108 | track.close(); | 108 | track.close(); |
@@ -111,5 +111,5 @@ void WavFile::closeFile() { | |||
111 | int WavFile::openFile(const QString ¤tFileName) { | 111 | int WavFile::openFile(const QString ¤tFileName) { |
112 | // odebug << "open play file "+currentFileName << oendl; | 112 | // odebug << "open play file "+currentFileName << oendl; |
113 | closeFile(); | 113 | closeFile(); |
114 | 114 | ||
115 | track.setName(currentFileName); | 115 | track.setName(currentFileName); |
@@ -118,3 +118,3 @@ int WavFile::openFile(const QString ¤tFileName) { | |||
118 | QString errorMsg=(QString)strerror(errno); | 118 | QString errorMsg=(QString)strerror(errno); |
119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; | 119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; |
120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | 120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); |
@@ -126,3 +126,3 @@ int WavFile::openFile(const QString ¤tFileName) { | |||
126 | } | 126 | } |
127 | 127 | ||
128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | 128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { |
@@ -136,3 +136,3 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | |||
136 | (*hdr).fmtTag = 1; // PCM | 136 | (*hdr).fmtTag = 1; // PCM |
137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; | 137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; |
138 | } | 138 | } |
@@ -140,3 +140,3 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | |||
140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM | 140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM |
141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; | 141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; |
142 | } | 142 | } |
@@ -154,4 +154,5 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | |||
154 | write( fd,hdr, sizeof(*hdr)); | 154 | write( fd,hdr, sizeof(*hdr)); |
155 | qDebug("writing header: bitrate%d, samplerate %d, channels %d", | 155 | odebug << "writing header: bitrate " << wavResolution |
156 | wavResolution, wavSampleRate, wavChannels); | 156 | << ", samplerate " << wavSampleRate |
157 | << ", channels " << wavChannels << oendl; | ||
157 | return true; | 158 | return true; |
@@ -165,3 +166,3 @@ bool WavFile::adjustHeaders(int fd, int total) { | |||
165 | write( fd, &total, sizeof(total)); | 166 | write( fd, &total, sizeof(total)); |
166 | odebug << "adjusting header " << total << "" << oendl; | 167 | odebug << "adjusting header " << total << "" << oendl; |
167 | return true; | 168 | return true; |
@@ -170,3 +171,3 @@ bool WavFile::adjustHeaders(int fd, int total) { | |||
170 | int WavFile::parseWavHeader(int fd) { | 171 | int WavFile::parseWavHeader(int fd) { |
171 | odebug << "Parsing wav header" << oendl; | 172 | odebug << "Parsing wav header" << oendl; |
172 | char string[4]; | 173 | char string[4]; |
@@ -178,3 +179,3 @@ int WavFile::parseWavHeader(int fd) { | |||
178 | if (read(fd, string, 4) < 4) { | 179 | if (read(fd, string, 4) < 4) { |
179 | odebug << " Could not read from sound file.\n" << oendl; | 180 | odebug << " Could not read from sound file.\n" << oendl; |
180 | return -1; | 181 | return -1; |
@@ -182,3 +183,3 @@ int WavFile::parseWavHeader(int fd) { | |||
182 | if (strncmp(string, "RIFF", 4)) { | 183 | if (strncmp(string, "RIFF", 4)) { |
183 | odebug << " not a valid WAV file.\n" << oendl; | 184 | odebug << " not a valid WAV file.\n" << oendl; |
184 | return -1; | 185 | return -1; |
@@ -187,3 +188,3 @@ int WavFile::parseWavHeader(int fd) { | |||
187 | if (read(fd, string, 4) < 4) { | 188 | if (read(fd, string, 4) < 4) { |
188 | odebug << "Could not read from sound file.\n" << oendl; | 189 | odebug << "Could not read from sound file.\n" << oendl; |
189 | return -1; | 190 | return -1; |
@@ -191,3 +192,3 @@ int WavFile::parseWavHeader(int fd) { | |||
191 | if (strncmp(string, "WAVE", 4)) { | 192 | if (strncmp(string, "WAVE", 4)) { |
192 | odebug << "not a valid WAV file.\n" << oendl; | 193 | odebug << "not a valid WAV file.\n" << oendl; |
193 | return -1; | 194 | return -1; |
@@ -198,3 +199,3 @@ int WavFile::parseWavHeader(int fd) { | |||
198 | if (read(fd, string, 4) < 4) { | 199 | if (read(fd, string, 4) < 4) { |
199 | odebug << "Could not read from sound file.\n" << oendl; | 200 | odebug << "Could not read from sound file.\n" << oendl; |
200 | return -1; | 201 | return -1; |
@@ -203,3 +204,3 @@ int WavFile::parseWavHeader(int fd) { | |||
203 | if (read(fd, &longdata, 4) < 4) { | 204 | if (read(fd, &longdata, 4) < 4) { |
204 | odebug << "Could not read from sound file.\n" << oendl; | 205 | odebug << "Could not read from sound file.\n" << oendl; |
205 | return -1; | 206 | return -1; |
@@ -210,3 +211,3 @@ int WavFile::parseWavHeader(int fd) { | |||
210 | if (read(fd, &fmt, 2) < 2) { | 211 | if (read(fd, &fmt, 2) < 2) { |
211 | odebug << "Could not read format chunk.\n" << oendl; | 212 | odebug << "Could not read format chunk.\n" << oendl; |
212 | return -1; | 213 | return -1; |
@@ -214,4 +215,3 @@ int WavFile::parseWavHeader(int fd) { | |||
214 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { | 215 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { |
215 | qDebug("Wave file contains unknown format." | 216 | odebug << "Wave file contains unknown format. Unable to continue.\n" << oendl; |
216 | " Unable to continue.\n"); | ||
217 | return -1; | 217 | return -1; |
@@ -220,5 +220,5 @@ int WavFile::parseWavHeader(int fd) { | |||
220 | // compressionFormat=fmt; | 220 | // compressionFormat=fmt; |
221 | odebug << "compressionFormat is " << fmt << "" << oendl; | 221 | odebug << "compressionFormat is " << fmt << "" << oendl; |
222 | if (read(fd, &ch, 2) < 2) { | 222 | if (read(fd, &ch, 2) < 2) { |
223 | odebug << "Could not read format chunk.\n" << oendl; | 223 | odebug << "Could not read format chunk.\n" << oendl; |
224 | return -1; | 224 | return -1; |
@@ -226,6 +226,6 @@ int WavFile::parseWavHeader(int fd) { | |||
226 | wavChannels = ch; | 226 | wavChannels = ch; |
227 | odebug << "File has " << ch << " channels" << oendl; | 227 | odebug << "File has " << ch << " channels" << oendl; |
228 | } | 228 | } |
229 | if (read(fd, &samplerrate, 4) < 4) { | 229 | if (read(fd, &samplerrate, 4) < 4) { |
230 | odebug << "Could not read from format chunk.\n" << oendl; | 230 | odebug << "Could not read from format chunk.\n" << oendl; |
231 | return -1; | 231 | return -1; |
@@ -234,3 +234,3 @@ int WavFile::parseWavHeader(int fd) { | |||
234 | // sampleRate = samplerrate; | 234 | // sampleRate = samplerrate; |
235 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; | 235 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; |
236 | } | 236 | } |
@@ -238,3 +238,3 @@ int WavFile::parseWavHeader(int fd) { | |||
238 | if (read(fd, &bitrate, 2) < 2) { | 238 | if (read(fd, &bitrate, 2) < 2) { |
239 | odebug << "Could not read format chunk.\n" << oendl; | 239 | odebug << "Could not read format chunk.\n" << oendl; |
240 | return -1; | 240 | return -1; |
@@ -243,3 +243,3 @@ int WavFile::parseWavHeader(int fd) { | |||
243 | // resolution = bitrate; | 243 | // resolution = bitrate; |
244 | odebug << "File has bitrate of " << bitrate << "" << oendl; | 244 | odebug << "File has bitrate of " << bitrate << "" << oendl; |
245 | } | 245 | } |
@@ -251,3 +251,3 @@ int WavFile::parseWavHeader(int fd) { | |||
251 | if (read(fd, string, 4) < 4) { | 251 | if (read(fd, string, 4) < 4) { |
252 | odebug << "Could not read from sound file.\n" << oendl; | 252 | odebug << "Could not read from sound file.\n" << oendl; |
253 | return -1; | 253 | return -1; |
@@ -257,3 +257,3 @@ int WavFile::parseWavHeader(int fd) { | |||
257 | if (read(fd, &longdata, 4)<4) { | 257 | if (read(fd, &longdata, 4)<4) { |
258 | odebug << "Could not read from sound file.\n" << oendl; | 258 | odebug << "Could not read from sound file.\n" << oendl; |
259 | return -1; | 259 | return -1; |
@@ -264,3 +264,3 @@ int WavFile::parseWavHeader(int fd) { | |||
264 | if (read(fd, &longdata, 4) < 4) { | 264 | if (read(fd, &longdata, 4) < 4) { |
265 | odebug << "Could not read from sound file.\n" << oendl; | 265 | odebug << "Could not read from sound file.\n" << oendl; |
266 | return -1; | 266 | return -1; |
@@ -268,6 +268,8 @@ int WavFile::parseWavHeader(int fd) { | |||
268 | wavNumberSamples = longdata; | 268 | wavNumberSamples = longdata; |
269 | qDebug("file has length of %d \nlasting %d seconds", (int)longdata, | 269 | odebug << "file hase length of " << (int)longdata << "\n" |
270 | (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) ); | 270 | << "lasting " |
271 | << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) | ||
272 | << " seconds" << oendl; | ||
271 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); | 273 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); |
272 | 274 | ||
273 | return longdata; | 275 | return longdata; |