ainstr_fm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * FM (OPL2/3) Instrument routines
  3. * Copyright (c) 2000 Uros Bizjak <uros@kss-loka.si>
  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. */
  20. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <sound/core.h>
  23. #include <sound/ainstr_fm.h>
  24. #include <sound/initval.h>
  25. #include <asm/uaccess.h>
  26. MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
  27. MODULE_DESCRIPTION("Advanced Linux Sound Architecture FM Instrument support.");
  28. MODULE_LICENSE("GPL");
  29. static int snd_seq_fm_put(void *private_data, struct snd_seq_kinstr *instr,
  30. char __user *instr_data, long len, int atomic, int cmd)
  31. {
  32. struct fm_instrument *ip;
  33. struct fm_xinstrument ix;
  34. int idx;
  35. if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE)
  36. return -EINVAL;
  37. /* copy instrument data */
  38. if (len < (long)sizeof(ix))
  39. return -EINVAL;
  40. if (copy_from_user(&ix, instr_data, sizeof(ix)))
  41. return -EFAULT;
  42. if (ix.stype != FM_STRU_INSTR)
  43. return -EINVAL;
  44. ip = (struct fm_instrument *)KINSTR_DATA(instr);
  45. ip->share_id[0] = le32_to_cpu(ix.share_id[0]);
  46. ip->share_id[1] = le32_to_cpu(ix.share_id[1]);
  47. ip->share_id[2] = le32_to_cpu(ix.share_id[2]);
  48. ip->share_id[3] = le32_to_cpu(ix.share_id[3]);
  49. ip->type = ix.type;
  50. for (idx = 0; idx < 4; idx++) {
  51. ip->op[idx].am_vib = ix.op[idx].am_vib;
  52. ip->op[idx].ksl_level = ix.op[idx].ksl_level;
  53. ip->op[idx].attack_decay = ix.op[idx].attack_decay;
  54. ip->op[idx].sustain_release = ix.op[idx].sustain_release;
  55. ip->op[idx].wave_select = ix.op[idx].wave_select;
  56. }
  57. for (idx = 0; idx < 2; idx++) {
  58. ip->feedback_connection[idx] = ix.feedback_connection[idx];
  59. }
  60. ip->echo_delay = ix.echo_delay;
  61. ip->echo_atten = ix.echo_atten;
  62. ip->chorus_spread = ix.chorus_spread;
  63. ip->trnsps = ix.trnsps;
  64. ip->fix_dur = ix.fix_dur;
  65. ip->modes = ix.modes;
  66. ip->fix_key = ix.fix_key;
  67. return 0;
  68. }
  69. static int snd_seq_fm_get(void *private_data, struct snd_seq_kinstr *instr,
  70. char __user *instr_data, long len, int atomic,
  71. int cmd)
  72. {
  73. struct fm_instrument *ip;
  74. struct fm_xinstrument ix;
  75. int idx;
  76. if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL)
  77. return -EINVAL;
  78. if (len < (long)sizeof(ix))
  79. return -ENOMEM;
  80. memset(&ix, 0, sizeof(ix));
  81. ip = (struct fm_instrument *)KINSTR_DATA(instr);
  82. ix.stype = FM_STRU_INSTR;
  83. ix.share_id[0] = cpu_to_le32(ip->share_id[0]);
  84. ix.share_id[1] = cpu_to_le32(ip->share_id[1]);
  85. ix.share_id[2] = cpu_to_le32(ip->share_id[2]);
  86. ix.share_id[3] = cpu_to_le32(ip->share_id[3]);
  87. ix.type = ip->type;
  88. for (idx = 0; idx < 4; idx++) {
  89. ix.op[idx].am_vib = ip->op[idx].am_vib;
  90. ix.op[idx].ksl_level = ip->op[idx].ksl_level;
  91. ix.op[idx].attack_decay = ip->op[idx].attack_decay;
  92. ix.op[idx].sustain_release = ip->op[idx].sustain_release;
  93. ix.op[idx].wave_select = ip->op[idx].wave_select;
  94. }
  95. for (idx = 0; idx < 2; idx++) {
  96. ix.feedback_connection[idx] = ip->feedback_connection[idx];
  97. }
  98. if (copy_to_user(instr_data, &ix, sizeof(ix)))
  99. return -EFAULT;
  100. ix.echo_delay = ip->echo_delay;
  101. ix.echo_atten = ip->echo_atten;
  102. ix.chorus_spread = ip->chorus_spread;
  103. ix.trnsps = ip->trnsps;
  104. ix.fix_dur = ip->fix_dur;
  105. ix.modes = ip->modes;
  106. ix.fix_key = ip->fix_key;
  107. return 0;
  108. }
  109. static int snd_seq_fm_get_size(void *private_data, struct snd_seq_kinstr *instr,
  110. long *size)
  111. {
  112. *size = sizeof(struct fm_xinstrument);
  113. return 0;
  114. }
  115. int snd_seq_fm_init(struct snd_seq_kinstr_ops *ops,
  116. struct snd_seq_kinstr_ops *next)
  117. {
  118. memset(ops, 0, sizeof(*ops));
  119. // ops->private_data = private_data;
  120. ops->add_len = sizeof(struct fm_instrument);
  121. ops->instr_type = SNDRV_SEQ_INSTR_ID_OPL2_3;
  122. ops->put = snd_seq_fm_put;
  123. ops->get = snd_seq_fm_get;
  124. ops->get_size = snd_seq_fm_get_size;
  125. // ops->remove = snd_seq_fm_remove;
  126. // ops->notify = snd_seq_fm_notify;
  127. ops->next = next;
  128. return 0;
  129. }
  130. /*
  131. * Init part
  132. */
  133. static int __init alsa_ainstr_fm_init(void)
  134. {
  135. return 0;
  136. }
  137. static void __exit alsa_ainstr_fm_exit(void)
  138. {
  139. }
  140. module_init(alsa_ainstr_fm_init)
  141. module_exit(alsa_ainstr_fm_exit)
  142. EXPORT_SYMBOL(snd_seq_fm_init);