wmclockmon: update change-log
[dockapps.git] / ascd / libworkman / drv_sony.c
blobba9e28f836e00d9439e59078ebf6c2b582a497b2
1 /*
2 * $Id: drv_sony.c,v 1.3 1999/02/14 09:50:42 dirk Exp $
4 * This file is part of WorkMan, the civilized CD player library
5 * (c) 1991-1997 by Steven Grimm (original author)
6 * (c) by Dirk Försterling (current 'author' = maintainer)
7 * The maintainer can be contacted by his e-mail address:
8 * milliByte@DeathsDoor.com
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Vendor-specific drive control routines for Sony CDU-8012 series.
28 static char drv_sony_id[] = "$Id: drv_sony.c,v 1.3 1999/02/14 09:50:42 dirk Exp $";
30 #include <stdio.h>
31 #include <errno.h>
32 #include "include/wm_config.h"
33 #include "include/wm_struct.h"
34 #include "include/wm_scsi.h"
36 #define PAGE_AUDIO 0x0e
38 /* local prototypes */
39 static int sony_init( struct wm_drive *d );
40 static int sony_set_volume(struct wm_drive *d, int left, int right );
41 static int sony_get_volume( struct wm_drive *d, int *left, int *right );
44 extern int min_volume, max_volume;
46 struct wm_drive sony_proto = {
47 -1, /* fd */
48 "Sony", /* vendor */
49 "CDU-8012", /* model */
50 "", /* revision */
51 NULL, /* aux */
52 NULL, /* daux */
54 sony_init, /* functions... */
55 gen_get_trackcount,
56 gen_get_cdlen,
57 gen_get_trackinfo,
58 gen_get_drive_status,
59 sony_get_volume,
60 sony_set_volume,
61 gen_pause,
62 gen_resume,
63 gen_stop,
64 gen_play,
65 gen_eject,
66 gen_closetray
70 * Initialize the driver.
72 static int sony_init( struct wm_drive *d ) {
74 /* Sun use Sony drives as well */
75 #if defined(SYSV) && defined(CODEC)
76 codec_init();
77 #endif
78 min_volume = 128;
79 max_volume = 255;
80 return( 0 );
81 } /* sony_init() */
84 * On the Sony CDU-8012 drive, the amount of sound coming out the jack
85 * increases much faster toward the top end of the volume scale than it
86 * does at the bottom. To make up for this, we make the volume scale look
87 * sort of logarithmic (actually an upside-down inverse square curve) so
88 * that the volume value passed to the drive changes less and less as you
89 * approach the maximum slider setting. Additionally, only the top half
90 * of the volume scale is valid; the bottom half is all silent. The actual
91 * formula looks like
93 * max^2 - (max - vol)^2 max
94 * v = --------------------- + ---
95 * max * 2 2
97 * Where "max" is the maximum value of the volume scale, usually 100.
99 static int
100 scale_volume(vol, max)
101 int vol, max;
103 vol = (max*max - (max - vol) * (max - vol)) / max;
104 return ((vol + max) / 2);
108 * Given a value between min_volume and max_volume, return the standard-scale
109 * volume value needed to achieve that hardware value.
111 * Rather than perform floating-point calculations to reverse the above
112 * formula, we simply do a binary search of scale_volume()'s return values.
114 static int
115 unscale_volume(cd_vol, max)
116 int cd_vol, max;
118 int vol = 0, top = max, bot = 0, scaled = 0;
120 cd_vol = (cd_vol * 100 + (max_volume - 1)) / max_volume;
122 while (bot <= top)
124 vol = (top + bot) / 2;
125 scaled = scale_volume(vol, max);
126 if (cd_vol <= scaled)
127 top = vol - 1;
128 else
129 bot = vol + 1;
132 /* Might have looked down too far for repeated scaled values */
133 if (cd_vol < scaled)
134 vol++;
136 if (vol < 0)
137 vol = 0;
138 else if (vol > max)
139 vol = max;
141 return (vol);
145 * Get the volume. Sun's CD-ROM driver doesn't support this operation, even
146 * though their drive does. Dumb.
148 static int
149 sony_get_volume( struct wm_drive *d, int *left, int *right )
151 unsigned char mode[16];
153 /* Get the current audio parameters first. */
154 if (wm_scsi_mode_sense(d, PAGE_AUDIO, mode))
155 return (-1);
157 *left = unscale_volume(mode[9], 100);
158 *right = unscale_volume(mode[11], 100);
160 return (0);
164 * Set the volume using the wacky scale outlined above. The Sony drive
165 * responds to the standard set-volume command.
167 static int
168 sony_set_volume(struct wm_drive *d, int left, int right )
170 left = scale_volume(left, 100);
171 right = scale_volume(right, 100);
172 return (gen_set_volume(d, left, right));