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