emux_synth.h 6.8 KB

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