1 /****************************************************************** 2 * SUN/DEC AF Support by Ricky Beam (cramer@catt.ncsu.edu) 3 * 4 ******************************************************************/ 5 6 7 #ifdef SUN 8 9 #include "config.h" 10 #include <unistd.h> 11 #include <stdio.h> 12 #include <fcntl.h> 13 #include <sys/types.h> 14 #include <multimedia/audio_hdr.h> 15 #include <multimedia/audio_errno.h> 16 #include <multimedia/audio_device.h> 17 #include "main.h" 18 #include "dsp.h" 19 20 Audio_hdr hdr_save, hdr; 21 static int audio; 22 23 int get_dsp_device() { 24 uint32 j; 25 26 audio = open("/dev/audio",O_WRONLY,0); 27 if (audio < 1) { 28 printf("Could not open audio device|\n"); 29 exit(1); 30 } 31 32 /* Save the device configuration 'cause it don't reset on its own */ 33 audio_get_play_config(audio, &hdr_save); 34 audio_get_play_config(audio, &hdr); 35 36 hdr.encoding = AUDIO_ENCODING_LINEAR; 37 hdr.bytes_per_unit = 2; 38 if (audio_set_play_config(audio, &hdr) != AUDIO_SUCCESS) 39 fprintf(stderr, "unable to set sample encoding\n"); 40 41 if (stereo) 42 { /* setup stereo */ 43 hdr.channels = 2; 44 if (audio_set_play_config(audio, &hdr) != AUDIO_SUCCESS) 45 fprintf(stderr, "unable to setup stereo\n"); 46 audio_get_play_config(audio, &hdr); 47 stereo = (hdr.channels==1)?0:1; 48 } 49 50 if (bit16) 51 { /* set 16 bit? */ 52 j = 16; 53 hdr.bytes_per_unit = 2; 54 if (audio_set_play_config(audio, &hdr) != AUDIO_SUCCESS) 55 fprintf(stderr, "unable to setup 16 bit samples\n"); 56 audio_get_play_config(audio, &hdr); 57 j = (hdr.bytes_per_unit==2)?16:8; 58 if (j != 16) bit16 = 0; 59 } 60 61 /* Setup playback speed */ 62 hdr.sample_rate = mixspeed; 63 if (audio_set_play_config(audio, &hdr) != AUDIO_SUCCESS) 64 fprintf(stderr, "unable to setup sample speed\n"); 65 audio_get_play_config(audio, &hdr); 66 mixspeed = hdr.sample_rate; 67 68 /* I don't know; what's a good size? */ 69 audio_buffer_size = 32768; 70 if (!(audio_start_buffer = (uint8 *) malloc(audio_buffer_size))) 71 { 72 printf("Could not get audio buffer memory!\n"); 73 exit(1); 74 } 75 audio_end_buffer = &audio_start_buffer[audio_buffer_size]; 76 audio_curptr = audio_start_buffer; 77 return; 78 } 79 80 void write_dsp_device(void *buf, int size) { 81 write(audio,audio_start_buffer,audio_buffer_size); 82 return; 83 } 84 85 void close_dsp_device() { 86 close(audio); 87 return; 88 } 89 90 #endif /* SUN */ 91