eas_sndlib.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*----------------------------------------------------------------------------
  2. *
  3. * File:
  4. * eas_sndlib.h
  5. *
  6. * Contents and purpose:
  7. * Declarations for the sound library
  8. *
  9. * Copyright Sonic Network Inc. 2005
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. *----------------------------------------------------------------------------
  23. * Revision Control:
  24. * $Revision: 550 $
  25. * $Date: 2007-02-02 09:37:03 -0800 (Fri, 02 Feb 2007) $
  26. *----------------------------------------------------------------------------
  27. */
  28. #ifndef _EAS_SNDLIB_H
  29. #define _EAS_SNDLIB_H
  30. #include "eas_types.h"
  31. #include "eas_synthcfg.h"
  32. #ifdef _WT_SYNTH
  33. #include "eas_wtengine.h"
  34. #endif
  35. /*----------------------------------------------------------------------------
  36. * This is bit of a hack to allow us to keep the same structure
  37. * declarations for the DLS parser. Normally, the data is located
  38. * in read-only memory, but for DLS, we store the data in RW
  39. * memory.
  40. *----------------------------------------------------------------------------
  41. */
  42. #ifndef SCNST
  43. #define SCNST const
  44. #endif
  45. /*----------------------------------------------------------------------------
  46. * sample size
  47. *----------------------------------------------------------------------------
  48. */
  49. #ifdef _16_BIT_SAMPLES
  50. typedef EAS_I16 EAS_SAMPLE;
  51. #else
  52. typedef EAS_I8 EAS_SAMPLE;
  53. #endif
  54. /*----------------------------------------------------------------------------
  55. * EAS Library ID - quick check for valid library and version
  56. *----------------------------------------------------------------------------
  57. */
  58. #define _EAS_LIBRARY_VERSION 0x01534145
  59. #define NUM_PROGRAMS_IN_BANK 128
  60. #define INVALID_REGION_INDEX 0xffff
  61. /* this bit in region index indicates that region is for secondary synth */
  62. #define FLAG_RGN_IDX_FM_SYNTH 0x8000
  63. #define FLAG_RGN_IDX_DLS_SYNTH 0x4000
  64. #define REGION_INDEX_MASK 0x3fff
  65. /*----------------------------------------------------------------------------
  66. * Generic region data structure
  67. *
  68. * This must be the first element in each region structure
  69. *----------------------------------------------------------------------------
  70. */
  71. typedef struct s_region_tag
  72. {
  73. EAS_U16 keyGroupAndFlags;
  74. EAS_U8 rangeLow;
  75. EAS_U8 rangeHigh;
  76. } S_REGION;
  77. /*
  78. * Bit fields for m_nKeyGroupAndFlags
  79. * Bits 0-2 are mode bits in FM synth
  80. * Bits 8-11 are the key group
  81. */
  82. #define REGION_FLAG_IS_LOOPED 0x01
  83. #define REGION_FLAG_USE_WAVE_GENERATOR 0x02
  84. #define REGION_FLAG_USE_ADPCM 0x04
  85. #define REGION_FLAG_ONE_SHOT 0x08
  86. #define REGION_FLAG_SQUARE_WAVE 0x10
  87. #define REGION_FLAG_OFF_CHIP 0x20
  88. #define REGION_FLAG_NON_SELF_EXCLUSIVE 0x40
  89. #define REGION_FLAG_LAST_REGION 0x8000
  90. /*----------------------------------------------------------------------------
  91. * Envelope data structure
  92. *----------------------------------------------------------------------------
  93. */
  94. typedef struct s_envelope_tag
  95. {
  96. EAS_I16 attackTime;
  97. EAS_I16 decayTime;
  98. EAS_I16 sustainLevel;
  99. EAS_I16 releaseTime;
  100. } S_ENVELOPE;
  101. /*----------------------------------------------------------------------------
  102. * DLS envelope data structure
  103. *----------------------------------------------------------------------------
  104. */
  105. typedef struct s_dls_envelope_tag
  106. {
  107. EAS_I16 delayTime;
  108. EAS_I16 attackTime;
  109. EAS_I16 holdTime;
  110. EAS_I16 decayTime;
  111. EAS_I16 sustainLevel;
  112. EAS_I16 releaseTime;
  113. EAS_I16 velToAttack;
  114. EAS_I16 keyNumToDecay;
  115. EAS_I16 keyNumToHold;
  116. } S_DLS_ENVELOPE;
  117. /*----------------------------------------------------------------------------
  118. * LFO data structure
  119. *----------------------------------------------------------------------------
  120. */
  121. typedef struct s_lfo_params_tag
  122. {
  123. EAS_I16 lfoFreq;
  124. EAS_I16 lfoDelay;
  125. } S_LFO_PARAMS;
  126. /*----------------------------------------------------------------------------
  127. * Articulation data structure
  128. *----------------------------------------------------------------------------
  129. */
  130. typedef struct s_articulation_tag
  131. {
  132. S_ENVELOPE eg1;
  133. S_ENVELOPE eg2;
  134. EAS_I16 lfoToPitch;
  135. EAS_I16 lfoDelay;
  136. EAS_I16 lfoFreq;
  137. EAS_I16 eg2ToPitch;
  138. EAS_I16 eg2ToFc;
  139. EAS_I16 filterCutoff;
  140. EAS_I8 lfoToGain;
  141. EAS_U8 filterQ;
  142. EAS_I8 pan;
  143. } S_ARTICULATION;
  144. /*----------------------------------------------------------------------------
  145. * DLS articulation data structure
  146. *----------------------------------------------------------------------------
  147. */
  148. typedef struct s_dls_articulation_tag
  149. {
  150. S_LFO_PARAMS modLFO;
  151. S_LFO_PARAMS vibLFO;
  152. S_DLS_ENVELOPE eg1;
  153. S_DLS_ENVELOPE eg2;
  154. EAS_I16 eg1ShutdownTime;
  155. EAS_I16 filterCutoff;
  156. EAS_I16 modLFOToFc;
  157. EAS_I16 modLFOCC1ToFc;
  158. EAS_I16 modLFOChanPressToFc;
  159. EAS_I16 eg2ToFc;
  160. EAS_I16 velToFc;
  161. EAS_I16 keyNumToFc;
  162. EAS_I16 modLFOToGain;
  163. EAS_I16 modLFOCC1ToGain;
  164. EAS_I16 modLFOChanPressToGain;
  165. EAS_I16 tuning;
  166. EAS_I16 keyNumToPitch;
  167. EAS_I16 vibLFOToPitch;
  168. EAS_I16 vibLFOCC1ToPitch;
  169. EAS_I16 vibLFOChanPressToPitch;
  170. EAS_I16 modLFOToPitch;
  171. EAS_I16 modLFOCC1ToPitch;
  172. EAS_I16 modLFOChanPressToPitch;
  173. EAS_I16 eg2ToPitch;
  174. /* pad to 4-byte boundary */
  175. EAS_U16 pad;
  176. EAS_I8 pan;
  177. EAS_U8 filterQandFlags;
  178. #ifdef _REVERB
  179. EAS_I16 reverbSend;
  180. EAS_I16 cc91ToReverbSend;
  181. #endif
  182. #ifdef _CHORUS
  183. EAS_I16 chorusSend;
  184. EAS_I16 cc93ToChorusSend;
  185. #endif
  186. } S_DLS_ARTICULATION;
  187. /* flags in filterQandFlags
  188. * NOTE: Q is stored in bottom 5 bits
  189. */
  190. #define FLAG_DLS_VELOCITY_SENSITIVE 0x80
  191. #define FILTER_Q_MASK 0x1f
  192. /*----------------------------------------------------------------------------
  193. * Wavetable region data structure
  194. *----------------------------------------------------------------------------
  195. */
  196. typedef struct s_wt_region_tag
  197. {
  198. S_REGION region;
  199. EAS_I16 tuning;
  200. EAS_I16 gain;
  201. EAS_U32 loopStart;
  202. EAS_U32 loopEnd;
  203. EAS_U16 waveIndex;
  204. EAS_U16 artIndex;
  205. } S_WT_REGION;
  206. /*----------------------------------------------------------------------------
  207. * DLS region data structure
  208. *----------------------------------------------------------------------------
  209. */
  210. typedef struct s_dls_region_tag
  211. {
  212. S_WT_REGION wtRegion;
  213. EAS_U8 velLow;
  214. EAS_U8 velHigh;
  215. } S_DLS_REGION;
  216. /*----------------------------------------------------------------------------
  217. * FM synthesizer data structures
  218. *----------------------------------------------------------------------------
  219. */
  220. typedef struct s_fm_oper_tag
  221. {
  222. EAS_I16 tuning;
  223. EAS_U8 attackDecay;
  224. EAS_U8 velocityRelease;
  225. EAS_U8 egKeyScale;
  226. EAS_U8 sustain;
  227. EAS_U8 gain;
  228. EAS_U8 flags;
  229. } S_FM_OPER;
  230. /* defines for S_FM_OPER.m_nFlags */
  231. #define FM_OPER_FLAG_MONOTONE 0x01
  232. #define FM_OPER_FLAG_NO_VIBRATO 0x02
  233. #define FM_OPER_FLAG_NOISE 0x04
  234. #define FM_OPER_FLAG_LINEAR_VELOCITY 0x08
  235. /* NOTE: The first two structure elements are common with S_WT_REGION
  236. * and we will rely on that in the voice management code and must
  237. * remain there unless the voice management code is revisited.
  238. */
  239. typedef struct s_fm_region_tag
  240. {
  241. S_REGION region;
  242. EAS_U8 vibTrem;
  243. EAS_U8 lfoFreqDelay;
  244. EAS_U8 feedback;
  245. EAS_I8 pan;
  246. S_FM_OPER oper[4];
  247. } S_FM_REGION;
  248. /*----------------------------------------------------------------------------
  249. * Common data structures
  250. *----------------------------------------------------------------------------
  251. */
  252. /*----------------------------------------------------------------------------
  253. * Program data structure
  254. * Used for individual programs not stored as a complete bank.
  255. *----------------------------------------------------------------------------
  256. */
  257. typedef struct s_program_tag
  258. {
  259. EAS_U32 locale;
  260. EAS_U16 regionIndex;
  261. } S_PROGRAM;
  262. /*----------------------------------------------------------------------------
  263. * Bank data structure
  264. *
  265. * A bank always consists of 128 programs. If a bank is less than 128
  266. * programs, it should be stored as a spare matrix in the pPrograms
  267. * array.
  268. *
  269. * bankNum: MSB/LSB of MIDI bank select controller
  270. * regionIndex: Index of first region in program
  271. *----------------------------------------------------------------------------
  272. */
  273. typedef struct s_bank_tag
  274. {
  275. EAS_U16 locale;
  276. EAS_U16 regionIndex[NUM_PROGRAMS_IN_BANK];
  277. } S_BANK;
  278. /* defines for libFormat field
  279. * bits 0-17 are the sample rate
  280. * bit 18 is true if wavetable is present
  281. * bit 19 is true if FM is present
  282. * bit 20 is true if filter is enabled
  283. * bit 21 is sample depth (0 = 8-bits, 1 = 16-bits)
  284. * bits 22-31 are reserved
  285. */
  286. #define LIBFORMAT_SAMPLE_RATE_MASK 0x0003ffff
  287. #define LIB_FORMAT_TYPE_MASK 0x000c0000
  288. #define LIB_FORMAT_WAVETABLE 0x00000000
  289. #define LIB_FORMAT_FM 0x00040000
  290. #define LIB_FORMAT_HYBRID 0x00080000
  291. #define LIB_FORMAT_FILTER_ENABLED 0x00100000
  292. #define LIB_FORMAT_16_BIT_SAMPLES 0x00200000
  293. #ifdef DLS_SYNTHESIZER
  294. /*----------------------------------------------------------------------------
  295. * DLS data structure
  296. *
  297. * pDLSPrograms pointer to array of DLS programs
  298. * pDLSRegions pointer to array of DLS regions
  299. * pDLSArticulations pointer to array of DLS articulations
  300. * pSampleLen pointer to array of sample lengths
  301. * ppSamples pointer to array of sample pointers
  302. * numDLSPrograms number of DLS programs
  303. * numDLSRegions number of DLS regions
  304. * numDLSArticulations number of DLS articulations
  305. * numDLSSamples number of DLS samples
  306. *----------------------------------------------------------------------------
  307. */
  308. typedef struct s_eas_dls_tag
  309. {
  310. S_PROGRAM *pDLSPrograms;
  311. S_DLS_REGION *pDLSRegions;
  312. S_DLS_ARTICULATION *pDLSArticulations;
  313. EAS_U32 *pDLSSampleLen;
  314. EAS_U32 *pDLSSampleOffsets;
  315. EAS_SAMPLE *pDLSSamples;
  316. EAS_U16 numDLSPrograms;
  317. EAS_U16 numDLSRegions;
  318. EAS_U16 numDLSArticulations;
  319. EAS_U16 numDLSSamples;
  320. EAS_U8 refCount;
  321. } S_DLS;
  322. #endif
  323. /*----------------------------------------------------------------------------
  324. * Sound library data structure
  325. *
  326. * pBanks pointer to array of banks
  327. * pPrograms pointer to array of programs
  328. * pWTRegions pointer to array of wavetable regions
  329. * pFMRegions pointer to array of FM regions
  330. * pArticulations pointer to array of articulations
  331. * pSampleLen pointer to array of sample lengths
  332. * ppSamples pointer to array of sample pointers
  333. * numBanks number of banks
  334. * numPrograms number of individual program
  335. * numRegions number of regions
  336. * numArticulations number of articulations
  337. * numSamples number of samples
  338. *----------------------------------------------------------------------------
  339. */
  340. typedef struct s_eas_sndlib_tag
  341. {
  342. SCNST EAS_U32 identifier;
  343. SCNST EAS_U32 libAttr;
  344. SCNST S_BANK *pBanks;
  345. SCNST S_PROGRAM *pPrograms;
  346. SCNST S_WT_REGION *pWTRegions;
  347. SCNST S_ARTICULATION *pArticulations;
  348. SCNST EAS_U32 *pSampleLen;
  349. SCNST EAS_U32 *pSampleOffsets;
  350. SCNST EAS_SAMPLE *pSamples;
  351. SCNST S_FM_REGION *pFMRegions;
  352. SCNST EAS_U16 numBanks;
  353. SCNST EAS_U16 numPrograms;
  354. SCNST EAS_U16 numWTRegions;
  355. SCNST EAS_U16 numArticulations;
  356. SCNST EAS_U16 numSamples;
  357. SCNST EAS_U16 numFMRegions;
  358. } S_EAS;
  359. #endif