synallocvoice.c
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*====================================================================
* synallocvoice.c
*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <os_internal.h>
#include <ultraerror.h>
#include "synthInternals.h"
s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority);
s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc)
{
PVoice *pvoice = 0;
ALFilter *f;
ALParam *update;
s32 stolen;
#ifdef _DEBUG
/* need two updates if voice is stolen */
if (drvr->paramList == 0) {
__osError(ERR_ALSYN_NO_UPDATE, 0);
return 0;
} else if (drvr->paramList->next == 0) {
__osError(ERR_ALSYN_NO_UPDATE, 0);
return 0;
}
#endif
voice->priority = vc->priority;
voice->unityPitch = vc->unityPitch;
voice->table = 0;
voice->fxBus = vc->fxBus;
voice->state = AL_STOPPED;
voice->pvoice = 0;
stolen = _allocatePVoice(drvr, &pvoice, vc->priority);
if (pvoice) { /* if we were able to allocate a voice */
f = pvoice->channelKnob;
if (stolen) {
pvoice->offset = 512;
pvoice->vvoice->pvoice = 0; /* zero stolen voice */
/*
* ramp down stolen voice
*/
update = __allocParam();
update->delta = drvr->paramSamples;
update->type = AL_FILTER_SET_VOLUME;
update->data.i = 0;
update->moredata.i = pvoice->offset - 64;
(*f->setParam)(f, AL_FILTER_ADD_UPDATE, update);
/*
* stop stolen voice
*/
update = __allocParam();
if (update) {
update->delta = drvr->paramSamples + pvoice->offset;
update->type = AL_FILTER_STOP_VOICE;
update->next = 0;
(*f->setParam)(f, AL_FILTER_ADD_UPDATE, update);
} else {
#ifdef _DEBUG
__osError(ERR_ALSYN_NO_UPDATE, 0);
#endif
}
} else {
pvoice->offset = 0;
}
pvoice->vvoice = voice; /* assign new voice */
voice->pvoice = pvoice;
}
return (pvoice != 0);
}
s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority)
{
ALLink *dl;
PVoice *pv;
s32 stolen = 0;
if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */
*pvoice = (PVoice *) dl;
alUnlink(dl);
alLink(dl, &drvr->pAllocList);
} else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */
*pvoice = (PVoice *) dl;
alUnlink(dl);
alLink(dl, &drvr->pAllocList);
} else { /* steal one */
for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) {
pv = (PVoice *)dl;
/*
* if it is lower priority and not already stolen, keep it
* as a candidate for stealing
*/
if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) {
*pvoice = pv;
priority = pv->vvoice->priority;
stolen = 1;
}
}
}
return stolen;
}