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