3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
7 * See http://liba52.sourceforge.net/ for updates.
9 * a52dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * a52dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/ioctl.h>
33 #include <sys/audioio.h>
37 #include "audio_out.h"
38 #include "audio_out_internal.h"
40 typedef struct solaris_instance_s {
48 int solaris_setup (ao_instance_t * _instance, int sample_rate, int * flags,
49 sample_t * level, sample_t * bias)
51 solaris_instance_t * instance = (solaris_instance_t *) _instance;
53 if ((instance->set_params == 0) && (instance->sample_rate != sample_rate))
55 instance->sample_rate = sample_rate;
57 *flags = instance->flags;
64 int solaris_play (ao_instance_t * _instance, int flags, sample_t * _samples)
66 solaris_instance_t * instance = (solaris_instance_t *) _instance;
67 int16_t int16_samples[256*2];
70 float samples[256 * 2];
73 for (i = 0; i < 256 * 2; i++)
74 samples[i] = _samples[i];
76 float * samples = _samples;
79 if (instance->set_params) {
82 /* Setup our parameters */
83 AUDIO_INITINFO (&info);
84 info.play.sample_rate = instance->sample_rate;
85 info.play.precision = 16;
86 info.play.channels = 2;
87 info.play.encoding = AUDIO_ENCODING_LINEAR;
89 /* Write our configuration */
90 /* An implicit GETINFO is also performed. */
91 if (ioctl (instance->fd, AUDIO_SETINFO, &info) < 0) {
92 perror ("Writing audio config block");
96 if ((info.play.sample_rate != instance->sample_rate) ||
97 (info.play.precision != 16) || (info.play.channels != 2)) {
98 fprintf (stderr, "Wanted %dHz %d bits %d channels\n",
99 instance->sample_rate, 16, 2);
100 fprintf (stderr, "Got %dHz %d bits %d channels\n",
101 info.play.sample_rate, info.play.precision,
106 instance->flags = flags;
107 instance->set_params = 0;
108 } else if ((flags == A52_DOLBY) && (instance->flags == A52_STEREO)) {
109 fprintf (stderr, "Switching from stereo to dolby surround\n");
110 instance->flags = A52_DOLBY;
111 } else if ((flags == A52_STEREO) && (instance->flags == A52_DOLBY)) {
112 fprintf (stderr, "Switching from dolby surround to stereo\n");
113 instance->flags = A52_STEREO;
114 } else if (flags != instance->flags)
117 float2s16_2 (samples, int16_samples);
118 write (instance->fd, int16_samples, 256 * sizeof (int16_t) * 2);
123 void solaris_close (ao_instance_t * _instance)
125 solaris_instance_t * instance = (solaris_instance_t *) _instance;
127 close (instance->fd);
130 ao_instance_t * solaris_open (int flags)
132 solaris_instance_t * instance;
134 instance = malloc (sizeof (solaris_instance_t));
135 if (instance == NULL)
138 instance->ao.setup = solaris_setup;
139 instance->ao.play = solaris_play;
140 instance->ao.close = solaris_close;
142 instance->sample_rate = 0;
143 instance->set_params = 1;
144 instance->flags = flags;
146 instance->fd = open ("/dev/audio", O_WRONLY);
147 if (instance->fd < 0) {
148 fprintf (stderr, "Can not open /dev/audio\n");
153 return (ao_instance_t *) instance;
156 ao_instance_t * ao_solaris_open (void)
158 return solaris_open (A52_STEREO);
161 ao_instance_t * ao_solarisdolby_open (void)
163 return solaris_open (A52_DOLBY);