summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-11-13 06:23:48 (UTC)
committer llornkcor <llornkcor>2003-11-13 06:23:48 (UTC)
commit452f0cc3d9fdd792d2050ceaffd33b3d1611fcc3 (patch) (unidiff)
treed391cef8c2c278f335c18344e4c6bf01589eaa50
parenta539861cbebf3517472d01ee6e9b34e9f763156e (diff)
downloadopie-452f0cc3d9fdd792d2050ceaffd33b3d1611fcc3.zip
opie-452f0cc3d9fdd792d2050ceaffd33b3d1611fcc3.tar.gz
opie-452f0cc3d9fdd792d2050ceaffd33b3d1611fcc3.tar.bz2
added waveform
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/qtrec.cpp14
-rw-r--r--noncore/multimedia/opierec/waveform.cpp160
-rw-r--r--noncore/multimedia/opierec/waveform.h63
3 files changed, 230 insertions, 7 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp
index 2bf795f..1e36c96 100644
--- a/noncore/multimedia/opierec/qtrec.cpp
+++ b/noncore/multimedia/opierec/qtrec.cpp
@@ -1,488 +1,488 @@
1/**************************************************************************** 1/****************************************************************************
2 // qtrec.cpp 2 // qtrec.cpp
3 Created: Thu Jan 17 11:19:58 2002 3 Created: Thu Jan 17 11:19:58 2002
4 copyright 2002 by L.J. Potter <ljp@llornkcor.com> 4 copyright 2002 by L.J. Potter <ljp@llornkcor.com>
5****************************************************************************/ 5****************************************************************************/
6 6
7#define DEV_VERSION 7#define DEV_VERSION
8 8
9#include "pixmaps.h" 9#include "pixmaps.h"
10#include "qtrec.h" 10#include "qtrec.h"
11 11
12#include <pthread.h> 12#include <pthread.h>
13 13
14extern "C" { 14extern "C" {
15#include "adpcm.h" 15#include "adpcm.h"
16} 16}
17 17
18#include <sys/soundcard.h> 18#include <sys/soundcard.h>
19 19
20// #if defined (QTOPIA_INTERNAL_FSLP) 20// #if defined (QTOPIA_INTERNAL_FSLP)
21// #include <qpe/lnkproperties.h> 21// #include <qpe/lnkproperties.h>
22// #endif 22// #endif
23 23
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/resource.h> 27#include <qpe/resource.h>
28#include <qpe/storage.h> 28#include <qpe/storage.h>
29 29
30#include <qcheckbox.h> 30#include <qcheckbox.h>
31#include <qcombobox.h> 31#include <qcombobox.h>
32//#include <qdatetime.h> 32//#include <qdatetime.h>
33#include <qdir.h> 33#include <qdir.h>
34#include <qgroupbox.h> 34#include <qgroupbox.h>
35#include <qlabel.h> 35#include <qlabel.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qlistview.h> 37#include <qlistview.h>
38#include <qmessagebox.h> 38#include <qmessagebox.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qslider.h> 41#include <qslider.h>
42#include <qtabwidget.h> 42#include <qtabwidget.h>
43#include <qtimer.h> 43#include <qtimer.h>
44 44
45#include <errno.h> 45#include <errno.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <math.h> 47#include <math.h>
48#include <mntent.h> 48#include <mntent.h>
49#include <stdio.h> 49#include <stdio.h>
50#include <stdlib.h> 50#include <stdlib.h>
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <sys/soundcard.h> 52#include <sys/soundcard.h>
53#include <sys/stat.h> 53#include <sys/stat.h>
54#include <sys/time.h> 54#include <sys/time.h>
55#include <sys/types.h> 55#include <sys/types.h>
56#include <sys/vfs.h> 56#include <sys/vfs.h>
57#include <unistd.h> 57#include <unistd.h>
58#include<sys/wait.h> 58#include<sys/wait.h>
59#include <sys/signal.h> 59#include <sys/signal.h>
60 60
61//#define ZAURUS 0 61//#define ZAURUS 0
62struct adpcm_state encoder_state; 62struct adpcm_state encoder_state;
63struct adpcm_state decoder_state; 63struct adpcm_state decoder_state;
64 64
65long findPeak(long input ); 65long findPeak(long input );
66//char deviceRates[]; 66//char deviceRates[];
67 67
68typedef struct { 68typedef struct {
69 int sampleRate; 69 int sampleRate;
70 /* int fragSize; */ 70 /* int fragSize; */
71 /* int blockSize; */ 71 /* int blockSize; */
72 int resolution; //bitrate 72 int resolution; //bitrate
73 int channels; //number of channels 73 int channels; //number of channels
74 int fd; //file descriptor 74 int fd; //file descriptor
75 int sd; //sound device descriptor 75 int sd; //sound device descriptor
76 int numberSamples; //total number of samples 76 int numberSamples; //total number of samples
77 int SecondsToRecord; // number of seconds that should be recorded 77 int SecondsToRecord; // number of seconds that should be recorded
78 float numberOfRecordedSeconds; //total number of samples recorded 78 float numberOfRecordedSeconds; //total number of samples recorded
79 int samplesToRecord; //number of samples to be recorded 79 int samplesToRecord; //number of samples to be recorded
80 int inVol; //input volume 80 int inVol; //input volume
81 int outVol; //output volume 81 int outVol; //output volume
82 int format; //wavfile format PCM.. ADPCM 82 int format; //wavfile format PCM.. ADPCM
83 const char *fileName; //name of fiel to be played/recorded 83 const char *fileName; //name of fiel to be played/recorded
84} fileParameters; 84} fileParameters;
85 85
86fileParameters filePara; 86fileParameters filePara;
87 87
88bool monitoring, recording; 88bool monitoring, recording;
89bool stopped; 89bool stopped;
90QLabel *timeLabel; 90QLabel *timeLabel;
91QSlider *timeSlider; 91QSlider *timeSlider;
92int sd; 92int sd;
93 93
94#if defined(QT_QWS_EBX) 94// #if defined(QT_QWS_EBX)
95#define DSPSTROUT "/dev/dsp" 95// #define DSPSTROUT "/dev/dsp"
96#define DSPSTRIN "/dev/dsp1" 96// #define DSPSTRIN "/dev/dsp1"
97#define DSPSTRMIXEROUT "/dev/mixer" 97// #define DSPSTRMIXEROUT "/dev/mixer"
98#define DSPSTRMIXERIN "/dev/mixer1" 98// #define DSPSTRMIXERIN "/dev/mixer1"
99#else 99// #else
100#define DSPSTROUT "/dev/dsp" 100#define DSPSTROUT "/dev/dsp"
101#define DSPSTRIN "/dev/dsp" 101#define DSPSTRIN "/dev/dsp"
102#define DSPSTRMIXERIN "/dev/mixer" 102#define DSPSTRMIXERIN "/dev/mixer"
103#define DSPSTRMIXEROUT "/dev/mixer" 103#define DSPSTRMIXEROUT "/dev/mixer"
104#endif 104//#endif
105 105
106// threaded recording 106// threaded recording
107void quickRec() { 107void quickRec() {
108//void QtRec::quickRec() { 108//void QtRec::quickRec() {
109 109
110 int total = 0; // Total number of bytes read in so far. 110 int total = 0; // Total number of bytes read in so far.
111 int bytesWritten, number; 111 int bytesWritten, number;
112 112
113 count_info info; 113 count_info info;
114 114
115 bytesWritten=0; 115 bytesWritten=0;
116 number=0; 116 number=0;
117 QString num, timeString; 117 QString num, timeString;
118 int level=0; 118 int level=0;
119 int threshold=0; 119 int threshold=0;
120 // if(limit != 0) 120 // if(limit != 0)
121 // t->start( ( limit +.3) , true); 121 // t->start( ( limit +.3) , true);
122 122
123 recording = true; 123 recording = true;
124 //rate=filePara.sampleRate; 124 //rate=filePara.sampleRate;
125 // int bits = filePara.resolution; 125 // int bits = filePara.resolution;
126 audio_buf_info inInfo; 126 audio_buf_info inInfo;
127 ioctl( filePara.fd, SNDCTL_DSP_GETISPACE, &inInfo); 127 ioctl( filePara.fd, SNDCTL_DSP_GETISPACE, &inInfo);
128 // qDebug("ispace is frags %d, total %d", inInfo.fragments, inInfo.fragstotal); 128 // qDebug("ispace is frags %d, total %d", inInfo.fragments, inInfo.fragstotal);
129 129
130 if( filePara.resolution == 16 ) { //AFMT_S16_LE) 130 if( filePara.resolution == 16 ) { //AFMT_S16_LE)
131 level=7; 131 level=7;
132 threshold=0; 132 threshold=0;
133 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); 133 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
134 timeLabel->setText( timeString+ " seconds"); 134 timeLabel->setText( timeString+ " seconds");
135 135
136 if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { 136 if( filePara.format==WAVE_FORMAT_DVI_ADPCM) {
137 // qDebug("start recording WAVE_FORMAT_DVI_ADPCM"); 137 // qDebug("start recording WAVE_FORMAT_DVI_ADPCM");
138 char abuf[BUFSIZE/2]; 138 char abuf[BUFSIZE/2];
139 short sbuf[BUFSIZE]; 139 short sbuf[BUFSIZE];
140 short sbuf2[BUFSIZE]; 140 short sbuf2[BUFSIZE];
141 memset( abuf,0,BUFSIZE/2); 141 memset( abuf,0,BUFSIZE/2);
142 memset( sbuf,0,BUFSIZE); 142 memset( sbuf,0,BUFSIZE);
143 memset( sbuf2,0,BUFSIZE); 143 memset( sbuf2,0,BUFSIZE);
144 144
145 for(;;) { 145 for(;;) {
146 if (stopped) { 146 if (stopped) {
147 break; // stop if playing was set to false 147 break; // stop if playing was set to false
148 } 148 }
149 149
150 number=::read( filePara.sd, sbuf, BUFSIZE); 150 number=::read( filePara.sd, sbuf, BUFSIZE);
151 if(number <= 0) { 151 if(number <= 0) {
152 perror("recording error "); 152 perror("recording error ");
153 // qDebug( "%s %d", filePara.fileName, number); 153 // qDebug( "%s %d", filePara.fileName, number);
154 // errorStop(); 154 // errorStop();
155 recording=stopped=false; 155 recording=stopped=false;
156// QMessageBox::message("Note", "Error recording to file\n%s",filePara.fileName); 156// QMessageBox::message("Note", "Error recording to file\n%s",filePara.fileName);
157 return; 157 return;
158 } 158 }
159 //if(stereo == 2) { 159 //if(stereo == 2) {
160// adpcm_coder( sbuf2, abuf, number/2, &encoder_state); 160// adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
161 adpcm_coder( sbuf, abuf, number/2, &encoder_state); 161 adpcm_coder( sbuf, abuf, number/2, &encoder_state);
162 bytesWritten = ::write( filePara.fd , abuf, number/4); 162 bytesWritten = ::write( filePara.fd , abuf, number/4);
163 long peak; 163 long peak;
164 for (int i = 0; i < number; i++) 164 for (int i = 0; i < number; i++)
165 { //since Z is mono do normally 165 { //since Z is mono do normally
166 peak = findPeak((long)sbuf[i]); 166 peak = findPeak((long)sbuf[i]);
167 printf("peak %ld\r",peak); 167 printf("peak %ld\r",peak);
168 fflush(stdout); 168 fflush(stdout);
169 } 169 }
170 //------------->>>> out to file 170 //------------->>>> out to file
171 // if(filePara.channels==1) 171 // if(filePara.channels==1)
172 // total += bytesWritten/2; //mono 172 // total += bytesWritten/2; //mono
173 // else 173 // else
174 total += bytesWritten; 174 total += bytesWritten;
175 filePara.numberSamples = total; 175 filePara.numberSamples = total;
176// if( total >= filePara.samplesToRecord) 176// if( total >= filePara.samplesToRecord)
177// timeSlider->setValue(0); 177// timeSlider->setValue(0);
178// else if( filePara.SecondsToRecord !=0) 178// else if( filePara.SecondsToRecord !=0)
179 timeSlider->setValue( total); 179 timeSlider->setValue( total);
180 180
181 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2; 181 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2;
182 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info); 182 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info);
183 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); 183 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
184 timeLabel->setText( timeString + " seconds"); 184 timeLabel->setText( timeString + " seconds");
185 185
186 qApp->processEvents(); 186 qApp->processEvents();
187 if( total >= filePara.samplesToRecord) 187 if( total >= filePara.samplesToRecord)
188 break; 188 break;
189 } 189 }
190 } else { 190 } else {
191 // qDebug("start recording WAVE_FORMAT_PCM"); 191 // qDebug("start recording WAVE_FORMAT_PCM");
192 short inbuffer[BUFSIZE], outbuffer[BUFSIZE]; 192 short inbuffer[BUFSIZE], outbuffer[BUFSIZE];
193 memset( inbuffer,0,BUFSIZE); 193 memset( inbuffer,0,BUFSIZE);
194 memset( outbuffer,0,BUFSIZE); 194 memset( outbuffer,0,BUFSIZE);
195 for(;;) { 195 for(;;) {
196 if (stopped) { 196 if (stopped) {
197 break; // stop if playing was set to false 197 break; // stop if playing was set to false
198 } 198 }
199 199
200 number=::read( filePara.sd, inbuffer, BUFSIZE); 200 number=::read( filePara.sd, inbuffer, BUFSIZE);
201 if(number <= 0) { 201 if(number <= 0) {
202 perror("recording error "); 202 perror("recording error ");
203 recording=stopped=false; 203 recording=stopped=false;
204 // errorStop(); 204 // errorStop();
205 return;// false; 205 return;// false;
206 } 206 }
207/* for (int i=0;i< number;i++) { //2*i is left channel 207/* for (int i=0;i< number;i++) { //2*i is left channel
208outbuffer[i]=inbuffer[i]>>1; // no clippy, please 208outbuffer[i]=inbuffer[i]>>1; // no clippy, please
209}*/ 209}*/
210 bytesWritten = ::write( filePara.fd , inbuffer, number); 210 bytesWritten = ::write( filePara.fd , inbuffer, number);
211//------------->>>> out to file 211//------------->>>> out to file
212 if(bytesWritten < 0) { 212 if(bytesWritten < 0) {
213 // errorStop(); 213 // errorStop();
214 perror("File writing error "); 214 perror("File writing error ");
215 return;// false; 215 return;// false;
216 } 216 }
217 217
218 // if(filePara.channels==1) 218 // if(filePara.channels==1)
219 // total += bytesWritten/2; //mono 219 // total += bytesWritten/2; //mono
220 // else 220 // else
221 total += bytesWritten; 221 total += bytesWritten;
222 long peak; 222 long peak;
223 for (int i = 0; i < number; i++) 223 for (int i = 0; i < number; i++)
224 { //since Z is mono do normally 224 { //since Z is mono do normally
225 peak = findPeak((long)inbuffer[i]); 225 peak = findPeak((long)inbuffer[i]);
226 printf("peak %ld\r",peak); 226 printf("peak %ld\r",peak);
227 fflush(stdout); 227 fflush(stdout);
228 } 228 }
229 filePara.numberSamples = total; 229 filePara.numberSamples = total;
230 if(filePara.SecondsToRecord !=0) 230 if(filePara.SecondsToRecord !=0)
231 timeSlider->setValue( total); 231 timeSlider->setValue( total);
232// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total); 232// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total);
233// fflush(stdout); 233// fflush(stdout);
234 234
235 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info); 235 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info);
236// qDebug("%d, %d", info.bytes, ( info.bytes / filePara.sampleRate) / 2); 236// qDebug("%d, %d", info.bytes, ( info.bytes / filePara.sampleRate) / 2);
237 237
238 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; 238 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
239 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); 239 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
240 timeLabel->setText( timeString + " seconds"); 240 timeLabel->setText( timeString + " seconds");
241 qApp->processEvents(); 241 qApp->processEvents();
242 if( total >= filePara.samplesToRecord) 242 if( total >= filePara.samplesToRecord)
243 break; 243 break;
244 } 244 }
245 } //end main loop 245 } //end main loop
246 246
247 } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; 247 } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8;
248 unsigned char unsigned_inbuffer[BUFSIZE], unsigned_outbuffer[BUFSIZE]; 248 unsigned char unsigned_inbuffer[BUFSIZE], unsigned_outbuffer[BUFSIZE];
249 memset( unsigned_inbuffer, 0, BUFSIZE); 249 memset( unsigned_inbuffer, 0, BUFSIZE);
250 memset( unsigned_outbuffer, 0, BUFSIZE); 250 memset( unsigned_outbuffer, 0, BUFSIZE);
251 251
252 for(;;) { 252 for(;;) {
253 if (stopped) { 253 if (stopped) {
254 // qDebug("quickRec:: stopped"); 254 // qDebug("quickRec:: stopped");
255 break; // stop if playing was set to false 255 break; // stop if playing was set to false
256 } 256 }
257 number=::read( filePara.sd, unsigned_inbuffer, BUFSIZE); 257 number=::read( filePara.sd, unsigned_inbuffer, BUFSIZE);
258//-------------<<<< in from device 258//-------------<<<< in from device
259// val = (data ^ 0x80) << 8; 259// val = (data ^ 0x80) << 8;
260 260
261//unsigned_outbuffer = (unsigned_inbuffer ^ 0x80) << 8; 261//unsigned_outbuffer = (unsigned_inbuffer ^ 0x80) << 8;
262 262
263// if(number <= 0) { 263// if(number <= 0) {
264// perror("recording error "); 264// perror("recording error ");
265// qDebug(filePara.fileName); 265// qDebug(filePara.fileName);
266// // errorStop(); 266// // errorStop();
267// QMessageBox::message("Note","error recording"); 267// QMessageBox::message("Note","error recording");
268// return;// false; 268// return;// false;
269// } 269// }
270// for (int i=0;i< number;i++) { //2*i is left channel 270// for (int i=0;i< number;i++) { //2*i is left channel
271// unsigned_outbuffer[i]=unsigned_inbuffer[i]>>1; // no clippy, please 271// unsigned_outbuffer[i]=unsigned_inbuffer[i]>>1; // no clippy, please
272// } 272// }
273 273
274 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); 274 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
275 275
276//------------->>>> out to file 276//------------->>>> out to file
277 if(bytesWritten < 0) { 277 if(bytesWritten < 0) {
278 recording=stopped=false; 278 recording=stopped=false;
279 // errorStop(); 279 // errorStop();
280 QMessageBox::message("Note","There was a problem\nwriting to the file"); 280 QMessageBox::message("Note","There was a problem\nwriting to the file");
281 perror("File writing error "); 281 perror("File writing error ");
282 return;// false; 282 return;// false;
283 } 283 }
284 total += bytesWritten; 284 total += bytesWritten;
285 filePara.numberSamples = total; 285 filePara.numberSamples = total;
286 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); 286 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total);
287 // fflush(stdout); 287 // fflush(stdout);
288 if(filePara.SecondsToRecord !=0) 288 if(filePara.SecondsToRecord !=0)
289 timeSlider->setValue( total); 289 timeSlider->setValue( total);
290 290
291 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; 291 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
292 292
293 timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); 293 timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
294 timeLabel->setText( timeString + " seconds"); 294 timeLabel->setText( timeString + " seconds");
295 295
296 qApp->processEvents(); 296 qApp->processEvents();
297 if( total >= filePara.samplesToRecord) 297 if( total >= filePara.samplesToRecord)
298 break; 298 break;
299 } //end main loop 299 } //end main loop
300 } 300 }
301// qDebug("Final %d, %d", filePara.samplesToRecord , filePara.numberOfRecordedSeconds); 301// qDebug("Final %d, %d", filePara.samplesToRecord , filePara.numberOfRecordedSeconds);
302} /// END quickRec() 302} /// END quickRec()
303 303
304// threaded play 304// threaded play
305void playIt() { 305void playIt() {
306 306
307} 307}
308 308
309/////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> 309/////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>
310QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) 310QtRec::QtRec( QWidget* parent, const char* name, WFlags fl )
311 : QWidget( parent, name, fl ) { 311 : QWidget( parent, name, fl ) {
312 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device 312 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device
313 // autoMute=TRUE; 313 // autoMute=TRUE;
314// QPEApplication::grabKeyboard(); 314// QPEApplication::grabKeyboard();
315 315
316 if ( !name ) 316 if ( !name )
317 setName( "OpieRec" ); 317 setName( "OpieRec" );
318 init(); 318 init();
319 initConfig(); 319 initConfig();
320 initConnections(); 320 initConnections();
321 renameBox = 0; 321 renameBox = 0;
322 322
323// open sound device to get volumes 323// open sound device to get volumes
324 soundDevice = new Device( this, DSPSTROUT, DSPSTRMIXEROUT, false); 324 soundDevice = new Device( this, DSPSTROUT, DSPSTRMIXEROUT, false);
325 325
326// soundDevice->setDeviceFormat(AFMT_S16_LE); 326// soundDevice->setDeviceFormat(AFMT_S16_LE);
327// soundDevice->setDeviceChannels(1); 327// soundDevice->setDeviceChannels(1);
328// soundDevice->setDeviceRate( 22050); 328// soundDevice->setDeviceRate( 22050);
329 329
330 getInVol(); 330 getInVol();
331 getOutVol(); 331 getOutVol();
332 332
333 soundDevice->closeDevice( true); 333 soundDevice->closeDevice( true);
334 soundDevice->sd=-1; 334 soundDevice->sd=-1;
335 soundDevice=0; 335 soundDevice=0;
336 wavFile=0; 336 wavFile=0;
337 337
338 if(soundDevice) delete soundDevice; 338 if(soundDevice) delete soundDevice;
339 339
340 initIconView(); 340 initIconView();
341 341
342 if(autoMute) 342 if(autoMute)
343 doMute(true); 343 doMute(true);
344 ListView1->setFocus(); 344 ListView1->setFocus();
345 playing=false; 345 playing=false;
346} 346}
347 347
348QtRec::~QtRec() { 348QtRec::~QtRec() {
349 349
350} 350}
351 351
352void QtRec::cleanUp() { 352void QtRec::cleanUp() {
353 353
354 if(!stopped) { 354 if(!stopped) {
355 stopped=true; 355 stopped=true;
356 endRecording(); 356 endRecording();
357 } 357 }
358 358
359 ListView1->clear(); 359 ListView1->clear();
360 360
361 if(autoMute) 361 if(autoMute)
362 doMute(false); 362 doMute(false);
363 363
364 if(wavFile) delete wavFile; 364 if(wavFile) delete wavFile;
365// if(soundDevice) delete soundDevice; 365// if(soundDevice) delete soundDevice;
366// QPEApplication::grabKeyboard(); 366// QPEApplication::grabKeyboard();
367// QPEApplication::ungrabKeyboard(); 367// QPEApplication::ungrabKeyboard();
368} 368}
369 369
370void QtRec::init() { 370void QtRec::init() {
371 371
372 needsStereoOut=false; 372 needsStereoOut=false;
373 QPixmap image3( ( const char** ) image3_data ); 373 QPixmap image3( ( const char** ) image3_data );
374 QPixmap image4( ( const char** ) image4_data ); 374 QPixmap image4( ( const char** ) image4_data );
375 QPixmap image6( ( const char** ) image6_data ); 375 QPixmap image6( ( const char** ) image6_data );
376 376
377 stopped=true; 377 stopped=true;
378 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); 378 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) );
379 QGridLayout *layout = new QGridLayout( this ); 379 QGridLayout *layout = new QGridLayout( this );
380 layout->setSpacing( 2); 380 layout->setSpacing( 2);
381 layout->setMargin( 2); 381 layout->setMargin( 2);
382 382
383 TabWidget = new QTabWidget( this, "TabWidget" ); 383 TabWidget = new QTabWidget( this, "TabWidget" );
384 layout->addMultiCellWidget(TabWidget, 0, 7, 0, 7); 384 layout->addMultiCellWidget(TabWidget, 0, 7, 0, 7);
385 // TabWidget->setTabShape(QTabWidget::Triangular); 385 // TabWidget->setTabShape(QTabWidget::Triangular);
386 386
387 ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** 387 ///**********<<<<<<<<<<<<>>>>>>>>>>>>***************
388 tab = new QWidget( TabWidget, "tab" ); 388 tab = new QWidget( TabWidget, "tab" );
389 389
390 QGridLayout *layout1 = new QGridLayout( tab); 390 QGridLayout *layout1 = new QGridLayout( tab);
391 layout1->setSpacing( 2); 391 layout1->setSpacing( 2);
392 layout1->setMargin( 2); 392 layout1->setMargin( 2);
393 393
394 timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); 394 timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" );
395 // timeSlider->setFixedWidth(150); 395 // timeSlider->setFixedWidth(150);
396 layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); 396 layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3);
397// timeSlider->setTickmarks(QSlider::Above); 397// timeSlider->setTickmarks(QSlider::Above);
398 398
399 timeLabel = new QLabel( tab, "TimeLabel" ); 399 timeLabel = new QLabel( tab, "TimeLabel" );
400 layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); 400 layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3);
401 401
402 playLabel2 = new QLabel(tab, "PlayLabel2" ); 402 playLabel2 = new QLabel(tab, "PlayLabel2" );
403 playLabel2->setText(tr("Play") ); 403 playLabel2->setText(tr("Play") );
404 playLabel2->setFixedHeight(18); 404 playLabel2->setFixedHeight(18);
405 layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); 405 layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4);
406 406
407 Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); 407 Stop_PushButton = new QPushButton( tab, "Stop_PushButton" );
408 layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); 408 layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4);
409 Stop_PushButton->setFixedSize(22,22); 409 Stop_PushButton->setFixedSize(22,22);
410 Stop_PushButton->setPixmap( image4 ); 410 Stop_PushButton->setPixmap( image4 );
411 411
412 toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); 412 toBeginningButton = new QPushButton( tab, "Beginning_PushButton" );
413 layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); 413 layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5);
414 toBeginningButton->setFixedSize(22,22); 414 toBeginningButton->setFixedSize(22,22);
415 toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); 415 toBeginningButton->setPixmap( Resource::loadPixmap("fastback") );
416 416
417 toEndButton = new QPushButton( tab, "End_PushButton" ); 417 toEndButton = new QPushButton( tab, "End_PushButton" );
418 layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); 418 layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6);
419 toEndButton->setFixedSize(22,22); 419 toEndButton->setFixedSize(22,22);
420 toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); 420 toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) );
421 421
422 QLabel *recLabel2; 422 QLabel *recLabel2;
423 recLabel2 = new QLabel( tab, "recLabel2" ); 423 recLabel2 = new QLabel( tab, "recLabel2" );
424 recLabel2->setText(tr("Rec")); 424 recLabel2->setText(tr("Rec"));
425 recLabel2->setFixedHeight(18); 425 recLabel2->setFixedHeight(18);
426 layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); 426 layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7);
427 427
428 Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); 428 Rec_PushButton = new QPushButton( tab, "Rec_PushButton" );
429 layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); 429 layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7);
430 Rec_PushButton->setFixedSize(22,22); 430 Rec_PushButton->setFixedSize(22,22);
431 Rec_PushButton->setPixmap( image6 ); 431 Rec_PushButton->setPixmap( image6 );
432 432
433 t = new QTimer( this ); 433 t = new QTimer( this );
434 connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 434 connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) );
435 435
436 rewindTimer = new QTimer( this ); 436 rewindTimer = new QTimer( this );
437 connect( rewindTimer, SIGNAL( timeout() ), SLOT( rewindTimerTimeout() ) ); 437 connect( rewindTimer, SIGNAL( timeout() ), SLOT( rewindTimerTimeout() ) );
438 438
439 forwardTimer = new QTimer( this ); 439 forwardTimer = new QTimer( this );
440 connect( forwardTimer, SIGNAL( timeout() ), SLOT( forwardTimerTimeout() ) ); 440 connect( forwardTimer, SIGNAL( timeout() ), SLOT( forwardTimerTimeout() ) );
441 441
442 deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); 442 deleteSoundButton = new QPushButton( tab, "deleteSoundButton" );
443 layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); 443 layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8);
444 deleteSoundButton->setText( tr( "Delete" ) ); 444 deleteSoundButton->setText( tr( "Delete" ) );
445 445
446 ListView1 = new QListView( tab, "IconView1" ); 446 ListView1 = new QListView( tab, "IconView1" );
447 layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); 447 layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8);
448 448
449 ListView1->addColumn( tr( "Name" ) ); 449 ListView1->addColumn( tr( "Name" ) );
450 ListView1->setColumnWidth(0,140); 450 ListView1->setColumnWidth(0,140);
451 ListView1->setSorting( 1, false); 451 ListView1->setSorting( 1, false);
452 ListView1->addColumn( tr( "Time" ) ); //in seconds 452 ListView1->addColumn( tr( "Time" ) ); //in seconds
453 ListView1->setColumnWidth(1,50); 453 ListView1->setColumnWidth(1,50);
454 ListView1->addColumn( tr("Location") ); 454 ListView1->addColumn( tr("Location") );
455 ListView1->setColumnWidth(2,50); 455 ListView1->setColumnWidth(2,50);
456 ListView1->addColumn( tr("Date") ); 456 ListView1->addColumn( tr("Date") );
457 ListView1->setColumnWidth(3,63); 457 ListView1->setColumnWidth(3,63);
458 458
459 ListView1->setColumnWidthMode(0,QListView::Manual); 459 ListView1->setColumnWidthMode(0,QListView::Manual);
460 ListView1->setColumnAlignment(1,QListView::AlignCenter); 460 ListView1->setColumnAlignment(1,QListView::AlignCenter);
461 ListView1->setColumnAlignment(2,QListView::AlignRight); 461 ListView1->setColumnAlignment(2,QListView::AlignRight);
462 ListView1->setColumnAlignment(3,QListView::AlignLeft); 462 ListView1->setColumnAlignment(3,QListView::AlignLeft);
463 ListView1->setAllColumnsShowFocus( true ); 463 ListView1->setAllColumnsShowFocus( true );
464 QPEApplication::setStylusOperation( ListView1->viewport(),QPEApplication::RightOnHold); 464 QPEApplication::setStylusOperation( ListView1->viewport(),QPEApplication::RightOnHold);
465 465
466 TabWidget->insertTab( tab, tr( "Files" ) ); 466 TabWidget->insertTab( tab, tr( "Files" ) );
467 467
468 ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** 468 ///**********<<<<<<<<<<<<>>>>>>>>>>>>***************
469 tab_3 = new QWidget( TabWidget, "tab_3" ); 469 tab_3 = new QWidget( TabWidget, "tab_3" );
470 //////////////////////////////////// 470 ////////////////////////////////////
471 471
472 Layout19 = new QHBoxLayout( tab_3); 472 Layout19 = new QHBoxLayout( tab_3);
473 Layout19->setSpacing( 2 ); 473 Layout19->setSpacing( 2 );
474 Layout19->setMargin( 0 ); 474 Layout19->setMargin( 0 );
475 475
476 Layout18 = new QVBoxLayout(this); 476 Layout18 = new QVBoxLayout(this);
477 Layout18->setSpacing( 2 ); 477 Layout18->setSpacing( 2 );
478 Layout18->setMargin( 0 ); 478 Layout18->setMargin( 0 );
479 479
480 Layout17 = new QHBoxLayout(this); 480 Layout17 = new QHBoxLayout(this);
481 Layout17->setSpacing( 2 ); 481 Layout17->setSpacing( 2 );
482 Layout17->setMargin( 0 ); 482 Layout17->setMargin( 0 );
483 483
484 sampleGroup = new QGroupBox( tab_3, "samplegroup" ); 484 sampleGroup = new QGroupBox( tab_3, "samplegroup" );
485 sampleGroup->setTitle( tr( "Sample Rate" ) ); 485 sampleGroup->setTitle( tr( "Sample Rate" ) );
486 sampleGroup->setFixedSize( 95,50); 486 sampleGroup->setFixedSize( 95,50);
487 487
488 sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); 488 sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" );
diff --git a/noncore/multimedia/opierec/waveform.cpp b/noncore/multimedia/opierec/waveform.cpp
new file mode 100644
index 0000000..05be373
--- a/dev/null
+++ b/noncore/multimedia/opierec/waveform.cpp
@@ -0,0 +1,160 @@
1/**********************************************************************
2 ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3 **
4 ** This file is part of the Qtopia Environment.
5 **
6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you.
18 **
19 **********************************************************************/
20#include "waveform.h"
21
22#include <qlabel.h>
23#include <qpainter.h>
24
25
26Waveform::Waveform( QWidget *parent, const char *name, WFlags fl )
27 : QWidget( parent, name, fl )
28{
29 pixmap = 0;
30 windowSize = 100;
31 samplesPerPixel = 8000 / (5 * windowSize);
32 currentValue = 0;
33 numSamples = 0;
34 windowPosn = 0;
35 window = 0;
36}
37
38
39void Waveform::changeSettings( int frequency, int channels )
40{
41 makePixmap();
42// qWarning("change waveform %d, %d", frequency, channels);
43 samplesPerPixel = frequency * channels / (5 * windowSize);
44 qWarning("Waveform::changeSettings %d", samplesPerPixel);
45 if ( !samplesPerPixel )
46 samplesPerPixel = 1;
47 currentValue = 0;
48 numSamples = 0;
49 windowPosn = 0;
50 draw();
51}
52
53
54Waveform::~Waveform()
55{
56 if ( window )
57 delete[] window;
58 if ( pixmap )
59 delete pixmap;
60}
61
62
63void Waveform::reset()
64{
65 makePixmap();
66 currentValue = 0;
67 numSamples = 0;
68 windowPosn = 0;
69 draw();
70}
71
72
73void Waveform::newSamples( const short *buf, int len )
74{
75 // Cache the object values in local variables.
76 int samplesPerPixel = this->samplesPerPixel;
77 int currentValue = this->currentValue;
78 int numSamples = this->numSamples;
79 short *window = this->window;
80 int windowPosn = this->windowPosn;
81 int windowSize = this->windowSize;
82
83 // Average the incoming samples to scale them to the window.
84 while ( len > 0 ) {
85 currentValue += *buf++;
86 --len;
87 if ( ++numSamples >= samplesPerPixel ) {
88 window[windowPosn++] = (short)(currentValue / numSamples);
89 if ( windowPosn >= windowSize ) {
90 this->windowPosn = windowPosn;
91 draw();
92 windowPosn = 0;
93 }
94 numSamples = 0;
95 currentValue = 0;
96 }
97 }
98
99 // Copy the final state back to the object.
100//qWarning("%d, %d, %d", currentValue, numSamples, windowPosn);
101 this->currentValue = currentValue;
102 this->numSamples = numSamples;
103 this->windowPosn = windowPosn;
104}
105
106
107void Waveform::makePixmap()
108{
109 if ( !pixmap ) {
110 pixmap = new QPixmap( size() );
111 windowSize = pixmap->width();
112 window = new short [windowSize];
113 }
114}
115
116
117void Waveform::draw()
118{
119 pixmap->fill( Qt::black );
120 QPainter painter;
121 painter.begin( pixmap );
122 painter.setPen( Qt::green );
123
124 int middle = pixmap->height() / 2;
125 int mag;
126 short *window = this->window;
127 int posn;
128 int size = windowPosn;
129 for( posn = 0; posn < size; ++posn )
130 {
131 mag = (window[posn] * middle / 32768);
132 painter.drawLine(posn, middle - mag, posn, middle + mag);
133 }
134 if ( windowPosn < windowSize )
135 {
136 painter.drawLine(windowPosn, middle, windowSize, middle);
137 }
138
139 painter.end();
140
141 paintEvent( 0 );
142}
143
144
145void Waveform::paintEvent( QPaintEvent * )
146{
147 QPainter painter;
148 painter.begin( this );
149
150 if ( pixmap ) {
151 painter.drawPixmap( 0, 0, *pixmap );
152 } else {
153 painter.setPen( Qt::green );
154 QSize sz = size();
155 painter.drawLine(0, sz.height() / 2, sz.width(), sz.height() / 2);
156 }
157
158 painter.end();
159}
160
diff --git a/noncore/multimedia/opierec/waveform.h b/noncore/multimedia/opierec/waveform.h
new file mode 100644
index 0000000..b9a4c70
--- a/dev/null
+++ b/noncore/multimedia/opierec/waveform.h
@@ -0,0 +1,63 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef WAVEFORM_H
21#define WAVEFORM_H
22
23#include <qwidget.h>
24#include <qpixmap.h>
25
26
27class QLabel;
28
29
30class Waveform : public QWidget
31{
32public:
33 Waveform( QWidget *parent=0, const char *name=0, WFlags fl=0 );
34 ~Waveform();
35
36public:
37 void changeSettings( int frequency, int channels );
38 void reset();
39 void newSamples( const short *buf, int len );
40
41private:
42
43 void makePixmap();
44 void draw();
45
46protected:
47
48 void paintEvent( QPaintEvent *event );
49
50private:
51 int samplesPerPixel;
52 int currentValue;
53 int numSamples;
54 short *window;
55 int windowPosn;
56 int windowSize;
57 QPixmap *pixmap;
58
59};
60
61
62#endif
63