soundfont.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __SOUND_SOUNDFONT_H
  2. #define __SOUND_SOUNDFONT_H
  3. /*
  4. * Soundfont defines and definitions.
  5. *
  6. * Copyright (C) 1999 Steve Ratcliffe
  7. * Copyright (c) 1999-2000 Takashi iwai <tiwai@suse.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <sound/sfnt_info.h>
  24. #include <sound/util_mem.h>
  25. #define SF_MAX_INSTRUMENTS 128 /* maximum instrument number */
  26. #define SF_MAX_PRESETS 256 /* drums are mapped from 128 to 256 */
  27. #define SF_IS_DRUM_BANK(z) ((z) == 128)
  28. struct snd_sf_zone {
  29. struct snd_sf_zone *next; /* Link to next */
  30. unsigned char bank; /* Midi bank for this zone */
  31. unsigned char instr; /* Midi program for this zone */
  32. unsigned char mapped; /* True if mapped to something else */
  33. struct soundfont_voice_info v; /* All the soundfont parameters */
  34. int counter;
  35. struct snd_sf_sample *sample; /* Link to sample */
  36. /* The following deals with preset numbers (programs) */
  37. struct snd_sf_zone *next_instr; /* Next zone of this instrument */
  38. struct snd_sf_zone *next_zone; /* Next zone in play list */
  39. };
  40. struct snd_sf_sample {
  41. struct soundfont_sample_info v;
  42. int counter;
  43. struct snd_util_memblk *block; /* allocated data block */
  44. struct snd_sf_sample *next;
  45. };
  46. /*
  47. * This represents all the information relating to a soundfont.
  48. */
  49. struct snd_soundfont {
  50. struct snd_soundfont *next; /* Link to next */
  51. /*struct snd_soundfont *prev;*/ /* Link to previous */
  52. short id; /* file id */
  53. short type; /* font type */
  54. unsigned char name[SNDRV_SFNT_PATCH_NAME_LEN]; /* identifier */
  55. struct snd_sf_zone *zones; /* Font information */
  56. struct snd_sf_sample *samples; /* The sample headers */
  57. };
  58. /*
  59. * Type of the sample access callback
  60. */
  61. struct snd_sf_callback {
  62. void *private_data;
  63. int (*sample_new)(void *private_data, struct snd_sf_sample *sp,
  64. struct snd_util_memhdr *hdr,
  65. const void __user *buf, long count);
  66. int (*sample_free)(void *private_data, struct snd_sf_sample *sp,
  67. struct snd_util_memhdr *hdr);
  68. void (*sample_reset)(void *private);
  69. };
  70. /*
  71. * List of soundfonts.
  72. */
  73. struct snd_sf_list {
  74. struct snd_soundfont *currsf; /* The currently open soundfont */
  75. int open_client; /* client pointer for lock */
  76. int mem_used; /* used memory size */
  77. struct snd_sf_zone *presets[SF_MAX_PRESETS];
  78. struct snd_soundfont *fonts; /* The list of soundfonts */
  79. int fonts_size; /* number of fonts allocated */
  80. int zone_counter; /* last allocated time for zone */
  81. int sample_counter; /* last allocated time for sample */
  82. int zone_locked; /* locked time for zone */
  83. int sample_locked; /* locked time for sample */
  84. struct snd_sf_callback callback; /* callback functions */
  85. int presets_locked;
  86. struct mutex presets_mutex;
  87. spinlock_t lock;
  88. struct snd_util_memhdr *memhdr;
  89. };
  90. /* Prototypes for soundfont.c */
  91. int snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
  92. long count, int client);
  93. int snd_soundfont_load_guspatch(struct snd_sf_list *sflist, const char __user *data,
  94. long count, int client);
  95. int snd_soundfont_close_check(struct snd_sf_list *sflist, int client);
  96. struct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback,
  97. struct snd_util_memhdr *hdr);
  98. void snd_sf_free(struct snd_sf_list *sflist);
  99. int snd_soundfont_remove_samples(struct snd_sf_list *sflist);
  100. int snd_soundfont_remove_unlocked(struct snd_sf_list *sflist);
  101. int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
  102. int preset, int bank,
  103. int def_preset, int def_bank,
  104. struct snd_sf_zone **table, int max_layers);
  105. /* Parameter conversions */
  106. int snd_sf_calc_parm_hold(int msec);
  107. int snd_sf_calc_parm_attack(int msec);
  108. int snd_sf_calc_parm_decay(int msec);
  109. #define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725)
  110. extern int snd_sf_vol_table[128];
  111. int snd_sf_linear_to_log(unsigned int amount, int offset, int ratio);
  112. #endif /* __SOUND_SOUNDFONT_H */