emux_synth.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef __SOUND_EMUX_SYNTH_H
  2. #define __SOUND_EMUX_SYNTH_H
  3. /*
  4. * Defines for the Emu-series WaveTable chip
  5. *
  6. * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <sound/seq_kernel.h>
  23. #include <sound/seq_device.h>
  24. #include <sound/soundfont.h>
  25. #include <sound/seq_midi_emul.h>
  26. #include <sound/seq_oss.h>
  27. #include <sound/emux_legacy.h>
  28. #include <sound/seq_virmidi.h>
  29. /*
  30. * compile flags
  31. */
  32. #define SNDRV_EMUX_USE_RAW_EFFECT
  33. struct snd_emux;
  34. struct snd_emux_port;
  35. struct snd_emux_voice;
  36. struct snd_emux_effect_table;
  37. /*
  38. * operators
  39. */
  40. struct snd_emux_operators {
  41. struct module *owner;
  42. struct snd_emux_voice *(*get_voice)(struct snd_emux *emu,
  43. struct snd_emux_port *port);
  44. int (*prepare)(struct snd_emux_voice *vp);
  45. void (*trigger)(struct snd_emux_voice *vp);
  46. void (*release)(struct snd_emux_voice *vp);
  47. void (*update)(struct snd_emux_voice *vp, int update);
  48. void (*terminate)(struct snd_emux_voice *vp);
  49. void (*free_voice)(struct snd_emux_voice *vp);
  50. void (*reset)(struct snd_emux *emu, int ch);
  51. /* the first parameters are struct snd_emux */
  52. int (*sample_new)(struct snd_emux *emu, struct snd_sf_sample *sp,
  53. struct snd_util_memhdr *hdr,
  54. const void __user *data, long count);
  55. int (*sample_free)(struct snd_emux *emu, struct snd_sf_sample *sp,
  56. struct snd_util_memhdr *hdr);
  57. void (*sample_reset)(struct snd_emux *emu);
  58. int (*load_fx)(struct snd_emux *emu, int type, int arg,
  59. const void __user *data, long count);
  60. void (*sysex)(struct snd_emux *emu, char *buf, int len, int parsed,
  61. struct snd_midi_channel_set *chset);
  62. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  63. int (*oss_ioctl)(struct snd_emux *emu, int cmd, int p1, int p2);
  64. #endif
  65. };
  66. /*
  67. * constant values
  68. */
  69. #define SNDRV_EMUX_MAX_PORTS 32 /* max # of sequencer ports */
  70. #define SNDRV_EMUX_MAX_VOICES 64 /* max # of voices */
  71. #define SNDRV_EMUX_MAX_MULTI_VOICES 16 /* max # of playable voices
  72. * simultineously
  73. */
  74. /*
  75. * flags
  76. */
  77. #define SNDRV_EMUX_ACCEPT_ROM (1<<0)
  78. /*
  79. * emuX wavetable
  80. */
  81. struct snd_emux {
  82. struct snd_card *card; /* assigned card */
  83. /* following should be initialized before registration */
  84. int max_voices; /* Number of voices */
  85. int mem_size; /* memory size (in byte) */
  86. int num_ports; /* number of ports to be created */
  87. int pitch_shift; /* pitch shift value (for Emu10k1) */
  88. struct snd_emux_operators ops; /* operators */
  89. void *hw; /* hardware */
  90. unsigned long flags; /* other conditions */
  91. int midi_ports; /* number of virtual midi devices */
  92. int midi_devidx; /* device offset of virtual midi */
  93. unsigned int linear_panning: 1; /* panning is linear (sbawe = 1, emu10k1 = 0) */
  94. int hwdep_idx; /* hwdep device index */
  95. struct snd_hwdep *hwdep; /* hwdep device */
  96. /* private */
  97. int num_voices; /* current number of voices */
  98. struct snd_sf_list *sflist; /* root of SoundFont list */
  99. struct snd_emux_voice *voices; /* Voices (EMU 'channel') */
  100. int use_time; /* allocation counter */
  101. spinlock_t voice_lock; /* Lock for voice access */
  102. struct mutex register_mutex;
  103. int client; /* For the sequencer client */
  104. int ports[SNDRV_EMUX_MAX_PORTS]; /* The ports for this device */
  105. struct snd_emux_port *portptrs[SNDRV_EMUX_MAX_PORTS];
  106. int used; /* use counter */
  107. char *name; /* name of the device (internal) */
  108. struct snd_rawmidi **vmidi;
  109. struct timer_list tlist; /* for pending note-offs */
  110. int timer_active;
  111. struct snd_util_memhdr *memhdr; /* memory chunk information */
  112. #ifdef CONFIG_SND_PROC_FS
  113. struct snd_info_entry *proc;
  114. #endif
  115. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  116. struct snd_seq_device *oss_synth;
  117. #endif
  118. };
  119. /*
  120. * sequencer port information
  121. */
  122. struct snd_emux_port {
  123. struct snd_midi_channel_set chset;
  124. struct snd_emux *emu;
  125. char port_mode; /* operation mode */
  126. int volume_atten; /* emuX raw attenuation */
  127. unsigned long drum_flags; /* drum bitmaps */
  128. int ctrls[EMUX_MD_END]; /* control parameters */
  129. #ifdef SNDRV_EMUX_USE_RAW_EFFECT
  130. struct snd_emux_effect_table *effect;
  131. #endif
  132. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  133. struct snd_seq_oss_arg *oss_arg;
  134. #endif
  135. };
  136. /* port_mode */
  137. #define SNDRV_EMUX_PORT_MODE_MIDI 0 /* normal MIDI port */
  138. #define SNDRV_EMUX_PORT_MODE_OSS_SYNTH 1 /* OSS synth port */
  139. #define SNDRV_EMUX_PORT_MODE_OSS_MIDI 2 /* OSS multi channel synth port */
  140. /*
  141. * A structure to keep track of each hardware voice
  142. */
  143. struct snd_emux_voice {
  144. int ch; /* Hardware channel number */
  145. int state; /* status */
  146. #define SNDRV_EMUX_ST_OFF 0x00 /* Not playing, and inactive */
  147. #define SNDRV_EMUX_ST_ON 0x01 /* Note on */
  148. #define SNDRV_EMUX_ST_RELEASED (0x02|SNDRV_EMUX_ST_ON) /* Note released */
  149. #define SNDRV_EMUX_ST_SUSTAINED (0x04|SNDRV_EMUX_ST_ON) /* Note sustained */
  150. #define SNDRV_EMUX_ST_STANDBY (0x08|SNDRV_EMUX_ST_ON) /* Waiting to be triggered */
  151. #define SNDRV_EMUX_ST_PENDING (0x10|SNDRV_EMUX_ST_ON) /* Note will be released */
  152. #define SNDRV_EMUX_ST_LOCKED 0x100 /* Not accessible */
  153. unsigned int time; /* An allocation time */
  154. unsigned char note; /* Note currently assigned to this voice */
  155. unsigned char key;
  156. unsigned char velocity; /* Velocity of current note */
  157. struct snd_sf_zone *zone; /* Zone assigned to this note */
  158. void *block; /* sample block pointer (optional) */
  159. struct snd_midi_channel *chan; /* Midi channel for this note */
  160. struct snd_emux_port *port; /* associated port */
  161. struct snd_emux *emu; /* assigned root info */
  162. void *hw; /* hardware pointer (emu8000 or emu10k1) */
  163. unsigned long ontime; /* jiffies at note triggered */
  164. /* Emu8k/Emu10k1 registers */
  165. struct soundfont_voice_info reg;
  166. /* additional registers */
  167. int avol; /* volume attenuation */
  168. int acutoff; /* cutoff target */
  169. int apitch; /* pitch offset */
  170. int apan; /* pan/aux pair */
  171. int aaux;
  172. int ptarget; /* pitch target */
  173. int vtarget; /* volume target */
  174. int ftarget; /* filter target */
  175. };
  176. /*
  177. * update flags (can be combined)
  178. */
  179. #define SNDRV_EMUX_UPDATE_VOLUME (1<<0)
  180. #define SNDRV_EMUX_UPDATE_PITCH (1<<1)
  181. #define SNDRV_EMUX_UPDATE_PAN (1<<2)
  182. #define SNDRV_EMUX_UPDATE_FMMOD (1<<3)
  183. #define SNDRV_EMUX_UPDATE_TREMFREQ (1<<4)
  184. #define SNDRV_EMUX_UPDATE_FM2FRQ2 (1<<5)
  185. #define SNDRV_EMUX_UPDATE_Q (1<<6)
  186. #ifdef SNDRV_EMUX_USE_RAW_EFFECT
  187. /*
  188. * effect table
  189. */
  190. struct snd_emux_effect_table {
  191. /* Emu8000 specific effects */
  192. short val[EMUX_NUM_EFFECTS];
  193. unsigned char flag[EMUX_NUM_EFFECTS];
  194. };
  195. #endif /* SNDRV_EMUX_USE_RAW_EFFECT */
  196. /*
  197. * prototypes - interface to Emu10k1 and Emu8k routines
  198. */
  199. int snd_emux_new(struct snd_emux **remu);
  200. int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name);
  201. int snd_emux_free(struct snd_emux *emu);
  202. /*
  203. * exported functions
  204. */
  205. void snd_emux_terminate_all(struct snd_emux *emu);
  206. void snd_emux_lock_voice(struct snd_emux *emu, int voice);
  207. void snd_emux_unlock_voice(struct snd_emux *emu, int voice);
  208. #endif /* __SOUND_EMUX_SYNTH_H */