author | llornkcor <llornkcor> | 2005-03-12 01:54:52 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-03-12 01:54:52 (UTC) |
commit | 84af289057291a49a52a60b390bc5320c02b5a55 (patch) (unidiff) | |
tree | 523f2d36240efd4f500bfbc35996771bebd7360d | |
parent | 6b67c3b2685b2d3f1bc7a787216aa769d4ea257a (diff) | |
download | opie-84af289057291a49a52a60b390bc5320c02b5a55.zip opie-84af289057291a49a52a60b390bc5320c02b5a55.tar.gz opie-84af289057291a49a52a60b390bc5320c02b5a55.tar.bz2 |
fix irregularity with adpcm and bits
-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 16 | ||||
-rw-r--r-- | noncore/multimedia/opierec/opierec.pro | 1 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 123 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 62 |
4 files changed, 105 insertions, 97 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index e7e0f4b..a76665e 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -1,276 +1,280 @@ | |||
1 | // device.cpp | 1 | // device.cpp |
2 | 2 | ||
3 | #include "device.h" | 3 | #include "device.h" |
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 | 7 | ||
8 | #include <opie2/odebug.h> | 8 | #include <opie2/odebug.h> |
9 | 9 | ||
10 | /* STD */ | 10 | /* STD */ |
11 | #include <fcntl.h> | 11 | #include <fcntl.h> |
12 | #include <stdio.h> | 12 | #include <stdio.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | #include <sys/ioctl.h> | 14 | #include <sys/ioctl.h> |
15 | #include <sys/soundcard.h> | 15 | #include <sys/soundcard.h> |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <sys/wait.h> | 17 | #include <sys/wait.h> |
18 | #include <unistd.h> | 18 | #include <unistd.h> |
19 | #include <errno.h> | 19 | #include <errno.h> |
20 | 20 | ||
21 | //extern QtRec *qperec; | 21 | //extern QtRec *qperec; |
22 | #if defined(QT_QWS_SL5XXX) | 22 | #if defined(QT_QWS_SL5XXX) |
23 | ///#if defined(QT_QWS_EBX) | 23 | ///#if defined(QT_QWS_EBX) |
24 | 24 | ||
25 | #define DSPSTROUT "/dev/dsp" | 25 | #define DSPSTROUT "/dev/dsp" |
26 | #define DSPSTRMIXEROUT "/dev/mixer" | 26 | #define DSPSTRMIXEROUT "/dev/mixer" |
27 | 27 | ||
28 | #ifdef SHARP | 28 | #ifdef SHARP |
29 | #define DSPSTRIN "/dev/dsp1" | 29 | #define DSPSTRIN "/dev/dsp1" |
30 | #define DSPSTRMIXERIN "/dev/mixer1" | 30 | #define DSPSTRMIXERIN "/dev/mixer1" |
31 | #else | 31 | #else |
32 | #define DSPSTRIN "/dev/dsp" | 32 | #define DSPSTRIN "/dev/dsp" |
33 | #define DSPSTRMIXERIN "/dev/mixer" | 33 | #define DSPSTRMIXERIN "/dev/mixer" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #else | 36 | #else |
37 | 37 | ||
38 | #ifdef QT_QWS_DEVFS | 38 | #ifdef QT_QWS_DEVFS |
39 | #define DSPSTROUT "/dev/sound/dsp" | 39 | #define DSPSTROUT "/dev/sound/dsp" |
40 | #define DSPSTRIN "/dev/sound/dsp" | 40 | #define DSPSTRIN "/dev/sound/dsp" |
41 | #define DSPSTRMIXERIN "/dev/sound/mixer" | 41 | #define DSPSTRMIXERIN "/dev/sound/mixer" |
42 | #define DSPSTRMIXEROUT "/dev/sound/mixer" | 42 | #define DSPSTRMIXEROUT "/dev/sound/mixer" |
43 | #else | 43 | #else |
44 | #define DSPSTROUT "/dev/dsp" | 44 | #define DSPSTROUT "/dev/dsp" |
45 | #define DSPSTRIN "/dev/dsp" | 45 | #define DSPSTRIN "/dev/dsp" |
46 | #define DSPSTRMIXERIN "/dev/mixer" | 46 | #define DSPSTRMIXERIN "/dev/mixer" |
47 | #define DSPSTRMIXEROUT "/dev/mixer" | 47 | #define DSPSTRMIXEROUT "/dev/mixer" |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | Device::Device( QObject * parent, bool record ) | 52 | Device::Device( QObject * parent, bool record ) |
53 | : QObject( parent) | 53 | : QObject( parent) |
54 | { | 54 | { |
55 | // dspstr = dsp; | 55 | // dspstr = dsp; |
56 | devForm = -1; | 56 | devForm = -1; |
57 | devCh = -1; | 57 | devCh = -1; |
58 | devRate = -1; | 58 | devRate = -1; |
59 | 59 | ||
60 | if( !record){ //playing | 60 | if( !record){ //playing |
61 | owarn << "setting up DSP for playing" << oendl; | 61 | owarn << "New Sound device DSP for playing" << oendl; |
62 | flags = O_WRONLY; | 62 | flags = O_RDWR; |
63 | // flags = O_WRONLY; | ||
63 | } else { //recording | 64 | } else { //recording |
64 | owarn << "setting up DSP for recording" << oendl; | 65 | owarn << "New Sound device DSP for recording" << oendl; |
65 | flags = O_RDWR; | 66 | flags = O_RDWR; |
66 | // flags = O_RDONLY; | 67 | // flags = O_RDONLY; |
67 | selectMicInput(); | 68 | selectMicInput(); |
68 | } | 69 | } |
69 | } | 70 | } |
70 | 71 | ||
71 | bool Device::openDsp() { | 72 | bool Device::openDsp() { |
73 | qWarning("Device::openDsp()"); | ||
72 | if( openDevice( flags) == -1) { | 74 | if( openDevice( flags) == -1) { |
73 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | 75 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); |
74 | return false; | 76 | return false; |
75 | } | 77 | } |
76 | return true; | 78 | return true; |
77 | } | 79 | } |
78 | 80 | ||
79 | int Device::openDevice( int flags) { | 81 | int Device::openDevice( int flags) { |
80 | owarn << "Opening"<< dspstr; | 82 | owarn << "Opening sound device:"<< DSPSTROUT << oendl; |
81 | 83 | ||
82 | if (( sd = ::open( DSPSTROUT, flags)) == -1) { | 84 | if (( sd = ::open( DSPSTROUT, O_RDWR)) == -1) { |
83 | perror("open(\"/dev/dsp\")"); | 85 | perror("open(\"/dev/dsp\")\n"); |
84 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 86 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
85 | +(QString)strerror(errno); | 87 | +(QString)strerror(errno); |
86 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | 88 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); |
87 | return -1; | 89 | return -1; |
88 | } | 90 | } |
89 | 91 | ||
90 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | 92 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ |
91 | perror("ioctl RESET"); | 93 | perror("ioctl RESET"); |
92 | } | 94 | } |
95 | qWarning("opened!"); | ||
93 | return sd; | 96 | return sd; |
94 | } | 97 | } |
95 | 98 | ||
96 | int Device::getInVolume() { | 99 | int Device::getInVolume() { |
97 | unsigned int volume = 0; | 100 | unsigned int volume = 0; |
98 | Config cfg("qpe"); | 101 | Config cfg("qpe"); |
99 | cfg.setGroup("Volume"); | 102 | cfg.setGroup("Volume"); |
100 | 103 | ||
101 | return cfg.readNumEntry("Mic"); | 104 | return cfg.readNumEntry("Mic"); |
102 | } | 105 | } |
103 | 106 | ||
104 | int Device::getOutVolume( ) { | 107 | int Device::getOutVolume( ) { |
105 | unsigned int volume; | 108 | unsigned int volume; |
106 | Config cfg("qpe"); | 109 | Config cfg("qpe"); |
107 | cfg.setGroup("Volume"); | 110 | cfg.setGroup("Volume"); |
108 | 111 | ||
109 | return cfg.readNumEntry("VolumePercent"); | 112 | return cfg.readNumEntry("VolumePercent"); |
110 | } | 113 | } |
111 | 114 | ||
112 | 115 | ||
113 | void Device::changedInVolume(int vol ) { | 116 | void Device::changedInVolume(int vol ) { |
114 | Config cfg("qpe"); | 117 | Config cfg("qpe"); |
115 | cfg.setGroup("Volume"); | 118 | cfg.setGroup("Volume"); |
116 | cfg.writeEntry("Mic", QString::number(vol )); | 119 | cfg.writeEntry("Mic", QString::number(vol )); |
117 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | 120 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; |
118 | } | 121 | } |
119 | 122 | ||
120 | void Device::changedOutVolume(int vol) { | 123 | void Device::changedOutVolume(int vol) { |
121 | Config cfg("qpe"); | 124 | Config cfg("qpe"); |
122 | cfg.setGroup("Volume"); | 125 | cfg.setGroup("Volume"); |
123 | cfg.writeEntry("VolumePercent", QString::number( vol )); | 126 | cfg.writeEntry("VolumePercent", QString::number( vol )); |
124 | 127 | ||
125 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; | 128 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; |
126 | 129 | ||
127 | owarn << "changing output vol " << vol << oendl; | 130 | owarn << "changing output vol " << vol << oendl; |
128 | } | 131 | } |
129 | 132 | ||
130 | bool Device::selectMicInput() { | 133 | bool Device::selectMicInput() { |
131 | 134 | ||
132 | int md = 0; | 135 | int md = 0; |
133 | int info = SOUND_MASK_MIC;//MIXER_WRITE(SOUND_MIXER_MIC); | 136 | int info = SOUND_MASK_MIC;//MIXER_WRITE(SOUND_MIXER_MIC); |
134 | owarn << "sectMicInput" << oendl; | 137 | owarn << "sectMicInput" << oendl; |
135 | md = ::open( DSPSTRMIXEROUT, O_RDWR ); | 138 | md = ::open( DSPSTRMIXEROUT, O_RDWR ); |
136 | 139 | ||
137 | if ( md <= 0) { | 140 | if ( md <= 0) { |
138 | QString err; | 141 | QString err; |
139 | err.sprintf("open %s", DSPSTRMIXEROUT); | 142 | err.sprintf("open %s", DSPSTRMIXEROUT); |
140 | perror(err.latin1()); | 143 | perror(err.latin1()); |
141 | } else { | 144 | } else { |
142 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 145 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
143 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 146 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
144 | ::close(md); | 147 | ::close(md); |
145 | return false; | 148 | return false; |
146 | } | 149 | } |
147 | ::close(md); | 150 | ::close(md); |
148 | 151 | ||
149 | return true; | 152 | return true; |
150 | } | 153 | } |
151 | 154 | ||
152 | bool Device::closeDevice( bool) { | 155 | bool Device::closeDevice( bool) { |
156 | if(sd) | ||
153 | ::close( sd); //close sound device | 157 | ::close( sd); //close sound device |
154 | return true; | 158 | return true; |
155 | } | 159 | } |
156 | 160 | ||
157 | bool Device::setDeviceFormat( int form) { | 161 | bool Device::setDeviceFormat( int form) { |
158 | qDebug( "set device res %d: %d ",form, sd ); | 162 | qDebug( "set device res %d: %d ",form, sd ); |
159 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | 163 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format |
160 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 164 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
161 | return false; | 165 | return false; |
162 | } | 166 | } |
163 | devRes=form; | 167 | devRes=form; |
164 | return true; | 168 | return true; |
165 | } | 169 | } |
166 | 170 | ||
167 | bool Device::setDeviceChannels( int ch) { | 171 | bool Device::setDeviceChannels( int ch) { |
168 | qDebug( "set channels %d: %d",ch ,sd); | 172 | qDebug( "set channels %d: %d",ch ,sd); |
169 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { | 173 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { |
170 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 174 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
171 | return false; | 175 | return false; |
172 | } | 176 | } |
173 | devCh=ch; | 177 | devCh=ch; |
174 | return true; | 178 | return true; |
175 | } | 179 | } |
176 | 180 | ||
177 | bool Device::setDeviceRate( int rate) { | 181 | bool Device::setDeviceRate( int rate) { |
178 | qDebug( "set rate %d: %d",rate,sd); | 182 | qDebug( "set rate %d: %d",rate,sd); |
179 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { | 183 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { |
180 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 184 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
181 | return false; | 185 | return false; |
182 | } | 186 | } |
183 | 187 | ||
184 | devRate=rate; | 188 | devRate=rate; |
185 | 189 | ||
186 | return true; | 190 | return true; |
187 | } | 191 | } |
188 | 192 | ||
189 | int Device::getRes() { | 193 | int Device::getRes() { |
190 | return devRes; | 194 | return devRes; |
191 | } | 195 | } |
192 | 196 | ||
193 | int Device::getFormat() { | 197 | int Device::getFormat() { |
194 | return devForm; | 198 | return devForm; |
195 | } | 199 | } |
196 | 200 | ||
197 | int Device::getRate() { | 201 | int Device::getRate() { |
198 | return devRate; | 202 | return devRate; |
199 | } | 203 | } |
200 | 204 | ||
201 | int Device::getChannels() { | 205 | int Device::getChannels() { |
202 | return devCh; | 206 | return devCh; |
203 | } | 207 | } |
204 | 208 | ||
205 | int Device::getDeviceFormat() { | 209 | int Device::getDeviceFormat() { |
206 | return 0; | 210 | return 0; |
207 | } | 211 | } |
208 | 212 | ||
209 | 213 | ||
210 | int Device::getDeviceRate() { | 214 | int Device::getDeviceRate() { |
211 | int dRate = 0; | 215 | int dRate = 0; |
212 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { | 216 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { |
213 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); | 217 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); |
214 | } | 218 | } |
215 | return dRate; | 219 | return dRate; |
216 | 220 | ||
217 | } | 221 | } |
218 | 222 | ||
219 | int Device::getDeviceBits() { | 223 | int Device::getDeviceBits() { |
220 | int dBits = 0; | 224 | int dBits = 0; |
221 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { | 225 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { |
222 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | 226 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); |
223 | } | 227 | } |
224 | return dBits; | 228 | return dBits; |
225 | } | 229 | } |
226 | 230 | ||
227 | int Device::getDeviceChannels() { | 231 | int Device::getDeviceChannels() { |
228 | int dCh = 0; | 232 | int dCh = 0; |
229 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | 233 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { |
230 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | 234 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); |
231 | } | 235 | } |
232 | return dCh; | 236 | return dCh; |
233 | } | 237 | } |
234 | 238 | ||
235 | int Device::getDeviceFragSize() { | 239 | int Device::getDeviceFragSize() { |
236 | int frag_size; | 240 | int frag_size; |
237 | 241 | ||
238 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { | 242 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { |
239 | qDebug( "no fragsize" ); | 243 | qDebug( "no fragsize" ); |
240 | } else { | 244 | } else { |
241 | qDebug( "driver says frag size is %d",frag_size); | 245 | qDebug( "driver says frag size is %d",frag_size); |
242 | } | 246 | } |
243 | return frag_size; | 247 | return frag_size; |
244 | } | 248 | } |
245 | 249 | ||
246 | bool Device::setFragSize(int frag) { | 250 | bool Device::setFragSize(int frag) { |
247 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | 251 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { |
248 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 252 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
249 | return false; | 253 | return false; |
250 | } | 254 | } |
251 | return true; | 255 | return true; |
252 | } | 256 | } |
253 | 257 | ||
254 | bool Device::reset() { | 258 | bool Device::reset() { |
255 | closeDevice(true); | 259 | closeDevice(true); |
256 | openDsp(); | 260 | openDsp(); |
257 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 261 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
258 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 262 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
259 | return false; | 263 | return false; |
260 | } | 264 | } |
261 | return true; | 265 | return true; |
262 | } | 266 | } |
263 | 267 | ||
264 | int Device::devRead(int soundDescriptor, short *buf, int size) { | 268 | int Device::devRead(int soundDescriptor, short *buf, int size) { |
265 | Q_UNUSED(soundDescriptor); | 269 | Q_UNUSED(soundDescriptor); |
266 | int number = 0; | 270 | int number = 0; |
267 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); | 271 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); |
268 | return number; | 272 | return number; |
269 | } | 273 | } |
270 | 274 | ||
271 | int Device::devWrite(int soundDescriptor, short * buf, int size) { | 275 | int Device::devWrite(int soundDescriptor, short * buf, int size) { |
272 | Q_UNUSED(soundDescriptor); | 276 | Q_UNUSED(soundDescriptor); |
273 | int bytesWritten = 0; | 277 | int bytesWritten = 0; |
274 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); | 278 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); |
275 | return bytesWritten; | 279 | return bytesWritten; |
276 | } | 280 | } |
diff --git a/noncore/multimedia/opierec/opierec.pro b/noncore/multimedia/opierec/opierec.pro index 6a5838a..6008bf7 100644 --- a/noncore/multimedia/opierec/opierec.pro +++ b/noncore/multimedia/opierec/opierec.pro | |||
@@ -1,38 +1,39 @@ | |||
1 | CONFIG = qt quick-app | 1 | CONFIG = qt quick-app |
2 | HEADERS = adpcm.h \ | 2 | HEADERS = adpcm.h \ |
3 | pixmaps.h \ | 3 | pixmaps.h \ |
4 | helpwindow.h \ | 4 | helpwindow.h \ |
5 | qtrec.h \ | 5 | qtrec.h \ |
6 | device.h \ | 6 | device.h \ |
7 | wavFile.h \ | 7 | wavFile.h \ |
8 | waveform.h | 8 | waveform.h |
9 | SOURCES = adpcm.c \ | 9 | SOURCES = adpcm.c \ |
10 | helpwindow.cpp \ | 10 | helpwindow.cpp \ |
11 | main.cpp \ | 11 | main.cpp \ |
12 | qtrec.cpp \ | 12 | qtrec.cpp \ |
13 | device.cpp \ | 13 | device.cpp \ |
14 | wavFile.cpp \ | 14 | wavFile.cpp \ |
15 | waveform.cpp | 15 | waveform.cpp |
16 | INTERFACES = | 16 | INTERFACES = |
17 | 17 | ||
18 | contains(CONFIG, pdaudio) { | 18 | contains(CONFIG, pdaudio) { |
19 | # LIBS += -L/opt/buildroot-opie/output/staging/target/lib -lqpe -lpthread -ljpeg -lpng -lz | 19 | # LIBS += -L/opt/buildroot-opie/output/staging/target/lib -lqpe -lpthread -ljpeg -lpng -lz |
20 | LIBS += -L$(QPEDIR)/lib -lqpe -lpthread -ljpeg -lpng -lz -lopiecore2 | 20 | LIBS += -L$(QPEDIR)/lib -lqpe -lpthread -ljpeg -lpng -lz -lopiecore2 |
21 | INCLUDEPATH += $(QPEDIR)/include | 21 | INCLUDEPATH += $(QPEDIR)/include |
22 | DEPENDPATH += $(QPEDIR)/include | 22 | DEPENDPATH += $(QPEDIR)/include |
23 | DEFINES += PDAUDIO | 23 | DEFINES += PDAUDIO |
24 | DEFINES += THREADED | 24 | DEFINES += THREADED |
25 | TARGET = qperec | 25 | TARGET = qperec |
26 | 26 | ||
27 | # DESTDIR=$(QPEDIR)/bin | 27 | # DESTDIR=$(QPEDIR)/bin |
28 | } | 28 | } |
29 | 29 | ||
30 | !contains(CONFIG, pdaudio) { | 30 | !contains(CONFIG, pdaudio) { |
31 | INCLUDEPATH += $(OPIEDIR)/include | 31 | INCLUDEPATH += $(OPIEDIR)/include |
32 | DEPENDPATH += $(OPIEDIR)/include | 32 | DEPENDPATH += $(OPIEDIR)/include |
33 | LIBS += -lqpe -lopiecore2 -lpthread | 33 | LIBS += -lqpe -lopiecore2 -lpthread |
34 | DEFINES += THREADED | ||
34 | TARGET = opierec | 35 | TARGET = opierec |
35 | include( $(OPIEDIR)/include.pro ) | 36 | include( $(OPIEDIR)/include.pro ) |
36 | } | 37 | } |
37 | 38 | ||
38 | 39 | ||
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index e827083..9b761aa 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -1,563 +1,565 @@ | |||
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 | //#define DEV_VERSION | 6 | //#define DEV_VERSION |
7 | 7 | ||
8 | #include "pixmaps.h" | 8 | #include "pixmaps.h" |
9 | #include "qtrec.h" | 9 | #include "qtrec.h" |
10 | #include "waveform.h" | 10 | #include "waveform.h" |
11 | extern "C" { | 11 | extern "C" { |
12 | #include "adpcm.h" | 12 | #include "adpcm.h" |
13 | } | 13 | } |
14 | 14 | ||
15 | /* OPIE */ | 15 | /* OPIE */ |
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/storage.h> | 21 | #include <qpe/storage.h> |
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | 23 | ||
24 | /* QT */ | 24 | /* QT */ |
25 | #include <qcheckbox.h> | 25 | #include <qcheckbox.h> |
26 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include <qgroupbox.h> | 28 | #include <qgroupbox.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qlayout.h> | 30 | #include <qlayout.h> |
31 | #include <qlistview.h> | 31 | #include <qlistview.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qpopupmenu.h> | 33 | #include <qpopupmenu.h> |
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qslider.h> | 35 | #include <qslider.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | /* STD */ | 39 | /* STD */ |
40 | #include <errno.h> | 40 | #include <errno.h> |
41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
42 | #include <math.h> | 42 | #include <math.h> |
43 | #include <mntent.h> | 43 | #include <mntent.h> |
44 | #include <stdio.h> | 44 | #include <stdio.h> |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <sys/ioctl.h> | 46 | #include <sys/ioctl.h> |
47 | #include <sys/soundcard.h> | 47 | #include <sys/soundcard.h> |
48 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
49 | #include <sys/time.h> | 49 | #include <sys/time.h> |
50 | #include <sys/types.h> | 50 | #include <sys/types.h> |
51 | #include <sys/vfs.h> | 51 | #include <sys/vfs.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <sys/wait.h> | 53 | #include <sys/wait.h> |
54 | #include <sys/signal.h> | 54 | #include <sys/signal.h> |
55 | #include <pthread.h> | 55 | #include <pthread.h> |
56 | 56 | ||
57 | #ifdef PDAUDIO //ALSA | 57 | #ifdef PDAUDIO //ALSA |
58 | #include <alsa/asoundlib.h> | 58 | #include <alsa/asoundlib.h> |
59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; | 59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; |
60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; | 60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; |
61 | #else //OSS | 61 | #else //OSS |
62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; | 62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; |
63 | static int deviceBitRates[] = { 8, 16, -1 }; | 63 | static int deviceBitRates[] = { 8, 16, -1 }; |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | 66 | ||
67 | //#define ZAURUS 0 | 67 | //#define ZAURUS 0 |
68 | struct adpcm_state encoder_state; | 68 | struct adpcm_state encoder_state; |
69 | struct adpcm_state decoder_state; | 69 | struct adpcm_state decoder_state; |
70 | 70 | ||
71 | typedef struct { | 71 | typedef struct { |
72 | int sampleRate; | 72 | int sampleRate; |
73 | /* int fragSize; */ | 73 | /* int fragSize; */ |
74 | /* int blockSize; */ | 74 | /* int blockSize; */ |
75 | int resolution; //bitrate | 75 | int resolution; //bitrate |
76 | int channels; //number of channels | 76 | int channels; //number of channels |
77 | int fd; //file descriptor | 77 | int fd; //file descriptor |
78 | int sd; //sound device descriptor | 78 | int sd; //sound device descriptor |
79 | int numberSamples; //total number of samples | 79 | int numberSamples; //total number of samples |
80 | int SecondsToRecord; // number of seconds that should be recorded | 80 | int SecondsToRecord; // number of seconds that should be recorded |
81 | float numberOfRecordedSeconds; //total number of samples recorded | 81 | float numberOfRecordedSeconds; //total number of samples recorded |
82 | int samplesToRecord; //number of samples to be recorded | 82 | int samplesToRecord; //number of samples to be recorded |
83 | int inVol; //input volume | 83 | int inVol; //input volume |
84 | int outVol; //output volume | 84 | int outVol; //output volume |
85 | int format; //wavfile format PCM.. ADPCM | 85 | int format; //wavfile format PCM.. ADPCM |
86 | const char *fileName; //name of fiel to be played/recorded | 86 | const char *fileName; //name of fiel to be played/recorded |
87 | } fileParameters; | 87 | } fileParameters; |
88 | 88 | ||
89 | fileParameters filePara; | 89 | fileParameters filePara; |
90 | 90 | ||
91 | bool monitoring, recording, playing; | 91 | bool monitoring, recording, playing; |
92 | bool stopped; | 92 | bool stopped; |
93 | QLabel *timeLabel; | 93 | QLabel *timeLabel; |
94 | QSlider *timeSlider; | 94 | QSlider *timeSlider; |
95 | int sd; | 95 | int sd; |
96 | 96 | ||
97 | Waveform* waveform; | 97 | Waveform* waveform; |
98 | Device *soundDevice; | 98 | Device *soundDevice; |
99 | 99 | ||
100 | 100 | ||
101 | #ifdef THREADED | 101 | #ifdef THREADED |
102 | void quickRec() | 102 | void quickRec() |
103 | #else | 103 | #else |
104 | void QtRec::quickRec() | 104 | void QtRec::quickRec() |
105 | #endif | 105 | #endif |
106 | { | 106 | { |
107 | 107 | ||
108 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; | 108 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; |
109 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate | 109 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate |
110 | << ", channels " << filePara.channels << oendl; | 110 | << ", channels " << filePara.channels << oendl; |
111 | 111 | ||
112 | int total = 0; // Total number of bytes read in so far. | 112 | int total = 0; // Total number of bytes read in so far. |
113 | int bytesWritten, number; | 113 | int bytesWritten, number; |
114 | 114 | ||
115 | bytesWritten = 0; | 115 | bytesWritten = 0; |
116 | number = 0; | 116 | number = 0; |
117 | QString num; | 117 | QString num; |
118 | int level = 0; | 118 | int level = 0; |
119 | int threshold = 0; | 119 | int threshold = 0; |
120 | int bits = filePara.resolution; | 120 | int bits = filePara.resolution; |
121 | odebug << "bits " << bits << "" << oendl; | 121 | odebug << "bits " << bits << "" << oendl; |
122 | 122 | ||
123 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | 123 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) |
124 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; | 124 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; |
125 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; | 125 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; |
126 | odebug << "" << filePara.sd << "" << oendl; | 126 | odebug << "" << filePara.sd << "" << oendl; |
127 | level = 7; | 127 | level = 7; |
128 | threshold = 0; | 128 | threshold = 0; |
129 | 129 | ||
130 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 130 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
131 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; | 131 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; |
132 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 132 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
133 | char abuf[ BUFSIZE/2 ]; | 133 | char abuf[ BUFSIZE/2 ]; |
134 | short sbuf[ BUFSIZE ]; | 134 | short sbuf[ BUFSIZE ]; |
135 | short sbuf2[ BUFSIZE ]; | 135 | short sbuf2[ BUFSIZE ]; |
136 | memset( abuf, 0, BUFSIZE/2); | 136 | memset( abuf, 0, BUFSIZE/2); |
137 | memset( sbuf, 0, BUFSIZE); | 137 | memset( sbuf, 0, BUFSIZE); |
138 | memset( sbuf2, 0, BUFSIZE); | 138 | memset( sbuf2, 0, BUFSIZE); |
139 | 139 | ||
140 | for(;;) { | 140 | for(;;) { |
141 | if ( stopped) { | 141 | if ( stopped) { |
142 | odebug << "quickRec:: stopped" << oendl; | 142 | odebug << "quickRec:: stopped" << oendl; |
143 | break; | 143 | break; |
144 | } | 144 | } |
145 | 145 | ||
146 | // number=::read( filePara.sd, sbuf, BUFSIZE); | 146 | // number=::read( filePara.sd, sbuf, BUFSIZE); |
147 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); | 147 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); |
148 | 148 | ||
149 | if(number <= 0) { | 149 | if(number <= 0) { |
150 | perror("recording error "); | 150 | perror("recording error "); |
151 | odebug << "" << filePara.fileName << " " << number << "" << oendl; | 151 | odebug << "" << filePara.fileName << " " << number << "" << oendl; |
152 | stopped = true; | 152 | stopped = true; |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | //if(stereo == 2) { | 155 | //if(stereo == 2) { |
156 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 156 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
157 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 157 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
158 | 158 | ||
159 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | 159 | bytesWritten = ::write( filePara.fd , abuf, number/4); |
160 | 160 | ||
161 | waveform->newSamples( sbuf, number ); | 161 | waveform->newSamples( sbuf, number ); |
162 | 162 | ||
163 | total += bytesWritten; | 163 | total += bytesWritten; |
164 | filePara.numberSamples = total; | 164 | filePara.numberSamples = total; |
165 | timeSlider->setValue( total); | 165 | timeSlider->setValue( total); |
166 | 166 | ||
167 | printf("%d, bytes %d,total %d\r", number, bytesWritten, total); | 167 | printf("%d, bytes %d,total %d\r", number, bytesWritten, total); |
168 | fflush(stdout); | 168 | fflush(stdout); |
169 | 169 | ||
170 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; | 170 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2;/// filePara.channels; |
171 | 171 | ||
172 | qApp->processEvents(); | 172 | qApp->processEvents(); |
173 | if( total >= filePara.samplesToRecord) { | 173 | if( total >= filePara.samplesToRecord) { |
174 | stopped = true; | 174 | stopped = true; |
175 | break; | 175 | break; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 179 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
180 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; | 180 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; |
181 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 181 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
182 | memset( inbuffer, 0, BUFSIZE); | 182 | memset( inbuffer, 0, BUFSIZE); |
183 | memset( outbuffer, 0, BUFSIZE); | 183 | memset( outbuffer, 0, BUFSIZE); |
184 | 184 | ||
185 | for(;;) { | 185 | for(;;) { |
186 | if ( stopped) { | 186 | if ( stopped) { |
187 | odebug << "quickRec:: stopped" << oendl; | 187 | odebug << "quickRec:: stopped" << oendl; |
188 | stopped = true; | 188 | stopped = true; |
189 | break; // stop if playing was set to false | 189 | break; // stop if playing was set to false |
190 | return; | 190 | return; |
191 | } | 191 | } |
192 | 192 | ||
193 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); | 193 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); |
194 | 194 | ||
195 | if( number <= 0) { | 195 | if( number <= 0) { |
196 | perror( "recording error "); | 196 | perror( "recording error "); |
197 | odebug << filePara.fileName << oendl; | 197 | odebug << filePara.fileName << oendl; |
198 | stopped = true; | 198 | stopped = true; |
199 | return; | 199 | return; |
200 | } | 200 | } |
201 | 201 | ||
202 | bytesWritten = ::write( filePara.fd , inbuffer, number); | 202 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
203 | waveform->newSamples( inbuffer, number ); | 203 | waveform->newSamples( inbuffer, number ); |
204 | 204 | ||
205 | if( bytesWritten < 0) { | 205 | if( bytesWritten < 0) { |
206 | perror("File writing error "); | 206 | perror("File writing error "); |
207 | stopped = true; | 207 | stopped = true; |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | 210 | ||
211 | total += bytesWritten; | 211 | total += bytesWritten; |
212 | 212 | ||
213 | filePara.numberSamples = total; | 213 | filePara.numberSamples = total; |
214 | 214 | ||
215 | if( filePara.SecondsToRecord != 0) | 215 | if( filePara.SecondsToRecord != 0) |
216 | timeSlider->setValue( total); | 216 | timeSlider->setValue( total); |
217 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); | 217 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); |
218 | fflush(stdout); | 218 | fflush(stdout); |
219 | 219 | ||
220 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate | 220 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate |
221 | / (float)2/filePara.channels; | 221 | / (float)2/filePara.channels; |
222 | qApp->processEvents(); | 222 | qApp->processEvents(); |
223 | 223 | ||
224 | if( total >= filePara.samplesToRecord) { | 224 | if( total >= filePara.samplesToRecord) { |
225 | stopped = true; | 225 | stopped = true; |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } //end main loop | 229 | } //end main loop |
230 | 230 | ||
231 | } else { | 231 | } else { |
232 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | 232 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; |
233 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; | 233 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; |
234 | memset( unsigned_inbuffer, 0, BUFSIZE); | 234 | memset( unsigned_inbuffer, 0, BUFSIZE); |
235 | memset( unsigned_outbuffer, 0, BUFSIZE); | 235 | memset( unsigned_outbuffer, 0, BUFSIZE); |
236 | 236 | ||
237 | for(;;) { | 237 | for(;;) { |
238 | if ( stopped) { | 238 | if ( stopped) { |
239 | odebug << "quickRec:: stopped" << oendl; | 239 | odebug << "quickRec:: stopped" << oendl; |
240 | break; // stop if playing was set to false | 240 | break; // stop if playing was set to false |
241 | } | 241 | } |
242 | 242 | ||
243 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); | 243 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); |
244 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); | 244 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); |
245 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); | 245 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); |
246 | 246 | ||
247 | if(bytesWritten < 0) { | 247 | if(bytesWritten < 0) { |
248 | stopped = true; | 248 | stopped = true; |
249 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); | 249 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); |
250 | perror("File writing error "); | 250 | perror("File writing error "); |
251 | return; | 251 | return; |
252 | } | 252 | } |
253 | 253 | ||
254 | total += bytesWritten; | 254 | total += bytesWritten; |
255 | filePara.numberSamples = total; | 255 | filePara.numberSamples = total; |
256 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); | 256 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); |
257 | // fflush(stdout); | 257 | // fflush(stdout); |
258 | if( filePara.SecondsToRecord !=0) | 258 | if( filePara.SecondsToRecord !=0) |
259 | timeSlider->setValue( total); | 259 | timeSlider->setValue( total); |
260 | 260 | ||
261 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 261 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
262 | 262 | ||
263 | qApp->processEvents(); | 263 | qApp->processEvents(); |
264 | if( total >= filePara.samplesToRecord) { | 264 | if( total >= filePara.samplesToRecord) { |
265 | stopped = true; | 265 | stopped = true; |
266 | break; | 266 | break; |
267 | } | 267 | } |
268 | } //end main loop | 268 | } //end main loop |
269 | } | 269 | } |
270 | printf("\n"); | 270 | printf("\n"); |
271 | } /// END quickRec() | 271 | } /// END quickRec() |
272 | 272 | ||
273 | 273 | ||
274 | #ifdef THREADED | 274 | #ifdef THREADED |
275 | void playIt() | 275 | void playIt() |
276 | #else | 276 | #else |
277 | void QtRec::playIt() | 277 | void QtRec::playIt() |
278 | #endif | 278 | #endif |
279 | { | 279 | { |
280 | int bytesWritten = 0; | 280 | int bytesWritten = 0; |
281 | int number = 0; | 281 | int number = 0; |
282 | int total = 0; // Total number of bytes read in so far. | 282 | int total = 0; // Total number of bytes read in so far. |
283 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { | 283 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { |
284 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 284 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
285 | char abuf[ BUFSIZE / 2 ]; | 285 | char abuf[ BUFSIZE / 2 ]; |
286 | short sbuf[ BUFSIZE ]; | 286 | short sbuf[ BUFSIZE ]; |
287 | short sbuf2[ BUFSIZE * 2 ]; | 287 | short sbuf2[ BUFSIZE * 2 ]; |
288 | memset( abuf, 0, BUFSIZE / 2); | 288 | memset( abuf, 0, BUFSIZE / 2); |
289 | memset( sbuf, 0, BUFSIZE); | 289 | memset( sbuf, 0, BUFSIZE); |
290 | memset( sbuf2, 0, BUFSIZE * 2); | 290 | memset( sbuf2, 0, BUFSIZE * 2); |
291 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 291 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
292 | for(;;) { // play loop | 292 | for(;;) { // play loop |
293 | if ( stopped) { | 293 | if ( stopped) { |
294 | break; | 294 | break; |
295 | return; | 295 | return; |
296 | }// stop if playing was set to false | 296 | }// stop if playing was set to false |
297 | 297 | ||
298 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); | 298 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); |
299 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); | 299 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); |
300 | 300 | ||
301 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 301 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
302 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | 302 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; |
303 | // } | 303 | // } |
304 | bytesWritten = write ( filePara.sd, sbuf, number * 4); | 304 | bytesWritten = write ( soundDevice->sd , sbuf, number * 4); |
305 | waveform->newSamples( (const short *)sbuf, number *4); | 305 | |
306 | waveform->newSamples( sbuf, number ); | ||
307 | |||
306 | // if(filePara.channels==1) | 308 | // if(filePara.channels==1) |
307 | // total += bytesWritten/2; //mono | 309 | // total += bytesWritten/2; //mono |
308 | // else | 310 | // else |
309 | total += bytesWritten; | 311 | total += bytesWritten; |
310 | filePara.numberSamples = total/4; | 312 | filePara.numberSamples = total/4; |
311 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | 313 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; |
312 | 314 | ||
313 | timeSlider->setValue( total/4); | 315 | timeSlider->setValue( total/4); |
314 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 316 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
315 | // if(filePara.numberOfRecordedSeconds>1) | 317 | // if(filePara.numberOfRecordedSeconds>1) |
316 | // timeLabel->setText( timeString+ tr(" seconds")); | 318 | // timeLabel->setText( timeString+ tr(" seconds")); |
317 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | 319 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); |
318 | // fflush(stdout); | 320 | // fflush(stdout); |
319 | 321 | ||
320 | qApp->processEvents(); | 322 | qApp->processEvents(); |
321 | 323 | ||
322 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 324 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
323 | // if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) { | 325 | // if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) { |
324 | stopped = true; | 326 | stopped = true; |
325 | break; | 327 | break; |
326 | } | 328 | } |
327 | } | 329 | } |
328 | } else { | 330 | } else { |
329 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 331 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
330 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 332 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
331 | memset( inbuffer, 0, BUFSIZE); | 333 | memset( inbuffer, 0, BUFSIZE); |
332 | memset( outbuffer, 0, BUFSIZE); | 334 | memset( outbuffer, 0, BUFSIZE); |
333 | 335 | ||
334 | for(;;) { // play loop | 336 | for(;;) { // play loop |
335 | if ( stopped) { | 337 | if ( stopped) { |
336 | break; | 338 | break; |
337 | return; | 339 | return; |
338 | } | 340 | } |
339 | // stop if playing was set to false | 341 | // stop if playing was set to false |
340 | number = ::read( filePara.fd, inbuffer, BUFSIZE); | 342 | number = ::read( filePara.fd, inbuffer, BUFSIZE); |
341 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 343 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
342 | // // for (int i=0;i< number ; i++) { //2*i is left channel | 344 | // // for (int i=0;i< number ; i++) { //2*i is left channel |
343 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; | 345 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; |
344 | // } | 346 | // } |
345 | bytesWritten = ::write( filePara.sd, inbuffer, number); | 347 | bytesWritten = ::write( soundDevice->sd, inbuffer, number); |
346 | waveform->newSamples( inbuffer, number); | 348 | waveform->newSamples( inbuffer, number); |
347 | //-------------->>>> out to device | 349 | //-------------->>>> out to device |
348 | // total+=bytesWritten; | 350 | // total+=bytesWritten; |
349 | // if(filePara.channels==1) | 351 | // if(filePara.channels==1) |
350 | // total += bytesWritten/2; //mono | 352 | // total += bytesWritten/2; //mono |
351 | // else | 353 | // else |
352 | total += bytesWritten; | 354 | total += bytesWritten; |
353 | timeSlider->setValue( total); | 355 | timeSlider->setValue( total); |
354 | 356 | ||
355 | filePara.numberSamples = total; | 357 | filePara.numberSamples = total; |
356 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; | 358 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; |
357 | 359 | ||
358 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | 360 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); |
359 | // timeLabel->setText( timeString + tr(" seconds")); | 361 | // timeLabel->setText( timeString + tr(" seconds")); |
360 | 362 | ||
361 | qApp->processEvents(); | 363 | qApp->processEvents(); |
362 | 364 | ||
363 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 365 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
364 | owarn << "Jane! Stop this crazy thing!" << oendl; | 366 | owarn << "Jane! Stop this crazy thing!" << oendl; |
365 | stopped = true; | 367 | stopped = true; |
366 | // playing = false; | 368 | // playing = false; |
367 | break; | 369 | break; |
368 | } | 370 | } |
369 | } | 371 | } |
370 | // printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); | 372 | // printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); |
371 | // fflush(stdout); | 373 | // fflush(stdout); |
372 | } //end loop | 374 | } //end loop |
373 | } else { | 375 | } else { |
374 | /////////////////////////////// format = AFMT_U8; | 376 | /////////////////////////////// format = AFMT_U8; |
375 | unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; | 377 | unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; |
376 | memset( unsigned_inbuffer, 0, BUFSIZE); | 378 | memset( unsigned_inbuffer, 0, BUFSIZE); |
377 | for(;;) { | 379 | for(;;) { |
378 | // main loop | 380 | // main loop |
379 | if (stopped) { | 381 | if (stopped) { |
380 | break; // stop if playing was set to false | 382 | break; // stop if playing was set to false |
381 | return; | 383 | return; |
382 | } | 384 | } |
383 | number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); | 385 | number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); |
384 | //data = (val >> 8) ^ 0x80; | 386 | //data = (val >> 8) ^ 0x80; |
385 | // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; | 387 | // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; |
386 | bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); | 388 | bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); |
387 | waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten ); | 389 | waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten ); |
388 | total += bytesWritten; | 390 | total += bytesWritten; |
389 | 391 | ||
390 | timeSlider->setValue( total); | 392 | timeSlider->setValue( total); |
391 | filePara.numberSamples = total; | 393 | filePara.numberSamples = total; |
392 | 394 | ||
393 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 395 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
394 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | 396 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); |
395 | // timeLabel->setText( timeString + tr(" seconds")); | 397 | // timeLabel->setText( timeString + tr(" seconds")); |
396 | qApp->processEvents(); | 398 | qApp->processEvents(); |
397 | 399 | ||
398 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 400 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
399 | // if( total >= filePara.numberSamples ) { | 401 | // if( total >= filePara.numberSamples ) { |
400 | stopped = true; | 402 | stopped = true; |
401 | break; | 403 | break; |
402 | } | 404 | } |
403 | // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); | 405 | // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); |
404 | // fflush(stdout); | 406 | // fflush(stdout); |
405 | } | 407 | } |
406 | } | 408 | } |
407 | } | 409 | } |
408 | 410 | ||
409 | 411 | ||
410 | QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) | 412 | QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) |
411 | : QWidget( parent, name, fl ) | 413 | : QWidget( parent, name, fl ) |
412 | { | 414 | { |
413 | if ( !name ) | 415 | if ( !name ) |
414 | setName( "OpieRec" ); | 416 | setName( "OpieRec" ); |
415 | init(); | 417 | init(); |
416 | initConfig(); | 418 | initConfig(); |
417 | initConnections(); | 419 | initConnections(); |
418 | renameBox = 0; | 420 | renameBox = 0; |
419 | 421 | ||
420 | // open sound device to get volumes | 422 | // open sound device to get volumes |
421 | Config hwcfg("OpieRec"); | 423 | Config hwcfg("OpieRec"); |
422 | hwcfg.setGroup("Hardware"); | 424 | hwcfg.setGroup("Hardware"); |
423 | 425 | ||
424 | 426 | ||
425 | soundDevice = new Device( this, false); //open play | 427 | soundDevice = new Device( this, false); //open play |
426 | 428 | ||
427 | getInVol(); | 429 | getInVol(); |
428 | getOutVol(); | 430 | getOutVol(); |
429 | 431 | ||
430 | soundDevice->closeDevice( true); | 432 | soundDevice->closeDevice( true); |
431 | soundDevice->sd = -1; | 433 | soundDevice->sd = -1; |
432 | soundDevice = 0; | 434 | soundDevice = 0; |
433 | wavFile = 0; | 435 | wavFile = 0; |
434 | // if( soundDevice) delete soundDevice; | 436 | // if( soundDevice) delete soundDevice; |
435 | QTimer::singleShot(100,this, SLOT(initIconView())); | 437 | QTimer::singleShot(100,this, SLOT(initIconView())); |
436 | 438 | ||
437 | if( autoMute) | 439 | if( autoMute) |
438 | doMute( true); | 440 | doMute( true); |
439 | // ListView1->setFocus(); | 441 | // ListView1->setFocus(); |
440 | playing = false; | 442 | playing = false; |
441 | } | 443 | } |
442 | 444 | ||
443 | QtRec::~QtRec() { | 445 | QtRec::~QtRec() { |
444 | // if( soundDevice) delete soundDevice; | 446 | // if( soundDevice) delete soundDevice; |
445 | 447 | ||
446 | } | 448 | } |
447 | 449 | ||
448 | void QtRec::cleanUp() { | 450 | void QtRec::cleanUp() { |
449 | 451 | ||
450 | if( !stopped) { | 452 | if( !stopped) { |
451 | stopped = true; | 453 | stopped = true; |
452 | endRecording(); | 454 | endRecording(); |
453 | } | 455 | } |
454 | 456 | ||
455 | ListView1->clear(); | 457 | ListView1->clear(); |
456 | 458 | ||
457 | if( autoMute) | 459 | if( autoMute) |
458 | doMute(false); | 460 | doMute(false); |
459 | 461 | ||
460 | // if( wavFile) delete wavFile; | 462 | // if( wavFile) delete wavFile; |
461 | // if(soundDevice) delete soundDevice; | 463 | // if(soundDevice) delete soundDevice; |
462 | } | 464 | } |
463 | 465 | ||
464 | void QtRec::init() { | 466 | void QtRec::init() { |
465 | 467 | ||
466 | needsStereoOut = false; | 468 | needsStereoOut = false; |
467 | QPixmap image3( ( const char** ) image3_data ); | 469 | QPixmap image3( ( const char** ) image3_data ); |
468 | QPixmap image4( ( const char** ) image4_data ); | 470 | QPixmap image4( ( const char** ) image4_data ); |
469 | QPixmap image6( ( const char** ) image6_data ); | 471 | QPixmap image6( ( const char** ) image6_data ); |
470 | 472 | ||
471 | stopped = true; | 473 | stopped = true; |
472 | setCaption( tr( "OpieRecord " )); | 474 | setCaption( tr( "OpieRecord " )); |
473 | QGridLayout *layout = new QGridLayout( this ); | 475 | QGridLayout *layout = new QGridLayout( this ); |
474 | layout->setSpacing( 2); | 476 | layout->setSpacing( 2); |
475 | layout->setMargin( 2); | 477 | layout->setMargin( 2); |
476 | 478 | ||
477 | TabWidget = new QTabWidget( this, "TabWidget" ); | 479 | TabWidget = new QTabWidget( this, "TabWidget" ); |
478 | layout->addMultiCellWidget(TabWidget, 0, 7, 0, 8); | 480 | layout->addMultiCellWidget(TabWidget, 0, 7, 0, 8); |
479 | // TabWidget->setTabShape(QTabWidget::Triangular); | 481 | // TabWidget->setTabShape(QTabWidget::Triangular); |
480 | 482 | ||
481 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | 483 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** |
482 | tab = new QWidget( TabWidget, "tab" ); | 484 | tab = new QWidget( TabWidget, "tab" ); |
483 | 485 | ||
484 | QGridLayout *layout1 = new QGridLayout( tab); | 486 | QGridLayout *layout1 = new QGridLayout( tab); |
485 | layout1->setSpacing( 2); | 487 | layout1->setSpacing( 2); |
486 | layout1->setMargin( 2); | 488 | layout1->setMargin( 2); |
487 | 489 | ||
488 | timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); | 490 | timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); |
489 | layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); | 491 | layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); |
490 | 492 | ||
491 | // timeLabel = new QLabel( tab, "TimeLabel" ); | 493 | // timeLabel = new QLabel( tab, "TimeLabel" ); |
492 | // layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); | 494 | // layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); |
493 | 495 | ||
494 | // playLabel2 = new QLabel(tab, "PlayLabel2" ); | 496 | // playLabel2 = new QLabel(tab, "PlayLabel2" ); |
495 | // playLabel2->setText(tr("Play") ); | 497 | // playLabel2->setText(tr("Play") ); |
496 | // playLabel2->setFixedHeight( 18); | 498 | // playLabel2->setFixedHeight( 18); |
497 | // layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); | 499 | // layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); |
498 | 500 | ||
499 | Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); | 501 | Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); |
500 | layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); | 502 | layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); |
501 | Stop_PushButton->setFixedSize( 22, 22); | 503 | Stop_PushButton->setFixedSize( 22, 22); |
502 | Stop_PushButton->setPixmap( image4 ); | 504 | Stop_PushButton->setPixmap( image4 ); |
503 | 505 | ||
504 | toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); | 506 | toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); |
505 | layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); | 507 | layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); |
506 | toBeginningButton->setFixedSize( 22, 22); | 508 | toBeginningButton->setFixedSize( 22, 22); |
507 | toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); | 509 | toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); |
508 | 510 | ||
509 | toEndButton = new QPushButton( tab, "End_PushButton" ); | 511 | toEndButton = new QPushButton( tab, "End_PushButton" ); |
510 | layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); | 512 | layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); |
511 | toEndButton->setFixedSize( 22, 22); | 513 | toEndButton->setFixedSize( 22, 22); |
512 | toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); | 514 | toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); |
513 | 515 | ||
514 | // QLabel *recLabel2; | 516 | // QLabel *recLabel2; |
515 | // recLabel2 = new QLabel( tab, "recLabel2" ); | 517 | // recLabel2 = new QLabel( tab, "recLabel2" ); |
516 | // recLabel2->setText(tr("Rec")); | 518 | // recLabel2->setText(tr("Rec")); |
517 | // recLabel2->setFixedHeight( 18); | 519 | // recLabel2->setFixedHeight( 18); |
518 | // layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); | 520 | // layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); |
519 | 521 | ||
520 | Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); | 522 | Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); |
521 | layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); | 523 | layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); |
522 | Rec_PushButton->setFixedSize( 22, 22); | 524 | Rec_PushButton->setFixedSize( 22, 22); |
523 | Rec_PushButton->setPixmap( image6 ); | 525 | Rec_PushButton->setPixmap( image6 ); |
524 | 526 | ||
525 | t = new QTimer( this ); | 527 | t = new QTimer( this ); |
526 | connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 528 | connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
527 | 529 | ||
528 | rewindTimer = new QTimer( this ); | 530 | rewindTimer = new QTimer( this ); |
529 | connect( rewindTimer, SIGNAL( timeout() ), | 531 | connect( rewindTimer, SIGNAL( timeout() ), |
530 | this, SLOT( rewindTimerTimeout() ) ); | 532 | this, SLOT( rewindTimerTimeout() ) ); |
531 | 533 | ||
532 | forwardTimer = new QTimer( this ); | 534 | forwardTimer = new QTimer( this ); |
533 | connect( forwardTimer, SIGNAL( timeout() ), | 535 | connect( forwardTimer, SIGNAL( timeout() ), |
534 | this, SLOT( forwardTimerTimeout() ) ); | 536 | this, SLOT( forwardTimerTimeout() ) ); |
535 | 537 | ||
536 | deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); | 538 | deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); |
537 | layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); | 539 | layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); |
538 | deleteSoundButton->setText( tr( "Del" ) ); | 540 | deleteSoundButton->setText( tr( "Del" ) ); |
539 | 541 | ||
540 | ListView1 = new QListView( tab, "IconView1" ); | 542 | ListView1 = new QListView( tab, "IconView1" ); |
541 | layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); | 543 | layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); |
542 | 544 | ||
543 | ListView1->addColumn( tr( "Name" ) ); | 545 | ListView1->addColumn( tr( "Name" ) ); |
544 | ListView1->setSorting( 1, false); | 546 | ListView1->setSorting( 1, false); |
545 | ListView1->addColumn( tr( "Time" ) ); //in seconds | 547 | ListView1->addColumn( tr( "Time" ) ); //in seconds |
546 | ListView1->setColumnWidthMode(0, QListView::Maximum); | 548 | ListView1->setColumnWidthMode(0, QListView::Maximum); |
547 | ListView1->setColumnAlignment( 1, QListView::AlignCenter); | 549 | ListView1->setColumnAlignment( 1, QListView::AlignCenter); |
548 | ListView1->setAllColumnsShowFocus( true ); | 550 | ListView1->setAllColumnsShowFocus( true ); |
549 | QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold); | 551 | QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold); |
550 | 552 | ||
551 | TabWidget->insertTab( tab, tr( "Files" ) ); | 553 | TabWidget->insertTab( tab, tr( "Files" ) ); |
552 | 554 | ||
553 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | 555 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** |
554 | tab_3 = new QWidget( TabWidget, "tab_3" ); | 556 | tab_3 = new QWidget( TabWidget, "tab_3" ); |
555 | QGridLayout *glayout3 = new QGridLayout( tab_3 ); | 557 | QGridLayout *glayout3 = new QGridLayout( tab_3 ); |
556 | glayout3->setSpacing( 2); | 558 | glayout3->setSpacing( 2); |
557 | glayout3->setMargin( 2); | 559 | glayout3->setMargin( 2); |
558 | //////////////////////////////////// | 560 | //////////////////////////////////// |
559 | sampleGroup = new QGroupBox( tab_3, "samplegroup" ); | 561 | sampleGroup = new QGroupBox( tab_3, "samplegroup" ); |
560 | sampleGroup->setTitle( tr( "Sample Rate" ) ); | 562 | sampleGroup->setTitle( tr( "Sample Rate" ) ); |
561 | sampleGroup->setFixedSize( 95,50); | 563 | sampleGroup->setFixedSize( 95,50); |
562 | 564 | ||
563 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); | 565 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); |
@@ -663,258 +665,258 @@ void QtRec::init() { | |||
663 | 665 | ||
664 | Layout19a->addLayout( Layout15 ); | 666 | Layout19a->addLayout( Layout15 ); |
665 | Layout19a->addLayout( Layout15b ); | 667 | Layout19a->addLayout( Layout15b ); |
666 | 668 | ||
667 | fillDirectoryCombo(); | 669 | fillDirectoryCombo(); |
668 | 670 | ||
669 | TabWidget->insertTab( tab_3, tr( "Options" ) ); | 671 | TabWidget->insertTab( tab_3, tr( "Options" ) ); |
670 | 672 | ||
671 | TabWidget->insertTab( tab_5, tr( "Volume" ) ); | 673 | TabWidget->insertTab( tab_5, tr( "Volume" ) ); |
672 | 674 | ||
673 | waveform = new Waveform( this, "waveform" ); | 675 | waveform = new Waveform( this, "waveform" ); |
674 | waveform->setMinimumSize( QSize( 0, 50 ) ); | 676 | waveform->setMinimumSize( QSize( 0, 50 ) ); |
675 | 677 | ||
676 | layout->addMultiCellWidget( waveform, 8, 8, 0, 8); | 678 | layout->addMultiCellWidget( waveform, 8, 8, 0, 8); |
677 | waveform->setBackgroundColor ( black ); | 679 | waveform->setBackgroundColor ( black ); |
678 | } | 680 | } |
679 | 681 | ||
680 | void QtRec::initIconView() { | 682 | void QtRec::initIconView() { |
681 | ListView1->clear(); | 683 | ListView1->clear(); |
682 | Config cfg("OpieRec"); | 684 | Config cfg("OpieRec"); |
683 | cfg.setGroup("Sounds"); | 685 | cfg.setGroup("Sounds"); |
684 | QString temp; | 686 | QString temp; |
685 | QPixmap image0( ( const char** ) image0_data ); | 687 | QPixmap image0( ( const char** ) image0_data ); |
686 | 688 | ||
687 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 689 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
688 | // owarn << "init number of files " << nFiles << "" << oendl; | 690 | // owarn << "init number of files " << nFiles << "" << oendl; |
689 | 691 | ||
690 | for(int i = 1; i <= nFiles; i++) { | 692 | for(int i = 1; i <= nFiles; i++) { |
691 | 693 | ||
692 | QListViewItem * item; | 694 | QListViewItem * item; |
693 | QString fileS, mediaLocation, fileDate, filePath; | 695 | QString fileS, mediaLocation, fileDate, filePath; |
694 | 696 | ||
695 | temp.sprintf( "%d",i); | 697 | temp.sprintf( "%d",i); |
696 | temp = cfg.readEntry( temp,""); //reads currentFile | 698 | temp = cfg.readEntry( temp,""); //reads currentFile |
697 | filePath = cfg.readEntry( temp,""); //currentFileName | 699 | filePath = cfg.readEntry( temp,""); //currentFileName |
698 | 700 | ||
699 | QFileInfo info(filePath); | 701 | QFileInfo info(filePath); |
700 | fileDate = info.lastModified().toString(); | 702 | fileDate = info.lastModified().toString(); |
701 | 703 | ||
702 | fileS = cfg.readEntry( filePath, "0" );// file length in seconds | 704 | fileS = cfg.readEntry( filePath, "0" );// file length in seconds |
703 | mediaLocation = getStorage( filePath); | 705 | mediaLocation = getStorage( filePath); |
704 | if( info.exists()) { | 706 | if( info.exists()) { |
705 | // owarn << "new item " << temp << oendl; | 707 | // owarn << "new item " << temp << oendl; |
706 | item = new QListViewItem( ListView1, temp, fileS /*, mediaLocation, fileDate*/); | 708 | item = new QListViewItem( ListView1, temp, fileS /*, mediaLocation, fileDate*/); |
707 | item->setPixmap( 0, image0); | 709 | item->setPixmap( 0, image0); |
708 | if( currentFileName == filePath) | 710 | if( currentFileName == filePath) |
709 | ListView1->setSelected( item, true); | 711 | ListView1->setSelected( item, true); |
710 | } | 712 | } |
711 | } | 713 | } |
712 | } | 714 | } |
713 | 715 | ||
714 | void QtRec::initConnections() { | 716 | void QtRec::initConnections() { |
715 | connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp())); | 717 | connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp())); |
716 | 718 | ||
717 | connect(toBeginningButton,SIGNAL(pressed()),this,SLOT(rewindPressed())); | 719 | connect(toBeginningButton,SIGNAL(pressed()),this,SLOT(rewindPressed())); |
718 | connect(toBeginningButton,SIGNAL(released()),this,SLOT(rewindReleased())); | 720 | connect(toBeginningButton,SIGNAL(released()),this,SLOT(rewindReleased())); |
719 | connect(toEndButton,SIGNAL(pressed()),this,SLOT(FastforwardPressed())); | 721 | connect(toEndButton,SIGNAL(pressed()),this,SLOT(FastforwardPressed())); |
720 | connect(toEndButton,SIGNAL(released()),this,SLOT(FastforwardReleased())); | 722 | connect(toEndButton,SIGNAL(released()),this,SLOT(FastforwardReleased())); |
721 | connect(deleteSoundButton,SIGNAL(released()),this,SLOT(deleteSound())); | 723 | connect(deleteSoundButton,SIGNAL(released()),this,SLOT(deleteSound())); |
722 | connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn())); | 724 | connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn())); |
723 | connect(Rec_PushButton,SIGNAL(released()),this,SLOT(newSound())); | 725 | connect(Rec_PushButton,SIGNAL(released()),this,SLOT(newSound())); |
724 | 726 | ||
725 | connect(TabWidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(thisTab(QWidget*))); | 727 | connect(TabWidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(thisTab(QWidget*))); |
726 | 728 | ||
727 | connect(OutputSlider,SIGNAL(sliderReleased()),this,SLOT(changedOutVolume())); | 729 | connect(OutputSlider,SIGNAL(sliderReleased()),this,SLOT(changedOutVolume())); |
728 | connect(InputSlider,SIGNAL(sliderReleased()),this,SLOT(changedInVolume())); | 730 | connect(InputSlider,SIGNAL(sliderReleased()),this,SLOT(changedInVolume())); |
729 | 731 | ||
730 | connect(sampleRateComboBox,SIGNAL(activated(int)),this,SLOT(changesamplerateCombo(int))); | 732 | connect(sampleRateComboBox,SIGNAL(activated(int)),this,SLOT(changesamplerateCombo(int))); |
731 | connect(bitRateComboBox,SIGNAL(activated(int)),this,SLOT(changebitrateCombo(int))); | 733 | connect(bitRateComboBox,SIGNAL(activated(int)),this,SLOT(changebitrateCombo(int))); |
732 | connect(directoryComboBox,SIGNAL(activated(int)),this,SLOT(changeDirCombo(int))); | 734 | connect(directoryComboBox,SIGNAL(activated(int)),this,SLOT(changeDirCombo(int))); |
733 | connect(sizeLimitCombo,SIGNAL(activated(int)),this,SLOT(changeSizeLimitCombo(int))); | 735 | connect(sizeLimitCombo,SIGNAL(activated(int)),this,SLOT(changeSizeLimitCombo(int))); |
734 | 736 | ||
735 | connect(stereoCheckBox,SIGNAL(toggled(bool)),this,SLOT(changeStereoCheck(bool))); | 737 | connect(stereoCheckBox,SIGNAL(toggled(bool)),this,SLOT(changeStereoCheck(bool))); |
736 | connect(outMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doVolMuting(bool))); | 738 | connect(outMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doVolMuting(bool))); |
737 | connect(inMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doMicMuting(bool))); | 739 | connect(inMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doMicMuting(bool))); |
738 | 740 | ||
739 | connect(ListView1,SIGNAL(doubleClicked(QListViewItem*)),this,SLOT(itClick(QListViewItem*))); | 741 | connect(ListView1,SIGNAL(doubleClicked(QListViewItem*)),this,SLOT(itClick(QListViewItem*))); |
740 | connect(ListView1,SIGNAL(mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),this,SLOT(listPressed(int,QListViewItem*,const QPoint&,int))); | 742 | connect(ListView1,SIGNAL(mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),this,SLOT(listPressed(int,QListViewItem*,const QPoint&,int))); |
741 | 743 | ||
742 | connect(timeSlider,SIGNAL(sliderMoved(int)),this,SLOT(changeTimeSlider(int))); | 744 | connect(timeSlider,SIGNAL(sliderMoved(int)),this,SLOT(changeTimeSlider(int))); |
743 | connect(timeSlider,SIGNAL(sliderPressed()),this,SLOT(timeSliderPressed())); | 745 | connect(timeSlider,SIGNAL(sliderPressed()),this,SLOT(timeSliderPressed())); |
744 | connect(timeSlider,SIGNAL(sliderReleased()),this,SLOT(timeSliderReleased())); | 746 | connect(timeSlider,SIGNAL(sliderReleased()),this,SLOT(timeSliderReleased())); |
745 | 747 | ||
746 | connect(compressionCheckBox,SIGNAL(toggled(bool)),this,SLOT(compressionSelected(bool))); | 748 | connect(compressionCheckBox,SIGNAL(toggled(bool)),this,SLOT(compressionSelected(bool))); |
747 | connect(autoMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(slotAutoMute(bool))); | 749 | connect(autoMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(slotAutoMute(bool))); |
748 | } | 750 | } |
749 | 751 | ||
750 | void QtRec::initConfig() { | 752 | void QtRec::initConfig() { |
751 | int index, fred, i; | 753 | int index, fred, i; |
752 | Config cfg("OpieRec"); | 754 | Config cfg("OpieRec"); |
753 | cfg.setGroup("Settings"); | 755 | cfg.setGroup("Settings"); |
754 | 756 | ||
755 | index = cfg.readNumEntry("samplerate",22050); | 757 | index = cfg.readNumEntry("samplerate",22050); |
756 | bool ok; | 758 | bool ok; |
757 | 759 | ||
758 | for(int ws=0;ws<sampleRateComboBox->count();ws++) { | 760 | for(int ws=0;ws<sampleRateComboBox->count();ws++) { |
759 | fred = sampleRateComboBox->text(ws).toInt(&ok, 10); | 761 | fred = sampleRateComboBox->text(ws).toInt(&ok, 10); |
760 | if( index == fred) { | 762 | if( index == fred) { |
761 | filePara.sampleRate = fred; | 763 | filePara.sampleRate = fred; |
762 | sampleRateComboBox->setCurrentItem(ws); | 764 | sampleRateComboBox->setCurrentItem(ws); |
763 | } | 765 | } |
764 | } | 766 | } |
765 | 767 | ||
766 | i = cfg.readNumEntry("bitrate",16); | 768 | i = cfg.readNumEntry("bitrate",16); |
767 | if(i == 16) | 769 | if(i == 16) |
768 | bitRateComboBox->setCurrentItem( 1); | 770 | bitRateComboBox->setCurrentItem( 1); |
769 | else if(i == 24) | 771 | else if(i == 24) |
770 | bitRateComboBox->setCurrentItem( 2); | 772 | bitRateComboBox->setCurrentItem( 2); |
771 | else if(i == 32) | 773 | else if(i == 32) |
772 | bitRateComboBox->setCurrentItem( 3); | 774 | bitRateComboBox->setCurrentItem( 3); |
773 | else | 775 | else |
774 | bitRateComboBox->setCurrentItem( 0); | 776 | bitRateComboBox->setCurrentItem( 0); |
775 | 777 | ||
776 | filePara.resolution = i; | 778 | filePara.resolution = i; |
777 | 779 | ||
778 | i = cfg.readNumEntry("sizeLimit", 5 ); | 780 | i = cfg.readNumEntry("sizeLimit", 5 ); |
779 | QString temp; | 781 | QString temp; |
780 | sizeLimitCombo->setCurrentItem((i/5)); | 782 | sizeLimitCombo->setCurrentItem((i/5)); |
781 | 783 | ||
782 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); | 784 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); |
783 | if( stereoCheckBox->isChecked()) { | 785 | if( stereoCheckBox->isChecked()) { |
784 | filePara.channels = 2; | 786 | filePara.channels = 2; |
785 | } else { | 787 | } else { |
786 | filePara.channels = 1; | 788 | filePara.channels = 1; |
787 | } | 789 | } |
788 | 790 | ||
789 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); | 791 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); |
790 | if( compressionCheckBox->isChecked()) { | 792 | if( compressionCheckBox->isChecked()) { |
793 | bitRateComboBox->setCurrentItem(1); | ||
791 | bitRateComboBox->setEnabled(false); | 794 | bitRateComboBox->setEnabled(false); |
792 | bitRateComboBox->setCurrentItem(0); | ||
793 | filePara.resolution=16; | 795 | filePara.resolution=16; |
794 | } | 796 | } |
795 | 797 | ||
796 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); | 798 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); |
797 | if( autoMuteCheckBox->isChecked()) | 799 | if( autoMuteCheckBox->isChecked()) |
798 | slotAutoMute(true); | 800 | slotAutoMute(true); |
799 | else | 801 | else |
800 | slotAutoMute(false); | 802 | slotAutoMute(false); |
801 | 803 | ||
802 | Config cofg( "qpe"); | 804 | Config cofg( "qpe"); |
803 | cofg.setGroup( "Volume"); | 805 | cofg.setGroup( "Volume"); |
804 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); | 806 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); |
805 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); | 807 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); |
806 | } | 808 | } |
807 | 809 | ||
808 | void QtRec::stop() { | 810 | void QtRec::stop() { |
809 | // owarn << "STOP" << oendl; | 811 | // owarn << "STOP" << oendl; |
810 | setRecordButton(false); | 812 | setRecordButton(false); |
811 | 813 | ||
812 | if( !recording) | 814 | if( !recording) |
813 | endPlaying(); | 815 | endPlaying(); |
814 | else | 816 | else |
815 | endRecording(); | 817 | endRecording(); |
816 | timeSlider->setValue(0); | 818 | timeSlider->setValue(0); |
817 | } | 819 | } |
818 | 820 | ||
819 | void QtRec::doPlayBtn() { | 821 | void QtRec::doPlayBtn() { |
820 | 822 | ||
821 | if(!stopped) { | 823 | if(!stopped) { |
822 | // playLabel2->setText(tr("Play")); | 824 | // playLabel2->setText(tr("Play")); |
823 | stop(); | 825 | stop(); |
824 | } else { | 826 | } else { |
825 | if(ListView1->currentItem() == 0) return; | 827 | if(ListView1->currentItem() == 0) return; |
826 | // playLabel2->setText(tr("Stop")); | 828 | // playLabel2->setText(tr("Stop")); |
827 | currentFile = ListView1->currentItem()->text(0); | 829 | currentFile = ListView1->currentItem()->text(0); |
828 | start(); | 830 | start(); |
829 | } | 831 | } |
830 | } | 832 | } |
831 | 833 | ||
832 | void QtRec::start() { //play | 834 | void QtRec::start() { //play |
833 | if( stopped) { | 835 | if( stopped) { |
834 | QPixmap image3( ( const char** ) image3_data ); | 836 | QPixmap image3( ( const char** ) image3_data ); |
835 | Stop_PushButton->setPixmap( image3 ); | 837 | Stop_PushButton->setPixmap( image3 ); |
836 | Stop_PushButton->setDown( true); | 838 | Stop_PushButton->setDown( true); |
837 | stopped = false; | 839 | stopped = false; |
838 | paused = false; | 840 | paused = false; |
839 | secCount = 1; | 841 | secCount = 1; |
840 | 842 | ||
841 | if( openPlayFile()) | 843 | if( openPlayFile()) |
842 | if( setupAudio( false)) //recording is false | 844 | if( setupAudio( false)) //recording is false |
843 | doPlay(); | 845 | doPlay(); |
844 | } | 846 | } |
845 | } | 847 | } |
846 | 848 | ||
847 | bool QtRec::rec() { //record | 849 | bool QtRec::rec() { //record |
848 | QString timeString; | 850 | QString timeString; |
849 | timeString.sprintf("%.0f", 0.0); | 851 | timeString.sprintf("%.0f", 0.0); |
850 | // timeLabel->setText( timeString+ " seconds"); | 852 | // timeLabel->setText( timeString+ " seconds"); |
851 | if(!stopped) { | 853 | if(!stopped) { |
852 | monitoring = true; | 854 | monitoring = true; |
853 | return false; | 855 | return false; |
854 | } else { | 856 | } else { |
855 | secCount = 1; | 857 | secCount = 1; |
856 | // playLabel2->setText(tr("Stop")); | 858 | // playLabel2->setText(tr("Stop")); |
857 | monitoring = false; | 859 | monitoring = false; |
858 | setRecordButton( true); | 860 | setRecordButton( true); |
859 | 861 | ||
860 | if( setupAudio( true)) | 862 | if( setupAudio( true)) |
861 | if(setUpFile()) { | 863 | if(setUpFile()) { |
862 | int fileSize = 0; | 864 | int fileSize = 0; |
863 | Config cfg("OpieRec"); | 865 | Config cfg("OpieRec"); |
864 | cfg.setGroup("Settings"); | 866 | cfg.setGroup("Settings"); |
865 | // odebug << "<<<<<<<Device bits " << soundDevice->getDeviceBits() | 867 | // odebug << "<<<<<<<Device bits " << soundDevice->getDeviceBits() |
866 | // << ", device rate " << soundDevice->getDeviceRate() | 868 | // << ", device rate " << soundDevice->getDeviceRate() |
867 | // << ", device channels " << soundDevice->getDeviceChannels() << oendl; | 869 | // << ", device channels " << soundDevice->getDeviceChannels() << oendl; |
868 | 870 | ||
869 | //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); | 871 | //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); |
870 | // odebug << "sample rate is " << filePara.sampleRate << "" << oendl; | 872 | // odebug << "sample rate is " << filePara.sampleRate << "" << oendl; |
871 | filePara.SecondsToRecord = getCurrentSizeLimit(); | 873 | filePara.SecondsToRecord = getCurrentSizeLimit(); |
872 | 874 | ||
873 | // odebug << "size limit " << filePara.SecondsToRecord << " sec" << oendl; | 875 | // odebug << "size limit " << filePara.SecondsToRecord << " sec" << oendl; |
874 | int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); | 876 | int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); |
875 | 877 | ||
876 | if( filePara.SecondsToRecord == 0) { | 878 | if( filePara.SecondsToRecord == 0) { |
877 | fileSize = diskSize; | 879 | fileSize = diskSize; |
878 | } else if( filePara.format == WAVE_FORMAT_PCM) { | 880 | } else if( filePara.format == WAVE_FORMAT_PCM) { |
879 | // odebug << "WAVE_FORMAT_PCM" << oendl; | 881 | // odebug << "WAVE_FORMAT_PCM" << oendl; |
880 | fileSize = (filePara.SecondsToRecord ) * filePara.channels | 882 | fileSize = (filePara.SecondsToRecord ) * filePara.channels |
881 | * filePara.sampleRate * ( filePara.resolution / 8) + 1000; | 883 | * filePara.sampleRate * ( filePara.resolution / 8) + 1000; |
882 | } else { | 884 | } else { |
883 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; | 885 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; |
884 | fileSize = ((filePara.SecondsToRecord) * filePara.channels | 886 | fileSize = ((filePara.SecondsToRecord) * filePara.channels |
885 | * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250; | 887 | * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250; |
886 | } | 888 | } |
887 | 889 | ||
888 | filePara.samplesToRecord = fileSize; | 890 | filePara.samplesToRecord = fileSize; |
889 | odebug << "filesize should be " << filePara.samplesToRecord | 891 | odebug << "filesize should be " << filePara.samplesToRecord |
890 | << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate; | 892 | << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate; |
891 | if( paused) { | 893 | if( paused) { |
892 | paused = false; | 894 | paused = false; |
893 | } | 895 | } |
894 | // else { | 896 | // else { |
895 | odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl; | 897 | odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl; |
896 | // if(fileSize != 0) | 898 | // if(fileSize != 0) |
897 | timeSlider->setRange(0, filePara.samplesToRecord); | 899 | timeSlider->setRange(0, filePara.samplesToRecord); |
898 | // } | 900 | // } |
899 | 901 | ||
900 | if( diskSize < fileSize/1024) { | 902 | if( diskSize < fileSize/1024) { |
901 | QMessageBox::warning(this, | 903 | QMessageBox::warning(this, |
902 | tr("Low Disk Space"), | 904 | tr("Low Disk Space"), |
903 | tr("You are running low of\nrecording space\n" | 905 | tr("You are running low of\nrecording space\n" |
904 | "or a card isn't being recognized")); | 906 | "or a card isn't being recognized")); |
905 | stopped = true; //we need to be stopped | 907 | stopped = true; //we need to be stopped |
906 | stop(); | 908 | stop(); |
907 | } else { | 909 | } else { |
908 | QString msg; | 910 | QString msg; |
909 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | 911 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); |
910 | #ifdef DEV_VERSION | 912 | #ifdef DEV_VERSION |
911 | setCaption( msg); | 913 | setCaption( msg); |
912 | #endif | 914 | #endif |
913 | filePara.fileName=currentFile.latin1(); | 915 | filePara.fileName=currentFile.latin1(); |
914 | odebug << "Start recording" << oendl; | 916 | odebug << "Start recording" << oendl; |
915 | stopped = false; | 917 | stopped = false; |
916 | 918 | ||
917 | #ifdef THREADED | 919 | #ifdef THREADED |
918 | odebug << "Start recording thread" << oendl; | 920 | odebug << "Start recording thread" << oendl; |
919 | pthread_t thread1; | 921 | pthread_t thread1; |
920 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); | 922 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); |
@@ -923,1078 +925,1079 @@ bool QtRec::rec() { //record | |||
923 | toEndButton->setEnabled( false); | 925 | toEndButton->setEnabled( false); |
924 | 926 | ||
925 | startTimer(1000); | 927 | startTimer(1000); |
926 | #ifndef THREADED | 928 | #ifndef THREADED |
927 | quickRec(); | 929 | quickRec(); |
928 | #endif | 930 | #endif |
929 | } | 931 | } |
930 | } //end setUpFile | 932 | } //end setUpFile |
931 | } //end setupAudio | 933 | } //end setupAudio |
932 | return true; | 934 | return true; |
933 | } | 935 | } |
934 | /* | 936 | /* |
935 | This happens when a tab is selected*/ | 937 | This happens when a tab is selected*/ |
936 | void QtRec::thisTab(QWidget* widg) { | 938 | void QtRec::thisTab(QWidget* widg) { |
937 | if(widg != NULL) { | 939 | if(widg != NULL) { |
938 | int index = TabWidget->currentPageIndex(); | 940 | int index = TabWidget->currentPageIndex(); |
939 | 941 | ||
940 | if(index == 0) { //file page | 942 | if(index == 0) { //file page |
941 | } | 943 | } |
942 | 944 | ||
943 | if(index == 1) { //control page | 945 | if(index == 1) { //control page |
944 | fillDirectoryCombo(); | 946 | fillDirectoryCombo(); |
945 | // soundDevice->getOutVol(); | 947 | // soundDevice->getOutVol(); |
946 | // soundDevice->getInVol(); | 948 | // soundDevice->getInVol(); |
947 | } | 949 | } |
948 | 950 | ||
949 | if( index==2) { //help page | 951 | if( index==2) { //help page |
950 | } | 952 | } |
951 | 953 | ||
952 | qApp->processEvents(); | 954 | qApp->processEvents(); |
953 | update(); | 955 | update(); |
954 | } | 956 | } |
955 | } | 957 | } |
956 | 958 | ||
957 | void QtRec::getOutVol( ) { | 959 | void QtRec::getOutVol( ) { |
958 | filePara.outVol = soundDevice->getOutVolume(); | 960 | filePara.outVol = soundDevice->getOutVolume(); |
959 | // odebug << "out vol " << filePara.outVol << "" << oendl; | 961 | // odebug << "out vol " << filePara.outVol << "" << oendl; |
960 | OutputSlider->setValue( -filePara.outVol); | 962 | OutputSlider->setValue( -filePara.outVol); |
961 | } | 963 | } |
962 | 964 | ||
963 | void QtRec::getInVol() { | 965 | void QtRec::getInVol() { |
964 | filePara.inVol = soundDevice->getInVolume(); | 966 | filePara.inVol = soundDevice->getInVolume(); |
965 | // odebug << "in vol " << filePara.inVol << "" << oendl; | 967 | // odebug << "in vol " << filePara.inVol << "" << oendl; |
966 | InputSlider->setValue( -filePara.inVol); | 968 | InputSlider->setValue( -filePara.inVol); |
967 | } | 969 | } |
968 | 970 | ||
969 | void QtRec::changedOutVolume() { | 971 | void QtRec::changedOutVolume() { |
970 | soundDevice->changedOutVolume( -OutputSlider->value()); | 972 | soundDevice->changedOutVolume( -OutputSlider->value()); |
971 | } | 973 | } |
972 | 974 | ||
973 | void QtRec::changedInVolume( ) { | 975 | void QtRec::changedInVolume( ) { |
974 | soundDevice->changedInVolume( -InputSlider->value()); | 976 | soundDevice->changedInVolume( -InputSlider->value()); |
975 | } | 977 | } |
976 | 978 | ||
977 | 979 | ||
978 | bool QtRec::setupAudio( bool b) { | 980 | bool QtRec::setupAudio( bool b) { |
979 | bool ok; | 981 | bool ok; |
980 | int sampleformat, stereo, flags; | 982 | int sampleformat, stereo, flags; |
981 | QString dspString, mixerString; | 983 | QString dspString, mixerString; |
982 | 984 | ||
983 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 | 985 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 |
984 | 986 | ||
985 | if( !b) { | 987 | if( !b) { |
986 | // we want to play | 988 | // we want to play |
987 | #ifdef PDAUDIO //ALSA | 989 | #ifdef PDAUDIO //ALSA |
988 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | 990 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { |
989 | sampleformat = SND_PCM_FORMAT_S16; | 991 | sampleformat = SND_PCM_FORMAT_S16; |
990 | filePara.resolution = 16; | 992 | filePara.resolution = 16; |
991 | } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { | 993 | } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { |
992 | sampleformat = SND_PCM_FORMAT_S24; | 994 | sampleformat = SND_PCM_FORMAT_S24; |
993 | filePara.resolution = 24; | 995 | filePara.resolution = 24; |
994 | } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { | 996 | } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { |
995 | sampleformat = SND_PCM_FORMAT_S32; | 997 | sampleformat = SND_PCM_FORMAT_S32; |
996 | filePara.resolution = 32; | 998 | filePara.resolution = 32; |
997 | } else { | 999 | } else { |
998 | sampleformat = SND_PCM_FORMAT_U8; | 1000 | sampleformat = SND_PCM_FORMAT_U8; |
999 | filePara.resolution = 8; | 1001 | filePara.resolution = 8; |
1000 | } | 1002 | } |
1001 | #else | 1003 | #else |
1002 | // we want to play | 1004 | // we want to play |
1003 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | 1005 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { |
1004 | sampleformat = AFMT_S16_LE; | 1006 | sampleformat = AFMT_S16_LE; |
1005 | filePara.resolution = 16; | 1007 | filePara.resolution = 16; |
1006 | } else { | 1008 | } else { |
1007 | sampleformat = AFMT_U8; | 1009 | sampleformat = AFMT_U8; |
1008 | filePara.resolution = 8; | 1010 | filePara.resolution = 8; |
1009 | } | 1011 | } |
1010 | #endif | 1012 | #endif |
1011 | 1013 | ||
1012 | stereo = filePara.channels; | 1014 | stereo = filePara.channels; |
1013 | flags = O_WRONLY; | 1015 | flags = O_WRONLY; |
1014 | recording = false; | 1016 | recording = false; |
1015 | } else { // we want to record | 1017 | } else { // we want to record |
1016 | 1018 | ||
1017 | #ifdef PDAUDIO //ALSA | 1019 | #ifdef PDAUDIO //ALSA |
1018 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | 1020 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") |
1019 | sampleformat = SND_PCM_FORMAT_S16; | 1021 | sampleformat = SND_PCM_FORMAT_S16; |
1020 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") | 1022 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") |
1021 | sampleformat = SND_PCM_FORMAT_S24; | 1023 | sampleformat = SND_PCM_FORMAT_S24; |
1022 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") | 1024 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") |
1023 | sampleformat = SND_PCM_FORMAT_S32; | 1025 | sampleformat = SND_PCM_FORMAT_S32; |
1024 | else | 1026 | else |
1025 | sampleformat = SND_PCM_FORMAT_U8; | 1027 | sampleformat = SND_PCM_FORMAT_U8; |
1026 | 1028 | ||
1027 | #else | 1029 | #else |
1028 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | 1030 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") |
1029 | sampleformat = AFMT_S16_LE; | 1031 | sampleformat = AFMT_S16_LE; |
1030 | else | 1032 | else |
1031 | sampleformat = AFMT_U8; | 1033 | sampleformat = AFMT_U8; |
1032 | 1034 | ||
1033 | if( !compressionCheckBox->isChecked()) { | 1035 | if( !compressionCheckBox->isChecked()) { |
1034 | filePara.format = WAVE_FORMAT_PCM; | 1036 | filePara.format = WAVE_FORMAT_PCM; |
1035 | // odebug << "WAVE_FORMAT_PCM" << oendl; | 1037 | // odebug << "WAVE_FORMAT_PCM" << oendl; |
1036 | } else { | 1038 | } else { |
1037 | filePara.format = WAVE_FORMAT_DVI_ADPCM; | 1039 | filePara.format = WAVE_FORMAT_DVI_ADPCM; |
1038 | sampleformat = AFMT_S16_LE; | 1040 | sampleformat = AFMT_S16_LE; |
1039 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; | 1041 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; |
1040 | } | 1042 | } |
1041 | #endif | 1043 | #endif |
1042 | 1044 | ||
1043 | stereo = filePara.channels; | 1045 | stereo = filePara.channels; |
1044 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; | 1046 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; |
1045 | flags= O_RDWR; | 1047 | flags= O_RDWR; |
1046 | // flags= O_RDONLY; | 1048 | // flags= O_RDONLY; |
1047 | recording = true; | 1049 | recording = true; |
1048 | } | 1050 | } |
1049 | 1051 | ||
1050 | // if(soundDevice) delete soundDevice; | 1052 | // if(soundDevice) delete soundDevice; |
1051 | odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; | 1053 | owarn << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; |
1052 | // owarn << "change waveform settings" << oendl; | 1054 | // owarn << "change waveform settings" << oendl; |
1053 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); | 1055 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); |
1054 | 1056 | ||
1055 | soundDevice = new Device( this, b); //open rec | 1057 | soundDevice = new Device( this, b); //open rec |
1056 | // soundDevice->openDsp(); | 1058 | // soundDevice->openDsp(); |
1057 | soundDevice->reset(); | 1059 | soundDevice->reset(); |
1058 | 1060 | ||
1059 | odebug << "device has been made " << soundDevice->sd << "" << oendl; | 1061 | odebug << "device has been made " << soundDevice->sd << "" << oendl; |
1060 | 1062 | ||
1061 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> | 1063 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> |
1062 | soundDevice->setDeviceFormat( sampleformat); | 1064 | soundDevice->setDeviceFormat( sampleformat); |
1063 | soundDevice->setDeviceChannels( filePara.channels); | 1065 | soundDevice->setDeviceChannels( filePara.channels); |
1064 | soundDevice->setDeviceRate( filePara.sampleRate); | 1066 | soundDevice->setDeviceRate( filePara.sampleRate); |
1065 | soundDevice->getDeviceFragSize(); | 1067 | soundDevice->getDeviceFragSize(); |
1066 | #ifdef QT_QWS_EBX | 1068 | #ifdef QT_QWS_EBX |
1067 | int frag = FRAGSIZE; | 1069 | int frag = FRAGSIZE; |
1068 | soundDevice->setFragSize( frag); | 1070 | soundDevice->setFragSize( frag); |
1069 | soundDevice->getDeviceFragSize(); | 1071 | soundDevice->getDeviceFragSize(); |
1070 | #endif | 1072 | #endif |
1071 | ///////////////// | 1073 | ///////////////// |
1072 | filePara.sd = soundDevice->sd; | 1074 | filePara.sd = soundDevice->sd; |
1073 | 1075 | ||
1074 | if ( filePara.sd == -1) { | 1076 | if ( filePara.sd == -1) { |
1075 | 1077 | ||
1076 | monitoring = false; | 1078 | monitoring = false; |
1077 | stopped = true; | 1079 | stopped = true; |
1078 | update(); | 1080 | update(); |
1079 | setCaption( tr( "OpieRecord " )+ QString::number(VERSION) ); | 1081 | setCaption( tr( "OpieRecord " )+ QString::number(VERSION) ); |
1080 | return false; | 1082 | return false; |
1081 | } | 1083 | } |
1082 | if(autoMute) | 1084 | if(autoMute) |
1083 | doMute(false); | 1085 | doMute(false); |
1084 | 1086 | ||
1085 | return true; | 1087 | return true; |
1086 | } | 1088 | } |
1087 | 1089 | ||
1088 | 1090 | ||
1089 | bool QtRec::setUpFile() { //setup file for recording | 1091 | bool QtRec::setUpFile() { //setup file for recording |
1090 | // odebug << "Setting up wavfile" << oendl; | 1092 | // odebug << "Setting up wavfile" << oendl; |
1091 | // if(wavFile) delete wavFile; | 1093 | // if(wavFile) delete wavFile; |
1092 | wavFile = new WavFile( this, (const QString &)"", | 1094 | wavFile = new WavFile( this, (const QString &)"", |
1093 | true, | 1095 | true, |
1094 | filePara.sampleRate, | 1096 | filePara.sampleRate, |
1095 | filePara.channels, | 1097 | filePara.channels, |
1096 | filePara.resolution, | 1098 | filePara.resolution, |
1097 | filePara.format); | 1099 | filePara.format); |
1098 | 1100 | ||
1099 | filePara.fd = wavFile->wavHandle(); | 1101 | filePara.fd = wavFile->wavHandle(); |
1100 | if(filePara.fd == -1) { | 1102 | if(filePara.fd == -1) { |
1101 | return false; | 1103 | return false; |
1102 | } else { | 1104 | } else { |
1103 | // filePara.channels=1; | 1105 | // filePara.channels=1; |
1104 | } | 1106 | } |
1105 | return true; | 1107 | return true; |
1106 | } | 1108 | } |
1107 | 1109 | ||
1108 | /// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> | 1110 | /// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> |
1109 | bool QtRec::doPlay() { | 1111 | bool QtRec::doPlay() { |
1110 | 1112 | ||
1111 | if( !paused) { | 1113 | if( !paused) { |
1112 | total = 0; | 1114 | total = 0; |
1113 | filePara.numberOfRecordedSeconds = 0; | 1115 | filePara.numberOfRecordedSeconds = 0; |
1114 | } else { | 1116 | } else { |
1115 | paused = false; | 1117 | paused = false; |
1116 | secCount = (int)filePara.numberOfRecordedSeconds; | 1118 | secCount = (int)filePara.numberOfRecordedSeconds; |
1117 | } | 1119 | } |
1118 | playing = true; | 1120 | playing = true; |
1119 | stopped = false; | 1121 | stopped = false; |
1120 | recording = false; | 1122 | recording = false; |
1121 | 1123 | ||
1122 | QString num; | 1124 | QString num; |
1123 | odebug << "Play number of samples " << filePara.numberSamples << "" << oendl; | 1125 | odebug << "Play number of samples " << filePara.numberSamples << "" << oendl; |
1124 | 1126 | ||
1125 | // timeSlider->setRange( 0, filePara.numberSamples); | 1127 | // timeSlider->setRange( 0, filePara.numberSamples); |
1126 | 1128 | ||
1127 | timeString.sprintf("%f", filePara.numberOfRecordedSeconds); | 1129 | timeString.sprintf("%f", filePara.numberOfRecordedSeconds); |
1128 | // timeLabel->setText( timeString+ tr(" seconds")); | 1130 | // timeLabel->setText( timeString+ tr(" seconds")); |
1129 | 1131 | ||
1130 | QString msg; | 1132 | QString msg; |
1131 | msg.sprintf("%d, %d, %d", | 1133 | msg.sprintf("%d, %d, %d", |
1132 | filePara.sampleRate, | 1134 | filePara.sampleRate, |
1133 | filePara.channels, | 1135 | filePara.channels, |
1134 | filePara.resolution); | 1136 | filePara.resolution); |
1135 | #ifdef DEV_VERSION | 1137 | #ifdef DEV_VERSION |
1136 | setCaption( msg); | 1138 | setCaption( msg); |
1137 | #endif | 1139 | #endif |
1138 | 1140 | ||
1139 | startTimer( 1000); | 1141 | startTimer( 1000); |
1140 | #ifdef THREADED | 1142 | #ifdef THREADED |
1141 | pthread_t thread2; | 1143 | pthread_t thread2; |
1142 | pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); | 1144 | pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); |
1143 | #endif | 1145 | #endif |
1144 | 1146 | ||
1145 | toBeginningButton->setEnabled( false); | 1147 | toBeginningButton->setEnabled( false); |
1146 | toEndButton->setEnabled( false); | 1148 | toEndButton->setEnabled( false); |
1147 | #ifndef THREADED | 1149 | #ifndef THREADED |
1148 | playIt(); | 1150 | playIt(); |
1149 | #endif | 1151 | #endif |
1150 | return true; | 1152 | return true; |
1151 | } | 1153 | } |
1152 | 1154 | ||
1153 | 1155 | ||
1154 | void QtRec::changebitrateCombo(int i) { | 1156 | void QtRec::changebitrateCombo(int i) { |
1155 | Config cfg("OpieRec"); | 1157 | Config cfg("OpieRec"); |
1156 | cfg.setGroup("Settings"); | 1158 | cfg.setGroup("Settings"); |
1157 | int bits = 0; | 1159 | int bits = 0; |
1158 | if( i == 1) { bits = 16; } | 1160 | if( i == 1) { bits = 16; } |
1159 | else if( i == 2) { bits = 24; } | 1161 | else if( i == 2) { bits = 24; } |
1160 | else if( i == 3) { bits = 32; } | 1162 | else if( i == 3) { bits = 32; } |
1161 | else { bits=8; } | 1163 | else { bits=8; } |
1162 | cfg.writeEntry("bitrate", bits); | 1164 | cfg.writeEntry("bitrate", bits); |
1163 | filePara.resolution = bits; | 1165 | filePara.resolution = bits; |
1164 | cfg.write(); | 1166 | cfg.write(); |
1165 | } | 1167 | } |
1166 | 1168 | ||
1167 | void QtRec::changesamplerateCombo(int i) { | 1169 | void QtRec::changesamplerateCombo(int i) { |
1168 | Config cfg("OpieRec"); | 1170 | Config cfg("OpieRec"); |
1169 | cfg.setGroup("Settings"); | 1171 | cfg.setGroup("Settings"); |
1170 | int rate=0; | 1172 | int rate=0; |
1171 | bool ok; | 1173 | bool ok; |
1172 | rate = sampleRateComboBox->text(i).toInt(&ok, 10); | 1174 | rate = sampleRateComboBox->text(i).toInt(&ok, 10); |
1173 | cfg.writeEntry( "samplerate",rate); | 1175 | cfg.writeEntry( "samplerate",rate); |
1174 | filePara.sampleRate=rate; | 1176 | filePara.sampleRate=rate; |
1175 | odebug << "Change sample rate " << rate << "" << oendl; | 1177 | odebug << "Change sample rate " << rate << "" << oendl; |
1176 | cfg.write(); | 1178 | cfg.write(); |
1177 | } | 1179 | } |
1178 | 1180 | ||
1179 | 1181 | ||
1180 | void QtRec::changeDirCombo(int index) { | 1182 | void QtRec::changeDirCombo(int index) { |
1181 | Config cfg("OpieRec"); | 1183 | Config cfg("OpieRec"); |
1182 | cfg.setGroup("Settings"); | 1184 | cfg.setGroup("Settings"); |
1183 | QString sName = directoryComboBox->text(index); | 1185 | QString sName = directoryComboBox->text(index); |
1184 | 1186 | ||
1185 | StorageInfo storageInfo; | 1187 | StorageInfo storageInfo; |
1186 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1188 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1187 | QListIterator<FileSystem> it ( fs ); | 1189 | QListIterator<FileSystem> it ( fs ); |
1188 | QString storage; | 1190 | QString storage; |
1189 | for( ; it.current(); ++it ){ | 1191 | for( ; it.current(); ++it ){ |
1190 | if( sName == (*it)->name()+" "+ (*it)->path() || | 1192 | if( sName == (*it)->name()+" "+ (*it)->path() || |
1191 | (*it)->name() == sName ) { | 1193 | (*it)->name() == sName ) { |
1192 | const QString path = (*it)->path(); | 1194 | const QString path = (*it)->path(); |
1193 | recDir = path; | 1195 | recDir = path; |
1194 | cfg.writeEntry("directory", recDir); | 1196 | cfg.writeEntry("directory", recDir); |
1195 | odebug << "new rec dir "+recDir << oendl; | 1197 | odebug << "new rec dir "+recDir << oendl; |
1196 | } | 1198 | } |
1197 | } | 1199 | } |
1198 | cfg.write(); | 1200 | cfg.write(); |
1199 | } | 1201 | } |
1200 | 1202 | ||
1201 | 1203 | ||
1202 | void QtRec::changeSizeLimitCombo(int) { | 1204 | void QtRec::changeSizeLimitCombo(int) { |
1203 | Config cfg("OpieRec"); | 1205 | Config cfg("OpieRec"); |
1204 | cfg.setGroup("Settings"); | 1206 | cfg.setGroup("Settings"); |
1205 | cfg.writeEntry("sizeLimit", getCurrentSizeLimit() ); | 1207 | cfg.writeEntry("sizeLimit", getCurrentSizeLimit() ); |
1206 | cfg.write(); | 1208 | cfg.write(); |
1207 | } | 1209 | } |
1208 | 1210 | ||
1209 | void QtRec::newSound() { | 1211 | void QtRec::newSound() { |
1210 | if( !rec()) { | 1212 | if( !rec()) { |
1211 | endRecording(); | 1213 | endRecording(); |
1212 | deleteSound(); | 1214 | deleteSound(); |
1213 | } | 1215 | } |
1214 | } | 1216 | } |
1215 | 1217 | ||
1216 | void QtRec::itClick(QListViewItem *item) { | 1218 | void QtRec::itClick(QListViewItem *item) { |
1217 | currentFile = item->text(0); | 1219 | currentFile = item->text(0); |
1218 | setCaption("OpieRecord "+currentFile); | 1220 | setCaption("OpieRecord "+currentFile); |
1219 | } | 1221 | } |
1220 | 1222 | ||
1221 | void QtRec::deleteSound() { | 1223 | void QtRec::deleteSound() { |
1222 | Config cfg("OpieRec"); | 1224 | Config cfg("OpieRec"); |
1223 | cfg.setGroup("Sounds"); | 1225 | cfg.setGroup("Sounds"); |
1224 | if( ListView1->currentItem() == NULL) | 1226 | if( ListView1->currentItem() == NULL) |
1225 | return; | 1227 | return; |
1226 | // #ifndef DEV_VERSION | 1228 | // #ifndef DEV_VERSION |
1227 | // switch ( QMessageBox::warning(this,tr("Delete"), | 1229 | // switch ( QMessageBox::warning(this,tr("Delete"), |
1228 | // tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), | 1230 | // tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), |
1229 | // tr("Yes"),tr("No"),0,1,1) ) { | 1231 | // tr("Yes"),tr("No"),0,1,1) ) { |
1230 | // case 0: | 1232 | // case 0: |
1231 | // #endif | 1233 | // #endif |
1232 | // { | 1234 | // { |
1233 | QString file = ListView1->currentItem()->text(0); | 1235 | QString file = ListView1->currentItem()->text(0); |
1234 | QString fileName; | 1236 | QString fileName; |
1235 | fileName = cfg.readEntry( file, ""); | 1237 | fileName = cfg.readEntry( file, ""); |
1236 | QFile f( fileName); | 1238 | QFile f( fileName); |
1237 | if( f.exists()) | 1239 | if( f.exists()) |
1238 | if( !f.remove()) | 1240 | if( !f.remove()) |
1239 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); | 1241 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); |
1240 | 1242 | ||
1241 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1243 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1242 | bool found = false; | 1244 | bool found = false; |
1243 | for(int i=0;i<nFiles+1;i++) { | 1245 | for(int i=0;i<nFiles+1;i++) { |
1244 | 1246 | ||
1245 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { | 1247 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { |
1246 | found = true; | 1248 | found = true; |
1247 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1249 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1248 | } | 1250 | } |
1249 | if(found) | 1251 | if(found) |
1250 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1252 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1251 | } | 1253 | } |
1252 | 1254 | ||
1253 | cfg.removeEntry( cfg.readEntry( file)); | 1255 | cfg.removeEntry( cfg.readEntry( file)); |
1254 | cfg.removeEntry( file); | 1256 | cfg.removeEntry( file); |
1255 | cfg.writeEntry( "NumberofFiles", nFiles-1); | 1257 | cfg.writeEntry( "NumberofFiles", nFiles-1); |
1256 | cfg.write(); | 1258 | cfg.write(); |
1257 | 1259 | ||
1258 | ListView1->takeItem( ListView1->currentItem() ); | 1260 | ListView1->takeItem( ListView1->currentItem() ); |
1259 | delete ListView1->currentItem(); | 1261 | delete ListView1->currentItem(); |
1260 | 1262 | ||
1261 | ListView1->clear(); | 1263 | ListView1->clear(); |
1262 | ListView1->setSelected( ListView1->firstChild(), true); | 1264 | ListView1->setSelected( ListView1->firstChild(), true); |
1263 | initIconView(); | 1265 | initIconView(); |
1264 | update(); | 1266 | update(); |
1265 | setCaption( tr( "OpieRecord " )); | 1267 | setCaption( tr( "OpieRecord " )); |
1266 | } | 1268 | } |
1267 | 1269 | ||
1268 | void QtRec::keyPressEvent( QKeyEvent *e) { | 1270 | void QtRec::keyPressEvent( QKeyEvent *e) { |
1269 | 1271 | ||
1270 | switch ( e->key() ) { | 1272 | switch ( e->key() ) { |
1271 | // case Key_F1: | 1273 | // case Key_F1: |
1272 | // if(stopped && !recording) | 1274 | // if(stopped && !recording) |
1273 | // newSound(); | 1275 | // newSound(); |
1274 | // else | 1276 | // else |
1275 | // stop(); | 1277 | // stop(); |
1276 | // break; | 1278 | // break; |
1277 | // case Key_F2: { | 1279 | // case Key_F2: { |
1278 | // if( !e->isAutoRepeat()) | 1280 | // if( !e->isAutoRepeat()) |
1279 | // rewindPressed(); | 1281 | // rewindPressed(); |
1280 | // } | 1282 | // } |
1281 | // break; | 1283 | // break; |
1282 | // case Key_F3: { | 1284 | // case Key_F3: { |
1283 | // if( !e->isAutoRepeat()) | 1285 | // if( !e->isAutoRepeat()) |
1284 | // FastforwardPressed(); | 1286 | // FastforwardPressed(); |
1285 | // } | 1287 | // } |
1286 | // break; | 1288 | // break; |
1287 | 1289 | ||
1288 | ////////////////////////////// Zaurus keys | 1290 | ////////////////////////////// Zaurus keys |
1289 | case Key_F9: //activity | 1291 | case Key_F9: //activity |
1290 | break; | 1292 | break; |
1291 | case Key_F10: //contacts | 1293 | case Key_F10: //contacts |
1292 | break; | 1294 | break; |
1293 | case Key_F11: //menu | 1295 | case Key_F11: //menu |
1294 | break; | 1296 | break; |
1295 | case Key_F12: //home | 1297 | case Key_F12: //home |
1296 | break; | 1298 | break; |
1297 | case Key_F13: //mail | 1299 | case Key_F13: //mail |
1298 | break; | 1300 | break; |
1299 | case Key_Space: | 1301 | case Key_Space: |
1300 | break; | 1302 | break; |
1301 | case Key_Delete: | 1303 | case Key_Delete: |
1302 | break; | 1304 | break; |
1303 | case Key_Up: | 1305 | case Key_Up: |
1304 | // stop(); | 1306 | // stop(); |
1305 | break; | 1307 | break; |
1306 | case Key_Down: | 1308 | case Key_Down: |
1307 | // newSound(); | 1309 | // newSound(); |
1308 | break; | 1310 | break; |
1309 | case Key_Left: { | 1311 | case Key_Left: { |
1310 | odebug << "rewinding" << oendl; | 1312 | odebug << "rewinding" << oendl; |
1311 | if( !e->isAutoRepeat()) | 1313 | if( !e->isAutoRepeat()) |
1312 | rewindPressed(); | 1314 | rewindPressed(); |
1313 | } | 1315 | } |
1314 | break; | 1316 | break; |
1315 | case Key_Right: { | 1317 | case Key_Right: { |
1316 | if( !e->isAutoRepeat()) | 1318 | if( !e->isAutoRepeat()) |
1317 | FastforwardPressed(); | 1319 | FastforwardPressed(); |
1318 | } | 1320 | } |
1319 | break; | 1321 | break; |
1320 | } | 1322 | } |
1321 | } | 1323 | } |
1322 | 1324 | ||
1323 | void QtRec::keyReleaseEvent( QKeyEvent *e) { | 1325 | void QtRec::keyReleaseEvent( QKeyEvent *e) { |
1324 | switch ( e->key() ) { | 1326 | switch ( e->key() ) { |
1325 | // case Key_F1: | 1327 | // case Key_F1: |
1326 | // if(stopped && !recording) | 1328 | // if(stopped && !recording) |
1327 | // newSound(); | 1329 | // newSound(); |
1328 | // else | 1330 | // else |
1329 | // stop(); | 1331 | // stop(); |
1330 | // break; | 1332 | // break; |
1331 | // case Key_F2: | 1333 | // case Key_F2: |
1332 | // rewindReleased(); | 1334 | // rewindReleased(); |
1333 | // break; | 1335 | // break; |
1334 | // case Key_F3: | 1336 | // case Key_F3: |
1335 | // FastforwardReleased(); | 1337 | // FastforwardReleased(); |
1336 | // break; | 1338 | // break; |
1337 | 1339 | ||
1338 | ////////////////////////////// Zaurus keys | 1340 | ////////////////////////////// Zaurus keys |
1339 | case Key_F9: //activity | 1341 | case Key_F9: //activity |
1340 | break; | 1342 | break; |
1341 | case Key_F10: //contacts | 1343 | case Key_F10: //contacts |
1342 | break; | 1344 | break; |
1343 | case Key_F11: //menu | 1345 | case Key_F11: //menu |
1344 | break; | 1346 | break; |
1345 | case Key_F12: //home | 1347 | case Key_F12: //home |
1346 | if(stopped) | 1348 | if(stopped) |
1347 | doPlayBtn(); | 1349 | doPlayBtn(); |
1348 | else | 1350 | else |
1349 | stop(); | 1351 | stop(); |
1350 | break; | 1352 | break; |
1351 | case Key_F13: //mail | 1353 | case Key_F13: //mail |
1352 | break; | 1354 | break; |
1353 | case Key_Space: | 1355 | case Key_Space: |
1354 | if(stopped && !recording) | 1356 | if(stopped && !recording) |
1355 | newSound(); | 1357 | newSound(); |
1356 | else | 1358 | else |
1357 | stop(); | 1359 | stop(); |
1358 | break; | 1360 | break; |
1359 | case Key_Delete: | 1361 | case Key_Delete: |
1360 | deleteSound(); | 1362 | deleteSound(); |
1361 | break; | 1363 | break; |
1362 | case Key_Up: | 1364 | case Key_Up: |
1363 | // stop(); | 1365 | // stop(); |
1364 | odebug << "Up" << oendl; | 1366 | odebug << "Up" << oendl; |
1365 | break; | 1367 | break; |
1366 | case Key_Down: | 1368 | case Key_Down: |
1367 | // start(); | 1369 | // start(); |
1368 | // odebug << "Down" << oendl; | 1370 | // odebug << "Down" << oendl; |
1369 | // newSound(); | 1371 | // newSound(); |
1370 | break; | 1372 | break; |
1371 | case Key_Left: | 1373 | case Key_Left: |
1372 | odebug << "Left" << oendl; | 1374 | odebug << "Left" << oendl; |
1373 | rewindReleased(); | 1375 | rewindReleased(); |
1374 | break; | 1376 | break; |
1375 | case Key_Right: | 1377 | case Key_Right: |
1376 | odebug << "Right" << oendl; | 1378 | odebug << "Right" << oendl; |
1377 | FastforwardReleased(); | 1379 | FastforwardReleased(); |
1378 | break; | 1380 | break; |
1379 | } | 1381 | } |
1380 | } | 1382 | } |
1381 | 1383 | ||
1382 | void QtRec::endRecording() { | 1384 | void QtRec::endRecording() { |
1383 | 1385 | ||
1384 | monitoring = false; | 1386 | monitoring = false; |
1385 | recording = false; | 1387 | recording = false; |
1386 | stopped = true; | 1388 | stopped = true; |
1387 | waveform->reset(); | 1389 | waveform->reset(); |
1388 | setRecordButton( false); | 1390 | setRecordButton( false); |
1389 | 1391 | ||
1390 | toBeginningButton->setEnabled( true); | 1392 | toBeginningButton->setEnabled( true); |
1391 | toEndButton->setEnabled( true); | 1393 | toEndButton->setEnabled( true); |
1392 | 1394 | ||
1393 | killTimers(); | 1395 | killTimers(); |
1394 | 1396 | ||
1395 | if(autoMute) | 1397 | if(autoMute) |
1396 | doMute( true); | 1398 | doMute( true); |
1397 | 1399 | ||
1398 | soundDevice->closeDevice( true); | 1400 | soundDevice->closeDevice( true); |
1399 | 1401 | ||
1400 | if( wavFile->track.isOpen()) { | 1402 | if( wavFile->track.isOpen()) { |
1401 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); | 1403 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); |
1402 | // soundDevice->sd=-1; | 1404 | // soundDevice->sd=-1; |
1403 | filePara.numberSamples = 0; | 1405 | filePara.numberSamples = 0; |
1404 | // filePara.sd=-1; | 1406 | // filePara.sd=-1; |
1405 | wavFile->closeFile(); | 1407 | wavFile->closeFile(); |
1406 | filePara.fd=0; | 1408 | filePara.fd=0; |
1407 | 1409 | ||
1408 | if( wavFile->isTempFile()) { | 1410 | if( wavFile->isTempFile()) { |
1409 | // move tmp file to regular file | 1411 | // move tmp file to regular file |
1410 | QString cmd; | 1412 | QString cmd; |
1411 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); | 1413 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); |
1412 | odebug << "moving tmp file to "+currentFileName << oendl; | 1414 | odebug << "moving tmp file to "+currentFileName << oendl; |
1413 | system( cmd.latin1()); | 1415 | system( cmd.latin1()); |
1414 | } | 1416 | } |
1415 | 1417 | ||
1416 | odebug << "Just moved " + wavFile->currentFileName << oendl; | 1418 | odebug << "Just moved " + wavFile->currentFileName << oendl; |
1417 | Config cfg("OpieRec"); | 1419 | Config cfg("OpieRec"); |
1418 | cfg.setGroup("Sounds"); | 1420 | cfg.setGroup("Sounds"); |
1419 | 1421 | ||
1420 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1422 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1421 | 1423 | ||
1422 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); | 1424 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); |
1423 | currentFile = currentFile.left( currentFile.length() - 4); | 1425 | currentFile = currentFile.left( currentFile.length() - 4); |
1424 | 1426 | ||
1425 | cfg.writeEntry( "NumberofFiles", nFiles + 1); | 1427 | cfg.writeEntry( "NumberofFiles", nFiles + 1); |
1426 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); | 1428 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); |
1427 | cfg.writeEntry( currentFile, wavFile->currentFileName); | 1429 | cfg.writeEntry( currentFile, wavFile->currentFileName); |
1428 | 1430 | ||
1429 | QString time; | 1431 | QString time; |
1430 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 1432 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
1431 | cfg.writeEntry( wavFile->currentFileName, time ); | 1433 | cfg.writeEntry( wavFile->currentFileName, time ); |
1432 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 1434 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
1433 | 1435 | ||
1434 | cfg.write(); | 1436 | cfg.write(); |
1435 | odebug << "finished recording" << oendl; | 1437 | odebug << "finished recording" << oendl; |
1436 | // timeLabel->setText(""); | 1438 | // timeLabel->setText(""); |
1437 | } | 1439 | } |
1438 | 1440 | ||
1439 | // if(soundDevice) delete soundDevice; | 1441 | // if(soundDevice) delete soundDevice; |
1440 | 1442 | ||
1441 | timeSlider->setValue(0); | 1443 | timeSlider->setValue(0); |
1442 | initIconView(); | 1444 | initIconView(); |
1443 | selectItemByName( currentFile); | 1445 | selectItemByName( currentFile); |
1444 | setCaption( tr( "OpieRecord " )); | 1446 | setCaption( tr( "OpieRecord " )); |
1445 | 1447 | ||
1446 | } | 1448 | } |
1447 | 1449 | ||
1448 | void QtRec::endPlaying() { | 1450 | void QtRec::endPlaying() { |
1449 | monitoring = false; | 1451 | monitoring = false; |
1450 | recording = false; | 1452 | recording = false; |
1451 | playing = false; | 1453 | playing = false; |
1452 | stopped = true; | 1454 | stopped = true; |
1453 | waveform->reset(); | 1455 | waveform->reset(); |
1454 | // errorStop(); | 1456 | // errorStop(); |
1455 | odebug << "end playing" << oendl; | 1457 | odebug << "end playing" << oendl; |
1456 | setRecordButton( false); | 1458 | setRecordButton( false); |
1457 | 1459 | ||
1458 | toBeginningButton->setEnabled( true); | 1460 | toBeginningButton->setEnabled( true); |
1459 | toEndButton->setEnabled( true); | 1461 | toEndButton->setEnabled( true); |
1460 | 1462 | ||
1461 | if(autoMute) | 1463 | if(autoMute) |
1462 | doMute( true); | 1464 | doMute( true); |
1463 | 1465 | ||
1464 | soundDevice->closeDevice( false); | 1466 | soundDevice->closeDevice( false); |
1465 | soundDevice->sd = -1; | 1467 | soundDevice->sd = -1; |
1466 | // if(soundDevice) delete soundDevice; | 1468 | // if(soundDevice) delete soundDevice; |
1467 | odebug << "file and sound device closed" << oendl; | 1469 | odebug << "file and sound device closed" << oendl; |
1468 | // timeLabel->setText(""); | 1470 | // timeLabel->setText(""); |
1469 | total = 0; | 1471 | total = 0; |
1470 | filePara.numberSamples = 0; | 1472 | filePara.numberSamples = 0; |
1471 | filePara.sd = -1; | 1473 | filePara.sd = -1; |
1472 | // wavFile->closeFile(); | 1474 | // wavFile->closeFile(); |
1473 | filePara.fd = 0; | 1475 | filePara.fd = 0; |
1474 | // if(wavFile) delete wavFile; //this crashes | 1476 | // if(wavFile) delete wavFile; //this crashes |
1475 | 1477 | ||
1476 | odebug << "track closed" << oendl; | 1478 | odebug << "track closed" << oendl; |
1477 | killTimers(); | 1479 | killTimers(); |
1478 | // owarn << "reset slider" << oendl; | 1480 | // owarn << "reset slider" << oendl; |
1479 | timeSlider->setValue(0); | 1481 | timeSlider->setValue(0); |
1480 | 1482 | ||
1481 | // if(soundDevice) delete soundDevice; | 1483 | // if(soundDevice) delete soundDevice; |
1482 | 1484 | ||
1483 | } | 1485 | } |
1484 | 1486 | ||
1485 | bool QtRec::openPlayFile() { | 1487 | bool QtRec::openPlayFile() { |
1486 | 1488 | qWarning("opening file"); | |
1487 | qApp->processEvents(); | 1489 | qApp->processEvents(); |
1488 | if( currentFile.isEmpty()) { | 1490 | if( currentFile.isEmpty()) { |
1489 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); | 1491 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); |
1490 | endPlaying(); | 1492 | endPlaying(); |
1491 | return false; | 1493 | return false; |
1492 | } | 1494 | } |
1493 | QString currentFileName; | 1495 | QString currentFileName; |
1494 | Config cfg("OpieRec"); | 1496 | Config cfg("OpieRec"); |
1495 | cfg.setGroup("Sounds"); | 1497 | cfg.setGroup("Sounds"); |
1496 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); | 1498 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); |
1497 | for(int i=0;i<nFiles+1;i++) { //look for file | 1499 | for(int i=0;i<nFiles+1;i++) { //look for file |
1498 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { | 1500 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { |
1499 | currentFileName = cfg.readEntry( currentFile, "" ); | 1501 | currentFileName = cfg.readEntry( currentFile, "" ); |
1500 | odebug << "opening for play: " + currentFileName << oendl; | 1502 | odebug << "opening for play: " + currentFileName << oendl; |
1501 | } | 1503 | } |
1502 | } | 1504 | } |
1503 | wavFile = new WavFile(this, | 1505 | wavFile = new WavFile(this, |
1504 | currentFileName, | 1506 | currentFileName, |
1505 | false); | 1507 | false); |
1506 | filePara.fd = wavFile->wavHandle(); | 1508 | filePara.fd = wavFile->wavHandle(); |
1507 | if(filePara.fd == -1) { | 1509 | if(filePara.fd == -1) { |
1508 | // if(!track.open(IO_ReadOnly)) { | 1510 | // if(!track.open(IO_ReadOnly)) { |
1509 | QString errorMsg = (QString)strerror(errno); | 1511 | QString errorMsg = (QString)strerror(errno); |
1510 | monitoring = false; | 1512 | monitoring = false; |
1511 | setCaption( tr( "OpieRecord " )); | 1513 | setCaption( tr( "OpieRecord " )); |
1512 | QMessageBox::message(tr("Note"), tr("Could not open audio file.\n") | 1514 | QMessageBox::message(tr("Note"), tr("Could not open audio file.\n") |
1513 | + errorMsg + "\n" + currentFile); | 1515 | + errorMsg + "\n" + currentFile); |
1514 | return false; | 1516 | return false; |
1515 | } else { | 1517 | } else { |
1516 | 1518 | ||
1517 | filePara.numberSamples = wavFile->getNumberSamples(); | 1519 | filePara.numberSamples = wavFile->getNumberSamples(); |
1518 | filePara.format = wavFile->getFormat(); | 1520 | filePara.format = wavFile->getFormat(); |
1519 | filePara.sampleRate = wavFile->getSampleRate(); | 1521 | filePara.sampleRate = wavFile->getSampleRate(); |
1520 | filePara.resolution = wavFile->getResolution(); | 1522 | filePara.resolution = wavFile->getResolution(); |
1521 | filePara.channels = wavFile->getChannels(); | 1523 | filePara.channels = wavFile->getChannels(); |
1522 | timeSlider->setPageStep(1); | 1524 | timeSlider->setPageStep(1); |
1523 | monitoring = true; | 1525 | monitoring = true; |
1524 | 1526 | ||
1525 | odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl; | 1527 | odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl; |
1526 | int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8)); | 1528 | int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8)); |
1527 | 1529 | ||
1528 | // owarn << "seconds " << sec << "" << oendl; | 1530 | // owarn << "seconds " << sec << "" << oendl; |
1529 | 1531 | ||
1530 | timeSlider->setRange(0, filePara.numberSamples ); | 1532 | timeSlider->setRange(0, filePara.numberSamples ); |
1531 | } | 1533 | } |
1532 | 1534 | ||
1533 | return true; | 1535 | return true; |
1534 | } | 1536 | } |
1535 | 1537 | ||
1536 | void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) { | 1538 | void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) { |
1537 | if(item == NULL ) | 1539 | if(item == NULL ) |
1538 | return; | 1540 | return; |
1539 | switch (mouse) { | 1541 | switch (mouse) { |
1540 | case 1: { | 1542 | case 1: { |
1541 | if( renameBox != 0 ) //tricky | 1543 | if( renameBox != 0 ) //tricky |
1542 | cancelRename(); | 1544 | cancelRename(); |
1543 | 1545 | ||
1544 | currentFile = item->text(0); | 1546 | currentFile = item->text(0); |
1545 | // setCaption( "OpieRecord " + currentFile); | 1547 | // setCaption( "OpieRecord " + currentFile); |
1546 | } | 1548 | } |
1547 | break; | 1549 | break; |
1548 | case 2: | 1550 | case 2: |
1549 | showListMenu(item); | 1551 | showListMenu(item); |
1550 | ListView1->clearSelection(); | 1552 | ListView1->clearSelection(); |
1551 | break; | 1553 | break; |
1552 | }; | 1554 | }; |
1553 | } | 1555 | } |
1554 | 1556 | ||
1555 | void QtRec::showListMenu(QListViewItem * item) { | 1557 | void QtRec::showListMenu(QListViewItem * item) { |
1556 | if(item == NULL) | 1558 | if(item == NULL) |
1557 | return; | 1559 | return; |
1558 | QPopupMenu *m = new QPopupMenu(this); | 1560 | QPopupMenu *m = new QPopupMenu(this); |
1559 | m->insertItem( tr("Play"), this, SLOT( doMenuPlay() )); | 1561 | m->insertItem( tr("Play"), this, SLOT( doMenuPlay() )); |
1560 | if(Ir::supported()) m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() )); | 1562 | if(Ir::supported()) m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() )); |
1561 | m->insertItem( tr( "Rename" ), this, SLOT( doRename() )); | 1563 | m->insertItem( tr( "Rename" ), this, SLOT( doRename() )); |
1562 | // #if defined (QTOPIA_INTERNAL_FSLP) | 1564 | // #if defined (QTOPIA_INTERNAL_FSLP) |
1563 | // m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | 1565 | // m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); |
1564 | // #endif | 1566 | // #endif |
1565 | m->insertSeparator(); | 1567 | m->insertSeparator(); |
1566 | m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) ); | 1568 | m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) ); |
1567 | m->exec( QCursor::pos() ); | 1569 | m->exec( QCursor::pos() ); |
1568 | qApp->processEvents(); | 1570 | qApp->processEvents(); |
1569 | } | 1571 | } |
1570 | 1572 | ||
1571 | void QtRec::fileBeamFinished( Ir *ir) { | 1573 | void QtRec::fileBeamFinished( Ir *ir) { |
1572 | if(ir) | 1574 | if(ir) |
1573 | QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") ); | 1575 | QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") ); |
1574 | 1576 | ||
1575 | } | 1577 | } |
1576 | 1578 | ||
1577 | void QtRec::doBeam() { | 1579 | void QtRec::doBeam() { |
1578 | qApp->processEvents(); | 1580 | qApp->processEvents(); |
1579 | if( ListView1->currentItem() == NULL) | 1581 | if( ListView1->currentItem() == NULL) |
1580 | return; | 1582 | return; |
1581 | Ir ir; | 1583 | Ir ir; |
1582 | if( ir.supported()) { | 1584 | if( ir.supported()) { |
1583 | QString file = ListView1->currentItem()->text(0); | 1585 | QString file = ListView1->currentItem()->text(0); |
1584 | Config cfg("OpieRec"); | 1586 | Config cfg("OpieRec"); |
1585 | cfg.setGroup("Sounds"); | 1587 | cfg.setGroup("Sounds"); |
1586 | 1588 | ||
1587 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 1589 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
1588 | 1590 | ||
1589 | for(int i=0;i<nFiles+1;i++) { | 1591 | for(int i=0;i<nFiles+1;i++) { |
1590 | if( cfg.readEntry( QString::number( i),"").find( file, 0, true) != -1) { | 1592 | if( cfg.readEntry( QString::number( i),"").find( file, 0, true) != -1) { |
1591 | QString filePath = cfg.readEntry(file,""); | 1593 | QString filePath = cfg.readEntry(file,""); |
1592 | Ir *file = new Ir(this, "IR"); | 1594 | Ir *file = new Ir(this, "IR"); |
1593 | connect( file, SIGNAL( done(Ir*)), | 1595 | connect( file, SIGNAL( done(Ir*)), |
1594 | this, SLOT( fileBeamFinished(Ir*))); | 1596 | this, SLOT( fileBeamFinished(Ir*))); |
1595 | file->send( filePath, "OPieRec audio file\n" + filePath ); | 1597 | file->send( filePath, "OPieRec audio file\n" + filePath ); |
1596 | } | 1598 | } |
1597 | } | 1599 | } |
1598 | } | 1600 | } |
1599 | } | 1601 | } |
1600 | 1602 | ||
1601 | void QtRec::doMenuPlay() { | 1603 | void QtRec::doMenuPlay() { |
1602 | qApp->processEvents(); | 1604 | qApp->processEvents(); |
1603 | currentFile = ListView1->currentItem()->text(0); | 1605 | currentFile = ListView1->currentItem()->text(0); |
1604 | } | 1606 | } |
1605 | 1607 | ||
1606 | void QtRec::doRename() { | 1608 | void QtRec::doRename() { |
1607 | QRect r = ListView1->itemRect( ListView1->currentItem( )); | 1609 | QRect r = ListView1->itemRect( ListView1->currentItem( )); |
1608 | r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() ); | 1610 | r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() ); |
1609 | r.setX( ListView1->contentsX() ); | 1611 | r.setX( ListView1->contentsX() ); |
1610 | if ( r.width() > ListView1->visibleWidth() ) | 1612 | if ( r.width() > ListView1->visibleWidth() ) |
1611 | r.setWidth( ListView1->visibleWidth() ); | 1613 | r.setWidth( ListView1->visibleWidth() ); |
1612 | 1614 | ||
1613 | renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" ); | 1615 | renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" ); |
1614 | renameBox->setFrame(true); | 1616 | renameBox->setFrame(true); |
1615 | 1617 | ||
1616 | renameBox->setText( ListView1->currentItem()->text(0) ); | 1618 | renameBox->setText( ListView1->currentItem()->text(0) ); |
1617 | 1619 | ||
1618 | renameBox->selectAll(); | 1620 | renameBox->selectAll(); |
1619 | renameBox->installEventFilter( this ); | 1621 | renameBox->installEventFilter( this ); |
1620 | ListView1->addChild( renameBox, r.x(), r.y() ); | 1622 | ListView1->addChild( renameBox, r.x(), r.y() ); |
1621 | renameBox->resize( r.size() ); | 1623 | renameBox->resize( r.size() ); |
1622 | ListView1->viewport()->setFocusProxy( renameBox ); | 1624 | ListView1->viewport()->setFocusProxy( renameBox ); |
1623 | renameBox->setFocus(); | 1625 | renameBox->setFocus(); |
1624 | renameBox->show(); | 1626 | renameBox->show(); |
1625 | 1627 | ||
1626 | } | 1628 | } |
1627 | 1629 | ||
1628 | void QtRec::okRename() { | 1630 | void QtRec::okRename() { |
1629 | odebug << renameBox->text() << oendl; | 1631 | odebug << renameBox->text() << oendl; |
1630 | QString filename = renameBox->text(); | 1632 | QString filename = renameBox->text(); |
1631 | cancelRename(); | 1633 | cancelRename(); |
1632 | 1634 | ||
1633 | if( ListView1->currentItem() == NULL) | 1635 | if( ListView1->currentItem() == NULL) |
1634 | return; | 1636 | return; |
1635 | 1637 | ||
1636 | Config cfg("OpieRec"); | 1638 | Config cfg("OpieRec"); |
1637 | cfg.setGroup("Sounds"); | 1639 | cfg.setGroup("Sounds"); |
1638 | 1640 | ||
1639 | QString file = ListView1->currentItem()->text(0); | 1641 | QString file = ListView1->currentItem()->text(0); |
1640 | 1642 | ||
1641 | odebug << "filename is " + filename << oendl; | 1643 | odebug << "filename is " + filename << oendl; |
1642 | 1644 | ||
1643 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 1645 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
1644 | 1646 | ||
1645 | for(int i=0;i<nFiles+1;i++) { //look for file | 1647 | for(int i=0;i<nFiles+1;i++) { //look for file |
1646 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { | 1648 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { |
1647 | 1649 | ||
1648 | QString filePath = cfg.readEntry(file,""); | 1650 | QString filePath = cfg.readEntry(file,""); |
1649 | 1651 | ||
1650 | cfg.writeEntry( QString::number(i), filename ); | 1652 | cfg.writeEntry( QString::number(i), filename ); |
1651 | cfg.writeEntry( filename, filePath ); | 1653 | cfg.writeEntry( filename, filePath ); |
1652 | cfg.removeEntry( file); | 1654 | cfg.removeEntry( file); |
1653 | cfg.write(); | 1655 | cfg.write(); |
1654 | } | 1656 | } |
1655 | } | 1657 | } |
1656 | 1658 | ||
1657 | ListView1->takeItem( ListView1->currentItem() ); | 1659 | ListView1->takeItem( ListView1->currentItem() ); |
1658 | delete ListView1->currentItem(); | 1660 | delete ListView1->currentItem(); |
1659 | ListView1->clear(); | 1661 | ListView1->clear(); |
1660 | initIconView(); | 1662 | initIconView(); |
1661 | update(); | 1663 | update(); |
1662 | } | 1664 | } |
1663 | 1665 | ||
1664 | void QtRec::cancelRename() { | 1666 | void QtRec::cancelRename() { |
1665 | bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; | 1667 | bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; |
1666 | delete renameBox; | 1668 | delete renameBox; |
1667 | renameBox = 0; | 1669 | renameBox = 0; |
1668 | if ( resetFocus ) { | 1670 | if ( resetFocus ) { |
1669 | ListView1->viewport()->setFocusProxy( ListView1 ); | 1671 | ListView1->viewport()->setFocusProxy( ListView1 ); |
1670 | ListView1->setFocus(); | 1672 | ListView1->setFocus(); |
1671 | } | 1673 | } |
1672 | } | 1674 | } |
1673 | 1675 | ||
1674 | bool QtRec::eventFilter( QObject * o, QEvent * e ) { | 1676 | bool QtRec::eventFilter( QObject * o, QEvent * e ) { |
1675 | if ( o->inherits( "QLineEdit" ) ) { | 1677 | if ( o->inherits( "QLineEdit" ) ) { |
1676 | if ( e->type() == QEvent::KeyPress ) { | 1678 | if ( e->type() == QEvent::KeyPress ) { |
1677 | QKeyEvent *ke = (QKeyEvent*)e; | 1679 | QKeyEvent *ke = (QKeyEvent*)e; |
1678 | if ( ke->key() == Key_Return || | 1680 | if ( ke->key() == Key_Return || |
1679 | ke->key() == Key_Enter ) { | 1681 | ke->key() == Key_Enter ) { |
1680 | okRename(); | 1682 | okRename(); |
1681 | return true; | 1683 | return true; |
1682 | } else if ( ke->key() == Key_Escape ) { | 1684 | } else if ( ke->key() == Key_Escape ) { |
1683 | cancelRename(); | 1685 | cancelRename(); |
1684 | return true; | 1686 | return true; |
1685 | } | 1687 | } |
1686 | } else if ( e->type() == QEvent::FocusOut ) { | 1688 | } else if ( e->type() == QEvent::FocusOut ) { |
1687 | cancelRename(); | 1689 | cancelRename(); |
1688 | return true; | 1690 | return true; |
1689 | } | 1691 | } |
1690 | } | 1692 | } |
1691 | return QWidget::eventFilter( o, e ); | 1693 | return QWidget::eventFilter( o, e ); |
1692 | } | 1694 | } |
1693 | 1695 | ||
1694 | 1696 | ||
1695 | int QtRec::getCurrentSizeLimit() { | 1697 | int QtRec::getCurrentSizeLimit() { |
1696 | return sizeLimitCombo->currentItem() * 5; | 1698 | return sizeLimitCombo->currentItem() * 5; |
1697 | } | 1699 | } |
1698 | 1700 | ||
1699 | void QtRec::timerBreak() { | 1701 | void QtRec::timerBreak() { |
1700 | endPlaying(); | 1702 | endPlaying(); |
1701 | } | 1703 | } |
1702 | 1704 | ||
1703 | void QtRec::doVolMuting(bool b) { | 1705 | void QtRec::doVolMuting(bool b) { |
1704 | Config cfg( "qpe" ); | 1706 | Config cfg( "qpe" ); |
1705 | cfg. setGroup( "Volume" ); | 1707 | cfg. setGroup( "Volume" ); |
1706 | cfg.writeEntry( "Mute",b); | 1708 | cfg.writeEntry( "Mute",b); |
1707 | cfg.write(); | 1709 | cfg.write(); |
1708 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; | 1710 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; |
1709 | } | 1711 | } |
1710 | 1712 | ||
1711 | void QtRec::doMicMuting(bool b) { | 1713 | void QtRec::doMicMuting(bool b) { |
1712 | // odebug << "mic mute" << oendl; | 1714 | // odebug << "mic mute" << oendl; |
1713 | Config cfg( "qpe" ); | 1715 | Config cfg( "qpe" ); |
1714 | cfg. setGroup( "Volume" ); | 1716 | cfg. setGroup( "Volume" ); |
1715 | cfg.writeEntry( "MicMute",b); | 1717 | cfg.writeEntry( "MicMute",b); |
1716 | cfg.write(); | 1718 | cfg.write(); |
1717 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; | 1719 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; |
1718 | } | 1720 | } |
1719 | 1721 | ||
1720 | void QtRec::compressionSelected(bool b) { | 1722 | void QtRec::compressionSelected(bool b) { |
1721 | Config cfg("OpieRec"); | 1723 | Config cfg("OpieRec"); |
1722 | cfg.setGroup("Settings"); | 1724 | cfg.setGroup("Settings"); |
1723 | cfg.writeEntry("wavCompression", b); | 1725 | cfg.writeEntry("wavCompression", b); |
1724 | cfg.writeEntry("bitrate", 16); | 1726 | cfg.writeEntry("bitrate", 16); |
1725 | filePara.resolution = 16; | 1727 | filePara.resolution = 16; |
1726 | cfg.write(); | 1728 | cfg.write(); |
1727 | 1729 | ||
1728 | if(b) { | 1730 | if(b) { |
1729 | bitRateComboBox->setEnabled( false); | 1731 | qWarning("set adpcm"); |
1730 | bitRateComboBox->setCurrentItem( 1); | 1732 | bitRateComboBox->setCurrentItem( 1); |
1733 | bitRateComboBox->setEnabled( false); | ||
1731 | filePara.resolution = 16; | 1734 | filePara.resolution = 16; |
1732 | } else{ | 1735 | } else{ |
1733 | bitRateComboBox->setEnabled( true); | 1736 | bitRateComboBox->setEnabled( true); |
1734 | } | 1737 | } |
1735 | } | 1738 | } |
1736 | 1739 | ||
1737 | long QtRec::checkDiskSpace(const QString &path) { | 1740 | long QtRec::checkDiskSpace(const QString &path) { |
1738 | 1741 | ||
1739 | struct statfs fs; | 1742 | struct statfs fs; |
1740 | 1743 | ||
1741 | if ( !statfs( path.latin1(), &fs ) ) { | 1744 | if ( !statfs( path.latin1(), &fs ) ) { |
1742 | 1745 | ||
1743 | int blkSize = fs.f_bsize; | 1746 | int blkSize = fs.f_bsize; |
1744 | int availBlks = fs.f_bavail; | 1747 | int availBlks = fs.f_bavail; |
1745 | 1748 | ||
1746 | long mult = blkSize / 1024; | 1749 | long mult = blkSize / 1024; |
1747 | long div = 1024 / blkSize; | 1750 | long div = 1024 / blkSize; |
1748 | 1751 | ||
1749 | if ( !mult ) mult = 1; | 1752 | if ( !mult ) mult = 1; |
1750 | if ( !div ) div = 1; | 1753 | if ( !div ) div = 1; |
1751 | 1754 | ||
1752 | return availBlks * mult / div; | 1755 | return availBlks * mult / div; |
1753 | } | 1756 | } |
1754 | return -1; | 1757 | return -1; |
1755 | } | 1758 | } |
1756 | 1759 | ||
1757 | // short f_fstyp; /* File system type */ | 1760 | // short f_fstyp; /* File system type */ |
1758 | // long f_bsize; /* Block size */ | 1761 | // long f_bsize; /* Block size */ |
1759 | // long f_frsize; /* Fragment size */ | 1762 | // long f_frsize; /* Fragment size */ |
1760 | // long f_blocks; /* Total number of blocks*/ | 1763 | // long f_blocks; /* Total number of blocks*/ |
1761 | // long f_bfree; /* Count of free blocks */ | 1764 | // long f_bfree; /* Count of free blocks */ |
1762 | // long f_files; /* Total number of file nodes */ | 1765 | // long f_files; /* Total number of file nodes */ |
1763 | // long f_ffree; /* Count of free file nodes */ | 1766 | // long f_ffree; /* Count of free file nodes */ |
1764 | // char f_fname[6]; /* Volumename */ | 1767 | // char f_fname[6]; /* Volumename */ |
1765 | // char f_fpack[6]; /* Pack name */ | 1768 | // char f_fpack[6]; /* Pack name */ |
1766 | 1769 | ||
1767 | void QtRec::receive( const QCString &msg, const QByteArray & ) { | 1770 | void QtRec::receive( const QCString &msg, const QByteArray & ) { |
1768 | odebug << "Voicerecord received message "+msg << oendl; | 1771 | odebug << "Voicerecord received message "+msg << oendl; |
1769 | 1772 | ||
1770 | } | 1773 | } |
1771 | 1774 | ||
1772 | 1775 | ||
1773 | ///////////////////////////// timerEvent | 1776 | ///////////////////////////// timerEvent |
1774 | void QtRec::timerEvent( QTimerEvent * ) { | 1777 | void QtRec::timerEvent( QTimerEvent * ) { |
1775 | 1778 | ||
1776 | // if(!recording) | 1779 | // if(!recording) |
1777 | // timeSlider->setValue( secCount); | 1780 | // timeSlider->setValue( secCount); |
1778 | // else | 1781 | // else |
1779 | // timeSlider->setValue( filePara.numberOfRecordedSeconds); | 1782 | // timeSlider->setValue( filePara.numberOfRecordedSeconds); |
1780 | 1783 | ||
1781 | if( stopped && playing) { | 1784 | if( stopped && playing) { |
1782 | stop(); | 1785 | stop(); |
1783 | } | 1786 | } |
1784 | 1787 | ||
1785 | if( stopped && recording ){ | 1788 | if( stopped && recording ){ |
1786 | stop(); | 1789 | stop(); |
1787 | } | 1790 | } |
1788 | 1791 | ||
1789 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { | 1792 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { |
1790 | stop(); | 1793 | stop(); |
1791 | } | 1794 | } |
1792 | 1795 | ||
1793 | odebug << "" << secCount << "" << oendl; | 1796 | odebug << "" << secCount << "" << oendl; |
1794 | QString timeString; | 1797 | QString timeString; |
1795 | 1798 | ||
1796 | timeString.sprintf("%d", secCount); | 1799 | timeString.sprintf("%d", secCount); |
1797 | // timeLabel->setText( timeString + " seconds"); | 1800 | // timeLabel->setText( timeString + " seconds"); |
1798 | 1801 | ||
1799 | secCount++; | 1802 | secCount++; |
1800 | } | 1803 | } |
1801 | 1804 | ||
1802 | void QtRec::changeTimeSlider(int index) { | 1805 | void QtRec::changeTimeSlider(int index) { |
1803 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; | 1806 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; |
1804 | odebug << "Slider moved to " << index << "" << oendl; | 1807 | odebug << "Slider moved to " << index << "" << oendl; |
1805 | paused = true; | 1808 | paused = true; |
1806 | stopped = true; | 1809 | stopped = true; |
1807 | 1810 | ||
1808 | sliderPos=index; | 1811 | sliderPos=index; |
1809 | 1812 | ||
1810 | QString timeString; | 1813 | QString timeString; |
1811 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1814 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1812 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1815 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1813 | secCount = (int)filePara.numberOfRecordedSeconds; | 1816 | secCount = (int)filePara.numberOfRecordedSeconds; |
1814 | // timeLabel->setText( timeString + tr(" seconds")); | 1817 | // timeLabel->setText( timeString + tr(" seconds")); |
1815 | } | 1818 | } |
1816 | 1819 | ||
1817 | void QtRec::timeSliderPressed() { | 1820 | void QtRec::timeSliderPressed() { |
1818 | if( ListView1->currentItem() == 0) return; | 1821 | if( ListView1->currentItem() == 0) return; |
1819 | odebug << "slider pressed" << oendl; | 1822 | odebug << "slider pressed" << oendl; |
1820 | paused = true; | 1823 | paused = true; |
1821 | stopped = true; | 1824 | stopped = true; |
1822 | } | 1825 | } |
1823 | 1826 | ||
1824 | void QtRec::timeSliderReleased() { | 1827 | void QtRec::timeSliderReleased() { |
1825 | if( ListView1->currentItem() == 0) return; | 1828 | if( ListView1->currentItem() == 0) return; |
1826 | sliderPos = timeSlider->value(); | 1829 | sliderPos = timeSlider->value(); |
1827 | 1830 | ||
1828 | odebug << "slider released " << sliderPos << "" << oendl; | 1831 | odebug << "slider released " << sliderPos << "" << oendl; |
1829 | stopped = false; | 1832 | stopped = false; |
1830 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1833 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1831 | total = newPos*4; | 1834 | total = newPos*4; |
1832 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1835 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1833 | 1836 | ||
1834 | doPlay(); | 1837 | doPlay(); |
1835 | } | 1838 | } |
1836 | 1839 | ||
1837 | void QtRec::rewindPressed() { | 1840 | void QtRec::rewindPressed() { |
1838 | if( ListView1->currentItem() == 0) return; | 1841 | if( ListView1->currentItem() == 0) return; |
1839 | if( !wavFile->track.isOpen()) { | 1842 | if( !wavFile->track.isOpen()) { |
1840 | if( !openPlayFile() ) | 1843 | if( !openPlayFile() ) |
1841 | return; | 1844 | return; |
1842 | else | 1845 | else |
1843 | if( !setupAudio( false)) | 1846 | if( !setupAudio( false)) |
1844 | return; | 1847 | return; |
1845 | } else { | 1848 | } else { |
1846 | killTimers(); | 1849 | killTimers(); |
1847 | paused = true; | 1850 | paused = true; |
1848 | stopped = true; | 1851 | stopped = true; |
1849 | rewindTimer->start( 50, false); | 1852 | rewindTimer->start( 50, false); |
1850 | } | 1853 | } |
1851 | } | 1854 | } |
1852 | 1855 | ||
1853 | void QtRec::rewindTimerTimeout() { | 1856 | void QtRec::rewindTimerTimeout() { |
1854 | int sliderValue = timeSlider->value(); | 1857 | int sliderValue = timeSlider->value(); |
1855 | sliderValue = sliderValue - ( filePara.numberSamples / 100); | 1858 | sliderValue = sliderValue - ( filePara.numberSamples / 100); |
1856 | // if(toBeginningButton->isDown()) | 1859 | // if(toBeginningButton->isDown()) |
1857 | timeSlider->setValue( sliderValue ) ; | 1860 | timeSlider->setValue( sliderValue ) ; |
1858 | odebug << "" << sliderValue << "" << oendl; | 1861 | odebug << "" << sliderValue << "" << oendl; |
1859 | QString timeString; | 1862 | QString timeString; |
1860 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; | 1863 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; |
1861 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1864 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1862 | // timeLabel->setText( timeString+ tr(" seconds")); | 1865 | // timeLabel->setText( timeString+ tr(" seconds")); |
1863 | } | 1866 | } |
1864 | 1867 | ||
1865 | void QtRec::rewindReleased() { | 1868 | void QtRec::rewindReleased() { |
1866 | rewindTimer->stop(); | 1869 | rewindTimer->stop(); |
1867 | if( wavFile->track.isOpen()) { | 1870 | if( wavFile->track.isOpen()) { |
1868 | sliderPos=timeSlider->value(); | 1871 | sliderPos=timeSlider->value(); |
1869 | stopped = false; | 1872 | stopped = false; |
1870 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1873 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1871 | total = newPos * 4; | 1874 | total = newPos * 4; |
1872 | odebug << "rewind released " << total << "" << oendl; | 1875 | odebug << "rewind released " << total << "" << oendl; |
1873 | startTimer( 1000); | 1876 | startTimer( 1000); |
1874 | doPlay(); | 1877 | doPlay(); |
1875 | } | 1878 | } |
1876 | } | 1879 | } |
1877 | 1880 | ||
1878 | void QtRec::FastforwardPressed() { | 1881 | void QtRec::FastforwardPressed() { |
1879 | if( ListView1->currentItem() == 0) return; | 1882 | if( ListView1->currentItem() == 0) return; |
1880 | if( !wavFile->track.isOpen()) | 1883 | if( !wavFile->track.isOpen()) |
1881 | if( !openPlayFile() ) | 1884 | if( !openPlayFile() ) |
1882 | return; | 1885 | return; |
1883 | else | 1886 | else |
1884 | if( !setupAudio( false)) | 1887 | if( !setupAudio( false)) |
1885 | return; | 1888 | return; |
1886 | killTimers(); | 1889 | killTimers(); |
1887 | 1890 | ||
1888 | paused = true; | 1891 | paused = true; |
1889 | stopped = true; | 1892 | stopped = true; |
1890 | forwardTimer->start(50, false); | 1893 | forwardTimer->start(50, false); |
1891 | } | 1894 | } |
1892 | 1895 | ||
1893 | 1896 | ||
1894 | void QtRec::forwardTimerTimeout() { | 1897 | void QtRec::forwardTimerTimeout() { |
1895 | int sliderValue = timeSlider->value(); | 1898 | int sliderValue = timeSlider->value(); |
1896 | sliderValue = sliderValue + ( filePara.numberSamples / 100); | 1899 | sliderValue = sliderValue + ( filePara.numberSamples / 100); |
1897 | 1900 | ||
1898 | // if(toEndButton->isDown()) | 1901 | // if(toEndButton->isDown()) |
1899 | timeSlider->setValue( sliderValue); | 1902 | timeSlider->setValue( sliderValue); |
1900 | 1903 | ||
1901 | QString timeString; | 1904 | QString timeString; |
1902 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; | 1905 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; |
1903 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1906 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1904 | // timeLabel->setText( timeString+ tr(" seconds")); | 1907 | // timeLabel->setText( timeString+ tr(" seconds")); |
1905 | } | 1908 | } |
1906 | 1909 | ||
1907 | void QtRec::FastforwardReleased() { | 1910 | void QtRec::FastforwardReleased() { |
1908 | forwardTimer->stop(); | 1911 | forwardTimer->stop(); |
1909 | if( wavFile->track.isOpen()) { | 1912 | if( wavFile->track.isOpen()) { |
1910 | sliderPos=timeSlider->value(); | 1913 | sliderPos=timeSlider->value(); |
1911 | stopped = false; | 1914 | stopped = false; |
1912 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1915 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1913 | total = newPos * 4; | 1916 | total = newPos * 4; |
1914 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1917 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1915 | startTimer( 1000); | 1918 | startTimer( 1000); |
1916 | doPlay(); | 1919 | doPlay(); |
1917 | } | 1920 | } |
1918 | } | 1921 | } |
1919 | 1922 | ||
1920 | 1923 | ||
1921 | QString QtRec::getStorage(const QString &fileName) { | 1924 | QString QtRec::getStorage(const QString &fileName) { |
1922 | 1925 | ||
1923 | StorageInfo storageInfo; | 1926 | StorageInfo storageInfo; |
1924 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1927 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1925 | QListIterator<FileSystem> it ( fs ); | 1928 | QListIterator<FileSystem> it ( fs ); |
1926 | QString storage; | 1929 | QString storage; |
1927 | for( ; it.current(); ++it ){ | 1930 | for( ; it.current(); ++it ){ |
1928 | const QString name = ( *it)->name(); | 1931 | const QString name = ( *it)->name(); |
1929 | const QString path = ( *it)->path(); | 1932 | const QString path = ( *it)->path(); |
1930 | const QString disk = ( *it)->disk(); | 1933 | const QString disk = ( *it)->disk(); |
1931 | if( fileName.find( path,0,true) != -1) | 1934 | if( fileName.find( path,0,true) != -1) |
1932 | storage = name; | 1935 | storage = name; |
1933 | // const QString options = (*it)->options(); | 1936 | // const QString options = (*it)->options(); |
1934 | // if( name.find( tr("Internal"),0,true) == -1) { | 1937 | // if( name.find( tr("Internal"),0,true) == -1) { |
1935 | // storageComboBox->insertItem( name +" -> "+disk); | 1938 | // storageComboBox->insertItem( name +" -> "+disk); |
1936 | // odebug << name << oendl; | 1939 | // odebug << name << oendl; |
1937 | } | 1940 | } |
1938 | return storage; | 1941 | return storage; |
1939 | // struct mntent *me; | 1942 | // struct mntent *me; |
1940 | // // if(fileName == "/etc/mtab") { | 1943 | // // if(fileName == "/etc/mtab") { |
1941 | // FILE *mntfp = setmntent( fileName.latin1(), "r" ); | 1944 | // FILE *mntfp = setmntent( fileName.latin1(), "r" ); |
1942 | // if ( mntfp ) { | 1945 | // if ( mntfp ) { |
1943 | // while ( (me = getmntent( mntfp )) != 0 ) { | 1946 | // while ( (me = getmntent( mntfp )) != 0 ) { |
1944 | // QString filesystemType = me->mnt_type; | 1947 | // QString filesystemType = me->mnt_type; |
1945 | 1948 | ||
1946 | // } | 1949 | // } |
1947 | // } | 1950 | // } |
1948 | // endmntent( mntfp ); | 1951 | // endmntent( mntfp ); |
1949 | } | 1952 | } |
1950 | 1953 | ||
1951 | void QtRec::setRecordButton(bool b) { | 1954 | void QtRec::setRecordButton(bool b) { |
1952 | 1955 | ||
1953 | if(b) { //about to record or play | 1956 | if(b) { //about to record or play |
1954 | 1957 | ||
1955 | Rec_PushButton->setDown( true); | 1958 | Rec_PushButton->setDown( true); |
1956 | QPixmap image3( ( const char** ) image3_data ); | 1959 | QPixmap image3( ( const char** ) image3_data ); |
1957 | Stop_PushButton->setPixmap( image3 ); | 1960 | Stop_PushButton->setPixmap( image3 ); |
1958 | if(Stop_PushButton->isDown()) | 1961 | if(Stop_PushButton->isDown()) |
1959 | Stop_PushButton->setDown( true); | 1962 | Stop_PushButton->setDown( true); |
1960 | // playLabel2->setText( tr("Stop") ); | 1963 | // playLabel2->setText( tr("Stop") ); |
1961 | 1964 | ||
1962 | } else { //about to stop | 1965 | } else { //about to stop |
1963 | 1966 | ||
1964 | QPixmap image4( ( const char** ) image4_data ); | 1967 | QPixmap image4( ( const char** ) image4_data ); |
1965 | Stop_PushButton->setPixmap( image4); | 1968 | Stop_PushButton->setPixmap( image4); |
1966 | if(Stop_PushButton->isDown()) | 1969 | if(Stop_PushButton->isDown()) |
1967 | Stop_PushButton->setDown( false); | 1970 | Stop_PushButton->setDown( false); |
1968 | // playLabel2->setText( tr("Play") ); | 1971 | // playLabel2->setText( tr("Play") ); |
1969 | if(Rec_PushButton->isDown()) | 1972 | if(Rec_PushButton->isDown()) |
1970 | Rec_PushButton->setDown( false); | 1973 | Rec_PushButton->setDown( false); |
1971 | } | 1974 | } |
1972 | } | 1975 | } |
1973 | 1976 | ||
1974 | void QtRec::fillDirectoryCombo() { | 1977 | void QtRec::fillDirectoryCombo() { |
1975 | if( directoryComboBox->count() > 0) | 1978 | if( directoryComboBox->count() > 0) |
1976 | directoryComboBox->clear(); | 1979 | directoryComboBox->clear(); |
1977 | int index = 0; | 1980 | int index = 0; |
1978 | Config cfg("OpieRec"); | 1981 | Config cfg("OpieRec"); |
1979 | cfg.setGroup("Settings"); | 1982 | cfg.setGroup("Settings"); |
1980 | QString dir = cfg.readEntry("directory", "/"); | 1983 | QString dir = cfg.readEntry("directory", "/"); |
1981 | StorageInfo storageInfo; | 1984 | StorageInfo storageInfo; |
1982 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1985 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1983 | QListIterator<FileSystem> it ( fs ); | 1986 | QListIterator<FileSystem> it ( fs ); |
1984 | QString storage; | 1987 | QString storage; |
1985 | for( ; it.current(); ++it ){ | 1988 | for( ; it.current(); ++it ){ |
1986 | const QString name = ( *it)->name(); | 1989 | const QString name = ( *it)->name(); |
1987 | const QString path = ( *it)->path(); | 1990 | const QString path = ( *it)->path(); |
1988 | // directoryComboBox->insertItem(name+" "+path); | 1991 | // directoryComboBox->insertItem(name+" "+path); |
1989 | directoryComboBox->insertItem(name); | 1992 | directoryComboBox->insertItem(name); |
1990 | if( path == dir) | 1993 | if( path == dir) |
1991 | directoryComboBox->setCurrentItem( index); | 1994 | directoryComboBox->setCurrentItem( index); |
1992 | index++; | 1995 | index++; |
1993 | } | 1996 | } |
1994 | } | 1997 | } |
1995 | 1998 | ||
1996 | void QtRec::errorStop() { | 1999 | void QtRec::errorStop() { |
1997 | stopped = true; | 2000 | stopped = true; |
1998 | wavFile->closeFile(); | 2001 | wavFile->closeFile(); |
1999 | killTimers(); | 2002 | killTimers(); |
2000 | } | 2003 | } |
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 80453e1..b53c416 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp | |||
@@ -1,314 +1,314 @@ | |||
1 | //wavFile.cpp | 1 | //wavFile.cpp |
2 | #include "wavFile.h" | 2 | #include "wavFile.h" |
3 | #include "qtrec.h" | 3 | #include "qtrec.h" |
4 | 4 | ||
5 | /* OPIE */ | 5 | /* OPIE */ |
6 | #include <opie2/odebug.h> | 6 | #include <opie2/odebug.h> |
7 | #include <qpe/config.h> | 7 | #include <qpe/config.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
12 | #include <qdir.h> | 12 | #include <qdir.h> |
13 | 13 | ||
14 | /* STD */ | 14 | /* STD */ |
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include <sys/time.h> | 16 | #include <sys/time.h> |
17 | #include <sys/types.h> | 17 | #include <sys/types.h> |
18 | #include <sys/vfs.h> | 18 | #include <sys/vfs.h> |
19 | #include <fcntl.h> | 19 | #include <fcntl.h> |
20 | #include <math.h> | 20 | #include <math.h> |
21 | #include <mntent.h> | 21 | #include <mntent.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | 25 | ||
26 | WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, | 26 | WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, |
27 | int channels, int resolution, int format ) | 27 | int channels, int resolution, int format ) |
28 | : QObject( parent) | 28 | : QObject( parent) |
29 | { | 29 | { |
30 | //odebug << "new wave file" << oendl; | 30 | owarn << "new wave file: " << fileName << oendl; |
31 | bool b = makeNwFile; | 31 | bool b = makeNwFile; |
32 | wavSampleRate=sampleRate; | 32 | wavSampleRate=sampleRate; |
33 | wavFormat=format; | 33 | wavFormat=format; |
34 | wavChannels=channels; | 34 | wavChannels=channels; |
35 | wavResolution=resolution; | 35 | wavResolution=resolution; |
36 | useTmpFile=false; | 36 | useTmpFile=false; |
37 | if( b) { | 37 | if( b) { |
38 | newFile(); | 38 | newFile(); |
39 | } else { | 39 | } else { |
40 | openFile(fileName); | 40 | openFile(fileName); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | bool WavFile::newFile() { | 44 | bool WavFile::newFile() { |
45 | 45 | ||
46 | // odebug << "Set up new file" << oendl; | 46 | // odebug << "Set up new file" << oendl; |
47 | Config cfg("OpieRec"); | 47 | Config cfg("OpieRec"); |
48 | cfg.setGroup("Settings"); | 48 | cfg.setGroup("Settings"); |
49 | 49 | ||
50 | currentFileName=cfg.readEntry("directory",QDir::homeDirPath()); | 50 | currentFileName=cfg.readEntry("directory",QDir::homeDirPath()); |
51 | QString date; | 51 | QString date; |
52 | QDateTime dt = QDateTime::currentDateTime(); | 52 | QDateTime dt = QDateTime::currentDateTime(); |
53 | date = dt.toString();//TimeString::dateString( QDateTime::currentDateTime(),false,true); | 53 | date = dt.toString();//TimeString::dateString( QDateTime::currentDateTime(),false,true); |
54 | date.replace(QRegExp("'"),""); | 54 | date.replace(QRegExp("'"),""); |
55 | date.replace(QRegExp(" "),"_"); | 55 | date.replace(QRegExp(" "),"_"); |
56 | date.replace(QRegExp(":"),"-"); | 56 | date.replace(QRegExp(":"),"-"); |
57 | date.replace(QRegExp(","),""); | 57 | date.replace(QRegExp(","),""); |
58 | 58 | ||
59 | QString currentFile=date; | 59 | QString currentFile=date; |
60 | if(currentFileName.right(1).find("/",0,true) == -1) | 60 | if(currentFileName.right(1).find("/",0,true) == -1) |
61 | currentFileName += "/" + date; | 61 | currentFileName += "/" + date; |
62 | else | 62 | else |
63 | currentFileName += date; | 63 | currentFileName += date; |
64 | currentFileName+=".wav"; | 64 | currentFileName+=".wav"; |
65 | 65 | ||
66 | // odebug << "set up file for recording: "+currentFileName << oendl; | 66 | // odebug << "set up file for recording: "+currentFileName << oendl; |
67 | char pointer[] = "/tmp/opierec-XXXXXX"; | 67 | char pointer[] = "/tmp/opierec-XXXXXX"; |
68 | int fd = 0; | 68 | int fd = 0; |
69 | 69 | ||
70 | if( currentFileName.find("/mnt",0,true) == -1 | 70 | if( currentFileName.find("/mnt",0,true) == -1 |
71 | && currentFileName.find("/tmp",0,true) == -1 ) { | 71 | && currentFileName.find("/tmp",0,true) == -1 ) { |
72 | // if destination file is most likely in flash (assuming jffs2) | 72 | // if destination file is most likely in flash (assuming jffs2) |
73 | // we have to write to a different filesystem first | 73 | // we have to write to a different filesystem first |
74 | 74 | ||
75 | useTmpFile = true; | 75 | useTmpFile = true; |
76 | if(( fd = mkstemp( pointer)) < 0 ) { | 76 | if(( fd = mkstemp( pointer)) < 0 ) { |
77 | perror("mkstemp failed"); | 77 | perror("mkstemp failed"); |
78 | return false; | 78 | return false; |
79 | } | 79 | } |
80 | 80 | ||
81 | // odebug << "Opening tmp file " << pointer << "" << oendl; | 81 | // odebug << "Opening tmp file " << pointer << "" << oendl; |
82 | track.setName( pointer); | 82 | track.setName( pointer); |
83 | 83 | ||
84 | } else { //just use regular file.. no moving | 84 | } else { //just use regular file.. no moving |
85 | 85 | ||
86 | useTmpFile = false; | 86 | useTmpFile = false; |
87 | track.setName( currentFileName); | 87 | track.setName( currentFileName); |
88 | } | 88 | } |
89 | if(!track.open( IO_ReadWrite | IO_Truncate)) { | 89 | if(!track.open( IO_ReadWrite | IO_Truncate)) { |
90 | QString errorMsg=(QString)strerror(errno); | 90 | QString errorMsg=(QString)strerror(errno); |
91 | odebug << errorMsg << oendl; | 91 | odebug << errorMsg << oendl; |
92 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | 92 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); |
93 | 93 | ||
94 | return false; | 94 | return false; |
95 | } else { | 95 | } else { |
96 | setWavHeader( track.handle() , &hdr); | 96 | setWavHeader( track.handle() , &hdr); |
97 | } | 97 | } |
98 | return true; | 98 | return true; |
99 | } | 99 | } |
100 | 100 | ||
101 | WavFile::~WavFile() { | 101 | WavFile::~WavFile() { |
102 | 102 | ||
103 | closeFile(); | 103 | closeFile(); |
104 | } | 104 | } |
105 | 105 | ||
106 | void WavFile::closeFile() { | 106 | void WavFile::closeFile() { |
107 | if(track.isOpen()) | 107 | if(track.isOpen()) |
108 | track.close(); | 108 | track.close(); |
109 | } | 109 | } |
110 | 110 | ||
111 | int WavFile::openFile(const QString ¤tFileName) { | 111 | int WavFile::openFile(const QString ¤tFileName) { |
112 | // odebug << "open play file "+currentFileName << oendl; | 112 | qWarning("open play file "+currentFileName);; |
113 | closeFile(); | 113 | closeFile(); |
114 | 114 | ||
115 | track.setName(currentFileName); | 115 | track.setName(currentFileName); |
116 | 116 | ||
117 | if(!track.open(IO_ReadOnly)) { | 117 | if(!track.open(IO_ReadOnly)) { |
118 | QString errorMsg=(QString)strerror(errno); | 118 | QString errorMsg=(QString)strerror(errno); |
119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; | 119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; |
120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | 120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); |
121 | return -1; | 121 | return -1; |
122 | } else { | 122 | } else { |
123 | parseWavHeader( track.handle()); | 123 | parseWavHeader( track.handle()); |
124 | } | 124 | } |
125 | return track.handle(); | 125 | return track.handle(); |
126 | } | 126 | } |
127 | 127 | ||
128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | 128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { |
129 | 129 | ||
130 | strncpy((*hdr).riffID, "RIFF", 4); // RIFF | 130 | strncpy((*hdr).riffID, "RIFF", 4); // RIFF |
131 | strncpy((*hdr).wavID, "WAVE", 4); //WAVE | 131 | strncpy((*hdr).wavID, "WAVE", 4); //WAVE |
132 | strncpy((*hdr).fmtID, "fmt ", 4); // fmt | 132 | strncpy((*hdr).fmtID, "fmt ", 4); // fmt |
133 | (*hdr).fmtLen = 16; // format length = 16 | 133 | (*hdr).fmtLen = 16; // format length = 16 |
134 | 134 | ||
135 | if( wavFormat == WAVE_FORMAT_PCM) { | 135 | if( wavFormat == WAVE_FORMAT_PCM) { |
136 | (*hdr).fmtTag = 1; // PCM | 136 | (*hdr).fmtTag = 1; // PCM |
137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; | 137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; |
138 | } | 138 | } |
139 | else { | 139 | else { |
140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM | 140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM |
141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; | 141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; |
142 | } | 142 | } |
143 | 143 | ||
144 | // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels | 144 | // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels |
145 | (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels | 145 | (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels |
146 | 146 | ||
147 | (*hdr).sampleRate = wavSampleRate; //samples per second | 147 | (*hdr).sampleRate = wavSampleRate; //samples per second |
148 | (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second | 148 | (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second |
149 | (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align | 149 | (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align |
150 | (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 | 150 | (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 |
151 | 151 | ||
152 | strncpy((*hdr).dataID, "data", 4); | 152 | strncpy((*hdr).dataID, "data", 4); |
153 | 153 | ||
154 | write( fd,hdr, sizeof(*hdr)); | 154 | write( fd,hdr, sizeof(*hdr)); |
155 | odebug << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; | 155 | owarn << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; |
156 | return true; | 156 | return true; |
157 | } | 157 | } |
158 | 158 | ||
159 | bool WavFile::adjustHeaders(int fd, int total) { | 159 | bool WavFile::adjustHeaders(int fd, int total) { |
160 | lseek(fd, 4, SEEK_SET); | 160 | lseek(fd, 4, SEEK_SET); |
161 | int i = total + 36; | 161 | int i = total + 36; |
162 | write( fd, &i, sizeof(i)); | 162 | write( fd, &i, sizeof(i)); |
163 | lseek( fd, 40, SEEK_SET); | 163 | lseek( fd, 40, SEEK_SET); |
164 | write( fd, &total, sizeof(total)); | 164 | write( fd, &total, sizeof(total)); |
165 | odebug << "adjusting header " << total << "" << oendl; | 165 | owarn << "adjusting header " << total << "" << oendl; |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | int WavFile::parseWavHeader(int fd) { | 169 | int WavFile::parseWavHeader(int fd) { |
170 | odebug << "Parsing wav header" << oendl; | 170 | owarn << "Parsing wav header" << oendl; |
171 | char string[4]; | 171 | char string[4]; |
172 | int found; | 172 | int found; |
173 | short fmt; | 173 | short fmt; |
174 | unsigned short ch, bitrate; | 174 | unsigned short ch, bitrate; |
175 | unsigned long samplerrate, longdata; | 175 | unsigned long samplerrate, longdata; |
176 | 176 | ||
177 | if (read(fd, string, 4) < 4) { | 177 | if (read(fd, string, 4) < 4) { |
178 | odebug << " Could not read from sound file." << oendl; | 178 | owarn << " Could not read from sound file." << oendl; |
179 | return -1; | 179 | return -1; |
180 | } | 180 | } |
181 | if (strncmp(string, "RIFF", 4)) { | 181 | if (strncmp(string, "RIFF", 4)) { |
182 | odebug << " not a valid WAV file." << oendl; | 182 | owarn << " not a valid WAV file." << oendl; |
183 | return -1; | 183 | return -1; |
184 | } | 184 | } |
185 | lseek(fd, 4, SEEK_CUR); | 185 | lseek(fd, 4, SEEK_CUR); |
186 | if (read(fd, string, 4) < 4) { | 186 | if (read(fd, string, 4) < 4) { |
187 | odebug << "Could not read from sound file." << oendl; | 187 | owarn << "Could not read from sound file." << oendl; |
188 | return -1; | 188 | return -1; |
189 | } | 189 | } |
190 | if (strncmp(string, "WAVE", 4)) { | 190 | if (strncmp(string, "WAVE", 4)) { |
191 | odebug << "not a valid WAV file." << oendl; | 191 | owarn << "not a valid WAV file." << oendl; |
192 | return -1; | 192 | return -1; |
193 | } | 193 | } |
194 | found = 0; | 194 | found = 0; |
195 | 195 | ||
196 | while (!found) { | 196 | while (!found) { |
197 | if (read(fd, string, 4) < 4) { | 197 | if (read(fd, string, 4) < 4) { |
198 | odebug << "Could not read from sound file." << oendl; | 198 | owarn << "Could not read from sound file." << oendl; |
199 | return -1; | 199 | return -1; |
200 | } | 200 | } |
201 | if (strncmp(string, "fmt ", 4)) { | 201 | if (strncmp(string, "fmt ", 4)) { |
202 | if (read(fd, &longdata, 4) < 4) { | 202 | if (read(fd, &longdata, 4) < 4) { |
203 | odebug << "Could not read from sound file." << oendl; | 203 | owarn << "Could not read from sound file." << oendl; |
204 | return -1; | 204 | return -1; |
205 | } | 205 | } |
206 | lseek(fd, longdata, SEEK_CUR); | 206 | lseek(fd, longdata, SEEK_CUR); |
207 | } else { | 207 | } else { |
208 | lseek(fd, 4, SEEK_CUR); | 208 | lseek(fd, 4, SEEK_CUR); |
209 | if (read(fd, &fmt, 2) < 2) { | 209 | if (read(fd, &fmt, 2) < 2) { |
210 | odebug << "Could not read format chunk." << oendl; | 210 | owarn << "Could not read format chunk." << oendl; |
211 | return -1; | 211 | return -1; |
212 | } | 212 | } |
213 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { | 213 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { |
214 | odebug << "Wave file contains unknown format. Unable to continue." << oendl; | 214 | owarn << "Wave file contains unknown format. Unable to continue." << oendl; |
215 | return -1; | 215 | return -1; |
216 | } | 216 | } |
217 | wavFormat = fmt; | 217 | wavFormat = fmt; |
218 | // compressionFormat=fmt; | 218 | // compressionFormat=fmt; |
219 | odebug << "compressionFormat is " << fmt << "" << oendl; | 219 | owarn << "compressionFormat is " << fmt << "" << oendl; |
220 | if (read(fd, &ch, 2) < 2) { | 220 | if (read(fd, &ch, 2) < 2) { |
221 | odebug << "Could not read format chunk." << oendl; | 221 | owarn << "Could not read format chunk." << oendl; |
222 | return -1; | 222 | return -1; |
223 | } else { | 223 | } else { |
224 | wavChannels = ch; | 224 | wavChannels = ch; |
225 | odebug << "File has " << ch << " channels" << oendl; | 225 | owarn << "File has " << ch << " channels" << oendl; |
226 | } | 226 | } |
227 | if (read(fd, &samplerrate, 4) < 4) { | 227 | if (read(fd, &samplerrate, 4) < 4) { |
228 | odebug << "Could not read from format chunk." << oendl; | 228 | owarn << "Could not read from format chunk." << oendl; |
229 | return -1; | 229 | return -1; |
230 | } else { | 230 | } else { |
231 | wavSampleRate = samplerrate; | 231 | wavSampleRate = samplerrate; |
232 | // sampleRate = samplerrate; | 232 | // sampleRate = samplerrate; |
233 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; | 233 | owarn << "File has samplerate of " << (int) samplerrate << "" << oendl; |
234 | } | 234 | } |
235 | lseek(fd, 6, SEEK_CUR); | 235 | lseek(fd, 6, SEEK_CUR); |
236 | if (read(fd, &bitrate, 2) < 2) { | 236 | if (read(fd, &bitrate, 2) < 2) { |
237 | odebug << "Could not read format chunk." << oendl; | 237 | owarn << "Could not read format chunk." << oendl; |
238 | return -1; | 238 | return -1; |
239 | } else { | 239 | } else { |
240 | wavResolution=bitrate; | 240 | wavResolution=bitrate; |
241 | // resolution = bitrate; | 241 | // resolution = bitrate; |
242 | odebug << "File has bitrate of " << bitrate << "" << oendl; | 242 | owarn << "File has bitrate of " << bitrate << "" << oendl; |
243 | } | 243 | } |
244 | found++; | 244 | found++; |
245 | } | 245 | } |
246 | } | 246 | } |
247 | found = 0; | 247 | found = 0; |
248 | while (!found) { | 248 | while (!found) { |
249 | if (read(fd, string, 4) < 4) { | 249 | if (read(fd, string, 4) < 4) { |
250 | odebug << "Could not read from sound file." << oendl; | 250 | odebug << "Could not read from sound file." << oendl; |
251 | return -1; | 251 | return -1; |
252 | } | 252 | } |
253 | 253 | ||
254 | if (strncmp(string, "data", 4)) { | 254 | if (strncmp(string, "data", 4)) { |
255 | if (read(fd, &longdata, 4)<4) { | 255 | if (read(fd, &longdata, 4)<4) { |
256 | odebug << "Could not read from sound file." << oendl; | 256 | odebug << "Could not read from sound file." << oendl; |
257 | return -1; | 257 | return -1; |
258 | } | 258 | } |
259 | 259 | ||
260 | lseek(fd, longdata, SEEK_CUR); | 260 | lseek(fd, longdata, SEEK_CUR); |
261 | } else { | 261 | } else { |
262 | if (read(fd, &longdata, 4) < 4) { | 262 | if (read(fd, &longdata, 4) < 4) { |
263 | odebug << "Could not read from sound file." << oendl; | 263 | odebug << "Could not read from sound file." << oendl; |
264 | return -1; | 264 | return -1; |
265 | } else { | 265 | } else { |
266 | wavNumberSamples = longdata; | 266 | wavNumberSamples = longdata; |
267 | odebug << "file hase length of " << (int)longdata << "" | 267 | odebug << "file hase length of " << (int)longdata << "" |
268 | << "lasting " | 268 | << "lasting " |
269 | << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) | 269 | << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) |
270 | << " seconds" << oendl; | 270 | << " seconds" << oendl; |
271 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); | 271 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); |
272 | 272 | ||
273 | return longdata; | 273 | return longdata; |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | lseek(fd, 0, SEEK_SET); | 278 | lseek(fd, 0, SEEK_SET); |
279 | 279 | ||
280 | return 0; | 280 | return 0; |
281 | } | 281 | } |
282 | 282 | ||
283 | QString WavFile::trackName() { | 283 | QString WavFile::trackName() { |
284 | return track.name(); | 284 | return track.name(); |
285 | } | 285 | } |
286 | 286 | ||
287 | int WavFile::wavHandle(){ | 287 | int WavFile::wavHandle(){ |
288 | return track.handle(); | 288 | return track.handle(); |
289 | } | 289 | } |
290 | 290 | ||
291 | int WavFile::getFormat() { | 291 | int WavFile::getFormat() { |
292 | return wavFormat; | 292 | return wavFormat; |
293 | } | 293 | } |
294 | 294 | ||
295 | int WavFile::getResolution() { | 295 | int WavFile::getResolution() { |
296 | return wavResolution; | 296 | return wavResolution; |
297 | } | 297 | } |
298 | 298 | ||
299 | int WavFile::getSampleRate() { | 299 | int WavFile::getSampleRate() { |
300 | return wavSampleRate; | 300 | return wavSampleRate; |
301 | } | 301 | } |
302 | 302 | ||
303 | int WavFile::getNumberSamples() { | 303 | int WavFile::getNumberSamples() { |
304 | return wavNumberSamples; | 304 | return wavNumberSamples; |
305 | } | 305 | } |
306 | 306 | ||
307 | bool WavFile::isTempFile() { | 307 | bool WavFile::isTempFile() { |
308 | return useTmpFile; | 308 | return useTmpFile; |
309 | } | 309 | } |
310 | 310 | ||
311 | int WavFile::getChannels() { | 311 | int WavFile::getChannels() { |
312 | 312 | ||
313 | return wavChannels; | 313 | return wavChannels; |
314 | } | 314 | } |