1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*4882a593Smuzhiyun #ifndef __SOUND_EMUX_SYNTH_H 3*4882a593Smuzhiyun #define __SOUND_EMUX_SYNTH_H 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun /* 6*4882a593Smuzhiyun * Defines for the Emu-series WaveTable chip 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de> 9*4882a593Smuzhiyun */ 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun #include <sound/seq_kernel.h> 12*4882a593Smuzhiyun #include <sound/seq_device.h> 13*4882a593Smuzhiyun #include <sound/soundfont.h> 14*4882a593Smuzhiyun #include <sound/seq_midi_emul.h> 15*4882a593Smuzhiyun #include <sound/seq_oss.h> 16*4882a593Smuzhiyun #include <sound/emux_legacy.h> 17*4882a593Smuzhiyun #include <sound/seq_virmidi.h> 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun /* 20*4882a593Smuzhiyun * compile flags 21*4882a593Smuzhiyun */ 22*4882a593Smuzhiyun #define SNDRV_EMUX_USE_RAW_EFFECT 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun struct snd_emux; 25*4882a593Smuzhiyun struct snd_emux_port; 26*4882a593Smuzhiyun struct snd_emux_voice; 27*4882a593Smuzhiyun struct snd_emux_effect_table; 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun /* 30*4882a593Smuzhiyun * operators 31*4882a593Smuzhiyun */ 32*4882a593Smuzhiyun struct snd_emux_operators { 33*4882a593Smuzhiyun struct module *owner; 34*4882a593Smuzhiyun struct snd_emux_voice *(*get_voice)(struct snd_emux *emu, 35*4882a593Smuzhiyun struct snd_emux_port *port); 36*4882a593Smuzhiyun int (*prepare)(struct snd_emux_voice *vp); 37*4882a593Smuzhiyun void (*trigger)(struct snd_emux_voice *vp); 38*4882a593Smuzhiyun void (*release)(struct snd_emux_voice *vp); 39*4882a593Smuzhiyun void (*update)(struct snd_emux_voice *vp, int update); 40*4882a593Smuzhiyun void (*terminate)(struct snd_emux_voice *vp); 41*4882a593Smuzhiyun void (*free_voice)(struct snd_emux_voice *vp); 42*4882a593Smuzhiyun void (*reset)(struct snd_emux *emu, int ch); 43*4882a593Smuzhiyun /* the first parameters are struct snd_emux */ 44*4882a593Smuzhiyun int (*sample_new)(struct snd_emux *emu, struct snd_sf_sample *sp, 45*4882a593Smuzhiyun struct snd_util_memhdr *hdr, 46*4882a593Smuzhiyun const void __user *data, long count); 47*4882a593Smuzhiyun int (*sample_free)(struct snd_emux *emu, struct snd_sf_sample *sp, 48*4882a593Smuzhiyun struct snd_util_memhdr *hdr); 49*4882a593Smuzhiyun void (*sample_reset)(struct snd_emux *emu); 50*4882a593Smuzhiyun int (*load_fx)(struct snd_emux *emu, int type, int arg, 51*4882a593Smuzhiyun const void __user *data, long count); 52*4882a593Smuzhiyun void (*sysex)(struct snd_emux *emu, char *buf, int len, int parsed, 53*4882a593Smuzhiyun struct snd_midi_channel_set *chset); 54*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) 55*4882a593Smuzhiyun int (*oss_ioctl)(struct snd_emux *emu, int cmd, int p1, int p2); 56*4882a593Smuzhiyun #endif 57*4882a593Smuzhiyun }; 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun /* 61*4882a593Smuzhiyun * constant values 62*4882a593Smuzhiyun */ 63*4882a593Smuzhiyun #define SNDRV_EMUX_MAX_PORTS 32 /* max # of sequencer ports */ 64*4882a593Smuzhiyun #define SNDRV_EMUX_MAX_VOICES 64 /* max # of voices */ 65*4882a593Smuzhiyun #define SNDRV_EMUX_MAX_MULTI_VOICES 16 /* max # of playable voices 66*4882a593Smuzhiyun * simultineously 67*4882a593Smuzhiyun */ 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun /* 70*4882a593Smuzhiyun * flags 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun #define SNDRV_EMUX_ACCEPT_ROM (1<<0) 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /* 75*4882a593Smuzhiyun * emuX wavetable 76*4882a593Smuzhiyun */ 77*4882a593Smuzhiyun struct snd_emux { 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun struct snd_card *card; /* assigned card */ 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun /* following should be initialized before registration */ 82*4882a593Smuzhiyun int max_voices; /* Number of voices */ 83*4882a593Smuzhiyun int mem_size; /* memory size (in byte) */ 84*4882a593Smuzhiyun int num_ports; /* number of ports to be created */ 85*4882a593Smuzhiyun int pitch_shift; /* pitch shift value (for Emu10k1) */ 86*4882a593Smuzhiyun struct snd_emux_operators ops; /* operators */ 87*4882a593Smuzhiyun void *hw; /* hardware */ 88*4882a593Smuzhiyun unsigned long flags; /* other conditions */ 89*4882a593Smuzhiyun int midi_ports; /* number of virtual midi devices */ 90*4882a593Smuzhiyun int midi_devidx; /* device offset of virtual midi */ 91*4882a593Smuzhiyun unsigned int linear_panning: 1; /* panning is linear (sbawe = 1, emu10k1 = 0) */ 92*4882a593Smuzhiyun int hwdep_idx; /* hwdep device index */ 93*4882a593Smuzhiyun struct snd_hwdep *hwdep; /* hwdep device */ 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun /* private */ 96*4882a593Smuzhiyun int num_voices; /* current number of voices */ 97*4882a593Smuzhiyun struct snd_sf_list *sflist; /* root of SoundFont list */ 98*4882a593Smuzhiyun struct snd_emux_voice *voices; /* Voices (EMU 'channel') */ 99*4882a593Smuzhiyun int use_time; /* allocation counter */ 100*4882a593Smuzhiyun spinlock_t voice_lock; /* Lock for voice access */ 101*4882a593Smuzhiyun struct mutex register_mutex; 102*4882a593Smuzhiyun int client; /* For the sequencer client */ 103*4882a593Smuzhiyun int ports[SNDRV_EMUX_MAX_PORTS]; /* The ports for this device */ 104*4882a593Smuzhiyun struct snd_emux_port *portptrs[SNDRV_EMUX_MAX_PORTS]; 105*4882a593Smuzhiyun int used; /* use counter */ 106*4882a593Smuzhiyun char *name; /* name of the device (internal) */ 107*4882a593Smuzhiyun struct snd_rawmidi **vmidi; 108*4882a593Smuzhiyun struct timer_list tlist; /* for pending note-offs */ 109*4882a593Smuzhiyun int timer_active; 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun struct snd_util_memhdr *memhdr; /* memory chunk information */ 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun #ifdef CONFIG_SND_PROC_FS 114*4882a593Smuzhiyun struct snd_info_entry *proc; 115*4882a593Smuzhiyun #endif 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) 118*4882a593Smuzhiyun struct snd_seq_device *oss_synth; 119*4882a593Smuzhiyun #endif 120*4882a593Smuzhiyun }; 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun /* 124*4882a593Smuzhiyun * sequencer port information 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun struct snd_emux_port { 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun struct snd_midi_channel_set chset; 129*4882a593Smuzhiyun struct snd_emux *emu; 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun char port_mode; /* operation mode */ 132*4882a593Smuzhiyun int volume_atten; /* emuX raw attenuation */ 133*4882a593Smuzhiyun unsigned long drum_flags; /* drum bitmaps */ 134*4882a593Smuzhiyun int ctrls[EMUX_MD_END]; /* control parameters */ 135*4882a593Smuzhiyun #ifdef SNDRV_EMUX_USE_RAW_EFFECT 136*4882a593Smuzhiyun struct snd_emux_effect_table *effect; 137*4882a593Smuzhiyun #endif 138*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) 139*4882a593Smuzhiyun struct snd_seq_oss_arg *oss_arg; 140*4882a593Smuzhiyun #endif 141*4882a593Smuzhiyun }; 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun /* port_mode */ 144*4882a593Smuzhiyun #define SNDRV_EMUX_PORT_MODE_MIDI 0 /* normal MIDI port */ 145*4882a593Smuzhiyun #define SNDRV_EMUX_PORT_MODE_OSS_SYNTH 1 /* OSS synth port */ 146*4882a593Smuzhiyun #define SNDRV_EMUX_PORT_MODE_OSS_MIDI 2 /* OSS multi channel synth port */ 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun /* 149*4882a593Smuzhiyun * A structure to keep track of each hardware voice 150*4882a593Smuzhiyun */ 151*4882a593Smuzhiyun struct snd_emux_voice { 152*4882a593Smuzhiyun int ch; /* Hardware channel number */ 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun int state; /* status */ 155*4882a593Smuzhiyun #define SNDRV_EMUX_ST_OFF 0x00 /* Not playing, and inactive */ 156*4882a593Smuzhiyun #define SNDRV_EMUX_ST_ON 0x01 /* Note on */ 157*4882a593Smuzhiyun #define SNDRV_EMUX_ST_RELEASED (0x02|SNDRV_EMUX_ST_ON) /* Note released */ 158*4882a593Smuzhiyun #define SNDRV_EMUX_ST_SUSTAINED (0x04|SNDRV_EMUX_ST_ON) /* Note sustained */ 159*4882a593Smuzhiyun #define SNDRV_EMUX_ST_STANDBY (0x08|SNDRV_EMUX_ST_ON) /* Waiting to be triggered */ 160*4882a593Smuzhiyun #define SNDRV_EMUX_ST_PENDING (0x10|SNDRV_EMUX_ST_ON) /* Note will be released */ 161*4882a593Smuzhiyun #define SNDRV_EMUX_ST_LOCKED 0x100 /* Not accessible */ 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun unsigned int time; /* An allocation time */ 164*4882a593Smuzhiyun unsigned char note; /* Note currently assigned to this voice */ 165*4882a593Smuzhiyun unsigned char key; 166*4882a593Smuzhiyun unsigned char velocity; /* Velocity of current note */ 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun struct snd_sf_zone *zone; /* Zone assigned to this note */ 169*4882a593Smuzhiyun void *block; /* sample block pointer (optional) */ 170*4882a593Smuzhiyun struct snd_midi_channel *chan; /* Midi channel for this note */ 171*4882a593Smuzhiyun struct snd_emux_port *port; /* associated port */ 172*4882a593Smuzhiyun struct snd_emux *emu; /* assigned root info */ 173*4882a593Smuzhiyun void *hw; /* hardware pointer (emu8000 or emu10k1) */ 174*4882a593Smuzhiyun unsigned long ontime; /* jiffies at note triggered */ 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun /* Emu8k/Emu10k1 registers */ 177*4882a593Smuzhiyun struct soundfont_voice_info reg; 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun /* additional registers */ 180*4882a593Smuzhiyun int avol; /* volume attenuation */ 181*4882a593Smuzhiyun int acutoff; /* cutoff target */ 182*4882a593Smuzhiyun int apitch; /* pitch offset */ 183*4882a593Smuzhiyun int apan; /* pan/aux pair */ 184*4882a593Smuzhiyun int aaux; 185*4882a593Smuzhiyun int ptarget; /* pitch target */ 186*4882a593Smuzhiyun int vtarget; /* volume target */ 187*4882a593Smuzhiyun int ftarget; /* filter target */ 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun }; 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun /* 192*4882a593Smuzhiyun * update flags (can be combined) 193*4882a593Smuzhiyun */ 194*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_VOLUME (1<<0) 195*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_PITCH (1<<1) 196*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_PAN (1<<2) 197*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_FMMOD (1<<3) 198*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_TREMFREQ (1<<4) 199*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_FM2FRQ2 (1<<5) 200*4882a593Smuzhiyun #define SNDRV_EMUX_UPDATE_Q (1<<6) 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun #ifdef SNDRV_EMUX_USE_RAW_EFFECT 204*4882a593Smuzhiyun /* 205*4882a593Smuzhiyun * effect table 206*4882a593Smuzhiyun */ 207*4882a593Smuzhiyun struct snd_emux_effect_table { 208*4882a593Smuzhiyun /* Emu8000 specific effects */ 209*4882a593Smuzhiyun short val[EMUX_NUM_EFFECTS]; 210*4882a593Smuzhiyun unsigned char flag[EMUX_NUM_EFFECTS]; 211*4882a593Smuzhiyun }; 212*4882a593Smuzhiyun #endif /* SNDRV_EMUX_USE_RAW_EFFECT */ 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun /* 216*4882a593Smuzhiyun * prototypes - interface to Emu10k1 and Emu8k routines 217*4882a593Smuzhiyun */ 218*4882a593Smuzhiyun int snd_emux_new(struct snd_emux **remu); 219*4882a593Smuzhiyun int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name); 220*4882a593Smuzhiyun int snd_emux_free(struct snd_emux *emu); 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun /* 223*4882a593Smuzhiyun * exported functions 224*4882a593Smuzhiyun */ 225*4882a593Smuzhiyun void snd_emux_terminate_all(struct snd_emux *emu); 226*4882a593Smuzhiyun void snd_emux_lock_voice(struct snd_emux *emu, int voice); 227*4882a593Smuzhiyun void snd_emux_unlock_voice(struct snd_emux *emu, int voice); 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun #endif /* __SOUND_EMUX_SYNTH_H */ 230