annotate pwplib/snd-oss.c @ 35:b9d679965320

Code cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 24 May 2010 01:22:33 +0300
parents c60e531d19cd
children 85671798fdb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "config.h"
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #ifdef DRIVE_OSS
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <stdio.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include <stdlib.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <unistd.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <fcntl.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <linux/soundcard.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include "pwplib.h"
35
b9d679965320 Code cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
13 #include "gb.h"
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #define TIMERHZ 72
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 struct{
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 int fd;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 char buf[4096];
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 int buflgt;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 int freq;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 }pwp_oss;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 void oss_loopflush()
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 for(;;)
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 {audio_buf_info bi;ioctl(pwp_oss.fd,SNDCTL_DSP_GETOSPACE,&bi);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 if(bi.fragments==1)break;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 pwplib.player();
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 gb_genwave(pwp_oss.buf,pwp_oss.buflgt);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 write(pwp_oss.fd,pwp_oss.buf,pwp_oss.buflgt);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 if(bi.fragments<3)break;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 void oss_restore()
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 close(pwp_oss.fd);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 int oss_init()
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 pwp_oss.fd=open("/dev/dsp",O_WRONLY);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 if(pwp_oss.fd<0)return 0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 pwpwrite("* OSS sound\n");
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 pwp_oss.freq=8000;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 pwp_oss.buflgt=pwp_oss.freq/TIMERHZ;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 pwplib.sound=gb_sound;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 pwplib.loopflush=oss_loopflush;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 gb_init(pwp_oss.freq);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
17
c60e531d19cd Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 pwplib_regdestr(oss_restore);
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 return 1;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 #endif