1 | /*
|
---|
2 | * Soundfont defines and definitions.
|
---|
3 | *
|
---|
4 | * Copyright (C) 1999 Steve Ratcliffe
|
---|
5 | * Copyright (c) 1999-2000 Takashi iwai <tiwai@suse.de>
|
---|
6 | *
|
---|
7 | * This program is free software; you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation; either version 2 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This program is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with this program; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef __SOUNDFONT_H
|
---|
23 | #define __SOUNDFONT_H
|
---|
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 |
|
---|
32 | typedef struct snd_sf_zone {
|
---|
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 |
|
---|
38 | soundfont_voice_info_t v; /* All the soundfont parameters */
|
---|
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 */
|
---|
45 | } snd_sf_zone_t;
|
---|
46 |
|
---|
47 | typedef struct snd_sf_sample {
|
---|
48 | soundfont_sample_info_t v;
|
---|
49 | int counter;
|
---|
50 | snd_util_memblk_t *block; /* allocated data block */
|
---|
51 | struct snd_sf_sample *next;
|
---|
52 | } snd_sf_sample_t;
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * This represents all the information relating to a soundfont.
|
---|
56 | */
|
---|
57 | typedef struct snd_soundfont {
|
---|
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 */
|
---|
63 | snd_sf_zone_t *zones; /* Font information */
|
---|
64 | snd_sf_sample_t *samples; /* The sample headers */
|
---|
65 | } snd_soundfont_t;
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Type of the sample access callback
|
---|
69 | */
|
---|
70 | typedef int (*snd_sf_sample_new_t)(void *private_data, snd_sf_sample_t *sp,
|
---|
71 | snd_util_memhdr_t *hdr, const void *buf, long count);
|
---|
72 | typedef int (*snd_sf_sample_free_t)(void *private_data, snd_sf_sample_t *sp,
|
---|
73 | snd_util_memhdr_t *hdr);
|
---|
74 | typedef void (*snd_sf_sample_reset_t)(void *private);
|
---|
75 |
|
---|
76 | typedef struct snd_sf_callback {
|
---|
77 | void *private_data;
|
---|
78 | snd_sf_sample_new_t sample_new;
|
---|
79 | snd_sf_sample_free_t sample_free;
|
---|
80 | snd_sf_sample_reset_t sample_reset;
|
---|
81 | } snd_sf_callback_t;
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * List of soundfonts.
|
---|
85 | */
|
---|
86 | typedef struct snd_sf_list {
|
---|
87 | snd_soundfont_t *currsf; /* The currently open soundfont */
|
---|
88 | int open_client; /* client pointer for lock */
|
---|
89 | int mem_used; /* used memory size */
|
---|
90 | snd_sf_zone_t *presets[SF_MAX_PRESETS];
|
---|
91 | snd_soundfont_t *fonts; /* The list of soundfonts */
|
---|
92 | int fonts_size; /* number of fonts allocated */
|
---|
93 | int zone_counter; /* last allocated time for zone */
|
---|
94 | int sample_counter; /* last allocated time for sample */
|
---|
95 | int zone_locked; /* locked time for zone */
|
---|
96 | int sample_locked; /* locked time for sample */
|
---|
97 | snd_sf_callback_t callback; /* callback functions */
|
---|
98 | char sf_locked; /* font lock flag */
|
---|
99 | struct semaphore presets_mutex;
|
---|
100 | spinlock_t lock;
|
---|
101 | snd_util_memhdr_t *memhdr;
|
---|
102 | } snd_sf_list_t;
|
---|
103 |
|
---|
104 | /* Prototypes for soundfont.c */
|
---|
105 | int snd_soundfont_load(snd_sf_list_t *sflist, const void *data, long count, int client);
|
---|
106 | int snd_soundfont_load_guspatch(snd_sf_list_t *sflist, const char *data,
|
---|
107 | long count, int client);
|
---|
108 | int snd_soundfont_close_check(snd_sf_list_t *sflist, int client);
|
---|
109 |
|
---|
110 | snd_sf_list_t *snd_sf_new(snd_sf_callback_t *callback, snd_util_memhdr_t *hdr);
|
---|
111 | void snd_sf_free(snd_sf_list_t *sflist);
|
---|
112 |
|
---|
113 | int snd_soundfont_remove_samples(snd_sf_list_t *sflist);
|
---|
114 | int snd_soundfont_remove_unlocked(snd_sf_list_t *sflist);
|
---|
115 | int snd_soundfont_mem_used(snd_sf_list_t *sflist);
|
---|
116 |
|
---|
117 | int snd_soundfont_search_zone(snd_sf_list_t *sflist, int *notep, int vel,
|
---|
118 | int preset, int bank,
|
---|
119 | int def_preset, int def_bank,
|
---|
120 | snd_sf_zone_t **table, int max_layers);
|
---|
121 |
|
---|
122 | /* Parameter conversions */
|
---|
123 | int snd_sf_calc_parm_hold(int msec);
|
---|
124 | int snd_sf_calc_parm_attack(int msec);
|
---|
125 | int snd_sf_calc_parm_decay(int msec);
|
---|
126 | #define snd_sf_calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725);
|
---|
127 | extern int snd_sf_vol_table[128];
|
---|
128 |
|
---|
129 |
|
---|
130 | #endif
|
---|