162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci#ifndef __SOUND_SOUNDFONT_H 362306a36Sopenharmony_ci#define __SOUND_SOUNDFONT_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci/* 662306a36Sopenharmony_ci * Soundfont defines and definitions. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 1999 Steve Ratcliffe 962306a36Sopenharmony_ci * Copyright (c) 1999-2000 Takashi iwai <tiwai@suse.de> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <sound/sfnt_info.h> 1362306a36Sopenharmony_ci#include <sound/util_mem.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define SF_MAX_INSTRUMENTS 128 /* maximum instrument number */ 1662306a36Sopenharmony_ci#define SF_MAX_PRESETS 256 /* drums are mapped from 128 to 256 */ 1762306a36Sopenharmony_ci#define SF_IS_DRUM_BANK(z) ((z) == 128) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cistruct snd_sf_zone { 2062306a36Sopenharmony_ci struct snd_sf_zone *next; /* Link to next */ 2162306a36Sopenharmony_ci unsigned char bank; /* Midi bank for this zone */ 2262306a36Sopenharmony_ci unsigned char instr; /* Midi program for this zone */ 2362306a36Sopenharmony_ci unsigned char mapped; /* True if mapped to something else */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci struct soundfont_voice_info v; /* All the soundfont parameters */ 2662306a36Sopenharmony_ci int counter; 2762306a36Sopenharmony_ci struct snd_sf_sample *sample; /* Link to sample */ 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci /* The following deals with preset numbers (programs) */ 3062306a36Sopenharmony_ci struct snd_sf_zone *next_instr; /* Next zone of this instrument */ 3162306a36Sopenharmony_ci struct snd_sf_zone *next_zone; /* Next zone in play list */ 3262306a36Sopenharmony_ci}; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_cistruct snd_sf_sample { 3562306a36Sopenharmony_ci struct soundfont_sample_info v; 3662306a36Sopenharmony_ci int counter; 3762306a36Sopenharmony_ci struct snd_util_memblk *block; /* allocated data block */ 3862306a36Sopenharmony_ci struct snd_sf_sample *next; 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* 4262306a36Sopenharmony_ci * This represents all the information relating to a soundfont. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_cistruct snd_soundfont { 4562306a36Sopenharmony_ci struct snd_soundfont *next; /* Link to next */ 4662306a36Sopenharmony_ci /*struct snd_soundfont *prev;*/ /* Link to previous */ 4762306a36Sopenharmony_ci short id; /* file id */ 4862306a36Sopenharmony_ci short type; /* font type */ 4962306a36Sopenharmony_ci unsigned char name[SNDRV_SFNT_PATCH_NAME_LEN]; /* identifier */ 5062306a36Sopenharmony_ci struct snd_sf_zone *zones; /* Font information */ 5162306a36Sopenharmony_ci struct snd_sf_sample *samples; /* The sample headers */ 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* 5562306a36Sopenharmony_ci * Type of the sample access callback 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_cistruct snd_sf_callback { 5862306a36Sopenharmony_ci void *private_data; 5962306a36Sopenharmony_ci int (*sample_new)(void *private_data, struct snd_sf_sample *sp, 6062306a36Sopenharmony_ci struct snd_util_memhdr *hdr, 6162306a36Sopenharmony_ci const void __user *buf, long count); 6262306a36Sopenharmony_ci int (*sample_free)(void *private_data, struct snd_sf_sample *sp, 6362306a36Sopenharmony_ci struct snd_util_memhdr *hdr); 6462306a36Sopenharmony_ci void (*sample_reset)(void *private); 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/* 6862306a36Sopenharmony_ci * List of soundfonts. 6962306a36Sopenharmony_ci */ 7062306a36Sopenharmony_cistruct snd_sf_list { 7162306a36Sopenharmony_ci struct snd_soundfont *currsf; /* The currently open soundfont */ 7262306a36Sopenharmony_ci int open_client; /* client pointer for lock */ 7362306a36Sopenharmony_ci int mem_used; /* used memory size */ 7462306a36Sopenharmony_ci struct snd_sf_zone *presets[SF_MAX_PRESETS]; 7562306a36Sopenharmony_ci struct snd_soundfont *fonts; /* The list of soundfonts */ 7662306a36Sopenharmony_ci int fonts_size; /* number of fonts allocated */ 7762306a36Sopenharmony_ci int zone_counter; /* last allocated time for zone */ 7862306a36Sopenharmony_ci int sample_counter; /* last allocated time for sample */ 7962306a36Sopenharmony_ci int zone_locked; /* locked time for zone */ 8062306a36Sopenharmony_ci int sample_locked; /* locked time for sample */ 8162306a36Sopenharmony_ci struct snd_sf_callback callback; /* callback functions */ 8262306a36Sopenharmony_ci int presets_locked; 8362306a36Sopenharmony_ci struct mutex presets_mutex; 8462306a36Sopenharmony_ci spinlock_t lock; 8562306a36Sopenharmony_ci struct snd_util_memhdr *memhdr; 8662306a36Sopenharmony_ci}; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* Prototypes for soundfont.c */ 8962306a36Sopenharmony_ciint snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data, 9062306a36Sopenharmony_ci long count, int client); 9162306a36Sopenharmony_ciint snd_soundfont_load_guspatch(struct snd_sf_list *sflist, const char __user *data, 9262306a36Sopenharmony_ci long count, int client); 9362306a36Sopenharmony_ciint snd_soundfont_close_check(struct snd_sf_list *sflist, int client); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistruct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback, 9662306a36Sopenharmony_ci struct snd_util_memhdr *hdr); 9762306a36Sopenharmony_civoid snd_sf_free(struct snd_sf_list *sflist); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciint snd_soundfont_remove_samples(struct snd_sf_list *sflist); 10062306a36Sopenharmony_ciint snd_soundfont_remove_unlocked(struct snd_sf_list *sflist); 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciint snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel, 10362306a36Sopenharmony_ci int preset, int bank, 10462306a36Sopenharmony_ci int def_preset, int def_bank, 10562306a36Sopenharmony_ci struct snd_sf_zone **table, int max_layers); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* Parameter conversions */ 10862306a36Sopenharmony_ciint snd_sf_calc_parm_hold(int msec); 10962306a36Sopenharmony_ciint snd_sf_calc_parm_attack(int msec); 11062306a36Sopenharmony_ciint snd_sf_calc_parm_decay(int msec); 11162306a36Sopenharmony_ci#define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725) 11262306a36Sopenharmony_ciextern int snd_sf_vol_table[128]; 11362306a36Sopenharmony_ciint snd_sf_linear_to_log(unsigned int amount, int offset, int ratio); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#endif /* __SOUND_SOUNDFONT_H */ 117