gus_instr.c 4.9 KB

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