soundfont.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "sfnt_info.h"
  24. #include "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. typedef 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. soundfont_voice_info_t 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. } snd_sf_zone_t;
  40. typedef struct snd_sf_sample {
  41. soundfont_sample_info_t v;
  42. int counter;
  43. snd_util_memblk_t *block; /* allocated data block */
  44. struct snd_sf_sample *next;
  45. } snd_sf_sample_t;
  46. /*
  47. * This represents all the information relating to a soundfont.
  48. */
  49. typedef 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. snd_sf_zone_t *zones; /* Font information */
  56. snd_sf_sample_t *samples; /* The sample headers */
  57. } snd_soundfont_t;
  58. /*
  59. * Type of the sample access callback
  60. */
  61. typedef int (*snd_sf_sample_new_t)(void *private_data, snd_sf_sample_t *sp,
  62. snd_util_memhdr_t *hdr, const void __user *buf, long count);
  63. typedef int (*snd_sf_sample_free_t)(void *private_data, snd_sf_sample_t *sp,
  64. snd_util_memhdr_t *hdr);
  65. typedef void (*snd_sf_sample_reset_t)(void *private);
  66. typedef struct snd_sf_callback {
  67. void *private_data;
  68. snd_sf_sample_new_t sample_new;
  69. snd_sf_sample_free_t sample_free;
  70. snd_sf_sample_reset_t sample_reset;
  71. } snd_sf_callback_t;
  72. /*
  73. * List of soundfonts.
  74. */
  75. typedef struct snd_sf_list {
  76. snd_soundfont_t *currsf; /* The currently open soundfont */
  77. int open_client; /* client pointer for lock */
  78. int mem_used; /* used memory size */
  79. snd_sf_zone_t *presets[SF_MAX_PRESETS];
  80. snd_soundfont_t *fonts; /* The list of soundfonts */
  81. int fonts_size; /* number of fonts allocated */
  82. int zone_counter; /* last allocated time for zone */
  83. int sample_counter; /* last allocated time for sample */
  84. int zone_locked; /* locked time for zone */
  85. int sample_locked; /* locked time for sample */
  86. snd_sf_callback_t callback; /* callback functions */
  87. int presets_locked;
  88. struct semaphore presets_mutex;
  89. spinlock_t lock;
  90. snd_util_memhdr_t *memhdr;
  91. } snd_sf_list_t;
  92. /* Prototypes for soundfont.c */
  93. int snd_soundfont_load(snd_sf_list_t *sflist, const void __user *data, long count, int client);
  94. int snd_soundfont_load_guspatch(snd_sf_list_t *sflist, const char __user *data,
  95. long count, int client);
  96. int snd_soundfont_close_check(snd_sf_list_t *sflist, int client);
  97. snd_sf_list_t *snd_sf_new(snd_sf_callback_t *callback, snd_util_memhdr_t *hdr);
  98. void snd_sf_free(snd_sf_list_t *sflist);
  99. int snd_soundfont_remove_samples(snd_sf_list_t *sflist);
  100. int snd_soundfont_remove_unlocked(snd_sf_list_t *sflist);
  101. int snd_soundfont_search_zone(snd_sf_list_t *sflist, int *notep, int vel,
  102. int preset, int bank,
  103. int def_preset, int def_bank,
  104. snd_sf_zone_t **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 */