source: abuse/tags/pd/imlib/port/sgi/sgi_sdrv.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1#include <sys/ipc.h>
2#include <sys/shm.h>
3#include <signal.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7extern "C" {
8#include <dmedia/audio.h>
9#include <dmedia/audiofile.h>
10}
11#include <fcntl.h>
12#include <unistd.h>
13#include <sys/types.h>
14#include <sys/time.h>
15#include <bstring.h>
16#include <sys/ioctl.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19
20void output_sample(unsigned char *buf, int size);
21void sound_uninit();
22int sound_init();
23
24#define BUF_SIZE 512
25
26ALconfig audioconfig;
27ALport audioport;
28
29
30
31
32void output_samples(unsigned char *buf, int size)
33{
34  ALwritesamps(audioport,buf,size);
35}
36
37#include "gen_drv.c"
38
39
40
41void sound_uninit()
42{
43  ALfreeconfig(audioconfig);
44  ALcloseport(audioport);
45}
46
47int sound_init()
48{
49  long pvbuf[4];
50  pvbuf[0] = AL_OUTPUT_COUNT;
51  pvbuf[2] = AL_MONITOR_CTL;
52  if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 4) < 0)
53  {   
54    fprintf(stderr,"sound driver : No audio hardware\n");
55    return 0;
56  }
57  pvbuf[0] = AL_OUTPUT_RATE;
58  pvbuf[1] = 11025;
59  if (ALsetparams(AL_DEFAULT_DEVICE,pvbuf,4) < 0)
60  {   
61    fprintf(stderr,"sound driver : Could not set sample rate\n");
62    return 0;
63  }
64
65  ALseterrorhandler(0);
66  audioconfig = ALnewconfig();
67  if (!audioconfig)
68  {
69    fprintf(stderr,"failed to create audio config\n");
70    return 0;
71  }
72  else if (ALsetchannels(audioconfig,AL_MONO))
73  { fprintf(stderr,"sound driver : could not set audio channels\n");
74    return 0;
75  }
76  else if (ALsetqueuesize(audioconfig,BUF_SIZE))
77  {
78    fprintf(stderr,"sound driver : could not set audio que size\n");
79    ALfreeconfig(audioconfig);
80    return 0;
81  } else if (ALsetwidth (audioconfig, AL_SAMPLE_8))
82  {
83    fprintf(stderr,"sound driver :could not set 8 bit samples\n");
84    ALfreeconfig(audioconfig);
85    return 0;
86  }
87
88  audioport=ALopenport("Abuse sound driver","w",audioconfig);
89  if (!audioport)
90  {
91    fprintf(stderr,"sound driver : could not open audio port\n");
92    ALfreeconfig(audioconfig);
93    return 0;
94  }
95
96  int i=0,j;
97  uchar *vd=volume_table;
98  for (;i<32;i++)
99  {
100    for (j=0;j<256;j++,vd++)
101      *vd=(j-128)*i/31+128;
102  }
103  return 1;
104}
105
106
Note: See TracBrowser for help on using the repository browser.