soundfont.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_SOUNDFONT_H
  3. #define __SOUND_SOUNDFONT_H
  4. /*
  5. * Soundfont defines and definitions.
  6. *
  7. * Copyright (C) 1999 Steve Ratcliffe
  8. * Copyright (c) 1999-2000 Takashi iwai <[email protected]>
  9. */
  10. #include <sound/sfnt_info.h>
  11. #include <sound/util_mem.h>
  12. #define SF_MAX_INSTRUMENTS 128 /* maximum instrument number */
  13. #define SF_MAX_PRESETS 256 /* drums are mapped from 128 to 256 */
  14. #define SF_IS_DRUM_BANK(z) ((z) == 128)
  15. struct snd_sf_zone {
  16. struct snd_sf_zone *next; /* Link to next */
  17. unsigned char bank; /* Midi bank for this zone */
  18. unsigned char instr; /* Midi program for this zone */
  19. unsigned char mapped; /* True if mapped to something else */
  20. struct soundfont_voice_info v; /* All the soundfont parameters */
  21. int counter;
  22. struct snd_sf_sample *sample; /* Link to sample */
  23. /* The following deals with preset numbers (programs) */
  24. struct snd_sf_zone *next_instr; /* Next zone of this instrument */
  25. struct snd_sf_zone *next_zone; /* Next zone in play list */
  26. };
  27. struct snd_sf_sample {
  28. struct soundfont_sample_info v;
  29. int counter;
  30. struct snd_util_memblk *block; /* allocated data block */
  31. struct snd_sf_sample *next;
  32. };
  33. /*
  34. * This represents all the information relating to a soundfont.
  35. */
  36. struct snd_soundfont {
  37. struct snd_soundfont *next; /* Link to next */
  38. /*struct snd_soundfont *prev;*/ /* Link to previous */
  39. short id; /* file id */
  40. short type; /* font type */
  41. unsigned char name[SNDRV_SFNT_PATCH_NAME_LEN]; /* identifier */
  42. struct snd_sf_zone *zones; /* Font information */
  43. struct snd_sf_sample *samples; /* The sample headers */
  44. };
  45. /*
  46. * Type of the sample access callback
  47. */
  48. struct snd_sf_callback {
  49. void *private_data;
  50. int (*sample_new)(void *private_data, struct snd_sf_sample *sp,
  51. struct snd_util_memhdr *hdr,
  52. const void __user *buf, long count);
  53. int (*sample_free)(void *private_data, struct snd_sf_sample *sp,
  54. struct snd_util_memhdr *hdr);
  55. void (*sample_reset)(void *private);
  56. };
  57. /*
  58. * List of soundfonts.
  59. */
  60. struct snd_sf_list {
  61. struct snd_soundfont *currsf; /* The currently open soundfont */
  62. int open_client; /* client pointer for lock */
  63. int mem_used; /* used memory size */
  64. struct snd_sf_zone *presets[SF_MAX_PRESETS];
  65. struct snd_soundfont *fonts; /* The list of soundfonts */
  66. int fonts_size; /* number of fonts allocated */
  67. int zone_counter; /* last allocated time for zone */
  68. int sample_counter; /* last allocated time for sample */
  69. int zone_locked; /* locked time for zone */
  70. int sample_locked; /* locked time for sample */
  71. struct snd_sf_callback callback; /* callback functions */
  72. int presets_locked;
  73. struct mutex presets_mutex;
  74. spinlock_t lock;
  75. struct snd_util_memhdr *memhdr;
  76. };
  77. /* Prototypes for soundfont.c */
  78. int snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
  79. long count, int client);
  80. int snd_soundfont_load_guspatch(struct snd_sf_list *sflist, const char __user *data,
  81. long count, int client);
  82. int snd_soundfont_close_check(struct snd_sf_list *sflist, int client);
  83. struct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback,
  84. struct snd_util_memhdr *hdr);
  85. void snd_sf_free(struct snd_sf_list *sflist);
  86. int snd_soundfont_remove_samples(struct snd_sf_list *sflist);
  87. int snd_soundfont_remove_unlocked(struct snd_sf_list *sflist);
  88. int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
  89. int preset, int bank,
  90. int def_preset, int def_bank,
  91. struct snd_sf_zone **table, int max_layers);
  92. /* Parameter conversions */
  93. int snd_sf_calc_parm_hold(int msec);
  94. int snd_sf_calc_parm_attack(int msec);
  95. int snd_sf_calc_parm_decay(int msec);
  96. #define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725)
  97. extern int snd_sf_vol_table[128];
  98. int snd_sf_linear_to_log(unsigned int amount, int offset, int ratio);
  99. #endif /* __SOUND_SOUNDFONT_H */