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

« back to all changes in this revision

Viewing changes to src/audio_mint.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_mint: audio output for MINT
 
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 by Petr Stehlik
 
7
*/
 
8
 
 
9
/* derived from LINUX, VOXWARE and SUN for MiNT Audio Device by Petr Stehlik */
 
10
#include <fcntl.h>
 
11
#include "config.h"
 
12
#include "mpg123.h"
 
13
#include <ioctl.h>
 
14
#include <audios.h>
 
15
 
 
16
extern int outburst;
 
17
 
 
18
int real_rate_printed = 0;
 
19
 
 
20
 
 
21
 
 
22
static int audio_rate_best_match(struct audio_info_struct *ai)
 
23
{
 
24
  int ret,dsp_rate;
 
25
 
 
26
  if(!ai || ai->fn < 0 || ai->rate < 0)
 
27
    return -1;
 
28
  dsp_rate = ai->rate;
 
29
  ret = ioctl(ai->fn,AIOCSSPEED, (void *)dsp_rate);
 
30
  ret = ioctl(ai->fn,AIOCGSPEED,&dsp_rate);
 
31
  if(ret < 0)
 
32
    return ret;
 
33
  ai->rate = dsp_rate;
 
34
  return 0;
 
35
}
 
36
 
 
37
static int audio_set_rate(struct audio_info_struct *ai)
 
38
{
 
39
  int dsp_rate = ai->rate;
 
40
 
 
41
  if(ai->rate >= 0) {
 
42
    int ret, real_rate;
 
43
    ret = ioctl(ai->fn, AIOCSSPEED, (void *)dsp_rate);
 
44
    if (ret >= 0 && !real_rate_printed) {
 
45
      ioctl(ai->fn,AIOCGSPEED,&real_rate);
 
46
      if (real_rate != dsp_rate) {
 
47
        fprintf(stderr, "Replay rate: %d Hz\n", real_rate);
 
48
        real_rate_printed = 1;
 
49
      }
 
50
    }
 
51
    return ret;
 
52
  }
 
53
 
 
54
  return 0;
 
55
}
 
56
 
 
57
static int audio_set_channels(struct audio_info_struct *ai)
 
58
{
 
59
  int chan = ai->channels;
 
60
 
 
61
  if(ai->channels < 1)
 
62
    return 0;
 
63
 
 
64
  return ioctl(ai->fn, AIOCSCHAN, (void *)chan);
 
65
}
 
66
 
 
67
static int audio_set_format(struct audio_info_struct *ai)
 
68
{
 
69
  int fmts;
 
70
 
 
71
  if(ai->format == -1)
 
72
    return 0;
 
73
 
 
74
  switch(ai->format) {
 
75
    case AUDIO_FORMAT_SIGNED_16:
 
76
    default:
 
77
      fmts = AFMT_S16;
 
78
      break;
 
79
    case AUDIO_FORMAT_UNSIGNED_8:
 
80
      fmts = AFMT_U8;
 
81
      break;
 
82
    case AUDIO_FORMAT_SIGNED_8:
 
83
      fmts = AFMT_S8;
 
84
      break;
 
85
    case AUDIO_FORMAT_ULAW_8:
 
86
      fmts = AFMT_ULAW;
 
87
      break;
 
88
  }
 
89
  return ioctl(ai->fn, AIOCSFMT, (void *)fmts);
 
90
}
 
91
 
 
92
static int audio_reset_parameters(struct audio_info_struct *ai)
 
93
{
 
94
  int ret;
 
95
  ret = ioctl(ai->fn,AIOCRESET,NULL);
 
96
  if(ret >= 0)
 
97
    ret = audio_set_format(ai);
 
98
  if(ret >= 0)
 
99
    ret = audio_set_channels(ai);
 
100
  if(ret >= 0)
 
101
    ret = audio_set_rate(ai);
 
102
  return ret;
 
103
}
 
104
 
 
105
 
 
106
 
 
107
int audio_open(struct audio_info_struct *ai)
 
108
{
 
109
  if(!ai)
 
110
    return -1;
 
111
 
 
112
  if(!ai->device)
 
113
    ai->device = "/dev/audio";
 
114
 
 
115
  ai->fn = open(ai->device,O_WRONLY);  
 
116
 
 
117
  if(ai->fn < 0)
 
118
  {
 
119
    fprintf(stderr,"Can't open %s!\n",ai->device);
 
120
    exit(1);
 
121
  }
 
122
  ioctl(ai->fn, AIOCGBLKSIZE, &outburst);
 
123
  if(outburst > MAXOUTBURST)
 
124
    outburst = MAXOUTBURST;
 
125
  if(audio_reset_parameters(ai) < 0) {
 
126
    close(ai->fn);
 
127
    return -1;
 
128
  }
 
129
  return ai->fn;
 
130
}
 
131
int audio_get_formats(struct audio_info_struct *ai)
 
132
{
 
133
  int ret = 0;
 
134
  int fmts;
 
135
 
 
136
  if(ioctl(ai->fn,AIOCGFMTS,&fmts) < 0)
 
137
    return -1;
 
138
 
 
139
  if(fmts & AFMT_ULAW)
 
140
    ret |= AUDIO_FORMAT_ULAW_8;
 
141
  if(fmts & AFMT_S16)
 
142
    ret |= AUDIO_FORMAT_SIGNED_16;
 
143
  if(fmts & AFMT_U8)
 
144
    ret |= AUDIO_FORMAT_UNSIGNED_8;
 
145
  if(fmts & AFMT_S8)
 
146
    ret |= AUDIO_FORMAT_SIGNED_8;
 
147
 
 
148
  return ret;
 
149
}
 
150
 
 
151
int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
 
152
{
 
153
  return write(ai->fn,buf,len);
 
154
}
 
155
 
 
156
int audio_close(struct audio_info_struct *ai)
 
157
{
 
158
  close (ai->fn);
 
159
  return 0;
 
160
}
 
161
 
 
162
void audio_queueflush(struct audio_info_struct *ai)
 
163
{
 
164
}
 
165