emux_synth.h 7.5 KB

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