summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-15 02:40:16 (UTC)
committer llornkcor <llornkcor>2002-02-15 02:40:16 (UTC)
commitb429144b79049fcc25dfff5a9a38415451399e58 (patch) (unidiff)
treee6a6bf929667e3c5a521145809b2615bb4b0c6e9
parente5ac946b3ced52f4aba73dfc64398bb3d8245734 (diff)
downloadopie-b429144b79049fcc25dfff5a9a38415451399e58.zip
opie-b429144b79049fcc25dfff5a9a38415451399e58.tar.gz
opie-b429144b79049fcc25dfff5a9a38415451399e58.tar.bz2
forgot length in header
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 25ee476..bba55a3 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,366 +1,367 @@
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
29typedef struct _waveheader { 29typedef struct _waveheader {
30 u_long main_chunk; /* 'RIFF' */ 30 u_long main_chunk; /* 'RIFF' */
31 u_long length; /* filelen */ 31 u_long length; /* filelen */
32 u_long chunk_type; /* 'WAVE' */ 32 u_long chunk_type; /* 'WAVE' */
33 u_long sub_chunk; /* 'fmt ' */ 33 u_long sub_chunk; /* 'fmt ' */
34 u_long sc_len; /* length of sub_chunk, =16 34 u_long sc_len; /* length of sub_chunk, =16
35 (chunckSize) format len */ 35 (chunckSize) format len */
36 u_short format; /* should be 1 for PCM-code (formatTag) */ 36 u_short format; /* should be 1 for PCM-code (formatTag) */
37 37
38 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 38 u_short modus; /* 1 Mono, 2 Stereo (channels) */
39 u_long sample_fq; /* samples per second (samplesPerSecond) */ 39 u_long sample_fq; /* samples per second (samplesPerSecond) */
40 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 40 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
41 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 41 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
42 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 42 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
43 43
44 u_long data_chunk; /* 'data' */ 44 u_long data_chunk; /* 'data' */
45 45
46 u_long data_length;/* samplecount */ 46 u_long data_length;/* samplecount */
47} WaveHeader; 47} WaveHeader;
48 48
49#define RIFF 0x46464952 49#define RIFF 0x46464952
50#define WAVE 0x45564157 50#define WAVE 0x45564157
51#define FMT 0x20746D66 51#define FMT 0x20746D66
52#define DATA 0x61746164 52#define DATA 0x61746164
53#define PCM_CODE 1 53#define PCM_CODE 1
54#define WAVE_MONO 1 54#define WAVE_MONO 1
55#define WAVE_STEREO 2 55#define WAVE_STEREO 2
56 56
57#include "vmemo.h" 57#include "vmemo.h"
58 58
59#include <qpe/qpeapplication.h> 59#include <qpe/qpeapplication.h>
60#include <qpe/resource.h> 60#include <qpe/resource.h>
61#include <qpe/config.h> 61#include <qpe/config.h>
62 62
63#include <qpainter.h> 63#include <qpainter.h>
64#include <qdatetime.h> 64#include <qdatetime.h>
65#include <qsound.h> 65#include <qsound.h>
66#include <qfile.h> 66#include <qfile.h>
67#include <qmessagebox.h> 67#include <qmessagebox.h>
68 68
69int seq = 0; 69int seq = 0;
70 70
71/* XPM */ 71/* XPM */
72static char * vmemo_xpm[] = { 72static char * vmemo_xpm[] = {
73"14 14 47 1", 73"14 14 47 1",
74" c None", 74" c None",
75". c #101010", 75". c #101010",
76"+ c #0D0D0D", 76"+ c #0D0D0D",
77"@ c #0B0B0B", 77"@ c #0B0B0B",
78"# c #393939", 78"# c #393939",
79"$ c #6C6C6C", 79"$ c #6C6C6C",
80"% c #5D5D5D", 80"% c #5D5D5D",
81"& c #4E4E4E", 81"& c #4E4E4E",
82"* c #1C1C1C", 82"* c #1C1C1C",
83"= c #131313", 83"= c #131313",
84"- c #7B7B7B", 84"- c #7B7B7B",
85"; c #303030", 85"; c #303030",
86"> c #383838", 86"> c #383838",
87", c #3F3F3F", 87", c #3F3F3F",
88"' c #343434", 88"' c #343434",
89") c #060606", 89") c #060606",
90"! c #444444", 90"! c #444444",
91"~ c #646464", 91"~ c #646464",
92"{ c #505050", 92"{ c #505050",
93"] c #717171", 93"] c #717171",
94"^ c #1B1B1B", 94"^ c #1B1B1B",
95"/ c #585858", 95"/ c #585858",
96"( c #4C4C4C", 96"( c #4C4C4C",
97"_ c #353535", 97"_ c #353535",
98": c #0E0E0E", 98": c #0E0E0E",
99"< c #080808", 99"< c #080808",
100"[ c #262626", 100"[ c #262626",
101"} c #121212", 101"} c #121212",
102"| c #7F7F7F", 102"| c #7F7F7F",
103"1 c #464646", 103"1 c #464646",
104"2 c #0C0C0C", 104"2 c #0C0C0C",
105"3 c #727272", 105"3 c #727272",
106"4 c #292929", 106"4 c #292929",
107"5 c #656565", 107"5 c #656565",
108"6 c #565656", 108"6 c #565656",
109"7 c #434343", 109"7 c #434343",
110"8 c #272727", 110"8 c #272727",
111"9 c #0F0F0F", 111"9 c #0F0F0F",
112"0 c #3A3A3A", 112"0 c #3A3A3A",
113"a c #090909", 113"a c #090909",
114"b c #535353", 114"b c #535353",
115"c c #545454", 115"c c #545454",
116"d c #494949", 116"d c #494949",
117"e c #7A7A7A", 117"e c #7A7A7A",
118"f c #202020", 118"f c #202020",
119"g c #3D3D3D", 119"g c #3D3D3D",
120"h c #1F1F1F", 120"h c #1F1F1F",
121" .+@ ", 121" .+@ ",
122" #$%&* ", 122" #$%&* ",
123" =-;>,')", 123" =-;>,')",
124" .$;!~,)", 124" .$;!~,)",
125" ;#{]!)", 125" ;#{]!)",
126" ^~/(_)", 126" ^~/(_)",
127" ./:@<[)", 127" ./:@<[)",
128" }. .|]1;;2 ", 128" }. .|]1;;2 ",
129" #-$;^/3&;;4@ ", 129" #-$;^/3&;;4@ ",
130".$;;#5:67;89 ", 130".$;;#5:67;89 ",
131":%;0%&ab;8. ", 131":%;0%&ab;8. ",
132"@cd%e!fg49 ", 132"@cd%e!fg49 ",
133" h0,!_;2@ ", 133" h0,!_;2@ ",
134" ))))) "}; 134" ))))) "};
135 135
136VMemo::VMemo( QWidget *parent, const char *name ) 136VMemo::VMemo( QWidget *parent, const char *name )
137 : QWidget( parent, name ) 137 : QWidget( parent, name )
138{ 138{
139 setFixedHeight( 18 ); 139 setFixedHeight( 18 );
140 setFixedWidth( 14 ); 140 setFixedWidth( 14 );
141 141
142 recording = FALSE; 142 recording = FALSE;
143 143
144 struct utsname name; /* check for embedix kernel running on the zaurus, if 144 struct utsname name; /* check for embedix kernel running on the zaurus, if
145 lineo change string, this break 145 lineo change string, this break
146 */ 146 */
147 if (uname(&name) != -1) 147 if (uname(&name) != -1)
148 { 148 {
149 QString release=name.release; 149 QString release=name.release;
150 qWarning("System release: %s\n", name.release); 150 qWarning("System release: %s\n", name.release);
151 if(release.find("embedix",0,TRUE) !=-1) 151 if(release.find("embedix",0,TRUE) !=-1)
152 systemZaurus=TRUE; 152 systemZaurus=TRUE;
153 else 153 else
154 systemZaurus=FALSE; 154 systemZaurus=FALSE;
155 } 155 }
156 156
157} 157}
158 158
159VMemo::~VMemo() 159VMemo::~VMemo()
160{ 160{
161} 161}
162 162
163void VMemo::paintEvent( QPaintEvent* ) 163void VMemo::paintEvent( QPaintEvent* )
164{ 164{
165 QPainter p(this); 165 QPainter p(this);
166 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 166 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
167} 167}
168 168
169void VMemo::mousePressEvent( QMouseEvent * ) 169void VMemo::mousePressEvent( QMouseEvent * )
170{ 170{
171 // just to be safe 171 // just to be safe
172 if (recording) 172 if (recording)
173 { 173 {
174 recording = FALSE; 174 recording = FALSE;
175 return; 175 return;
176 } 176 }
177 177
178 qWarning("VMemo::mousePress()"); 178 qWarning("VMemo::mousePress()");
179 QSound::play(Resource::findSound("vmemob")); 179 QSound::play(Resource::findSound("vmemob"));
180 180
181 recording = TRUE; 181 recording = TRUE;
182 qWarning("VMemo::mousePress() -> Starting to record"); 182 qWarning("VMemo::mousePress() -> Starting to record");
183 if (openDSP() == -1) 183 if (openDSP() == -1)
184 { 184 {
185 // ### Display an error box 185 // ### Display an error box
186 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); 186 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort");
187 recording = FALSE; 187 recording = FALSE;
188 return; 188 return;
189 } 189 }
190 190
191 Config vmCfg("VMemo"); 191 Config vmCfg("VMemo");
192 vmCfg.setGroup("Defaults"); 192 vmCfg.setGroup("Defaults");
193 193
194 QDateTime dt = QDateTime::currentDateTime(); 194 QDateTime dt = QDateTime::currentDateTime();
195 QString fileName; 195 QString fileName;
196 if(systemZaurus) 196 if(systemZaurus)
197 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs 197 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
198 else 198 else
199 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); 199 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
200 200
201 fileName += "vm_"; 201 fileName += "vm_";
202 fileName += dt.toString(); 202 fileName += dt.toString();
203 fileName += ".wav"; 203 fileName += ".wav";
204 204
205 // No spaces in the filename 205 // No spaces in the filename
206 fileName.replace(QRegExp("'"),""); 206 fileName.replace(QRegExp("'"),"");
207 fileName.replace(QRegExp(" "),"_"); 207 fileName.replace(QRegExp(" "),"_");
208 fileName.replace(QRegExp(":"),"."); 208 fileName.replace(QRegExp(":"),".");
209 fileName.replace(QRegExp(","),""); 209 fileName.replace(QRegExp(","),"");
210 210
211 if(openWAV(fileName.latin1()) == -1) 211 if(openWAV(fileName.latin1()) == -1)
212 { 212 {
213 // ### Display an error box 213 // ### Display an error box
214 qWarning("VMemo::mousePress() -> WAV error"); 214 qWarning("VMemo::mousePress() -> WAV error");
215 close(dsp); 215 close(dsp);
216 return; 216 return;
217 } 217 }
218 218
219 QArray<int> cats(1); 219 QArray<int> cats(1);
220 cats[0] = vmCfg.readNumEntry("Category", 0); 220 cats[0] = vmCfg.readNumEntry("Category", 0);
221 221
222 QString dlName("vm_"); 222 QString dlName("vm_");
223 dlName += dt.toString(); 223 dlName += dt.toString();
224 DocLnk l; 224 DocLnk l;
225 l.setFile(fileName); 225 l.setFile(fileName);
226 l.setName(dlName); 226 l.setName(dlName);
227 l.setType("audio/x-wav"); 227 l.setType("audio/x-wav");
228 l.setCategories(cats); 228 l.setCategories(cats);
229 l.writeLink(); 229 l.writeLink();
230 230
231 record(); 231 record();
232} 232}
233 233
234void VMemo::mouseReleaseEvent( QMouseEvent * ) 234void VMemo::mouseReleaseEvent( QMouseEvent * )
235{ 235{
236 qWarning("VMemo::mouseRelese() -> Done recording"); 236 qWarning("VMemo::mouseRelese() -> Done recording");
237 recording = FALSE; 237 recording = FALSE;
238} 238}
239 239
240int VMemo::openDSP() 240int VMemo::openDSP()
241{ 241{
242 Config cfg("Sound"); 242 Config cfg("Sound");
243 cfg.setGroup("Record"); 243 cfg.setGroup("Record");
244 244
245 speed = cfg.readNumEntry("SampleRate", 22050); 245 speed = cfg.readNumEntry("SampleRate", 22050);
246 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 246 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
247 if (cfg.readNumEntry("SixteenBit", 1)==1) 247 if (cfg.readNumEntry("SixteenBit", 1)==1)
248 { 248 {
249 format = AFMT_S16_LE; 249 format = AFMT_S16_LE;
250 resolution = 16; 250 resolution = 16;
251 } 251 }
252 else 252 else
253 { 253 {
254 format = AFMT_U8; 254 format = AFMT_U8;
255 resolution = 8; 255 resolution = 8;
256 } 256 }
257 257
258 if(systemZaurus) 258 if(systemZaurus)
259 { 259 {
260 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 260 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
261 channels=1; //zaurus has one input channel 261 channels=1; //zaurus has one input channel
262 } 262 }
263 else 263 else
264 dsp = open("/dev/dsp", O_RDWR); 264 dsp = open("/dev/dsp", O_RDWR);
265 265
266 if(dsp == -1) 266 if(dsp == -1)
267 { 267 {
268 perror("open(\"/dev/dsp\")"); 268 perror("open(\"/dev/dsp\")");
269 return -1; 269 return -1;
270 } 270 }
271 271
272 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) 272 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1)
273 { 273 {
274 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 274 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
275 return -1; 275 return -1;
276 } 276 }
277 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) 277 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1)
278 { 278 {
279 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 279 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
280 return -1; 280 return -1;
281 } 281 }
282 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) 282 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1)
283 { 283 {
284 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 284 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
285 return -1; 285 return -1;
286 } 286 }
287 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) 287 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1)
288 { 288 {
289 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 289 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
290 return -1; 290 return -1;
291 } 291 }
292 292
293 return 1; 293 return 1;
294} 294}
295 295
296int VMemo::openWAV(const char *filename) 296int VMemo::openWAV(const char *filename)
297{ 297{
298 qDebug("Creating %s ",filename); 298 qDebug("Creating %s ",filename);
299 track.setName(filename); 299 track.setName(filename);
300 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) 300 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw))
301 { 301 {
302 qDebug("Could not open file"); 302 qDebug("Could not open file");
303 return -1; 303 return -1;
304 } 304 }
305 wav=track.handle(); 305 wav=track.handle();
306 306
307 WaveHeader wh; 307 WaveHeader wh;
308 308
309 wh.main_chunk = RIFF;// RIFF 309 wh.main_chunk = RIFF;// RIFF
310 wh.length=0; /* filelen */
310 wh.chunk_type = WAVE;//WAVE 311 wh.chunk_type = WAVE;//WAVE
311 wh.sub_chunk = FMT;// fmt 312 wh.sub_chunk = FMT;// fmt
312 wh.sc_len = 16;// format length = 16 313 wh.sc_len = 16;// format length = 16
313 wh.format = PCM_CODE;// PCM 314 wh.format = PCM_CODE;// PCM
314 wh.modus = channels;// channels 315 wh.modus = channels;// channels
315 wh.sample_fq = speed;//samplerate 316 wh.sample_fq = speed;//samplerate
316 wh.byte_p_sec = speed * channels * resolution/8;// av bytes per second 317 wh.byte_p_sec = speed * channels * resolution/8;// av bytes per second
317 wh.byte_p_spl = channels * (resolution / 8); //block align 318 wh.byte_p_spl = channels * (resolution / 8); //block align
318 wh.bit_p_spl = resolution;//bits per sample 8, or 16 319 wh.bit_p_spl = resolution;//bits per sample 8, or 16
319 wh.data_chunk = DATA; 320 wh.data_chunk = DATA;
320 wh.data_length= 0; // <--- 321 wh.data_length= 0; // <---
321// qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 322// qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
322// , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 323// , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
323 write (wav, &wh, sizeof(WaveHeader)); 324 write (wav, &wh, sizeof(WaveHeader));
324 325
325 return 1; 326 return 1;
326} 327}
327 328
328void VMemo::record(void) 329void VMemo::record(void)
329{ 330{
330 int length=0, result, value; 331 int length=0, result, value;
331 char sound[8192]; 332 char sound[8192];
332 333
333 qWarning("VMemo::record()"); 334 qWarning("VMemo::record()");
334 335
335 while(recording) 336 while(recording)
336 { 337 {
337 result = read(dsp, sound, 512); // 8192 338 result = read(dsp, sound, 512); // 8192
338 qApp->processEvents(); 339 qApp->processEvents();
339 write(wav, sound, result); 340 write(wav, sound, result);
340 qApp->processEvents(); 341 qApp->processEvents();
341 length += result; 342 length += result;
342 qApp->processEvents(); 343 qApp->processEvents();
343// printf("%d\r",length); 344// printf("%d\r",length);
344// fflush(stdout); 345// fflush(stdout);
345 } 346 }
346 347
347 qWarning("VMemo::record() -> Done recording"); 348 qWarning("VMemo::record() -> Done recording");
348 qWarning("VMemo::record() -> Closing dsp"); 349 qWarning("VMemo::record() -> Closing dsp");
349 350
350 value = length+36; 351 value = length+36;
351 lseek(wav, 4, SEEK_SET); 352 lseek(wav, 4, SEEK_SET);
352 write(wav, &value, 4); 353 write(wav, &value, 4);
353 lseek(wav, 40, SEEK_SET); 354 lseek(wav, 40, SEEK_SET);
354 write(wav, &length, 4); 355 write(wav, &length, 4);
355// qDebug("File length %d, samplecount %d", value, length); 356// qDebug("File length %d, samplecount %d", value, length);
356 track.close(); 357 track.close();
357 358
358 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while 359 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while
359 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 360 perror("ioctl(\"SNDCTL_DSP_RESET\")");
360 ::close(dsp); 361 ::close(dsp);
361 362
362 qWarning("VMemo::record() -> playing done recording sound"); 363 qWarning("VMemo::record() -> playing done recording sound");
363 QSound::play(Resource::findSound("vmemoe")); 364 QSound::play(Resource::findSound("vmemoe"));
364 qWarning("VMemo::record() -> terminating"); 365 qWarning("VMemo::record() -> terminating");
365 QMessageBox::information(0, "VMemo", "Recording Done", 1); 366 QMessageBox::information(0, "VMemo", "Recording Done", 1);
366} 367}