~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/audio_sgi.c

Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        audio_sgi.c: audio output on sgi boxen
 
3
 
 
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 (as it seems) by Thomas Woerner
 
7
*/
 
8
 
 
9
 
 
10
 
 
11
#include <sys/types.h>
 
12
#include <stdio.h>
 
13
#include <unistd.h>
 
14
#include <fcntl.h>
 
15
#include <stdlib.h>
 
16
 
 
17
/* #include <audio.h> */
 
18
#include <dmedia/audio.h>
 
19
 
 
20
#include "config.h"
 
21
#include "mpg123.h"
 
22
 
 
23
 
 
24
/* Analog output constant */
 
25
static const char analog_output_res_name[] = ".AnalogOut";
 
26
 
 
27
 
 
28
static int audio_set_rate(struct audio_info_struct *ai, ALconfig config)
 
29
{
 
30
  int dev = alGetDevice(config);
 
31
  ALpv params[1];
 
32
  
 
33
  /* Make sure the device is OK */
 
34
  if (dev < 0)
 
35
    {
 
36
      fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror()));
 
37
      return 1;      
 
38
    }
 
39
 
 
40
  params[0].param = AL_OUTPUT_RATE;
 
41
  params[0].value.ll = alDoubleToFixed(ai->rate);
 
42
  
 
43
  if (alSetParams(dev, params,1) < 0)
 
44
    fprintf(stderr,"audio_set_rate : %s\n",alGetErrorString(oserror()));
 
45
  
 
46
  return 0;
 
47
}
 
48
 
 
49
static int audio_set_channels(struct audio_info_struct *ai, ALconfig config)
 
50
{
 
51
  int ret;
 
52
  
 
53
  if(ai->channels == 2)
 
54
    ret = alSetChannels(config, AL_STEREO);
 
55
  else
 
56
    ret = alSetChannels(config, AL_MONO);
 
57
 
 
58
  if (ret < 0)
 
59
    fprintf(stderr,"audio_set_channels : %s\n",alGetErrorString(oserror()));
 
60
  
 
61
  return 0;
 
62
}
 
63
 
 
64
static int audio_set_format(struct audio_info_struct *ai, ALconfig config)
 
65
{
 
66
  if (alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP) < 0)
 
67
    fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
 
68
  
 
69
  if (alSetWidth(config,AL_SAMPLE_16) < 0)
 
70
    fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
 
71
  
 
72
  return 0;
 
73
}
 
74
 
 
75
 
 
76
int audio_open(struct audio_info_struct *ai)
 
77
{
 
78
  int dev = AL_DEFAULT_OUTPUT;
 
79
  ALconfig config = alNewConfig();
 
80
  ALport port = NULL;
 
81
  
 
82
  /* Test for correct completion */
 
83
  if (config == 0) {
 
84
    fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
 
85
    exit(-1);
 
86
  }
 
87
  
 
88
  /* Set port parameters */
 
89
  if(ai->channels == 2)
 
90
    alSetChannels(config, AL_STEREO);
 
91
  else
 
92
    alSetChannels(config, AL_MONO);
 
93
 
 
94
  alSetWidth(config, AL_SAMPLE_16);
 
95
  alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP);
 
96
  alSetQueueSize(config, 131069);
 
97
 
 
98
  /* Setup output device to specified module. If there is no module
 
99
     specified in ai structure, use the default four output */
 
100
  if ((ai->device) != NULL) {
 
101
    
 
102
    char *dev_name;
 
103
    
 
104
    dev_name=malloc((strlen(ai->device) + strlen(analog_output_res_name) + 1) *
 
105
                  sizeof(char));
 
106
    
 
107
    strcpy(dev_name,ai->device);
 
108
    strcat(dev_name,analog_output_res_name);
 
109
    
 
110
    /* Find the asked device resource */
 
111
    dev=alGetResourceByName(AL_SYSTEM,dev_name,AL_DEVICE_TYPE);
 
112
 
 
113
    /* Free allocated space */
 
114
    free(dev_name);
 
115
 
 
116
    if (!dev) {
 
117
      fprintf(stderr,"Invalid audio resource: %s (%s)\n",dev_name,
 
118
            alGetErrorString(oserror()));
 
119
      exit(-1);
 
120
    }
 
121
  }
 
122
  
 
123
  /* Set the device */
 
124
  if (alSetDevice(config,dev) < 0)
 
125
    {
 
126
      fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
 
127
      exit(-1);
 
128
    }
 
129
  
 
130
  /* Open the audio port */
 
131
  port = alOpenPort("mpg123-VSC", "w", config);
 
132
  if(port == NULL) {
 
133
    fprintf(stderr, "Unable to open audio channel: %s\n",
 
134
          alGetErrorString(oserror()));
 
135
    exit(-1);
 
136
  }
 
137
  
 
138
  ai->handle = (void*)port;
 
139
  
 
140
  
 
141
  audio_set_format(ai, config);
 
142
  audio_set_channels(ai, config);
 
143
  audio_set_rate(ai, config);
 
144
    
 
145
 
 
146
  alFreeConfig(config);
 
147
 
 
148
  return 1;
 
149
}
 
150
 
 
151
 
 
152
int audio_get_formats(struct audio_info_struct *ai)
 
153
{
 
154
  return AUDIO_FORMAT_SIGNED_16;
 
155
}
 
156
 
 
157
 
 
158
int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
 
159
{
 
160
  ALport port = (ALport)ai->handle;
 
161
 
 
162
  if(ai->format == AUDIO_FORMAT_SIGNED_8)
 
163
    alWriteFrames(port, buf, len>>1);
 
164
  else
 
165
    alWriteFrames(port, buf, len>>2);
 
166
 
 
167
  return len;
 
168
}
 
169
 
 
170
int audio_close(struct audio_info_struct *ai)
 
171
{
 
172
  ALport port = (ALport)ai->handle;
 
173
 
 
174
  if (port) {
 
175
    while(alGetFilled(port) > 0)
 
176
      sginap(1);  
 
177
    alClosePort(port);
 
178
    ai->handle=NULL;
 
179
  }
 
180
  
 
181
  return 0;
 
182
}
 
183
 
 
184
void audio_queueflush(struct audio_info_struct *ai)
 
185
{
 
186
}