summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opierec/device.cpp51
-rw-r--r--noncore/multimedia/opierec/device.h3
-rw-r--r--noncore/multimedia/opierec/main.cpp3
-rw-r--r--noncore/multimedia/opierec/opierec.control2
-rw-r--r--noncore/multimedia/opierec/opierec.pro23
-rw-r--r--noncore/multimedia/opierec/qtrec.cpp983
-rw-r--r--noncore/multimedia/opierec/qtrec.h11
-rw-r--r--noncore/multimedia/opierec/wavFile.cpp13
-rw-r--r--noncore/multimedia/opierec/wavFile.h1
9 files changed, 540 insertions, 550 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp
index 11071d8..ce49e96 100644
--- a/noncore/multimedia/opierec/device.cpp
+++ b/noncore/multimedia/opierec/device.cpp
@@ -4,7 +4,7 @@
4 4
5#include <qpe/config.h> 5#include <qpe/config.h>
6#include <qpe/qcopenvelope_qws.h> 6#include <qpe/qcopenvelope_qws.h>
7#include <qpe/custom.h> 7
8 8
9#include <fcntl.h> 9#include <fcntl.h>
10#include <stdio.h> 10#include <stdio.h>
@@ -38,7 +38,9 @@ Device::Device( QObject * parent, const char * dsp, const char * mixr, bool reco
38 qDebug("setting up DSP for recording"); 38 qDebug("setting up DSP for recording");
39 flags = O_RDWR; 39 flags = O_RDWR;
40// flags = O_RDONLY; 40// flags = O_RDONLY;
41 selectMicInput(); 41
42// selectMicInput();
43
42 } 44 }
43} 45}
44 46
@@ -94,6 +96,7 @@ void Device::changedOutVolume(int vol) {
94 cfg.setGroup("Volume"); 96 cfg.setGroup("Volume");
95 cfg.writeEntry("VolumePercent", QString::number( vol )); 97 cfg.writeEntry("VolumePercent", QString::number( vol ));
96 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; 98 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false;
99 qWarning("changing output vol %d", vol);
97 } 100 }
98 ::close(fd); 101 ::close(fd);
99} 102}
@@ -108,12 +111,13 @@ void Device::changedInVolume(int vol ) {
108 cfg.setGroup("Volume"); 111 cfg.setGroup("Volume");
109 cfg.writeEntry("Mic", QString::number(vol )); 112 cfg.writeEntry("Mic", QString::number(vol ));
110 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; 113 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
114 qWarning("changing input volume %d", vol);
111 } 115 }
112 ::close(fd); 116 ::close(fd);
113} 117}
114 118
115bool Device::selectMicInput() { 119bool Device::selectMicInput() {
116/* 120
117 int md=0; 121 int md=0;
118 int info=MIXER_WRITE(SOUND_MIXER_MIC); 122 int info=MIXER_WRITE(SOUND_MIXER_MIC);
119 md = ::open( "/dev/mixer", O_RDWR ); 123 md = ::open( "/dev/mixer", O_RDWR );
@@ -126,7 +130,7 @@ bool Device::selectMicInput() {
126 return false; 130 return false;
127 } 131 }
128 ::close(md); 132 ::close(md);
129*/ 133
130 return true; 134 return true;
131} 135}
132 136
@@ -145,18 +149,22 @@ exit(1);
145 break; 149 break;
146 case 0: { 150 case 0: {
147 */ 151 */
152qDebug("Opening %s",dspstr);
148 if (( sd = ::open( dspstr, flags)) == -1) { 153 if (( sd = ::open( dspstr, flags)) == -1) {
149 perror("open(\"/dev/dsp\")"); 154 perror("open(\"/dev/dsp\")");
150 QString errorMsg="Could not open audio device\n /dev/dsp\n" 155 QString errorMsg="Could not open audio device\n /dev/dsp\n"
151 +(QString)strerror(errno); 156 +(QString)strerror(errno);
152 qDebug(errorMsg); 157 qDebug("XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg);
153 return -1; 158 return -1;
154 } 159 }
155 160
161qDebug("Opening mixer");
156 int mixerHandle=0; 162 int mixerHandle=0;
157 /* Set the input dsp device and its input gain the weird Zaurus way */ 163 if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) {
158 if (( mixerHandle = open("/dev/mixer1",O_RDWR))<0) { 164 perror("open(\"/dev/mixer\")");
159 perror("open(\"/dev/mixer1\")"); 165 QString errorMsg="Could not open audio device\n /dev/dsp\n"
166 +(QString)strerror(errno);
167 qDebug("XXXXXXXXXXXXXXXXXXXXXX "+errorMsg);
160 } 168 }
161 169
162 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ 170 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
@@ -203,12 +211,12 @@ exit(1);
203// f2.close(); 211// f2.close();
204// } 212// }
205::close(mixerHandle ); 213::close(mixerHandle );
206 qDebug("open device %s", dspstr); 214// qDebug("open device %s", dspstr);
207 qDebug("success! %d",sd); 215// qDebug("success! %d",sd);
208 return sd; 216 return sd;
209} 217}
210 218
211bool Device::closeDevice( bool b) { 219bool Device::closeDevice( bool) {
212// if(b) {//close now 220// if(b) {//close now
213// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { 221// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
214// perror("ioctl(\"SNDCTL_DSP_RESET\")"); 222// perror("ioctl(\"SNDCTL_DSP_RESET\")");
@@ -222,7 +230,7 @@ bool Device::closeDevice( bool b) {
222 ::close( sd); //close sound device 230 ::close( sd); //close sound device
223// sdfd=0; 231// sdfd=0;
224 // sd=0; 232 // sd=0;
225 qDebug("closed dsp"); 233// qDebug("closed dsp");
226 return true; 234 return true;
227} 235}
228 236
@@ -290,7 +298,7 @@ int Device::getDeviceRate() {
290 298
291int Device::getDeviceBits() { 299int Device::getDeviceBits() {
292 int dBits=0; 300 int dBits=0;
293#if !defined(OPIE_NO_SOUND_PCM_READ_BITS) // zaurus doesnt have this 301#ifndef QT_QWS_EBX // zaurus doesnt have this
294 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { 302 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) {
295 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); 303 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")");
296 } 304 }
@@ -311,8 +319,9 @@ int Device::getDeviceFragSize() {
311 319
312 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { 320 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) {
313 qDebug("no fragsize"); 321 qDebug("no fragsize");
314 } else 322 } else {
315 qDebug("driver says frag size is %d", frag_size); 323 qDebug("driver says frag size is %d", frag_size);
324 }
316 return frag_size; 325 return frag_size;
317} 326}
318 327
@@ -333,3 +342,17 @@ bool Device::reset() {
333 } 342 }
334 return true; 343 return true;
335} 344}
345
346int Device::devRead(int soundDescriptor, short *buf, int size) {
347 int number = 0;
348 number = ::read( soundDescriptor, (char *)buf, size);
349 return number;
350}
351
352int Device::devWrite(int soundDescriptor, short * buf, int size) {
353 int bytesWritten = 0;
354 bytesWritten = ::write( soundDescriptor, buf, size);
355 return bytesWritten;
356}
357
358
diff --git a/noncore/multimedia/opierec/device.h b/noncore/multimedia/opierec/device.h
index f92be98..8152e85 100644
--- a/noncore/multimedia/opierec/device.h
+++ b/noncore/multimedia/opierec/device.h
@@ -31,6 +31,9 @@ public:
31 bool setDeviceFormat(int); 31 bool setDeviceFormat(int);
32bool reset(); 32bool reset();
33 33
34 int devRead(int, short *, int);
35 int devWrite(int, short *, int);
36
34private: 37private:
35 int devRes, devCh, devRate, devForm, flags; 38 int devRes, devCh, devRate, devForm, flags;
36 char *dspstr, *mixstr; 39 char *dspstr, *mixstr;
diff --git a/noncore/multimedia/opierec/main.cpp b/noncore/multimedia/opierec/main.cpp
index 4a94800..e36d050 100644
--- a/noncore/multimedia/opierec/main.cpp
+++ b/noncore/multimedia/opierec/main.cpp
@@ -14,3 +14,6 @@
14#include <opie/oapplicationfactory.h> 14#include <opie/oapplicationfactory.h>
15 15
16OPIE_EXPORT_APP( OApplicationFactory<QtRec> ) 16OPIE_EXPORT_APP( OApplicationFactory<QtRec> )
17
18
19
diff --git a/noncore/multimedia/opierec/opierec.control b/noncore/multimedia/opierec/opierec.control
index cb97933..b01406e 100644
--- a/noncore/multimedia/opierec/opierec.control
+++ b/noncore/multimedia/opierec/opierec.control
@@ -1,5 +1,5 @@
1Package: opierec 1Package: opierec
2Files: plugins/application/libopierec.so* bin/opierec pics/opierec apps/Applications/opierec.desktop 2Files: bin/opierec pics/opierec apps/Applications/opierec.desktop
3Priority: optional 3Priority: optional
4Section: multimedia/applications 4Section: multimedia/applications
5Maintainer: L.J. Potter <ljp@llornkcor.com> 5Maintainer: L.J. Potter <ljp@llornkcor.com>
diff --git a/noncore/multimedia/opierec/opierec.pro b/noncore/multimedia/opierec/opierec.pro
index 7dbc4f7..b607c09 100644
--- a/noncore/multimedia/opierec/opierec.pro
+++ b/noncore/multimedia/opierec/opierec.pro
@@ -1,11 +1,26 @@
1CONFIG = qt warn_on debug 1CONFIG = qt warn_on release
2#CONFIG = qt warn_on release quick-app 2#CONFIG = qt warn_on release quick-app
3HEADERS = adpcm.h pixmaps.h qtrec.h device.h wavFile.h 3HEADERS = adpcm.h \
4SOURCES = adpcm.c main.cpp qtrec.cpp device.cpp wavFile.cpp 4 pixmaps.h \
5 helpwindow.h \
6 qtrec.h \
7 device.h \
8 wavFile.h \
9 waveform.h
10SOURCES = adpcm.c \
11 helpwindow.cpp \
12 main.cpp \
13 qtrec.cpp \
14 device.cpp \
15 wavFile.cpp \
16 waveform.cpp
5INCLUDEPATH += $(OPIEDIR)/include 17INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include 18DEPENDPATH += $(OPIEDIR)/include
19#LIBS += -L/opt/buildroot-opie/output/staging/target/lib -lqpe -lpthread -ljpeg -lpng -lz
7LIBS += -lqpe -lpthread 20LIBS += -lqpe -lpthread
8INTERFACES = 21INTERFACES =
9TARGET = opierec 22TARGET = opierec
10#TMAKE_CXXFLAGS += -DQT_QWS_VERCEL_IDR -DQWS -fno-exceptions -fno-rtti 23DESTDIR=$(OPIEDIR)/bin
24
11include ( $(OPIEDIR)/include.pro ) 25include ( $(OPIEDIR)/include.pro )
26
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp
index 1e36c96..aeab26d 100644
--- a/noncore/multimedia/opierec/qtrec.cpp
+++ b/noncore/multimedia/opierec/qtrec.cpp
@@ -8,6 +8,8 @@
8 8
9#include "pixmaps.h" 9#include "pixmaps.h"
10#include "qtrec.h" 10#include "qtrec.h"
11#include "waveform.h"
12#include "device.h"
11 13
12#include <pthread.h> 14#include <pthread.h>
13 15
@@ -17,10 +19,6 @@ extern "C" {
17 19
18#include <sys/soundcard.h> 20#include <sys/soundcard.h>
19 21
20// #if defined (QTOPIA_INTERNAL_FSLP)
21// #include <qpe/lnkproperties.h>
22// #endif
23
24#include <qpe/config.h> 22#include <qpe/config.h>
25#include <qpe/qcopenvelope_qws.h> 23#include <qpe/qcopenvelope_qws.h>
26#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
@@ -58,13 +56,27 @@ extern "C" {
58#include<sys/wait.h> 56#include<sys/wait.h>
59#include <sys/signal.h> 57#include <sys/signal.h>
60 58
59#if defined(QT_QWS_SL5XXX)
60///#if defined(QT_QWS_EBX)
61
62#define DSPSTROUT "/dev/dsp"
63#define DSPSTRIN "/dev/dsp1"
64#define DSPSTRMIXEROUT "/dev/mixer"
65#define DSPSTRMIXERIN "/dev/mixer1"
66
67#else
68
69#define DSPSTROUT "/dev/dsp"
70#define DSPSTRIN "/dev/dsp"
71#define DSPSTRMIXERIN "/dev/mixer"
72#define DSPSTRMIXEROUT "/dev/mixer"
73
74#endif
75
61//#define ZAURUS 0 76//#define ZAURUS 0
62struct adpcm_state encoder_state; 77struct adpcm_state encoder_state;
63struct adpcm_state decoder_state; 78struct adpcm_state decoder_state;
64 79
65long findPeak(long input );
66//char deviceRates[];
67
68typedef struct { 80typedef struct {
69 int sampleRate; 81 int sampleRate;
70 /* int fragSize; */ 82 /* int fragSize; */
@@ -85,56 +97,47 @@ typedef struct {
85 97
86fileParameters filePara; 98fileParameters filePara;
87 99
88bool monitoring, recording; 100bool monitoring, recording, playing;
89bool stopped; 101bool stopped;
90QLabel *timeLabel; 102QLabel *timeLabel;
91QSlider *timeSlider; 103QSlider *timeSlider;
92int sd; 104int sd;
93 105
94// #if defined(QT_QWS_EBX) 106Waveform* waveform;
95// #define DSPSTROUT "/dev/dsp" 107Device *soundDevice;
96// #define DSPSTRIN "/dev/dsp1"
97// #define DSPSTRMIXEROUT "/dev/mixer"
98// #define DSPSTRMIXERIN "/dev/mixer1"
99// #else
100#define DSPSTROUT "/dev/dsp"
101#define DSPSTRIN "/dev/dsp"
102#define DSPSTRMIXERIN "/dev/mixer"
103#define DSPSTRMIXEROUT "/dev/mixer"
104//#endif
105 108
106// threaded recording 109// threaded recording
107void quickRec() { 110//fuckin fulgy here
111void quickRec()
112{
108//void QtRec::quickRec() { 113//void QtRec::quickRec() {
109 114
115 qDebug("%d",
116 filePara.numberSamples/filePara.sampleRate * filePara.channels);
117 qDebug("samples %d, rate %d, channels %d",
118 filePara.numberSamples, filePara.sampleRate, filePara.channels);
119
110 int total = 0; // Total number of bytes read in so far. 120 int total = 0; // Total number of bytes read in so far.
111 int bytesWritten, number; 121 int bytesWritten, number;
112 122
113 count_info info;
114
115 bytesWritten=0; 123 bytesWritten=0;
116 number=0; 124 number=0;
117 QString num, timeString; 125 QString num;
118 int level=0; 126 int level=0;
119 int threshold=0; 127 int threshold=0;
120 // if(limit != 0)
121 // t->start( ( limit +.3) , true);
122
123 recording = true;
124 //rate=filePara.sampleRate;
125 // int bits = filePara.resolution; 128 // int bits = filePara.resolution;
126 audio_buf_info inInfo; 129// qDebug("bits %d", bits);
127 ioctl( filePara.fd, SNDCTL_DSP_GETISPACE, &inInfo);
128 // qDebug("ispace is frags %d, total %d", inInfo.fragments, inInfo.fragstotal);
129 130
130 if( filePara.resolution == 16 ) { //AFMT_S16_LE) 131 if( filePara.resolution == 16 ) { //AFMT_S16_LE)
132// qDebug("AFMT_S16_LE size %d", filePara.SecondsToRecord);
133// qDebug("samples to record %d", filePara.samplesToRecord);
134// qDebug("%d", filePara.sd);
131 level=7; 135 level=7;
132 threshold=0; 136 threshold=0;
133 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
134 timeLabel->setText( timeString+ " seconds");
135 137
136 if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { 138 if( filePara.format==WAVE_FORMAT_DVI_ADPCM) {
137 // qDebug("start recording WAVE_FORMAT_DVI_ADPCM"); 139 // qDebug("start recording WAVE_FORMAT_DVI_ADPCM");
140 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
138 char abuf[BUFSIZE/2]; 141 char abuf[BUFSIZE/2];
139 short sbuf[BUFSIZE]; 142 short sbuf[BUFSIZE];
140 short sbuf2[BUFSIZE]; 143 short sbuf2[BUFSIZE];
@@ -144,104 +147,88 @@ void quickRec() {
144 147
145 for(;;) { 148 for(;;) {
146 if (stopped) { 149 if (stopped) {
147 break; // stop if playing was set to false 150 qDebug("quickRec:: stopped");
151 break;
148 } 152 }
149 153
150 number=::read( filePara.sd, sbuf, BUFSIZE); 154// number=::read( filePara.sd, sbuf, BUFSIZE);
155 number = soundDevice ->devRead( filePara.sd, sbuf, BUFSIZE);
156
151 if(number <= 0) { 157 if(number <= 0) {
152 perror("recording error "); 158 perror("recording error ");
153 // qDebug( "%s %d", filePara.fileName, number); 159 qDebug( "%s %d", filePara.fileName, number);
154 // errorStop(); 160 stopped = true;
155 recording=stopped=false;
156// QMessageBox::message("Note", "Error recording to file\n%s",filePara.fileName);
157 return; 161 return;
158 } 162 }
159 //if(stereo == 2) { 163 //if(stereo == 2) {
160// adpcm_coder( sbuf2, abuf, number/2, &encoder_state); 164// adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
161 adpcm_coder( sbuf, abuf, number/2, &encoder_state); 165 adpcm_coder( sbuf, abuf, number/2, &encoder_state);
162 bytesWritten = ::write( filePara.fd , abuf, number/4); 166 bytesWritten = soundDevice->devWrite( filePara.fd , (short *)abuf, number/4);
163 long peak; 167 waveform->newSamples( (const short *)abuf, bytesWritten );
164 for (int i = 0; i < number; i++) 168
165 { //since Z is mono do normally
166 peak = findPeak((long)sbuf[i]);
167 printf("peak %ld\r",peak);
168 fflush(stdout);
169 }
170 //------------->>>> out to file
171 // if(filePara.channels==1)
172 // total += bytesWritten/2; //mono
173 // else
174 total += bytesWritten; 169 total += bytesWritten;
175 filePara.numberSamples = total; 170 filePara.numberSamples = total;
176// if( total >= filePara.samplesToRecord)
177// timeSlider->setValue(0);
178// else if( filePara.SecondsToRecord !=0)
179 timeSlider->setValue( total); 171 timeSlider->setValue( total);
180 172
181 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2; 173 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2 / filePara.channels;
182 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info);
183 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
184 timeLabel->setText( timeString + " seconds");
185 174
186 qApp->processEvents(); 175 qApp->processEvents();
187 if( total >= filePara.samplesToRecord) 176 if( total >= filePara.samplesToRecord) {
177 stopped = true;
188 break; 178 break;
189 } 179 }
180 }
190 } else { 181 } else {
191 // qDebug("start recording WAVE_FORMAT_PCM"); 182 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
183 qDebug("start recording WAVE_FORMAT_PCM");
192 short inbuffer[BUFSIZE], outbuffer[BUFSIZE]; 184 short inbuffer[BUFSIZE], outbuffer[BUFSIZE];
193 memset( inbuffer,0,BUFSIZE); 185 memset( inbuffer,0,BUFSIZE);
194 memset( outbuffer,0,BUFSIZE); 186 memset( outbuffer,0,BUFSIZE);
187
195 for(;;) { 188 for(;;) {
196 if (stopped) { 189 if (stopped) {
190 qDebug("quickRec:: stopped");
191 stopped = true;
197 break; // stop if playing was set to false 192 break; // stop if playing was set to false
193 return;
198 } 194 }
199 195
200 number=::read( filePara.sd, inbuffer, BUFSIZE); 196 number = soundDevice ->devRead( filePara.sd, (short *)inbuffer, BUFSIZE);
197 waveform->newSamples( inbuffer, number );
198
201 if(number <= 0) { 199 if(number <= 0) {
202 perror("recording error "); 200 perror("recording error ");
203 recording=stopped=false; 201 qDebug( filePara.fileName);
204 // errorStop(); 202 stopped = true;
205 return;// false; 203 return;
206 } 204 }
207/* for (int i=0;i< number;i++) { //2*i is left channel 205
208outbuffer[i]=inbuffer[i]>>1; // no clippy, please 206 bytesWritten = soundDevice->devWrite( filePara.fd , inbuffer, number);
209}*/ 207
210 bytesWritten = ::write( filePara.fd , inbuffer, number);
211//------------->>>> out to file
212 if(bytesWritten < 0) { 208 if(bytesWritten < 0) {
213 // errorStop();
214 perror("File writing error "); 209 perror("File writing error ");
215 return;// false; 210 stopped = true;
211 return;
216 } 212 }
217 213
218 // if(filePara.channels==1)
219 // total += bytesWritten/2; //mono
220 // else
221 total += bytesWritten; 214 total += bytesWritten;
222 long peak; 215
223 for (int i = 0; i < number; i++)
224 { //since Z is mono do normally
225 peak = findPeak((long)inbuffer[i]);
226 printf("peak %ld\r",peak);
227 fflush(stdout);
228 }
229 filePara.numberSamples = total; 216 filePara.numberSamples = total;
217
230 if(filePara.SecondsToRecord !=0) 218 if(filePara.SecondsToRecord !=0)
231 timeSlider->setValue( total); 219 timeSlider->setValue( total);
232// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total); 220// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total);
233// fflush(stdout); 221// fflush(stdout);
234 222
235 ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info); 223 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2/filePara.channels;
236// qDebug("%d, %d", info.bytes, ( info.bytes / filePara.sampleRate) / 2);
237 224
238 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
239 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
240 timeLabel->setText( timeString + " seconds");
241 qApp->processEvents(); 225 qApp->processEvents();
242 if( total >= filePara.samplesToRecord) 226
227 if( total >= filePara.samplesToRecord) {
228 stopped = true;
243 break; 229 break;
244 } 230 }
231 }
245 } //end main loop 232 } //end main loop
246 233
247 } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; 234 } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8;
@@ -251,36 +238,20 @@ outbuffer[i]=inbuffer[i]>>1; // no clippy, please
251 238
252 for(;;) { 239 for(;;) {
253 if (stopped) { 240 if (stopped) {
254 // qDebug("quickRec:: stopped"); 241 qDebug("quickRec:: stopped");
255 break; // stop if playing was set to false 242 break; // stop if playing was set to false
256 } 243 }
257 number=::read( filePara.sd, unsigned_inbuffer, BUFSIZE);
258//-------------<<<< in from device
259// val = (data ^ 0x80) << 8;
260
261//unsigned_outbuffer = (unsigned_inbuffer ^ 0x80) << 8;
262
263// if(number <= 0) {
264// perror("recording error ");
265// qDebug(filePara.fileName);
266// // errorStop();
267// QMessageBox::message("Note","error recording");
268// return;// false;
269// }
270// for (int i=0;i< number;i++) { //2*i is left channel
271// unsigned_outbuffer[i]=unsigned_inbuffer[i]>>1; // no clippy, please
272// }
273 244
245 number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE);
274 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); 246 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
275 247
276//------------->>>> out to file
277 if(bytesWritten < 0) { 248 if(bytesWritten < 0) {
278 recording=stopped=false; 249 stopped = true;
279 // errorStop();
280 QMessageBox::message("Note","There was a problem\nwriting to the file"); 250 QMessageBox::message("Note","There was a problem\nwriting to the file");
281 perror("File writing error "); 251 perror("File writing error ");
282 return;// false; 252 return;
283 } 253 }
254
284 total += bytesWritten; 255 total += bytesWritten;
285 filePara.numberSamples = total; 256 filePara.numberSamples = total;
286 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); 257 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total);
@@ -290,29 +261,151 @@ outbuffer[i]=inbuffer[i]>>1; // no clippy, please
290 261
291 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; 262 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
292 263
293 timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
294 timeLabel->setText( timeString + " seconds");
295
296 qApp->processEvents(); 264 qApp->processEvents();
297 if( total >= filePara.samplesToRecord) 265 if( total >= filePara.samplesToRecord) {
266 stopped = true;
298 break; 267 break;
268 }
299 } //end main loop 269 } //end main loop
300 } 270 }
301// qDebug("Final %d, %d", filePara.samplesToRecord , filePara.numberOfRecordedSeconds);
302} /// END quickRec() 271} /// END quickRec()
303 272
304// threaded play
305void playIt() {
306 273
274void playIt()
275{
276 int bytesWritten, number;
277 int total = 0; // Total number of bytes read in so far.
278 if( filePara.resolution == 16 ) { //AFMT_S16_LE) {
279 if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
280 char abuf[ BUFSIZE / 2 ];
281 short sbuf[ BUFSIZE ];
282 short sbuf2[ BUFSIZE * 2 ];
283 memset( abuf, 0, BUFSIZE / 2);
284 memset( sbuf, 0, BUFSIZE);
285 memset( sbuf2, 0, BUFSIZE * 2);
286// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
287 for(;;) { // play loop
288 if ( stopped) {
289 break;
290 return;
291 }// stop if playing was set to false
292
293 number = ::read( filePara.fd, abuf, BUFSIZE / 2);
294 adpcm_decoder( abuf, sbuf, number * 2, &decoder_state);
295
296// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
297// sbuf2[i+1]=sbuf2[i]=sbuf[i];
298// }
299 bytesWritten = write ( filePara.sd, sbuf, number * 4);
300 waveform->newSamples( (const short *)sbuf, number );
301 // if(filePara.channels==1)
302 // total += bytesWritten/2; //mono
303 // else
304 total += bytesWritten;
305 filePara.numberSamples = total/4;
306 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2;
307
308 timeSlider->setValue( total/4);
309// timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
310// if(filePara.numberOfRecordedSeconds>1)
311// timeLabel->setText( timeString+ tr(" seconds"));
312 printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4);
313 fflush(stdout);
314
315 qApp->processEvents();
316
317 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
318// if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) {
319 stopped = true;
320 break;
321 }
322 }
323 } else {
324 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
325 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
326 memset( inbuffer, 0, BUFSIZE);
327 memset( outbuffer, 0, BUFSIZE);
328
329 for(;;) { // play loop
330 if ( stopped) {
331 break;
332 return;
333 }
334// stop if playing was set to false
335 number = ::read( filePara.fd, inbuffer, BUFSIZE);
336// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
337// // for (int i=0;i< number ; i++) { //2*i is left channel
338// outbuffer[i+1]= outbuffer[i]=inbuffer[i];
339// }
340 bytesWritten = ::write( filePara.sd, inbuffer, number);
341 waveform->newSamples( inbuffer, bytesWritten );
342 //-------------->>>> out to device
343 // total+=bytesWritten;
344 // if(filePara.channels==1)
345 // total += bytesWritten/2; //mono
346 // else
347 total += bytesWritten;
348 timeSlider->setValue( total);
349
350 filePara.numberSamples = total;
351 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
352
353// timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
354// timeLabel->setText( timeString + tr(" seconds"));
355
356 qApp->processEvents();
357
358 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
359 qWarning("Jane! Stop this crazy thing!");
360 stopped = true;
361// playing = false;
362 break;
363 }
364 }
365 printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total);
366 fflush(stdout);
367 } //end loop
368 } else {
369/////////////////////////////// format = AFMT_U8;
370 unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE];
371 memset( unsigned_inbuffer, 0, BUFSIZE);
372 for(;;) {
373// main loop
374 if (stopped) {
375 break; // stop if playing was set to false
376 return;
377 }
378 number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE);
379//data = (val >> 8) ^ 0x80;
380 // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80;
381 bytesWritten = write ( filePara.sd, unsigned_inbuffer, number);
382 waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten );
383 total += bytesWritten;
384
385 timeSlider->setValue( total);
386 filePara.numberSamples = total;
387
388 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
389// timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
390// timeLabel->setText( timeString + tr(" seconds"));
391 qApp->processEvents();
392
393 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
394// if( total >= filePara.numberSamples ) {
395 stopped = true;
396 break;
397 }
398 printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples);
399 fflush(stdout);
400 }
401 }
307} 402}
308 403
309/////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> 404/////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>
310QtRec::QtRec( QWidget* parent, const char* name, WFlags fl )
311 : QWidget( parent, name, fl ) {
312 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device
313 // autoMute=TRUE;
314// QPEApplication::grabKeyboard();
315 405
406QtRec::QtRec( QWidget* parent, const char* name, WFlags fl )
407 : QWidget( parent, name, fl )
408{
316 if ( !name ) 409 if ( !name )
317 setName( "OpieRec" ); 410 setName( "OpieRec" );
318 init(); 411 init();
@@ -363,8 +456,6 @@ void QtRec::cleanUp() {
363 456
364 if(wavFile) delete wavFile; 457 if(wavFile) delete wavFile;
365// if(soundDevice) delete soundDevice; 458// if(soundDevice) delete soundDevice;
366// QPEApplication::grabKeyboard();
367// QPEApplication::ungrabKeyboard();
368} 459}
369 460
370void QtRec::init() { 461void QtRec::init() {
@@ -392,9 +483,7 @@ void QtRec::init() {
392 layout1->setMargin( 2); 483 layout1->setMargin( 2);
393 484
394 timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); 485 timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" );
395 // timeSlider->setFixedWidth(150);
396 layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); 486 layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3);
397// timeSlider->setTickmarks(QSlider::Above);
398 487
399 timeLabel = new QLabel( tab, "TimeLabel" ); 488 timeLabel = new QLabel( tab, "TimeLabel" );
400 layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); 489 layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3);
@@ -434,10 +523,12 @@ void QtRec::init() {
434 connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 523 connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) );
435 524
436 rewindTimer = new QTimer( this ); 525 rewindTimer = new QTimer( this );
437 connect( rewindTimer, SIGNAL( timeout() ), SLOT( rewindTimerTimeout() ) ); 526 connect( rewindTimer, SIGNAL( timeout() ),
527 this, SLOT( rewindTimerTimeout() ) );
438 528
439 forwardTimer = new QTimer( this ); 529 forwardTimer = new QTimer( this );
440 connect( forwardTimer, SIGNAL( timeout() ), SLOT( forwardTimerTimeout() ) ); 530 connect( forwardTimer, SIGNAL( timeout() ),
531 this, SLOT( forwardTimerTimeout() ) );
441 532
442 deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); 533 deleteSoundButton = new QPushButton( tab, "deleteSoundButton" );
443 layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); 534 layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8);
@@ -467,20 +558,10 @@ void QtRec::init() {
467 558
468 ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** 559 ///**********<<<<<<<<<<<<>>>>>>>>>>>>***************
469 tab_3 = new QWidget( TabWidget, "tab_3" ); 560 tab_3 = new QWidget( TabWidget, "tab_3" );
561 QGridLayout *glayout3 = new QGridLayout( tab_3 );
562 glayout3->setSpacing( 2);
563 glayout3->setMargin( 2);
470 //////////////////////////////////// 564 ////////////////////////////////////
471
472 Layout19 = new QHBoxLayout( tab_3);
473 Layout19->setSpacing( 2 );
474 Layout19->setMargin( 0 );
475
476 Layout18 = new QVBoxLayout(this);
477 Layout18->setSpacing( 2 );
478 Layout18->setMargin( 0 );
479
480 Layout17 = new QHBoxLayout(this);
481 Layout17->setSpacing( 2 );
482 Layout17->setMargin( 0 );
483
484 sampleGroup = new QGroupBox( tab_3, "samplegroup" ); 565 sampleGroup = new QGroupBox( tab_3, "samplegroup" );
485 sampleGroup->setTitle( tr( "Sample Rate" ) ); 566 sampleGroup->setTitle( tr( "Sample Rate" ) );
486 sampleGroup->setFixedSize( 95,50); 567 sampleGroup->setFixedSize( 95,50);
@@ -498,7 +579,7 @@ void QtRec::init() {
498 sampleRateComboBox->insertItem( tr( "8000")); 579 sampleRateComboBox->insertItem( tr( "8000"));
499 //#endif 580 //#endif
500 581
501 Layout17->addWidget( sampleGroup ); 582 glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0);
502 583
503 sizeGroup= new QGroupBox( tab_3, "sizeGroup" ); 584 sizeGroup= new QGroupBox( tab_3, "sizeGroup" );
504 sizeGroup->setTitle( tr( "Limit Size" ) ); 585 sizeGroup->setTitle( tr( "Limit Size" ) );
@@ -507,24 +588,13 @@ void QtRec::init() {
507 sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" ); 588 sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" );
508 sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) ); 589 sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) );
509 sizeLimitCombo->insertItem(tr("Unlimited")); 590 sizeLimitCombo->insertItem(tr("Unlimited"));
591
510 for(int i=1;i<13; i++) { 592 for(int i=1;i<13; i++) {
511 sizeLimitCombo->insertItem( QString::number(i*5)); 593 sizeLimitCombo->insertItem( QString::number(i*5));
512 } 594 }
513 595
514// sizeLimitCombo->insertItem(tr("5 secs"));
515// sizeLimitCombo->insertItem(tr("10 secs"));
516// sizeLimitCombo->insertItem(tr("15 secs"));
517// sizeLimitCombo->insertItem(tr("20 secs"));
518
519 // Layout18->addWidget( sizeGroup );
520 Layout17->addWidget( sizeGroup );
521
522 Layout18->addLayout( Layout17 );
523
524 Layout16 = new QHBoxLayout(this);
525 Layout16->setSpacing( 2 );
526 Layout16->setMargin( 0 );
527 596
597 glayout3->addMultiCellWidget( sizeGroup, 0, 0, 1, 1);
528 dirGroup = new QGroupBox( tab_3, "dirGroup" ); 598 dirGroup = new QGroupBox( tab_3, "dirGroup" );
529 dirGroup->setTitle( tr( "File Directory" ) ); 599 dirGroup->setTitle( tr( "File Directory" ) );
530 dirGroup->setFixedSize(130,50); 600 dirGroup->setFixedSize(130,50);
@@ -532,7 +602,7 @@ void QtRec::init() {
532 directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" ); 602 directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" );
533 directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) ); 603 directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) );
534 604
535 Layout18->addWidget( dirGroup ); 605 glayout3->addMultiCellWidget( dirGroup, 1, 1, 0, 0);
536 606
537 bitGroup = new QGroupBox( tab_3, "bitGroup" ); 607 bitGroup = new QGroupBox( tab_3, "bitGroup" );
538 bitGroup->setTitle( tr( "Bit Depth" ) ); 608 bitGroup->setTitle( tr( "Bit Depth" ) );
@@ -543,22 +613,21 @@ void QtRec::init() {
543 bitRateComboBox->insertItem( tr( "8" ) ); 613 bitRateComboBox->insertItem( tr( "8" ) );
544 bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); 614 bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) );
545 615
546 Layout18->addWidget( bitGroup ); 616 glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1);
547 617
548 compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 ); 618 compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 );
549 Layout18->addWidget( compressionCheckBox );
550 619
551 autoMuteCheckBox= new QCheckBox ( tr("auto Mute"), tab_3 ); 620 autoMuteCheckBox = new QCheckBox ( tr("Auto Mute"), tab_3 );
552 Layout18->addWidget( autoMuteCheckBox ); 621 stereoCheckBox = new QCheckBox ( tr("Stereo Channels"), tab_3 );
553 622
554 Layout19->addLayout( Layout18 ); 623 glayout3->addMultiCellWidget( compressionCheckBox, 2, 2, 0, 3);
624 glayout3->addMultiCellWidget( autoMuteCheckBox, 3, 3, 0, 0);
625 glayout3->addMultiCellWidget( stereoCheckBox, 3, 3, 1, 1);
555 626
556 QWidget *d = QApplication::desktop(); 627 QWidget *d = QApplication::desktop();
557 int width=d->width(); 628 int width=d->width();
558 int height=d->height(); 629 int height=d->height();
559 630
560
561
562 if( width < height) { 631 if( width < height) {
563 632
564 tab_5 = new QWidget( TabWidget, "tab_5" ); 633 tab_5 = new QWidget( TabWidget, "tab_5" );
@@ -568,7 +637,6 @@ void QtRec::init() {
568 Layout19a->setSpacing( 2 ); 637 Layout19a->setSpacing( 2 );
569 Layout19a->setMargin( 0 ); 638 Layout19a->setMargin( 0 );
570 639
571
572 Layout15 = new QVBoxLayout(this); 640 Layout15 = new QVBoxLayout(this);
573 Layout15->setSpacing( 2 ); 641 Layout15->setSpacing( 2 );
574 Layout15->setMargin( 0 ); 642 Layout15->setMargin( 0 );
@@ -634,11 +702,11 @@ void QtRec::init() {
634 Layout15b->addWidget( TextLabel3 ); 702 Layout15b->addWidget( TextLabel3 );
635 703
636 InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_3, (const char *) "InputSlider" ); 704 InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_3, (const char *) "InputSlider" );
637 // InputSlider->setTickmarks(QSlider::Both); 705 InputSlider->setTickmarks(QSlider::Both);
638 Layout15->addWidget( InputSlider); 706 Layout15->addWidget( InputSlider);
639 707
640 OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_3,(const char *) "OutputSlider" ); 708 OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_3,(const char *) "OutputSlider" );
641 // OutputSlider->setTickmarks(QSlider::Both); 709 OutputSlider->setTickmarks(QSlider::Both);
642 710
643 Layout15b->addWidget( OutputSlider ); 711 Layout15b->addWidget( OutputSlider );
644 712
@@ -659,35 +727,12 @@ void QtRec::init() {
659 727
660 } 728 }
661 729
730 waveform = new Waveform( this, "waveform" );
731// waveform->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)3, waveform->sizePolicy().hasHeightForWidth() ) );
732 waveform->setMinimumSize( QSize( 0, 50 ) );
662 733
663 ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** 734 layout->addMultiCellWidget( waveform, 8, 8, 0, 7 );
664 735 waveform->setBackgroundColor ( black );
665// tab_4 = new QWidget( TabWidget, "tab_4" );
666// QGridLayout *layout4 = new QGridLayout( tab_4);
667// layout4->setSpacing( 2);
668// layout4->setMargin( 2);
669// TabWidget->insertTab( tab_4, tr( "Help"));
670
671// ///////////////////////////////////////////// FIXME change to a real helpfile path
672// QString url="/index.html";
673// HelpWindow *help = new HelpWindow( url, ".", tab_4, "opierec_help");
674// layout4->addMultiCellWidget( help, 0, 1, 0, 1);
675// if( !QFile(url).exists()) {
676// help->hide();
677// //help->showMaximized();
678// QLabel *helpLabel;
679// helpLabel = new QLabel( tab_4, "TimeLabel" );
680// layout4->addMultiCellWidget( helpLabel, 0, 3, 0, 4 );
681// helpLabel->setText( "<B>OpieRec</B><br>"
682// "Records files in standard wav format<br>"
683// "or a compressed version<br>"
684// "For help, please email the author<br>"
685// "<B>OpieRec</B> is copyright&copy; 2002 by"
686// " L.J. Potter<br>llornkcor@handhelds.org<BR>"
687// "and is licensed under the <B>QPL</B>");
688// }
689 ///**********<<<<<<<<<<<<>>>>>>>>>>>>***************
690
691} 736}
692 737
693void QtRec::initIconView() { 738void QtRec::initIconView() {
@@ -698,8 +743,9 @@ void QtRec::initIconView() {
698 QString temp; 743 QString temp;
699 QPixmap image0( ( const char** ) image0_data ); 744 QPixmap image0( ( const char** ) image0_data );
700 745
701
702 int nFiles = cfg.readNumEntry("NumberofFiles",0); 746 int nFiles = cfg.readNumEntry("NumberofFiles",0);
747 qDebug("init number of files %d", nFiles);
748
703 for(int i=1;i<= nFiles;i++) { 749 for(int i=1;i<= nFiles;i++) {
704 750
705 QListViewItem * item; 751 QListViewItem * item;
@@ -708,7 +754,6 @@ void QtRec::initIconView() {
708 temp.sprintf("%d",i); 754 temp.sprintf("%d",i);
709 temp=cfg.readEntry(temp,""); //reads currentFile 755 temp=cfg.readEntry(temp,""); //reads currentFile
710 filePath = cfg.readEntry(temp,""); //currentFileName 756 filePath = cfg.readEntry(temp,""); //currentFileName
711 // qDebug(filePath);
712 757
713 QFileInfo info(filePath); 758 QFileInfo info(filePath);
714 fileDate = info.lastModified().toString(); 759 fileDate = info.lastModified().toString();
@@ -727,34 +772,59 @@ void QtRec::initIconView() {
727void QtRec::initConnections() { 772void QtRec::initConnections() {
728 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 773 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
729 774
730 connect( toBeginningButton, SIGNAL( pressed()), this, SLOT( rewindPressed() )); 775 connect( toBeginningButton, SIGNAL( pressed()),
731 connect( toBeginningButton, SIGNAL( released()), this, SLOT( rewindReleased() )); 776 this, SLOT( rewindPressed() ));
732 connect( toEndButton, SIGNAL( pressed()), this, SLOT( FastforwardPressed() )); 777 connect( toBeginningButton, SIGNAL( released()),
733 connect( toEndButton, SIGNAL( released()), this, SLOT( FastforwardReleased() )); 778 this, SLOT( rewindReleased() ));
734 connect( deleteSoundButton, SIGNAL(released()), this, SLOT( deleteSound() )); 779 connect( toEndButton, SIGNAL( pressed()),
735 connect( Stop_PushButton, SIGNAL(released()), this, SLOT( doPlayBtn() )); 780 this, SLOT( FastforwardPressed() ));
736 connect( Rec_PushButton, SIGNAL(released()), this, SLOT( newSound() ) ); 781 connect( toEndButton, SIGNAL( released()),
737 connect( TabWidget, SIGNAL( currentChanged( QWidget*)),this, SLOT(thisTab(QWidget*) )); 782 this, SLOT( FastforwardReleased() ));
738 connect( OutputSlider, SIGNAL(sliderReleased()), this, SLOT( changedOutVolume()) ); 783 connect( deleteSoundButton, SIGNAL(released()),
739 connect( InputSlider, SIGNAL(sliderReleased()), this, SLOT( changedInVolume()) ); 784 this, SLOT( deleteSound() ));
740 785 connect( Stop_PushButton, SIGNAL(released()),
741 // connect( OutputSlider, SIGNAL(valueChanged( int)), this, SLOT(changedOutVolume(int)) ); 786 this, SLOT( doPlayBtn() ));
742 // connect( InputSlider, SIGNAL(valueChanged( int)), this, SLOT(changedInVolume(int)) ); 787 connect( Rec_PushButton, SIGNAL(released()),
743 788 this, SLOT( newSound() ) );
744 connect( sampleRateComboBox, SIGNAL(activated( int)), this, SLOT( changesamplerateCombo(int)) ); 789 connect( TabWidget, SIGNAL( currentChanged( QWidget*)),
745 connect( bitRateComboBox, SIGNAL(activated( int)), this, SLOT( changebitrateCombo(int)) ); 790 this, SLOT(thisTab(QWidget*) ));
746 connect( directoryComboBox, SIGNAL(activated( int)), this, SLOT( changeDirCombo(int)) ); 791 connect( OutputSlider, SIGNAL(sliderReleased()),
747 connect( sizeLimitCombo, SIGNAL(activated( int)), this, SLOT( changeSizeLimitCombo(int)) ); 792 this, SLOT( changedOutVolume()) );
748 connect( outMuteCheckBox, SIGNAL(toggled( bool)), this, SLOT( doVolMuting(bool)) ); 793 connect( InputSlider, SIGNAL(sliderReleased()),
749 connect( inMuteCheckBox , SIGNAL(toggled( bool)), this, SLOT( doMicMuting(bool)) ); 794 this, SLOT( changedInVolume()) );
750 connect( ListView1,SIGNAL(doubleClicked( QListViewItem*)),this,SLOT( itClick(QListViewItem*))); 795
796 connect( sampleRateComboBox, SIGNAL(activated( int)),
797 this, SLOT( changesamplerateCombo(int)) );
798 connect( bitRateComboBox, SIGNAL(activated( int)),
799 this, SLOT( changebitrateCombo(int)) );
800
801 connect( directoryComboBox, SIGNAL(activated( int)),
802 this, SLOT( changeDirCombo(int)) );
803 connect( sizeLimitCombo, SIGNAL(activated( int)),
804 this, SLOT( changeSizeLimitCombo(int)) );
805
806 connect( stereoCheckBox, SIGNAL(toggled( bool)),
807 this, SLOT( changeStereoCheck(bool)) );
808
809 connect( outMuteCheckBox, SIGNAL(toggled( bool)),
810 this, SLOT( doVolMuting(bool)) );
811 connect( inMuteCheckBox , SIGNAL(toggled( bool)),
812 this, SLOT( doMicMuting(bool)) );
813
814 connect( ListView1,SIGNAL(doubleClicked( QListViewItem*)),
815 this,SLOT( itClick(QListViewItem*)));
751 connect( ListView1, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 816 connect( ListView1, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
752 this,SLOT( listPressed(int, QListViewItem *, const QPoint&, int)) ); 817 this,SLOT( listPressed(int, QListViewItem *, const QPoint&, int)) );
753 connect( timeSlider, SIGNAL( sliderMoved( int)), this, SLOT( changeTimeSlider(int) )); 818 connect( timeSlider, SIGNAL( sliderMoved( int)),
754 connect( timeSlider, SIGNAL( sliderPressed( )), this, SLOT( timeSliderPressed() )); 819 this, SLOT( changeTimeSlider(int) ));
755 connect( timeSlider, SIGNAL( sliderReleased( )), this, SLOT( timeSliderReleased() )); 820 connect( timeSlider, SIGNAL( sliderPressed( )),
756 connect( compressionCheckBox, SIGNAL( toggled(bool)),this, SLOT( compressionSelected(bool))); 821 this, SLOT( timeSliderPressed() ));
757 connect( autoMuteCheckBox, SIGNAL( toggled(bool)),this, SLOT( slotAutoMute(bool))); 822 connect( timeSlider, SIGNAL( sliderReleased( )),
823 this, SLOT( timeSliderReleased() ));
824 connect( compressionCheckBox, SIGNAL( toggled(bool)),
825 this, SLOT( compressionSelected(bool)));
826 connect( autoMuteCheckBox, SIGNAL( toggled(bool)),
827 this, SLOT( slotAutoMute(bool)));
758} 828}
759 829
760void QtRec::initConfig() { 830void QtRec::initConfig() {
@@ -782,13 +852,15 @@ void QtRec::initConfig() {
782 852
783 i=cfg.readNumEntry("sizeLimit", 5 ); 853 i=cfg.readNumEntry("sizeLimit", 5 );
784 QString temp; 854 QString temp;
785// for(int i=1;i<13; i++) {
786// temp = sizeLimitCombo->text(i);
787
788// sizeLimitCombo->insertItem( QString::number(i*5)+tr(" secs"));
789// }
790 sizeLimitCombo->setCurrentItem((i/5)); 855 sizeLimitCombo->setCurrentItem((i/5));
791 856
857 stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1));
858 if( stereoCheckBox->isChecked()) {
859 filePara.channels = 2;
860 } else {
861 filePara.channels = 1;
862 }
863
792 compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); 864 compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1));
793 if( compressionCheckBox->isChecked()) { 865 if( compressionCheckBox->isChecked()) {
794 bitRateComboBox->setEnabled(false); 866 bitRateComboBox->setEnabled(false);
@@ -808,20 +880,15 @@ void QtRec::initConfig() {
808 inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); 880 inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0));
809} 881}
810 882
811//================
812
813void QtRec::stop() { 883void QtRec::stop() {
814 // qDebug("<<<<<<<<<stop()"); 884 qWarning("STOP");
815 setRecordButton(false); 885 setRecordButton(false);
816 monitoring=false;
817 stopped=true;
818 886
819 if( !recording) 887 if( !recording)
820 endPlaying(); 888 endPlaying();
821 else 889 else
822 endRecording(); 890 endRecording();
823 timeSlider->setValue(0); 891 timeSlider->setValue(0);
824 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device
825} 892}
826 893
827void QtRec::doPlayBtn() { 894void QtRec::doPlayBtn() {
@@ -853,6 +920,9 @@ void QtRec::start() { //play
853} 920}
854 921
855bool QtRec::rec() { //record 922bool QtRec::rec() { //record
923 QString timeString;
924 timeString.sprintf("%.0f", 0.0);
925 timeLabel->setText( timeString+ " seconds");
856 if(!stopped) { 926 if(!stopped) {
857 monitoring=true; 927 monitoring=true;
858 return false; 928 return false;
@@ -861,34 +931,47 @@ bool QtRec::rec() { //record
861 playLabel2->setText(tr("Stop")); 931 playLabel2->setText(tr("Stop"));
862 monitoring=false; 932 monitoring=false;
863 setRecordButton(true); 933 setRecordButton(true);
864 stopped=false;
865 934
866 if( setupAudio( true)) 935 if( setupAudio( true))
867 if(setUpFile()) { 936 if(setUpFile()) {
868 int fileSize=0; 937 int fileSize=0;
869 Config cfg("OpieRec"); 938 Config cfg("OpieRec");
870 cfg.setGroup("Settings"); 939 cfg.setGroup("Settings");
940// qDebug( "<<<<<<<Device bits %d, device rate %d, device channels %d",
941// soundDevice->getDeviceBits(),
942// soundDevice->getDeviceRate(),
943// soundDevice->getDeviceChannels());
944
871 //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); 945 //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050);
872 // qDebug("sample rate is %d", filePara.sampleRate); 946 // qDebug("sample rate is %d", filePara.sampleRate);
873 filePara.SecondsToRecord = getCurrentSizeLimit(); 947 filePara.SecondsToRecord = getCurrentSizeLimit();
874 948
949// qDebug("size limit %d sec", filePara.SecondsToRecord);
875 int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); 950 int diskSize = checkDiskSpace( (const QString &) wavFile->trackName());
876 951
877 if( filePara.SecondsToRecord == 0) { 952 if( filePara.SecondsToRecord == 0) {
878 fileSize = diskSize; 953 fileSize = diskSize;
879 } else if( filePara.format==WAVE_FORMAT_PCM) { 954 } else if( filePara.format==WAVE_FORMAT_PCM) {
955// qDebug("WAVE_FORMAT_PCM");
880 fileSize = (filePara.SecondsToRecord ) * filePara.channels 956 fileSize = (filePara.SecondsToRecord ) * filePara.channels
881 * filePara.sampleRate *(filePara.resolution/8)+1000; 957 * filePara.sampleRate *(filePara.resolution/8)+1000;
882 } else { 958 } else {
959// qDebug("WAVE_FORMAT_DVI_ADPCM");
883 fileSize = ((filePara.SecondsToRecord) * filePara.channels 960 fileSize = ((filePara.SecondsToRecord) * filePara.channels
884 * filePara.sampleRate *(filePara.resolution/8) )/4+250; 961 * filePara.sampleRate *(filePara.resolution/8) )/4+250;
885 } 962 }
886 963
887 filePara.samplesToRecord = fileSize; 964 filePara.samplesToRecord = fileSize;
965 qDebug("filesize should be %d, bits %d, rate %d",
966 filePara.samplesToRecord, filePara.resolution, filePara.sampleRate);
888 if(paused) { 967 if(paused) {
889 paused = false; 968 paused = false;
890 } 969 }
970 // else {
971 qDebug("Setting timeslider %d", filePara.samplesToRecord);
972 // if(fileSize != 0)
891 timeSlider->setRange(0, filePara.samplesToRecord); 973 timeSlider->setRange(0, filePara.samplesToRecord);
974 // }
892 975
893 if( diskSize < fileSize/1024) { 976 if( diskSize < fileSize/1024) {
894 QMessageBox::warning(this, 977 QMessageBox::warning(this,
@@ -904,6 +987,8 @@ bool QtRec::rec() { //record
904 setCaption( msg); 987 setCaption( msg);
905#endif 988#endif
906 filePara.fileName=currentFile.latin1(); 989 filePara.fileName=currentFile.latin1();
990// qDebug("Start recording thread");
991 stopped = false;
907 992
908 pthread_t thread1; 993 pthread_t thread1;
909 pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); 994 pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/);
@@ -911,28 +996,10 @@ bool QtRec::rec() { //record
911 toEndButton->setEnabled(false); 996 toEndButton->setEnabled(false);
912 997
913 startTimer(1000); 998 startTimer(1000);
999// quickRec();
914 } 1000 }
915 } //end setUpFile 1001 } //end setUpFile
916 } //end setupAudio 1002 } //end setupAudio
917 // _exit( 0);
918
919 // ///* default:
920// // /* pid greater than zero is parent getting the child's pid */
921// /* printf("Child's pid is %d\n",pid);
922// waitpid( pid, &status, 0);
923// printf("Child[%d] exited with status %d\n", pid, status);*/
924 // while (wait(NULL) != pid)
925// ;
926// printf("child %ld terminated normally, return status is zero\n", (long) pid);
927 // endRecording();
928/* else { //device was not opened
929 qDebug("Audio device open failed");
930 return false;
931 }
932 }*/
933// } //end fork
934// }
935// }
936 return true; 1003 return true;
937} 1004}
938/* 1005/*
@@ -941,8 +1008,8 @@ void QtRec::thisTab(QWidget* widg) {
941 if(widg != NULL) { 1008 if(widg != NULL) {
942 int index=TabWidget->currentPageIndex(); 1009 int index=TabWidget->currentPageIndex();
943 1010
944// if(index==0) { //file page 1011 if(index == 0) { //file page
945// } 1012 }
946 1013
947 if(index ==1) { //control page 1014 if(index ==1) { //control page
948 fillDirectoryCombo(); 1015 fillDirectoryCombo();
@@ -950,8 +1017,9 @@ void QtRec::thisTab(QWidget* widg) {
950// soundDevice->getInVol(); 1017// soundDevice->getInVol();
951 } 1018 }
952 1019
953// if(index==2) { //help page 1020 if( index==2) { //help page
954// } 1021 }
1022
955 qApp->processEvents(); 1023 qApp->processEvents();
956 update(); 1024 update();
957 } 1025 }
@@ -959,11 +1027,13 @@ void QtRec::thisTab(QWidget* widg) {
959 1027
960void QtRec::getOutVol( ) { 1028void QtRec::getOutVol( ) {
961 filePara.outVol = soundDevice->getOutVolume(); 1029 filePara.outVol = soundDevice->getOutVolume();
1030// qDebug("out vol %d", filePara.outVol);
962 OutputSlider->setValue( -filePara.outVol); 1031 OutputSlider->setValue( -filePara.outVol);
963} 1032}
964 1033
965void QtRec::getInVol() { 1034void QtRec::getInVol() {
966 filePara.inVol = soundDevice->getInVolume(); 1035 filePara.inVol = soundDevice->getInVolume();
1036// qDebug("in vol %d", filePara.inVol);
967 InputSlider->setValue( -filePara.inVol); 1037 InputSlider->setValue( -filePara.inVol);
968} 1038}
969 1039
@@ -983,7 +1053,8 @@ bool QtRec::setupAudio( bool b) {
983 1053
984 filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 1054 filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16
985 1055
986 if( !b){ // we want to play 1056 if( !b) {
1057// we want to play
987 if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { 1058 if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) {
988 sampleformat = AFMT_S16_LE; 1059 sampleformat = AFMT_S16_LE;
989 filePara.resolution = 16; 1060 filePara.resolution = 16;
@@ -992,10 +1063,11 @@ bool QtRec::setupAudio( bool b) {
992 filePara.resolution=8; 1063 filePara.resolution=8;
993 } 1064 }
994 1065
995 stereo = filePara.channels = 1; 1066 stereo = filePara.channels;
996 flags= O_WRONLY; 1067 flags= O_WRONLY;
997 dspString = DSPSTROUT; 1068 dspString = DSPSTROUT;
998 mixerString = DSPSTRMIXEROUT; 1069 mixerString = DSPSTRMIXEROUT;
1070 recording = false;
999 } else { // we want to record 1071 } else { // we want to record
1000 1072
1001 if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") 1073 if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
@@ -1005,22 +1077,34 @@ bool QtRec::setupAudio( bool b) {
1005 1077
1006 if( !compressionCheckBox->isChecked()) { 1078 if( !compressionCheckBox->isChecked()) {
1007 filePara.format=WAVE_FORMAT_PCM; 1079 filePara.format=WAVE_FORMAT_PCM;
1080// qDebug("WAVE_FORMAT_PCM");
1008 } else { 1081 } else {
1009 filePara.format=WAVE_FORMAT_DVI_ADPCM; 1082 filePara.format=WAVE_FORMAT_DVI_ADPCM;
1010 sampleformat=AFMT_S16_LE; 1083 sampleformat=AFMT_S16_LE;
1084// qDebug("WAVE_FORMAT_DVI_ADPCM");
1011 } 1085 }
1012 1086
1013 stereo = filePara.channels = 1; 1087 stereo = filePara.channels;
1088// filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100;
1014 flags= O_RDWR; 1089 flags= O_RDWR;
1090// flags= O_RDONLY;
1015 dspString = DSPSTRIN; 1091 dspString = DSPSTRIN;
1016 mixerString = DSPSTRMIXEROUT; 1092 mixerString = DSPSTRMIXEROUT;
1093 recording = true;
1017 } 1094 }
1018 1095
1019 // if(soundDevice) delete soundDevice; 1096 // if(soundDevice) delete soundDevice;
1097 qDebug("<<<<<<<<<<<<<<<<<<<open dsp %d %d %d", filePara.sampleRate, filePara.channels, sampleformat);
1098 qWarning("change waveform settings");
1099 waveform->changeSettings( filePara.sampleRate, filePara.channels );
1100
1020 soundDevice = new Device( this, dspString, mixerString, b); 1101 soundDevice = new Device( this, dspString, mixerString, b);
1021// soundDevice->openDsp(); 1102// soundDevice->openDsp();
1022 soundDevice->reset(); 1103 soundDevice->reset();
1023 1104
1105 qDebug("device has been made %d", soundDevice->sd);
1106
1107 ////////////////// <<<<<<<<<<<<>>>>>>>>>>>>
1024 soundDevice->setDeviceFormat( sampleformat); 1108 soundDevice->setDeviceFormat( sampleformat);
1025 soundDevice->setDeviceChannels( filePara.channels); 1109 soundDevice->setDeviceChannels( filePara.channels);
1026 soundDevice->setDeviceRate( filePara.sampleRate); 1110 soundDevice->setDeviceRate( filePara.sampleRate);
@@ -1030,15 +1114,15 @@ bool QtRec::setupAudio( bool b) {
1030 soundDevice->setFragSize( frag); 1114 soundDevice->setFragSize( frag);
1031 soundDevice->getDeviceFragSize(); 1115 soundDevice->getDeviceFragSize();
1032#endif 1116#endif
1033 1117 /////////////////
1034 filePara.sd = soundDevice->sd; 1118 filePara.sd = soundDevice->sd;
1035 1119
1036 if ( filePara.sd == -1) { 1120 if ( filePara.sd == -1) {
1121
1037 monitoring=false; 1122 monitoring=false;
1038 stopped=true; 1123 stopped=true;
1039 update(); 1124 update();
1040 setCaption( tr( "OpieRecord " ) /*+ QString::number(VERSION)*/ ); 1125 setCaption( tr( "OpieRecord " )+ QString::number(VERSION) );
1041 stopped=true;
1042 return false; 1126 return false;
1043 } 1127 }
1044 if(autoMute) 1128 if(autoMute)
@@ -1062,7 +1146,7 @@ bool QtRec::setUpFile() { //setup file for recording
1062 if(filePara.fd == -1) { 1146 if(filePara.fd == -1) {
1063 return false; 1147 return false;
1064 } else { 1148 } else {
1065 filePara.channels=1; 1149// filePara.channels=1;
1066 } 1150 }
1067 return true; 1151 return true;
1068} 1152}
@@ -1070,163 +1154,41 @@ bool QtRec::setUpFile() { //setup file for recording
1070/// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> 1154/// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>>
1071bool QtRec::doPlay() { 1155bool QtRec::doPlay() {
1072 1156
1073// pthread_t thread2;
1074// pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/);
1075
1076 // qDebug("doPlay file %d", filePara.fd);
1077 int bytesWritten, number;
1078 recording = false;
1079// int number=0;
1080 if( !paused) { 1157 if( !paused) {
1081 // qDebug("new");
1082 total=0; 1158 total=0;
1083 bytesWritten=0;
1084 filePara.numberOfRecordedSeconds = 0; 1159 filePara.numberOfRecordedSeconds = 0;
1085 } else { 1160 } else {
1086 paused = false; 1161 paused = false;
1087 secCount = (int)filePara.numberOfRecordedSeconds; 1162 secCount = (int)filePara.numberOfRecordedSeconds;
1088 } 1163 }
1089 playing=true; 1164 playing=true;
1090 number=0; 1165 stopped = false;
1166 recording = false;
1091 1167
1092 QString num; 1168 QString num;
1093// block=BUFSIZE; 1169 qDebug( "Play number of samples %d", filePara.numberSamples);
1094 timeSlider->setRange(0, filePara.numberSamples); 1170
1095 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); 1171// timeSlider->setRange( 0, filePara.numberSamples);
1172
1173 timeString.sprintf("%d", filePara.numberOfRecordedSeconds);
1096 timeLabel->setText( timeString+ tr(" seconds")); 1174 timeLabel->setText( timeString+ tr(" seconds"));
1097 1175
1098// if( filePara.format==WAVE_FORMAT_DVI_ADPCM) {
1099// // qDebug("WAVE_FORMAT_DVI_ADPCM");
1100// } else {
1101// // qDebug("WAVE_FORMAT_PCM");
1102// }
1103 QString msg; 1176 QString msg;
1104 msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); 1177 msg.sprintf("%d, %d, %d",
1178 filePara.sampleRate,
1179 filePara.channels,
1180 filePara.resolution);
1105#ifdef DEV_VERSION 1181#ifdef DEV_VERSION
1106 setCaption( msg); 1182 setCaption( msg);
1107#endif 1183#endif
1108 if( filePara.resolution == 16 ) { //AFMT_S16_LE) {
1109 // qDebug("16 bit");
1110 1184
1111 startTimer(1000); 1185 startTimer(1000);
1186 pthread_t thread2;
1187 pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/);
1112 1188
1113 if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { 1189 toBeginningButton->setEnabled( false);
1114 char abuf[BUFSIZE/2]; 1190 toEndButton->setEnabled( false);
1115 short sbuf[BUFSIZE];
1116 short sbuf2[BUFSIZE*2];
1117 memset( abuf, 0, BUFSIZE / 2);
1118 memset( sbuf, 0, BUFSIZE);
1119 memset( sbuf2, 0, BUFSIZE * 2);
1120// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
1121 for(;;) { // play loop
1122 if (stopped)
1123 break; // stop if playing was set to false
1124
1125
1126 number=::read( filePara.fd, abuf, BUFSIZE/2);
1127 adpcm_decoder( abuf, sbuf, number*2, &decoder_state);
1128
1129// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
1130// sbuf2[i+1]=sbuf2[i]=sbuf[i];
1131// }
1132
1133 bytesWritten = write ( filePara.sd, sbuf, number*4);
1134 // if(filePara.channels==1)
1135 // total += bytesWritten/2; //mono
1136 // else
1137 total += bytesWritten;
1138 timeSlider->setValue( total / 4);
1139
1140 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2;
1141
1142 timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
1143// if(filePara.numberOfRecordedSeconds>1)
1144 timeLabel->setText( timeString+ tr(" seconds"));
1145// printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4);
1146// printf("playing number %d, bytes %d, total %d totalsamples %d number recorded seconds %.2f\r",
1147// number, bytesWritten, total/4, filePara.numberSamples, filePara.numberOfRecordedSeconds);
1148// fflush(stdout);
1149
1150 qApp->processEvents();
1151
1152 if( bytesWritten <= 0 ){//|| secCount > filePara.numberOfRecordedSeconds ) {
1153 stopped = true;
1154 endPlaying();
1155 }
1156 }
1157 } else {
1158 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
1159 short inbuffer[BUFSIZE], outbuffer[BUFSIZE];
1160 memset( inbuffer, 0, BUFSIZE);
1161 memset( outbuffer, 0, BUFSIZE);
1162
1163 for(;;) { // play loop
1164 if (stopped)
1165 break; // stop if playing was set to false
1166 number=::read( filePara.fd, inbuffer, BUFSIZE);
1167// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
1168// // for (int i=0;i< number ; i++) { //2*i is left channel
1169// outbuffer[i+1]= outbuffer[i]=inbuffer[i];
1170// }
1171
1172 bytesWritten = ::write( filePara.sd, inbuffer, number);
1173 //-------------->>>> out to device
1174 // total+=bytesWritten;
1175 // if(filePara.channels==1)
1176 // total += bytesWritten/2; //mono
1177 // else
1178 total += bytesWritten;
1179
1180 timeSlider->setValue( total);
1181 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
1182
1183 timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
1184 timeLabel->setText( timeString + tr(" seconds"));
1185
1186 qApp->processEvents();
1187
1188 if( bytesWritten <= 0 && secCount > filePara.numberOfRecordedSeconds ) {
1189 stopped = true;
1190 endPlaying();
1191 }
1192 }
1193// printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total);
1194// fflush(stdout);
1195 } //end loop
1196 } else { /////////////////////////////// format = AFMT_U8;
1197 unsigned char unsigned_inbuffer[BUFSIZE];//, unsigned_outbuffer[BUFSIZE];
1198 memset( unsigned_inbuffer,0,BUFSIZE);
1199 for(;;) { // main loop
1200 if (stopped)
1201 break; // stop if playing was set to false
1202 number=::read( filePara.fd, unsigned_inbuffer, BUFSIZE);
1203//data = (val >> 8) ^ 0x80;
1204 // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80;
1205 bytesWritten = write ( filePara.sd, unsigned_inbuffer, number);
1206 total+=bytesWritten;
1207
1208 timeSlider->setValue( total);
1209
1210 filePara.numberOfRecordedSeconds=(float)total/(float)filePara.sampleRate;
1211 timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
1212 timeLabel->setText( timeString + tr(" seconds"));
1213 qApp->processEvents();
1214
1215 if( bytesWritten <= 0 && secCount > filePara.numberOfRecordedSeconds ) {
1216 stopped = true;
1217 endPlaying();
1218 }
1219 // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples);
1220 // fflush(stdout);
1221 }
1222 }
1223 1191
1224// qDebug("\nstopped or paused %d", total/4);
1225 if(!paused && !stopped) {
1226 stopped = true;
1227// endPlaying();
1228 endPlaying();
1229 }
1230 return true; 1192 return true;
1231} 1193}
1232 1194
@@ -1250,19 +1212,8 @@ void QtRec::changesamplerateCombo(int i) {
1250 rate = sampleRateComboBox->text(i).toInt(&ok, 10); 1212 rate = sampleRateComboBox->text(i).toInt(&ok, 10);
1251 cfg.writeEntry("samplerate",rate); 1213 cfg.writeEntry("samplerate",rate);
1252 filePara.sampleRate=rate; 1214 filePara.sampleRate=rate;
1253/* soundDevice = new Device( this, DSPSTROUT, DSPSTRMIXER, false); 1215 qDebug( "Change sample rate %d", rate);
1254 soundDevice->openDsp();*/
1255//
1256// soundDevice->setDeviceFormat(AFMT_S16_LE);
1257// soundDevice->setDeviceChannels(filePara.channels);
1258// soundDevice->setDeviceRate(filePara.sampleRate);
1259//
1260// soundDevice->closeDevice( true);
1261// soundDevice=0;
1262// delete soundDevice;
1263 // qDebug("Change sample rate %d", rate);
1264 cfg.write(); 1216 cfg.write();
1265
1266} 1217}
1267 1218
1268 1219
@@ -1281,7 +1232,7 @@ void QtRec::changeDirCombo(int index) {
1281 const QString path = (*it)->path(); 1232 const QString path = (*it)->path();
1282 recDir = path; 1233 recDir = path;
1283 cfg.writeEntry("directory", recDir); 1234 cfg.writeEntry("directory", recDir);
1284 // qDebug("new rec dir "+recDir); 1235 qDebug("new rec dir "+recDir);
1285 } 1236 }
1286 } 1237 }
1287 cfg.write(); 1238 cfg.write();
@@ -1296,14 +1247,10 @@ void QtRec::changeSizeLimitCombo(int) {
1296} 1247}
1297 1248
1298void QtRec::newSound() { 1249void QtRec::newSound() {
1299 // qDebug("<<<<<<<<<new sound");
1300
1301 if( !rec()) { 1250 if( !rec()) {
1302 // qDebug("rec() failed");
1303 endRecording(); 1251 endRecording();
1304 deleteSound(); 1252 deleteSound();
1305 } 1253 }
1306
1307} 1254}
1308 1255
1309void QtRec::itClick(QListViewItem *item) { 1256void QtRec::itClick(QListViewItem *item) {
@@ -1324,11 +1271,9 @@ void QtRec::deleteSound() {
1324#endif 1271#endif
1325 { 1272 {
1326 QString file = ListView1->currentItem()->text(0); 1273 QString file = ListView1->currentItem()->text(0);
1327 // qDebug("Filename to find is "+file);
1328 QString fileName; 1274 QString fileName;
1329 fileName = cfg.readEntry( file, ""); 1275 fileName = cfg.readEntry( file, "");
1330 QFile f(fileName); 1276 QFile f(fileName);
1331 // qDebug("fileName is "+fileName);
1332 if(f.exists()) 1277 if(f.exists())
1333 if( !f.remove()) 1278 if( !f.remove())
1334 QMessageBox::message(tr("Error"),tr("Could not remove file.")); 1279 QMessageBox::message(tr("Error"),tr("Could not remove file."));
@@ -1336,11 +1281,9 @@ void QtRec::deleteSound() {
1336 int nFiles = cfg.readNumEntry("NumberofFiles",0); 1281 int nFiles = cfg.readNumEntry("NumberofFiles",0);
1337 bool found=false; 1282 bool found=false;
1338 for(int i=0;i<nFiles+1;i++) { 1283 for(int i=0;i<nFiles+1;i++) {
1339 // qDebug(cfg.readEntry(QString::number(i)));
1340 1284
1341 if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { 1285 if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) {
1342 found = true; 1286 found = true;
1343// qDebug( cfg.readEntry(QString::number(i))+"\n" +cfg.readEntry(QString::number(i+1)) );
1344 cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); 1287 cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),""));
1345 } 1288 }
1346 if(found) 1289 if(found)
@@ -1349,12 +1292,10 @@ void QtRec::deleteSound() {
1349 1292
1350 cfg.removeEntry(cfg.readEntry(file)); 1293 cfg.removeEntry(cfg.readEntry(file));
1351 cfg.removeEntry( file); 1294 cfg.removeEntry( file);
1352 // cfg.removeEntry( QString::number(nFiles));
1353 cfg.writeEntry("NumberofFiles", nFiles-1); 1295 cfg.writeEntry("NumberofFiles", nFiles-1);
1354 cfg.write(); 1296 cfg.write();
1355 1297
1356 ListView1->takeItem( ListView1->currentItem() ); 1298 ListView1->takeItem( ListView1->currentItem() );
1357 // ListView1->takeItem( ListView1->itemAt(nFiles) );
1358 delete ListView1->currentItem(); 1299 delete ListView1->currentItem();
1359 1300
1360 ListView1->clear(); 1301 ListView1->clear();
@@ -1365,32 +1306,13 @@ void QtRec::deleteSound() {
1365#ifndef DEV_VERSION 1306#ifndef DEV_VERSION
1366 }; 1307 };
1367#endif 1308#endif
1368 setCaption( tr( "OpieRecord " ) /*+ QString::number(VERSION)*/ ); 1309 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) );
1369 1310
1370} 1311}
1371 1312
1372void QtRec::keyPressEvent( QKeyEvent *e) { 1313void QtRec::keyPressEvent( QKeyEvent *e) {
1373 1314
1374 switch ( e->key() ) { 1315 switch ( e->key() ) {
1375 /*
1376 vercel keys->
1377 right side
1378 0
1379 1 0x1030 Key_F1
1380 2 0x1031 Key_F2
1381 3 0x1032 Key_F3
1382 4 0x1016 Key_PageUp
1383 5 0x1017 Key_PageDown
1384 6
1385 ---------------
1386 left side
1387 Up 0x1013 Key_Up
1388 Down 0x1015 Key_Down
1389 Left 0x1012 Key_Left
1390 Right 0x1014 Key_Right
1391 0x1010 Key_Home
1392
1393 */
1394 // case Key_F1: 1316 // case Key_F1:
1395 // if(stopped && !recording) 1317 // if(stopped && !recording)
1396 // newSound(); 1318 // newSound();
@@ -1430,7 +1352,7 @@ void QtRec::keyPressEvent( QKeyEvent *e) {
1430 // newSound(); 1352 // newSound();
1431 break; 1353 break;
1432 case Key_Left: { 1354 case Key_Left: {
1433 // qDebug("rewinding"); 1355 qDebug("rewinding");
1434 if( !e->isAutoRepeat()) 1356 if( !e->isAutoRepeat())
1435 rewindPressed(); 1357 rewindPressed();
1436 } 1358 }
@@ -1484,7 +1406,7 @@ void QtRec::keyReleaseEvent( QKeyEvent *e) {
1484 break; 1406 break;
1485 case Key_Up: 1407 case Key_Up:
1486 // stop(); 1408 // stop();
1487 // qDebug("Up"); 1409 qDebug("Up");
1488 break; 1410 break;
1489 case Key_Down: 1411 case Key_Down:
1490 // start(); 1412 // start();
@@ -1492,25 +1414,26 @@ void QtRec::keyReleaseEvent( QKeyEvent *e) {
1492 // newSound(); 1414 // newSound();
1493 break; 1415 break;
1494 case Key_Left: 1416 case Key_Left:
1495 // qDebug("Left"); 1417 qDebug("Left");
1496 rewindReleased(); 1418 rewindReleased();
1497 break; 1419 break;
1498 case Key_Right: 1420 case Key_Right:
1499 // qDebug("Right"); 1421 qDebug("Right");
1500 FastforwardReleased(); 1422 FastforwardReleased();
1501 break; 1423 break;
1502 } 1424 }
1503} 1425}
1504 1426
1505void QtRec::endRecording() { 1427void QtRec::endRecording() {
1506 // qDebug("endRecording"); 1428 monitoring = false;
1429 recording = false;
1430 stopped = true;
1431 waveform->reset();
1507 setRecordButton(false); 1432 setRecordButton(false);
1508 timeSlider->setValue(0); 1433
1509 toBeginningButton->setEnabled(true); 1434 toBeginningButton->setEnabled(true);
1510 toEndButton->setEnabled(true); 1435 toEndButton->setEnabled(true);
1511 1436
1512 monitoring=false;
1513
1514 killTimers(); 1437 killTimers();
1515 1438
1516 if(autoMute) 1439 if(autoMute)
@@ -1518,10 +1441,6 @@ void QtRec::endRecording() {
1518 1441
1519 soundDevice->closeDevice( true); 1442 soundDevice->closeDevice( true);
1520 1443
1521 recording = false;
1522 stopped=true;
1523 t->stop();
1524
1525 if( wavFile->track.isOpen()) { 1444 if( wavFile->track.isOpen()) {
1526 wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); 1445 wavFile->adjustHeaders( filePara.fd, filePara.numberSamples);
1527 // soundDevice->sd=-1; 1446 // soundDevice->sd=-1;
@@ -1538,7 +1457,7 @@ void QtRec::endRecording() {
1538 system(cmd.latin1()); 1457 system(cmd.latin1());
1539 } 1458 }
1540 1459
1541 // qDebug("Just moved "+wavFile->currentFileName); 1460 qDebug("Just moved " + wavFile->currentFileName);
1542 Config cfg("OpieRec"); 1461 Config cfg("OpieRec");
1543 cfg.setGroup("Sounds"); 1462 cfg.setGroup("Sounds");
1544 1463
@@ -1557,18 +1476,24 @@ void QtRec::endRecording() {
1557 // qDebug("writing config numberOfRecordedSeconds "+time); 1476 // qDebug("writing config numberOfRecordedSeconds "+time);
1558 1477
1559 cfg.write(); 1478 cfg.write();
1560 // qDebug("finished recording"); 1479 qDebug("finished recording");
1561 timeLabel->setText(""); 1480 timeLabel->setText("");
1562 } 1481 }
1563 1482
1564 if(soundDevice) delete soundDevice; 1483 if(soundDevice) delete soundDevice;
1565 1484
1485 timeSlider->setValue(0);
1566 initIconView(); 1486 initIconView();
1567 selectItemByName(currentFile); 1487 selectItemByName(currentFile);
1568} 1488}
1569 1489
1570void QtRec::endPlaying() { 1490void QtRec::endPlaying() {
1571 1491 monitoring = false;
1492 recording = false;
1493 playing = false;
1494 stopped = true;
1495 waveform->reset();
1496// errorStop();
1572 // qDebug("end playing"); 1497 // qDebug("end playing");
1573 setRecordButton(false); 1498 setRecordButton(false);
1574 1499
@@ -1582,19 +1507,17 @@ void QtRec::endPlaying() {
1582 soundDevice->sd=-1; 1507 soundDevice->sd=-1;
1583 // if(soundDevice) delete soundDevice; 1508 // if(soundDevice) delete soundDevice;
1584 // qDebug("file and sound device closed"); 1509 // qDebug("file and sound device closed");
1585 stopped=true;
1586 recording=false;
1587 playing=false;
1588 timeLabel->setText(""); 1510 timeLabel->setText("");
1589 monitoring=false;
1590 total = 0; 1511 total = 0;
1591 filePara.numberSamples=0; 1512 filePara.numberSamples=0;
1592 filePara.sd=-1; 1513 filePara.sd=-1;
1593 wavFile->closeFile(); 1514// wavFile->closeFile();
1594 filePara.fd=0; 1515 filePara.fd=0;
1595// if(wavFile) delete wavFile; //this crashes 1516// if(wavFile) delete wavFile; //this crashes
1596 1517
1597 // qDebug("track closed"); 1518 // qDebug("track closed");
1519 killTimers();
1520 qWarning("reset slider");
1598 timeSlider->setValue(0); 1521 timeSlider->setValue(0);
1599 1522
1600 if(soundDevice) delete soundDevice; 1523 if(soundDevice) delete soundDevice;
@@ -1616,7 +1539,7 @@ bool QtRec::openPlayFile() {
1616 for(int i=0;i<nFiles+1;i++) { //look for file 1539 for(int i=0;i<nFiles+1;i++) { //look for file
1617 if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { 1540 if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) {
1618 currentFileName=cfg.readEntry( currentFile, "" ); 1541 currentFileName=cfg.readEntry( currentFile, "" );
1619 // qDebug("opening for play: "+currentFileName); 1542 qDebug("opening for play: " + currentFileName);
1620 } 1543 }
1621 } 1544 }
1622 wavFile = new WavFile(this, 1545 wavFile = new WavFile(this,
@@ -1627,20 +1550,26 @@ bool QtRec::openPlayFile() {
1627 // if(!track.open(IO_ReadOnly)) { 1550 // if(!track.open(IO_ReadOnly)) {
1628 QString errorMsg=(QString)strerror(errno); 1551 QString errorMsg=(QString)strerror(errno);
1629 monitoring=false; 1552 monitoring=false;
1630 setCaption( tr( "OpieRecord " )/* + QString::number(VERSION)*/ ); 1553 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) );
1631 QMessageBox::message(tr("Note"),tr("Could not open audio file.\n") 1554 QMessageBox::message(tr("Note"),tr("Could not open audio file.\n")
1632 +errorMsg+"\n"+currentFile); 1555 +errorMsg+"\n"+currentFile);
1633 return false; 1556 return false;
1634 } else { 1557 } else {
1558
1635 filePara.numberSamples=wavFile->getNumberSamples(); 1559 filePara.numberSamples=wavFile->getNumberSamples();
1636 filePara.format = wavFile->getFormat(); 1560 filePara.format = wavFile->getFormat();
1637 // qDebug("file %d, samples %f", filePara.fd, filePara.numberSamples);
1638 filePara.sampleRate= wavFile->getSampleRate(); 1561 filePara.sampleRate= wavFile->getSampleRate();
1639 filePara.resolution=wavFile->getResolution(); 1562 filePara.resolution=wavFile->getResolution();
1563 filePara.channels = wavFile->getChannels();
1640 timeSlider->setPageStep(1); 1564 timeSlider->setPageStep(1);
1641 monitoring=true; 1565 monitoring=true;
1566
1567 qDebug("file %d, samples %d %d", filePara.fd, filePara.numberSamples, filePara.sampleRate);
1568 int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8));
1569
1570 qWarning("seconds %d", sec);
1571
1642 timeSlider->setRange(0, filePara.numberSamples ); 1572 timeSlider->setRange(0, filePara.numberSamples );
1643 filePara.numberOfRecordedSeconds=(float) filePara.numberSamples / (float)filePara.sampleRate * (float)2;
1644 } 1573 }
1645 1574
1646 return true; 1575 return true;
@@ -1703,7 +1632,8 @@ void QtRec::doBeam() {
1703 if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { 1632 if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) {
1704 QString filePath = cfg.readEntry(file,""); 1633 QString filePath = cfg.readEntry(file,"");
1705 Ir *file = new Ir(this, "IR"); 1634 Ir *file = new Ir(this, "IR");
1706 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); 1635 connect( file, SIGNAL( done(Ir*)),
1636 this, SLOT( fileBeamFinished( Ir * )));
1707 file->send( filePath, "OPieRec audio file\n"+filePath ); 1637 file->send( filePath, "OPieRec audio file\n"+filePath );
1708 } 1638 }
1709 } 1639 }
@@ -1738,8 +1668,7 @@ void QtRec::doRename() {
1738} 1668}
1739 1669
1740void QtRec::okRename() { 1670void QtRec::okRename() {
1741 // qDebug("okRename"); 1671 qDebug(renameBox->text());
1742 // qDebug(renameBox->text());
1743 QString filename = renameBox->text(); 1672 QString filename = renameBox->text();
1744 cancelRename(); 1673 cancelRename();
1745 1674
@@ -1751,7 +1680,7 @@ void QtRec::okRename() {
1751 1680
1752 QString file = ListView1->currentItem()->text(0); 1681 QString file = ListView1->currentItem()->text(0);
1753 1682
1754 // qDebug("filename is " + filename); 1683 qDebug("filename is " + filename);
1755 1684
1756 int nFiles = cfg.readNumEntry("NumberofFiles",0); 1685 int nFiles = cfg.readNumEntry("NumberofFiles",0);
1757 1686
@@ -1775,7 +1704,6 @@ void QtRec::okRename() {
1775} 1704}
1776 1705
1777void QtRec::cancelRename() { 1706void QtRec::cancelRename() {
1778 // qDebug("cancel rename");
1779 bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; 1707 bool resetFocus = ListView1->viewport()->focusProxy() == renameBox;
1780 delete renameBox; 1708 delete renameBox;
1781 renameBox = 0; 1709 renameBox = 0;
@@ -1811,8 +1739,7 @@ int QtRec::getCurrentSizeLimit() {
1811} 1739}
1812 1740
1813void QtRec::timerBreak() { 1741void QtRec::timerBreak() {
1814 // qDebug("timer break"); 1742 endPlaying();
1815 stop();
1816} 1743}
1817 1744
1818void QtRec::doVolMuting(bool b) { 1745void QtRec::doVolMuting(bool b) {
@@ -1836,7 +1763,8 @@ void QtRec::compressionSelected(bool b) {
1836 Config cfg("OpieRec"); 1763 Config cfg("OpieRec");
1837 cfg.setGroup("Settings"); 1764 cfg.setGroup("Settings");
1838 cfg.writeEntry("wavCompression", b); 1765 cfg.writeEntry("wavCompression", b);
1839 cfg.writeEntry("bitrate",16); filePara.resolution=16; 1766 cfg.writeEntry("bitrate", 16);
1767 filePara.resolution = 16;
1840 cfg.write(); 1768 cfg.write();
1841 1769
1842 if(b) { 1770 if(b) {
@@ -1878,43 +1806,43 @@ long QtRec::checkDiskSpace(const QString &path) {
1878// char f_fname[6]; /* Volumename */ 1806// char f_fname[6]; /* Volumename */
1879// char f_fpack[6]; /* Pack name */ 1807// char f_fpack[6]; /* Pack name */
1880 1808
1881void QtRec::receive( const QCString &/* msg*/, const QByteArray & ) { 1809void QtRec::receive( const QCString &msg, const QByteArray & ) {
1882 // qDebug("Voicerecord received message "+msg); 1810 qDebug("Voicerecord received message "+msg);
1883 1811
1884} 1812}
1885 1813
1886 1814
1887///////////////////////////// timerEvent 1815///////////////////////////// timerEvent
1888void QtRec::timerEvent( QTimerEvent *e ) { 1816void QtRec::timerEvent( QTimerEvent *e ) {
1889// qDebug( "%d", secCount ); 1817
1818// if(!recording)
1819// timeSlider->setValue( secCount);
1820// else
1821// timeSlider->setValue( filePara.numberOfRecordedSeconds);
1822
1823 if( stopped && playing) {
1824 stop();
1825 }
1826
1827 if( stopped && recording ){
1828 stop();
1829 }
1830
1831 if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) {
1832 stop();
1833 }
1834
1835 qDebug( "%d", secCount );
1836 QString timeString;
1890#ifdef DEV_VERSION 1837#ifdef DEV_VERSION
1891 QString msg; 1838 QString msg;
1892 msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); 1839 msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution);
1893 setCaption( msg +" :: "+QString::number(secCount)); 1840 setCaption( msg +" :: "+QString::number(secCount));
1894#endif 1841#endif
1895 1842
1896 if( !playing ) { 1843 timeString.sprintf("%d", secCount);
1897 if(!recording ){ 1844 timeLabel->setText( timeString + " seconds");
1898 killTimer(e->timerId()); 1845
1899///* stopped=true;
1900// recording=false;
1901///*/
1902// _exit( 0);
1903 }
1904 if(filePara.SecondsToRecord < secCount && filePara.SecondsToRecord !=0) {
1905 killTimer(e->timerId());
1906 stop();
1907 }
1908 }
1909// if( stopped && !paused) {
1910// if( filePara.numberOfRecordedSeconds < secCount) {
1911// stopped = true;
1912// // playing=false;
1913// killTimer(e->timerId());
1914// endPlaying();
1915// }
1916// }
1917// qApp->processEvents();
1918 secCount++; 1846 secCount++;
1919} 1847}
1920 1848
@@ -2141,28 +2069,41 @@ void QtRec::selectItemByName(const QString & name) {
2141} 2069}
2142 2070
2143 2071
2144long findPeak(long input ) { 2072// long findPeak(long input ) {
2145 2073
2146// halfLife = time in seconds for output to decay to half value after an impulse 2074// // halfLife = time in seconds for output to decay to half value after an impulse
2147 float output = 0.0; 2075// static float output = 0.0;
2148 float halfLife = .25; 2076// float halfLife = .0025;
2149 float vsf = .0025; 2077// float vsf = .0025;
2150 float scalar = pow( 0.5, 1.0/(halfLife * filePara.sampleRate )); 2078// float scalar = pow( 0.5, 1.0/(halfLife * filePara.sampleRate ));
2151 if( input < 0.0 ) 2079// if( input < 0.0 )
2152 input = -input; // Absolute value. 2080// input = -input; // Absolute value.
2153 if ( input >= output) { 2081// if ( input >= output ) {
2154 // When we hit a peak, ride the peak to the top. 2082// // When we hit a peak, ride the peak to the top.
2155 output = input; 2083// output = input;
2156 } else { 2084// } else {
2157// Exponential decay of output when signal is low. 2085// // Exponential decay of output when signal is low.
2158 output = output * scalar; 2086// output = output * scalar;
2159// 2087// //
2160// When current gets close to 0.0, set current to 0.0 to prevent FP underflow 2088// // When current gets close to 0.0, set current to 0.0 to prevent FP underflow
2161// which can cause a severe performance degradation due to a flood 2089// // which can cause a severe performance degradation due to a flood
2162// of interrupts. 2090// // of interrupts.
2163// 2091// //
2164 if( output < vsf ) output = 0.0; 2092// if( output < vsf ) output = 0.0;
2165 } 2093// }
2166 2094
2167 return (long)output; 2095// return (long) output;
2096// }
2097
2098void QtRec::changeStereoCheck(bool b) {
2099 Config cfg("OpieRec");
2100 cfg.setGroup("Settings");
2101 int ch = 0;
2102 if ( !b) { ch = 1;}
2103 else { ch = 2;}
2104 cfg.writeEntry("stereo", b);
2105 filePara.channels = ch;
2106
2107 cfg.write();
2168} 2108}
2109
diff --git a/noncore/multimedia/opierec/qtrec.h b/noncore/multimedia/opierec/qtrec.h
index ada3270..93b9b5f 100644
--- a/noncore/multimedia/opierec/qtrec.h
+++ b/noncore/multimedia/opierec/qtrec.h
@@ -4,7 +4,7 @@ copyright 2002 by L.J. Potter ljp@llornkcor.com
4****************************************************************************/ 4****************************************************************************/
5#ifndef QTREC_H 5#ifndef QTREC_H
6#define QTREC_H 6#define QTREC_H
7#define VERSION 1.0 7#define VERSION 20030920
8 8
9#include <qpe/ir.h> 9#include <qpe/ir.h>
10 10
@@ -72,7 +72,7 @@ private:
72 QString currentFile; 72 QString currentFile;
73 QString date, currentFileName, tmpFileName; 73 QString date, currentFileName, tmpFileName;
74 QTimer *t_timer; 74 QTimer *t_timer;
75 bool needsStereoOut, paused, playing; 75 bool needsStereoOut, paused;
76 bool useTmpFile, autoMute; 76 bool useTmpFile, autoMute;
77 77
78 bool eventFilter( QObject * , QEvent * ); 78 bool eventFilter( QObject * , QEvent * );
@@ -98,13 +98,14 @@ private:
98 98
99private slots: 99private slots:
100 100
101
102 void FastforwardPressed(); 101 void FastforwardPressed();
103 void FastforwardReleased(); 102 void FastforwardReleased();
104 void changeDirCombo(int); 103 void changeDirCombo(int);
105 void changeSizeLimitCombo(int); 104 void changeSizeLimitCombo(int);
106 void changeTimeSlider(int); 105 void changeTimeSlider(int);
107 void changebitrateCombo(int); 106 void changebitrateCombo(int);
107 void changeStereoCheck( bool);
108
108 void changedInVolume(); 109 void changedInVolume();
109 void changedOutVolume(); 110 void changedOutVolume();
110 void changesamplerateCombo(int); 111 void changesamplerateCombo(int);
@@ -134,11 +135,9 @@ private slots:
134 135
135protected: 136protected:
136 137
137 Device *soundDevice;
138 WavFile *wavFile; 138 WavFile *wavFile;
139
140 QButtonGroup *ButtonGroup1; 139 QButtonGroup *ButtonGroup1;
141 QCheckBox *outMuteCheckBox, *inMuteCheckBox, *compressionCheckBox, *autoMuteCheckBox; 140 QCheckBox *outMuteCheckBox, *inMuteCheckBox, *compressionCheckBox, *autoMuteCheckBox, *stereoCheckBox;
142 QComboBox* sampleRateComboBox, * bitRateComboBox, *directoryComboBox, *sizeLimitCombo; 141 QComboBox* sampleRateComboBox, * bitRateComboBox, *directoryComboBox, *sizeLimitCombo;
143 QHBoxLayout* Layout12; 142 QHBoxLayout* Layout12;
144 QHBoxLayout* Layout13; 143 QHBoxLayout* Layout13;
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp
index b177c91..987fa32 100644
--- a/noncore/multimedia/opierec/wavFile.cpp
+++ b/noncore/multimedia/opierec/wavFile.cpp
@@ -149,8 +149,8 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) {
149 strncpy((*hdr).dataID, "data", 4); 149 strncpy((*hdr).dataID, "data", 4);
150 150
151 write( fd,hdr, sizeof(*hdr)); 151 write( fd,hdr, sizeof(*hdr));
152// qDebug("writing header: bitrate%d, samplerate %d, channels %d", 152 qDebug("writing header: bitrate%d, samplerate %d, channels %d",
153// wavResolution, wavSampleRate, wavChannels); 153 wavResolution, wavSampleRate, wavChannels);
154 return true; 154 return true;
155} 155}
156 156
@@ -160,12 +160,12 @@ bool WavFile::adjustHeaders(int fd, int total) {
160 write( fd, &i, sizeof(i)); 160 write( fd, &i, sizeof(i));
161 lseek( fd, 40, SEEK_SET); 161 lseek( fd, 40, SEEK_SET);
162 write( fd, &total, sizeof(total)); 162 write( fd, &total, sizeof(total));
163// qDebug("adjusting header %d", total); 163 qDebug("adjusting header %d", total);
164 return true; 164 return true;
165} 165}
166 166
167int WavFile::parseWavHeader(int fd) { 167int WavFile::parseWavHeader(int fd) {
168// qDebug("Parsing wav header"); 168 qDebug("Parsing wav header");
169 char string[4]; 169 char string[4];
170 int found; 170 int found;
171 short fmt; 171 short fmt;
@@ -304,3 +304,8 @@ return wavNumberSamples;
304bool WavFile::isTempFile() { 304bool WavFile::isTempFile() {
305return useTmpFile; 305return useTmpFile;
306} 306}
307
308int WavFile::getChannels() {
309
310 return wavChannels;
311}
diff --git a/noncore/multimedia/opierec/wavFile.h b/noncore/multimedia/opierec/wavFile.h
index b70c09d..e18cfce 100644
--- a/noncore/multimedia/opierec/wavFile.h
+++ b/noncore/multimedia/opierec/wavFile.h
@@ -41,6 +41,7 @@ public:
41 int getResolution(); 41 int getResolution();
42 int getSampleRate(); 42 int getSampleRate();
43 int getNumberSamples(); 43 int getNumberSamples();
44 int getChannels();
44 bool isTempFile(); 45 bool isTempFile();
45 int openFile(const QString &); 46 int openFile(const QString &);
46 bool newFile(); 47 bool newFile();