~ubuntu-branches/ubuntu/jaunty/openal-soft/jaunty

« back to all changes in this revision

Viewing changes to OpenAL32/alListener.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-06-07 17:44:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080607174448-fmamd83uujnkhutw
Tags: upstream-1.3.253
ImportĀ upstreamĀ versionĀ 1.3.253

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * OpenAL cross platform audio library
 
3
 * Copyright (C) 1999-2000 by authors.
 
4
 * This library is free software; you can redistribute it and/or
 
5
 *  modify it under the terms of the GNU Library General Public
 
6
 *  License as published by the Free Software Foundation; either
 
7
 *  version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 *  Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 *  License along with this library; if not, write to the
 
16
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 *  Boston, MA  02111-1307, USA.
 
18
 * Or go to http://www.gnu.org/copyleft/lgpl.html
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include "alMain.h"
 
24
#include "AL/alc.h"
 
25
#include "alError.h"
 
26
#include "alListener.h"
 
27
 
 
28
ALAPI ALvoid ALAPIENTRY alListenerf(ALenum eParam, ALfloat flValue)
 
29
{
 
30
    ALCcontext *pContext;
 
31
 
 
32
    pContext = alcGetCurrentContext();
 
33
    if (pContext)
 
34
    {
 
35
        SuspendContext(pContext);
 
36
 
 
37
        switch (eParam)
 
38
        {
 
39
        case AL_GAIN:
 
40
            if (flValue >= 0.0f)
 
41
                pContext->Listener.Gain = flValue;
 
42
            else
 
43
                alSetError(AL_INVALID_VALUE);
 
44
            break;
 
45
 
 
46
        case AL_METERS_PER_UNIT:
 
47
            if (flValue > 0.0f)
 
48
                pContext->Listener.MetersPerUnit = flValue;
 
49
            else
 
50
                alSetError(AL_INVALID_VALUE);
 
51
            break;
 
52
 
 
53
        default:
 
54
            alSetError(AL_INVALID_ENUM);
 
55
            break;
 
56
        }
 
57
 
 
58
        ProcessContext(pContext);
 
59
    }
 
60
    else
 
61
        alSetError(AL_INVALID_OPERATION);
 
62
 
 
63
    return;
 
64
}
 
65
 
 
66
 
 
67
ALAPI ALvoid ALAPIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
 
68
{
 
69
    ALCcontext *pContext;
 
70
 
 
71
    pContext = alcGetCurrentContext();
 
72
    if (pContext)
 
73
    {
 
74
        SuspendContext(pContext);
 
75
 
 
76
        switch(eParam)
 
77
        {
 
78
        case AL_POSITION:
 
79
            pContext->Listener.Position[0] = flValue1;
 
80
            pContext->Listener.Position[1] = flValue2;
 
81
            pContext->Listener.Position[2] = flValue3;
 
82
            break;
 
83
 
 
84
        case AL_VELOCITY:
 
85
            pContext->Listener.Velocity[0] = flValue1;
 
86
            pContext->Listener.Velocity[1] = flValue2;
 
87
            pContext->Listener.Velocity[2] = flValue3;
 
88
            break;
 
89
 
 
90
        default:
 
91
            alSetError(AL_INVALID_ENUM);
 
92
            break;
 
93
        }
 
94
 
 
95
        ProcessContext(pContext);
 
96
    }
 
97
    else
 
98
        alSetError(AL_INVALID_OPERATION);
 
99
 
 
100
    return;
 
101
}
 
102
 
 
103
 
 
104
ALAPI ALvoid ALAPIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
 
105
{
 
106
    ALCcontext *pContext;
 
107
 
 
108
    pContext = alcGetCurrentContext();
 
109
    if (pContext)
 
110
    {
 
111
        SuspendContext(pContext);
 
112
 
 
113
        if (pflValues)
 
114
        {
 
115
            switch (eParam)
 
116
            {
 
117
            case AL_GAIN:
 
118
                if (pflValues[0] >= 0.0f)
 
119
                    pContext->Listener.Gain = pflValues[0];
 
120
                else
 
121
                    alSetError(AL_INVALID_VALUE);
 
122
                break;
 
123
 
 
124
            case AL_METERS_PER_UNIT:
 
125
                if (pflValues[0] > 0.0f)
 
126
                    pContext->Listener.MetersPerUnit = pflValues[0];
 
127
                else
 
128
                    alSetError(AL_INVALID_VALUE);
 
129
                break;
 
130
 
 
131
            case AL_POSITION:
 
132
                pContext->Listener.Position[0] = pflValues[0];
 
133
                pContext->Listener.Position[1] = pflValues[1];
 
134
                pContext->Listener.Position[2] = pflValues[2];
 
135
                break;
 
136
 
 
137
            case AL_VELOCITY:
 
138
                pContext->Listener.Velocity[0] = pflValues[0];
 
139
                pContext->Listener.Velocity[1] = pflValues[1];
 
140
                pContext->Listener.Velocity[2] = pflValues[2];
 
141
                break;
 
142
 
 
143
            case AL_ORIENTATION:
 
144
                // AT then UP
 
145
                pContext->Listener.Forward[0] = pflValues[0];
 
146
                pContext->Listener.Forward[1] = pflValues[1];
 
147
                pContext->Listener.Forward[2] = pflValues[2];
 
148
                pContext->Listener.Up[0] = pflValues[3];
 
149
                pContext->Listener.Up[1] = pflValues[4];
 
150
                pContext->Listener.Up[2] = pflValues[5];
 
151
                break;
 
152
 
 
153
            default:
 
154
                alSetError(AL_INVALID_ENUM);
 
155
                break;
 
156
            }
 
157
        }
 
158
        else
 
159
            alSetError(AL_INVALID_VALUE);
 
160
 
 
161
        ProcessContext(pContext);
 
162
    }
 
163
    else
 
164
        alSetError(AL_INVALID_OPERATION);
 
165
 
 
166
    return;
 
167
}
 
168
 
 
169
 
 
170
ALAPI ALvoid ALAPIENTRY alListeneri(ALenum eParam, ALint lValue)
 
171
{
 
172
    ALCcontext *pContext;
 
173
 
 
174
    (void)lValue;
 
175
 
 
176
    pContext = alcGetCurrentContext();
 
177
    if (pContext)
 
178
    {
 
179
        SuspendContext(pContext);
 
180
 
 
181
        switch (eParam)
 
182
        {
 
183
        default:
 
184
            alSetError(AL_INVALID_ENUM);
 
185
            break;
 
186
        }
 
187
 
 
188
        ProcessContext(pContext);
 
189
    }
 
190
    else
 
191
        alSetError(AL_INVALID_OPERATION);
 
192
 
 
193
    return;
 
194
}
 
195
 
 
196
 
 
197
ALAPI void ALAPIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
 
198
{
 
199
    ALCcontext *pContext;
 
200
 
 
201
    pContext = alcGetCurrentContext();
 
202
    if (pContext)
 
203
    {
 
204
        SuspendContext(pContext);
 
205
 
 
206
        switch(eParam)
 
207
        {
 
208
        case AL_POSITION:
 
209
        case AL_VELOCITY:
 
210
            alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
 
211
            break;
 
212
 
 
213
        default:
 
214
            alSetError(AL_INVALID_ENUM);
 
215
            break;
 
216
        }
 
217
 
 
218
        ProcessContext(pContext);
 
219
    }
 
220
    else
 
221
        alSetError(AL_INVALID_OPERATION);
 
222
 
 
223
    return;
 
224
}
 
225
 
 
226
 
 
227
ALAPI void ALAPIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
 
228
{
 
229
    ALCcontext *pContext;
 
230
    ALfloat flValues[6];
 
231
 
 
232
    pContext = alcGetCurrentContext();
 
233
    if (pContext)
 
234
    {
 
235
        SuspendContext(pContext);
 
236
 
 
237
        if (plValues)
 
238
        {
 
239
            switch (eParam)
 
240
            {
 
241
            case AL_POSITION:
 
242
            case AL_VELOCITY:
 
243
                flValues[0] = (ALfloat)plValues[0];
 
244
                flValues[1] = (ALfloat)plValues[1];
 
245
                flValues[2] = (ALfloat)plValues[2];
 
246
                alListenerfv(eParam, flValues);
 
247
                break;
 
248
 
 
249
            case AL_ORIENTATION:
 
250
                flValues[0] = (ALfloat)plValues[0];
 
251
                flValues[1] = (ALfloat)plValues[1];
 
252
                flValues[2] = (ALfloat)plValues[2];
 
253
                flValues[3] = (ALfloat)plValues[3];
 
254
                flValues[4] = (ALfloat)plValues[4];
 
255
                flValues[5] = (ALfloat)plValues[5];
 
256
                alListenerfv(eParam, flValues);
 
257
                break;
 
258
 
 
259
            default:
 
260
                alSetError(AL_INVALID_ENUM);
 
261
                break;
 
262
            }
 
263
        }
 
264
        else
 
265
            alSetError(AL_INVALID_VALUE);
 
266
 
 
267
        ProcessContext(pContext);
 
268
    }
 
269
    else
 
270
        alSetError(AL_INVALID_OPERATION);
 
271
 
 
272
    return;
 
273
}
 
274
 
 
275
 
 
276
ALAPI ALvoid ALAPIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
 
277
{
 
278
    ALCcontext *pContext;
 
279
 
 
280
    pContext = alcGetCurrentContext();
 
281
    if (pContext)
 
282
    {
 
283
        SuspendContext(pContext);
 
284
 
 
285
        if (pflValue)
 
286
        {
 
287
            switch (eParam)
 
288
            {
 
289
            case AL_GAIN:
 
290
                *pflValue = pContext->Listener.Gain;
 
291
                break;
 
292
 
 
293
            case AL_METERS_PER_UNIT:
 
294
                *pflValue = pContext->Listener.MetersPerUnit;
 
295
                break;
 
296
 
 
297
            default:
 
298
                alSetError(AL_INVALID_ENUM);
 
299
                break;
 
300
            }
 
301
        }
 
302
        else
 
303
            alSetError(AL_INVALID_VALUE);
 
304
 
 
305
        ProcessContext(pContext);
 
306
    }
 
307
    else
 
308
        alSetError(AL_INVALID_OPERATION);
 
309
 
 
310
    return;
 
311
}
 
312
 
 
313
 
 
314
ALAPI ALvoid ALAPIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
 
315
{
 
316
    ALCcontext *pContext;
 
317
 
 
318
    pContext = alcGetCurrentContext();
 
319
    if (pContext)
 
320
    {
 
321
        SuspendContext(pContext);
 
322
 
 
323
        if ((pflValue1) && (pflValue2) && (pflValue3))
 
324
        {
 
325
            switch (eParam)
 
326
            {
 
327
            case AL_POSITION:
 
328
                *pflValue1 = pContext->Listener.Position[0];
 
329
                *pflValue2 = pContext->Listener.Position[1];
 
330
                *pflValue3 = pContext->Listener.Position[2];
 
331
                break;
 
332
 
 
333
            case AL_VELOCITY:
 
334
                *pflValue1 = pContext->Listener.Velocity[0];
 
335
                *pflValue2 = pContext->Listener.Velocity[1];
 
336
                *pflValue3 = pContext->Listener.Velocity[2];
 
337
                break;
 
338
 
 
339
            default:
 
340
                alSetError(AL_INVALID_ENUM);
 
341
                break;
 
342
            }
 
343
        }
 
344
        else
 
345
            alSetError(AL_INVALID_VALUE);
 
346
 
 
347
        ProcessContext(pContext);
 
348
    }
 
349
    else
 
350
        alSetError(AL_INVALID_OPERATION);
 
351
 
 
352
    return;
 
353
}
 
354
 
 
355
 
 
356
ALAPI ALvoid ALAPIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
 
357
{
 
358
    ALCcontext *pContext;
 
359
 
 
360
    pContext = alcGetCurrentContext();
 
361
    if (pContext)
 
362
    {
 
363
        SuspendContext(pContext);
 
364
 
 
365
        if (pflValues)
 
366
        {
 
367
            switch (eParam)
 
368
            {
 
369
            case AL_GAIN:
 
370
                pflValues[0] = pContext->Listener.Gain;
 
371
                break;
 
372
 
 
373
            case AL_METERS_PER_UNIT:
 
374
                pflValues[0] = pContext->Listener.MetersPerUnit;
 
375
                break;
 
376
 
 
377
            case AL_POSITION:
 
378
                pflValues[0] = pContext->Listener.Position[0];
 
379
                pflValues[1] = pContext->Listener.Position[1];
 
380
                pflValues[2] = pContext->Listener.Position[2];
 
381
                break;
 
382
 
 
383
            case AL_VELOCITY:
 
384
                pflValues[0] = pContext->Listener.Velocity[0];
 
385
                pflValues[1] = pContext->Listener.Velocity[1];
 
386
                pflValues[2] = pContext->Listener.Velocity[2];
 
387
                break;
 
388
 
 
389
            case AL_ORIENTATION:
 
390
                // AT then UP
 
391
                pflValues[0] = pContext->Listener.Forward[0];
 
392
                pflValues[1] = pContext->Listener.Forward[1];
 
393
                pflValues[2] = pContext->Listener.Forward[2];
 
394
                pflValues[3] = pContext->Listener.Up[0];
 
395
                pflValues[4] = pContext->Listener.Up[1];
 
396
                pflValues[5] = pContext->Listener.Up[2];
 
397
                break;
 
398
 
 
399
            default:
 
400
                alSetError(AL_INVALID_ENUM);
 
401
                break;
 
402
            }
 
403
        }
 
404
        else
 
405
            alSetError(AL_INVALID_VALUE);
 
406
 
 
407
        ProcessContext(pContext);
 
408
    }
 
409
    else
 
410
        alSetError(AL_INVALID_OPERATION);
 
411
 
 
412
    return;
 
413
}
 
414
 
 
415
 
 
416
ALAPI ALvoid ALAPIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
 
417
{
 
418
    ALCcontext *pContext;
 
419
 
 
420
    pContext = alcGetCurrentContext();
 
421
    if (pContext)
 
422
    {
 
423
        SuspendContext(pContext);
 
424
 
 
425
        if (plValue)
 
426
        {
 
427
            switch (eParam)
 
428
            {
 
429
            default:
 
430
                alSetError(AL_INVALID_ENUM);
 
431
                break;
 
432
            }
 
433
        }
 
434
        else
 
435
            alSetError(AL_INVALID_VALUE);
 
436
 
 
437
        ProcessContext(pContext);
 
438
    }
 
439
    else
 
440
        alSetError(AL_INVALID_OPERATION);
 
441
 
 
442
    return;
 
443
}
 
444
 
 
445
 
 
446
ALAPI void ALAPIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
 
447
{
 
448
    ALCcontext *pContext;
 
449
 
 
450
    pContext = alcGetCurrentContext();
 
451
    if (pContext)
 
452
    {
 
453
        SuspendContext(pContext);
 
454
 
 
455
        if ((plValue1) && (plValue2) && (plValue3))
 
456
        {
 
457
            switch (eParam)
 
458
            {
 
459
            case AL_POSITION:
 
460
                *plValue1 = (ALint)pContext->Listener.Position[0];
 
461
                *plValue2 = (ALint)pContext->Listener.Position[1];
 
462
                *plValue3 = (ALint)pContext->Listener.Position[2];
 
463
                break;
 
464
 
 
465
            case AL_VELOCITY:
 
466
                *plValue1 = (ALint)pContext->Listener.Velocity[0];
 
467
                *plValue2 = (ALint)pContext->Listener.Velocity[1];
 
468
                *plValue3 = (ALint)pContext->Listener.Velocity[2];
 
469
                break;
 
470
 
 
471
            default:
 
472
                alSetError(AL_INVALID_ENUM);
 
473
                break;
 
474
            }
 
475
        }
 
476
        else
 
477
            alSetError(AL_INVALID_VALUE);
 
478
 
 
479
        ProcessContext(pContext);
 
480
    }
 
481
    else
 
482
        alSetError(AL_INVALID_OPERATION);
 
483
 
 
484
    return;
 
485
}
 
486
 
 
487
 
 
488
ALAPI void ALAPIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
 
489
{
 
490
    ALCcontext *pContext;
 
491
 
 
492
    pContext = alcGetCurrentContext();
 
493
    if (pContext)
 
494
    {
 
495
        SuspendContext(pContext);
 
496
 
 
497
        if (plValues)
 
498
        {
 
499
            switch (eParam)
 
500
            {
 
501
            case AL_POSITION:
 
502
                plValues[0] = (ALint)pContext->Listener.Position[0];
 
503
                plValues[1] = (ALint)pContext->Listener.Position[1];
 
504
                plValues[2] = (ALint)pContext->Listener.Position[2];
 
505
                break;
 
506
 
 
507
            case AL_VELOCITY:
 
508
                plValues[0] = (ALint)pContext->Listener.Velocity[0];
 
509
                plValues[1] = (ALint)pContext->Listener.Velocity[1];
 
510
                plValues[2] = (ALint)pContext->Listener.Velocity[2];
 
511
                break;
 
512
 
 
513
            case AL_ORIENTATION:
 
514
                // AT then UP
 
515
                plValues[0] = (ALint)pContext->Listener.Forward[0];
 
516
                plValues[1] = (ALint)pContext->Listener.Forward[1];
 
517
                plValues[2] = (ALint)pContext->Listener.Forward[2];
 
518
                plValues[3] = (ALint)pContext->Listener.Up[0];
 
519
                plValues[4] = (ALint)pContext->Listener.Up[1];
 
520
                plValues[5] = (ALint)pContext->Listener.Up[2];
 
521
                break;
 
522
 
 
523
            default:
 
524
                alSetError(AL_INVALID_ENUM);
 
525
                break;
 
526
            }
 
527
        }
 
528
        else
 
529
            alSetError(AL_INVALID_VALUE);
 
530
 
 
531
        ProcessContext(pContext);
 
532
    }
 
533
    else
 
534
        alSetError(AL_INVALID_OPERATION);
 
535
 
 
536
    return;
 
537
}