This is soundhpux.c in view mode; [Download] [Up]
/* * soundhpux.c - Implementation of the HPUX sound device * * Written by * Teemu Rantanen (tvr@cs.hut.fi) * * This file is part of VICE, the Versatile Commodore Emulator. * See README for copyright notice. * * 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., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. * */ #include <fcntl.h> #include <sys/ioctl.h> #include <sys/audio.h> #include "vice.h" #include "sound.h" static int hpux_fd = -1; static int hpux_init(warn_t *w, char *param, int *speed, int *fragsize, int *fragnr, double bufsize) { int st, tmp, i; if (!param) param = "/dev/audio"; /* open device */ hpux_fd = open(param, O_WRONLY, 0777); if (hpux_fd < 0) return 1; /* set 16bit */ st = ioctl(hpux_fd, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_LINEAR16BIT); if (st < 0) goto fail; /* set speed */ st = ioctl(hpux_fd, AUDIO_SET_SAMPLE_RATE, *speed); if (st < 0) goto fail; /* channels */ st = ioctl(hpux_fd, AUDIO_SET_CHANNELS, 1); if (st < 0) goto fail; /* should we use the default? */ st = ioctl(hpux_fd, AUDIO_SET_OUTPUT, AUDIO_OUT_SPEAKER); if (st < 0) goto fail; /* set buffer size */ tmp = (*fragsize)*(*fragnr)*sizeof(SWORD); st = ioctl(hpux_fd, AUDIO_SET_TXBUFSIZE, tmp); if (st < 0) { /* XXX: what are valid buffersizes? */ for (i = 1; i < tmp; i *= 2); tmp = i; st = ioctl(hpux_fd, AUDIO_SET_TXBUFSIZE, tmp); if (st < 0) goto fail; *fragnr = tmp / ((*fragsize)*sizeof(SWORD)); } return 0; fail: close(hpux_fd); hpux_fd = -1; return 1; } static int hpux_write(warn_t *w, SWORD *pbuf, int nr) { int total, i, now; total = nr*sizeof(SWORD); for (i = 0; i < total; i += now) { now = write(hpux_fd, (char *)pbuf + i, total - i); if (now <= 0) return 1; } return 0; } static int hpux_bufferstatus(warn_t *w, int first) { int st; struct audio_status ast; st = ioctl(hpux_fd, AUDIO_GET_STATUS, &ast); if (st < 0) return -1; return ast.transmit_buffer_count / sizeof(SWORD); } static void hpux_close(warn_t *w) { close(hpux_fd); hpux_fd = -1; } static sound_device_t hpux_device = { "hpux", hpux_init, hpux_write, NULL, NULL, hpux_bufferstatus, hpux_close, NULL, NULL }; int sound_init_hpux_device(void) { return sound_register_device(&hpux_device); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.