-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 7cc4062..f5d2b20 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -113,386 +113,388 @@ static char * vmemo_xpm[] = { | |||
113 | "8 c #757578", | 113 | "8 c #757578", |
114 | "9 c #87878E", | 114 | "9 c #87878E", |
115 | "0 c #222224", | 115 | "0 c #222224", |
116 | "a c #414144", | 116 | "a c #414144", |
117 | "b c #6A6A6E", | 117 | "b c #6A6A6E", |
118 | "c c #020C16", | 118 | "c c #020C16", |
119 | "d c #6B6B6F", | 119 | "d c #6B6B6F", |
120 | "e c #68686D", | 120 | "e c #68686D", |
121 | "f c #5B5B60", | 121 | "f c #5B5B60", |
122 | "g c #8A8A8F", | 122 | "g c #8A8A8F", |
123 | "h c #6B6B6E", | 123 | "h c #6B6B6E", |
124 | "i c #ADADB2", | 124 | "i c #ADADB2", |
125 | "j c #828289", | 125 | "j c #828289", |
126 | "k c #3E3E41", | 126 | "k c #3E3E41", |
127 | "l c #CFCFD7", | 127 | "l c #CFCFD7", |
128 | "m c #4C4C50", | 128 | "m c #4C4C50", |
129 | "n c #000000", | 129 | "n c #000000", |
130 | "o c #66666A", | 130 | "o c #66666A", |
131 | "p c #505054", | 131 | "p c #505054", |
132 | "q c #838388", | 132 | "q c #838388", |
133 | "r c #A1A1A7", | 133 | "r c #A1A1A7", |
134 | "s c #A9A9AE", | 134 | "s c #A9A9AE", |
135 | "t c #A8A8B0", | 135 | "t c #A8A8B0", |
136 | "u c #5E5E63", | 136 | "u c #5E5E63", |
137 | "v c #3A3A3E", | 137 | "v c #3A3A3E", |
138 | "w c #BDBDC6", | 138 | "w c #BDBDC6", |
139 | "x c #59595E", | 139 | "x c #59595E", |
140 | "y c #76767C", | 140 | "y c #76767C", |
141 | "z c #373738", | 141 | "z c #373738", |
142 | "A c #717174", | 142 | "A c #717174", |
143 | "B c #727278", | 143 | "B c #727278", |
144 | "C c #1C1C1E", | 144 | "C c #1C1C1E", |
145 | "D c #3C3C3F", | 145 | "D c #3C3C3F", |
146 | "E c #ADADB6", | 146 | "E c #ADADB6", |
147 | "F c #54555A", | 147 | "F c #54555A", |
148 | "G c #8B8C94", | 148 | "G c #8B8C94", |
149 | "H c #5A5A5F", | 149 | "H c #5A5A5F", |
150 | "I c #BBBBC3", | 150 | "I c #BBBBC3", |
151 | "J c #C4C4CB", | 151 | "J c #C4C4CB", |
152 | "K c #909098", | 152 | "K c #909098", |
153 | "L c #737379", | 153 | "L c #737379", |
154 | "M c #343437", | 154 | "M c #343437", |
155 | "N c #8F8F98", | 155 | "N c #8F8F98", |
156 | "O c #000407", | 156 | "O c #000407", |
157 | "P c #2D3137", | 157 | "P c #2D3137", |
158 | "Q c #B0B1BC", | 158 | "Q c #B0B1BC", |
159 | "R c #3B3C40", | 159 | "R c #3B3C40", |
160 | "S c #6E6E74", | 160 | "S c #6E6E74", |
161 | "T c #95959C", | 161 | "T c #95959C", |
162 | "U c #74747A", | 162 | "U c #74747A", |
163 | "V c #1D1D1E", | 163 | "V c #1D1D1E", |
164 | "W c #91929A", | 164 | "W c #91929A", |
165 | "X c #42444A", | 165 | "X c #42444A", |
166 | "Y c #22282E", | 166 | "Y c #22282E", |
167 | "Z c #B0B2BC", | 167 | "Z c #B0B2BC", |
168 | "` c #898A90", | 168 | "` c #898A90", |
169 | " . c #65656A", | 169 | " . c #65656A", |
170 | ".. c #999AA2", | 170 | ".. c #999AA2", |
171 | "+. c #52535A", | 171 | "+. c #52535A", |
172 | "@. c #151B21", | 172 | "@. c #151B21", |
173 | "#. c #515257", | 173 | "#. c #515257", |
174 | "$. c #B5B5BE", | 174 | "$. c #B5B5BE", |
175 | "%. c #616167", | 175 | "%. c #616167", |
176 | "&. c #1A1D22", | 176 | "&. c #1A1D22", |
177 | "*. c #000713", | 177 | "*. c #000713", |
178 | "=. c #1F1F21", | 178 | "=. c #1F1F21", |
179 | " ", | 179 | " ", |
180 | " . + @ # ", | 180 | " . + @ # ", |
181 | " $ % & * = - ", | 181 | " $ % & * = - ", |
182 | " ; > , ' ) ! ~ ", | 182 | " ; > , ' ) ! ~ ", |
183 | " { ] ^ / ( _ : ", | 183 | " { ] ^ / ( _ : ", |
184 | " < [ } | 1 2 3 ", | 184 | " < [ } | 1 2 3 ", |
185 | " 4 5 6 7 8 9 0 a b c ", | 185 | " 4 5 6 7 8 9 0 a b c ", |
186 | " d e f g h i j 3 k l m n ", | 186 | " d e f g h i j 3 k l m n ", |
187 | " o p q r s t u v w n ", | 187 | " o p q r s t u v w n ", |
188 | " o x y z A B C D E n ", | 188 | " o x y z A B C D E n ", |
189 | " F G H I J K L M N O ", | 189 | " F G H I J K L M N O ", |
190 | " P Q R S T U V W X ", | 190 | " P Q R S T U V W X ", |
191 | " Y Z ` b ...+. ", | 191 | " Y Z ` b ...+. ", |
192 | " @.#.$.%.&. ", | 192 | " @.#.$.%.&. ", |
193 | " *.B =. ", | 193 | " *.B =. ", |
194 | " n n n n n n n n n "}; | 194 | " n n n n n n n n n "}; |
195 | 195 | ||
196 | 196 | ||
197 | VMemo::VMemo( QWidget *parent, const char *_name ) | 197 | VMemo::VMemo( QWidget *parent, const char *_name ) |
198 | : QWidget( parent, _name ) | 198 | : QWidget( parent, _name ) |
199 | { | 199 | { |
200 | setFixedHeight( 18 ); | 200 | setFixedHeight( 18 ); |
201 | setFixedWidth( 14 ); | 201 | setFixedWidth( 14 ); |
202 | 202 | ||
203 | recording = FALSE; | 203 | recording = FALSE; |
204 | 204 | ||
205 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 205 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
206 | if (uname(&name) != -1) { | 206 | if (uname(&name) != -1) { |
207 | QString release=name.release; | 207 | QString release=name.release; |
208 | Config vmCfg("VMemo"); | 208 | Config vmCfg("VMemo"); |
209 | vmCfg.setGroup("Defaults"); | 209 | vmCfg.setGroup("Defaults"); |
210 | int toggleKey = vmCfg.readNumEntry("toggleKey", -1); | 210 | int toggleKey = vmCfg.readNumEntry("toggleKey", -1); |
211 | 211 | ||
212 | if(release.find("embedix",0,TRUE) !=-1) | 212 | if(release.find("embedix",0,TRUE) !=-1) |
213 | systemZaurus=TRUE; | 213 | systemZaurus=TRUE; |
214 | else | 214 | else |
215 | systemZaurus=FALSE; | 215 | systemZaurus=FALSE; |
216 | 216 | ||
217 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 217 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
218 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 218 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
219 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 219 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
220 | 220 | ||
221 | if( toggleKey != -1 ) { | 221 | if( toggleKey != -1 ) { |
222 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 222 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
223 | // e << 4096; // Key_Escape | 223 | // e << 4096; // Key_Escape |
224 | // e << Key_F5; //4148 | 224 | // e << Key_F5; //4148 |
225 | e << toggleKey; | 225 | e << toggleKey; |
226 | e << QString("QPE/VMemo"); | 226 | e << QString("QPE/VMemo"); |
227 | e << QString("toggleRecord()"); | 227 | e << QString("toggleRecord()"); |
228 | } | 228 | } |
229 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 229 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
230 | hide(); | 230 | hide(); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | VMemo::~VMemo() | 234 | VMemo::~VMemo() |
235 | { | 235 | { |
236 | } | 236 | } |
237 | 237 | ||
238 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 238 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
239 | { | 239 | { |
240 | QDataStream stream( data, IO_ReadOnly ); | 240 | QDataStream stream( data, IO_ReadOnly ); |
241 | if (msg == "toggleRecord()") { | 241 | if (msg == "toggleRecord()") { |
242 | if (recording) { | 242 | if (recording) { |
243 | fromToggle = TRUE; | 243 | fromToggle = TRUE; |
244 | stopRecording(); | 244 | stopRecording(); |
245 | } else { | 245 | } else { |
246 | fromToggle = TRUE; | 246 | fromToggle = TRUE; |
247 | startRecording(); | 247 | startRecording(); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | void VMemo::paintEvent( QPaintEvent* ) | 252 | void VMemo::paintEvent( QPaintEvent* ) |
253 | { | 253 | { |
254 | QPainter p(this); | 254 | QPainter p(this); |
255 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 255 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
256 | } | 256 | } |
257 | 257 | ||
258 | void VMemo::mousePressEvent( QMouseEvent * ) | 258 | void VMemo::mousePressEvent( QMouseEvent * ) |
259 | { | 259 | { |
260 | startRecording(); | 260 | startRecording(); |
261 | } | 261 | } |
262 | 262 | ||
263 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 263 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
264 | { | 264 | { |
265 | stopRecording(); | 265 | stopRecording(); |
266 | } | 266 | } |
267 | 267 | ||
268 | bool VMemo::startRecording() { | 268 | bool VMemo::startRecording() { |
269 | 269 | ||
270 | if ( recording) | 270 | if ( recording) |
271 | return FALSE;; | 271 | return FALSE;; |
272 | Config config( "Vmemo" ); | 272 | Config config( "Vmemo" ); |
273 | config.setGroup( "System" ); | 273 | config.setGroup( "System" ); |
274 | useAlerts = config.readBoolEntry("Alert"); | 274 | useAlerts = config.readBoolEntry("Alert"); |
275 | 275 | ||
276 | // if(useAlerts) | 276 | // if(useAlerts) |
277 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 277 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
278 | // return; | 278 | // return; |
279 | // } else { | 279 | // } else { |
280 | if (!systemZaurus ) | 280 | if (!systemZaurus ) |
281 | QSound::play(Resource::findSound("vmemob")); | 281 | QSound::play(Resource::findSound("vmemob")); |
282 | // } | 282 | // } |
283 | qDebug("Start recording"); | 283 | qDebug("Start recording"); |
284 | recording = TRUE; | 284 | recording = TRUE; |
285 | if (openDSP() == -1) { | 285 | if (openDSP() == -1) { |
286 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 286 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
287 | recording = FALSE; | 287 | recording = FALSE; |
288 | return FALSE; | 288 | return FALSE; |
289 | } | 289 | } |
290 | 290 | ||
291 | config.setGroup("Defaults"); | 291 | config.setGroup("Defaults"); |
292 | 292 | ||
293 | QDateTime dt = QDateTime::currentDateTime(); | 293 | QDateTime dt = QDateTime::currentDateTime(); |
294 | 294 | ||
295 | QString fName; | 295 | QString fName; |
296 | config.setGroup( "System" ); | 296 | config.setGroup( "System" ); |
297 | fName = QPEApplication::documentDir() ; | 297 | fName = QPEApplication::documentDir() ; |
298 | fileName = config.readEntry("RecLocation", fName); | 298 | fileName = config.readEntry("RecLocation", fName); |
299 | 299 | ||
300 | int s; | 300 | int s; |
301 | s=fileName.find(':'); | 301 | s=fileName.find(':'); |
302 | if(s) | 302 | if(s) |
303 | fileName=fileName.right(fileName.length()-s-2); | 303 | fileName=fileName.right(fileName.length()-s-2); |
304 | qDebug("filename will be "+fileName); | 304 | qDebug("filename will be "+fileName); |
305 | if( fileName.right(1).find('/') == -1) | 305 | if( fileName.left(1).find('/') == -1) |
306 | fileName+="/"; | 306 | fileName="/"+fileName; |
307 | if( fileName.right(1).find('/') == -1) | ||
308 | fileName+="/"; | ||
307 | fName = "vm_"+ dt.toString()+ ".wav"; | 309 | fName = "vm_"+ dt.toString()+ ".wav"; |
308 | 310 | ||
309 | fileName+=fName; | 311 | fileName+=fName; |
310 | qDebug("filename is "+fileName); | 312 | qDebug("filename is "+fileName); |
311 | // No spaces in the filename | 313 | // No spaces in the filename |
312 | fileName.replace(QRegExp("'"),""); | 314 | fileName.replace(QRegExp("'"),""); |
313 | fileName.replace(QRegExp(" "),"_"); | 315 | fileName.replace(QRegExp(" "),"_"); |
314 | fileName.replace(QRegExp(":"),"."); | 316 | fileName.replace(QRegExp(":"),"."); |
315 | fileName.replace(QRegExp(","),""); | 317 | fileName.replace(QRegExp(","),""); |
316 | 318 | ||
317 | if(openWAV(fileName.latin1()) == -1) { | 319 | if(openWAV(fileName.latin1()) == -1) { |
318 | QString err("Could not open the output file\n"); | 320 | QString err("Could not open the output file\n"); |
319 | err += fileName; | 321 | err += fileName; |
320 | QMessageBox::critical(0, "VMemo", err, "Abort"); | 322 | QMessageBox::critical(0, "VMemo", err, "Abort"); |
321 | close(dsp); | 323 | close(dsp); |
322 | return FALSE; | 324 | return FALSE; |
323 | } | 325 | } |
324 | 326 | ||
325 | QArray<int> cats(1); | 327 | QArray<int> cats(1); |
326 | cats[0] = config.readNumEntry("Category", 0); | 328 | cats[0] = config.readNumEntry("Category", 0); |
327 | 329 | ||
328 | QString dlName("vm_"); | 330 | QString dlName("vm_"); |
329 | dlName += dt.toString(); | 331 | dlName += dt.toString(); |
330 | DocLnk l; | 332 | DocLnk l; |
331 | l.setFile(fileName); | 333 | l.setFile(fileName); |
332 | l.setName(dlName); | 334 | l.setName(dlName); |
333 | l.setType("audio/x-wav"); | 335 | l.setType("audio/x-wav"); |
334 | l.setCategories(cats); | 336 | l.setCategories(cats); |
335 | l.writeLink(); | 337 | l.writeLink(); |
336 | 338 | ||
337 | record(); | 339 | record(); |
338 | return TRUE; | 340 | return TRUE; |
339 | } | 341 | } |
340 | 342 | ||
341 | void VMemo::stopRecording() { | 343 | void VMemo::stopRecording() { |
342 | recording = FALSE; | 344 | recording = FALSE; |
343 | } | 345 | } |
344 | 346 | ||
345 | int VMemo::openDSP() | 347 | int VMemo::openDSP() |
346 | { | 348 | { |
347 | Config cfg("Vmemo"); | 349 | Config cfg("Vmemo"); |
348 | cfg.setGroup("Record"); | 350 | cfg.setGroup("Record"); |
349 | 351 | ||
350 | speed = cfg.readNumEntry("SampleRate", 22050); | 352 | speed = cfg.readNumEntry("SampleRate", 22050); |
351 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 353 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
352 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 354 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
353 | format = AFMT_S16_LE; | 355 | format = AFMT_S16_LE; |
354 | resolution = 16; | 356 | resolution = 16; |
355 | } else { | 357 | } else { |
356 | format = AFMT_U8; | 358 | format = AFMT_U8; |
357 | resolution = 8; | 359 | resolution = 8; |
358 | } | 360 | } |
359 | 361 | ||
360 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 362 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
361 | 363 | ||
362 | if(systemZaurus) { | 364 | if(systemZaurus) { |
363 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 365 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
364 | channels=1; //zaurus has one input channel | 366 | channels=1; //zaurus has one input channel |
365 | } else { | 367 | } else { |
366 | dsp = open("/dev/dsp", O_RDWR); | 368 | dsp = open("/dev/dsp", O_RDWR); |
367 | } | 369 | } |
368 | 370 | ||
369 | if(dsp == -1) { | 371 | if(dsp == -1) { |
370 | perror("open(\"/dev/dsp\")"); | 372 | perror("open(\"/dev/dsp\")"); |
371 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 373 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
372 | return -1; | 374 | return -1; |
373 | } | 375 | } |
374 | 376 | ||
375 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 377 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
376 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 378 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
377 | return -1; | 379 | return -1; |
378 | } | 380 | } |
379 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 381 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
380 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 382 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
381 | return -1; | 383 | return -1; |
382 | } | 384 | } |
383 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 385 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
384 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 386 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
385 | return -1; | 387 | return -1; |
386 | } | 388 | } |
387 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 389 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
388 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 390 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
389 | return -1; | 391 | return -1; |
390 | } | 392 | } |
391 | 393 | ||
392 | return 1; | 394 | return 1; |
393 | } | 395 | } |
394 | 396 | ||
395 | int VMemo::openWAV(const char *filename) | 397 | int VMemo::openWAV(const char *filename) |
396 | { | 398 | { |
397 | track.setName(filename); | 399 | track.setName(filename); |
398 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 400 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
399 | errorMsg=filename; | 401 | errorMsg=filename; |
400 | return -1; | 402 | return -1; |
401 | } | 403 | } |
402 | 404 | ||
403 | wav=track.handle(); | 405 | wav=track.handle(); |
404 | 406 | ||
405 | WaveHeader wh; | 407 | WaveHeader wh; |
406 | 408 | ||
407 | wh.main_chunk = RIFF; | 409 | wh.main_chunk = RIFF; |
408 | wh.length=0; | 410 | wh.length=0; |
409 | wh.chunk_type = WAVE; | 411 | wh.chunk_type = WAVE; |
410 | wh.sub_chunk = FMT; | 412 | wh.sub_chunk = FMT; |
411 | wh.sc_len = 16; | 413 | wh.sc_len = 16; |
412 | wh.format = PCM_CODE; | 414 | wh.format = PCM_CODE; |
413 | wh.modus = channels; | 415 | wh.modus = channels; |
414 | wh.sample_fq = speed; | 416 | wh.sample_fq = speed; |
415 | wh.byte_p_sec = speed * channels * resolution/8; | 417 | wh.byte_p_sec = speed * channels * resolution/8; |
416 | wh.byte_p_spl = channels * (resolution / 8); | 418 | wh.byte_p_spl = channels * (resolution / 8); |
417 | wh.bit_p_spl = resolution; | 419 | wh.bit_p_spl = resolution; |
418 | wh.data_chunk = DATA; | 420 | wh.data_chunk = DATA; |
419 | wh.data_length= 0; | 421 | wh.data_length= 0; |
420 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 422 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
421 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 423 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
422 | write (wav, &wh, sizeof(WaveHeader)); | 424 | write (wav, &wh, sizeof(WaveHeader)); |
423 | 425 | ||
424 | return 1; | 426 | return 1; |
425 | } | 427 | } |
426 | 428 | ||
427 | void VMemo::record(void) | 429 | void VMemo::record(void) |
428 | { | 430 | { |
429 | int length=0, result, value; | 431 | int length=0, result, value; |
430 | qDebug("Recording"); | 432 | qDebug("Recording"); |
431 | 433 | ||
432 | if(systemZaurus) { | 434 | if(systemZaurus) { |
433 | signed short sound[512], monoBuffer[512]; | 435 | signed short sound[512], monoBuffer[512]; |
434 | if(format==AFMT_S16_LE) { | 436 | if(format==AFMT_S16_LE) { |
435 | while(recording) { | 437 | while(recording) { |
436 | result = read(dsp, sound, 512); // 8192 | 438 | result = read(dsp, sound, 512); // 8192 |
437 | int j=0; | 439 | int j=0; |
438 | if(systemZaurus) { | 440 | if(systemZaurus) { |
439 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 441 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
440 | monoBuffer[i] = sound[i]; | 442 | monoBuffer[i] = sound[i]; |
441 | } | 443 | } |
442 | length+=write(wav, monoBuffer, result); | 444 | length+=write(wav, monoBuffer, result); |
443 | } else { //ipaq /stereo inputs | 445 | } else { //ipaq /stereo inputs |
444 | for (int i = 0; i < result; i+=2) { | 446 | for (int i = 0; i < result; i+=2) { |
445 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 447 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
446 | j++; | 448 | j++; |
447 | } | 449 | } |
448 | length+=write(wav, monoBuffer, result/2); | 450 | length+=write(wav, monoBuffer, result/2); |
449 | } | 451 | } |
450 | // printf("%d\r",length); | 452 | // printf("%d\r",length); |
451 | // fflush(stdout); | 453 | // fflush(stdout); |
452 | } | 454 | } |
453 | } else { //AFMT_U8 | 455 | } else { //AFMT_U8 |
454 | // 8bit unsigned | 456 | // 8bit unsigned |
455 | unsigned short sound[512], monoBuffer[512]; | 457 | unsigned short sound[512], monoBuffer[512]; |
456 | while(recording) { | 458 | while(recording) { |
457 | result = read(dsp, sound, 512); // 8192 | 459 | result = read(dsp, sound, 512); // 8192 |
458 | int j=0; | 460 | int j=0; |
459 | if(systemZaurus) { | 461 | if(systemZaurus) { |
460 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 462 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
461 | monoBuffer[i] = sound[i]; | 463 | monoBuffer[i] = sound[i]; |
462 | } | 464 | } |
463 | length+=write(wav, monoBuffer, result); | 465 | length+=write(wav, monoBuffer, result); |
464 | } else { //ipaq /stereo inputs | 466 | } else { //ipaq /stereo inputs |
465 | for (int i = 0; i < result; i+=2) { | 467 | for (int i = 0; i < result; i+=2) { |
466 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 468 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
467 | j++; | 469 | j++; |
468 | } | 470 | } |
469 | length+=write(wav, monoBuffer, result/2); | 471 | length+=write(wav, monoBuffer, result/2); |
470 | } | 472 | } |
471 | length += result; | 473 | length += result; |
472 | // printf("%d\r",length); | 474 | // printf("%d\r",length); |
473 | // fflush(stdout); | 475 | // fflush(stdout); |
474 | } | 476 | } |
475 | 477 | ||
476 | qApp->processEvents(); | 478 | qApp->processEvents(); |
477 | } | 479 | } |
478 | 480 | ||
479 | } else { // this is specific for ipaqs that do not have 8 bit capabilities | 481 | } else { // this is specific for ipaqs that do not have 8 bit capabilities |
480 | 482 | ||
481 | signed short sound[512], monoBuffer[512]; | 483 | signed short sound[512], monoBuffer[512]; |
482 | 484 | ||
483 | while(recording) { | 485 | while(recording) { |
484 | result = read(dsp, sound, 512); // 8192 | 486 | result = read(dsp, sound, 512); // 8192 |
485 | write(wav, sound, result); | 487 | write(wav, sound, result); |
486 | length += result; | 488 | length += result; |
487 | 489 | ||
488 | qApp->processEvents(); | 490 | qApp->processEvents(); |
489 | } | 491 | } |
490 | // printf("%d\r",length); | 492 | // printf("%d\r",length); |
491 | // fflush(stdout); | 493 | // fflush(stdout); |
492 | // qDebug("file has length of %d lasting %d seconds", | 494 | // qDebug("file has length of %d lasting %d seconds", |
493 | // length, (( length / speed) / channels) / 2 ); | 495 | // length, (( length / speed) / channels) / 2 ); |
494 | // medialplayer states wrong length in secs | 496 | // medialplayer states wrong length in secs |
495 | } | 497 | } |
496 | 498 | ||
497 | value = length+36; | 499 | value = length+36; |
498 | lseek(wav, 4, SEEK_SET); | 500 | lseek(wav, 4, SEEK_SET); |