opl4_mixer.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * OPL4 mixer functions
  3. * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "opl4_local.h"
  20. #include <sound/control.h>
  21. static int snd_opl4_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  22. {
  23. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  24. uinfo->count = 2;
  25. uinfo->value.integer.min = 0;
  26. uinfo->value.integer.max = 7;
  27. return 0;
  28. }
  29. static int snd_opl4_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  30. {
  31. struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
  32. unsigned long flags;
  33. u8 reg = kcontrol->private_value;
  34. u8 value;
  35. spin_lock_irqsave(&opl4->reg_lock, flags);
  36. value = snd_opl4_read(opl4, reg);
  37. spin_unlock_irqrestore(&opl4->reg_lock, flags);
  38. ucontrol->value.integer.value[0] = 7 - (value & 7);
  39. ucontrol->value.integer.value[1] = 7 - ((value >> 3) & 7);
  40. return 0;
  41. }
  42. static int snd_opl4_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  43. {
  44. struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
  45. unsigned long flags;
  46. u8 reg = kcontrol->private_value;
  47. u8 value, old_value;
  48. value = (7 - (ucontrol->value.integer.value[0] & 7)) |
  49. ((7 - (ucontrol->value.integer.value[1] & 7)) << 3);
  50. spin_lock_irqsave(&opl4->reg_lock, flags);
  51. old_value = snd_opl4_read(opl4, reg);
  52. snd_opl4_write(opl4, reg, value);
  53. spin_unlock_irqrestore(&opl4->reg_lock, flags);
  54. return value != old_value;
  55. }
  56. static struct snd_kcontrol_new snd_opl4_controls[] = {
  57. {
  58. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  59. .name = "FM Playback Volume",
  60. .info = snd_opl4_ctl_info,
  61. .get = snd_opl4_ctl_get,
  62. .put = snd_opl4_ctl_put,
  63. .private_value = OPL4_REG_MIX_CONTROL_FM
  64. },
  65. {
  66. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  67. .name = "Wavetable Playback Volume",
  68. .info = snd_opl4_ctl_info,
  69. .get = snd_opl4_ctl_get,
  70. .put = snd_opl4_ctl_put,
  71. .private_value = OPL4_REG_MIX_CONTROL_PCM
  72. }
  73. };
  74. int snd_opl4_create_mixer(struct snd_opl4 *opl4)
  75. {
  76. struct snd_card *card = opl4->card;
  77. int i, err;
  78. strcat(card->mixername, ",OPL4");
  79. for (i = 0; i < 2; ++i) {
  80. err = snd_ctl_add(card, snd_ctl_new1(&snd_opl4_controls[i], opl4));
  81. if (err < 0)
  82. return err;
  83. }
  84. return 0;
  85. }