2
audio_alib.c: audio output for HP-UX using alib
4
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
5
see COPYING and AUTHORS files in distribution or http://mpg123.de
6
initially written by Erwan Ducroquet
7
based on source code from HP (Audio SDK)
16
* LDFLAGS=-L/opt/audio/lib \
18
* OBJECTS=decode.o dct64.o \
19
* CFLAGS=-Ae +O3 -DREAL_IS_FLOAT -D_HPUX_SOURCE -DHPUX -I/opt/audio/include \
25
* I don't use the "set_rate" and "set_channels" functions
26
* these are set directly in the "audio_open" function
32
* If you launch mpg123 on a XTerm with sound capabilities, it's OK
33
* Else, you have to set the environment variable "AUDIO" to the name of
34
* an HP Xterm with sound card.
37
/**************************************************************************/
39
#include <sys/types.h>
44
#include <sys/socket.h>
46
#include <netinet/in.h>
47
#include <netinet/tcp.h>
53
#include "Alib.h" /* /opt/audio/include */
54
#include "CUlib.h" /* /opt/audio/include */
60
* int audio_open(struct audio_info_struct *ai);
61
* int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len);
62
* int audio_close(struct audio_info_struct *ai);
66
* int audio_set_rate(struct audio_info_struct *ai);
67
* int audio_set_channels(struct audio_info_struct *ai);
71
/**************************************************************************/
74
* Some things used only for HP Audio
77
static Audio *audioServer = (Audio *) NULL;
78
static struct protoent *tcpProtocolEntry;
81
static void printAudioError(Audio *audio,char *message,int errorCode) {
83
AGetErrorText(audio, errorCode, errorbuff, 131);
84
fprintf ( stderr, "%s: %s\n", message, errorbuff);
86
static long myHandler(Audio *audio,AErrorEvent *err_event) {
87
printAudioError( audio, "Audio error", err_event->error_code );
91
/**************************************************************************/
94
* Set the fn element of ai
95
* Use ai->rate and ai->channels
96
* Doesn't set any volume
99
int audio_open(struct audio_info_struct *ai) {
100
AudioAttributes Attribs;
101
AudioAttrMask AttribsMask;
102
AGainEntry gainEntry[4];
103
SSPlayParams playParams;
105
AErrorHandler prevHandler;
111
{fprintf(stderr,"openAudio: audio already open\n");exit(1);}
113
prevHandler = ASetErrorHandler(myHandler);
116
audioServer = AOpenAudio( server, NULL );
117
if(audioServer==NULL)
118
{fprintf(stderr,"Error: could not open audio\n");exit(1);}
120
ai->fn = socket( AF_INET, SOCK_STREAM, 0 );
122
{fprintf(stderr,"Socket creation failed");exit(1);}
124
Attribs.type = ATSampled;
125
Attribs.attr.sampled_attr.sampling_rate = ai->rate;
126
Attribs.attr.sampled_attr.channels = ai->channels;
127
Attribs.attr.sampled_attr.data_format = ADFLin16;
128
AttribsMask = ASSamplingRateMask | ASChannelsMask | ASDataFormatMask;
130
gainEntry[0].gain = AUnityGain;
131
gainEntry[0].u.o.out_ch = AOCTMono;
132
gainEntry[0].u.o.out_dst = AODTDefaultOutput;
134
playParams.gain_matrix.type = AGMTOutput; /* gain matrix */
135
playParams.gain_matrix.num_entries = 1;
136
playParams.gain_matrix.gain_entries = gainEntry;
137
playParams.play_volume = AUnityGain; /* play volume */
138
playParams.priority = APriorityNormal; /* normal priority */
139
playParams.event_mask = 0; /* don't solicit any events */
141
xid=APlaySStream(audioServer,AttribsMask,&Attribs,
142
&playParams,&audioStream,NULL);
144
status=connect(ai->fn,
145
(struct sockaddr *) &audioStream.tcp_sockaddr,
146
sizeof(struct sockaddr_in) );
147
if(status<0){fprintf(stderr,"Connect failed");exit(1);}
150
tcpProtocolEntry=getprotobyname("tcp");
151
setsockopt(ai->fn,tcpProtocolEntry->p_proto,TCP_NODELAY,&i,sizeof(i));
156
/**************************************************************************/
158
int audio_close(struct audio_info_struct *ai)
161
ASetCloseDownMode( audioServer, AKeepTransactions, NULL );
162
ACloseAudio( audioServer, NULL );
163
audioServer = (Audio *) NULL;
167
/**************************************************************************/
171
* deserv to be inline
174
inline int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
176
return write(ai->fn,buf,len*2);
179
/**************************************************************************/
181
int audio_get_formats(struct audio_info_struct *ai)
183
return AUDIO_FORMAT_SIGNED_16;
186
void audio_queueflush(struct audio_info_struct *ai)
191
/**************************************************************************
192
* T H A T ' S A L L F O L K S
193
**************************************************************************/