emu10k1_synth.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. MODULE_AUTHOR("Takashi Iwai");
  23. MODULE_DESCRIPTION("Routines for control of EMU10K1 WaveTable synth");
  24. MODULE_LICENSE("GPL");
  25. /*
  26. * create a new hardware dependent device for Emu10k1
  27. */
  28. static int snd_emu10k1_synth_new_device(struct snd_seq_device *dev)
  29. {
  30. struct snd_emux *emu;
  31. struct snd_emu10k1 *hw;
  32. struct snd_emu10k1_synth_arg *arg;
  33. unsigned long flags;
  34. arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
  35. if (arg == NULL)
  36. return -EINVAL;
  37. if (arg->seq_ports <= 0)
  38. return 0; /* nothing */
  39. if (arg->max_voices < 1)
  40. arg->max_voices = 1;
  41. else if (arg->max_voices > 64)
  42. arg->max_voices = 64;
  43. if (snd_emux_new(&emu) < 0)
  44. return -ENOMEM;
  45. snd_emu10k1_ops_setup(emu);
  46. emu->hw = hw = arg->hwptr;
  47. emu->max_voices = arg->max_voices;
  48. emu->num_ports = arg->seq_ports;
  49. emu->pitch_shift = -501;
  50. emu->memhdr = hw->memhdr;
  51. emu->midi_ports = arg->seq_ports < 2 ? arg->seq_ports : 2; /* maximum two ports */
  52. emu->midi_devidx = hw->audigy ? 2 : 1; /* audigy has two external midis */
  53. emu->linear_panning = 0;
  54. emu->hwdep_idx = 2; /* FIXED */
  55. if (snd_emux_register(emu, dev->card, arg->index, "Emu10k1") < 0) {
  56. snd_emux_free(emu);
  57. emu->hw = NULL;
  58. return -ENOMEM;
  59. }
  60. spin_lock_irqsave(&hw->voice_lock, flags);
  61. hw->synth = emu;
  62. hw->get_synth_voice = snd_emu10k1_synth_get_voice;
  63. spin_unlock_irqrestore(&hw->voice_lock, flags);
  64. dev->driver_data = emu;
  65. return 0;
  66. }
  67. static int snd_emu10k1_synth_delete_device(struct snd_seq_device *dev)
  68. {
  69. struct snd_emux *emu;
  70. struct snd_emu10k1 *hw;
  71. unsigned long flags;
  72. if (dev->driver_data == NULL)
  73. return 0; /* not registered actually */
  74. emu = dev->driver_data;
  75. hw = emu->hw;
  76. spin_lock_irqsave(&hw->voice_lock, flags);
  77. hw->synth = NULL;
  78. hw->get_synth_voice = NULL;
  79. spin_unlock_irqrestore(&hw->voice_lock, flags);
  80. snd_emux_free(emu);
  81. return 0;
  82. }
  83. /*
  84. * INIT part
  85. */
  86. static int __init alsa_emu10k1_synth_init(void)
  87. {
  88. static struct snd_seq_dev_ops ops = {
  89. snd_emu10k1_synth_new_device,
  90. snd_emu10k1_synth_delete_device,
  91. };
  92. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
  93. sizeof(struct snd_emu10k1_synth_arg));
  94. }
  95. static void __exit alsa_emu10k1_synth_exit(void)
  96. {
  97. snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH);
  98. }
  99. module_init(alsa_emu10k1_synth_init)
  100. module_exit(alsa_emu10k1_synth_exit)