opl4_local.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Local definitions for the OPL4 driver
  3. *
  4. * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * Alternatively, this software may be distributed and/or modified under the
  17. * terms of the GNU General Public License as published by the Free Software
  18. * Foundation; either version 2 of the License, or (at your option) any later
  19. * version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  25. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. */
  33. #ifndef __OPL4_LOCAL_H
  34. #define __OPL4_LOCAL_H
  35. #include <sound/opl4.h>
  36. /*
  37. * Register numbers
  38. */
  39. #define OPL4_REG_TEST0 0x00
  40. #define OPL4_REG_TEST1 0x01
  41. #define OPL4_REG_MEMORY_CONFIGURATION 0x02
  42. #define OPL4_MODE_BIT 0x01
  43. #define OPL4_MTYPE_BIT 0x02
  44. #define OPL4_TONE_HEADER_MASK 0x1c
  45. #define OPL4_DEVICE_ID_MASK 0xe0
  46. #define OPL4_REG_MEMORY_ADDRESS_HIGH 0x03
  47. #define OPL4_REG_MEMORY_ADDRESS_MID 0x04
  48. #define OPL4_REG_MEMORY_ADDRESS_LOW 0x05
  49. #define OPL4_REG_MEMORY_DATA 0x06
  50. /*
  51. * Offsets to the register banks for voices. To get the
  52. * register number just add the voice number to the bank offset.
  53. *
  54. * Wave Table Number low bits (0x08 to 0x1F)
  55. */
  56. #define OPL4_REG_TONE_NUMBER 0x08
  57. /* Wave Table Number high bit, F-Number low bits (0x20 to 0x37) */
  58. #define OPL4_REG_F_NUMBER 0x20
  59. #define OPL4_TONE_NUMBER_BIT8 0x01
  60. #define OPL4_F_NUMBER_LOW_MASK 0xfe
  61. /* F-Number high bits, Octave, Pseudo-Reverb (0x38 to 0x4F) */
  62. #define OPL4_REG_OCTAVE 0x38
  63. #define OPL4_F_NUMBER_HIGH_MASK 0x07
  64. #define OPL4_BLOCK_MASK 0xf0
  65. #define OPL4_PSEUDO_REVERB_BIT 0x08
  66. /* Total Level, Level Direct (0x50 to 0x67) */
  67. #define OPL4_REG_LEVEL 0x50
  68. #define OPL4_TOTAL_LEVEL_MASK 0xfe
  69. #define OPL4_LEVEL_DIRECT_BIT 0x01
  70. /* Key On, Damp, LFO RST, CH, Panpot (0x68 to 0x7F) */
  71. #define OPL4_REG_MISC 0x68
  72. #define OPL4_KEY_ON_BIT 0x80
  73. #define OPL4_DAMP_BIT 0x40
  74. #define OPL4_LFO_RESET_BIT 0x20
  75. #define OPL4_OUTPUT_CHANNEL_BIT 0x10
  76. #define OPL4_PAN_POT_MASK 0x0f
  77. /* LFO, VIB (0x80 to 0x97) */
  78. #define OPL4_REG_LFO_VIBRATO 0x80
  79. #define OPL4_LFO_FREQUENCY_MASK 0x38
  80. #define OPL4_VIBRATO_DEPTH_MASK 0x07
  81. #define OPL4_CHORUS_SEND_MASK 0xc0 /* ML only */
  82. /* Attack / Decay 1 rate (0x98 to 0xAF) */
  83. #define OPL4_REG_ATTACK_DECAY1 0x98
  84. #define OPL4_ATTACK_RATE_MASK 0xf0
  85. #define OPL4_DECAY1_RATE_MASK 0x0f
  86. /* Decay level / 2 rate (0xB0 to 0xC7) */
  87. #define OPL4_REG_LEVEL_DECAY2 0xb0
  88. #define OPL4_DECAY_LEVEL_MASK 0xf0
  89. #define OPL4_DECAY2_RATE_MASK 0x0f
  90. /* Release rate / Rate correction (0xC8 to 0xDF) */
  91. #define OPL4_REG_RELEASE_CORRECTION 0xc8
  92. #define OPL4_RELEASE_RATE_MASK 0x0f
  93. #define OPL4_RATE_INTERPOLATION_MASK 0xf0
  94. /* AM (0xE0 to 0xF7) */
  95. #define OPL4_REG_TREMOLO 0xe0
  96. #define OPL4_TREMOLO_DEPTH_MASK 0x07
  97. #define OPL4_REVERB_SEND_MASK 0xe0 /* ML only */
  98. /* Mixer */
  99. #define OPL4_REG_MIX_CONTROL_FM 0xf8
  100. #define OPL4_REG_MIX_CONTROL_PCM 0xf9
  101. #define OPL4_MIX_LEFT_MASK 0x07
  102. #define OPL4_MIX_RIGHT_MASK 0x38
  103. #define OPL4_REG_ATC 0xfa
  104. #define OPL4_ATC_BIT 0x01 /* ???, ML only */
  105. /* bits in the OPL3 Status register */
  106. #define OPL4_STATUS_BUSY 0x01
  107. #define OPL4_STATUS_LOAD 0x02
  108. #define OPL4_MAX_VOICES 24
  109. #define SNDRV_SEQ_DEV_ID_OPL4 "opl4-synth"
  110. struct opl4_sound {
  111. u16 tone;
  112. s16 pitch_offset;
  113. u8 key_scaling;
  114. s8 panpot;
  115. u8 vibrato;
  116. u8 tone_attenuate;
  117. u8 volume_factor;
  118. u8 reg_lfo_vibrato;
  119. u8 reg_attack_decay1;
  120. u8 reg_level_decay2;
  121. u8 reg_release_correction;
  122. u8 reg_tremolo;
  123. };
  124. struct opl4_region {
  125. u8 key_min, key_max;
  126. struct opl4_sound sound;
  127. };
  128. struct opl4_region_ptr {
  129. int count;
  130. const struct opl4_region *regions;
  131. };
  132. struct opl4_voice {
  133. struct list_head list;
  134. int number;
  135. struct snd_midi_channel *chan;
  136. int note;
  137. int velocity;
  138. const struct opl4_sound *sound;
  139. u8 level_direct;
  140. u8 reg_f_number;
  141. u8 reg_misc;
  142. u8 reg_lfo_vibrato;
  143. };
  144. struct snd_opl4 {
  145. unsigned long fm_port;
  146. unsigned long pcm_port;
  147. struct resource *res_fm_port;
  148. struct resource *res_pcm_port;
  149. unsigned short hardware;
  150. spinlock_t reg_lock;
  151. struct snd_card *card;
  152. #ifdef CONFIG_PROC_FS
  153. struct snd_info_entry *proc_entry;
  154. int memory_access;
  155. #endif
  156. struct mutex access_mutex;
  157. #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
  158. int used;
  159. int seq_dev_num;
  160. int seq_client;
  161. struct snd_seq_device *seq_dev;
  162. struct snd_midi_channel_set *chset;
  163. struct opl4_voice voices[OPL4_MAX_VOICES];
  164. struct list_head off_voices;
  165. struct list_head on_voices;
  166. #endif
  167. };
  168. /* opl4_lib.c */
  169. void snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value);
  170. u8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg);
  171. void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size);
  172. void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size);
  173. /* opl4_mixer.c */
  174. int snd_opl4_create_mixer(struct snd_opl4 *opl4);
  175. #ifdef CONFIG_PROC_FS
  176. /* opl4_proc.c */
  177. int snd_opl4_create_proc(struct snd_opl4 *opl4);
  178. void snd_opl4_free_proc(struct snd_opl4 *opl4);
  179. #endif
  180. /* opl4_seq.c */
  181. extern int volume_boost;
  182. /* opl4_synth.c */
  183. void snd_opl4_synth_reset(struct snd_opl4 *opl4);
  184. void snd_opl4_synth_shutdown(struct snd_opl4 *opl4);
  185. void snd_opl4_note_on(void *p, int note, int vel, struct snd_midi_channel *chan);
  186. void snd_opl4_note_off(void *p, int note, int vel, struct snd_midi_channel *chan);
  187. void snd_opl4_terminate_note(void *p, int note, struct snd_midi_channel *chan);
  188. void snd_opl4_control(void *p, int type, struct snd_midi_channel *chan);
  189. void snd_opl4_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset);
  190. /* yrw801.c */
  191. int snd_yrw801_detect(struct snd_opl4 *opl4);
  192. extern const struct opl4_region_ptr snd_yrw801_regions[];
  193. #endif /* __OPL4_LOCAL_H */