Lines Matching +full:next +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Copyright (c) 1999-2000 Takashi Iwai <tiwai@suse.de>
69 scoped_guard(spinlock_irqsave, &sflist->lock) {
70 if (sflist->open_client != client)
94 dev_err(card->dev, "patch record too small %ld\n", count);
95 return -EINVAL;
98 return -EFAULT;
100 count -= sizeof(patch);
104 dev_err(card->dev, "The wrong kind of patch %x\n", patch.key);
105 return -EINVAL;
108 dev_err(card->dev, "Patch too short %ld, need %d\n",
110 return -EINVAL;
113 dev_err(card->dev, "poor length %d\n", patch.len);
114 return -EINVAL;
124 scoped_guard(spinlock_irqsave, &sflist->lock) {
125 if (sflist->open_client != client)
126 return -EBUSY;
130 rc = -EINVAL;
152 if (!sflist->currsf) {
153 dev_err(card->dev,
155 rc = -EINVAL;
160 if (! remove_info(sflist, sflist->currsf, bank, instr))
161 rc = -EINVAL;
172 /* check if specified type is special font (GUS or preset-alias) */
190 scoped_guard(spinlock_irqsave, &sflist->lock) {
191 if (sflist->open_client >= 0 || sflist->currsf)
192 return -EBUSY;
196 return -EFAULT;
204 return -ENOMEM;
207 scoped_guard(spinlock_irqsave, &sflist->lock) {
208 sflist->open_client = client;
209 sflist->currsf = sf;
225 for (sf = sflist->fonts; sf; sf = sf->next) {
232 /* not found -- create a new one */
236 sf->id = sflist->fonts_size;
237 sflist->fonts_size++;
240 sf->next = sflist->fonts;
241 sflist->fonts = sf;
243 sf->type = type;
244 sf->zones = NULL;
245 sf->samples = NULL;
247 memcpy(sf->name, name, SNDRV_SFNT_PATCH_NAME_LEN);
256 return ((sf->type & SNDRV_SFNT_PAT_SHARED) &&
257 (sf->type & 0x0f) == (type & 0x0f) &&
259 memcmp(sf->name, name, SNDRV_SFNT_PATCH_NAME_LEN) == 0));
268 scoped_guard(spinlock_irqsave, &sflist->lock) {
269 sflist->currsf = NULL;
270 sflist->open_client = -1;
279 /* probe sample in the current list -- nothing to be loaded */
284 if (sflist->currsf) {
286 if (find_sample(sflist->currsf, sample_id))
289 return -EINVAL;
299 zp->counter = sflist->zone_counter++;
300 if (sf->type & SNDRV_SFNT_PAT_LOCKED)
301 sflist->zone_locked = sflist->zone_counter;
315 zp->next = sf->zones;
316 sf->zones = zp;
318 init_voice_info(&zp->v);
332 sp->counter = sflist->sample_counter++;
333 if (sf->type & SNDRV_SFNT_PAT_LOCKED)
334 sflist->sample_locked = sflist->sample_counter;
349 sp->next = sf->samples;
350 sf->samples = sp;
357 * delete sample list -- this is an exceptional job.
365 if (sp == sf->samples) {
366 sf->samples = sp->next;
382 return -EINVAL;
384 return -EFAULT;
387 return -EINVAL;
391 return -ENOMEM;
394 for (zp = sf->zones; zp; prevp = zp, zp = zp->next) {
395 if (zp->mapped &&
396 zp->instr == map.map_instr &&
397 zp->bank == map.map_bank &&
398 zp->v.low == map.map_key &&
399 zp->v.start == map.src_instr &&
400 zp->v.end == map.src_bank &&
401 zp->v.fixkey == map.src_key) {
405 prevp->next = zp->next;
406 zp->next = sf->zones;
407 sf->zones = zp;
418 return -ENOMEM;
420 zp->bank = map.map_bank;
421 zp->instr = map.map_instr;
422 zp->mapped = 1;
424 zp->v.low = map.map_key;
425 zp->v.high = map.map_key;
427 zp->v.start = map.src_instr;
428 zp->v.end = map.src_bank;
429 zp->v.fixkey = map.src_key;
430 zp->v.sf_id = sf->id;
443 struct snd_sf_zone *prev, *next, *p;
447 for (p = sf->zones; p; p = next) {
448 next = p->next;
449 if (! p->mapped &&
450 p->bank == bank && p->instr == instr) {
453 prev->next = next;
455 sf->zones = next;
481 sf = sflist->currsf;
483 return -EINVAL;
485 if (is_special_type(sf->type))
486 return -EINVAL;
489 dev_err(card->dev, "Soundfont error: invalid patch zone length\n");
490 return -EINVAL;
493 return -EFAULT;
496 count -= sizeof(hdr);
499 dev_err(card->dev, "Soundfont error: Illegal voice number %d\n",
501 return -EINVAL;
505 dev_err(card->dev,
508 return -EINVAL;
513 /* exclusive mode - if the instrument already exists,
515 for (zone = sf->zones; zone; zone = zone->next) {
516 if (!zone->mapped &&
517 zone->bank == hdr.bank &&
518 zone->instr == hdr.instr)
519 return -EINVAL;
523 /* replace mode - remove the instrument if it already exists */
533 return -EFAULT;
537 count -= sizeof(tmpzone.v);
542 tmpzone.v.sf_id = sf->id;
543 if (tmpzone.v.mode & SNDRV_SFNT_MODE_INIT_PARM)
549 return -ENOMEM;
552 zone->bank = tmpzone.bank;
553 zone->instr = tmpzone.instr;
554 zone->v = tmpzone.v;
557 zone->sample = set_sample(sf, &zone->v);
570 avp->root = 60;
571 avp->high = 127;
572 avp->velhigh = 127;
573 avp->fixkey = -1;
574 avp->fixvel = -1;
575 avp->fixpan = -1;
576 avp->pan = -1;
577 avp->amplitude = 127;
578 avp->scaleTuning = 100;
580 init_voice_parm(&avp->parm);
594 pp->moddelay = 0x8000;
595 pp->modatkhld = 0x7f7f;
596 pp->moddcysus = 0x7f7f;
597 pp->modrelease = 0x807f;
599 pp->voldelay = 0x8000;
600 pp->volatkhld = 0x7f7f;
601 pp->voldcysus = 0x7f7f;
602 pp->volrelease = 0x807f;
604 pp->lfo1delay = 0x8000;
605 pp->lfo2delay = 0x8000;
607 pp->cutoff = 0xff;
616 sample = find_sample(sf, avp->sample);
625 avp->start += sample->v.start;
626 avp->end += sample->v.end;
627 avp->loopstart += sample->v.loopstart;
628 avp->loopend += sample->v.loopend;
630 /* copy mode flags */
631 avp->sample_mode = sample->v.mode_flags;
645 for (p = sf->samples; p; p = p->next) {
646 if (p->v.sample == sample_id)
656 if (si->end < 0 || si->end > si->size)
657 return -EINVAL;
658 if (si->loopstart < 0 || si->loopstart > si->end)
659 return -EINVAL;
660 if (si->loopend < 0 || si->loopend > si->end)
661 return -EINVAL;
663 if (si->loopstart > si->loopend)
664 swap(si->loopstart, si->loopend);
682 sf = sflist->currsf;
684 return -EINVAL;
686 if (is_special_type(sf->type))
687 return -EINVAL;
690 return -EINVAL;
693 return -EFAULT;
695 count -= sizeof(sample_info);
699 return -EINVAL;
704 if (sf->type & SNDRV_SFNT_PAT_SHARED)
706 return -EINVAL;
711 return -EINVAL;
715 sample_info.end -= sample_info.start;
716 sample_info.loopstart -= sample_info.start;
717 sample_info.loopend -= sample_info.start;
721 return -EINVAL;
727 return -ENOMEM;
729 sp->v = sample_info;
730 sp->v.sf_id = sf->id;
731 sp->v.dummy = 0;
732 sp->v.truesize = 0;
737 if (sp->v.size > 0) {
739 rc = sflist->callback.sample_new
740 (sflist->callback.private_data, sp, sflist->memhdr,
746 sflist->mem_used += sp->v.truesize;
797 v = (log_tbl[s + 1] * low + log_tbl[s] * (0x100 - low)) >> 8;
798 v -= offset;
800 v += (24 - bit) * ratio;
828 * eg, when rate is 22050, this offset becomes -4096.
844 r = (3 - ((rate >> 6) & 3)) * 3;
848 t = end - start;
849 if (t < 0) t = -t;
851 t = t << (13 - r);
853 t = t >> (r - 13);
882 /* delay time = 0x8000 - msec/92 */
886 int val = (0x7f * 92 - msec) / 92;
933 #define calc_gus_sustain(val) (0x7f - snd_sf_vol_table[(val)/2])
949 dev_err(card->dev, "patch record too small %ld\n", count);
950 return -EINVAL;
953 return -EFAULT;
954 count -= sizeof(patch);
957 if ((patch.len << (patch.mode & WAVE_16_BITS ? 1 : 0)) != count)
958 return -EINVAL;
962 return -ENOMEM;
965 return -ENOMEM;
966 sample_id = sflist->sample_counter;
967 smp->v.sample = sample_id;
968 smp->v.start = 0;
969 smp->v.end = patch.len;
970 smp->v.loopstart = patch.loop_start;
971 smp->v.loopend = patch.loop_end;
972 smp->v.size = patch.len;
974 if (validate_sample_info(&smp->v) < 0) {
976 return -EINVAL;
979 /* set up mode flags */
980 smp->v.mode_flags = 0;
981 if (!(patch.mode & WAVE_16_BITS))
982 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_8BITS;
983 if (patch.mode & WAVE_UNSIGNED)
984 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_UNSIGNED;
985 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_NO_BLANK;
986 if (!(patch.mode & (WAVE_LOOPING|WAVE_BIDIR_LOOP|WAVE_LOOP_BACK)))
987 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_SINGLESHOT;
988 if (patch.mode & WAVE_BIDIR_LOOP)
989 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_BIDIR_LOOP;
990 if (patch.mode & WAVE_LOOP_BACK)
991 smp->v.mode_flags |= SNDRV_SFNT_SAMPLE_REVERSE_LOOP;
993 if (patch.mode & WAVE_16_BITS) {
995 smp->v.size /= 2;
996 smp->v.end /= 2;
997 smp->v.loopstart /= 2;
998 smp->v.loopend /= 2;
1000 /*smp->v.loopend++;*/
1002 smp->v.dummy = 0;
1003 smp->v.truesize = 0;
1004 smp->v.sf_id = sf->id;
1010 return -ENOMEM;
1016 if (smp->v.size > 0) {
1017 rc = sflist->callback.sample_new
1018 (sflist->callback.private_data, smp, sflist->memhdr,
1029 sflist->mem_used += smp->v.truesize;
1031 zone->v.sample = sample_id; /* the last sample */
1032 zone->v.rate_offset = calc_rate_offset(patch.base_freq);
1034 zone->v.root = note / 100;
1035 zone->v.tune = -(note % 100);
1036 zone->v.low = (freq_to_note(patch.low_note) + 99) / 100;
1037 zone->v.high = freq_to_note(patch.high_note) / 100;
1038 /* panning position; -128 - 127 => 0-127 */
1039 zone->v.pan = (patch.panning + 128) / 2;
1042 "gus: basefrq=%d (ofs=%d) root=%d,tune=%d, range:%d-%d\n",
1043 (int)patch.base_freq, zone->v.rate_offset,
1044 zone->v.root, zone->v.tune, zone->v.low, zone->v.high);
1049 if (patch.mode & WAVE_ENVELOPES) {
1068 zone->v.parm.volatkhld =
1071 zone->v.parm.voldcysus = (calc_gus_sustain(patch.env_offset[2]) << 8) |
1073 zone->v.parm.volrelease = 0x8000 | snd_sf_calc_parm_decay(release);
1074 zone->v.attenuation = calc_gus_attenuation(patch.env_offset[0]);
1076 dev_dbg(card->dev,
1078 zone->v.parm.volatkhld,
1079 zone->v.parm.voldcysus,
1080 zone->v.parm.volrelease,
1081 zone->v.attenuation);
1086 if (patch.mode & WAVE_FAST_RELEASE) {
1087 zone->v.parm.volrelease = 0x807f;
1091 if (patch.mode & WAVE_TREMOLO) {
1093 zone->v.parm.tremfrq = ((patch.tremolo_depth / 2) << 8) | rate;
1096 if (patch.mode & WAVE_VIBRATO) {
1098 zone->v.parm.fm2frq2 = ((patch.vibrato_depth / 6) << 8) | rate;
1103 if (!(smp->v.mode_flags & SNDRV_SFNT_SAMPLE_SINGLESHOT))
1104 zone->v.mode = SNDRV_SFNT_MODE_LOOPING;
1106 zone->v.mode = 0;
1109 /*zone->bank = ctrls[AWE_MD_GUS_BANK];*/
1110 zone->bank = 0;
1111 zone->instr = patch.instr_no;
1112 zone->mapped = 0;
1113 zone->v.sf_id = sf->id;
1115 zone->sample = set_sample(sf, &zone->v);
1148 memset(sflist->presets, 0, sizeof(sflist->presets));
1151 for (sf = sflist->fonts; sf; sf = sf->next) {
1152 for (cur = sf->zones; cur; cur = cur->next) {
1153 if (! cur->mapped && cur->sample == NULL) {
1155 cur->sample = set_sample(sf, &cur->v);
1156 if (cur->sample == NULL)
1175 zone = search_first_zone(sflist, cur->bank, cur->instr, cur->v.low);
1176 if (zone && zone->v.sf_id != cur->v.sf_id) {
1180 for (p = zone; p; p = p->next_zone) {
1181 if (p->counter > cur->counter)
1191 index = get_index(cur->bank, cur->instr, cur->v.low);
1194 cur->next_zone = zone; /* zone link */
1195 cur->next_instr = sflist->presets[index]; /* preset table link */
1196 sflist->presets[index] = cur;
1208 index = get_index(zp->bank, zp->instr, zp->v.low);
1211 for (p = sflist->presets[index]; p; p = p->next_instr) {
1212 while (p->next_instr == zp) {
1213 p->next_instr = zp->next_instr;
1214 zp = zp->next_zone;
1241 guard(spinlock_irqsave)(&sflist->lock);
1242 if (sflist->presets_locked)
1268 for (zp = sflist->presets[index]; zp; zp = zp->next_instr) {
1269 if (zp->instr == preset && zp->bank == bank)
1289 for (; zp; zp = zp->next_zone) {
1290 if (*notep >= zp->v.low && *notep <= zp->v.high &&
1291 vel >= zp->v.vellow && vel <= zp->v.velhigh) {
1292 if (zp->mapped) {
1294 int key = zp->v.fixkey;
1295 preset = zp->v.start;
1296 bank = zp->v.end;
1322 * if the index is out of range, return -1.
1334 return -1;
1344 memset(sflist->presets, 0, sizeof(sflist->presets));
1346 sflist->mem_used = 0;
1347 sflist->currsf = NULL;
1348 sflist->open_client = -1;
1349 sflist->fonts = NULL;
1350 sflist->fonts_size = 0;
1351 sflist->zone_counter = 0;
1352 sflist->sample_counter = 0;
1353 sflist->zone_locked = 0;
1354 sflist->sample_locked = 0;
1367 for (sf = sflist->fonts; sf; sf = nextsf) {
1368 nextsf = sf->next;
1369 for (zp = sf->zones; zp; zp = nextzp) {
1370 nextzp = zp->next;
1373 for (sp = sf->samples; sp; sp = nextsp) {
1374 nextsp = sp->next;
1375 sflist->callback.sample_free(sflist->callback.private_data,
1376 sp, sflist->memhdr);
1398 mutex_init(&sflist->presets_mutex);
1399 spin_lock_init(&sflist->lock);
1400 sflist->memhdr = hdr;
1403 sflist->callback = *callback;
1420 if (sflist->callback.sample_reset)
1421 sflist->callback.sample_reset(sflist->callback.private_data);
1436 if (sflist->callback.sample_reset)
1437 sflist->callback.sample_reset(sflist->callback.private_data);
1456 if (sflist->callback.sample_reset)
1457 sflist->callback.sample_reset(sflist->callback.private_data);
1460 memset(sflist->presets, 0, sizeof(sflist->presets));
1462 for (sf = sflist->fonts; sf; sf = sf->next) {
1463 for (zp = sf->zones; zp; zp = nextzp) {
1464 if (zp->counter < sflist->zone_locked)
1466 nextzp = zp->next;
1467 sf->zones = nextzp;
1471 for (sp = sf->samples; sp; sp = nextsp) {
1472 if (sp->counter < sflist->sample_locked)
1474 nextsp = sp->next;
1475 sf->samples = nextsp;
1476 sflist->mem_used -= sp->v.truesize;
1477 sflist->callback.sample_free(sflist->callback.private_data,
1478 sp, sflist->memhdr);
1483 sflist->zone_counter = sflist->zone_locked;
1484 sflist->sample_counter = sflist->sample_locked;