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