summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/wavFile.cpp
authorar <ar>2004-05-12 20:25:15 (UTC)
committer ar <ar>2004-05-12 20:25:15 (UTC)
commit4b9dcabe79d0d3e73d638981ea045c4969bf21fc (patch) (unidiff)
treea29198fb88fee4fbdceba3acec7457fdc31668f8 /noncore/multimedia/opierec/wavFile.cpp
parent00efb6af5ff15e43913f91fcc5c33805233c7e91 (diff)
downloadopie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.zip
opie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.tar.gz
opie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.tar.bz2
- convert qDebug to odebug
Diffstat (limited to 'noncore/multimedia/opierec/wavFile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp86
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
@@ -27,7 +27,7 @@ WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int
27 int channels, int resolution, int format ) 27 int channels, int resolution, int format )
28 : QObject( parent) 28 : QObject( parent)
29{ 29{
30//odebug << "new wave file" << oendl; 30//odebug << "new wave file" << oendl;
31 bool b = makeNwFile; 31 bool b = makeNwFile;
32 wavSampleRate=sampleRate; 32 wavSampleRate=sampleRate;
33 wavFormat=format; 33 wavFormat=format;
@@ -43,7 +43,7 @@ WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int
43 43
44bool WavFile::newFile() { 44bool 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");
48 cfg.setGroup("Settings"); 48 cfg.setGroup("Settings");
49 49
@@ -63,7 +63,7 @@ bool WavFile::newFile() {
63 currentFileName += date; 63 currentFileName += date;
64 currentFileName+=".wav"; 64 currentFileName+=".wav";
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";
68 int fd = 0; 68 int fd = 0;
69 69
@@ -71,26 +71,26 @@ bool WavFile::newFile() {
71 && currentFileName.find("/tmp",0,true) == -1 ) { 71 && currentFileName.find("/tmp",0,true) == -1 ) {
72 // if destination file is most likely in flash (assuming jffs2) 72 // if destination file is most likely in flash (assuming jffs2)
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;
76 if(( fd = mkstemp( pointer)) < 0 ) { 76 if(( fd = mkstemp( pointer)) < 0 ) {
77 perror("mkstemp failed"); 77 perror("mkstemp failed");
78 return false; 78 return false;
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);
83 83
84 } else { //just use regular file.. no moving 84 } else { //just use regular file.. no moving
85 85
86 useTmpFile = false; 86 useTmpFile = false;
87 track.setName( currentFileName); 87 track.setName( currentFileName);
88 } 88 }
89 if(!track.open( IO_ReadWrite | IO_Truncate)) { 89 if(!track.open( IO_ReadWrite | IO_Truncate)) {
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;
95 } else { 95 } else {
96 setWavHeader( track.handle() , &hdr); 96 setWavHeader( track.handle() , &hdr);
@@ -104,19 +104,19 @@ WavFile::~WavFile() {
104} 104}
105 105
106void WavFile::closeFile() { 106void WavFile::closeFile() {
107 if(track.isOpen()) 107 if(track.isOpen())
108 track.close(); 108 track.close();
109} 109}
110 110
111int WavFile::openFile(const QString &currentFileName) { 111int WavFile::openFile(const QString &currentFileName) {
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);
116 116
117 if(!track.open(IO_ReadOnly)) { 117 if(!track.open(IO_ReadOnly)) {
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);
121 return -1; 121 return -1;
122 } else { 122 } else {
@@ -124,7 +124,7 @@ int WavFile::openFile(const QString &currentFileName) {
124 } 124 }
125 return track.handle(); 125 return track.handle();
126} 126}
127 127
128bool WavFile::setWavHeader(int fd, wavhdr *hdr) { 128bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
129 129
130 strncpy((*hdr).riffID, "RIFF", 4); // RIFF 130 strncpy((*hdr).riffID, "RIFF", 4); // RIFF
@@ -134,11 +134,11 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
134 134
135 if( wavFormat == WAVE_FORMAT_PCM) { 135 if( wavFormat == WAVE_FORMAT_PCM) {
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 }
139 else { 139 else {
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 }
143 143
144 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels 144 // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels
@@ -152,8 +152,9 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
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 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;
158} 159}
159 160
@@ -163,12 +164,12 @@ bool WavFile::adjustHeaders(int fd, int total) {
163 write( fd, &i, sizeof(i)); 164 write( fd, &i, sizeof(i));
164 lseek( fd, 40, SEEK_SET); 165 lseek( fd, 40, SEEK_SET);
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;
168} 169}
169 170
170int WavFile::parseWavHeader(int fd) { 171int WavFile::parseWavHeader(int fd) {
171 odebug << "Parsing wav header" << oendl; 172 odebug << "Parsing wav header" << oendl;
172 char string[4]; 173 char string[4];
173 int found; 174 int found;
174 short fmt; 175 short fmt;
@@ -176,72 +177,71 @@ int WavFile::parseWavHeader(int fd) {
176 unsigned long samplerrate, longdata; 177 unsigned long samplerrate, longdata;
177 178
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;
181 } 182 }
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;
185 } 186 }
186 lseek(fd, 4, SEEK_CUR); 187 lseek(fd, 4, SEEK_CUR);
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;
190 } 191 }
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;
194 } 195 }
195 found = 0; 196 found = 0;
196 197
197 while (!found) { 198 while (!found) {
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;
201 } 202 }
202 if (strncmp(string, "fmt ", 4)) { 203 if (strncmp(string, "fmt ", 4)) {
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;
206 } 207 }
207 lseek(fd, longdata, SEEK_CUR); 208 lseek(fd, longdata, SEEK_CUR);
208 } else { 209 } else {
209 lseek(fd, 4, SEEK_CUR); 210 lseek(fd, 4, SEEK_CUR);
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;
213 } 214 }
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;
218 } 218 }
219 wavFormat = fmt; 219 wavFormat = fmt;
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;
225 } else { 225 } else {
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;
232 } else { 232 } else {
233 wavSampleRate = samplerrate; 233 wavSampleRate = samplerrate;
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 }
237 lseek(fd, 6, SEEK_CUR); 237 lseek(fd, 6, SEEK_CUR);
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;
241 } else { 241 } else {
242 wavResolution=bitrate; 242 wavResolution=bitrate;
243 // resolution = bitrate; 243 // resolution = bitrate;
244 odebug << "File has bitrate of " << bitrate << "" << oendl; 244 odebug << "File has bitrate of " << bitrate << "" << oendl;
245 } 245 }
246 found++; 246 found++;
247 } 247 }
@@ -249,27 +249,29 @@ int WavFile::parseWavHeader(int fd) {
249 found = 0; 249 found = 0;
250 while (!found) { 250 while (!found) {
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;
254 } 254 }
255 255
256 if (strncmp(string, "data", 4)) { 256 if (strncmp(string, "data", 4)) {
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;
260 } 260 }
261 261
262 lseek(fd, longdata, SEEK_CUR); 262 lseek(fd, longdata, SEEK_CUR);
263 } else { 263 } else {
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;
267 } else { 267 } else {
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;
274 } 276 }
275 } 277 }