[49] | 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> |
---|
| 7 | #include <dmedia/audio.h> |
---|
| 8 | #include <dmedia/audiofile.h> |
---|
| 9 | #include <fcntl.h> |
---|
| 10 | #include <unistd.h> |
---|
| 11 | #include <sys/types.h> |
---|
| 12 | #include <sys/time.h> |
---|
| 13 | #include <bstring.h> |
---|
| 14 | #include <sys/ioctl.h> |
---|
| 15 | #include <sys/types.h> |
---|
| 16 | #include <sys/stat.h> |
---|
| 17 | |
---|
| 18 | void output_sample(unsigned char *buf, int size); |
---|
| 19 | void sound_uninit(); |
---|
| 20 | int sound_init(); |
---|
| 21 | |
---|
| 22 | #define BUF_SIZE 512 |
---|
| 23 | |
---|
| 24 | ALconfig audioconfig; |
---|
| 25 | ALport audioport; |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | void output_samples(unsigned char *buf, int size) |
---|
| 31 | { |
---|
| 32 | ALwritesamps(audioport,buf,size); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | #include "gen_drv.c" |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | void sound_uninit() |
---|
| 40 | { |
---|
| 41 | ALfreeconfig(audioconfig); |
---|
| 42 | ALcloseport(audioport); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int sound_init() |
---|
| 46 | { |
---|
| 47 | long pvbuf[2]; |
---|
| 48 | pvbuf[0] = AL_OUTPUT_COUNT; |
---|
| 49 | pvbuf[2] = AL_MONITOR_CTL; |
---|
| 50 | if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 4) < 0) |
---|
| 51 | { |
---|
| 52 | fprintf(stderr,"sound driver : No audio hardware\n"); |
---|
| 53 | return 0; |
---|
| 54 | } |
---|
| 55 | pvbuf[0] = AL_OUTPUT_RATE; |
---|
| 56 | pvbuf[1] = 11025; |
---|
| 57 | if (ALsetparams(AL_DEFAULT_DEVICE,pvbuf,4) < 0) |
---|
| 58 | { |
---|
| 59 | fprintf(stderr,"sound driver : Could not set sample rate\n"); |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | ALseterrorhandler(0); |
---|
| 64 | audioconfig = ALnewconfig(); |
---|
| 65 | if (!audioconfig) |
---|
| 66 | { |
---|
| 67 | fprintf(stderr,"failed to create audio config\n"); |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
| 70 | else if (ALsetchannels(audioconfig,AL_MONO)) |
---|
| 71 | { fprintf(stderr,"sound driver : could not set audio channels\n"); |
---|
| 72 | return 0; |
---|
| 73 | } |
---|
| 74 | else if (ALsetqueuesize(audioconfig,BUF_SIZE)) |
---|
| 75 | { |
---|
| 76 | fprintf(stderr,"sound driver : could not set audio que size\n"); |
---|
| 77 | ALfreeconfig(audioconfig); |
---|
| 78 | return 0; |
---|
| 79 | } else if (ALsetwidth (audioconfig, AL_SAMPLE_8)) |
---|
| 80 | { |
---|
| 81 | fprintf(stderr,"sound driver :could not set 8 bit samples\n"); |
---|
| 82 | ALfreeconfig(audioconfig); |
---|
| 83 | return 0; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | audioport=ALopenport("Abuse sound driver","w",audioconfig); |
---|
| 87 | if (!audioport) |
---|
| 88 | { |
---|
| 89 | fprintf(stderr,"sound driver : could not open audio port\n"); |
---|
| 90 | ALfreeconfig(audioconfig); |
---|
| 91 | return 0; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | int i=0,j; |
---|
| 95 | uchar *vd=volume_table; |
---|
| 96 | for (;i<32;i++) |
---|
| 97 | { |
---|
| 98 | for (j=0;j<256;j++,vd++) |
---|
| 99 | *vd=(j-128)*i/31+128; |
---|
| 100 | } |
---|
| 101 | return 1; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|