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
32 #include "audio_out.h"
33 #include "audio_out_internal.h"
35 typedef struct aif_instance_s {
43 static uint8_t aif_header[] = {
44 'F', 'O', 'R', 'M', 0xff, 0xff, 0xff, 0xfe, 'A', 'I', 'F', 'F',
45 'C', 'O', 'M', 'M', 0, 0, 0, 18,
46 0, 2, 0x3f, 0xff, 0xff, 0xf4, 0, 16, 0x40, 0x0e, -1, -1, 0, 0, 0, 0, 0, 0,
47 'S', 'S', 'N', 'D', 0xff, 0xff, 0xff, 0xd8, 0, 0, 0, 0, 0, 0, 0, 0
50 int aif_setup (ao_instance_t * _instance, int sample_rate, int * flags,
51 sample_t * level, sample_t * bias)
53 aif_instance_t * instance = (aif_instance_t *) _instance;
55 if ((instance->set_params == 0) && (instance->sample_rate != sample_rate))
57 instance->sample_rate = sample_rate;
59 *flags = instance->flags;
66 static void store4 (uint8_t * buf, int value)
74 static void store2 (uint8_t * buf, int16_t value)
80 int aif_play (ao_instance_t * _instance, int flags, sample_t * _samples)
82 aif_instance_t * instance = (aif_instance_t *) _instance;
83 int16_t int16_samples[256*2];
86 float samples[256 * 2];
89 for (i = 0; i < 256 * 2; i++)
90 samples[i] = _samples[i];
92 float * samples = _samples;
95 if (instance->set_params) {
96 instance->set_params = 0;
97 store2 (aif_header + 30, instance->sample_rate);
98 fwrite (aif_header, sizeof (aif_header), 1, stdout);
101 float2s16_2 (samples, int16_samples);
102 s16_BE (int16_samples, 2);
103 fwrite (int16_samples, 256 * sizeof (int16_t) * 2, 1, stdout);
105 instance->size += 256 * sizeof (int16_t) * 2;
110 void aif_close (ao_instance_t * _instance)
112 aif_instance_t * instance = (aif_instance_t *) _instance;
114 if (fseek (stdout, 0, SEEK_SET) < 0)
117 store4 (aif_header + 4, instance->size + 46);
118 store4 (aif_header + 22, instance->size / 4);
119 store4 (aif_header + 42, instance->size + 8);
120 fwrite (aif_header, sizeof (aif_header), 1, stdout);
123 ao_instance_t * aif_open (int flags)
125 aif_instance_t * instance;
127 instance = malloc (sizeof (aif_instance_t));
128 if (instance == NULL)
131 instance->ao.setup = aif_setup;
132 instance->ao.play = aif_play;
133 instance->ao.close = aif_close;
135 instance->sample_rate = 0;
136 instance->set_params = 1;
137 instance->flags = flags;
140 return (ao_instance_t *) instance;
143 ao_instance_t * ao_aif_open (void)
145 return aif_open (A52_STEREO);
148 ao_instance_t * ao_aifdolby_open (void)
150 return aif_open (A52_DOLBY);