From bfc73fa021f349b38a25c6e65f76b2f9e14f9654 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 24 Jan 2005 18:03:50 +0000 Subject: [PATCH] Dwlere the old proprietary-Linux support. Here's why: 1. Joe Dellinger tells me the Sun code stopped working on newer Sun hardware some time back. Let 'em use X11. 2. HP7000s and Indigos were end-of-lifed in the 1990s. 3. The AdLib code had to write to ports and run suid. This makes it a security risk. Screw it. It's 2005, 99% of the machines this will ever run on are Linux laptops and the other 1% have X. --- Makefile | 37 +------- beepAdLib.c | 168 ---------------------------------- beepHP.c | 177 ------------------------------------ beepIndigo.c | 248 --------------------------------------------------- beepSun.c | 200 ----------------------------------------- 5 files changed, 2 insertions(+), 828 deletions(-) delete mode 100644 beepAdLib.c delete mode 100644 beepHP.c delete mode 100644 beepIndigo.c delete mode 100644 beepSun.c diff --git a/Makefile b/Makefile index d5a3a00..288e3a3 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,7 @@ # Select your audio output device. Current choices are: # -# Sun: Sun workstation with audio hardware. -# HP: HP9000s700 with audio hardware. # X11: The X11 window system. -# Indigo: SGI Indigo workstation. # Linux: IBM PC Console running Linux. -# AdLib: AdLib/SoundBlaster FM chip. # OSS: Open Sound System /dev/dsp device. # # Two notes about OSS: @@ -19,29 +15,19 @@ # beep.h interface. See beep*.c for examples. Please send any additions # to the authors! # -#DEVICE = Sun -#DEVICE = HP #DEVICE = X11 -#DEVICE = Indigo #DEVICE = Linux -#DEVICE = AdLib DEVICE = OSS # # For alternate random number generator, add either -DUSELRAND for lrand48(), # or -DUSERAND for (ugh) rand(). Default is -DUSERANDOM for random(). -# -# On a Sun workstation you may want to compile with -DFULLVOLUME (see beepSun.c -# for more details). -# #DEFINES = -DUSELRAND -#DEFINES = -DFULLVOLUME #DEFINES = VERS=$(shell sed -#include -#include -#include -#include - -#include "alarm.h" -#include "beep.h" - -/* Define it if you want to reset the AdLib/SoundBlaster FM chip. */ -#undef RESET_ADLIB - -/* The port addresses for the FM chip is always the same. */ -#define reg_port 0x0388 -#define data_port reg_port+1 - -void wr_register(int index, int data) /* See the PC Game Programmers Encyclopedia */ -{ - int i,temp; - outb(index,reg_port); - for (i=1;i<7;i++) - temp = inb(reg_port); - outb(data,data_port); - for (i=1;i<36;i++) - temp = inb(reg_port); -} - -int AdLib_found(void) /* See the PC Game Programmers Encyclopedia */ -{ - long temp1,temp2; - wr_register(4,0x60); - wr_register(4,0x80); - temp1 = inb(reg_port); - wr_register(2,0xFF); - wr_register(4,0x21); - sleep(1); - temp2 = inb(reg_port); - wr_register(4,0x60); - wr_register(4,0x80); - if (((temp1 & 0xE0) == 0) && ((temp2 & 0xE0) == 0xC0)) - { - return 0; /* card found and no errors */ - } else { - return 1; /* card not found or errors */ - } -} - -#ifdef RESET_ADLIB -void Reset_AdLib(void) /* Set all registers to 0 */ -{ - int i; - for (i=1;i<245;i++) - wr_register(i,0); -} -#endif - -int BeepInit(void) -{ - if (geteuid()) - { - fprintf(stderr,"This program must run as root (setuid root).\n"); - return 1; - } - ioperm(reg_port,17,1); - ioperm(data_port,17,1); - if (AdLib_found()) - { - fprintf(stderr,"The AdLib/SoundBlaster card not found.\n"); - ioperm(reg_port,17,0); - ioperm(data_port,17,0); - return 2; - } -#ifdef RESET_ADLIB - Reset_AdLib(); -#else - wr_register(0xB0,0x00); /* Turn off sound, was 0x11 */ -#endif - return 0; -} - -int Beep(int time, int volume, int pitch) -{ - int blk = -1; - int f_num; - int A0_reg,B0_reg,B0_reg10,B0_reg432; - - BeepWait(); - AlarmSet(time); - - if (volume > 0 && pitch > 0) - { - wr_register(0x20,1); /* Play sound at fundamental freq. */ - wr_register(0x23,1); /* Carrier at specified freq. */ - wr_register(0x43,(64*(100-volume)/100)); /* Volume 0-64 */ - - wr_register(0x63,0xF0); /* Carrier attack = fast, decay = slow */ - wr_register(0x83,0xFF); /* Carrier sustain = soft, release = fast */ - - /* Would you belive it took three days to work out how to do this ? */ - do - { - blk++; - f_num = (int)(((float)pitch / 50000.0) / (1/(pow(2,abs(blk-20))))); - } while (f_num > 1023); - A0_reg = f_num & 0x00FF; - B0_reg10 = (f_num & 0x0300) >> 8; - B0_reg432 = (blk << 2) & 0x00FF; /* Do I really need to & 0x00ff ?? */ - B0_reg = (32 | B0_reg432 | B0_reg10) & 0x00FF; - - wr_register(0xA0,A0_reg); - wr_register(0xB0,B0_reg); - -#ifdef DEBUG_FREQ - printf("blk = %d f_num = %d\n",blk,f_num); - printf("B0_reg432 = %2x\n",B0_reg432); /* bits 4 3 2 */ - printf("B0_reg10 = %2x\n",B0_reg10); /* bits 1 0 */ - printf("B0_reg = %2x A0_reg = %2x\n\n\n",B0_reg,A0_reg); -#endif - } - - return 0; -} - -int BeepWait(void) -{ - AlarmWait(); - wr_register(0xB0,0x00); /* Turn off sound, was 0x11 */ - return 0; -} - -int BeepCleanup(void) -{ -#ifdef RESET_ADLIB - Reset_AdLib(); -#else - wr_register(0xB0,0x00); /* Turn off sound, was 0x11 */ -#endif - ioperm(reg_port,17,0); - ioperm(data_port,17,0); - return 0; -} - -int BeepResume(void) -{ - ioperm(reg_port,17,1); - ioperm(data_port,17,1); -#ifdef RESET_ADLIB - Reset_AdLib(); -#else - wr_register(0xB0,0x00); /* Turn off sound, was 0x11 */ -#endif - return 0; -} diff --git a/beepHP.c b/beepHP.c deleted file mode 100644 index 4e9607c..0000000 --- a/beepHP.c +++ /dev/null @@ -1,177 +0,0 @@ -/* beepHP.c -- seligman 5/92 */ - -/* --- Implementation of beep.h for HP9000s700 with audio hardware. --- --- If the environment variable SPEAKER begins with "E", the external --- audio connection is used. If it begins with "I", the internal speaker --- is used. Otherwise both are used. --- --- Compile with the math library "-lm". -*/ - -#include "beep.h" -#include "alarm.h" -#include -#include -#include -#include -#include -#include -#include - - -static char *AudioDev; - -static int DoBeep(); - - -int BeepInit() -{ - char *speaker = getenv("SPEAKER"); - int fd; - - AudioDev = speaker && toupper(speaker[0])=='E' ? "/dev/audioEL" - : speaker && toupper(speaker[0])=='I' ? "/dev/audioIL" - : "/dev/audioBL"; - - /* - -- A quick check to ensure that we can open the device. - */ - if ((fd = open(AudioDev, O_WRONLY)) < 0) { - perror("?? Error opening audio device"); - return 1; - } - close(fd); - return 0; -} - - -/* --- Optimized for the case where volume & pitch don't change (except possibly --- to zero and back) between successive calls. -*/ -int Beep(time, volume, pitch) - int time, volume, pitch; -{ - int rc; - - AlarmWait(); - if (volume != 0 && pitch != 0) - if ((rc = DoBeep(time, volume, pitch)) != 0) - return rc; - AlarmSet(time); - return 0; -} - - -int BeepWait() -{ - AlarmWait(); - return 0; -} - - -int BeepCleanup() -{ - return 0; -} - - -int BeepResume() -{ - return 0; -} - - -/*----------------------------------------*/ - -#define SamplingRate 8000 /* audio device samples per second */ -#define NumRamp (SamplingRate / 200) /* # samples in 5ms ramp up/down */ - -typedef short int Sample; -#define MaxSample (Sample)0x7FFF - - -/* --- Sound a beep. --- Optimized for the case where volume & pitch don't change between successive --- calls. -*/ -static int DoBeep(time, volume, pitch) - int time, volume, pitch; -{ - static int audioDevFD = -1; /* -1 indicates not yet open. */ - - /* Save sample buffer from call to call, and reuse it when possible. */ - static Sample *buf = NULL; - static int bufLen = 0; - static int bufVolume = 0; - static int bufPitch = 0; - - Sample rampbuf[NumRamp]; /* Sample buffer for ramp-down. */ - - /* Are volume and pitch same as previous call? */ - int sameVP = (volume == bufVolume && pitch == bufPitch); - - int i, j; - int numSamples = SamplingRate * time / 1000; - - /* - -- It seems that the first write to the audio device after it's - -- been opened must be the longest. - */ - if (numSamples > bufLen) { - if (audioDevFD >= 0) close(audioDevFD); - audioDevFD = -1; - } - if (audioDevFD < 0) { - if ((audioDevFD = open(AudioDev, O_WRONLY)) < 0) { - perror("?? Error opening audio device"); - return 1; - } - } - - /* - -- Allocate space for sample buffer. Set "i" to lowest index in - -- need of updating. - */ - i = sameVP ? bufLen : 0; - if (numSamples > bufLen) { - if (sameVP) { - buf = realloc(buf, numSamples * sizeof(Sample)); - } else { - if (buf != NULL) free(buf); - bufVolume = volume; - bufPitch = pitch; - buf = malloc(numSamples * sizeof(Sample)); - } - if (buf == NULL) { - fprintf(stderr, "?? Buy more memory.\n"); - return 1; - } - bufLen = numSamples; - } - - /* - -- Update any newly-allocated tail of sample buffer. The ramp-up is - -- handled here (since it always occurs at the same place); the ramp-down - -- is handled later. - */ - while (i < bufLen) { - double rampScale = (i < NumRamp) ? (double) i / NumRamp : 1; - double t = (double) i / SamplingRate; - buf[i++] = - sin(2 * M_PI * pitch * t) * MaxSample * rampScale * volume / 100; - } - - /* Sound the beep, except for the ramp-down. */ - write(audioDevFD, buf, (numSamples - NumRamp) * sizeof(Sample)); - - /* Ramp-down */ - for (i = 0, j = numSamples-NumRamp; i < NumRamp; i++, j++) - rampbuf[i] = buf[j] * ((double) (NumRamp - i) / NumRamp); - write(audioDevFD, rampbuf, sizeof rampbuf); - - return 0; -} diff --git a/beepIndigo.c b/beepIndigo.c deleted file mode 100644 index 59869ee..0000000 --- a/beepIndigo.c +++ /dev/null @@ -1,248 +0,0 @@ -/* beepIndigo.c John R. Murray murray@scri.fsu.edu Jan. 4, 1994. Implementation - * of beep.h for SGI Indigos. Basically a quick rewrite of beepSun.c, written - * by seligman et al 6/92 - */ - -/* - * If the audio library or audio include files are missing, you need - * to get sound support off the SGI distribution tapes or CD. - * - * Defining FULLVOLUME has no effect. See notes below. - */ - -/* NOTES: This will not compile on the older Personal Irises (4D/20 and 4D/25). --- It should work for newer PIs (4D/30 and 4D/35) on SGI models newer than the --- Indigo (Indy and Indigo^2), but has not been tested. Basically, anything --- that uses the Audio Library (ALwhatever function names), and *not* the --- /dev/audio interface, should work. --- --- The sound library on my machine is only a partial implementation, so some --- functionality in beep.h is missing. Notably: --- --- 1) No software volume control. (relative volume with -v still works, tho) --- --- 2) No software control of sampling rate. --- --- These parameters are controllable through the Audio Control Panel, --- accessible through the Tools submenu, or by running /usr/sbin/apanel. --- NOTE: This code assumes you have the output sampling rate set to 48 KHz --- (the default). If the tone is too low and the code timing is too slow, --- your output sampling rate is incorrect and will need to be set to 48 KHz. --- --- If you implement volume and sampling rate control, please be sure to send --- the updated code to the writer of morse.c, joe@montebello.soest.hawaii.edu, --- or to me and I'll forward it. -*/ - -#include "beep.h" -#include -#include - -#define ABUFSIZ (100000) /* 100000 is default buffer size */ -#define RATE (48000) /*48 K samples = 1 second (assuming it's set to the default)*/ -#define RAMP (RATE * 10 / 1000) /* 10 millisecond ramp */ -#define MAXTIME (ABUFSIZ) /* If STEREO, MAXTIME = ABUFSIZ / 2 */ -#define ASCALE (100) /* multiplier to size waveform to port width (assuming 8bit) */ - -ALport outPort; - -void writeSound(port, buffer, len) -ALport port; -signed char buffer[]; -unsigned long len; -{ - signed char *bufp; - unsigned long len2, fill; - - bufp = buffer; - len2 = len; - while ((fill = ALgetfillable(port)) < len2) - { - if (fill) - { - /* write as much as we can */ - ALwritesamps(port, bufp, fill); - bufp += fill; - len2 -= fill; - } - else - { - /* wait 1/CLK_TCK seconds (1/100 sec on my machine) */ - sginap(1); - } - } - ALwritesamps(port, bufp, len2); -} - -int -BeepInit () -{ - - ALconfig config; - - config = ALnewconfig(); - /* starting with default config (stereo, 16 bit wide samples, 100k buffer) */ - /* NOTE: we're assuming the sampling rate is set to the default (48K) */ - /* (software control of sampling rate is not fully implemented by SGI yet */ - - if (config == 0) - { - /* Uh oh! */ - return 1; - } - else - { - /* this is just to avoid rewriting much of Beep, we could - * run 24 bit stereo if we wanted. - */ - ALsetwidth(config, AL_SAMPLE_8); - ALsetchannels(config, AL_MONO); /* if STEREO, fix the #define of MAXTIME */ - ALsetqueuesize(config, ABUFSIZ); - -#ifdef FULLVOLUME - /* software volume control not fully implemented by SGI yet */ -#endif - - if (0 == (outPort = ALopenport("morse", "w", config))) - /* another problem */ - return 1; - ALfreeconfig(config); - return 0; - } -} - - -int -Beep (time, volume, pitch) - int time, volume, pitch; -{ -static signed char silence[MAXTIME]; -static signed char soundbuf[MAXTIME - RAMP]; -static signed char ramp_down[RAMP]; -static long last_n = 0xFFFFFFFFL; -static int last_pitch = -1, last_volume = -1; -static int first_time = 1; - -int i, cycle; -unsigned long n, first_len, down_len; -double dt; - -/* - * Initialize the sound of silence - */ - if (first_time == 1) - { - for (i = 0; i < MAXTIME; i++) - silence[i] = 0; - first_time = 0; - } - - -/* - * Finagle the number of samples - */ - n = (time / 1000.) * RATE; /* Number samples in tone time */ - n = n < MAXTIME ? n : MAXTIME; /* clip to buffer size */ - n = n < 2 * RAMP ? 2 * RAMP : n; /* leave room for ramps */ - -/* - * Catch stupidity - */ - if (pitch <= 0) - volume = 0; - - - if (volume <= 0) - { - writeSound(outPort, silence, n); - } - else - { -/* - * clip to Nyquist - * (Of course this means that if you ask for too high a frequency you - * just get silence, since you sample all the zero-crossings of the - * sine wave.) - */ - pitch = pitch < RATE / 2 ? pitch : RATE / 2; - cycle = ((RATE + 1.e-6) / pitch); /* samples per cycle */ - - if (cycle > MAXTIME / 2) - cycle = MAXTIME / 2; - - /* round down length of (rampup + mesa top) to integral cycle */ - first_len = ((n - RAMP) / cycle) * cycle; - if (first_len < cycle) - first_len = cycle; - if (first_len > MAXTIME - RAMP) - first_len = MAXTIME - RAMP; - - /* round down length of (rampdown) to integral cycle */ - down_len = ((RAMP) / cycle) * cycle; - if (down_len < cycle) - down_len = cycle; - if (down_len > RAMP) - down_len = RAMP; - -/* - * Can we just reuse what we had before? - */ - if (pitch != last_pitch || n > last_n || volume != last_volume) - { - last_pitch = pitch; - last_n = n; - last_volume = volume; - - dt = 2. * 3.14159 / cycle; /* sine scale factor */ - -/* Ramp up; begin with silence */ - - for (i = 0; i < RAMP; i++) - { - soundbuf[i] = ASCALE * ((float) i / RAMP) * (volume / 100.) - * sin (i * dt); - } - -/* Mesa top */ - for (i = RAMP; i < first_len; i++) - { - soundbuf[i] = ASCALE * 1. * (volume / 100.) * sin (i * dt); - } - -/* Ramp down; end with silence */ - for (i = 0; i < down_len; i++) - { - ramp_down[i] = ASCALE * (1. - (float) (i + 1) / down_len) - * (volume / 100.) * sin (i * dt); - } - } - writeSound(outPort, soundbuf, first_len); - writeSound(outPort, ramp_down, down_len); - } - - return 0; -} - - -int -BeepWait () -{ - while (ALgetfilled(outPort) > 0) - sginap(1); /* wait 1/CLK_TCK seconds (1/100th second on my machine) */ - return 0; -} - - -int -BeepCleanup () -{ - ALcloseport(outPort); - return 0; -} - - -int -BeepResume () -{ - return BeepInit(); -} diff --git a/beepSun.c b/beepSun.c deleted file mode 100644 index a6340eb..0000000 --- a/beepSun.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * If the audio library or audio include files are missing, you need - * to get /usr/demo/SOUND off the Sun OS tapes or CD. - * - * If FULLVOLUME is defined this routine will turn your audio device up to - * full volume; it will not attempt to reset the current speaker / jack choice. - */ - -/* beepSun.c -- seligman 6/92 */ - -/* --- Implementation of beep.h for Sun. --- Rick to Joe to Scott to Joe. -*/ - -/* Date: Fri, 2 Aug 91 08:26:08 PDT */ -/* From: rick@st.unocal.com (Richard Ottolini) */ - -/* Revised: Joe Dellinger */ -/* Sat Nov 28 02:30:32 HST 1992 */ - -/* Revised: Brian Suggs (fixed the "annoying click" bug) */ -/* Fri Sep 16 12:29:13 PDT 1994 */ - -#include "beep.h" -#include -#include -#include -#include -#include -#include - - -#define RATE (8000) /* 8 K samples = 1 second */ -#define RAMP (RATE * 5 / 1000) /* 5 millisecond ramp */ -#define MAXTIME (2 * RATE) /* 2 seconds max tone time */ - -static int audio; -static audio_info_t audio_stat; - -int -BeepInit () -{ - audio = open ("/dev/audio", O_WRONLY); - - if (audio < 0) - /* Uh oh! */ - return 1; - else - { -#ifdef FULLVOLUME - /* - * Turn the speaker (or headphone, whichever the user has it set to) - * up to full volume. - */ - AUDIO_INITINFO(&audio_stat); - audio_stat.play.gain = AUDIO_MAX_GAIN; - ioctl (audio, AUDIO_SETINFO, &audio_stat); -#endif - - return 0; - } -} - - -int -Beep (time, volume, pitch) - int time, volume, pitch; -{ -static unsigned char silence[MAXTIME]; -static unsigned char soundbuf[MAXTIME - RAMP]; -static unsigned char ramp_down[RAMP]; -static int last_pitch = -1, last_n = -1, last_volume = -1; -static int first_time = 1; - -int i, n, first_len, down_len, cycle; -double dt; - -/* - * Initialize the sound of silence - */ - if (first_time == 1) - { - for (i = 0; i < MAXTIME; i++) - silence[i] = audio_l2u (0); - first_time = 0; - } - - -/* - * Finagle the number of samples - */ - n = (time / 1000.) * RATE; /* Number samples in tone time */ - n = n < MAXTIME ? n : MAXTIME; /* clip to buffer size */ - n = n < 2 * RAMP ? 2 * RAMP : n; /* leave room for ramps */ - -/* - * Catch stupidity - */ - if (pitch <= 0) - volume = 0; - - - if (volume <= 0) - { - write (audio, silence, n); - } - else - { -/* - * clip to Nyquist - * (Of course this means that if you ask for too high a frequency you - * just get silence, since you sample all the zero-crossings of the - * sine wave.) - */ - pitch = pitch < RATE / 2 ? pitch : RATE / 2; - cycle = ((RATE + 1.e-6) / pitch); /* samples per cycle */ - - if (cycle > MAXTIME / 2) - cycle = MAXTIME / 2; - - /* round down length of (rampup + mesa top) to integral cycle */ - first_len = ((n - RAMP) / cycle) * cycle; - if (first_len < cycle) - first_len = cycle; - if (first_len > MAXTIME - RAMP) - first_len = MAXTIME - RAMP; - - /* round down length of (rampdown) to integral cycle */ - down_len = ((RAMP) / cycle) * cycle; - if (down_len < cycle) - down_len = cycle; - if (down_len > RAMP) - down_len = RAMP; - -/* - * Can we just reuse what we had before? - */ - if (pitch != last_pitch || n > last_n || volume != last_volume) - { - last_pitch = pitch; - last_n = n; - last_volume = volume; - - dt = 2. * M_PI / cycle; /* sine scale factor */ - -/* Ramp up; begin with silence */ - - for (i = 0; i < RAMP; i++) - { - soundbuf[i] = audio_l2u (audio_d2l ( - ((float) i / RAMP) * (volume / 100.) * sin (i * dt) - )); - } - -/* Mesa top */ - for (i = RAMP; i < first_len; i++) - { - soundbuf[i] = audio_l2u (audio_d2l ( - 1. * (volume / 100.) * sin (i * dt) - )); - } - -/* Ramp down; end with silence */ - for (i = 0; i < down_len; i++) - { - ramp_down[i] = audio_l2u (audio_d2l ( - (1. - (float) (i + 1) / down_len) * (volume / 100.) * sin (i * dt) - )); - } - } - - write (audio, soundbuf, first_len); - write (audio, ramp_down, down_len); - } - - return 0; -} - - -int -BeepWait () -{ - ioctl (audio, AUDIO_DRAIN); - return 0; -} - - -int -BeepCleanup () -{ - return 0; -} - - -int -BeepResume () -{ - return 0; -} -- 2.43.0