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
@@ -118,249 +118,250 @@ static char * vmemo_xpm[] = {
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}