~ubuntu-branches/ubuntu/karmic/mpg123/karmic

« back to all changes in this revision

Viewing changes to src/output/mint.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2008-09-07 17:02:54 UTC
  • mfrom: (5.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080907170254-m83mo5cgdk0hrqnp
Tags: 1.4.3-4
* src/wav.c: Backport upstream patch for writing WAV output to stdout
  via '-w -'. Fixes regression from etch. Closes: #493285
* debian/rules: Only include ALSA dependencies when respective plugin has
  been built. Original patch thanks to Petr Salinger. Fixes build failure
  on GNU/kFreeBSD. Closes: #493423

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        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.org
 
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 "mpg123app.h"
 
12
#include <ioctl.h>
 
13
#include <audios.h>
 
14
#include "debug.h"
 
15
 
 
16
/* Globals */
 
17
extern int outburst;
 
18
int real_rate_printed = 0;
 
19
 
 
20
 
 
21
 
 
22
static int rate_best_match(audio_output_t *ao)
 
23
{
 
24
        int ret,dsp_rate;
 
25
        
 
26
        if(!ai || ao->fn < 0 || ao->rate < 0)
 
27
                return -1;
 
28
        
 
29
        dsp_rate = ao->rate;
 
30
        ret = ioctl(ao->fn,AIOCSSPEED, (void *)dsp_rate);
 
31
        ret = ioctl(ao->fn,AIOCGSPEED,&dsp_rate);
 
32
        if(ret < 0) return ret;
 
33
        ao->rate = dsp_rate;
 
34
        return 0;
 
35
}
 
36
 
 
37
static int set_rate(audio_output_t *ao)
 
38
{
 
39
        int dsp_rate = ao->rate;
 
40
        
 
41
        if(ao->rate >= 0) {
 
42
                int ret, real_rate;
 
43
                ret = ioctl(ao->fn, AIOCSSPEED, (void *)dsp_rate);
 
44
                if (ret >= 0 && !real_rate_printed) {
 
45
                        ioctl(ao->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 set_channels(audio_output_t *ao)
 
58
{
 
59
        int chan = ao->channels;
 
60
        
 
61
        if(ao->channels < 1) return 0;
 
62
        
 
63
        return ioctl(ao->fn, AIOCSCHAN, (void *)chan);
 
64
}
 
65
 
 
66
static int set_format(audio_output_t *ao)
 
67
{
 
68
        int fmts;
 
69
        
 
70
        if(ao->format == -1)
 
71
                return 0;
 
72
        
 
73
        switch(ao->format) {
 
74
                case MPG123_ENC_SIGNED_16:
 
75
                default:
 
76
                        fmts = AFMT_S16;
 
77
                break;
 
78
                case MPG123_ENC_UNSIGNED_8:
 
79
                        fmts = AFMT_U8;
 
80
                break;
 
81
                case MPG123_ENC_SIGNED_8:
 
82
                        fmts = AFMT_S8;
 
83
                break;
 
84
                case MPG123_ENC_ULAW_8:
 
85
                        fmts = AFMT_ULAW;
 
86
                break;
 
87
        }
 
88
        
 
89
        return ioctl(ao->fn, AIOCSFMT, (void *)fmts);
 
90
}
 
91
 
 
92
static int reset_parameters(audio_output_t *ao)
 
93
{
 
94
        int ret;
 
95
        ret = ioctl(ao->fn,AIOCRESET,NULL);
 
96
        if(ret >= 0) ret = set_format(ai);
 
97
        if(ret >= 0) ret = set_channels(ai);
 
98
        if(ret >= 0) ret = set_rate(ai);
 
99
        return ret;
 
100
}
 
101
 
 
102
 
 
103
 
 
104
static int open_mint(audio_output_t *ao)
 
105
{
 
106
        if(!ai) return -1;
 
107
 
 
108
        if(!ao->device)
 
109
                ao->device = "/dev/audio";
 
110
        
 
111
        ao->fn = open(ao->device,O_WRONLY);  
 
112
        
 
113
        if(ao->fn < 0)
 
114
        {
 
115
                error1("Can't open %s!",ao->device);
 
116
                return -1;
 
117
        }
 
118
        ioctl(ao->fn, AIOCGBLKSIZE, &outburst);
 
119
        if(outburst > MAXOUTBURST)
 
120
                outburst = MAXOUTBURST;
 
121
        if(audio_reset_parameters(ai) < 0) {
 
122
                close(ao->fn);
 
123
                return -1;
 
124
        }
 
125
        
 
126
        return ao->fn;
 
127
}
 
128
 
 
129
static int get_formats_mint(audio_output_t *ao)
 
130
{
 
131
        int ret = 0;
 
132
        int fmts;
 
133
        
 
134
        if(ioctl(ao->fn,AIOCGFMTS,&fmts) < 0)
 
135
                return -1;
 
136
        
 
137
        if(fmts & AFMT_ULAW)
 
138
                ret |= MPG123_ENC_ULAW_8;
 
139
        if(fmts & AFMT_S16)
 
140
                ret |= MPG123_ENC_SIGNED_16;
 
141
        if(fmts & AFMT_U8)
 
142
                ret |= MPG123_ENC_UNSIGNED_8;
 
143
        if(fmts & AFMT_S8)
 
144
                ret |= MPG123_ENC_SIGNED_8;
 
145
        
 
146
        return ret;
 
147
}
 
148
 
 
149
static int write_mint(audio_output_t *ao,unsigned char *buf,int len)
 
150
{
 
151
        return write(ao->fn,buf,len);
 
152
}
 
153
 
 
154
static int close_mint(audio_output_t *ao)
 
155
{
 
156
        close (ao->fn);
 
157
        return 0;
 
158
}
 
159
 
 
160
static void flush_mint(audio_output_t *ao)
 
161
{
 
162
}
 
163
 
 
164
 
 
165
static int init_mint(audio_output_t* ao)
 
166
{
 
167
        if (ao==NULL) return -1;
 
168
 
 
169
        /* Set callbacks */
 
170
        ao->open = open_mint;
 
171
        ao->flush = flush_mint;
 
172
        ao->write = write_mint;
 
173
        ao->get_formats = get_formats_mint;
 
174
        ao->close = close_mint;
 
175
 
 
176
        /* Success */
 
177
        return 0;
 
178
}
 
179
 
 
180
 
 
181
 
 
182
 
 
183
 
 
184
/* 
 
185
        Module information data structure
 
186
*/
 
187
mpg123_module_t mpg123_output_module_info = {
 
188
        /* api_version */       MPG123_MODULE_API_VERSION,
 
189
        /* name */                      "mint",                                         
 
190
        /* description */       "Audio output for MINT.",
 
191
        /* revision */          "$Rev:$",                                               
 
192
        /* handle */            NULL,
 
193
        
 
194
        /* init_output */       init_mint,                                              
 
195
};
 
196
 
 
197