gus_instr.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Routines for Gravis UltraSound soundcards - Synthesizer
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  4. *
  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. */
  21. #include <sound/driver.h>
  22. #include <linux/time.h>
  23. #include <sound/core.h>
  24. #include <sound/gus.h>
  25. /*
  26. *
  27. */
  28. int snd_gus_iwffff_put_sample(void *private_data, struct iwffff_wave *wave,
  29. char __user *data, long len, int atomic)
  30. {
  31. struct snd_gus_card *gus = private_data;
  32. struct snd_gf1_mem_block *block;
  33. int err;
  34. if (wave->format & IWFFFF_WAVE_ROM)
  35. return 0; /* it's probably ok - verify the address? */
  36. if (wave->format & IWFFFF_WAVE_STEREO)
  37. return -EINVAL; /* not supported */
  38. block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
  39. SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF,
  40. NULL, wave->size,
  41. wave->format & IWFFFF_WAVE_16BIT, 1,
  42. wave->share_id);
  43. if (block == NULL)
  44. return -ENOMEM;
  45. err = snd_gus_dram_write(gus, data,
  46. block->ptr, wave->size);
  47. if (err < 0) {
  48. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
  49. snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
  50. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
  51. return err;
  52. }
  53. wave->address.memory = block->ptr;
  54. return 0;
  55. }
  56. int snd_gus_iwffff_get_sample(void *private_data, struct iwffff_wave *wave,
  57. char __user *data, long len, int atomic)
  58. {
  59. struct snd_gus_card *gus = private_data;
  60. return snd_gus_dram_read(gus, data, wave->address.memory, wave->size,
  61. wave->format & IWFFFF_WAVE_ROM ? 1 : 0);
  62. }
  63. int snd_gus_iwffff_remove_sample(void *private_data, struct iwffff_wave *wave,
  64. int atomic)
  65. {
  66. struct snd_gus_card *gus = private_data;
  67. if (wave->format & IWFFFF_WAVE_ROM)
  68. return 0; /* it's probably ok - verify the address? */
  69. return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
  70. }
  71. /*
  72. *
  73. */
  74. int snd_gus_gf1_put_sample(void *private_data, struct gf1_wave *wave,
  75. char __user *data, long len, int atomic)
  76. {
  77. struct snd_gus_card *gus = private_data;
  78. struct snd_gf1_mem_block *block;
  79. int err;
  80. if (wave->format & GF1_WAVE_STEREO)
  81. return -EINVAL; /* not supported */
  82. block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
  83. SNDRV_GF1_MEM_OWNER_WAVE_GF1,
  84. NULL, wave->size,
  85. wave->format & GF1_WAVE_16BIT, 1,
  86. wave->share_id);
  87. if (block == NULL)
  88. return -ENOMEM;
  89. err = snd_gus_dram_write(gus, data,
  90. block->ptr, wave->size);
  91. if (err < 0) {
  92. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
  93. snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
  94. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
  95. return err;
  96. }
  97. wave->address.memory = block->ptr;
  98. return 0;
  99. }
  100. int snd_gus_gf1_get_sample(void *private_data, struct gf1_wave *wave,
  101. char __user *data, long len, int atomic)
  102. {
  103. struct snd_gus_card *gus = private_data;
  104. return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 0);
  105. }
  106. int snd_gus_gf1_remove_sample(void *private_data, struct gf1_wave *wave,
  107. int atomic)
  108. {
  109. struct snd_gus_card *gus = private_data;
  110. return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
  111. }
  112. /*
  113. *
  114. */
  115. int snd_gus_simple_put_sample(void *private_data, struct simple_instrument *instr,
  116. char __user *data, long len, int atomic)
  117. {
  118. struct snd_gus_card *gus = private_data;
  119. struct snd_gf1_mem_block *block;
  120. int err;
  121. if (instr->format & SIMPLE_WAVE_STEREO)
  122. return -EINVAL; /* not supported */
  123. block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
  124. SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE,
  125. NULL, instr->size,
  126. instr->format & SIMPLE_WAVE_16BIT, 1,
  127. instr->share_id);
  128. if (block == NULL)
  129. return -ENOMEM;
  130. err = snd_gus_dram_write(gus, data, block->ptr, instr->size);
  131. if (err < 0) {
  132. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
  133. snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
  134. snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
  135. return err;
  136. }
  137. instr->address.memory = block->ptr;
  138. return 0;
  139. }
  140. int snd_gus_simple_get_sample(void *private_data, struct simple_instrument *instr,
  141. char __user *data, long len, int atomic)
  142. {
  143. struct snd_gus_card *gus = private_data;
  144. return snd_gus_dram_read(gus, data, instr->address.memory, instr->size, 0);
  145. }
  146. int snd_gus_simple_remove_sample(void *private_data, struct simple_instrument *instr,
  147. int atomic)
  148. {
  149. struct snd_gus_card *gus = private_data;
  150. return snd_gf1_mem_free(&gus->gf1.mem_alloc, instr->address.memory);
  151. }