Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __SOUND_SOUNDFONT_H
0003 #define __SOUND_SOUNDFONT_H
0004 
0005 /*
0006  *  Soundfont defines and definitions.
0007  *
0008  *  Copyright (C) 1999 Steve Ratcliffe
0009  *  Copyright (c) 1999-2000 Takashi iwai <tiwai@suse.de>
0010  */
0011 
0012 #include <sound/sfnt_info.h>
0013 #include <sound/util_mem.h>
0014 
0015 #define SF_MAX_INSTRUMENTS  128 /* maximum instrument number */
0016 #define SF_MAX_PRESETS  256 /* drums are mapped from 128 to 256 */
0017 #define SF_IS_DRUM_BANK(z) ((z) == 128)
0018 
0019 struct snd_sf_zone {
0020     struct snd_sf_zone *next;   /* Link to next */
0021     unsigned char bank;     /* Midi bank for this zone */
0022     unsigned char instr;        /* Midi program for this zone */
0023     unsigned char mapped;       /* True if mapped to something else */
0024 
0025     struct soundfont_voice_info v;  /* All the soundfont parameters */
0026     int counter;
0027     struct snd_sf_sample *sample;   /* Link to sample */
0028 
0029     /* The following deals with preset numbers (programs) */
0030     struct snd_sf_zone *next_instr; /* Next zone of this instrument */
0031     struct snd_sf_zone *next_zone;  /* Next zone in play list */
0032 };
0033 
0034 struct snd_sf_sample {
0035     struct soundfont_sample_info v;
0036     int counter;
0037     struct snd_util_memblk *block;  /* allocated data block */
0038     struct snd_sf_sample *next;
0039 };
0040 
0041 /*
0042  * This represents all the information relating to a soundfont.
0043  */
0044 struct snd_soundfont {
0045     struct snd_soundfont *next; /* Link to next */
0046     /*struct snd_soundfont *prev;*/ /* Link to previous */
0047     short  id;      /* file id */
0048     short  type;        /* font type */
0049     unsigned char name[SNDRV_SFNT_PATCH_NAME_LEN];  /* identifier */
0050     struct snd_sf_zone *zones; /* Font information */
0051     struct snd_sf_sample *samples; /* The sample headers */
0052 };
0053 
0054 /*
0055  * Type of the sample access callback
0056  */
0057 struct snd_sf_callback {
0058     void *private_data;
0059     int (*sample_new)(void *private_data, struct snd_sf_sample *sp,
0060               struct snd_util_memhdr *hdr,
0061               const void __user *buf, long count);
0062     int (*sample_free)(void *private_data, struct snd_sf_sample *sp,
0063                struct snd_util_memhdr *hdr);
0064     void (*sample_reset)(void *private);
0065 };
0066 
0067 /*
0068  * List of soundfonts.
0069  */
0070 struct snd_sf_list {
0071     struct snd_soundfont *currsf; /* The currently open soundfont */
0072     int open_client;    /* client pointer for lock */
0073     int mem_used;       /* used memory size */
0074     struct snd_sf_zone *presets[SF_MAX_PRESETS];
0075     struct snd_soundfont *fonts; /* The list of soundfonts */
0076     int fonts_size; /* number of fonts allocated */
0077     int zone_counter;   /* last allocated time for zone */
0078     int sample_counter; /* last allocated time for sample */
0079     int zone_locked;    /* locked time for zone */
0080     int sample_locked;  /* locked time for sample */
0081     struct snd_sf_callback callback;    /* callback functions */
0082     int presets_locked;
0083     struct mutex presets_mutex;
0084     spinlock_t lock;
0085     struct snd_util_memhdr *memhdr;
0086 };
0087 
0088 /* Prototypes for soundfont.c */
0089 int snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
0090                long count, int client);
0091 int snd_soundfont_load_guspatch(struct snd_sf_list *sflist, const char __user *data,
0092                 long count, int client);
0093 int snd_soundfont_close_check(struct snd_sf_list *sflist, int client);
0094 
0095 struct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback,
0096                    struct snd_util_memhdr *hdr);
0097 void snd_sf_free(struct snd_sf_list *sflist);
0098 
0099 int snd_soundfont_remove_samples(struct snd_sf_list *sflist);
0100 int snd_soundfont_remove_unlocked(struct snd_sf_list *sflist);
0101 
0102 int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
0103                   int preset, int bank,
0104                   int def_preset, int def_bank,
0105                   struct snd_sf_zone **table, int max_layers);
0106 
0107 /* Parameter conversions */
0108 int snd_sf_calc_parm_hold(int msec);
0109 int snd_sf_calc_parm_attack(int msec);
0110 int snd_sf_calc_parm_decay(int msec);
0111 #define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725)
0112 extern int snd_sf_vol_table[128];
0113 int snd_sf_linear_to_log(unsigned int amount, int offset, int ratio);
0114 
0115 
0116 #endif /* __SOUND_SOUNDFONT_H */