summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-27 05:29:36 (UTC)
committer llornkcor <llornkcor>2002-03-27 05:29:36 (UTC)
commit347240bf66daf78f6a0e7c98bc32a53810f710a9 (patch) (unidiff)
tree8b638f2e12cb32b8bdbe329aa2a1d03635105329
parent531e1365f5ae7ffcbfc9c9ebe92274282358025e (diff)
downloadopie-347240bf66daf78f6a0e7c98bc32a53810f710a9.zip
opie-347240bf66daf78f6a0e7c98bc32a53810f710a9.tar.gz
opie-347240bf66daf78f6a0e7c98bc32a53810f710a9.tar.bz2
forgot to uncomment ipaq code again
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index e6c4ff9..4d4d598 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,498 +1,498 @@
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"16 16 102 2", 73"16 16 102 2",
74" c None", 74" c None",
75". c #60636A", 75". c #60636A",
76"+ c #6E6E72", 76"+ c #6E6E72",
77"@ c #68696E", 77"@ c #68696E",
78"# c #4D525C", 78"# c #4D525C",
79"$ c #6B6C70", 79"$ c #6B6C70",
80"% c #E3E3E8", 80"% c #E3E3E8",
81"& c #EEEEF2", 81"& c #EEEEF2",
82"* c #EAEAEF", 82"* c #EAEAEF",
83"= c #CACAD0", 83"= c #CACAD0",
84"- c #474A51", 84"- c #474A51",
85"; c #171819", 85"; c #171819",
86"> c #9B9B9F", 86"> c #9B9B9F",
87", c #EBEBF0", 87", c #EBEBF0",
88"' c #F4F4F7", 88"' c #F4F4F7",
89") c #F1F1F5", 89") c #F1F1F5",
90"! c #DEDEE4", 90"! c #DEDEE4",
91"~ c #57575C", 91"~ c #57575C",
92"{ c #010101", 92"{ c #010101",
93"] c #A2A2A6", 93"] c #A2A2A6",
94"^ c #747477", 94"^ c #747477",
95"/ c #B5B5B8", 95"/ c #B5B5B8",
96"( c #AEAEB2", 96"( c #AEAEB2",
97"_ c #69696D", 97"_ c #69696D",
98": c #525256", 98": c #525256",
99"< c #181C24", 99"< c #181C24",
100"[ c #97979B", 100"[ c #97979B",
101"} c #A7A7AC", 101"} c #A7A7AC",
102"| c #B0B0B4", 102"| c #B0B0B4",
103"1 c #C8C8D1", 103"1 c #C8C8D1",
104"2 c #75757B", 104"2 c #75757B",
105"3 c #46464A", 105"3 c #46464A",
106"4 c #494A4F", 106"4 c #494A4F",
107"5 c #323234", 107"5 c #323234",
108"6 c #909095", 108"6 c #909095",
109"7 c #39393B", 109"7 c #39393B",
110"8 c #757578", 110"8 c #757578",
111"9 c #87878E", 111"9 c #87878E",
112"0 c #222224", 112"0 c #222224",
113"a c #414144", 113"a c #414144",
114"b c #6A6A6E", 114"b c #6A6A6E",
115"c c #020C16", 115"c c #020C16",
116"d c #6B6B6F", 116"d c #6B6B6F",
117"e c #68686D", 117"e c #68686D",
118"f c #5B5B60", 118"f c #5B5B60",
119"g c #8A8A8F", 119"g c #8A8A8F",
120"h c #6B6B6E", 120"h c #6B6B6E",
121"i c #ADADB2", 121"i c #ADADB2",
122"j c #828289", 122"j c #828289",
123"k c #3E3E41", 123"k c #3E3E41",
124"l c #CFCFD7", 124"l c #CFCFD7",
125"m c #4C4C50", 125"m c #4C4C50",
126"n c #000000", 126"n c #000000",
127"o c #66666A", 127"o c #66666A",
128"p c #505054", 128"p c #505054",
129"q c #838388", 129"q c #838388",
130"r c #A1A1A7", 130"r c #A1A1A7",
131"s c #A9A9AE", 131"s c #A9A9AE",
132"t c #A8A8B0", 132"t c #A8A8B0",
133"u c #5E5E63", 133"u c #5E5E63",
134"v c #3A3A3E", 134"v c #3A3A3E",
135"w c #BDBDC6", 135"w c #BDBDC6",
136"x c #59595E", 136"x c #59595E",
137"y c #76767C", 137"y c #76767C",
138"z c #373738", 138"z c #373738",
139"A c #717174", 139"A c #717174",
140"B c #727278", 140"B c #727278",
141"C c #1C1C1E", 141"C c #1C1C1E",
142"D c #3C3C3F", 142"D c #3C3C3F",
143"E c #ADADB6", 143"E c #ADADB6",
144"F c #54555A", 144"F c #54555A",
145"G c #8B8C94", 145"G c #8B8C94",
146"H c #5A5A5F", 146"H c #5A5A5F",
147"I c #BBBBC3", 147"I c #BBBBC3",
148"J c #C4C4CB", 148"J c #C4C4CB",
149"K c #909098", 149"K c #909098",
150"L c #737379", 150"L c #737379",
151"M c #343437", 151"M c #343437",
152"N c #8F8F98", 152"N c #8F8F98",
153"O c #000407", 153"O c #000407",
154"P c #2D3137", 154"P c #2D3137",
155"Q c #B0B1BC", 155"Q c #B0B1BC",
156"R c #3B3C40", 156"R c #3B3C40",
157"S c #6E6E74", 157"S c #6E6E74",
158"T c #95959C", 158"T c #95959C",
159"U c #74747A", 159"U c #74747A",
160"V c #1D1D1E", 160"V c #1D1D1E",
161"W c #91929A", 161"W c #91929A",
162"X c #42444A", 162"X c #42444A",
163"Y c #22282E", 163"Y c #22282E",
164"Z c #B0B2BC", 164"Z c #B0B2BC",
165"` c #898A90", 165"` c #898A90",
166" . c #65656A", 166" . c #65656A",
167".. c #999AA2", 167".. c #999AA2",
168"+. c #52535A", 168"+. c #52535A",
169"@. c #151B21", 169"@. c #151B21",
170"#. c #515257", 170"#. c #515257",
171"$. c #B5B5BE", 171"$. c #B5B5BE",
172"%. c #616167", 172"%. c #616167",
173"&. c #1A1D22", 173"&. c #1A1D22",
174"*. c #000713", 174"*. c #000713",
175"=. c #1F1F21", 175"=. c #1F1F21",
176" ", 176" ",
177" . + @ # ", 177" . + @ # ",
178" $ % & * = - ", 178" $ % & * = - ",
179" ; > , ' ) ! ~ ", 179" ; > , ' ) ! ~ ",
180" { ] ^ / ( _ : ", 180" { ] ^ / ( _ : ",
181" < [ } | 1 2 3 ", 181" < [ } | 1 2 3 ",
182" 4 5 6 7 8 9 0 a b c ", 182" 4 5 6 7 8 9 0 a b c ",
183" d e f g h i j 3 k l m n ", 183" d e f g h i j 3 k l m n ",
184" o p q r s t u v w n ", 184" o p q r s t u v w n ",
185" o x y z A B C D E n ", 185" o x y z A B C D E n ",
186" F G H I J K L M N O ", 186" F G H I J K L M N O ",
187" P Q R S T U V W X ", 187" P Q R S T U V W X ",
188" Y Z ` b ...+. ", 188" Y Z ` b ...+. ",
189" @.#.$.%.&. ", 189" @.#.$.%.&. ",
190" *.B =. ", 190" *.B =. ",
191" n n n n n n n n n "}; 191" n n n n n n n n n "};
192 192
193 193
194VMemo::VMemo( QWidget *parent, const char *_name ) 194VMemo::VMemo( QWidget *parent, const char *_name )
195 : QWidget( parent, _name ) 195 : QWidget( parent, _name )
196{ 196{
197 setFixedHeight( 18 ); 197 setFixedHeight( 18 );
198 setFixedWidth( 14 ); 198 setFixedWidth( 14 );
199 199
200 recording = FALSE; 200 recording = FALSE;
201 201
202 struct utsname name; /* check for embedix kernel running on the zaurus*/ 202 struct utsname name; /* check for embedix kernel running on the zaurus*/
203 if (uname(&name) != -1) { 203 if (uname(&name) != -1) {
204 QString release=name.release; 204 QString release=name.release;
205 if(release.find("embedix",0,TRUE) !=-1) 205 if(release.find("embedix",0,TRUE) !=-1)
206 systemZaurus=TRUE; 206 systemZaurus=TRUE;
207 else { 207 else {
208 systemZaurus=FALSE; 208 systemZaurus=FALSE;
209 myChannel = new QCopChannel( "QPE/VMemo", this ); 209 myChannel = new QCopChannel( "QPE/VMemo", this );
210 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 210 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
211 this, SLOT(receive(const QCString&, const QByteArray&)) ); 211 this, SLOT(receive(const QCString&, const QByteArray&)) );
212 212
213// // Register the REC key press, for ipaq only 213// // Register the REC key press, for ipaq only
214 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 214 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
215 e << 4096; 215 e << 4096;
216 e << QString("QPE/VMemo"); 216 e << QString("QPE/VMemo");
217 e << QString("toggleRecord()"); 217 e << QString("toggleRecord()");
218 } 218 }
219 } 219 }
220} 220}
221 221
222VMemo::~VMemo() 222VMemo::~VMemo()
223{ 223{
224} 224}
225 225
226void VMemo::receive( const QCString &msg, const QByteArray &data ) 226void VMemo::receive( const QCString &msg, const QByteArray &data )
227{ 227{
228 QDataStream stream( data, IO_ReadOnly ); 228 QDataStream stream( data, IO_ReadOnly );
229 if (msg == "toggleRecord()") { 229 if (msg == "toggleRecord()") {
230 if (recording) 230 if (recording)
231 mouseReleaseEvent(NULL); 231 mouseReleaseEvent(NULL);
232 else 232 else
233 mousePressEvent(NULL); 233 mousePressEvent(NULL);
234 } 234 }
235} 235}
236 236
237void VMemo::paintEvent( QPaintEvent* ) 237void VMemo::paintEvent( QPaintEvent* )
238{ 238{
239 QPainter p(this); 239 QPainter p(this);
240 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 240 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
241} 241}
242 242
243void VMemo::mousePressEvent( QMouseEvent *me ) 243void VMemo::mousePressEvent( QMouseEvent *me )
244{ 244{
245 // just to be safe 245 // just to be safe
246 if (recording) { 246 if (recording) {
247 recording = FALSE; 247 recording = FALSE;
248 return; 248 return;
249 } 249 }
250 250
251 /* 251 /*
252 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 252 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
253 mousePressEvent and mouseReleaseEvent with a NULL parameter. 253 mousePressEvent and mouseReleaseEvent with a NULL parameter.
254 */ 254 */
255// if (!systemZaurus && me != NULL) 255 if (!systemZaurus && me != NULL)
256// return; 256 return;
257 257
258// Config config( "Sound" ); 258// Config config( "Sound" );
259// config.setGroup( "System" ); 259// config.setGroup( "System" );
260// useAlerts = config.readBoolEntry("Alert"); 260// useAlerts = config.readBoolEntry("Alert");
261 261
262// if(useAlerts) { 262// if(useAlerts) {
263// if( QMessageBox::warning(this,"VMemo","Really Record?","Yes","No",0,0,1) ==1) 263// if( QMessageBox::warning(this,"VMemo","Really Record?","Yes","No",0,0,1) ==1)
264// return; 264// return;
265// } else { 265// } else {
266 QSound::play(Resource::findSound("vmemob")); 266 QSound::play(Resource::findSound("vmemob"));
267// } 267// }
268 qDebug("Start recording"); 268 qDebug("Start recording");
269 recording = TRUE; 269 recording = TRUE;
270 if (openDSP() == -1) { 270 if (openDSP() == -1) {
271 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); 271 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort");
272 recording = FALSE; 272 recording = FALSE;
273 return; 273 return;
274 } 274 }
275 275
276 Config vmCfg("VMemo"); 276 Config vmCfg("VMemo");
277 vmCfg.setGroup("Defaults"); 277 vmCfg.setGroup("Defaults");
278 278
279 QDateTime dt = QDateTime::currentDateTime(); 279 QDateTime dt = QDateTime::currentDateTime();
280 QString fileName; 280 QString fileName;
281 281
282 if(systemZaurus) 282 if(systemZaurus)
283 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs 283 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
284 else 284 else
285 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); 285 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
286 286
287 fileName += "vm_"; 287 fileName += "vm_";
288 fileName += dt.toString(); 288 fileName += dt.toString();
289 fileName += ".wav"; 289 fileName += ".wav";
290 290
291 // No spaces in the filename 291 // No spaces in the filename
292 fileName.replace(QRegExp("'"),""); 292 fileName.replace(QRegExp("'"),"");
293 fileName.replace(QRegExp(" "),"_"); 293 fileName.replace(QRegExp(" "),"_");
294 fileName.replace(QRegExp(":"),"."); 294 fileName.replace(QRegExp(":"),".");
295 fileName.replace(QRegExp(","),""); 295 fileName.replace(QRegExp(","),"");
296 296
297 if(openWAV(fileName.latin1()) == -1) { 297 if(openWAV(fileName.latin1()) == -1) {
298 QString err("Could not open the output file: "); 298 QString err("Could not open the output file: ");
299 err += fileName; 299 err += fileName;
300 300
301 QMessageBox::critical(0, "VMemo", err, "Abort"); 301 QMessageBox::critical(0, "VMemo", err, "Abort");
302 close(dsp); 302 close(dsp);
303 return; 303 return;
304 } 304 }
305 305
306 QArray<int> cats(1); 306 QArray<int> cats(1);
307 cats[0] = vmCfg.readNumEntry("Category", 0); 307 cats[0] = vmCfg.readNumEntry("Category", 0);
308 308
309 QString dlName("vm_"); 309 QString dlName("vm_");
310 dlName += dt.toString(); 310 dlName += dt.toString();
311 DocLnk l; 311 DocLnk l;
312 l.setFile(fileName); 312 l.setFile(fileName);
313 l.setName(dlName); 313 l.setName(dlName);
314 l.setType("audio/x-wav"); 314 l.setType("audio/x-wav");
315 l.setCategories(cats); 315 l.setCategories(cats);
316 l.writeLink(); 316 l.writeLink();
317 317
318 record(); 318 record();
319} 319}
320 320
321void VMemo::mouseReleaseEvent( QMouseEvent * ) 321void VMemo::mouseReleaseEvent( QMouseEvent * )
322{ 322{
323 recording = FALSE; 323 recording = FALSE;
324} 324}
325 325
326int VMemo::openDSP() 326int VMemo::openDSP()
327{ 327{
328 Config cfg("Sound"); 328 Config cfg("Sound");
329 cfg.setGroup("Record"); 329 cfg.setGroup("Record");
330 330
331 speed = cfg.readNumEntry("SampleRate", 22050); 331 speed = cfg.readNumEntry("SampleRate", 22050);
332 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 332 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
333 if (cfg.readNumEntry("SixteenBit", 1)==1) { 333 if (cfg.readNumEntry("SixteenBit", 1)==1) {
334 format = AFMT_S16_LE; 334 format = AFMT_S16_LE;
335 resolution = 16; 335 resolution = 16;
336 } else { 336 } else {
337 format = AFMT_S8; 337 format = AFMT_S8;
338 resolution = 8; 338 resolution = 8;
339 } 339 }
340 340
341 341
342 if(systemZaurus) { 342 if(systemZaurus) {
343 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 343 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
344 channels=1; //zaurus has one input channel 344 channels=1; //zaurus has one input channel
345 } else { 345 } else {
346 dsp = open("/dev/dsp", O_RDWR); 346 dsp = open("/dev/dsp", O_RDWR);
347 } 347 }
348 348
349 if(dsp == -1) { 349 if(dsp == -1) {
350 perror("open(\"/dev/dsp\")"); 350 perror("open(\"/dev/dsp\")");
351 return -1; 351 return -1;
352 } 352 }
353 353
354 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 354 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
355 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 355 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
356 return -1; 356 return -1;
357 } 357 }
358 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 358 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
359 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 359 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
360 return -1; 360 return -1;
361 } 361 }
362 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 362 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
363 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 363 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
364 return -1; 364 return -1;
365 } 365 }
366 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 366 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
367 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 367 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
368 return -1; 368 return -1;
369 } 369 }
370 370
371 return 1; 371 return 1;
372} 372}
373 373
374int VMemo::openWAV(const char *filename) 374int VMemo::openWAV(const char *filename)
375{ 375{
376 track.setName(filename); 376 track.setName(filename);
377 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) 377 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw))
378 return -1; 378 return -1;
379 379
380 wav=track.handle(); 380 wav=track.handle();
381 381
382 WaveHeader wh; 382 WaveHeader wh;
383 383
384 wh.main_chunk = RIFF; 384 wh.main_chunk = RIFF;
385 wh.length=0; 385 wh.length=0;
386 wh.chunk_type = WAVE; 386 wh.chunk_type = WAVE;
387 wh.sub_chunk = FMT; 387 wh.sub_chunk = FMT;
388 wh.sc_len = 16; 388 wh.sc_len = 16;
389 wh.format = PCM_CODE; 389 wh.format = PCM_CODE;
390 wh.modus = channels; 390 wh.modus = channels;
391 wh.sample_fq = speed; 391 wh.sample_fq = speed;
392 wh.byte_p_sec = speed * channels * resolution/8; 392 wh.byte_p_sec = speed * channels * resolution/8;
393 wh.byte_p_spl = channels * (resolution / 8); 393 wh.byte_p_spl = channels * (resolution / 8);
394 wh.bit_p_spl = resolution; 394 wh.bit_p_spl = resolution;
395 wh.data_chunk = DATA; 395 wh.data_chunk = DATA;
396 wh.data_length= 0; 396 wh.data_length= 0;
397 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 397 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
398 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 398 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
399 write (wav, &wh, sizeof(WaveHeader)); 399 write (wav, &wh, sizeof(WaveHeader));
400 400
401 return 1; 401 return 1;
402} 402}
403 403
404void VMemo::record(void) 404void VMemo::record(void)
405{ 405{
406 int length=0, result, value; 406 int length=0, result, value;
407 qDebug("Recording"); 407 qDebug("Recording");
408 408
409 if(systemZaurus) { 409 if(systemZaurus) {
410 signed short sound[512], monoBuffer[512]; 410 signed short sound[512], monoBuffer[512];
411 if(format==AFMT_S16_LE) { 411 if(format==AFMT_S16_LE) {
412 while(recording) { 412 while(recording) {
413 result = read(dsp, sound, 512); // 8192 413 result = read(dsp, sound, 512); // 8192
414 qApp->processEvents(); 414 qApp->processEvents();
415 int j=0; 415 int j=0;
416 if(systemZaurus) { 416 if(systemZaurus) {
417 for (int i = 0; i < result; i++) { //since Z is mono do normally 417 for (int i = 0; i < result; i++) { //since Z is mono do normally
418 monoBuffer[i] = sound[i]; 418 monoBuffer[i] = sound[i];
419 } 419 }
420 qApp->processEvents(); 420 qApp->processEvents();
421 length+=write(wav, monoBuffer, result); 421 length+=write(wav, monoBuffer, result);
422 } else { //ipaq /stereo inputs 422 } else { //ipaq /stereo inputs
423 for (int i = 0; i < result; i+=2) { 423 for (int i = 0; i < result; i+=2) {
424 monoBuffer[j] = (sound[i]+sound[i+1])/2; 424 monoBuffer[j] = (sound[i]+sound[i+1])/2;
425 j++; 425 j++;
426 } 426 }
427 qApp->processEvents(); 427 qApp->processEvents();
428 length+=write(wav, monoBuffer, result/2); 428 length+=write(wav, monoBuffer, result/2);
429 } 429 }
430 printf("%d\r",length); 430 printf("%d\r",length);
431 fflush(stdout); 431 fflush(stdout);
432 } 432 }
433 } else { //AFMT_S8 433 } else { //AFMT_S8
434// 8bit unsigned 434// 8bit unsigned
435 unsigned short sound[512], monoBuffer[512]; 435 unsigned short sound[512], monoBuffer[512];
436 while(recording) { 436 while(recording) {
437 result = read(dsp, sound, 512); // 8192 437 result = read(dsp, sound, 512); // 8192
438 qApp->processEvents(); 438 qApp->processEvents();
439 int j=0; 439 int j=0;
440 if(systemZaurus) { 440 if(systemZaurus) {
441 for (int i = 0; i < result; i++) { //since Z is mono do normally 441 for (int i = 0; i < result; i++) { //since Z is mono do normally
442 monoBuffer[i] = sound[i]; 442 monoBuffer[i] = sound[i];
443 } 443 }
444 qApp->processEvents(); 444 qApp->processEvents();
445 length+=write(wav, monoBuffer, result); 445 length+=write(wav, monoBuffer, result);
446 } else { //ipaq /stereo inputs 446 } else { //ipaq /stereo inputs
447 for (int i = 0; i < result; i+=2) { 447 for (int i = 0; i < result; i+=2) {
448 monoBuffer[j] = (sound[i]+sound[i+1])/2; 448 monoBuffer[j] = (sound[i]+sound[i+1])/2;
449 j++; 449 j++;
450 } 450 }
451 qApp->processEvents(); 451 qApp->processEvents();
452 length+=write(wav, monoBuffer, result/2); 452 length+=write(wav, monoBuffer, result/2);
453 } 453 }
454 length += result; 454 length += result;
455 printf("%d\r",length); 455 printf("%d\r",length);
456 fflush(stdout); 456 fflush(stdout);
457 457
458 qApp->processEvents(); 458 qApp->processEvents();
459 } 459 }
460 460
461 qApp->processEvents(); 461 qApp->processEvents();
462 } 462 }
463 463
464 } else { 464 } else {
465 465
466 signed short sound[512], monoBuffer[512]; 466 signed short sound[512], monoBuffer[512];
467 467
468 while(recording) { 468 while(recording) {
469 result = read(dsp, sound, 512); // 8192 469 result = read(dsp, sound, 512); // 8192
470 qApp->processEvents(); 470 qApp->processEvents();
471 471
472 write(wav, sound, result); 472 write(wav, sound, result);
473 length += result; 473 length += result;
474 474
475 qApp->processEvents(); 475 qApp->processEvents();
476 } 476 }
477 printf("%d\r",length); 477 printf("%d\r",length);
478 fflush(stdout); 478 fflush(stdout);
479 // qDebug("file has length of %d lasting %d seconds", 479 // qDebug("file has length of %d lasting %d seconds",
480 // length, (( length / speed) / channels) / 2 ); 480 // length, (( length / speed) / channels) / 2 );
481 // medialplayer states wrong length in secs 481 // medialplayer states wrong length in secs
482 } 482 }
483 483
484 value = length+36; 484 value = length+36;
485 lseek(wav, 4, SEEK_SET); 485 lseek(wav, 4, SEEK_SET);
486 write(wav, &value, 4); 486 write(wav, &value, 4);
487 lseek(wav, 40, SEEK_SET); 487 lseek(wav, 40, SEEK_SET);
488 write(wav, &length, 4); 488 write(wav, &length, 4);
489 track.close(); 489 track.close();
490 490
491 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 491 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
492 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 492 perror("ioctl(\"SNDCTL_DSP_RESET\")");
493 ::close(dsp); 493 ::close(dsp);
494// if(useAlerts) 494// if(useAlerts)
495// QMessageBox::message("Vmemo"," Done recording"); 495// QMessageBox::message("Vmemo"," Done recording");
496// else 496// else
497 QSound::play(Resource::findSound("vmemoe")); 497 QSound::play(Resource::findSound("vmemoe"));
498} 498}