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