-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 186 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 2 |
2 files changed, 98 insertions, 90 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 6f04c66..6bd1622 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -11,48 +11,49 @@ | |||
11 | *********************************************************************************************/ | 11 | *********************************************************************************************/ |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <sys/utsname.h> | ||
17 | #include <sys/time.h> | 18 | #include <sys/time.h> |
18 | #include <sys/types.h> | 19 | #include <sys/types.h> |
19 | #include <unistd.h> | 20 | #include <unistd.h> |
20 | #include <stdio.h> | 21 | #include <stdio.h> |
21 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
22 | #include <fcntl.h> | 23 | #include <fcntl.h> |
23 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
24 | #include <linux/soundcard.h> | 25 | #include <linux/soundcard.h> |
25 | #include <string.h> | 26 | #include <string.h> |
26 | #include <stdlib.h> | 27 | #include <stdlib.h> |
27 | 28 | ||
28 | typedef struct _waveheader { | 29 | typedef struct _waveheader { |
29 | u_long main_chunk;/* 'RIFF' */ | 30 | u_long main_chunk; /* 'RIFF' */ |
30 | u_long length; /* filelen */ | 31 | u_long length; /* filelen */ |
31 | u_long chunk_type;/* 'WAVE' */ | 32 | u_long chunk_type; /* 'WAVE' */ |
32 | 33 | ||
33 | u_long sub_chunk;/* 'fmt ' */ | 34 | u_long sub_chunk; /* 'fmt ' */ |
34 | u_long sc_len; /* length of sub_chunk, =16 (chunckSize) */ | 35 | u_long sc_len; /* length of sub_chunk, =16 (chunckSize) */ |
35 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 36 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
36 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 37 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
37 | u_long sample_fq;/* samples per second (samplesPerSecond) */ | 38 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
38 | u_longbyte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 39 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
39 | u_short byte_p_spl;/* samplesize; 1 or 2 bytes (blockAlign) */ | 40 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
40 | u_short bit_p_spl;/* 8, 12 or 16 bit (bitsPerSample) */ | 41 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
41 | 42 | ||
42 | u_long data_chunk;/* 'data' */ | 43 | u_long data_chunk; /* 'data' */ |
43 | u_long data_length;/* samplecount */ | 44 | u_long data_length; /* samplecount */ |
44 | } WaveHeader; | 45 | } WaveHeader; |
45 | 46 | ||
46 | #define RIFF 0x46464952 | 47 | #define RIFF 0x46464952 |
47 | #define WAVE 0x45564157 | 48 | #define WAVE 0x45564157 |
48 | #define FMT 0x20746D66 | 49 | #define FMT 0x20746D66 |
49 | #define DATA 0x61746164 | 50 | #define DATA 0x61746164 |
50 | #define PCM_CODE1 | 51 | #define PCM_CODE 1 |
51 | #define WAVE_MONO1 | 52 | #define WAVE_MONO 1 |
52 | #define WAVE_STEREO2 | 53 | #define WAVE_STEREO 2 |
53 | 54 | ||
54 | #include "vmemo.h" | 55 | #include "vmemo.h" |
55 | 56 | ||
56 | #include <qpe/qpeapplication.h> | 57 | #include <qpe/qpeapplication.h> |
57 | #include <qpe/resource.h> | 58 | #include <qpe/resource.h> |
58 | #include <qpe/config.h> | 59 | #include <qpe/config.h> |
@@ -133,12 +134,23 @@ VMemo::VMemo( QWidget *parent, const char *name ) | |||
133 | : QWidget( parent, name ) | 134 | : QWidget( parent, name ) |
134 | { | 135 | { |
135 | setFixedHeight( 18 ); | 136 | setFixedHeight( 18 ); |
136 | setFixedWidth( 14 ); | 137 | setFixedWidth( 14 ); |
137 | 138 | ||
138 | recording = FALSE; | 139 | recording = FALSE; |
140 | |||
141 | struct utsname name; //check for embedix kernel running on the zaurus, if lineo change string, this break | ||
142 | if (uname(&name) != -1) { | ||
143 | QString release=name.release; | ||
144 | if(release.find("embedix",0,TRUE) !=-1) { | ||
145 | systemZaurus=TRUE; | ||
146 | printf("System release: %s\n", name.release); | ||
147 | } else | ||
148 | systemZaurus=FALSE; | ||
149 | } | ||
150 | |||
139 | } | 151 | } |
140 | 152 | ||
141 | VMemo::~VMemo() | 153 | VMemo::~VMemo() |
142 | { | 154 | { |
143 | } | 155 | } |
144 | 156 | ||
@@ -149,64 +161,63 @@ void VMemo::paintEvent( QPaintEvent* ) | |||
149 | } | 161 | } |
150 | 162 | ||
151 | void VMemo::mousePressEvent( QMouseEvent * ) | 163 | void VMemo::mousePressEvent( QMouseEvent * ) |
152 | { | 164 | { |
153 | qWarning("VMemo::mousePress()"); | 165 | qWarning("VMemo::mousePress()"); |
154 | QSound::play(Resource::findSound("vmemob")); | 166 | QSound::play(Resource::findSound("vmemob")); |
155 | 167 | ||
156 | recording = TRUE; | 168 | recording = TRUE; |
157 | qWarning("VMemo::mousePress() -> Starting to record"); | 169 | qWarning("VMemo::mousePress() -> Starting to record"); |
158 | if (openDSP() == -1) | 170 | if (openDSP() == -1) |
159 | { | 171 | { |
160 | // ### Display an error box | 172 | // ### Display an error box |
161 | qWarning("VMemo::mousePress() -> DSP error"); | 173 | qWarning("VMemo::mousePress() -> DSP error"); |
162 | recording = FALSE; | 174 | recording = FALSE; |
163 | return; | 175 | return; |
164 | } | 176 | } |
165 | 177 | ||
166 | Config vmCfg("VMemo"); | 178 | Config vmCfg("VMemo"); |
167 | vmCfg.setGroup("Defaults"); | 179 | vmCfg.setGroup("Defaults"); |
168 | 180 | ||
169 | QDateTime dt = QDateTime::currentDateTime(); | 181 | QDateTime dt = QDateTime::currentDateTime(); |
170 | 182 | QString fileName; | |
171 | #if defined(QT_QWS_EBX) //if zaurus | 183 | if(systemZaurus) |
172 | QString fileName(vmCfg.readEntry("Dir", "/mnt/cf/")); // zaurus does not have /mnt/ramfs | 184 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
173 | #else | 185 | else |
174 | QString fileName(vmCfg.readEntry("Dir", "/mnt/ramfs/")); | 186 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
175 | #endif | 187 | |
176 | |||
177 | fileName += "vm_"; | 188 | fileName += "vm_"; |
178 | fileName += dt.toString(); | 189 | fileName += dt.toString(); |
179 | fileName += ".wav"; | 190 | fileName += ".wav"; |
180 | 191 | ||
181 | // No spaces in the filename | 192 | // No spaces in the filename |
182 | fileName.replace(QRegExp("'"),""); | 193 | fileName.replace(QRegExp("'"),""); |
183 | fileName.replace(QRegExp(" "),"_"); | 194 | fileName.replace(QRegExp(" "),"_"); |
184 | fileName.replace(QRegExp(":"),"."); | 195 | fileName.replace(QRegExp(":"),"."); |
185 | fileName.replace(QRegExp(","),""); | 196 | fileName.replace(QRegExp(","),""); |
186 | 197 | ||
187 | if(openWAV(fileName.latin1()) == -1) | 198 | if(openWAV(fileName.latin1()) == -1) |
188 | { | 199 | { |
189 | // ### Display an error box | 200 | // ### Display an error box |
190 | qWarning("VMemo::mousePress() -> WAV error"); | 201 | qWarning("VMemo::mousePress() -> WAV error"); |
191 | close(dsp); | 202 | close(dsp); |
192 | return; | 203 | return; |
193 | } | 204 | } |
194 | 205 | ||
195 | QArray<int> cats(1); | 206 | QArray<int> cats(1); |
196 | cats[0] = vmCfg.readNumEntry("Category", 0); | 207 | cats[0] = vmCfg.readNumEntry("Category", 0); |
197 | 208 | ||
198 | QString dlName("vm_"); | 209 | QString dlName("vm_"); |
199 | dlName += dt.toString(); | 210 | dlName += dt.toString(); |
200 | DocLnk l; | 211 | DocLnk l; |
201 | l.setFile(fileName); | 212 | l.setFile(fileName); |
202 | l.setName(dlName); | 213 | l.setName(dlName); |
203 | l.setType("audio/x-wav"); | 214 | l.setType("audio/x-wav"); |
204 | l.setCategories(cats); | 215 | l.setCategories(cats); |
205 | l.writeLink(); | 216 | l.writeLink(); |
206 | 217 | ||
207 | record(); | 218 | record(); |
208 | } | 219 | } |
209 | 220 | ||
210 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 221 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
211 | { | 222 | { |
212 | qWarning("VMemo::mouseRelese() -> Done recording"); | 223 | qWarning("VMemo::mouseRelese() -> Done recording"); |
@@ -215,41 +226,38 @@ void VMemo::mouseReleaseEvent( QMouseEvent * ) | |||
215 | } | 226 | } |
216 | 227 | ||
217 | int VMemo::openDSP() | 228 | int VMemo::openDSP() |
218 | { | 229 | { |
219 | Config cfg("Sound"); | 230 | Config cfg("Sound"); |
220 | cfg.setGroup("Record"); | 231 | cfg.setGroup("Record"); |
221 | 232 | ||
222 | speed = cfg.readNumEntry("SampleRate", 11025); | 233 | speed = cfg.readNumEntry("SampleRate", 11025); |
223 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 234 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
224 | if (cfg.readNumEntry("SixteenBit", 1)) | 235 | if (cfg.readNumEntry("SixteenBit", 1)) |
225 | { | 236 | { |
226 | format = AFMT_S16_LE; | 237 | format = AFMT_S16_LE; |
227 | resolution = 16; | 238 | resolution = 16; |
228 | } | 239 | } |
229 | else | 240 | else |
230 | { | 241 | { |
231 | format = AFMT_U8; | 242 | format = AFMT_U8; |
232 | resolution = 8; | 243 | resolution = 8; |
233 | } | 244 | } |
234 | 245 | ||
235 | #if defined(QT_QWS_EBX) //if zaurus | 246 | if(systemZaurus) |
236 | //dsp = open("/dev/dsp1", O_RDONLY); //on the Zaurus this needs to be /dev/dsp1 !!!! | 247 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
237 | dsp = open("/dev/dsp1", O_RDWR); //on the Zaurus this needs to be /dev/dsp1 !!!! | 248 | else |
238 | #else | 249 | dsp = open("/dev/dsp", O_RDWR); |
239 | //dsp = open("/dev/dsp", O_RDONLY); | ||
240 | dsp = open("/dev/dsp", O_RDWR); | ||
241 | #endif | ||
242 | 250 | ||
243 | qWarning("speed = %i", speed); | 251 | qWarning("speed = %i", speed); |
244 | 252 | ||
245 | if(dsp == -1) | 253 | if(dsp == -1) |
246 | { | 254 | { |
247 | perror("open(\"/dev/dsp\")"); | 255 | perror("open(\"/dev/dsp\")"); |
248 | return -1; | 256 | return -1; |
249 | } | 257 | } |
250 | 258 | ||
251 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 259 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
252 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 260 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
253 | return -1; | 261 | return -1; |
254 | } | 262 | } |
255 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 263 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
@@ -262,32 +270,32 @@ int VMemo::openDSP() | |||
262 | } | 270 | } |
263 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 271 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
264 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 272 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
265 | return -1; | 273 | return -1; |
266 | } | 274 | } |
267 | qWarning("speed = %i", speed); | 275 | qWarning("speed = %i", speed); |
268 | 276 | ||
269 | return 1; | 277 | return 1; |
270 | } | 278 | } |
271 | 279 | ||
272 | int VMemo::openWAV(const char *filename) | 280 | int VMemo::openWAV(const char *filename) |
273 | { | 281 | { |
274 | char buffer[256]; | 282 | char buffer[256]; |
275 | 283 | ||
276 | qDebug("Creating %s ",filename); | 284 | qDebug("Creating %s ",filename); |
277 | track.setName(filename); | 285 | track.setName(filename); |
278 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 286 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
279 | { | 287 | { |
280 | qDebug("Could not open file"); | 288 | qDebug("Could not open file"); |
281 | return -1; | 289 | return -1; |
282 | } | 290 | } |
283 | wav=track.handle(); | 291 | wav=track.handle(); |
284 | 292 | ||
285 | WaveHeader wh; | 293 | WaveHeader wh; |
286 | 294 | ||
287 | /* | 295 | /* |
288 | wh.main_chunk = RIFF; | 296 | wh.main_chunk = RIFF; |
289 | wh.length = 0; | 297 | wh.length = 0; |
290 | wh.chunk_type = WAVE; | 298 | wh.chunk_type = WAVE; |
291 | wh.sub_chunk = FMT; | 299 | wh.sub_chunk = FMT; |
292 | wh.sc_len = 16; | 300 | wh.sc_len = 16; |
293 | wh.format = PCM_CODE; | 301 | wh.format = PCM_CODE; |
@@ -311,16 +319,16 @@ int VMemo::openWAV(const char *filename) | |||
311 | wh.sample_fq = speed; | 319 | wh.sample_fq = speed; |
312 | wh.bit_p_spl = resolution; | 320 | wh.bit_p_spl = resolution; |
313 | wh.byte_p_sec = wh.sample_fq * wh.bit_p_spl; | 321 | wh.byte_p_sec = wh.sample_fq * wh.bit_p_spl; |
314 | wh.byte_p_spl = channels * (wh.bit_p_spl % 8); | 322 | wh.byte_p_spl = channels * (wh.bit_p_spl % 8); |
315 | 323 | ||
316 | qWarning("channels = %i\n" | 324 | qWarning("channels = %i\n" |
317 | "samplesPerSecond = %i\n" | 325 | "samplesPerSecond = %i\n" |
318 | "avgBytesPerSecond = %i\n" | 326 | "avgBytesPerSecond = %i\n" |
319 | "blockAlign = %i\n" | 327 | "blockAlign = %i\n" |
320 | "bitsPerSecond = %i\n", wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl); | 328 | "bitsPerSecond = %i\n", wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl); |
321 | 329 | ||
322 | wh.data_chunk = DATA; | 330 | wh.data_chunk = DATA; |
323 | wh.data_length= 0; | 331 | wh.data_length= 0; |
324 | 332 | ||
325 | write (wav, &wh, sizeof(WaveHeader)); | 333 | write (wav, &wh, sizeof(WaveHeader)); |
326 | 334 | ||
@@ -332,29 +340,29 @@ void VMemo::record(void) | |||
332 | int length=0, result, value; | 340 | int length=0, result, value; |
333 | char sound[8192]; | 341 | char sound[8192]; |
334 | 342 | ||
335 | qWarning("VMemo::record()"); | 343 | qWarning("VMemo::record()"); |
336 | 344 | ||
337 | while(recording) | 345 | while(recording) |
338 | { | 346 | { |
339 | result = read(dsp, sound, 8192); | 347 | result = read(dsp, sound, 8192); |
340 | write(wav, sound, result); | 348 | write(wav, sound, result); |
341 | length += result; | 349 | length += result; |
342 | qApp->processEvents(); | 350 | qApp->processEvents(); |
343 | } | 351 | } |
344 | 352 | ||
345 | qWarning("VMemo::record() -> Done recording"); | 353 | qWarning("VMemo::record() -> Done recording"); |
346 | qWarning("VMemo::record() -> Closing dsp"); | 354 | qWarning("VMemo::record() -> Closing dsp"); |
347 | 355 | ||
348 | value = length+36; | 356 | value = length+36; |
349 | lseek(wav, 4, SEEK_SET); | 357 | lseek(wav, 4, SEEK_SET); |
350 | write(wav, &value, 4); | 358 | write(wav, &value, 4); |
351 | lseek(wav, 40, SEEK_SET); | 359 | lseek(wav, 40, SEEK_SET); |
352 | write(wav, &length, 4); | 360 | write(wav, &length, 4); |
353 | track.close(); | 361 | track.close(); |
354 | 362 | ||
355 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while | 363 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while |
356 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 364 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
357 | ::close(dsp); | 365 | ::close(dsp); |
358 | 366 | ||
359 | qWarning("VMemo::record() -> terminating"); | 367 | qWarning("VMemo::record() -> terminating"); |
360 | } | 368 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 9ce08f2..ee375b0 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -38,13 +38,13 @@ private: | |||
38 | void paintEvent( QPaintEvent* ); | 38 | void paintEvent( QPaintEvent* ); |
39 | 39 | ||
40 | int openDSP(); | 40 | int openDSP(); |
41 | int openWAV(const char *filename); | 41 | int openWAV(const char *filename); |
42 | 42 | ||
43 | QPixmap vmemoPixmap; | 43 | QPixmap vmemoPixmap; |
44 | 44 | bool systemZaurus; | |
45 | int dsp, wav, rate, speed, channels, format, resolution; | 45 | int dsp, wav, rate, speed, channels, format, resolution; |
46 | bool recording; | 46 | bool recording; |
47 | }; | 47 | }; |
48 | 48 | ||
49 | #endif // __VMEMO_H__ | 49 | #endif // __VMEMO_H__ |
50 | 50 | ||