summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/wavFile.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opierec/wavFile.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp67
1 files changed, 35 insertions, 32 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp
index 35bc14d..7e9b50f 100644
--- a/noncore/multimedia/opierec/wavFile.cpp
+++ b/noncore/multimedia/opierec/wavFile.cpp
@@ -2,17 +2,20 @@
2#include "wavFile.h" 2#include "wavFile.h"
3#include "qtrec.h" 3#include "qtrec.h"
4 4
5/* OPIE */
6#include <opie2/odebug.h>
7#include <qpe/config.h>
8using namespace Opie::Core;
9
10/* QT */
5#include <qmessagebox.h> 11#include <qmessagebox.h>
6#include <qdir.h> 12#include <qdir.h>
7 13
8#include <qpe/config.h> 14/* STD */
9
10#include <errno.h> 15#include <errno.h>
11
12#include <sys/time.h> 16#include <sys/time.h>
13#include <sys/types.h> 17#include <sys/types.h>
14#include <sys/vfs.h> 18#include <sys/vfs.h>
15
16#include <fcntl.h> 19#include <fcntl.h>
17#include <math.h> 20#include <math.h>
18#include <mntent.h> 21#include <mntent.h>
@@ -24,7 +27,7 @@ WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int
24 int channels, int resolution, int format ) 27 int channels, int resolution, int format )
25 : QObject( parent) 28 : QObject( parent)
26{ 29{
27//qDebug("new wave file"); 30//odebug << "new wave file" << oendl;
28 bool b = makeNwFile; 31 bool b = makeNwFile;
29 wavSampleRate=sampleRate; 32 wavSampleRate=sampleRate;
30 wavFormat=format; 33 wavFormat=format;
@@ -40,7 +43,7 @@ WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int
40 43
41bool WavFile::newFile() { 44bool WavFile::newFile() {
42 45
43// qDebug("Set up new file"); 46// odebug << "Set up new file" << oendl;
44 Config cfg("OpieRec"); 47 Config cfg("OpieRec");
45 cfg.setGroup("Settings"); 48 cfg.setGroup("Settings");
46 49
@@ -60,7 +63,7 @@ bool WavFile::newFile() {
60 currentFileName += date; 63 currentFileName += date;
61 currentFileName+=".wav"; 64 currentFileName+=".wav";
62 65
63// qDebug("set up file for recording: "+currentFileName); 66// odebug << "set up file for recording: "+currentFileName << oendl;
64 char pointer[] = "/tmp/opierec-XXXXXX"; 67 char pointer[] = "/tmp/opierec-XXXXXX";
65 int fd = 0; 68 int fd = 0;
66 69
@@ -75,7 +78,7 @@ bool WavFile::newFile() {
75 return false; 78 return false;
76 } 79 }
77 80
78// qDebug("Opening tmp file %s",pointer); 81// odebug << "Opening tmp file " << pointer << "" << oendl;
79 track.setName( pointer); 82 track.setName( pointer);
80 83
81 } else { //just use regular file.. no moving 84 } else { //just use regular file.. no moving
@@ -85,7 +88,7 @@ bool WavFile::newFile() {
85 } 88 }
86 if(!track.open( IO_ReadWrite | IO_Truncate)) { 89 if(!track.open( IO_ReadWrite | IO_Truncate)) {
87 QString errorMsg=(QString)strerror(errno); 90 QString errorMsg=(QString)strerror(errno);
88 qDebug(errorMsg); 91 odebug << errorMsg << oendl;
89 QMessageBox::message("Note", "Error opening file.\n" +errorMsg); 92 QMessageBox::message("Note", "Error opening file.\n" +errorMsg);
90 93
91 return false; 94 return false;
@@ -106,14 +109,14 @@ void WavFile::closeFile() {
106} 109}
107 110
108int WavFile::openFile(const QString &currentFileName) { 111int WavFile::openFile(const QString &currentFileName) {
109// qDebug("open play file "+currentFileName); 112// odebug << "open play file "+currentFileName << oendl;
110 closeFile(); 113 closeFile();
111 114
112 track.setName(currentFileName); 115 track.setName(currentFileName);
113 116
114 if(!track.open(IO_ReadOnly)) { 117 if(!track.open(IO_ReadOnly)) {
115 QString errorMsg=(QString)strerror(errno); 118 QString errorMsg=(QString)strerror(errno);
116 qDebug("<<<<<<<<<<< "+errorMsg+currentFileName); 119 odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl;
117 QMessageBox::message("Note", "Error opening file.\n" +errorMsg); 120 QMessageBox::message("Note", "Error opening file.\n" +errorMsg);
118 return -1; 121 return -1;
119 } else { 122 } else {
@@ -131,11 +134,11 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
131 134
132 if( wavFormat == WAVE_FORMAT_PCM) { 135 if( wavFormat == WAVE_FORMAT_PCM) {
133 (*hdr).fmtTag = 1; // PCM 136 (*hdr).fmtTag = 1; // PCM
134// qDebug("set header WAVE_FORMAT_PCM"); 137// odebug << "set header WAVE_FORMAT_PCM" << oendl;
135 } 138 }
136 else { 139 else {
137 (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM 140 (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM
138 // qDebug("set header WAVE_FORMAT_DVI_ADPCM"); 141 // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl;
139 } 142 }
140 143
141 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels 144 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels
@@ -160,12 +163,12 @@ bool WavFile::adjustHeaders(int fd, int total) {
160 write( fd, &i, sizeof(i)); 163 write( fd, &i, sizeof(i));
161 lseek( fd, 40, SEEK_SET); 164 lseek( fd, 40, SEEK_SET);
162 write( fd, &total, sizeof(total)); 165 write( fd, &total, sizeof(total));
163 qDebug("adjusting header %d", total); 166 odebug << "adjusting header " << total << "" << oendl;
164 return true; 167 return true;
165} 168}
166 169
167int WavFile::parseWavHeader(int fd) { 170int WavFile::parseWavHeader(int fd) {
168 qDebug("Parsing wav header"); 171 odebug << "Parsing wav header" << oendl;
169 char string[4]; 172 char string[4];
170 int found; 173 int found;
171 short fmt; 174 short fmt;
@@ -173,39 +176,39 @@ int WavFile::parseWavHeader(int fd) {
173 unsigned long samplerrate, longdata; 176 unsigned long samplerrate, longdata;
174 177
175 if (read(fd, string, 4) < 4) { 178 if (read(fd, string, 4) < 4) {
176 qDebug(" Could not read from sound file.\n"); 179 odebug << " Could not read from sound file.\n" << oendl;
177 return -1; 180 return -1;
178 } 181 }
179 if (strncmp(string, "RIFF", 4)) { 182 if (strncmp(string, "RIFF", 4)) {
180 qDebug(" not a valid WAV file.\n"); 183 odebug << " not a valid WAV file.\n" << oendl;
181 return -1; 184 return -1;
182 } 185 }
183 lseek(fd, 4, SEEK_CUR); 186 lseek(fd, 4, SEEK_CUR);
184 if (read(fd, string, 4) < 4) { 187 if (read(fd, string, 4) < 4) {
185 qDebug("Could not read from sound file.\n"); 188 odebug << "Could not read from sound file.\n" << oendl;
186 return -1; 189 return -1;
187 } 190 }
188 if (strncmp(string, "WAVE", 4)) { 191 if (strncmp(string, "WAVE", 4)) {
189 qDebug("not a valid WAV file.\n"); 192 odebug << "not a valid WAV file.\n" << oendl;
190 return -1; 193 return -1;
191 } 194 }
192 found = 0; 195 found = 0;
193 196
194 while (!found) { 197 while (!found) {
195 if (read(fd, string, 4) < 4) { 198 if (read(fd, string, 4) < 4) {
196 qDebug("Could not read from sound file.\n"); 199 odebug << "Could not read from sound file.\n" << oendl;
197 return -1; 200 return -1;
198 } 201 }
199 if (strncmp(string, "fmt ", 4)) { 202 if (strncmp(string, "fmt ", 4)) {
200 if (read(fd, &longdata, 4) < 4) { 203 if (read(fd, &longdata, 4) < 4) {
201 qDebug("Could not read from sound file.\n"); 204 odebug << "Could not read from sound file.\n" << oendl;
202 return -1; 205 return -1;
203 } 206 }
204 lseek(fd, longdata, SEEK_CUR); 207 lseek(fd, longdata, SEEK_CUR);
205 } else { 208 } else {
206 lseek(fd, 4, SEEK_CUR); 209 lseek(fd, 4, SEEK_CUR);
207 if (read(fd, &fmt, 2) < 2) { 210 if (read(fd, &fmt, 2) < 2) {
208 qDebug("Could not read format chunk.\n"); 211 odebug << "Could not read format chunk.\n" << oendl;
209 return -1; 212 return -1;
210 } 213 }
211 if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { 214 if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) {
@@ -215,30 +218,30 @@ int WavFile::parseWavHeader(int fd) {
215 } 218 }
216 wavFormat = fmt; 219 wavFormat = fmt;
217 // compressionFormat=fmt; 220 // compressionFormat=fmt;
218 qDebug("compressionFormat is %d", fmt); 221 odebug << "compressionFormat is " << fmt << "" << oendl;
219 if (read(fd, &ch, 2) < 2) { 222 if (read(fd, &ch, 2) < 2) {
220 qDebug("Could not read format chunk.\n"); 223 odebug << "Could not read format chunk.\n" << oendl;
221 return -1; 224 return -1;
222 } else { 225 } else {
223 wavChannels = ch; 226 wavChannels = ch;
224 qDebug("File has %d channels", ch); 227 odebug << "File has " << ch << " channels" << oendl;
225 } 228 }
226 if (read(fd, &samplerrate, 4) < 4) { 229 if (read(fd, &samplerrate, 4) < 4) {
227 qDebug("Could not read from format chunk.\n"); 230 odebug << "Could not read from format chunk.\n" << oendl;
228 return -1; 231 return -1;
229 } else { 232 } else {
230 wavSampleRate = samplerrate; 233 wavSampleRate = samplerrate;
231 // sampleRate = samplerrate; 234 // sampleRate = samplerrate;
232 qDebug("File has samplerate of %d",(int) samplerrate); 235 odebug << "File has samplerate of " << (int) samplerrate << "" << oendl;
233 } 236 }
234 lseek(fd, 6, SEEK_CUR); 237 lseek(fd, 6, SEEK_CUR);
235 if (read(fd, &bitrate, 2) < 2) { 238 if (read(fd, &bitrate, 2) < 2) {
236 qDebug("Could not read format chunk.\n"); 239 odebug << "Could not read format chunk.\n" << oendl;
237 return -1; 240 return -1;
238 } else { 241 } else {
239 wavResolution=bitrate; 242 wavResolution=bitrate;
240 // resolution = bitrate; 243 // resolution = bitrate;
241 qDebug("File has bitrate of %d", bitrate); 244 odebug << "File has bitrate of " << bitrate << "" << oendl;
242 } 245 }
243 found++; 246 found++;
244 } 247 }
@@ -246,20 +249,20 @@ int WavFile::parseWavHeader(int fd) {
246 found = 0; 249 found = 0;
247 while (!found) { 250 while (!found) {
248 if (read(fd, string, 4) < 4) { 251 if (read(fd, string, 4) < 4) {
249 qDebug("Could not read from sound file.\n"); 252 odebug << "Could not read from sound file.\n" << oendl;
250 return -1; 253 return -1;
251 } 254 }
252 255
253 if (strncmp(string, "data", 4)) { 256 if (strncmp(string, "data", 4)) {
254 if (read(fd, &longdata, 4)<4) { 257 if (read(fd, &longdata, 4)<4) {
255 qDebug("Could not read from sound file.\n"); 258 odebug << "Could not read from sound file.\n" << oendl;
256 return -1; 259 return -1;
257 } 260 }
258 261
259 lseek(fd, longdata, SEEK_CUR); 262 lseek(fd, longdata, SEEK_CUR);
260 } else { 263 } else {
261 if (read(fd, &longdata, 4) < 4) { 264 if (read(fd, &longdata, 4) < 4) {
262 qDebug("Could not read from sound file.\n"); 265 odebug << "Could not read from sound file.\n" << oendl;
263 return -1; 266 return -1;
264 } else { 267 } else {
265 wavNumberSamples = longdata; 268 wavNumberSamples = longdata;