Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __SOUND_SOUNDFONT_H |
| 2 | #define __SOUND_SOUNDFONT_H |
| 3 | |
| 4 | /* |
| 5 | * Soundfont defines and definitions. |
| 6 | * |
| 7 | * Copyright (C) 1999 Steve Ratcliffe |
| 8 | * Copyright (c) 1999-2000 Takashi iwai <tiwai@suse.de> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include "sfnt_info.h" |
| 26 | #include "util_mem.h" |
| 27 | |
| 28 | #define SF_MAX_INSTRUMENTS 128 /* maximum instrument number */ |
| 29 | #define SF_MAX_PRESETS 256 /* drums are mapped from 128 to 256 */ |
| 30 | #define SF_IS_DRUM_BANK(z) ((z) == 128) |
| 31 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 32 | struct snd_sf_zone { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct snd_sf_zone *next; /* Link to next */ |
| 34 | unsigned char bank; /* Midi bank for this zone */ |
| 35 | unsigned char instr; /* Midi program for this zone */ |
| 36 | unsigned char mapped; /* True if mapped to something else */ |
| 37 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 38 | struct soundfont_voice_info v; /* All the soundfont parameters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | int counter; |
| 40 | struct snd_sf_sample *sample; /* Link to sample */ |
| 41 | |
| 42 | /* The following deals with preset numbers (programs) */ |
| 43 | struct snd_sf_zone *next_instr; /* Next zone of this instrument */ |
| 44 | struct snd_sf_zone *next_zone; /* Next zone in play list */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 45 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 47 | struct snd_sf_sample { |
| 48 | struct soundfont_sample_info v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | int counter; |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 50 | struct snd_util_memblk *block; /* allocated data block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | struct snd_sf_sample *next; |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 52 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * This represents all the information relating to a soundfont. |
| 56 | */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 57 | struct snd_soundfont { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | struct snd_soundfont *next; /* Link to next */ |
| 59 | /*struct snd_soundfont *prev;*/ /* Link to previous */ |
| 60 | short id; /* file id */ |
| 61 | short type; /* font type */ |
| 62 | unsigned char name[SNDRV_SFNT_PATCH_NAME_LEN]; /* identifier */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 63 | struct snd_sf_zone *zones; /* Font information */ |
| 64 | struct snd_sf_sample *samples; /* The sample headers */ |
| 65 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Type of the sample access callback |
| 69 | */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 70 | struct snd_sf_callback { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | void *private_data; |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 72 | int (*sample_new)(void *private_data, struct snd_sf_sample *sp, |
| 73 | struct snd_util_memhdr *hdr, |
| 74 | const void __user *buf, long count); |
| 75 | int (*sample_free)(void *private_data, struct snd_sf_sample *sp, |
| 76 | struct snd_util_memhdr *hdr); |
| 77 | void (*sample_reset)(void *private); |
| 78 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * List of soundfonts. |
| 82 | */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 83 | struct snd_sf_list { |
| 84 | struct snd_soundfont *currsf; /* The currently open soundfont */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | int open_client; /* client pointer for lock */ |
| 86 | int mem_used; /* used memory size */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 87 | struct snd_sf_zone *presets[SF_MAX_PRESETS]; |
| 88 | struct snd_soundfont *fonts; /* The list of soundfonts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | int fonts_size; /* number of fonts allocated */ |
| 90 | int zone_counter; /* last allocated time for zone */ |
| 91 | int sample_counter; /* last allocated time for sample */ |
| 92 | int zone_locked; /* locked time for zone */ |
| 93 | int sample_locked; /* locked time for sample */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 94 | struct snd_sf_callback callback; /* callback functions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int presets_locked; |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 96 | struct mutex presets_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | spinlock_t lock; |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 98 | struct snd_util_memhdr *memhdr; |
| 99 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* Prototypes for soundfont.c */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 102 | int snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data, |
| 103 | long count, int client); |
| 104 | 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] | 105 | long count, int client); |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 106 | int snd_soundfont_close_check(struct snd_sf_list *sflist, int client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 108 | struct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback, |
| 109 | struct snd_util_memhdr *hdr); |
| 110 | void snd_sf_free(struct snd_sf_list *sflist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 112 | int snd_soundfont_remove_samples(struct snd_sf_list *sflist); |
| 113 | int snd_soundfont_remove_unlocked(struct snd_sf_list *sflist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 115 | 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] | 116 | int preset, int bank, |
| 117 | int def_preset, int def_bank, |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 118 | struct snd_sf_zone **table, int max_layers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* Parameter conversions */ |
| 121 | int snd_sf_calc_parm_hold(int msec); |
| 122 | int snd_sf_calc_parm_attack(int msec); |
| 123 | int snd_sf_calc_parm_decay(int msec); |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 124 | #define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | extern int snd_sf_vol_table[128]; |
| 126 | int snd_sf_linear_to_log(unsigned int amount, int offset, int ratio); |
| 127 | |
| 128 | |
| 129 | #endif /* __SOUND_SOUNDFONT_H */ |