-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 | |||
@@ -16,2 +16,3 @@ | |||
16 | 16 | ||
17 | #include <sys/utsname.h> | ||
17 | #include <sys/time.h> | 18 | #include <sys/time.h> |
@@ -28,26 +29,26 @@ | |||
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 | ||
@@ -138,2 +139,13 @@ VMemo::VMemo( QWidget *parent, const char *name ) | |||
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 | } |
@@ -154,3 +166,3 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
154 | QSound::play(Resource::findSound("vmemob")); | 166 | QSound::play(Resource::findSound("vmemob")); |
155 | 167 | ||
156 | recording = TRUE; | 168 | recording = TRUE; |
@@ -158,20 +170,19 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
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_"; |
@@ -181,3 +192,3 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
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(" "),"_"); |
@@ -185,14 +196,14 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
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_"); |
@@ -205,3 +216,3 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
205 | l.writeLink(); | 216 | l.writeLink(); |
206 | 217 | ||
207 | record(); | 218 | record(); |
@@ -220,3 +231,3 @@ int VMemo::openDSP() | |||
220 | cfg.setGroup("Record"); | 231 | cfg.setGroup("Record"); |
221 | 232 | ||
222 | speed = cfg.readNumEntry("SampleRate", 11025); | 233 | speed = cfg.readNumEntry("SampleRate", 11025); |
@@ -224,27 +235,24 @@ int VMemo::openDSP() | |||
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 | ||
@@ -267,3 +275,3 @@ int VMemo::openDSP() | |||
267 | qWarning("speed = %i", speed); | 275 | qWarning("speed = %i", speed); |
268 | 276 | ||
269 | return 1; | 277 | return 1; |
@@ -278,6 +286,6 @@ int VMemo::openWAV(const char *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(); |
@@ -286,3 +294,3 @@ int VMemo::openWAV(const char *filename) | |||
286 | 294 | ||
287 | /* | 295 | /* |
288 | wh.main_chunk = RIFF; | 296 | wh.main_chunk = RIFF; |
@@ -316,6 +324,6 @@ int VMemo::openWAV(const char *filename) | |||
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 | ||
@@ -337,12 +345,12 @@ void VMemo::record(void) | |||
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; |
@@ -355,5 +363,5 @@ void VMemo::record(void) | |||
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"); |
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 | |||
@@ -43,3 +43,3 @@ private: | |||
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; |