Forgot to include the rsynth module.mk file in the last commit.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1114 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-06-12 00:11:12 +00:00
parent 228e7c1a5d
commit 66861f2f95
16 changed files with 21 additions and 2666 deletions

View File

@ -1,130 +0,0 @@
/*****************************************************************/
/*****************************************************************/
/*** ***/
/*** ***/
/*** Play out a file on the NeXT ***/
/*** ***/
/*** ***/
/*** B. Stuyts 21-feb-94 ***/
/*** ***/
/*** ***/
/*****************************************************************/
/*****************************************************************/
#include <sound/sound.h>
#include <stdio.h>
#include <libc.h>
#include "getargs.h"
#include "hplay.h"
#undef DEBUG
#define SAMP_RATE SND_RATE_CODEC
long samp_rate = SAMP_RATE;
SNDSoundStruct *sound = NULL;
int
audio_init(int argc, char *argv[])
{
int err;
int rate_set = 0;
#ifdef DEBUG
int i;
printf("audio_init: %d\n", argc);
for (i = 0; i < argc; i++)
printf("audio_init arg %d = %s\n", i, argv[i]);
#endif
argc = getargs("NeXT audio",argc, argv,
"r", "%d", &rate_set, "Sample rate",
NULL);
if (help_only)
return argc;
if (rate_set)
samp_rate = rate_set;
err = SNDAlloc(&sound, 1000000, SND_FORMAT_LINEAR_16, samp_rate, 1, 0);
if (err)
{
fprintf(stderr, "audio_init: %s\n", SNDSoundError(err));
exit(1);
}
return argc;
}
void
audio_play(int n, short *data)
{
int err;
#ifdef DEBUG
printf("audio_play: %d words\n", n);
#if 0
printf("audio_play: sound = %ld\n", sound);
printf("audio_play: dataLocation = %ld\n", sound->dataLocation);
printf("audio_play: sum = %ld\n", (char *) sound + sound->dataLocation);
#endif
#endif
if (n > 0)
{
/* Wait for previous sound to finish before changing
fields in sound
*/
err = SNDWait(0);
if (err)
{
fprintf(stderr, "SNDWait: %s\n", SNDSoundError(err));
exit(1);
}
sound->dataSize = n * sizeof(short);
/* Patch from benstn@olivetti.nl (Ben Stuyts)
Thanks to ugubser@avalon.unizh.ch for finding out why the NEXTSTEP
version of rsynth didn't work on Intel systems. As suspected, it was a
byte-order problem.
*/
#if i386
swab((char *) data, (char *) sound + sound->dataLocation, n * sizeof(short));
#else /* i386 */
bcopy(data, (char *) sound + sound->dataLocation, n * sizeof(short));
#endif
err = SNDStartPlaying(sound, 1, 5, 0, 0, 0);
if (err)
{
fprintf(stderr, "audio_play: %s\n", SNDSoundError(err));
exit(1);
}
}
}
void
audio_term()
{
int err;
#ifdef DEBUG
printf("audio_term\n");
#endif
if(!sound)
return;
err = SNDWait(0);
if (err)
{
fprintf(stderr, "audio_play: %s\n", SNDSoundError(err));
exit(1);
}
err = SNDFree(sound);
if (err)
{
fprintf(stderr, "audio_term: %s\n", SNDSoundError(err));
exit(1);
}
}

View File

@ -1,209 +0,0 @@
/*
Copyright (c) 2003 Nick Ing-Simmons.
All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#include "config.h"
#include "useconfig.h"
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <unistd.h>
// #define ALSA_PCM_OLD_HW_PARAMS_API
#include <alsa/asoundlib.h>
#include "l2u.h"
char *pcm_name = "default";
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 11025
long samp_rate = SAMP_RATE;
/* Audio Parameters */
static int linear_fd = -1;
char *prog = "hplay";
static snd_pcm_t *pcm;
static snd_pcm_hw_params_t *hwparams;
static snd_pcm_uframes_t chunk;
static int
audio_open(void)
{
int err;
if ((err = snd_pcm_open(&pcm,pcm_name,SND_PCM_STREAM_PLAYBACK,0)) < 0)
{
fprintf(stderr,"Cannot open %s:%s",pcm_name,snd_strerror(err));
return 0;
}
else
{
unsigned int want = samp_rate;
int dir = 0;
snd_pcm_hw_params_malloc(&hwparams);
snd_pcm_hw_params_any(pcm,hwparams);
/* Check capabilities */
if ((err = snd_pcm_hw_params_set_access(pcm, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{
fprintf(stderr,"Cannot set access %s:%s",pcm_name,snd_strerror(err));
return 0;
}
/* Set sample format */
if ((err=snd_pcm_hw_params_set_format(pcm, hwparams, SND_PCM_FORMAT_S16)) < 0)
{
fprintf(stderr,"Error setting format %s:%s",pcm_name,snd_strerror(err));
return(0);
}
#ifdef ALSA_PCM_OLD_HW_PARAMS_API
want = snd_pcm_hw_params_set_rate_near(pcm, hwparams, want, &dir);
#else
err = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &want, &dir);
#endif
if (dir != 0 || want != samp_rate)
{
fprintf(stderr,"Wanted %ldHz, got %uHz (%d)",samp_rate,want,dir);
samp_rate = want;
}
if ((err=snd_pcm_hw_params_set_channels(pcm, hwparams, 1)) < 0)
{
fprintf(stderr,"Error setting channels %s:%s",pcm_name,snd_strerror(err));
return(0);
}
/* Apply HW parameter settings to */
/* PCM device and prepare device */
if ((err=snd_pcm_hw_params(pcm, hwparams)) < 0)
{
fprintf(stderr,"Error setting parameters %s:%s",pcm_name,snd_strerror(err));
return(0);
}
#ifdef ALSA_PCM_OLD_HW_PARAMS_API
chunk = snd_pcm_hw_params_get_buffer_size (hwparams);
#else
snd_pcm_hw_params_get_buffer_size (hwparams,&chunk);
#endif
return 1;
}
}
int
audio_init(int argc, char *argv[])
{
int rate_set = 0;
int use_audio = 1;
prog = argv[0];
argc = getargs("ALSA Sound driver",argc, argv,
"r", "%d", &rate_set, "Sample rate",
"A", "default", &pcm_name, "Device",
"a", NULL, &use_audio, "Audio enable",
NULL);
if (help_only)
return argc;
if (rate_set)
samp_rate = rate_set;
if (use_audio)
audio_open();
return argc;
}
void
audio_term(void)
{
/* Finish linear file */
if (linear_fd >= 0)
{
ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR));
close(linear_fd);
linear_fd = -1;
}
/* Close audio system */
if (pcm)
{
int err = snd_pcm_drain(pcm);
if (err < 0)
{
fprintf(stderr,"%s:%s\n",pcm_name,snd_strerror(err));
}
if ((err = snd_pcm_close(pcm)) < 0)
{
fprintf(stderr,"%s:%s\n",pcm_name,snd_strerror(err));
}
pcm = 0;
}
if (hwparams)
{
snd_pcm_hw_params_free(hwparams);
hwparams = 0;
}
}
void
audio_play(int n, short *data)
{
if (n > 0)
{
if (linear_fd >= 0)
{
if (write(linear_fd, data, n) != n)
perror("write");
}
if (pcm)
{
snd_pcm_sframes_t ret;
while (n > 0)
{
size_t amount = ((size_t) n > chunk) ? chunk : (size_t) n;
while ((ret = snd_pcm_writei(pcm, data, amount)) < 0)
{
/* Pipe may well drain - but harmless as we write
whole words to the pipe
*/
if (ret != -EPIPE)
{
fprintf(stderr,"%s:%s\n",pcm_name,snd_strerror(ret));
}
snd_pcm_prepare(pcm);
}
n -= ret;
data += ret;
}
}
}
}

View File

@ -1,103 +0,0 @@
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
/* Define to empty if the keyword does not work. */
/* #undef const */
/* Define to `long' if <sys/types.h> doesn't define. */
/* #undef off_t */
/* Define if you need to in order for stat and other things to work. */
/* #undef _POSIX_SOURCE */
/* Define as the return type of signal handlers (int or void). */
#define RETSIGTYPE void
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if prototype cannot use a type of float if followed by K&R defn. */
#define NOPROTOFLOAT 1
/* turn off strict IEEE compliance in favour of speed */
/* #undef HAVE_NONSTDARITH */
/* Define if we can find -lX11 */
#define HAVE_LIBX11 1
/* Define if we can find nas -laudio */
/* #define HAVE_NAS 1 */
/* Define if we can find /dev/dsp - linux/FreeBSD */
/* #undef HAVE_DEV_DSP */
/* Define if we can find /dev/sbdsp - linux (older drivers) */
/* #undef HAVE_DEV_SBDSP */
/* Define if you have the memcpy function. */
/* #undef HAVE_MEMCPY */
/* Define if you have the strchr function. */
/* #undef HAVE_STRCHR */
/* Define if you have the <audio/audiolib.h> header file. */
/* #define HAVE_AUDIO_AUDIOLIB_H 1 */
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <libc.h> header file. */
/* #undef HAVE_LIBC_H */
/* Define if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define if you have the <machine/soundcard.h> header file. */
/* #undef HAVE_MACHINE_SOUNDCARD_H */
/* Define if you have the <malloc.h> header file. */
/* #undef HAVE_MALLOC_H */
/* Define if you have the <memory.h> header file. */
/* #undef HAVE_MEMORY_H */
/* Define if you have the <sun/audioio.h> header file. */
/* #undef HAVE_SUN_AUDIOIO_H */
/* Define if you have the <sys/audioio.h> header file. */
/* #define HAVE_SYS_AUDIOIO_H 1 */
/* Define if you have the <sys/file.h> header file. */
#define HAVE_SYS_FILE_H 1
/* Define if you have the <sys/ioccom.h> header file. */
#define HAVE_SYS_IOCCOM_H 1
/* Define if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define if you have the <sys/soundcard.h> header file. */
/* #undef HAVE_SYS_SOUNDCARD_H */
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define if you have the <unistd.h> header file. */
/* #define HAVE_UNISTD_H 1 */
/* Define if you have the M library (-lM). */
#define HAVE_LIBM 1
/* Define if you have the audio library (-laudio). */
/* #undef HAVE_LIBAUDIO */
/* Define if you have the gdbm library (-lgdbm). */
/* #define HAVE_LIBGDBM 1 */
/* Define if you have the m library (-lm). */
#define HAVE_LIBM 1

View File

@ -1,22 +0,0 @@
#include <config.h>
#include <stdio.h>
#include "getargs.h"
#include "hplay.h"
long samp_rate = 8000;
int
audio_init(int argc, char **argv)
{
return (0);
}
void
audio_term(void)
{
}
void
audio_play(int n, short *data)
{
}

View File

@ -1,144 +0,0 @@
#include <config.h>
/*****************************************************************/
/*** ***/
/*** Play out a file on Linux ***/
/*** ***/
/*** H.F. Silverman 1/4/91 ***/
/*** Modified: H.F. Silverman 1/16/91 for amax parameter ***/
/*** Modified: A. Smith 2/14/91 for 8kHz for klatt synth ***/
/*** Modified: Rob W. W. Hooft (hooft@EMBL-Heidelberg.DE) ***/
/*** adapted for linux soundpackage Version 2.0 ***/
/*** ***/
/*****************************************************************/
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <machine/soundcard.h>
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 8000
long samp_rate = SAMP_RATE;
/* Audio Parameters */
static int dev_fd = -1;
/* file descriptor for audio device */
char *dev_file = "/dev/dsp";
static int linear_fd = -1;
static char *linear_file = NULL;
char *prog = "hplay";
static int
audio_open(void)
{
dev_fd = open(dev_file, O_WRONLY | O_NDELAY);
if (dev_fd < 0)
{
perror(dev_file);
return 0;
}
return 1;
}
int
audio_init(int argc, char *argv[])
{
int rate_set = 0;
int use_audio = 1;
prog = argv[0];
argc = getargs("FreeBSD Audio",argc, argv,
"r", "%d", &rate_set, "Sample rate",
"a", NULL, &use_audio, "Audio enable",
NULL);
if (help_only)
return argc;
if (use_audio)
audio_open();
if (rate_set)
samp_rate = rate_set;
if (dev_fd > 0)
{
ioctl(dev_fd, SNDCTL_DSP_SPEED, &samp_rate);
printf("Actual sound rate: %ld\n", samp_rate);
}
return argc;
}
void
audio_term()
{
int dummy;
/* Close audio system */
if (dev_fd >= 0)
{
ioctl(dev_fd, SNDCTL_DSP_SYNC, &dummy);
close(dev_fd);
dev_fd = -1;
}
/* Finish linear file */
if (linear_fd >= 0)
{
ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR));
close(linear_fd);
linear_fd = -1;
}
}
void
audio_play(int n, short *data)
{
if (n > 0)
{
unsigned char *converted = (unsigned char *) malloc(n);
int i;
if (converted == NULL)
{
fprintf(stderr, "Could not allocate memory for conversion\n");
exit(3);
}
for (i = 0; i < n; i++)
converted[i] = (data[i] - 32768) / 256;
if (linear_fd >= 0)
{
if (write(linear_fd, converted, n) != n)
perror("write");
}
if (dev_fd >= 0)
{
if (write(dev_fd, converted, n) != n)
perror("write");
}
free(converted);
}
}

View File

@ -1,187 +0,0 @@
#include <config.h>
/*****************************************************************/
/*** ***/
/*** Play out a file on an HP ***/
/*** ***/
/*** accesses audio device directly, ***/
/*** should use Aserver & Alib instead ***/
/*** ***/
/*** Markus.Gyger@itr.ch 23 Jul 94 ***/
/*** ***/
/*****************************************************************/
#include <useconfig.h>
#include <stdio.h>
#include <fcntl.h>
/* Force this on as otherwise <sys/ioctl.h> may not
expand enough for <sys/audio.h> to work as expected,
and that is after all the *whole* point of this file.
*/
#define _INCLUDE_HPUX_SOURCE
#include <sys/ioctl.h>
#include <sys/audio.h>
#include <errno.h>
#include <limits.h>
#include "getargs.h"
#include "hplay.h"
#include "getargs.h"
#define AUDIO_DEVICE "/dev/audio"
#define SAMP_RATE 10000 /* desired, will be 11025 or 8000 */
long samp_rate = SAMP_RATE;
static int audioDescriptor = -1;
int
audio_init(argc, argv)
int argc;
char *argv[];
{
int i,
sr,
headphone = 2,
speaker = 2,
waitidle = 0;
struct audio_describe audioInfo;
struct audio_gain audioGain;
audioGain.cgain[0].transmit_gain = INT_MIN; /* never used value */
/* options g/h/s aren't needed if AudioCP or acontrol is used */
argc = getargs("HP-UX Audio",argc, argv,
"r", "%ld", &samp_rate, "Sample rate",
"g", "%d", &audioGain.cgain[0].transmit_gain, "Gain -128..127",
"h", NULL, &headphone, "Headphones",
"s", NULL, &speaker, "Speaker",
"W", NULL, &waitidle, "Wait until idle (not implemented)",
NULL);
if (help_only)
return argc;
/* open audio device */
audioDescriptor = open(AUDIO_DEVICE, O_WRONLY);
if (audioDescriptor == -1)
{
perror("open");
exit(1);
}
/* get list of available sample rates */
if (ioctl(audioDescriptor, AUDIO_DESCRIBE, &audioInfo) == -1)
{
perror("AUDIO_DESCRIBE");
exit(1);
}
/* set output gain */
if (audioGain.cgain[0].transmit_gain != INT_MIN)
{
if (audioGain.cgain[0].transmit_gain < AUDIO_OFF_GAIN)
audioGain.cgain[0].transmit_gain = AUDIO_OFF_GAIN;
if (audioGain.cgain[0].transmit_gain > AUDIO_MAX_GAIN)
audioGain.cgain[0].transmit_gain = AUDIO_MAX_GAIN;
audioGain.channel_mask = AUDIO_CHANNEL_0;
audioGain.cgain[0].receive_gain = AUDIO_OFF_GAIN;
audioGain.cgain[0].monitor_gain = AUDIO_OFF_GAIN;
if (ioctl(audioDescriptor, AUDIO_SET_GAINS, &audioGain) == -1)
{
perror("AUDIO_SET_GAINS");
exit(1);
}
}
/* select output */
if (headphone != 2 || speaker != 2)
{
int outSel;
if (ioctl(audioDescriptor, AUDIO_GET_OUTPUT, &outSel) == -1)
{
perror("AUDIO_GET_OUTPUT");
exit(1);
}
if (headphone != 2)
if (headphone)
outSel |= AUDIO_OUT_EXTERNAL;
else
outSel &= ~AUDIO_OUT_EXTERNAL;
if (speaker != 2) /* internal and external speakers */
if (speaker)
outSel |= (AUDIO_OUT_INTERNAL | AUDIO_OUT_LINE);
else
outSel &= ~(AUDIO_OUT_INTERNAL | AUDIO_OUT_LINE);
if (ioctl(audioDescriptor, AUDIO_SET_OUTPUT, outSel) == -1)
{
perror("AUDIO_SET_OUTPUT");
exit(1);
}
}
/* switch to 16 bit samples (710 converts to u-law) */
if (ioctl(audioDescriptor, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_LINEAR16BIT) == -1)
{
perror("AUDIO_SET_DATA_FORMAT");
exit(1);
}
/* choose nearest available sample rate (710 has 8 kHz only) */
sr = audioInfo.sample_rate[0];
for (i = 1; i < audioInfo.nrates; i++)
if (abs(audioInfo.sample_rate[i] - samp_rate) < abs(sr - samp_rate))
sr = audioInfo.sample_rate[i];
samp_rate = sr;
/* set sampling rate */
if (ioctl(audioDescriptor, AUDIO_SET_SAMPLE_RATE, (int) samp_rate) == -1)
{
perror("AUDIO_SET_SAMPLE_RATE");
exit(1);
}
/* switch to mono */
if (ioctl(audioDescriptor, AUDIO_SET_CHANNELS, 1) == -1)
{
perror("AUDIO_SET_CHANNELS");
exit(1);
}
return argc;
}
void
audio_term()
{
if (audioDescriptor >= 0)
{
if (ioctl(audioDescriptor, AUDIO_DRAIN) == -1)
{
perror("AUDIO_DRAIN");
exit(1);
}
if (close(audioDescriptor) == -1)
{
perror("close");
exit(1);
}
audioDescriptor = -1;
}
}
void
audio_play(n, data)
int n;
short *data;
{
if (n > 0)
{
unsigned size = n * sizeof(*data);
if (write(audioDescriptor, data, size) != size)
perror("write");
}
}

View File

@ -1,21 +0,0 @@
# This bit of Makefile only works if GNU make is available
# The classic make version would have `$(SRCDIR)/getrev $(SRCDIR)`
# which does not work as it gets evaluated by 'sh' once we have cd'ed
# elsewhere. GNU make scheme uses := and $(shell...) to evaluate
# REVISION once at Makefile parse time
# It is really only needed by developer
REVISION := $(shell $(SRCDIR)/getrev $(SRCDIR))
distribution:
rm -rf /tmp/rsynth-$(REVISION)
mkdir /tmp/rsynth-$(REVISION)
(cd $(SRCDIR); tar cf - `cat MANIFEST` ) | (cd /tmp/rsynth-$(REVISION); tar xf - )
(cd /tmp; tar cvf - rsynth-$(REVISION) ) | gzip -c > $(SRCDIR)/../rsynth-$(REVISION).tar.gz
disttest :
rm -rf /tmp/rsynth-$(REVISION)
mkdir /tmp/rsynth-$(REVISION)
(cd $(SRCDIR); tar cf - `cat MANIFEST` ) | (cd /tmp/rsynth-$(REVISION); tar xf - )
(cd /tmp/rsynth-$(REVISION); CC=$(CC) configure ; make CC=$(CC) -k check)

View File

@ -1,210 +0,0 @@
#ifndef _INC_MMSYSTEM
#define _INC_MMSYSTEM
typedef UINT MMRESULT;
typedef UINT MMVERSION; /* major (high byte), minor (low byte) */
typedef UINT *LPUINT;
#define MAXPNAMELEN 32 /* max product name length (including NULL) */
DECLARE_HANDLE(HWAVE);
DECLARE_HANDLE(HWAVEIN);
DECLARE_HANDLE(HWAVEOUT);
#ifndef _WIN32_VXD
typedef HWAVEIN *LPHWAVEIN;
typedef HWAVEOUT *LPHWAVEOUT;
#endif
typedef struct wavehdr_tag {
LPSTR lpData; /* pointer to locked data buffer */
DWORD dwBufferLength; /* length of data buffer */
DWORD dwBytesRecorded; /* used for input only */
DWORD dwUser; /* for client's use */
DWORD dwFlags; /* assorted flags (see defines) */
DWORD dwLoops; /* loop control counter */
struct wavehdr_tag FAR *lpNext; /* reserved for driver */
DWORD reserved; /* reserved for driver */
} PACKED WAVEHDR, *LPWAVEHDR;
#define MM_WOM_OPEN 0x3BB /* waveform output */
#define MM_WOM_CLOSE 0x3BC
#define MM_WOM_DONE 0x3BD
#define MM_WIM_OPEN 0x3BE /* waveform input */
#define MM_WIM_CLOSE 0x3BF
#define MM_WIM_DATA 0x3C0
/* wave callback messages */
#define WOM_OPEN MM_WOM_OPEN
#define WOM_CLOSE MM_WOM_CLOSE
#define WOM_DONE MM_WOM_DONE
#define WIM_OPEN MM_WIM_OPEN
#define WIM_CLOSE MM_WIM_CLOSE
#define WIM_DATA MM_WIM_DATA
/* flags for dwFlags parameter in waveOutOpen() and waveInOpen() */
#define WAVE_FORMAT_QUERY 0x0001
#define WAVE_ALLOWSYNC 0x0002
#if(WINVER >= 0x0400)
#define WAVE_MAPPED 0x0004
#define WAVE_FORMAT_DIRECT 0x0008
#define WAVE_FORMAT_DIRECT_QUERY (WAVE_FORMAT_QUERY | WAVE_FORMAT_DIRECT)
#endif /* WINVER >= 0x0400 */
#define CALLBACK_TYPEMASK 0x00070000l /* callback type mask */
#define CALLBACK_NULL 0x00000000l /* no callback */
#define CALLBACK_WINDOW 0x00010000l /* dwCallback is a HWND */
#define CALLBACK_TASK 0x00020000l /* dwCallback is a HTASK */
#define CALLBACK_FUNCTION 0x00030000l /* dwCallback is a FARPROC */
#ifdef _WIN32
#define CALLBACK_THREAD (CALLBACK_TASK)/* thread ID replaces 16 bit task */
#define CALLBACK_EVENT 0x00050000l /* dwCallback is an EVENT Handle */
#endif
/* flags for wFormatTag field of WAVEFORMAT */
#define WAVE_FORMAT_PCM 1
/* OLD general waveform format structure (information common to all formats) */
typedef struct waveformat_tag {
WORD wFormatTag; /* format type */
WORD nChannels; /* number of channels (i.e. mono, stereo, etc.) */
DWORD nSamplesPerSec; /* sample rate */
DWORD nAvgBytesPerSec; /* for buffer estimation */
WORD nBlockAlign; /* block size of data */
} PACKED WAVEFORMAT, *LPWAVEFORMAT;
/* specific waveform format structure for PCM data */
typedef struct pcmwaveformat_tag {
WAVEFORMAT wf;
WORD wBitsPerSample;
} PACKED PCMWAVEFORMAT, *LPPCMWAVEFORMAT;
#ifndef UNICODE_ONLY
typedef struct tagWAVEOUTCAPSA {
WORD wMid; /* manufacturer ID */
WORD wPid; /* product ID */
MMVERSION vDriverVersion; /* version of the driver */
CHAR szPname[MAXPNAMELEN]; /* product name (NULL terminated string) */
DWORD dwFormats; /* formats supported */
WORD wChannels; /* number of sources supported */
WORD wReserved1; /* packing */
DWORD dwSupport; /* functionality supported by driver */
} PACKED WAVEOUTCAPSA, *PWAVEOUTCAPSA, *NPWAVEOUTCAPSA, *LPWAVEOUTCAPSA;
#endif /*!UNICODE_ONLY */
#ifndef ANSI_ONLY
typedef struct tagWAVEOUTCAPSW {
WORD wMid; /* manufacturer ID */
WORD wPid; /* product ID */
MMVERSION vDriverVersion; /* version of the driver */
WCHAR szPname[MAXPNAMELEN]; /* product name (NULL terminated string) */
DWORD dwFormats; /* formats supported */
WORD wChannels; /* number of sources supported */
WORD wReserved1; /* packing */
DWORD dwSupport; /* functionality supported by driver */
} PACKED WAVEOUTCAPSW, *PWAVEOUTCAPSW, *NPWAVEOUTCAPSW, *LPWAVEOUTCAPSW;
#endif /*!ANSI_ONLY */
#ifdef UNICODE
typedef WAVEOUTCAPSW WAVEOUTCAPS;
typedef PWAVEOUTCAPSW PWAVEOUTCAPS;
typedef NPWAVEOUTCAPSW NPWAVEOUTCAPS;
typedef LPWAVEOUTCAPSW LPWAVEOUTCAPS;
#else
typedef WAVEOUTCAPSA WAVEOUTCAPS;
typedef PWAVEOUTCAPSA PWAVEOUTCAPS;
typedef NPWAVEOUTCAPSA NPWAVEOUTCAPS;
typedef LPWAVEOUTCAPSA LPWAVEOUTCAPS;
#endif /* UNICODE */
/*
* extended waveform format structure used for all non-PCM formats. this
* structure is common to all non-PCM formats.
*/
typedef struct tWAVEFORMATEX
{
WORD wFormatTag; /* format type */
WORD nChannels; /* number of channels (i.e. mono, stereo...) */
DWORD nSamplesPerSec; /* sample rate */
DWORD nAvgBytesPerSec; /* for buffer estimation */
WORD nBlockAlign; /* block size of data */
WORD wBitsPerSample; /* number of bits per sample of mono data */
WORD cbSize; /* the count in bytes of the size of */
/* extra information (after cbSize) */
} PACKED WAVEFORMATEX, *LPWAVEFORMATEX;
typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
/* MMTIME data structure */
typedef struct mmtime_tag
{
UINT wType; /* indicates the contents of the union */
union
{
DWORD ms; /* milliseconds */
DWORD sample; /* samples */
DWORD cb; /* byte count */
DWORD ticks; /* ticks in MIDI stream */
/* SMPTE */
struct
{
BYTE hour; /* hours */
BYTE min; /* minutes */
BYTE sec; /* seconds */
BYTE frame; /* frames */
BYTE fps; /* frames per second */
BYTE dummy; /* pad */
BYTE pad[2];
} smpte;
/* MIDI */
struct
{
DWORD songptrpos; /* song pointer position */
} midi;
} u;
} PACKED MMTIME, *LPMMTIME;
#define WINMMAPI extern
/* waveform audio function prototypes */
WINMMAPI UINT WINAPI waveOutGetNumDevs(void);
#ifndef UNICODE_ONLY
WINMMAPI MMRESULT WINAPI waveOutGetDevCapsA(UINT uDeviceID, LPWAVEOUTCAPSA pwoc, UINT cbwoc);
#endif /*!UNICODE_ONLY */
#ifndef ANSI_ONLY
WINMMAPI MMRESULT WINAPI waveOutGetDevCapsW(UINT uDeviceID, LPWAVEOUTCAPSW pwoc, UINT cbwoc);
#endif /*!ANSI_ONLY */
#ifdef UNICODE
#define waveOutGetDevCaps waveOutGetDevCapsW
#else
#define waveOutGetDevCaps waveOutGetDevCapsA
#endif /* !UNICODE */
#ifndef UNICODE_ONLY
WINMMAPI MMRESULT WINAPI waveOutGetErrorTextA(MMRESULT mmrError, LPSTR pszText, UINT cchText);
#endif //!UNICODE_ONLY
#ifndef ANSI_ONLY
WINMMAPI MMRESULT WINAPI waveOutGetErrorTextW(MMRESULT mmrError, LPWSTR pszText, UINT cchText);
#endif //!ANSI_ONLY
#ifdef UNICODE
#define waveOutGetErrorText waveOutGetErrorTextW
#else
#define waveOutGetErrorText waveOutGetErrorTextA
#endif // !UNICODE
WINMMAPI MMRESULT WINAPI waveOutOpen(LPHWAVEOUT phwo, UINT uDeviceID,
LPCWAVEFORMATEX pwfx, DWORD dwCallback, DWORD dwInstance, DWORD fdwOpen);
WINMMAPI MMRESULT WINAPI waveOutClose(HWAVEOUT hwo);
WINMMAPI MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
WINMMAPI MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
WINMMAPI MMRESULT WINAPI waveOutWrite(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh);
WINMMAPI MMRESULT WINAPI waveOutPause(HWAVEOUT hwo);
WINMMAPI MMRESULT WINAPI waveOutRestart(HWAVEOUT hwo);
WINMMAPI MMRESULT WINAPI waveOutReset(HWAVEOUT hwo);
WINMMAPI MMRESULT WINAPI waveOutBreakLoop(HWAVEOUT hwo);
WINMMAPI MMRESULT WINAPI waveOutGetPosition(HWAVEOUT hwo, LPMMTIME pmmt, UINT cbmmt);
WINMMAPI MMRESULT WINAPI waveOutGetPitch(HWAVEOUT hwo, LPDWORD pdwPitch);
WINMMAPI MMRESULT WINAPI waveOutSetPitch(HWAVEOUT hwo, DWORD dwPitch);
WINMMAPI MMRESULT WINAPI waveOutGetPlaybackRate(HWAVEOUT hwo, LPDWORD pdwRate);
WINMMAPI MMRESULT WINAPI waveOutSetPlaybackRate(HWAVEOUT hwo, DWORD dwRate);
WINMMAPI MMRESULT WINAPI waveOutGetID(HWAVEOUT hwo, LPUINT puDeviceID);
#endif /* _INC_MMSYSTEM */

View File

@ -1,150 +0,0 @@
/*
Copyright (c) 1998,2001-2002 Nick Ing-Simmons. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#include "config.h"
#include "useconfig.h"
#include <sys/time.h>
#include <sys/stat.h>
#ifdef __GNUC__
#define NeedFunctionPrototypes 1
#define NeedNestedPrototypes 1
#endif
#include <audio/audiolib.h>
#include <audio/soundlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include "getargs.h"
#include "hplay.h"
long samp_rate = 8000;
static int volume = 100;
static char *audioserver = NULL;
static AuServer *aud;
static void done(AuServer * aud, AuEventHandlerRec * handler, AuEvent * ev, AuPointer data)
{
switch (ev->auany.type)
{
case AuEventTypeElementNotify:
{
int *d = (int *) data;
*d = (ev->auelementnotify.cur_state == AuStateStop);
if (!*d || ev->auelementnotify.reason != AuReasonEOF)
{
fprintf(stderr, "curr_state=%d reason=%d\n",
ev->auelementnotify.cur_state,
ev->auelementnotify.reason);
}
}
break;
case AuEventTypeMonitorNotify:
break;
default:
fprintf(stderr, "type=%d serial=%ld time=%ld id=%ld\n",
ev->auany.type, ev->auany.serial, ev->auany.time, ev->auany.id);
break;
}
}
void
audio_play(int n,short *data)
{
int endian = 1;
#define little_endian ((*((char *)&endian) == 1))
int priv = 0;
AuEvent ev;
Sound s = SoundCreate(SoundFileFormatNone, little_endian ?
AuFormatLinearSigned16LSB : AuFormatLinearSigned16MSB,
1, samp_rate, n, "Chit chat");
if (aud)
{
#ifdef USE_ALL_ARGS
AuStatus ret_status;
AuFlowID flow = 0;
int monitor = 0;
int multiplier = 0;
if (!AuSoundPlayFromData(aud, s, data, AuNone,
AuFixedPointFromFraction(volume, 100),
done, &priv,
&flow, &multiplier,
&monitor, &ret_status))
#else
if (!AuSoundPlayFromData(aud, s, data, AuNone,
AuFixedPointFromFraction(volume, 100),
done, &priv,
NULL, NULL, NULL, NULL))
#endif
perror("problems playing data");
else
{
while (1)
{
AuNextEvent(aud, AuTrue, &ev);
AuDispatchEvent(aud, &ev);
if (priv)
break;
}
}
}
SoundDestroy(s);
}
void
audio_term(void)
{
if (aud)
{
AuFlush(aud);
AuCloseServer(aud);
}
}
int
audio_init(int argc,char *argv[])
{
int rate_set = samp_rate;
int vol = 0;
argc = getargs("Nas",argc, argv,
"r", "%d", &rate_set, "Sample rate Hz",
"V", "%d", &vol, "Volume 0 .. 1.0",
"a", "", &audioserver,"Name of server",
NULL);
if (help_only)
return argc;
if ((aud = AuOpenServer(audioserver, 0, NULL, 0, NULL, NULL)) == (AuServer *) 0)
perror(audioserver);
if (rate_set && rate_set != samp_rate)
samp_rate = rate_set;
if (vol)
volume = vol;
return argc;
}

View File

@ -1,316 +0,0 @@
/*
Copyright (c) 1991, H.F. Silverman, A. Smith, Rob W. W. Hooft.
Copyright (c) 1994,1999,2001-2002 Nick Ing-Simmons.
All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#include "config.h"
/******************************************************************
***
*** Play out a file on Linux
***
*** H.F. Silverman 1/4/91
*** Modified: H.F. Silverman 1/16/91 for amax parameter
*** Modified: A. Smith 2/14/91 for 8kHz for klatt synth
*** Modified: Rob W. W. Hooft (hooft@EMBL-Heidelberg.DE)
*** adapted for linux soundpackage Version 2.0
*** Merged FreeBSD version - 11/11/94 NIS
*** Re-worked for OSS now I have one myself - NIS Sept. 1999
*** Re-worked again to use linear if we can figure out that
*** device supports it. Also turn off O_NONBLOCK and O_NDELAY
*** after open
***
*******************************************************************/
#include "useconfig.h"
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <unistd.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_SOUNDCARD_H /* linux style */
#include <sys/soundcard.h>
#endif
#ifdef HAVE_MACHINE_SOUNDCARD_H /* FreeBSD style */
#include <machine/soundcard.h>
#endif
#ifndef AFMT_S16_LE
#define AFMT_S16_LE 16
#endif
#ifndef AFMT_U8
#define AFMT_U8 8
#endif
#ifndef AFMT_MU_LAW
#define AFMT_MU_LAW 1
#endif
/* file descriptor for audio device */
#include "l2u.h"
#if defined(HAVE_DEV_DSP)
char *dev_file = "/dev/dsp";
static int dev_fmt = AFMT_U8;
#else /* DSP */
#if defined(HAVE_DEV_AUDIO)
char *dev_file = "/dev/audio";
static int dev_fmt = AFMT_MU_LAW;
#else
#if defined(HAVE_DEV_DSPW) || !defined(HAVE_DEV_SBDSP)
char *dev_file = "/dev/dspW";
static int dev_fmt = AFMT_S16_LE;
#else
#if defined(HAVE_DEV_SBDSP)
char *dev_file = "/dev/sbdsp";
static int dev_fmt = AFMT_U8;
#endif /* SBDSP */
#endif /* DSPW */
#endif /* AUDIO */
#endif /* DSP */
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 11025
long samp_rate = SAMP_RATE;
/* Audio Parameters */
static int dev_fd = -1;
static int linear_fd = -1;
char *prog = "hplay";
static const short endian = 0x1234;
static int
audio_open(void)
{
int attempt;
for (attempt = 0; attempt < 50; attempt++)
{
dev_fd = open(dev_file, O_WRONLY | O_NDELAY | O_EXCL);
if (dev_fd >= 0 || errno != EBUSY)
break;
usleep(10000);
}
if (dev_fd >= 0)
{
/* Modern /dev/dsp honours O_NONBLOCK and O_NDELAY for write which
leads to data being dropped if we try and write and device isn't ready
we would either have to retry or we can just turn it off ...
*/
int fl = fcntl(dev_fd,F_GETFL,0);
if (fl != -1)
{
if (fcntl(dev_fd,F_SETFL,fl & ~(O_NONBLOCK|O_NDELAY)) == 0)
{
#ifdef SNDCTL_DSP_GETFMTS
int fmts;
if (ioctl(dev_fd,SNDCTL_DSP_GETFMTS,&fl) == 0)
{
fmts = fl;
if (*((const char *)(&endian)) == 0x34)
{
if ((fl = fmts & AFMT_S16_LE) && ioctl(dev_fd,SNDCTL_DSP_SETFMT,&fl) == 0)
{
dev_fmt = fl;
return 1;
}
}
else
{
if ((fl = fmts & AFMT_S16_BE) && ioctl(dev_fd,SNDCTL_DSP_SETFMT,&fl) == 0)
{
dev_fmt = fl;
return 1;
}
}
if ((fl = fmts & AFMT_MU_LAW) && ioctl(dev_fd,SNDCTL_DSP_SETFMT,&fl) == 0)
{
dev_fmt = fl;
return 1;
}
}
#endif
fprintf(stderr,"Using %s on %d fl=%X\n",dev_file,dev_fd,fl);
return 1;
}
}
}
perror(dev_file);
return 0;
}
int
audio_init(int argc, char *argv[])
{
int rate_set = 0;
int use_audio = 1;
prog = argv[0];
argc = getargs("Sound driver",argc, argv,
"r", "%d", &rate_set, "Sample rate",
"a", NULL, &use_audio, "Audio enable",
NULL);
if (help_only)
return argc;
if (use_audio)
audio_open();
if (rate_set)
samp_rate = rate_set;
if (dev_fd > 0)
{
int want = samp_rate;
ioctl(dev_fd, SNDCTL_DSP_SPEED, &samp_rate);
if (samp_rate != want)
printf("Actual sample rate: %ld\n", samp_rate);
}
return argc;
}
void
audio_term(void)
{
int dummy;
/* Close audio system */
if (dev_fd >= 0)
{
ioctl(dev_fd, SNDCTL_DSP_SYNC, &dummy);
close(dev_fd);
dev_fd = -1;
}
/* Finish linear file */
if (linear_fd >= 0)
{
ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR));
close(linear_fd);
linear_fd = -1;
}
}
void
audio_play(int n, short *data)
{
if (n > 0)
{
if (dev_fmt == AFMT_S16_LE || dev_fmt == AFMT_S16_BE)
{
n *= 2;
if (dev_fd >= 0)
{
if (write(dev_fd, data, n) != n)
perror("write");
}
if (linear_fd >= 0)
{
if (write(linear_fd, data, n) != n)
perror("write");
}
}
else if (dev_fmt == AFMT_U8)
{
unsigned char *converted = (unsigned char *) malloc(n);
int i;
if (converted == NULL)
{
fprintf(stderr, "Could not allocate memory for conversion\n");
exit(3);
}
for (i = 0; i < n; i++)
converted[i] = (data[i] - 32767) / 256;
if (linear_fd >= 0)
{
if (write(linear_fd, converted, n) != n)
perror("write");
}
if (dev_fd >= 0)
{
if (write(dev_fd, converted, n) != n)
perror("write");
}
free(converted);
}
else if (dev_fmt == AFMT_MU_LAW)
{
unsigned char *plabuf = (unsigned char *) malloc(n);
if (plabuf)
{
int w;
unsigned char *p = plabuf;
unsigned char *e = p + n;
while (p < e)
{
*p++ = short2ulaw(*data++);
}
p = plabuf;
while ((w = write(dev_fd, p, n)) != n)
{
if (w == -1 && errno != EINTR)
{
fprintf(stderr, "%d,%s:%d\n", errno, __FILE__, __LINE__);
perror("audio");
abort();
}
else
{
fprintf(stderr, "Writing %u, only wrote %u\n", n, w);
p += w;
n -= w;
}
}
free(plabuf);
}
else
{
fprintf(stderr, "%s : No memory for ulaw data\n", program);
}
}
else
{
fprintf(stderr, "%s : unknown audio format\n", program);
}
}
}

View File

@ -1,29 +0,0 @@
#include <config.h>
#include <useconfig.h>
#include <stdio.h>
#include "getargs.h"
#include "hplay.h"
#include <fcntl.h>
static FILE *dev_fd;
long samp_rate = 8000;
int
audio_init(int argc, char **argv)
{
dev_fd = popen("/usr/audio/bin/send_sound -l16", "w");
return (0);
}
void
audio_term(void)
{
pclose(dev_fd);
}
void
audio_play(int n, short *data)
{
fwrite(data, 2, n, dev_fd);
fflush(dev_fd);
}

View File

@ -1,92 +0,0 @@
#include <config.h>
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <stropts.h>
#include <sys/ioctl.h>
#define TRUE 1
#define FALSE 0
#include <audio.h>
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 11025
long samp_rate = SAMP_RATE;
/* Audio Parameters */
int Verbose = FALSE; /* verbose messages */
int Immediate = FALSE; /* Should we hang waiting for device ? */
static int async = TRUE;
char *Ifile; /* current filename */
static ALconfig alconf;
static ALport alprt;
/* sgi system doesn't need to be opened */
static int audio_open
(void)
{
long pvbuf[2];
long buflen;
pvbuf[0] = AL_OUTPUT_RATE;
pvbuf[1] = samp_rate;
buflen = 2;
ALsetparams(AL_DEFAULT_DEVICE, pvbuf, buflen);
alconf = ALnewconfig();
ALsetwidth(alconf, AL_SAMPLE_16);
ALsetchannels(alconf, AL_MONO);
alprt = ALopenport("say", "w", alconf);
if (alprt == NULL)
{
fprintf(stderr, "cannot open audio port\n");
ALfreeconfig(alconf);
return 1;
}
return 0;
}
/* sgi system */
int
audio_init(int argc, char **argv)
{
argc = getargs("Sun Audio",argc, argv,
/* Really should support sample rate ... */
NULL);
if (help_only)
return argc;
audio_open();
return argc;
}
void
audio_term(void)
{
/* on sgi systems, wait for port to complete */
while (ALgetfilled(alprt) != 0)
{
sleep(1);
}
ALcloseport(alprt);
}
void
audio_play(int n, short *data)
{
ALwritesamps(alprt, (void *) data, (long) n);
}

View File

@ -1,311 +0,0 @@
/*
Copyright (c) 1994, 2002 Nick Ing-Simmons. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#include <config.h>
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/filio.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <signal.h>
#include <stropts.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_IOCCOM_H
#include <sys/ioccom.h>
#endif
#ifdef HAVE_SYS_AUDIOIO_H
#include <sys/audioio.h>
#endif
#ifdef HAVE_SUN_AUDIOIO_H
#include <sun/audioio.h>
#endif
#include "l2u.h"
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 8000
long samp_rate = SAMP_RATE;
/* Audio Parameters */
int Verbose = 0; /* verbose messages */
int Wait = 1; /* Should we hang waiting for device ? */
static int async = 1;
static audio_info_t dev_info; /* audio header for device */
#ifdef AUDIO_DEV_AMD
static int dev_kind = AUDIO_DEV_AMD;
#endif
static int dev_fd = -1; /* file descriptor for audio device */
char *dev_file = "/dev/audio";
char *Ifile; /* current filename */
static RETSIGTYPE audio_catch(int);
static RETSIGTYPE
audio_catch(sig)
int sig;
{
fprintf(stderr, "signal\n");
}
static int audio_open
(void)
{
/* Try it quickly, first */
dev_fd = open(dev_file, O_WRONLY | O_NDELAY);
if ((dev_fd < 0) && (errno == EBUSY))
{
if (!Wait)
{
if (Verbose)
fprintf(stderr, "%s: %s is busy\n", program, dev_file);
exit(1);
}
if (Verbose)
{
fprintf(stderr, "%s: waiting for %s...", program, dev_file);
(void) fflush(stderr);
}
/* Now hang until it's open */
dev_fd = open(dev_file, O_WRONLY);
if (Verbose)
fprintf(stderr, "%s\n", (dev_fd < 0) ? "" : "open");
}
else if (dev_fd >= 0)
{
int flags = fcntl(dev_fd, F_GETFL, NULL);
if (flags >= 0)
fcntl(dev_fd, F_SETFL, flags & ~O_NDELAY);
else
perror("fcntl - F_GETFL");
}
if (dev_fd < 0)
{
fprintf(stderr, "%s: error opening ", program);
perror(dev_file);
return 0;
}
else
{
#ifdef AUDIO_DEV_AMD
/* Get the device output encoding configuration */
if (ioctl(dev_fd, AUDIO_GETDEV, &dev_kind))
{
/* Old releases of SunOs don't support the ioctl,
but can only be run on old machines which have AMD device...
*/
dev_kind = AUDIO_DEV_AMD;
}
#endif
if (ioctl(dev_fd, AUDIO_GETINFO, &dev_info) != 0)
{
perror(dev_file);
return 0;
}
}
return 1;
}
int
audio_init(argc, argv)
int argc;
char *argv[];
{
int rate_set = 0;
int use_linear = 0;
int use_audio = 1;
double gain = -1.0;
int headphone = 2;
int speaker = 2;
argc = getargs("Sun Audio",argc, argv,
"g", "%lg", &gain, "Gain 0 .. 0.1",
"r", "%d", &rate_set, "Sample rate",
"h", NULL, &headphone, "Headphones",
"s", NULL, &speaker, "Speaker",
"W", NULL, &Wait, "Wait till idle",
"a", NULL, &use_audio, "Use audio",
"L", NULL, &use_linear,"Force linear",
NULL);
if (help_only)
return argc;
if (rate_set)
{
samp_rate = rate_set;
}
if (use_audio && audio_open())
{
if (!rate_set)
samp_rate = dev_info.play.sample_rate;
if (rate_set || use_linear)
{
dev_info.play.sample_rate = samp_rate;
#ifdef AUDIO_ENCODING_LINEAR
if (samp_rate > 8000 || use_linear)
{
dev_info.play.encoding = AUDIO_ENCODING_LINEAR;
dev_info.play.precision = 16;
}
#endif
if (ioctl(dev_fd, AUDIO_SETINFO, &dev_info) != 0)
{
perror(dev_file);
close(dev_fd);
dev_fd = -1;
}
}
}
if (dev_fd >= 0)
{
if (gain >= 0.0)
{
dev_info.play.gain = (unsigned) (AUDIO_MAX_GAIN * gain);
if (ioctl(dev_fd, AUDIO_SETINFO, &dev_info) != 0)
perror("gain");
}
if (speaker != 2 || headphone != 2)
{
if (headphone != 2)
{
if (headphone)
dev_info.play.port |= AUDIO_HEADPHONE;
else
dev_info.play.port &= ~AUDIO_HEADPHONE;
}
if (speaker != 2)
{
if (speaker)
dev_info.play.port |= AUDIO_SPEAKER;
else
dev_info.play.port &= ~AUDIO_SPEAKER;
}
if (ioctl(dev_fd, AUDIO_SETINFO, &dev_info) != 0)
perror("port");
}
if (async)
{
int flag = 1;
/* May need to use streams calls to send a SIGPOLL when write
buffer is no longer full and use non-blocking writes, and
manipluate our own buffer of unwritten data.
However, at present just use FIOASYNC which means write
returns as soon as it can queue the data (I think).
*/
signal(SIGIO, audio_catch);
ioctl(dev_fd, FIOASYNC, &flag);
}
}
return argc;
}
void
audio_term()
{
/* Close audio system */
if (dev_fd >= 0)
{
ioctl(dev_fd, AUDIO_DRAIN, 0);
close(dev_fd);
dev_fd = -1;
if (async)
signal(SIGPOLL, SIG_DFL);
}
}
void
audio_play(n, data)
int n;
short *data;
{
if (n > 0 && dev_fd >= 0)
{
#ifdef AUDIO_ENCODING_LINEAR
if (dev_info.play.encoding == AUDIO_ENCODING_LINEAR)
{
unsigned size = n * sizeof(short);
if (write(dev_fd, data, n * sizeof(short)) != size)
perror("write");
}
else
#endif
if (dev_info.play.encoding == AUDIO_ENCODING_ULAW)
{
unsigned char *plabuf = (unsigned char *) malloc(n);
if (plabuf)
{
int w;
unsigned char *p = plabuf;
unsigned char *e = p + n;
while (p < e)
{
*p++ = short2ulaw(*data++);
}
p = plabuf;
while ((w = write(dev_fd, p, n)) != n)
{
if (w == -1)
{
fprintf(stderr, "%d,%s:%d\n", errno, __FILE__, __LINE__);
perror("audio");
abort();
}
else
{
fprintf(stderr, "Writing %u, only wrote %u\n", n, w);
p += w;
n -= w;
}
}
free(plabuf);
}
else
{
fprintf(stderr, "%s : No memory for ulaw data\n", program);
}
}
}
}

View File

@ -1,425 +0,0 @@
#include <config.h>
/*****************************************************************/
/*****************************************************************/
/*** ***/
/*** ***/
/*** Play out a 20kHz file on the SPARC ***/
/*** ***/
/*** ***/
/*** H.F. Silverman 1/4/91 ***/
/*** Modified: H.F. Silverman 1/16/91 for amax parameter ***/
/*** Modified: A. Smith 2/14/91 for 8kHz for klatt synth ***/
/*** ***/
/*** Called: hplay(n,volume,amax,a) ***/
/*** ***/
/*** int n -- No. of 8kHz pts. ***/
/*** int device -- 0 -> speaker, 1 -> Jack ***/
/*** ***/
/*** ***/
/*****************************************************************/
/*****************************************************************/
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/filio.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <signal.h>
#include <stropts.h>
#include <sys/ioctl.h>
#include <multimedia/libaudio.h>
#include <multimedia/audio_device.h>
#ifndef __svr4__
#include <multimedia/ulaw2linear.h>
#endif
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 8000
long samp_rate = SAMP_RATE;
/* Audio Parameters */
int Verbose = FALSE;
/* verbose messages */
int Immediate = FALSE;
/* Should we hang waiting for device ? */
static int async = TRUE;
static Audio_hdr dev_header;
/* audio header for device */
static int dev_fd = -1;
/* file descriptor for audio device */
char *dev_file = "/dev/audio";
static Audio_hdr ulaw_header;
/* audio header for file */
static int ulaw_fd = -1;
/* file descriptor for .au ulaw file */
static char *ulaw_file = NULL;
static int linear_fd = -1;
#ifdef AUDIO_DEV_AMD
static int dev_kind = AUDIO_DEV_AMD;
#endif
/* file descriptor for 16 bit linear file */
static char *linear_file = NULL;
char *prog = "hplay";
char *Ifile; /* current filename */
static RETSIGTYPE audio_catch(int);
static RETSIGTYPE
audio_catch(sig)
int sig;
{
fprintf(stderr, "signal\n");
}
static int audio_open
(void)
{
/* Try it quickly, first */
dev_fd = open(dev_file, O_WRONLY | O_NDELAY);
if ((dev_fd < 0) && (errno == EBUSY))
{
if (Immediate)
{
fprintf(stderr, "%s: %s is busy\n", prog, dev_file);
return 0;
}
if (Verbose)
{
fprintf(stderr, "%s: waiting for %s...", prog, dev_file);
(void) fflush(stderr);
}
/* Now hang until it's open */
dev_fd = open(dev_file, O_WRONLY);
if (Verbose)
fprintf(stderr, "%s\n", (dev_fd < 0) ? "" : "open");
}
else
{
int flags = fcntl(dev_fd, F_GETFL, NULL);
if (flags >= 0)
fcntl(dev_fd, F_SETFL, flags & ~O_NDELAY);
}
if (dev_fd < 0)
{
fprintf(stderr, "%s: error opening ", prog);
perror(dev_file);
return 0;
}
else
{
#ifdef AUDIO_DEV_AMD
/* Get the device output encoding configuration */
if (ioctl(dev_fd, AUDIO_GETDEV, &dev_kind))
{
/* Old releases of SunOs don't support the ioctl,
but can only be run on old machines which have AMD device...
*/
dev_kind = AUDIO_DEV_AMD;
}
#endif
if (audio_get_play_config(dev_fd, &dev_header) != AUDIO_SUCCESS)
{
fprintf(stderr, "%s: %s is not an audio device\n", prog, dev_file);
close(dev_fd);
dev_fd = -1;
return 0;
}
}
return 1;
}
int
audio_init(argc, argv)
int argc;
char *argv[];
{
int rate_set = 0;
int use_linear = 0;
int use_audio = 1;
double gain = -1.0;
int headphone = 2;
int speaker = 2;
prog = argv[0];
argc = getargs("Old Sun (demo/SOUND)",argc, argv,
"g", "%lg", &gain, "Gain 0 .. 1.0",
"r", "%d", &rate_set, "Sample rate",
"h", NULL, &headphone, "Headphones",
"s", NULL, &speaker, "Speaker",
"a", NULL, &use_audio, "Audio enable",
"L", NULL, &use_linear, "Force linear",
"u", "", &ulaw_file, "Sun .au file",
"l", "", &linear_file, "Raw linear file",
NULL);
if (help_only)
return argc;
if (ulaw_file)
{
if (strcmp(ulaw_file, "-") == 0)
{
ulaw_fd = 1; /* stdout */
}
else
{
ulaw_fd = open(ulaw_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (ulaw_fd < 0)
perror(ulaw_file);
}
}
if (linear_file)
{
if (strcmp(linear_file, "-") == 0)
{
linear_fd = 1 /* stdout */ ;
}
else
{
linear_fd = open(linear_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (linear_fd < 0)
perror(linear_file);
}
}
if (rate_set)
{
samp_rate = rate_set;
}
if (use_audio && audio_open())
{
if (!rate_set)
samp_rate = dev_header.sample_rate;
if (rate_set || use_linear)
{
dev_header.sample_rate = samp_rate;
if (samp_rate > 8000 || use_linear)
{
dev_header.encoding = AUDIO_ENCODING_LINEAR;
dev_header.bytes_per_unit = 2;
}
if (audio_set_play_config(dev_fd, &dev_header) != AUDIO_SUCCESS)
{
fprintf(stderr, "%s : %s cannot accept sample rate of %ldHz\n",
prog, dev_file, samp_rate);
close(dev_fd);
dev_fd = -1;
}
}
}
if (dev_fd >= 0)
{
int myport = 0;
if (gain >= 0.0)
{
int err = audio_set_play_gain(dev_fd, &gain);
if (err != AUDIO_SUCCESS)
{
fprintf(stderr, "%s: could not set output volume for %s\n", prog, dev_file);
}
}
if (headphone != 2)
{
if (headphone)
myport |= AUDIO_HEADPHONE;
else
myport &= ~AUDIO_HEADPHONE;
}
if (speaker != 2)
{
if (speaker)
myport |= AUDIO_SPEAKER;
else
myport &= ~AUDIO_SPEAKER;
}
if (myport != 0)
audio_set_play_port(dev_fd, &myport);
if (async)
{
int flag = 1;
/* May need to use streams calls to send a SIGPOLL when write
buffer is no longer full and use non-blocking writes, and
manipluate our own buffer of unwritten data.
However, at present just use FIOASYNC which means write
returns as soon as it can queue the data (I think).
*/
signal(SIGIO, audio_catch);
ioctl(dev_fd, FIOASYNC, &flag);
}
}
if (ulaw_fd >= 0)
{
ulaw_header.sample_rate = samp_rate;
if (samp_rate > 8000)
{
ulaw_header.encoding = AUDIO_ENCODING_LINEAR;
ulaw_header.bytes_per_unit = 2;
}
else
{
ulaw_header.encoding = AUDIO_ENCODING_ULAW;
ulaw_header.bytes_per_unit = 1;
}
ulaw_header.samples_per_unit = 1;
ulaw_header.channels = 1;
ulaw_header.data_size = AUDIO_UNKNOWN_SIZE;
/* Write header - note that data_size is unknown at this stage,
so we set it to AUDIO_UNKNOWN_SIZE (AFEB);
if all goes well we will lseek back and do this again
in audio_term()
*/
audio_write_filehdr(ulaw_fd, &ulaw_header, NULL, 0);
/* reset the header info, so we can simply add to it */
ulaw_header.data_size = 0;
}
return argc;
}
void
audio_term()
{
/* Close audio system */
if (dev_fd >= 0)
{
audio_drain(dev_fd, FALSE);
close(dev_fd);
dev_fd = -1;
if (async)
signal(SIGPOLL, SIG_DFL);
}
/* Finish ulaw file */
if (ulaw_fd >= 0)
{
off_t here = lseek(ulaw_fd, 0L, SEEK_CUR);
if (here >= 0)
{
/* can seek this file - truncate it */
ftruncate(ulaw_fd, here);
/* Now go back and overwite header with actual size */
if (lseek(ulaw_fd, 0L, SEEK_SET) == 0)
{
audio_write_filehdr(ulaw_fd, &ulaw_header, NULL, 0);
}
}
close(ulaw_fd);
ulaw_fd = -1;
}
/* Finish linear file */
if (linear_fd >= 0)
{
ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR));
close(linear_fd);
linear_fd = -1;
}
}
void
audio_play(n, data)
int n;
short *data;
{
if (n > 0)
{
if (linear_fd >= 0)
{
unsigned size = n * sizeof(short);
if (write(linear_fd, data, n * sizeof(short)) != size)
perror("write");
}
if (dev_fd >= 0 && dev_header.encoding == AUDIO_ENCODING_LINEAR)
{
unsigned size = n * sizeof(short);
if (write(dev_fd, data, n * sizeof(short)) != size)
perror("write");
}
if (ulaw_fd >= 0 && ulaw_header.encoding == AUDIO_ENCODING_LINEAR)
{
unsigned size = n * sizeof(short);
if (write(ulaw_fd, data, n * sizeof(short)) != size)
perror("write");
else
ulaw_header.data_size += size;
}
if ((dev_fd >= 0 && dev_header.encoding == AUDIO_ENCODING_ULAW) ||
(ulaw_fd >= 0 && ulaw_header.encoding == AUDIO_ENCODING_ULAW))
{
unsigned char *plabuf = (unsigned char *) malloc(n);
if (plabuf)
{
int w;
unsigned char *p = plabuf;
unsigned char *e = p + n;
while (p < e)
{
*p++ = audio_s2u(*data++);
}
if (dev_fd >= 0 && dev_header.encoding == AUDIO_ENCODING_ULAW)
{
p = plabuf;
while ((w = write(dev_fd, p, n)) != n)
{
if (w == -1)
{
fprintf(stderr, "%d,%s:%d\n", errno, __FILE__, __LINE__);
perror("audio");
abort();
}
else
{
fprintf(stderr, "Writing %u, only wrote %u\n", n, w);
p += w;
n -= w;
}
}
}
if (ulaw_fd >= 0 && ulaw_header.encoding == AUDIO_ENCODING_ULAW)
{
if (write(ulaw_fd, plabuf, n) != n)
perror(ulaw_file);
else
ulaw_header.data_size += n;
}
free(plabuf);
}
else
{
fprintf(stderr, "%s : No memory for ulaw data\n", prog);
}
}
}
}

View File

@ -1,317 +0,0 @@
/*
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
win_audio.c
Functions to play sound on the Win32 audio driver (Win 95 or Win NT).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#ifdef __MINGW32__
#include "config/mmsystem.h"
#endif
#include "config.h"
#include "hplay.h"
#include "getargs.h"
typedef long int32;
static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
static void close_output(void);
static void output_data(int32 *buf, int32 count);
static void flush_output(void);
static void purge_output(void);
/* export the playback mode */
#define dpm win32_play_mode
#define PE_MONO 1
#define PE_SIGNED 2
#define PE_16BIT 4
#define PE_ULAW 8
#define PE_BYTESWAP 16
#define DEFAULT_RATE 8000
typedef struct
{
int32 rate;
int32 encoding;
int32 extra_param[1];
} PlayMode;
long samp_rate = DEFAULT_RATE;
int
ftruncate(int fd,long size)
{
return 0;
}
PlayMode dpm = {
DEFAULT_RATE, PE_16BIT|PE_SIGNED|PE_MONO,
{16},
};
/* Max audio blocks waiting to be played */
static LPHWAVEOUT dev;
static int nBlocks;
CRITICAL_SECTION critSect;
static void wait (void)
{
while (nBlocks)
Sleep (0);
}
static int play (void *mem, int len)
{
HGLOBAL hg;
LPWAVEHDR wh;
MMRESULT res;
while (nBlocks >= dpm.extra_param[0])
Sleep (0);
hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR));
if (!hg)
{
fprintf(stderr, "GlobalAlloc failed!");
return FALSE;
}
wh = GlobalLock (hg);
wh->dwBufferLength = len;
wh->lpData = mem;
res = waveOutPrepareHeader (dev, wh, sizeof (WAVEHDR));
if (res)
{
fprintf(stderr, "waveOutPrepareHeader: %d", res);
GlobalUnlock (hg);
GlobalFree (hg);
return TRUE;
}
res = waveOutWrite (dev, wh, sizeof (WAVEHDR));
if (res)
{
fprintf(stderr, "waveOutWrite: %d", res);
GlobalUnlock (hg);
GlobalFree (hg);
return TRUE;
}
EnterCriticalSection (&critSect);
nBlocks++;
LeaveCriticalSection (&critSect);
return FALSE;
}
#pragma argsused
static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg,
DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
WAVEHDR *wh;
HGLOBAL hg;
if (uMsg == WOM_DONE)
{
EnterCriticalSection (&critSect);
wh = (WAVEHDR *)dwParam1;
waveOutUnprepareHeader (dev, wh, sizeof (WAVEHDR));
hg = GlobalHandle (wh->lpData);
GlobalUnlock (hg);
GlobalFree (hg);
hg = GlobalHandle (wh);
GlobalUnlock (hg);
GlobalFree (hg);
nBlocks--;
LeaveCriticalSection (&critSect);
}
}
static int open_output (void)
{
int i, j, mono, eight_bit, warnings = 0;
PCMWAVEFORMAT pcm;
MMRESULT res;
/* Check if there is at least one audio device */
if (!waveOutGetNumDevs ())
{
fprintf(stderr, "No audio devices present!");
return -1;
}
/* They can't mean these */
dpm.encoding &= ~(PE_ULAW|PE_BYTESWAP);
if (dpm.encoding & PE_16BIT)
dpm.encoding |= PE_SIGNED;
else
dpm.encoding &= ~PE_SIGNED;
mono = (dpm.encoding & PE_MONO);
eight_bit = !(dpm.encoding & PE_16BIT);
pcm.wf.wFormatTag = WAVE_FORMAT_PCM;
pcm.wf.nChannels = mono ? 1 : 2;
pcm.wf.nSamplesPerSec = i = dpm.rate;
j = 1;
if (!mono)
{
i *= 2;
j *= 2;
}
if (!eight_bit)
{
i *= 2;
j *= 2;
}
pcm.wf.nAvgBytesPerSec = i;
pcm.wf.nBlockAlign = j;
pcm.wBitsPerSample = eight_bit ? 8 : 16;
res = waveOutOpen (NULL, 0, (LPWAVEFORMAT)&pcm, NULL, 0, WAVE_FORMAT_QUERY);
if (res)
{
fprintf(stderr, "Format not supported!\n");
return -1;
}
res = waveOutOpen (&dev, 0, (LPWAVEFORMAT)&pcm, (DWORD)wave_callback, 0, CALLBACK_FUNCTION);
if (res)
{
fprintf(stderr, "Can't open audio device");
return -1;
}
nBlocks = 0;
return warnings;
}
void
conv8bit(short *lp, int c)
{
unsigned char *cp = (unsigned char *) lp;
short l;
while (c--)
{
short l = (*lp++) >> (16-8);
if (l > 127) l = 127;
else if (l < -128) l = -128;
*cp++ = 0x80 ^ ((unsigned char) l);
}
}
void
audio_play(int count, short *buf)
{
int len = count;
HGLOBAL hg;
void *b;
if (!(dpm.encoding & PE_MONO)) /* Stereo sample */
{
count *= 2;
len *= 2;
}
if (dpm.encoding & PE_16BIT)
len *= 2;
hg = GlobalAlloc (GMEM_MOVEABLE, len);
if (!hg)
{
fprintf(stderr, "GlobalAlloc failed!");
return;
}
b = GlobalLock (hg);
if (!(dpm.encoding & PE_16BIT))
/* Convert to 8-bit unsigned. */
conv8bit(buf, count);
#ifdef __MINGW32__
memcpy(b, buf, len);
#else
CopyMemory(b, buf, len);
#endif
if (play (b, len))
{
GlobalUnlock (hg);
GlobalFree (hg);
}
}
static void close_output (void)
{
wait ();
waveOutClose (dev);
}
static void flush_output (void)
{
wait ();
}
static void purge_output (void)
{
waveOutReset (dev);
wait ();
}
int use_audio = 1;
int
audio_init(argc, argv)
int argc;
char *argv[];
{
InitializeCriticalSection(&critSect);
argc = getargs("Win32 waveOut",argc, argv,
"a", NULL, &use_audio, "Use audio",
#if 0
"g", "%lg", &gain, "Gain 0 .. 0.1",
"r", "%d", &rate_set, "Sample rate",
"h", NULL, &headphone, "Headphones",
"s", NULL, &speaker, "Speaker",
"W", NULL, &Wait, "Wait till idle",
"L", NULL, &use_linear,"Force linear",
#endif
NULL);
if (help_only)
return argc;
open_output();
return argc;
}
void
audio_term()
{
close_output();
DeleteCriticalSection(&critSect);
}

View File

@ -0,0 +1,21 @@
MODULE := src/emucore/rsynth
MODULE_OBJS := \
src/emucore/rsynth/charset.o \
src/emucore/rsynth/darray.o \
src/emucore/rsynth/deutsch.o \
src/emucore/rsynth/elements.o \
src/emucore/rsynth/english.o \
src/emucore/rsynth/holmes.o \
src/emucore/rsynth/opsynth.o \
src/emucore/rsynth/phones.o \
src/emucore/rsynth/phtoelm.o \
src/emucore/rsynth/say.o \
src/emucore/rsynth/text.o \
src/emucore/rsynth/trie.o
MODULE_DIRS += \
src/emucore/rsynth
# Include common rules
include $(srcdir)/common.rules