author | jeremy <jeremy> | 2002-02-16 03:38:51 (UTC) |
---|---|---|
committer | jeremy <jeremy> | 2002-02-16 03:38:51 (UTC) |
commit | f866bbd2fd77f07cff04a702eb52e59fcc0013b7 (patch) (unidiff) | |
tree | f5a3dbb1577c77e9a5cc8efa5d66b1b103989e0a | |
parent | f8744f9a9a59f7968ddbac66c927ba8da358f223 (diff) | |
download | opie-f866bbd2fd77f07cff04a702eb52e59fcc0013b7.zip opie-f866bbd2fd77f07cff04a702eb52e59fcc0013b7.tar.gz opie-f866bbd2fd77f07cff04a702eb52e59fcc0013b7.tar.bz2 |
Left a debug message box in the code. Opps. That was removed ("Recording
Done")
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 006e0ba..aa23ba7 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -146,258 +146,258 @@ VMemo::VMemo( QWidget *parent, const char *name ) | |||
146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
147 | 147 | ||
148 | struct utsname name; /* check for embedix kernel running on the zaurus, if | 148 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
149 | lineo change string, this break | 149 | lineo change string, this break |
150 | */ | 150 | */ |
151 | if (uname(&name) != -1) | 151 | if (uname(&name) != -1) |
152 | { | 152 | { |
153 | QString release=name.release; | 153 | QString release=name.release; |
154 | qWarning("System release: %s\n", name.release); | 154 | qWarning("System release: %s\n", name.release); |
155 | if(release.find("embedix",0,TRUE) !=-1) | 155 | if(release.find("embedix",0,TRUE) !=-1) |
156 | systemZaurus=TRUE; | 156 | systemZaurus=TRUE; |
157 | else | 157 | else |
158 | { | 158 | { |
159 | systemZaurus=FALSE; | 159 | systemZaurus=FALSE; |
160 | 160 | ||
161 | // Register the REC key press. | 161 | // Register the REC key press. |
162 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 162 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
163 | e << 4096; | 163 | e << 4096; |
164 | e << QString("QPE/VMemo"); | 164 | e << QString("QPE/VMemo"); |
165 | e << QString("toggleRecord()"); | 165 | e << QString("toggleRecord()"); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | qWarning("VMemo done init"); | 168 | qWarning("VMemo done init"); |
169 | } | 169 | } |
170 | 170 | ||
171 | VMemo::~VMemo() | 171 | VMemo::~VMemo() |
172 | { | 172 | { |
173 | } | 173 | } |
174 | 174 | ||
175 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 175 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
176 | { | 176 | { |
177 | QDataStream stream( data, IO_ReadOnly ); | 177 | QDataStream stream( data, IO_ReadOnly ); |
178 | qWarning("VMemo::receive: %s", (const char *)msg); | 178 | qWarning("VMemo::receive: %s", (const char *)msg); |
179 | if (msg == "toggleRecord()") | 179 | if (msg == "toggleRecord()") |
180 | { | 180 | { |
181 | if (recording) | 181 | if (recording) |
182 | mouseReleaseEvent(NULL); | 182 | mouseReleaseEvent(NULL); |
183 | else | 183 | else |
184 | mousePressEvent(NULL); | 184 | mousePressEvent(NULL); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | void VMemo::paintEvent( QPaintEvent* ) | 188 | void VMemo::paintEvent( QPaintEvent* ) |
189 | { | 189 | { |
190 | QPainter p(this); | 190 | QPainter p(this); |
191 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 191 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
192 | } | 192 | } |
193 | 193 | ||
194 | void VMemo::mousePressEvent( QMouseEvent * ) | 194 | void VMemo::mousePressEvent( QMouseEvent * ) |
195 | { | 195 | { |
196 | // just to be safe | 196 | // just to be safe |
197 | if (recording) | 197 | if (recording) |
198 | { | 198 | { |
199 | recording = FALSE; | 199 | recording = FALSE; |
200 | return; | 200 | return; |
201 | } | 201 | } |
202 | 202 | ||
203 | qWarning("VMemo::mousePress()"); | 203 | qWarning("VMemo::mousePress()"); |
204 | QSound::play(Resource::findSound("vmemob")); | 204 | QSound::play(Resource::findSound("vmemob")); |
205 | 205 | ||
206 | recording = TRUE; | 206 | recording = TRUE; |
207 | qWarning("VMemo::mousePress() -> Starting to record"); | 207 | qWarning("VMemo::mousePress() -> Starting to record"); |
208 | if (openDSP() == -1) | 208 | if (openDSP() == -1) |
209 | { | 209 | { |
210 | // ### Display an error box | 210 | // ### Display an error box |
211 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 211 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
212 | recording = FALSE; | 212 | recording = FALSE; |
213 | return; | 213 | return; |
214 | } | 214 | } |
215 | 215 | ||
216 | Config vmCfg("VMemo"); | 216 | Config vmCfg("VMemo"); |
217 | vmCfg.setGroup("Defaults"); | 217 | vmCfg.setGroup("Defaults"); |
218 | 218 | ||
219 | QDateTime dt = QDateTime::currentDateTime(); | 219 | QDateTime dt = QDateTime::currentDateTime(); |
220 | QString fileName; | 220 | QString fileName; |
221 | if(systemZaurus) | 221 | if(systemZaurus) |
222 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 222 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
223 | else | 223 | else |
224 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 224 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
225 | 225 | ||
226 | fileName += "vm_"; | 226 | fileName += "vm_"; |
227 | fileName += dt.toString(); | 227 | fileName += dt.toString(); |
228 | fileName += ".wav"; | 228 | fileName += ".wav"; |
229 | 229 | ||
230 | // No spaces in the filename | 230 | // No spaces in the filename |
231 | fileName.replace(QRegExp("'"),""); | 231 | fileName.replace(QRegExp("'"),""); |
232 | fileName.replace(QRegExp(" "),"_"); | 232 | fileName.replace(QRegExp(" "),"_"); |
233 | fileName.replace(QRegExp(":"),"."); | 233 | fileName.replace(QRegExp(":"),"."); |
234 | fileName.replace(QRegExp(","),""); | 234 | fileName.replace(QRegExp(","),""); |
235 | 235 | ||
236 | if(openWAV(fileName.latin1()) == -1) | 236 | if(openWAV(fileName.latin1()) == -1) |
237 | { | 237 | { |
238 | // ### Display an error box | 238 | // ### Display an error box |
239 | qWarning("VMemo::mousePress() -> WAV error"); | 239 | qWarning("VMemo::mousePress() -> WAV error"); |
240 | close(dsp); | 240 | close(dsp); |
241 | return; | 241 | return; |
242 | } | 242 | } |
243 | 243 | ||
244 | QArray<int> cats(1); | 244 | QArray<int> cats(1); |
245 | cats[0] = vmCfg.readNumEntry("Category", 0); | 245 | cats[0] = vmCfg.readNumEntry("Category", 0); |
246 | 246 | ||
247 | QString dlName("vm_"); | 247 | QString dlName("vm_"); |
248 | dlName += dt.toString(); | 248 | dlName += dt.toString(); |
249 | DocLnk l; | 249 | DocLnk l; |
250 | l.setFile(fileName); | 250 | l.setFile(fileName); |
251 | l.setName(dlName); | 251 | l.setName(dlName); |
252 | l.setType("audio/x-wav"); | 252 | l.setType("audio/x-wav"); |
253 | l.setCategories(cats); | 253 | l.setCategories(cats); |
254 | l.writeLink(); | 254 | l.writeLink(); |
255 | 255 | ||
256 | record(); | 256 | record(); |
257 | } | 257 | } |
258 | 258 | ||
259 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 259 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
260 | { | 260 | { |
261 | qWarning("VMemo::mouseRelese() -> Done recording"); | 261 | qWarning("VMemo::mouseRelese() -> Done recording"); |
262 | recording = FALSE; | 262 | recording = FALSE; |
263 | } | 263 | } |
264 | 264 | ||
265 | int VMemo::openDSP() | 265 | int VMemo::openDSP() |
266 | { | 266 | { |
267 | Config cfg("Sound"); | 267 | Config cfg("Sound"); |
268 | cfg.setGroup("Record"); | 268 | cfg.setGroup("Record"); |
269 | 269 | ||
270 | speed = cfg.readNumEntry("SampleRate", 22050); | 270 | speed = cfg.readNumEntry("SampleRate", 22050); |
271 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 271 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
272 | if (cfg.readNumEntry("SixteenBit", 1)==1) | 272 | if (cfg.readNumEntry("SixteenBit", 1)==1) |
273 | { | 273 | { |
274 | format = AFMT_S16_LE; | 274 | format = AFMT_S16_LE; |
275 | resolution = 16; | 275 | resolution = 16; |
276 | } | 276 | } |
277 | else | 277 | else |
278 | { | 278 | { |
279 | format = AFMT_U8; | 279 | format = AFMT_U8; |
280 | resolution = 8; | 280 | resolution = 8; |
281 | } | 281 | } |
282 | 282 | ||
283 | if(systemZaurus) | 283 | if(systemZaurus) |
284 | { | 284 | { |
285 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 285 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
286 | channels=1; //zaurus has one input channel | 286 | channels=1; //zaurus has one input channel |
287 | } | 287 | } |
288 | else | 288 | else |
289 | dsp = open("/dev/dsp", O_RDWR); | 289 | dsp = open("/dev/dsp", O_RDWR); |
290 | 290 | ||
291 | if(dsp == -1) | 291 | if(dsp == -1) |
292 | { | 292 | { |
293 | perror("open(\"/dev/dsp\")"); | 293 | perror("open(\"/dev/dsp\")"); |
294 | return -1; | 294 | return -1; |
295 | } | 295 | } |
296 | 296 | ||
297 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) | 297 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
298 | { | 298 | { |
299 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 299 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
300 | return -1; | 300 | return -1; |
301 | } | 301 | } |
302 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) | 302 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
303 | { | 303 | { |
304 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 304 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) | 307 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
308 | { | 308 | { |
309 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 309 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
310 | return -1; | 310 | return -1; |
311 | } | 311 | } |
312 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) | 312 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
313 | { | 313 | { |
314 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 314 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
315 | return -1; | 315 | return -1; |
316 | } | 316 | } |
317 | 317 | ||
318 | return 1; | 318 | return 1; |
319 | } | 319 | } |
320 | 320 | ||
321 | int VMemo::openWAV(const char *filename) | 321 | int VMemo::openWAV(const char *filename) |
322 | { | 322 | { |
323 | qDebug("Creating %s ",filename); | 323 | qDebug("Creating %s ",filename); |
324 | track.setName(filename); | 324 | track.setName(filename); |
325 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 325 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
326 | { | 326 | { |
327 | qDebug("Could not open file"); | 327 | qDebug("Could not open file"); |
328 | return -1; | 328 | return -1; |
329 | } | 329 | } |
330 | wav=track.handle(); | 330 | wav=track.handle(); |
331 | 331 | ||
332 | WaveHeader wh; | 332 | WaveHeader wh; |
333 | 333 | ||
334 | wh.main_chunk = RIFF; | 334 | wh.main_chunk = RIFF; |
335 | wh.length=0; | 335 | wh.length=0; |
336 | wh.chunk_type = WAVE; | 336 | wh.chunk_type = WAVE; |
337 | wh.sub_chunk = FMT; | 337 | wh.sub_chunk = FMT; |
338 | wh.sc_len = 16; | 338 | wh.sc_len = 16; |
339 | wh.format = PCM_CODE; | 339 | wh.format = PCM_CODE; |
340 | wh.modus = channels; | 340 | wh.modus = channels; |
341 | wh.sample_fq = speed; | 341 | wh.sample_fq = speed; |
342 | wh.byte_p_sec = speed * channels * resolution/8; | 342 | wh.byte_p_sec = speed * channels * resolution/8; |
343 | wh.byte_p_spl = channels * (resolution / 8); | 343 | wh.byte_p_spl = channels * (resolution / 8); |
344 | wh.bit_p_spl = resolution; | 344 | wh.bit_p_spl = resolution; |
345 | wh.data_chunk = DATA; | 345 | wh.data_chunk = DATA; |
346 | wh.data_length= 0; | 346 | wh.data_length= 0; |
347 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 347 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
348 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 348 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
349 | write (wav, &wh, sizeof(WaveHeader)); | 349 | write (wav, &wh, sizeof(WaveHeader)); |
350 | 350 | ||
351 | return 1; | 351 | return 1; |
352 | } | 352 | } |
353 | 353 | ||
354 | void VMemo::record(void) | 354 | void VMemo::record(void) |
355 | { | 355 | { |
356 | int length=0, result, value; //, i; | 356 | int length=0, result, value; //, i; |
357 | char sound[512]; //, leftBuffer[256], rightBuffer[256]; | 357 | char sound[512]; //, leftBuffer[256], rightBuffer[256]; |
358 | 358 | ||
359 | qWarning("VMemo::record()"); | 359 | qWarning("VMemo::record()"); |
360 | 360 | ||
361 | while(recording) | 361 | while(recording) |
362 | { | 362 | { |
363 | result = read(dsp, sound, 512); // 8192 | 363 | result = read(dsp, sound, 512); // 8192 |
364 | qApp->processEvents(); | 364 | qApp->processEvents(); |
365 | 365 | ||
366 | /* attempt to write only one channel...didnt work. | 366 | /* attempt to write only one channel...didnt work. |
367 | for (i = 0; i < result; i++) { | 367 | for (i = 0; i < result; i++) { |
368 | leftBuffer[i] = sound[2*i]; | 368 | leftBuffer[i] = sound[2*i]; |
369 | rightBuffer[i] = sound[2*i+1]; | 369 | rightBuffer[i] = sound[2*i+1]; |
370 | } | 370 | } |
371 | */ | 371 | */ |
372 | qApp->processEvents(); | 372 | qApp->processEvents(); |
373 | 373 | ||
374 | /* needed to only write one channel. comment out above "write/length" code. | 374 | /* needed to only write one channel. comment out above "write/length" code. |
375 | write(wav, leftBuffer, result / 2); | 375 | write(wav, leftBuffer, result / 2); |
376 | length += result/2; | 376 | length += result/2; |
377 | */ | 377 | */ |
378 | 378 | ||
379 | write(wav, sound, result); | 379 | write(wav, sound, result); |
380 | length += result; | 380 | length += result; |
381 | 381 | ||
382 | qApp->processEvents(); | 382 | qApp->processEvents(); |
383 | } | 383 | } |
384 | 384 | ||
385 | qWarning("VMemo::record() -> Done recording"); | 385 | qWarning("VMemo::record() -> Done recording"); |
386 | qWarning("VMemo::record() -> Closing dsp"); | 386 | qWarning("VMemo::record() -> Closing dsp"); |
387 | 387 | ||
388 | value = length+36; | 388 | value = length+36; |
389 | lseek(wav, 4, SEEK_SET); | 389 | lseek(wav, 4, SEEK_SET); |
390 | write(wav, &value, 4); | 390 | write(wav, &value, 4); |
391 | lseek(wav, 40, SEEK_SET); | 391 | lseek(wav, 40, SEEK_SET); |
392 | write(wav, &length, 4); | 392 | write(wav, &length, 4); |
393 | track.close(); | 393 | track.close(); |
394 | 394 | ||
395 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 395 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
396 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 396 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
397 | ::close(dsp); | 397 | ::close(dsp); |
398 | 398 | ||
399 | qWarning("VMemo::record() -> playing done recording sound"); | 399 | qWarning("VMemo::record() -> playing done recording sound"); |
400 | QSound::play(Resource::findSound("vmemoe")); | 400 | QSound::play(Resource::findSound("vmemoe")); |
401 | qWarning("VMemo::record() -> terminating"); | 401 | qWarning("VMemo::record() -> terminating"); |
402 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | 402 | //QMessageBox::information(0, "VMemo", "Recording Done", 1); |
403 | } | 403 | } |