save.c
3.85 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
133
134
135
136
137
138
139
140
141
142
143
/*====================================================================
* save.c
*
* Copyright 1993, 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 <libaudio.h>
#include "synthInternals.h"
#include <em.h>
#include <os.h>
void alSaveNew(ALSave *f)
{
int i;
/*
* init filter superclass
*/
alFilterNew((ALFilter *) f, alSavePull, alSaveParam, AL_SAVE);
/*
* init the save state, which is a virtual dram address
*/
f->dramout = 0;
f->first = 1;
f->ratio = 1.0;
f->delta = 0.0;
}
Acmd *alSavePull(void *filter, short *outp, int outCount, int flags, Acmd *p)
{
Acmd *ptr = p;
ALSave *f = (ALSave *)filter;
ALFilter *source;
int inCount;
int incr;
float fCount;
/*
* determine how many samples to generate - should be a multiple of 8
*/
fCount = f->delta + (f->ratio * (float) outCount);
inCount = (int) fCount;
if (inCount & 0x7)
inCount += 8 - (inCount & 0x7);
f->delta = fCount - (float)inCount;
if (source = f->filter.source) {
ptr = (*source->handler)(source, outp, inCount, flags, ptr);
} else {
/* error */
}
if (f->ratio < 1.0){
incr = (int)(f->ratio * UNITY_PITCH);
/*
* Left channel
*/
aSetBuffer(ptr++, 0, AL_MAIN_L_OUT, 0, outCount<<1);
if (f->first){
aResample(ptr++, A_INIT, incr, osVirtualToPhysical(f->stateL.rstate));
} else
aResample(ptr++, A_OUT, incr, osVirtualToPhysical(f->stateL.rstate));
/*
* Right channel
*/
aSetBuffer(ptr++, 0, AL_MAIN_R_OUT, outCount<<1, outCount<<1);
if (f->first){
f->first = 0;
aResample(ptr++, A_INIT, incr, osVirtualToPhysical(f->stateR.rstate));
} else
aResample(ptr++, A_OUT, incr, osVirtualToPhysical(f->stateR.rstate));
aSetBuffer(ptr++, 0, 0, outCount<<2, outCount<<1);
aInterleave(ptr++, 0, outCount<<1);
aSetBuffer(ptr++, 0, 0, outCount<<2, outCount<<2);
aSaveBuffer(ptr++, f->dramout);
} else {
aSetBuffer(ptr++, 0, 0, 0, outCount<<1);
aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT);
aSetBuffer(ptr++, 0, 0, 0, outCount<<2);
aSaveBuffer(ptr++, f->dramout);
}
return ptr;
}
int alSaveParam(void *filter, int paramID, void *param)
{
ALSave *a = (ALSave *) filter;
ALFilter *f = (ALFilter *) filter;
int pp = (int) param;
union {
float f;
int i;
} data;
switch (paramID) {
case (AL_FILTER_SET_SOURCE):
f->source = (ALFilter *) param;
break;
case (AL_FILTER_SET_DRAM):
a->dramout = pp;
break;
case (AL_FILTER_SET_PITCH):
a->delta = 0.0;
data.i = (int) param;
a->ratio = data.f;
break;
default:
if (f->source)
(*f->source->setParam)(f, paramID, param);
break;
}
return 0;
}