Changeset 3df0f75 in mainline
- Timestamp:
- 2011-11-25T22:07:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 53a7fda
- Parents:
- 1269160
- Location:
- uspace/drv/audio/sb16
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/mixer.c
r1269160 r3df0f75 35 35 36 36 typedef struct channel { 37 const char *name; 37 38 uint8_t address; 38 39 unsigned shift; … … 49 50 /* CT1335 channels */ 50 51 static const channel_t channels_table_ct1335[] = { 51 { 0x02, 1, 8, false }, /* Master, Mono, 3bit volume level */52 { 0x06, 1, 8, false }, /* Midi, Mono, 3bit volume level */53 { 0x08, 1, 8, false }, /* CD, Mono, 3bit volume level */54 { 0x0a, 1, 4, false }, /* Voice, Mono, 2bit volume level */52 { "", 0x02, 1, 8, false }, /* Master, Mono, 3bit volume level */ 53 { "", 0x06, 1, 8, false }, /* Midi, Mono, 3bit volume level */ 54 { "", 0x08, 1, 8, false }, /* CD, Mono, 3bit volume level */ 55 { "", 0x0a, 1, 4, false }, /* Voice, Mono, 2bit volume level */ 55 56 }; 56 57 57 58 /* CT1345 channels */ 58 59 static const channel_t channels_table_ct1345[] = { 59 { 0x22, 5, 8, true }, /* Master, Left, 3bit volume level */60 { 0x22, 1, 8, true }, /* Master, Right, 3bit volume level */61 { 0x26, 5, 8, true }, /* Midi, Left, 3bit volume level */62 { 0x26, 1, 8, true }, /* Midi, Right, 3bit volume level */63 { 0x28, 5, 8, true }, /* CD, Left, 3bit volume level */64 { 0x28, 1, 8, true }, /* CD, Right, 3bit volume level */65 { 0x2e, 5, 8, true }, /* Line, Left, 3bit volume level */66 { 0x2e, 1, 8, true }, /* Line, Right, 3bit volume level */67 { 0x04, 5, 8, true }, /* Voice, Left, 3bit volume level */68 { 0x04, 1, 8, true }, /* Voice, Right, 3bit volume level */69 { 0x0a, 1, 4, false }, /* Mic, Mono, 2bit volume level */60 { "Left", 0x22, 5, 8, true }, /* Master, Left, 3bit volume level */ 61 { "Right", 0x22, 1, 8, true }, /* Master, Right, 3bit volume level */ 62 { "Left", 0x26, 5, 8, true }, /* Midi, Left, 3bit volume level */ 63 { "Right", 0x26, 1, 8, true }, /* Midi, Right, 3bit volume level */ 64 { "Left", 0x28, 5, 8, true }, /* CD, Left, 3bit volume level */ 65 { "Right", 0x28, 1, 8, true }, /* CD, Right, 3bit volume level */ 66 { "Left", 0x2e, 5, 8, true }, /* Line, Left, 3bit volume level */ 67 { "Right", 0x2e, 1, 8, true }, /* Line, Right, 3bit volume level */ 68 { "Left", 0x04, 5, 8, true }, /* Voice, Left, 3bit volume level */ 69 { "Right", 0x04, 1, 8, true }, /* Voice, Right, 3bit volume level */ 70 { "", 0x0a, 1, 4, false }, /* Mic, Mono, 2bit volume level */ 70 71 }; 71 72 72 73 /* CT1745 channels */ 73 74 static const channel_t channels_table_ct1745[] = { 74 { 0x30, 3, 32, false },/* Master, Left, 5bit volume level */75 { 0x31, 3, 32, false }, /* Master, Right, 5bit volume level */76 { 0x32, 3, 32, false },/* Voice, Left, 5bit volume level */77 { 0x33, 3, 32, false }, /* Voice, Right, 5bit volume level */78 { 0x34, 3, 32, false }, /* MIDI, Left, 5bit volume level */79 { 0x35, 3, 32, false }, /* MIDI, Right, 5bit volume level */80 { 0x36, 3, 32, false }, /* CD, Left, 5bit volume level */81 { 0x37, 3, 32, false }, /* CD, Right, 5bit volume level */82 { 0x38, 3, 32, false }, /* Line, Left, 5bit volume level */83 { 0x39, 3, 32, false }, /* Line, Right, 5bit volume level */84 { 0x3a, 3, 32, false }, /* Mic, Mono, 5bit volume level */85 { 0x3b, 6, 4, false }, /* PC speaker, Mono, 2bit volumelevel */86 { 0x3f, 6, 4, false }, /* Input Gain, Left, 2bit volumelevel */87 { 0x40, 6, 4, false }, /* Input Gain, Right, 2bit volumelevel */88 { 0x41, 6, 4, false }, /* Output Gain, Left, 2bit volumelevel */89 { 0x42, 6, 4, false }, /* Output Gain, Right, 2bit volumelevel */90 { 0x44, 4, 16, false }, /* Treble, Left, 4bit volume level */91 { 0x45, 4, 16, false }, /* Treble, Right, 4bit volume level */92 { 0x46, 4, 16, false }, /* Bass, Left, 4bit volume level */93 { 0x47, 4, 16, false }, /* Bass, Right, 4bit volume level */75 { "Left", 0x30, 3, 32, false }, /* Master, Left, 5bit volume level */ 76 { "Right", 0x31, 3, 32, false }, /* Master, Right, 5bit volume level */ 77 { "Left", 0x32, 3, 32, false }, /* Voice, Left, 5bit volume level */ 78 { "Right", 0x33, 3, 32, false }, /* Voice, Right, 5bit volume level */ 79 { "Left", 0x34, 3, 32, false }, /* MIDI, Left, 5bit volume level */ 80 { "Right", 0x35, 3, 32, false }, /* MIDI, Right, 5bit volume level */ 81 { "Left", 0x36, 3, 32, false }, /* CD, Left, 5bit volume level */ 82 { "Right", 0x37, 3, 32, false }, /* CD, Right, 5bit volume level */ 83 { "Left", 0x38, 3, 32, false }, /* Line, Left, 5bit volume level */ 84 { "Right", 0x39, 3, 32, false }, /* Line, Right, 5bit volume level */ 85 { "", 0x3a, 3, 32, false }, /* Mic, Mono, 5bit volume level */ 86 { "", 0x3b, 6, 4, false }, /* PC speaker, Mono, 2bit level */ 87 { "Left", 0x3f, 6, 4, false }, /* Input Gain, Left, 2bit level */ 88 { "Right", 0x40, 6, 4, false }, /* Input Gain, Right, 2bit level */ 89 { "Left", 0x41, 6, 4, false }, /* Output Gain, Left, 2bit level */ 90 { "Right", 0x42, 6, 4, false }, /* Output Gain, Right, 2bit level */ 91 { "Left", 0x44, 4, 16, false }, /* Treble, Left, 4bit volume level */ 92 { "Right", 0x45, 4, 16, false }, /* Treble, Right, 4bit volume level */ 93 { "Left", 0x46, 4, 16, false }, /* Bass, Left, 4bit volume level */ 94 { "Right", 0x47, 4, 16, false }, /* Bass, Right, 4bit volume level */ 94 95 }; 95 96 … … 145 146 return; 146 147 const unsigned item = 0; /* 0 is Master. */ 147 unsigned levels = 0, channels = 0, level;148 unsigned channels = 0; 148 149 const char *name = NULL; 149 150 150 sb_mixer_get_control_item_info(mixer, item, &name, &channels , &levels);151 sb_mixer_get_control_item_info(mixer, item, &name, &channels); 151 152 for (unsigned channel = 0; channel < channels; ++channel) { 152 level = sb_mixer_get_volume_level(mixer, item, channel); 153 unsigned levels = 0; 154 const int ret = sb_mixer_get_channel_info(mixer, item, channel, 155 NULL, &levels); 156 if (ret != EOK) 157 continue; 158 159 unsigned level = 160 sb_mixer_get_volume_level(mixer, item, channel); 153 161 ddf_log_note("Setting %s channel %d to %d (%d).\n", 154 162 name, channel, levels - 1, level); … … 201 209 /*----------------------------------------------------------------------------*/ 202 210 int sb_mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index, 203 const char** name, unsigned *channels , unsigned *levels)211 const char** name, unsigned *channels) 204 212 { 205 213 assert(mixer); … … 207 215 return ENOENT; 208 216 209 const volume_item_t item =volume_table[mixer->type].table[index];217 const volume_item_t *item = &volume_table[mixer->type].table[index]; 210 218 if (name) 211 *name = item .description;219 *name = item->description; 212 220 if (channels) 213 *channels = item.channels; 221 *channels = item->channels; 222 return EOK; 223 } 224 /*----------------------------------------------------------------------------*/ 225 int sb_mixer_get_channel_info(const sb_mixer_t *mixer, unsigned index, 226 unsigned channel, const char **name, unsigned *levels) 227 { 228 assert(mixer); 229 if (index > volume_table[mixer->type].count) 230 return ENOENT; 231 232 const volume_item_t *item = &volume_table[mixer->type].table[index]; 233 if (channel > item->channels) 234 return ENOENT; 235 236 const channel_t *chan = &item->channel_table[channel]; 237 if (name) 238 *name = chan->name; 214 239 if (levels) 215 *levels = item.channel_table[0].volume_levels;240 *levels = chan->volume_levels; 216 241 return EOK; 217 242 } … … 226 251 if (channel >= volume_table[mixer->type].table[index].channels) 227 252 return ENOENT; 228 const channel_t chan = 229 volume_table[mixer->type].table[index].channel_table[channel]; 230 231 if (level > chan.volume_levels) 232 level = chan.volume_levels; 233 234 pio_write_8(&mixer->regs->mixer_address, chan.address); 253 254 const channel_t *chan = 255 &volume_table[mixer->type].table[index].channel_table[channel]; 256 257 if (level > chan->volume_levels) 258 level = chan->volume_levels; 259 260 pio_write_8(&mixer->regs->mixer_address, chan->address); 261 235 262 uint8_t value = 0; 236 237 if (chan.preserve_bits) { 263 if (chan->preserve_bits) { 238 264 value = pio_read_8(&mixer->regs->mixer_data); 239 value &= ~(uint8_t)((chan .volume_levels - 1) << chan.shift);265 value &= ~(uint8_t)((chan->volume_levels - 1) << chan->shift); 240 266 } 241 267 242 value |= level << chan .shift;268 value |= level << chan->shift; 243 269 pio_write_8(&mixer->regs->mixer_data, value); 244 270 return EOK; … … 255 281 return 0; 256 282 257 const channel_t chan = 258 volume_table[mixer->type].table[index].channel_table[channel]; 259 pio_write_8(&mixer->regs->mixer_address, chan.address); 260 return (pio_read_8(&mixer->regs->mixer_data) >> chan.shift) 261 & (chan.volume_levels - 1); 262 } 283 const channel_t *chan = 284 &volume_table[mixer->type].table[index].channel_table[channel]; 285 286 pio_write_8(&mixer->regs->mixer_address, chan->address); 287 return (pio_read_8(&mixer->regs->mixer_data) >> chan->shift) 288 & (chan->volume_levels - 1); 289 } -
uspace/drv/audio/sb16/mixer.h
r1269160 r3df0f75 54 54 int sb_mixer_get_control_item_count(const sb_mixer_t *mixer); 55 55 int sb_mixer_get_control_item_info(const sb_mixer_t *mixer, unsigned index, 56 const char** name, unsigned *channels, unsigned *levels); 56 const char **name, unsigned *channels); 57 int sb_mixer_get_channel_info(const sb_mixer_t *mixer, unsigned index, 58 unsigned channel, const char **name, unsigned *levels); 57 59 int sb_mixer_set_volume_level(const sb_mixer_t *mixer, 58 60 unsigned item, unsigned channel, unsigned level);
Note:
See TracChangeset
for help on using the changeset viewer.