ainstr_fm.c 4.6 KB

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