rdpsnd_sgi.c revision d65680efa46fa49e8bf14e67b29b782510ff934c
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* -*- c-basic-offset: 8 -*-
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rdesktop: A Remote Desktop Protocol client.
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync Sound Channel Process Functions - SGI/IRIX
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Copyright (C) Matthew Chapman 2003-2007
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Copyright (C) Jeremy Meng void.foo@gmail.com 2004, 2005
c58f1213e628a545081c70e26c6b67a841cff880vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync This program is free software; you can redistribute it and/or modify
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync it under the terms of the GNU General Public License as published by
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync the Free Software Foundation; either version 2 of the License, or
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync (at your option) any later version.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync This program is distributed in the hope that it will be useful,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GNU General Public License for more details.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync You should have received a copy of the GNU General Public License
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync along with this program; if not, write to the Free Software
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Sun GPL Disclaimer: For the avoidance of doubt, except that if any license choice
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * other than GPL or LGPL is available it will apply instead, Sun elects to use only
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * the General Public License version 2 (GPLv2) at this time for any software where
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * a choice of GPL license versions is made available with the language indicating
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * that GPLv2 or any later version may be used, or where a choice of which version
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * of the GPL is applied is otherwise unspecified.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "rdesktop.h"
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <errno.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <dmedia/audio.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* #define IRIX_DEBUG 1 */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync#define IRIX_MAX_VOL 65535
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncALconfig audioconfig;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncALport output_port;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic int g_snd_rate;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic int width = AL_SAMPLE_16;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncstatic char *sgi_output_device = NULL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncdouble min_volume, max_volume, volume_range;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncint resource, maxFillable;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncint combinedFrameSize;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncvoid sgi_play(void);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncvoid
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncsgi_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* We need to be called rather often... */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (output_port != (ALport) 0 && !rdpsnd_queue_empty())
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync FD_SET(0, wfds);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncvoid
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncsgi_check_fds(fd_set * rfds, fd_set * wfds)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (output_port == (ALport) 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
376b92d26cc4fad78e813cf33afcc0784adc9b19vboxsync if (!rdpsnd_queue_empty())
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync sgi_play();
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync}
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsyncRD_BOOL
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsyncsgi_open(void)
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync{
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync ALparamInfo pinfo;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync static int warned = 0;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync#if (defined(IRIX_DEBUG))
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync fprintf(stderr, "sgi_open: begin\n");
376b92d26cc4fad78e813cf33afcc0784adc9b19vboxsync#endif
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync if (!warned && sgi_output_device)
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync {
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync warning("device-options not supported for libao-driver\n");
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync warned = 1;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_open: alGetParamInfo failed: %s\n",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync alGetErrorString(oserror()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync min_volume = alFixedToDouble(pinfo.min.ll);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync max_volume = alFixedToDouble(pinfo.max.ll);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync volume_range = (max_volume - min_volume);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if (defined(IRIX_DEBUG))
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync fprintf(stderr, "sgi_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync min_volume, max_volume, volume_range);
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync audioconfig = alNewConfig();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (audioconfig == (ALconfig) 0)
f409459bdd4c15cdb8d7fb6c6d54338cce9ac814vboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_open: alNewConfig failed: %s\n", alGetErrorString(oserror()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return False;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync output_port = alOpenPort("rdpsnd", "w", 0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (output_port == (ALport) 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_open: alOpenPort failed: %s\n", alGetErrorString(oserror()));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return False;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if (defined(IRIX_DEBUG))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_open: returning\n");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return True;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncvoid
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncsgi_close(void)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Ack all remaining packets */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if (defined(IRIX_DEBUG))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_close: begin\n");
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#endif
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync while (!rdpsnd_queue_empty())
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync rdpsnd_queue_next(0);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync alDiscardFrames(output_port, 0);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync alClosePort(output_port);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync output_port = (ALport) 0;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync alFreeConfig(audioconfig);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#if (defined(IRIX_DEBUG))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync fprintf(stderr, "sgi_close: returning\n");
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#endif
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync}
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsyncRD_BOOL
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsyncsgi_format_supported(RD_WAVEFORMATEX * pwfx)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync{
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync return False;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync return False;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync return False;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync return True;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync}
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsyncRD_BOOL
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsyncsgi_set_format(RD_WAVEFORMATEX * pwfx)
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync{
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync int channels;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync int frameSize, channelCount;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync ALpv params;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync#if (defined(IRIX_DEBUG))
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync fprintf(stderr, "sgi_set_format: init...\n");
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync#endif
9cb702c3a5fd2287c57c7c1e98a61ba9e357b4devboxsync
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync if (pwfx->wBitsPerSample == 8)
6fe1329154975472e055284198df7fa8e64dee3avboxsync width = AL_SAMPLE_8;
6fe1329154975472e055284198df7fa8e64dee3avboxsync else if (pwfx->wBitsPerSample == 16)
6fe1329154975472e055284198df7fa8e64dee3avboxsync width = AL_SAMPLE_16;
6fe1329154975472e055284198df7fa8e64dee3avboxsync
6fe1329154975472e055284198df7fa8e64dee3avboxsync /* Limited support to configure an opened audio port in IRIX. The
6fe1329154975472e055284198df7fa8e64dee3avboxsync number of channels is a static setting and can not be changed after
6fe1329154975472e055284198df7fa8e64dee3avboxsync a port is opened. So if the number of channels remains the same, we
6fe1329154975472e055284198df7fa8e64dee3avboxsync can configure other settings; otherwise we have to reopen the audio
6fe1329154975472e055284198df7fa8e64dee3avboxsync port, using same config. */
6fe1329154975472e055284198df7fa8e64dee3avboxsync
6fe1329154975472e055284198df7fa8e64dee3avboxsync channels = pwfx->nChannels;
6fe1329154975472e055284198df7fa8e64dee3avboxsync g_snd_rate = pwfx->nSamplesPerSec;
6fe1329154975472e055284198df7fa8e64dee3avboxsync
6fe1329154975472e055284198df7fa8e64dee3avboxsync alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
6fe1329154975472e055284198df7fa8e64dee3avboxsync alSetWidth(audioconfig, width);
6fe1329154975472e055284198df7fa8e64dee3avboxsync if (channels != alGetChannels(audioconfig))
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync alClosePort(output_port);
6fe1329154975472e055284198df7fa8e64dee3avboxsync alSetChannels(audioconfig, channels);
6fe1329154975472e055284198df7fa8e64dee3avboxsync output_port = alOpenPort("rdpsnd", "w", audioconfig);
6fe1329154975472e055284198df7fa8e64dee3avboxsync
6fe1329154975472e055284198df7fa8e64dee3avboxsync if (output_port == (ALport) 0)
6fe1329154975472e055284198df7fa8e64dee3avboxsync {
6fe1329154975472e055284198df7fa8e64dee3avboxsync fprintf(stderr, "sgi_set_format: alOpenPort failed: %s\n",
6fe1329154975472e055284198df7fa8e64dee3avboxsync alGetErrorString(oserror()));
6fe1329154975472e055284198df7fa8e64dee3avboxsync return False;
6fe1329154975472e055284198df7fa8e64dee3avboxsync }
6fe1329154975472e055284198df7fa8e64dee3avboxsync
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync resource = alGetResource(output_port);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync maxFillable = alGetFillable(output_port);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync channelCount = alGetChannels(audioconfig);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync frameSize = alGetWidth(audioconfig);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (frameSize == 0 || channelCount == 0)
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync fprintf(stderr, "sgi_set_format: bad frameSize or channelCount\n");
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync return False;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync combinedFrameSize = frameSize * channelCount;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync params.param = AL_RATE;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync params.value.ll = (long long) g_snd_rate << 32;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (alSetParams(resource, &params, 1) < 0)
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync alGetErrorString(oserror()));
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync return False;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync if (params.sizeOut < 0)
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync {
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync return False;
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if (defined(IRIX_DEBUG))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fprintf(stderr, "sgi_set_format: returning...\n");
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return True;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
ae16af2d7d3c99d359094a7f19f5937efc2e66bdvboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncvoid
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncsgi_volume(uint16 left, uint16 right)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync double gainleft, gainright;
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync ALpv pv[1];
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync ALfixed gain[8];
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync#if (defined(IRIX_DEBUG))
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync fprintf(stderr, "sgi_volume: begin\n");
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync fprintf(stderr, "left='%d', right='%d'\n", left, right);
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync#endif
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync gainleft = (double) left / IRIX_MAX_VOL;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync gainright = (double) right / IRIX_MAX_VOL;
8b7ee9f7ebabcdbf40fececa0d6321d97d5143d8vboxsync
8b7ee9f7ebabcdbf40fececa0d6321d97d5143d8vboxsync gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync pv[0].param = AL_GAIN;
31a693ce9a8a9ebbecdcea9f24ce7f912aef4cd1vboxsync pv[0].value.ptr = gain;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync pv[0].sizeIn = 8;
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync fprintf(stderr, "sgi_volume: alSetParams failed: %s\n",
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync alGetErrorString(oserror()));
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync return;
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync }
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync#if (defined(IRIX_DEBUG))
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync fprintf(stderr, "sgi_volume: returning\n");
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsyncvoid
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsyncsgi_play(void)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync{
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync struct audio_packet *packet;
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync ssize_t len;
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync unsigned int i;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync STREAM out;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int gf;
ae16af2d7d3c99d359094a7f19f5937efc2e66bdvboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync while (1)
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync {
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync if (rdpsnd_queue_empty())
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync return;
cdf129515a2b03bc9d122091ce7656d6e6934cc7vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync packet = rdpsnd_queue_current_packet();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync out = &packet->s;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync len = out->end - out->p;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync alWriteFrames(output_port, out->p, len / combinedFrameSize);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync out->p += len;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (out->p == out->end)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync gf = alGetFilled(output_port);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (gf < (4 * maxFillable / 10))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync rdpsnd_queue_next(0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if (defined(IRIX_DEBUG))
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* fprintf(stderr,"Busy playing...\n"); */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync usleep(10);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync return;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncstruct audio_driver *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncsgi_register(char *options)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync static struct audio_driver sgi_driver;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
42aef05f4b27fb393967e581be04be455064c80avboxsync memset(&sgi_driver, 0, sizeof(sgi_driver));
42aef05f4b27fb393967e581be04be455064c80avboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.name = "sgi";
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync sgi_driver.description = "SGI output driver";
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.add_fds = sgi_add_fds;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.check_fds = sgi_check_fds;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync sgi_driver.wave_out_open = sgi_open;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.wave_out_close = sgi_close;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.wave_out_format_supported = sgi_format_supported;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.wave_out_set_format = sgi_set_format;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync sgi_driver.wave_out_volume = sgi_volume;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.need_byteswap_on_be = 1;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_driver.need_resampling = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (options)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync sgi_output_device = xstrdup(options);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync return &sgi_driver;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync