emu10k1_synth.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
  3. *
  4. * Routines for control of EMU10K1 WaveTable synth
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include "emu10k1_synth_local.h"
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. MODULE_AUTHOR("Takashi Iwai");
  24. MODULE_DESCRIPTION("Routines for control of EMU10K1 WaveTable synth");
  25. MODULE_LICENSE("GPL");
  26. /*
  27. * create a new hardware dependent device for Emu10k1
  28. */
  29. static int snd_emu10k1_synth_probe(struct device *_dev)
  30. {
  31. struct snd_seq_device *dev = to_seq_dev(_dev);
  32. struct snd_emux *emux;
  33. struct snd_emu10k1 *hw;
  34. struct snd_emu10k1_synth_arg *arg;
  35. unsigned long flags;
  36. arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
  37. if (arg == NULL)
  38. return -EINVAL;
  39. if (arg->seq_ports <= 0)
  40. return 0; /* nothing */
  41. if (arg->max_voices < 1)
  42. arg->max_voices = 1;
  43. else if (arg->max_voices > 64)
  44. arg->max_voices = 64;
  45. if (snd_emux_new(&emux) < 0)
  46. return -ENOMEM;
  47. snd_emu10k1_ops_setup(emux);
  48. hw = arg->hwptr;
  49. emux->hw = hw;
  50. emux->max_voices = arg->max_voices;
  51. emux->num_ports = arg->seq_ports;
  52. emux->pitch_shift = -501;
  53. emux->memhdr = hw->memhdr;
  54. /* maximum two ports */
  55. emux->midi_ports = arg->seq_ports < 2 ? arg->seq_ports : 2;
  56. /* audigy has two external midis */
  57. emux->midi_devidx = hw->audigy ? 2 : 1;
  58. emux->linear_panning = 0;
  59. emux->hwdep_idx = 2; /* FIXED */
  60. if (snd_emux_register(emux, dev->card, arg->index, "Emu10k1") < 0) {
  61. snd_emux_free(emux);
  62. return -ENOMEM;
  63. }
  64. spin_lock_irqsave(&hw->voice_lock, flags);
  65. hw->synth = emux;
  66. hw->get_synth_voice = snd_emu10k1_synth_get_voice;
  67. spin_unlock_irqrestore(&hw->voice_lock, flags);
  68. dev->driver_data = emux;
  69. return 0;
  70. }
  71. static int snd_emu10k1_synth_remove(struct device *_dev)
  72. {
  73. struct snd_seq_device *dev = to_seq_dev(_dev);
  74. struct snd_emux *emux;
  75. struct snd_emu10k1 *hw;
  76. unsigned long flags;
  77. if (dev->driver_data == NULL)
  78. return 0; /* not registered actually */
  79. emux = dev->driver_data;
  80. hw = emux->hw;
  81. spin_lock_irqsave(&hw->voice_lock, flags);
  82. hw->synth = NULL;
  83. hw->get_synth_voice = NULL;
  84. spin_unlock_irqrestore(&hw->voice_lock, flags);
  85. snd_emux_free(emux);
  86. return 0;
  87. }
  88. /*
  89. * INIT part
  90. */
  91. static struct snd_seq_driver emu10k1_synth_driver = {
  92. .driver = {
  93. .name = KBUILD_MODNAME,
  94. .probe = snd_emu10k1_synth_probe,
  95. .remove = snd_emu10k1_synth_remove,
  96. },
  97. .id = SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
  98. .argsize = sizeof(struct snd_emu10k1_synth_arg),
  99. };
  100. module_snd_seq_driver(emu10k1_synth_driver);