sound.c++
3.35 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
//====================================================================
// sound.c++
//
// Synopsis:
//
// Author(s)
// Steve Shepard
//
// 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 <stdlib.h>
#include "libbank.h"
ICSound::ICSound()
{
declclass = ICSOUND;
size = sizeof(ALSound);
samplePan = AL_PAN_CENTER;
sampleVolume = AL_VOL_FULL;
sound = 0;
wave = 0;
envelope = 0;
keymap = 0;
}
void ICSound::SetPan(int pan)
{
FailIf(((pan < AL_PAN_LEFT) || (pan > AL_PAN_RIGHT)), IC_PARAMETER_ERR);
samplePan = pan;
}
void ICSound::SetVol(int vol)
{
FailIf( (vol < 0) || (vol > AL_VOL_FULL), IC_PARAMETER_ERR);
sampleVolume = vol;
}
void ICSound::SetKeyMap(ICKeyMap *map)
{
FailIf(map->GetObjectClass() != ICKEYMAP, IC_TYPE_ERR);
keymap = map;
}
void ICSound::SetEnvelope(ICEnvelope *env)
{
FailIf(env->GetObjectClass() != ICENVELOPE, IC_TYPE_ERR);
envelope = env;
}
void ICSound::SetWaveTable(ICWave *w)
{
FailIf(w->GetObjectClass() != ICWAVE, IC_TYPE_ERR);
wave = w;
}
void ICSound::Assemble()
{
char msg[256];
FailIfMsg(!declid, IC_INTERNAL_ERR, "undeclared sound");
FailIfMsg(!keymap, IC_MISC_ERR,
icErrStr(msg, declid->name, " must have a keymap\n"));
FailIfMsg(!envelope, IC_MISC_ERR,
icErrStr(msg, declid->name, " must have an envelope\n"));
FailIfMsg(!wave, IC_MISC_ERR,
icErrStr(msg, declid->name,
" must have at least one wavetable\n"));
size = Size();
ALSound *s = (ALSound *)calloc(1, size);
FailIf(!s, IC_INTERNAL_ERR);
s->samplePan = samplePan;
s->sampleVolume = sampleVolume;
s->keyMap = (ALKeyMap *)keymap->GetObjectOffset();
s->envelope = (ALEnvelope *)envelope->GetObjectOffset();
s->wavetable = (ALWaveTable *)wave->GetObjectOffset();
sound = s;
thing = sound;
}
void ICSound::Prune()
{
this->IncRefCount();
keymap->Prune();
envelope->Prune();
wave->Prune();
}
void ICSound::MarkUsed(void)
{
if(!usedFlag)
usedFlag = TRUE;
keymap->MarkUsed();
envelope->MarkUsed();
wave->MarkUsed();
}
void ICSound::Print()
{
printf("Sound: %s\n", declid->name);
ICObject::Print();
printf("\twavetable:\t= %x\n", sound->wavetable);
printf("\tenvelope:\t= %x\n", sound->envelope);
printf("\tkey map:\t= %x\n", sound->keyMap);
printf("\tsamplePan:\t= %x\n", sound->samplePan);
printf("\tsampleVolume:\t= %x\n", sound->sampleVolume);
printf("\n");
}