summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-26 02:10:09 (UTC)
committer llornkcor <llornkcor>2002-03-26 02:10:09 (UTC)
commit8e658c0aa14db9f8b88eec738827ec640c0be818 (patch) (unidiff)
tree4b12ce21c111fd7ad6ba49259f766a32ee3c9d02
parentfb6b1e63a784a6724e05f16269126ea49a7ad54b (diff)
downloadopie-8e658c0aa14db9f8b88eec738827ec640c0be818.zip
opie-8e658c0aa14db9f8b88eec738827ec640c0be818.tar.gz
opie-8e658c0aa14db9f8b88eec738827ec640c0be818.tar.bz2
I need this format, if I am to take this ove.. :(
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp154
1 files changed, 77 insertions, 77 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index b3edbc1..ae5cf0c 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,434 +1,434 @@
1/************************************************************************************ 1/************************************************************************************
2** 2**
3** This file may be distributed and/or modified under the terms of the 3** This file may be distributed and/or modified under the terms of the
4** GNU General Public License version 2 as published by the Free Software 4** GNU General Public License version 2 as published by the Free Software
5** Foundation and appearing in the file LICENSE.GPL included in the 5** Foundation and appearing in the file LICENSE.GPL included in the
6** packaging of this file. 6** packaging of this file.
7** 7**
8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10** 10**
11************************************************************************************/ 11************************************************************************************/
12 12
13/* 13/*
14 * $Id$ 14 * $Id$
15 */ 15 */
16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> 16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com>
17#include <sys/utsname.h> 17#include <sys/utsname.h>
18#include <sys/time.h> 18#include <sys/time.h>
19#include <sys/types.h> 19#include <sys/types.h>
20#include <unistd.h> 20#include <unistd.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <fcntl.h> 23#include <fcntl.h>
24#include <sys/ioctl.h> 24#include <sys/ioctl.h>
25#include <linux/soundcard.h> 25#include <linux/soundcard.h>
26#include <string.h> 26#include <string.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29typedef struct _waveheader { 29typedef struct _waveheader {
30 u_long main_chunk; /* 'RIFF' */ 30 u_long main_chunk; /* 'RIFF' */
31 u_long length; /* filelen */ 31 u_long length; /* filelen */
32 u_long chunk_type; /* 'WAVE' */ 32 u_long chunk_type; /* 'WAVE' */
33 u_long sub_chunk; /* 'fmt ' */ 33 u_long sub_chunk; /* 'fmt ' */
34 u_long sc_len; /* length of sub_chunk, =16 34 u_long sc_len; /* length of sub_chunk, =16
35 (chunckSize) format len */ 35 (chunckSize) format len */
36 u_short format; /* should be 1 for PCM-code (formatTag) */ 36 u_short format; /* should be 1 for PCM-code (formatTag) */
37 37
38 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 38 u_short modus; /* 1 Mono, 2 Stereo (channels) */
39 u_long sample_fq; /* samples per second (samplesPerSecond) */ 39 u_long sample_fq; /* samples per second (samplesPerSecond) */
40 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 40 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
41 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 41 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
42 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 42 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
43 43
44 u_long data_chunk; /* 'data' */ 44 u_long data_chunk; /* 'data' */
45 45
46 u_long data_length;/* samplecount */ 46 u_long data_length;/* samplecount */
47} WaveHeader; 47} WaveHeader;
48 48
49#define RIFF 0x46464952 49#define RIFF 0x46464952
50#define WAVE 0x45564157 50#define WAVE 0x45564157
51#define FMT 0x20746D66 51#define FMT 0x20746D66
52#define DATA 0x61746164 52#define DATA 0x61746164
53#define PCM_CODE 1 53#define PCM_CODE 1
54#define WAVE_MONO 1 54#define WAVE_MONO 1
55#define WAVE_STEREO 2 55#define WAVE_STEREO 2
56 56
57#include "vmemo.h" 57#include "vmemo.h"
58 58
59#include <qpe/qpeapplication.h> 59#include <qpe/qpeapplication.h>
60#include <qpe/resource.h> 60#include <qpe/resource.h>
61#include <qpe/config.h> 61#include <qpe/config.h>
62 62
63#include <qpainter.h> 63#include <qpainter.h>
64#include <qdatetime.h> 64#include <qdatetime.h>
65#include <qsound.h> 65#include <qsound.h>
66#include <qfile.h> 66#include <qfile.h>
67#include <qmessagebox.h> 67#include <qmessagebox.h>
68 68
69int seq = 0; 69int seq = 0;
70 70
71/* XPM */ 71/* XPM */
72static char * vmemo_xpm[] = { 72static char * vmemo_xpm[] = {
73"14 14 47 1", 73"14 14 47 1",
74" c None", 74" c None",
75". c #101010", 75". c #101010",
76"+ c #0D0D0D", 76"+ c #0D0D0D",
77"@ c #0B0B0B", 77"@ c #0B0B0B",
78"# c #393939", 78"# c #393939",
79"$ c #6C6C6C", 79"$ c #6C6C6C",
80"% c #5D5D5D", 80"% c #5D5D5D",
81"& c #4E4E4E", 81"& c #4E4E4E",
82"* c #1C1C1C", 82"* c #1C1C1C",
83"= c #131313", 83"= c #131313",
84"- c #7B7B7B", 84"- c #7B7B7B",
85"; c #303030", 85"; c #303030",
86"> c #383838", 86"> c #383838",
87", c #3F3F3F", 87", c #3F3F3F",
88"' c #343434", 88"' c #343434",
89") c #060606", 89") c #060606",
90"! c #444444", 90"! c #444444",
91"~ c #646464", 91"~ c #646464",
92"{ c #505050", 92"{ c #505050",
93"] c #717171", 93"] c #717171",
94"^ c #1B1B1B", 94"^ c #1B1B1B",
95"/ c #585858", 95"/ c #585858",
96"( c #4C4C4C", 96"( c #4C4C4C",
97"_ c #353535", 97"_ c #353535",
98": c #0E0E0E", 98": c #0E0E0E",
99"< c #080808", 99"< c #080808",
100"[ c #262626", 100"[ c #262626",
101"} c #121212", 101"} c #121212",
102"| c #7F7F7F", 102"| c #7F7F7F",
103"1 c #464646", 103"1 c #464646",
104"2 c #0C0C0C", 104"2 c #0C0C0C",
105"3 c #727272", 105"3 c #727272",
106"4 c #292929", 106"4 c #292929",
107"5 c #656565", 107"5 c #656565",
108"6 c #565656", 108"6 c #565656",
109"7 c #434343", 109"7 c #434343",
110"8 c #272727", 110"8 c #272727",
111"9 c #0F0F0F", 111"9 c #0F0F0F",
112"0 c #3A3A3A", 112"0 c #3A3A3A",
113"a c #090909", 113"a c #090909",
114"b c #535353", 114"b c #535353",
115"c c #545454", 115"c c #545454",
116"d c #494949", 116"d c #494949",
117"e c #7A7A7A", 117"e c #7A7A7A",
118"f c #202020", 118"f c #202020",
119"g c #3D3D3D", 119"g c #3D3D3D",
120"h c #1F1F1F", 120"h c #1F1F1F",
121" .+@ ", 121" .+@ ",
122" #$%&* ", 122" #$%&* ",
123" =-;>,')", 123" =-;>,')",
124" .$;!~,)", 124" .$;!~,)",
125" ;#{]!)", 125" ;#{]!)",
126" ^~/(_)", 126" ^~/(_)",
127" ./:@<[)", 127" ./:@<[)",
128" }. .|]1;;2 ", 128" }. .|]1;;2 ",
129" #-$;^/3&;;4@ ", 129" #-$;^/3&;;4@ ",
130".$;;#5:67;89 ", 130".$;;#5:67;89 ",
131":%;0%&ab;8. ", 131":%;0%&ab;8. ",
132"@cd%e!fg49 ", 132"@cd%e!fg49 ",
133" h0,!_;2@ ", 133" h0,!_;2@ ",
134" ))))) "}; 134" ))))) "};
135 135
136VMemo::VMemo( QWidget *parent, const char *_name ) 136VMemo::VMemo( QWidget *parent, const char *_name )
137 : QWidget( parent, _name ) 137 : QWidget( parent, _name )
138{ 138{
139 setFixedHeight( 18 ); 139 setFixedHeight( 18 );
140 setFixedWidth( 14 ); 140 setFixedWidth( 14 );
141 141
142 recording = FALSE; 142 recording = FALSE;
143 143
144 struct utsname name; /* check for embedix kernel running on the zaurus*/ 144 struct utsname name; /* check for embedix kernel running on the zaurus*/
145 if (uname(&name) != -1) { 145 if (uname(&name) != -1) {
146 QString release=name.release; 146 QString release=name.release;
147 if(release.find("embedix",0,TRUE) !=-1) 147 if(release.find("embedix",0,TRUE) !=-1)
148 systemZaurus=TRUE; 148 systemZaurus=TRUE;
149 else { 149 else {
150 systemZaurus=FALSE; 150 systemZaurus=FALSE;
151 myChannel = new QCopChannel( "QPE/VMemo", this ); 151 myChannel = new QCopChannel( "QPE/VMemo", this );
152 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 152 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
153 this, SLOT(receive(const QCString&, const QByteArray&)) ); 153 this, SLOT(receive(const QCString&, const QByteArray&)) );
154 154
155// // Register the REC key press, for ipaq only 155// // Register the REC key press, for ipaq only
156 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 156 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
157 e << 4096; 157 e << 4096;
158 e << QString("QPE/VMemo"); 158 e << QString("QPE/VMemo");
159 e << QString("toggleRecord()"); 159 e << QString("toggleRecord()");
160 } 160 }
161 } 161 }
162} 162}
163 163
164VMemo::~VMemo() 164VMemo::~VMemo()
165{ 165{
166} 166}
167 167
168void VMemo::receive( const QCString &msg, const QByteArray &data ) 168void VMemo::receive( const QCString &msg, const QByteArray &data )
169{ 169{
170 QDataStream stream( data, IO_ReadOnly ); 170 QDataStream stream( data, IO_ReadOnly );
171 if (msg == "toggleRecord()") 171 if (msg == "toggleRecord()")
172 { 172 {
173 if (recording) 173 if (recording)
174 mouseReleaseEvent(NULL); 174 mouseReleaseEvent(NULL);
175 else 175 else
176 mousePressEvent(NULL); 176 mousePressEvent(NULL);
177 } 177 }
178} 178}
179 179
180void VMemo::paintEvent( QPaintEvent* ) 180void VMemo::paintEvent( QPaintEvent* )
181{ 181{
182 QPainter p(this); 182 QPainter p(this);
183 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 183 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
184} 184}
185 185
186void VMemo::mousePressEvent( QMouseEvent *me ) 186void VMemo::mousePressEvent( QMouseEvent *me )
187{ 187{
188 // just to be safe 188 // just to be safe
189 if (recording) 189 if (recording)
190 { 190 {
191 recording = FALSE; 191 recording = FALSE;
192 return; 192 return;
193 } 193 }
194 194
195 /* 195 /*
196 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 196 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
197 mousePressEvent and mouseReleaseEvent with a NULL parameter. 197 mousePressEvent and mouseReleaseEvent with a NULL parameter.
198 */ 198 */
199// if (!systemZaurus && me != NULL) 199// if (!systemZaurus && me != NULL)
200// return; 200// return;
201 201
202 QSound::play(Resource::findSound("vmemob")); 202 QSound::play(Resource::findSound("vmemob"));
203 qDebug("Start recording"); 203 qDebug("Start recording");
204 recording = TRUE; 204 recording = TRUE;
205 if (openDSP() == -1) 205 if (openDSP() == -1)
206 { 206 {
207 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); 207 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort");
208 recording = FALSE; 208 recording = FALSE;
209 return; 209 return;
210 } 210 }
211 211
212 Config vmCfg("VMemo"); 212 Config vmCfg("VMemo");
213 vmCfg.setGroup("Defaults"); 213 vmCfg.setGroup("Defaults");
214 214
215 QDateTime dt = QDateTime::currentDateTime(); 215 QDateTime dt = QDateTime::currentDateTime();
216 QString fileName; 216 QString fileName;
217 217
218 if(systemZaurus) 218 if(systemZaurus)
219 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs 219 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
220 else 220 else
221 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); 221 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
222 222
223 fileName += "vm_"; 223 fileName += "vm_";
224 fileName += dt.toString(); 224 fileName += dt.toString();
225 fileName += ".wav"; 225 fileName += ".wav";
226 226
227 // No spaces in the filename 227 // No spaces in the filename
228 fileName.replace(QRegExp("'"),""); 228 fileName.replace(QRegExp("'"),"");
229 fileName.replace(QRegExp(" "),"_"); 229 fileName.replace(QRegExp(" "),"_");
230 fileName.replace(QRegExp(":"),"."); 230 fileName.replace(QRegExp(":"),".");
231 fileName.replace(QRegExp(","),""); 231 fileName.replace(QRegExp(","),"");
232 232
233 if(openWAV(fileName.latin1()) == -1) 233 if(openWAV(fileName.latin1()) == -1)
234 { 234 {
235 QString err("Could not open the output file: "); 235 QString err("Could not open the output file: ");
236 err += fileName; 236 err += fileName;
237 237
238 QMessageBox::critical(0, "VMemo", err, "Abort"); 238 QMessageBox::critical(0, "VMemo", err, "Abort");
239 close(dsp); 239 close(dsp);
240 return; 240 return;
241 } 241 }
242 242
243 QArray<int> cats(1); 243 QArray<int> cats(1);
244 cats[0] = vmCfg.readNumEntry("Category", 0); 244 cats[0] = vmCfg.readNumEntry("Category", 0);
245 245
246 QString dlName("vm_"); 246 QString dlName("vm_");
247 dlName += dt.toString(); 247 dlName += dt.toString();
248 DocLnk l; 248 DocLnk l;
249 l.setFile(fileName); 249 l.setFile(fileName);
250 l.setName(dlName); 250 l.setName(dlName);
251 l.setType("audio/x-wav"); 251 l.setType("audio/x-wav");
252 l.setCategories(cats); 252 l.setCategories(cats);
253 l.writeLink(); 253 l.writeLink();
254 254
255 record(); 255 record();
256} 256}
257 257
258void VMemo::mouseReleaseEvent( QMouseEvent * ) 258void VMemo::mouseReleaseEvent( QMouseEvent * )
259{ 259{
260 recording = FALSE; 260 recording = FALSE;
261} 261}
262 262
263int VMemo::openDSP() 263int VMemo::openDSP()
264{ 264{
265 Config cfg("Sound"); 265 Config cfg("Sound");
266 cfg.setGroup("Record"); 266 cfg.setGroup("Record");
267 267
268 speed = cfg.readNumEntry("SampleRate", 22050); 268 speed = cfg.readNumEntry("SampleRate", 22050);
269 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 269 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
270 if (cfg.readNumEntry("SixteenBit", 1)==1) { 270 if (cfg.readNumEntry("SixteenBit", 1)==1) {
271 format = AFMT_S16_LE; 271 format = AFMT_S16_LE;
272 resolution = 16; 272 resolution = 16;
273 } 273 }
274 else { 274 else {
275 format = AFMT_S8; 275 format = AFMT_S8;
276 resolution = 8; 276 resolution = 8;
277 } 277 }
278 278
279 if(systemZaurus) { 279 if(systemZaurus) {
280 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 280 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
281 channels=1; //zaurus has one input channel 281 channels=1; //zaurus has one input channel
282 } else { 282 } else {
283 dsp = open("/dev/dsp", O_RDWR); 283 dsp = open("/dev/dsp", O_RDWR);
284 } 284 }
285 285
286 if(dsp == -1) { 286 if(dsp == -1) {
287 perror("open(\"/dev/dsp\")"); 287 perror("open(\"/dev/dsp\")");
288 return -1; 288 return -1;
289 } 289 }
290 290
291 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 291 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
292 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 292 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
293 return -1; 293 return -1;
294 } 294 }
295 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 295 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
296 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 296 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
297 return -1; 297 return -1;
298 } 298 }
299 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 299 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
300 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 300 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
301 return -1; 301 return -1;
302 } 302 }
303 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 303 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
304 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 304 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
305 return -1; 305 return -1;
306 } 306 }
307 307
308 return 1; 308 return 1;
309} 309}
310 310
311int VMemo::openWAV(const char *filename) 311int VMemo::openWAV(const char *filename)
312{ 312{
313 track.setName(filename); 313 track.setName(filename);
314 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) 314 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw))
315 return -1; 315 return -1;
316 316
317 wav=track.handle(); 317 wav=track.handle();
318 318
319 WaveHeader wh; 319 WaveHeader wh;
320 320
321 wh.main_chunk = RIFF; 321 wh.main_chunk = RIFF;
322 wh.length=0; 322 wh.length=0;
323 wh.chunk_type = WAVE; 323 wh.chunk_type = WAVE;
324 wh.sub_chunk = FMT; 324 wh.sub_chunk = FMT;
325 wh.sc_len = 16; 325 wh.sc_len = 16;
326 wh.format = PCM_CODE; 326 wh.format = PCM_CODE;
327 wh.modus = channels; 327 wh.modus = channels;
328 wh.sample_fq = speed; 328 wh.sample_fq = speed;
329 wh.byte_p_sec = speed * channels * resolution/8; 329 wh.byte_p_sec = speed * channels * resolution/8;
330 wh.byte_p_spl = channels * (resolution / 8); 330 wh.byte_p_spl = channels * (resolution / 8);
331 wh.bit_p_spl = resolution; 331 wh.bit_p_spl = resolution;
332 wh.data_chunk = DATA; 332 wh.data_chunk = DATA;
333 wh.data_length= 0; 333 wh.data_length= 0;
334 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 334 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
335 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 335 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
336 write (wav, &wh, sizeof(WaveHeader)); 336 write (wav, &wh, sizeof(WaveHeader));
337 337
338 return 1; 338 return 1;
339} 339}
340 340
341void VMemo::record(void) 341void VMemo::record(void)
342{ 342{
343 int length=0, result, value; 343 int length=0, result, value;
344 qDebug("Recording"); 344 qDebug("Recording");
345 345
346 if(systemZaurus) { 346 if(systemZaurus) {
347 signed short sound[512], monoBuffer[512]; 347 signed short sound[512], monoBuffer[512];
348 348
349 if(format==AFMT_S16_LE) { 349 if(format==AFMT_S16_LE) {
350 while(recording) { 350 while(recording) {
351 result = read(dsp, sound, 512); // 8192 351 result = read(dsp, sound, 512); // 8192
352 qApp->processEvents(); 352 qApp->processEvents();
353 int j=0; 353 int j=0;
354 if(systemZaurus) { 354 if(systemZaurus) {
355 for (int i = 0; i < result; i++) { //since Z is mono do normally 355 for (int i = 0; i < result; i++) { //since Z is mono do normally
356 monoBuffer[i] = sound[i]; 356 monoBuffer[i] = sound[i];
357 } 357 }
358 qApp->processEvents(); 358 qApp->processEvents();
359 length+=write(wav, monoBuffer, result); 359 length+=write(wav, monoBuffer, result);
360 } else { //ipaq /stereo inputs 360 } else { //ipaq /stereo inputs
361 for (int i = 0; i < result; i+=2) { 361 for (int i = 0; i < result; i+=2) {
362 monoBuffer[j] = (sound[i]+sound[i+1])/2; 362 monoBuffer[j] = (sound[i]+sound[i+1])/2;
363 j++; 363 j++;
364 } 364 }
365 qApp->processEvents(); 365 qApp->processEvents();
366 length+=write(wav, monoBuffer, result/2); 366 length+=write(wav, monoBuffer, result/2);
367 } 367 }
368 printf("%d\r",length); 368 printf("%d\r",length);
369 fflush(stdout); 369 fflush(stdout);
370 } 370 }
371 } 371 }
372 else { //AFMT_S8 // don't try this yet.. as player doesn't understand 8bit unsigned 372 else { //AFMT_S8 // don't try this yet.. as player doesn't understand 8bit unsigned
373 while(recording) 373 while(recording)
374 { 374 {
375 result = read(dsp, sound, 512); // 8192 375 result = read(dsp, sound, 512); // 8192
376 qApp->processEvents(); 376 qApp->processEvents();
377 int j=0; 377 int j=0;
378 if(systemZaurus) 378 if(systemZaurus)
379 { 379 {
380 for (int i = 0; i < result; i++) { //since Z is mono do normally 380 for (int i = 0; i < result; i++) { //since Z is mono do normally
381 monoBuffer[i] = sound[i]; 381 monoBuffer[i] = sound[i];
382 } 382 }
383 qApp->processEvents(); 383 qApp->processEvents();
384 length+=write(wav, monoBuffer, result); 384 length+=write(wav, monoBuffer, result);
385 } else { //ipaq /stereo inputs 385 } else { //ipaq /stereo inputs
386 for (int i = 0; i < result; i+=2) { 386 for (int i = 0; i < result; i+=2) {
387 monoBuffer[j] = (sound[i]+sound[i+1])/2; 387 monoBuffer[j] = (sound[i]+sound[i+1])/2;
388 j++; 388 j++;
389 } 389 }
390 qApp->processEvents(); 390 qApp->processEvents();
391 length+=write(wav, monoBuffer, result/2); 391 length+=write(wav, monoBuffer, result/2);
392 } 392 }
393 length += result; 393 length += result;
394 printf("%d\r",length); 394 printf("%d\r",length);
395 fflush(stdout); 395 fflush(stdout);
396 396
397 qApp->processEvents(); 397 qApp->processEvents();
398 } 398 }
399} 399 }
400 400
401} else { 401 } else {
402 402
403 char sound[512]; //char is 8 bit 403 char sound[512]; //char is 8 bit
404 404
405 while(recording) 405 while(recording)
406{ 406 {
407 result = read(dsp, sound, 512); // 8192 407 result = read(dsp, sound, 512); // 8192
408 qApp->processEvents(); 408 qApp->processEvents();
409 409
410 write(wav, sound, result); 410 write(wav, sound, result);
411 length += result; 411 length += result;
412 412
413 qApp->processEvents(); 413 qApp->processEvents();
414} 414 }
415// qDebug("file has length of %d lasting %d seconds", 415 // qDebug("file has length of %d lasting %d seconds",
416// length, (( length / speed) / channels) / 2 ); 416 // length, (( length / speed) / channels) / 2 );
417// medialplayer states wrong length in secs 417 // medialplayer states wrong length in secs
418} 418 }
419 419
420 value = length+36; 420 value = length+36;
421 lseek(wav, 4, SEEK_SET); 421 lseek(wav, 4, SEEK_SET);
422 write(wav, &value, 4); 422 write(wav, &value, 4);
423 lseek(wav, 40, SEEK_SET); 423 lseek(wav, 40, SEEK_SET);
424 write(wav, &length, 4); 424 write(wav, &length, 4);
425 track.close(); 425 track.close();
426 426
427 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 427 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
428 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 428 perror("ioctl(\"SNDCTL_DSP_RESET\")");
429 ::close(dsp); 429 ::close(dsp);
430 if(systemZaurus) 430 if(systemZaurus)
431 QMessageBox::message("Vmemo"," Done recording"); 431 QMessageBox::message("Vmemo"," Done recording");
432 432
433 QSound::play(Resource::findSound("vmemoe")); 433 QSound::play(Resource::findSound("vmemoe"));
434} 434}