author | jeremy <jeremy> | 2002-02-15 21:10:04 (UTC) |
---|---|---|
committer | jeremy <jeremy> | 2002-02-15 21:10:04 (UTC) |
commit | b15950bcf97b5590d37373ec2beedab80e40ded6 (patch) (unidiff) | |
tree | 85f44cdb278d0b0825868892db8d3bc2d2a5fba5 | |
parent | 756a71b71837bd6771bec8fc510e072a5f4233f8 (diff) | |
download | opie-b15950bcf97b5590d37373ec2beedab80e40ded6.zip opie-b15950bcf97b5590d37373ec2beedab80e40ded6.tar.gz opie-b15950bcf97b5590d37373ec2beedab80e40ded6.tar.bz2 |
Added support for the rec button on iPAQ's. This addition will only work if
you have opie-taskbar-1.5.0_beta7.1 ...
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 97 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 1 |
2 files changed, 33 insertions, 65 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 5ce6fa9..006e0ba 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,434 +1,403 @@ | |||
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 | 16 | ||
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 | ||
29 | typedef struct _waveheader { | 29 | typedef 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 | ||
69 | int seq = 0; | 69 | int seq = 0; |
70 | 70 | ||
71 | /* XPM */ | 71 | /* XPM */ |
72 | static char * vmemo_xpm[] = { | 72 | static 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 | ||
136 | VMemo::VMemo( QWidget *parent, const char *name ) | 136 | VMemo::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 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 144 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
145 | connect( myChannel, SIGNAL(sayHi()), this, SLOT(sayHi()) ); | ||
146 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 145 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
147 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
148 | 147 | ||
149 | struct utsname name; /* check for embedix kernel running on the zaurus, if | 148 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
150 | lineo change string, this break | 149 | lineo change string, this break |
151 | */ | 150 | */ |
152 | if (uname(&name) != -1) | 151 | if (uname(&name) != -1) |
153 | { | 152 | { |
154 | QString release=name.release; | 153 | QString release=name.release; |
155 | qWarning("System release: %s\n", name.release); | 154 | qWarning("System release: %s\n", name.release); |
156 | if(release.find("embedix",0,TRUE) !=-1) | 155 | if(release.find("embedix",0,TRUE) !=-1) |
157 | systemZaurus=TRUE; | 156 | systemZaurus=TRUE; |
158 | else | 157 | else |
159 | { | 158 | { |
160 | int fr; | ||
161 | systemZaurus=FALSE; | 159 | systemZaurus=FALSE; |
162 | 160 | ||
163 | if ((fr = fork()) == -1) | 161 | // Register the REC key press. |
164 | { | 162 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
165 | qWarning("Fork failed"); | 163 | e << 4096; |
166 | } | 164 | e << QString("QPE/VMemo"); |
167 | else if (fr == 0) | 165 | e << QString("toggleRecord()"); |
168 | { | ||
169 | int key, max; | ||
170 | fd_set fdr; | ||
171 | char buffer[10]; | ||
172 | |||
173 | key = open("/dev/touchscreen/key", O_RDONLY); | ||
174 | if (key == -1) | ||
175 | { | ||
176 | qWarning("Could not open key"); | ||
177 | exit(1); | ||
178 | } | ||
179 | |||
180 | while(1) | ||
181 | { | ||
182 | FD_ZERO(&fdr); | ||
183 | FD_SET(key, &fdr); | ||
184 | max = key; | ||
185 | |||
186 | qWarning("while"); | ||
187 | |||
188 | read(key, buffer, 10); | ||
189 | if(*buffer == (char)129) | ||
190 | { | ||
191 | qWarning("REC = stop"); | ||
192 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
193 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
194 | } | ||
195 | else if(*buffer == (char)1) | ||
196 | { | ||
197 | qWarning("REC = start"); | ||
198 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
199 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | else if(fr) | ||
204 | qWarning("parent: Fork = good"); | ||
205 | } | 166 | } |
206 | } | 167 | } |
207 | qWarning("VMemo done init"); | 168 | qWarning("VMemo done init"); |
208 | } | 169 | } |
209 | 170 | ||
210 | VMemo::~VMemo() | 171 | VMemo::~VMemo() |
211 | { | 172 | { |
212 | } | 173 | } |
213 | 174 | ||
214 | void VMemo::sayHi() | ||
215 | { | ||
216 | qWarning("Hi"); | ||
217 | } | ||
218 | |||
219 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 175 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
220 | { | 176 | { |
221 | QDataStream stream( data, IO_ReadOnly ); | 177 | QDataStream stream( data, IO_ReadOnly ); |
222 | qWarning(msg); | 178 | qWarning("VMemo::receive: %s", (const char *)msg); |
223 | if ( msg == "toggleRecord()" ) { | 179 | if (msg == "toggleRecord()") |
224 | qWarning("Hello"); | 180 | { |
225 | } | 181 | if (recording) |
182 | mouseReleaseEvent(NULL); | ||
183 | else | ||
184 | mousePressEvent(NULL); | ||
185 | } | ||
226 | } | 186 | } |
227 | 187 | ||
228 | void VMemo::paintEvent( QPaintEvent* ) | 188 | void VMemo::paintEvent( QPaintEvent* ) |
229 | { | 189 | { |
230 | QPainter p(this); | 190 | QPainter p(this); |
231 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 191 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
232 | } | 192 | } |
233 | 193 | ||
234 | void VMemo::mousePressEvent( QMouseEvent * ) | 194 | void VMemo::mousePressEvent( QMouseEvent * ) |
235 | { | 195 | { |
236 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
237 | |||
238 | // just to be safe | 196 | // just to be safe |
239 | if (recording) | 197 | if (recording) |
240 | { | 198 | { |
241 | recording = FALSE; | 199 | recording = FALSE; |
242 | return; | 200 | return; |
243 | } | 201 | } |
244 | 202 | ||
245 | qWarning("VMemo::mousePress()"); | 203 | qWarning("VMemo::mousePress()"); |
246 | QSound::play(Resource::findSound("vmemob")); | 204 | QSound::play(Resource::findSound("vmemob")); |
247 | 205 | ||
248 | recording = TRUE; | 206 | recording = TRUE; |
249 | qWarning("VMemo::mousePress() -> Starting to record"); | 207 | qWarning("VMemo::mousePress() -> Starting to record"); |
250 | if (openDSP() == -1) | 208 | if (openDSP() == -1) |
251 | { | 209 | { |
252 | // ### Display an error box | 210 | // ### Display an error box |
253 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 211 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
254 | recording = FALSE; | 212 | recording = FALSE; |
255 | return; | 213 | return; |
256 | } | 214 | } |
257 | 215 | ||
258 | Config vmCfg("VMemo"); | 216 | Config vmCfg("VMemo"); |
259 | vmCfg.setGroup("Defaults"); | 217 | vmCfg.setGroup("Defaults"); |
260 | 218 | ||
261 | QDateTime dt = QDateTime::currentDateTime(); | 219 | QDateTime dt = QDateTime::currentDateTime(); |
262 | QString fileName; | 220 | QString fileName; |
263 | if(systemZaurus) | 221 | if(systemZaurus) |
264 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 222 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
265 | else | 223 | else |
266 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 224 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
267 | 225 | ||
268 | fileName += "vm_"; | 226 | fileName += "vm_"; |
269 | fileName += dt.toString(); | 227 | fileName += dt.toString(); |
270 | fileName += ".wav"; | 228 | fileName += ".wav"; |
271 | 229 | ||
272 | // No spaces in the filename | 230 | // No spaces in the filename |
273 | fileName.replace(QRegExp("'"),""); | 231 | fileName.replace(QRegExp("'"),""); |
274 | fileName.replace(QRegExp(" "),"_"); | 232 | fileName.replace(QRegExp(" "),"_"); |
275 | fileName.replace(QRegExp(":"),"."); | 233 | fileName.replace(QRegExp(":"),"."); |
276 | fileName.replace(QRegExp(","),""); | 234 | fileName.replace(QRegExp(","),""); |
277 | 235 | ||
278 | if(openWAV(fileName.latin1()) == -1) | 236 | if(openWAV(fileName.latin1()) == -1) |
279 | { | 237 | { |
280 | // ### Display an error box | 238 | // ### Display an error box |
281 | qWarning("VMemo::mousePress() -> WAV error"); | 239 | qWarning("VMemo::mousePress() -> WAV error"); |
282 | close(dsp); | 240 | close(dsp); |
283 | return; | 241 | return; |
284 | } | 242 | } |
285 | 243 | ||
286 | QArray<int> cats(1); | 244 | QArray<int> cats(1); |
287 | cats[0] = vmCfg.readNumEntry("Category", 0); | 245 | cats[0] = vmCfg.readNumEntry("Category", 0); |
288 | 246 | ||
289 | QString dlName("vm_"); | 247 | QString dlName("vm_"); |
290 | dlName += dt.toString(); | 248 | dlName += dt.toString(); |
291 | DocLnk l; | 249 | DocLnk l; |
292 | l.setFile(fileName); | 250 | l.setFile(fileName); |
293 | l.setName(dlName); | 251 | l.setName(dlName); |
294 | l.setType("audio/x-wav"); | 252 | l.setType("audio/x-wav"); |
295 | l.setCategories(cats); | 253 | l.setCategories(cats); |
296 | l.writeLink(); | 254 | l.writeLink(); |
297 | 255 | ||
298 | record(); | 256 | record(); |
299 | } | 257 | } |
300 | 258 | ||
301 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 259 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
302 | { | 260 | { |
303 | qWarning("VMemo::mouseRelese() -> Done recording"); | 261 | qWarning("VMemo::mouseRelese() -> Done recording"); |
304 | recording = FALSE; | 262 | recording = FALSE; |
305 | } | 263 | } |
306 | 264 | ||
307 | int VMemo::openDSP() | 265 | int VMemo::openDSP() |
308 | { | 266 | { |
309 | Config cfg("Sound"); | 267 | Config cfg("Sound"); |
310 | cfg.setGroup("Record"); | 268 | cfg.setGroup("Record"); |
311 | 269 | ||
312 | speed = cfg.readNumEntry("SampleRate", 22050); | 270 | speed = cfg.readNumEntry("SampleRate", 22050); |
313 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 271 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
314 | if (cfg.readNumEntry("SixteenBit", 1)==1) | 272 | if (cfg.readNumEntry("SixteenBit", 1)==1) |
315 | { | 273 | { |
316 | format = AFMT_S16_LE; | 274 | format = AFMT_S16_LE; |
317 | resolution = 16; | 275 | resolution = 16; |
318 | } | 276 | } |
319 | else | 277 | else |
320 | { | 278 | { |
321 | format = AFMT_U8; | 279 | format = AFMT_U8; |
322 | resolution = 8; | 280 | resolution = 8; |
323 | } | 281 | } |
324 | 282 | ||
325 | if(systemZaurus) | 283 | if(systemZaurus) |
326 | { | 284 | { |
327 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 285 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
328 | channels=1; //zaurus has one input channel | 286 | channels=1; //zaurus has one input channel |
329 | } | 287 | } |
330 | else | 288 | else |
331 | dsp = open("/dev/dsp", O_RDWR); | 289 | dsp = open("/dev/dsp", O_RDWR); |
332 | 290 | ||
333 | if(dsp == -1) | 291 | if(dsp == -1) |
334 | { | 292 | { |
335 | perror("open(\"/dev/dsp\")"); | 293 | perror("open(\"/dev/dsp\")"); |
336 | return -1; | 294 | return -1; |
337 | } | 295 | } |
338 | 296 | ||
339 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) | 297 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
340 | { | 298 | { |
341 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 299 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
342 | return -1; | 300 | return -1; |
343 | } | 301 | } |
344 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) | 302 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
345 | { | 303 | { |
346 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 304 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
347 | return -1; | 305 | return -1; |
348 | } | 306 | } |
349 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) | 307 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
350 | { | 308 | { |
351 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 309 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
352 | return -1; | 310 | return -1; |
353 | } | 311 | } |
354 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) | 312 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
355 | { | 313 | { |
356 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 314 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
357 | return -1; | 315 | return -1; |
358 | } | 316 | } |
359 | 317 | ||
360 | return 1; | 318 | return 1; |
361 | } | 319 | } |
362 | 320 | ||
363 | int VMemo::openWAV(const char *filename) | 321 | int VMemo::openWAV(const char *filename) |
364 | { | 322 | { |
365 | qDebug("Creating %s ",filename); | 323 | qDebug("Creating %s ",filename); |
366 | track.setName(filename); | 324 | track.setName(filename); |
367 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 325 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
368 | { | 326 | { |
369 | qDebug("Could not open file"); | 327 | qDebug("Could not open file"); |
370 | return -1; | 328 | return -1; |
371 | } | 329 | } |
372 | wav=track.handle(); | 330 | wav=track.handle(); |
373 | 331 | ||
374 | WaveHeader wh; | 332 | WaveHeader wh; |
375 | 333 | ||
376 | wh.main_chunk = RIFF; | 334 | wh.main_chunk = RIFF; |
377 | wh.length=0; | 335 | wh.length=0; |
378 | wh.chunk_type = WAVE; | 336 | wh.chunk_type = WAVE; |
379 | wh.sub_chunk = FMT; | 337 | wh.sub_chunk = FMT; |
380 | wh.sc_len = 16; | 338 | wh.sc_len = 16; |
381 | wh.format = PCM_CODE; | 339 | wh.format = PCM_CODE; |
382 | wh.modus = channels; | 340 | wh.modus = channels; |
383 | wh.sample_fq = speed; | 341 | wh.sample_fq = speed; |
384 | wh.byte_p_sec = speed * channels * resolution/8; | 342 | wh.byte_p_sec = speed * channels * resolution/8; |
385 | wh.byte_p_spl = channels * (resolution / 8); | 343 | wh.byte_p_spl = channels * (resolution / 8); |
386 | wh.bit_p_spl = resolution; | 344 | wh.bit_p_spl = resolution; |
387 | wh.data_chunk = DATA; | 345 | wh.data_chunk = DATA; |
388 | wh.data_length= 0; | 346 | wh.data_length= 0; |
389 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 347 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
390 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 348 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
391 | write (wav, &wh, sizeof(WaveHeader)); | 349 | write (wav, &wh, sizeof(WaveHeader)); |
392 | 350 | ||
393 | return 1; | 351 | return 1; |
394 | } | 352 | } |
395 | 353 | ||
396 | void VMemo::record(void) | 354 | void VMemo::record(void) |
397 | { | 355 | { |
398 | int length=0, result, value; | 356 | int length=0, result, value; //, i; |
399 | char sound[8192]; | 357 | char sound[512]; //, leftBuffer[256], rightBuffer[256]; |
400 | 358 | ||
401 | qWarning("VMemo::record()"); | 359 | qWarning("VMemo::record()"); |
402 | 360 | ||
403 | while(recording) | 361 | while(recording) |
404 | { | 362 | { |
405 | result = read(dsp, sound, 512); // 8192 | 363 | result = read(dsp, sound, 512); // 8192 |
406 | qApp->processEvents(); | 364 | qApp->processEvents(); |
407 | write(wav, sound, result); | 365 | |
366 | /* attempt to write only one channel...didnt work. | ||
367 | for (i = 0; i < result; i++) { | ||
368 | leftBuffer[i] = sound[2*i]; | ||
369 | rightBuffer[i] = sound[2*i+1]; | ||
370 | } | ||
371 | */ | ||
408 | qApp->processEvents(); | 372 | qApp->processEvents(); |
373 | |||
374 | /* needed to only write one channel. comment out above "write/length" code. | ||
375 | write(wav, leftBuffer, result / 2); | ||
376 | length += result/2; | ||
377 | */ | ||
378 | |||
379 | write(wav, sound, result); | ||
409 | length += result; | 380 | length += result; |
381 | |||
410 | qApp->processEvents(); | 382 | qApp->processEvents(); |
411 | // printf("%d\r",length); | ||
412 | // fflush(stdout); | ||
413 | } | 383 | } |
414 | 384 | ||
415 | qWarning("VMemo::record() -> Done recording"); | 385 | qWarning("VMemo::record() -> Done recording"); |
416 | qWarning("VMemo::record() -> Closing dsp"); | 386 | qWarning("VMemo::record() -> Closing dsp"); |
417 | 387 | ||
418 | value = length+36; | 388 | value = length+36; |
419 | lseek(wav, 4, SEEK_SET); | 389 | lseek(wav, 4, SEEK_SET); |
420 | write(wav, &value, 4); | 390 | write(wav, &value, 4); |
421 | lseek(wav, 40, SEEK_SET); | 391 | lseek(wav, 40, SEEK_SET); |
422 | write(wav, &length, 4); | 392 | write(wav, &length, 4); |
423 | // qDebug("File length %d, samplecount %d", value, length); | ||
424 | track.close(); | 393 | track.close(); |
425 | 394 | ||
426 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 395 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
427 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 396 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
428 | ::close(dsp); | 397 | ::close(dsp); |
429 | 398 | ||
430 | qWarning("VMemo::record() -> playing done recording sound"); | 399 | qWarning("VMemo::record() -> playing done recording sound"); |
431 | QSound::play(Resource::findSound("vmemoe")); | 400 | QSound::play(Resource::findSound("vmemoe")); |
432 | qWarning("VMemo::record() -> terminating"); | 401 | qWarning("VMemo::record() -> terminating"); |
433 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | 402 | QMessageBox::information(0, "VMemo", "Recording Done", 1); |
434 | } | 403 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 824309e..d96cd94 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -1,55 +1,54 @@ | |||
1 | /**************************************************************************************94x78** | 1 | /**************************************************************************************94x78** |
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 | 16 | ||
17 | #ifndef __VMEMO_H__ | 17 | #ifndef __VMEMO_H__ |
18 | #define __VMEMO_H__ | 18 | #define __VMEMO_H__ |
19 | 19 | ||
20 | #include <qwidget.h> | 20 | #include <qwidget.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | 25 | ||
26 | class VMemo : public QWidget | 26 | class VMemo : public QWidget |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | public: | 29 | public: |
30 | VMemo( QWidget *parent, const char *name = NULL); | 30 | VMemo( QWidget *parent, const char *name = NULL); |
31 | ~VMemo(); | 31 | ~VMemo(); |
32 | QFile track; | 32 | QFile track; |
33 | 33 | ||
34 | public slots: | 34 | public slots: |
35 | void record(); | 35 | void record(); |
36 | void mousePressEvent( QMouseEvent * ); | 36 | void mousePressEvent( QMouseEvent * ); |
37 | void mouseReleaseEvent( QMouseEvent * ); | 37 | void mouseReleaseEvent( QMouseEvent * ); |
38 | void receive( const QCString &msg, const QByteArray &data ); | 38 | void receive( const QCString &msg, const QByteArray &data ); |
39 | void sayHi(); | ||
40 | 39 | ||
41 | private: | 40 | private: |
42 | void paintEvent( QPaintEvent* ); | 41 | void paintEvent( QPaintEvent* ); |
43 | 42 | ||
44 | int openDSP(); | 43 | int openDSP(); |
45 | int openWAV(const char *filename); | 44 | int openWAV(const char *filename); |
46 | 45 | ||
47 | QPixmap vmemoPixmap; | 46 | QPixmap vmemoPixmap; |
48 | QCopChannel *myChannel; | 47 | QCopChannel *myChannel; |
49 | bool systemZaurus; | 48 | bool systemZaurus; |
50 | int dsp, wav, rate, speed, channels, format, resolution; | 49 | int dsp, wav, rate, speed, channels, format, resolution; |
51 | bool recording; | 50 | bool recording; |
52 | }; | 51 | }; |
53 | 52 | ||
54 | #endif // __VMEMO_H__ | 53 | #endif // __VMEMO_H__ |
55 | 54 | ||