source: abuse/tags/pd/imlib/port/linux/lnx_sdrv.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1/*     Sound driver, (C) 1994 Jonathan Clark    */
2#include <sys/ipc.h>
3#include <sys/shm.h>
4#include <signal.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <fcntl.h>
8#include <unistd.h>
9#include <linux/soundcard.h>
10#include <sys/ioctl.h>
11#include <sys/stat.h>
12#include <sys/types.h>
13#include <sys/time.h>
14#include <string.h>
15#include <signal.h>
16
17#define uchar unsigned char
18
19#define BUF_BITS 9
20#define BUF_SIZE (1<<BUF_BITS)
21#define NUM_CHANNELS 8
22#define SAMPLE_SPEED 11025
23
24
25int s_dev,full_pot=0,start_seq;
26
27int sound_init();
28void output_samples(uchar *buffer, int size);
29void sound_uninit();
30
31#include "../sgi/gen_drv.c"         // include generic sound driver code, hackish I know, but I'm outa time :)
32
33
34int sound_init()
35
36  int i; 
37  s_dev=open("/dev/dsp",O_WRONLY,0);
38  if (s_dev<0)
39  {
40    fprintf(stderr,"SNDDRV : Unable to open /dev/dsp, sound effects disabled\n"
41                   "   **Make sure no other process is using this (perhaps old lnx_sdrv?) **\n");   
42    return 0; 
43  }
44 
45
46  i = 0x00020000|BUF_BITS;      /* 2 fragments of 2^BUF_BITS bytes */
47  ioctl(s_dev, SNDCTL_DSP_SETFRAGMENT, &i);
48
49  i = 8;     // samples are 8 bit
50  if (ioctl(s_dev, SNDCTL_DSP_SAMPLESIZE, &i)<0)
51  {
52    fprintf(stderr,"SNDDRV : Sample size 8 failed, sound effects disabled\n");   
53    close(s_dev);
54    s_dev=-1;   
55    return 0;   
56  }
57
58  i = SAMPLE_SPEED;
59  if (ioctl(s_dev, SNDCTL_DSP_SPEED, &i)<0)
60  {
61    fprintf(stderr,"SNDDRV : dsp_speed failed, sound effects disabled\n");   
62    close(s_dev);
63    s_dev=-1;   
64    return 0;   
65  }
66
67  i = 0;     // no stero
68  if (ioctl(s_dev, SNDCTL_DSP_STEREO, &i)<0)
69  {
70    fprintf(stderr,"SNDDRV : Sample size 8 failed, sound effects disabled\n");   
71    close(s_dev);
72    s_dev=-1;   
73    return 0;   
74  }
75
76
77
78  int j;
79  uchar *vd=volume_table;
80  for (;i<32;i++)
81  {
82    for (j=0;j<256;j++,vd++)
83      *vd=(j-128)*i/31+128;
84  }
85  return 1;
86
87}
88
89
90void output_samples(uchar *buffer, int size)
91{
92  write(s_dev, buf, size);
93}
94
95
96void sound_uninit()
97{
98  close(s_dev);
99}
Note: See TracBrowser for help on using the repository browser.