~ubuntu-branches/ubuntu/quantal/openal-soft/quantal

« back to all changes in this revision

Viewing changes to OpenAL32/alDatabuffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Ritchie
  • Date: 2010-04-16 15:20:20 UTC
  • mfrom: (0.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100416152020-7gbp12lzhugfr2n0
Tags: 1:1.12.854-0ubuntu1
* New upstream release (LP: #565071)
  - Fully backwards compatible
  - Fixed playback when the PulseAudio buffer is calculated to be more than 64KB.
  - Restored compatibility with some older PulseAudio libs.
  - Alternative buffer sizing for PulseAudio, specified using a new config option.
  - Improved buffer size calculations, to prevent drastic latency changes when certain properties (such as ALC_FREQUENCY) are modified.
  - "Not broken" unlike 1.11.753, according to upstream
* Should fix some remaining crackling issues (LP: #351732, #516435)
* Should be ok to sync over; no extra patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "alThunk.h"
33
33
 
34
34
 
 
35
DECL_VERIFIER(Databuffer, ALdatabuffer, databuffer)
 
36
 
35
37
/*
36
38
*    alGenDatabuffersEXT(ALsizei n, ALuint *puiBuffers)
37
39
*
38
40
*    Generates n AL Databuffers, and stores the Databuffers Names in the array pointed to by puiBuffers
39
41
*/
40
 
ALvoid ALAPIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers)
 
42
AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers)
41
43
{
42
44
    ALCcontext *Context;
43
45
    ALsizei i=0;
54
56
         * Databuffer Names) */
55
57
        if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
56
58
        {
57
 
            ALdatabuffer **list = &device->Databuffers;
 
59
            ALdatabuffer *end;
 
60
            ALdatabuffer **list = &device->DatabufferList;
58
61
            while(*list)
59
62
                list = &(*list)->next;
60
63
 
61
64
            /* Create all the new Databuffers */
 
65
            end = *list;
62
66
            while(i < n)
63
67
            {
64
68
                *list = calloc(1, sizeof(ALdatabuffer));
65
69
                if(!(*list))
66
70
                {
67
 
                    alDeleteDatabuffersEXT(i, puiBuffers);
68
 
                    alSetError(AL_OUT_OF_MEMORY);
 
71
                    while(end->next)
 
72
                    {
 
73
                        ALdatabuffer *temp = end->next;
 
74
                        end->next = temp->next;
 
75
 
 
76
                        ALTHUNK_REMOVEENTRY(temp->databuffer);
 
77
                        device->DatabufferCount--;
 
78
                        free(temp);
 
79
                    }
 
80
                    alSetError(Context, AL_OUT_OF_MEMORY);
69
81
                    break;
70
82
                }
71
83
 
79
91
            }
80
92
        }
81
93
        else
82
 
            alSetError(AL_INVALID_VALUE);
 
94
            alSetError(Context, AL_INVALID_VALUE);
83
95
    }
84
96
 
85
97
    ProcessContext(Context);
90
102
*
91
103
*    Deletes the n AL Databuffers pointed to by puiBuffers
92
104
*/
93
 
ALvoid ALAPIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuffers)
 
105
AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuffers)
94
106
{
95
107
    ALCcontext *Context;
96
108
    ALdatabuffer *ALBuf;
109
121
         * deleted */
110
122
        for(i = 0;i < n;i++)
111
123
        {
112
 
            /* Check for valid Buffer ID (can be NULL buffer) */
113
 
            if(alIsDatabufferEXT(puiBuffers[i]))
 
124
            if(!puiBuffers[i])
 
125
                continue;
 
126
 
 
127
            /* Check for valid Buffer ID */
 
128
            if((ALBuf=VerifyDatabuffer(device->DatabufferList, puiBuffers[i])) != NULL)
114
129
            {
115
 
                /* If not the NULL buffer, check that it's unmapped */
116
 
                ALBuf = ((ALdatabuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
117
 
                if(ALBuf)
 
130
                if(ALBuf->state != UNMAPPED)
118
131
                {
119
 
                    if(ALBuf->state != UNMAPPED)
120
 
                    {
121
 
                        /* Databuffer still in use, cannot be deleted */
122
 
                        alSetError(AL_INVALID_OPERATION);
123
 
                        bFailed = AL_TRUE;
124
 
                    }
 
132
                    /* Databuffer still in use, cannot be deleted */
 
133
                    alSetError(Context, AL_INVALID_OPERATION);
 
134
                    bFailed = AL_TRUE;
 
135
                    break;
125
136
                }
126
137
            }
127
138
            else
128
139
            {
129
140
                /* Invalid Databuffer */
130
 
                alSetError(AL_INVALID_NAME);
 
141
                alSetError(Context, AL_INVALID_NAME);
131
142
                bFailed = AL_TRUE;
 
143
                break;
132
144
            }
133
145
        }
134
146
 
138
150
        {
139
151
            for(i = 0;i < n;i++)
140
152
            {
141
 
                if(puiBuffers[i] && alIsDatabufferEXT(puiBuffers[i]))
 
153
                if((ALBuf=VerifyDatabuffer(device->DatabufferList, puiBuffers[i])) != NULL)
142
154
                {
143
 
                    ALdatabuffer **list = &device->Databuffers;
 
155
                    ALdatabuffer **list = &device->DatabufferList;
144
156
 
145
 
                    ALBuf = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(puiBuffers[i]);
146
157
                    while(*list && *list != ALBuf)
147
158
                        list = &(*list)->next;
148
159
 
167
178
        }
168
179
    }
169
180
    else
170
 
        alSetError(AL_INVALID_VALUE);
 
181
        alSetError(Context, AL_INVALID_VALUE);
171
182
 
172
183
    ProcessContext(Context);
173
184
}
177
188
*
178
189
*    Checks if ulBuffer is a valid Databuffer Name
179
190
*/
180
 
ALboolean ALAPIENTRY alIsDatabufferEXT(ALuint uiBuffer)
 
191
AL_API ALboolean AL_APIENTRY alIsDatabufferEXT(ALuint uiBuffer)
181
192
{
182
193
    ALCcontext *Context;
183
 
    ALdatabuffer *ALBuf;
 
194
    ALboolean  result = AL_TRUE;
 
195
    ALCdevice *device;
184
196
 
185
197
    Context = GetContextSuspended();
186
198
    if(!Context) return AL_FALSE;
187
199
 
188
 
    /* Check through list of generated databuffers for uiBuffer */
189
 
    ALBuf = Context->Device->Databuffers;
190
 
    while(ALBuf && ALBuf->databuffer != uiBuffer)
191
 
        ALBuf = ALBuf->next;
 
200
    device = Context->Device;
 
201
    if(uiBuffer)
 
202
        result = (VerifyDatabuffer(device->DatabufferList, uiBuffer) ?
 
203
                  AL_TRUE : AL_FALSE);
192
204
 
193
205
    ProcessContext(Context);
194
206
 
195
 
    return ((ALBuf || !uiBuffer) ? AL_TRUE : AL_FALSE);
 
207
    return result;
196
208
}
197
209
 
198
210
/*
200
212
*
201
213
*    Fill databuffer with data
202
214
*/
203
 
ALvoid ALAPIENTRY alDatabufferDataEXT(ALuint buffer,const ALvoid *data,ALsizei size,ALenum usage)
 
215
AL_API ALvoid AL_APIENTRY alDatabufferDataEXT(ALuint buffer,const ALvoid *data,ALsizeiptrEXT size,ALenum usage)
204
216
{
205
217
    ALCcontext *Context;
206
218
    ALdatabuffer *ALBuf;
 
219
    ALCdevice *Device;
207
220
    ALvoid *temp;
208
221
 
209
222
    Context = GetContextSuspended();
210
223
    if(!Context) return;
211
224
 
212
 
    if(alIsDatabufferEXT(buffer) && buffer != 0)
 
225
    Device = Context->Device;
 
226
    if((ALBuf=VerifyDatabuffer(Device->DatabufferList, buffer)) != NULL)
213
227
    {
214
 
        ALBuf = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(buffer);
215
228
        if(ALBuf->state == UNMAPPED)
216
229
        {
217
230
            if(usage == AL_STREAM_WRITE_EXT || usage == AL_STREAM_READ_EXT ||
220
233
               usage == AL_DYNAMIC_WRITE_EXT || usage == AL_DYNAMIC_READ_EXT ||
221
234
               usage == AL_DYNAMIC_COPY_EXT)
222
235
            {
223
 
                /* (Re)allocate data */
224
 
                temp = realloc(ALBuf->data, size);
225
 
                if(temp)
 
236
                if(size >= 0)
226
237
                {
227
 
                    ALBuf->data = temp;
228
 
                    ALBuf->size = size;
229
 
                    ALBuf->usage = usage;
230
 
                    if(data)
231
 
                        memcpy(ALBuf->data, data, size);
 
238
                    /* (Re)allocate data */
 
239
                    temp = realloc(ALBuf->data, size);
 
240
                    if(temp)
 
241
                    {
 
242
                        ALBuf->data = temp;
 
243
                        ALBuf->size = size;
 
244
                        ALBuf->usage = usage;
 
245
                        if(data)
 
246
                            memcpy(ALBuf->data, data, size);
 
247
                    }
 
248
                    else
 
249
                        alSetError(Context, AL_OUT_OF_MEMORY);
232
250
                }
233
251
                else
234
 
                    alSetError(AL_OUT_OF_MEMORY);
 
252
                    alSetError(Context, AL_INVALID_VALUE);
235
253
            }
236
254
            else
237
 
                alSetError(AL_INVALID_ENUM);
 
255
                alSetError(Context, AL_INVALID_ENUM);
238
256
        }
239
257
        else
240
 
            alSetError(AL_INVALID_OPERATION);
 
258
            alSetError(Context, AL_INVALID_OPERATION);
241
259
    }
242
260
    else
243
 
        alSetError(AL_INVALID_NAME);
 
261
        alSetError(Context, AL_INVALID_NAME);
244
262
 
245
263
    ProcessContext(Context);
246
264
}
247
265
 
248
 
ALvoid ALAPIENTRY alDatabufferSubDataEXT(ALuint uiBuffer, ALuint start, ALsizei length, const ALvoid *data)
 
266
AL_API ALvoid AL_APIENTRY alDatabufferSubDataEXT(ALuint uiBuffer, ALintptrEXT start, ALsizeiptrEXT length, const ALvoid *data)
249
267
{
250
268
    ALCcontext    *pContext;
251
269
    ALdatabuffer  *pBuffer;
 
270
    ALCdevice     *Device;
252
271
 
253
272
    pContext = GetContextSuspended();
254
273
    if(!pContext) return;
255
274
 
256
 
    if(alIsDatabufferEXT(uiBuffer) && uiBuffer != 0)
 
275
    Device = pContext->Device;
 
276
    if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
257
277
    {
258
 
        pBuffer = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(uiBuffer);
259
 
 
260
 
        if(length >= 0 && start+length <= pBuffer->size)
 
278
        if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
261
279
        {
262
280
            if(pBuffer->state == UNMAPPED)
263
281
                memcpy(pBuffer->data+start, data, length);
264
282
            else
265
 
                alSetError(AL_INVALID_OPERATION);
 
283
                alSetError(pContext, AL_INVALID_OPERATION);
266
284
        }
267
285
        else
268
 
            alSetError(AL_INVALID_VALUE);
 
286
            alSetError(pContext, AL_INVALID_VALUE);
269
287
    }
270
288
    else
271
 
        alSetError(AL_INVALID_NAME);
 
289
        alSetError(pContext, AL_INVALID_NAME);
272
290
 
273
291
    ProcessContext(pContext);
274
292
}
275
293
 
276
 
ALvoid ALAPIENTRY alGetDatabufferSubDataEXT(ALuint uiBuffer, ALuint start, ALsizei length, ALvoid *data)
 
294
AL_API ALvoid AL_APIENTRY alGetDatabufferSubDataEXT(ALuint uiBuffer, ALintptrEXT start, ALsizeiptrEXT length, ALvoid *data)
277
295
{
278
296
    ALCcontext    *pContext;
279
297
    ALdatabuffer  *pBuffer;
 
298
    ALCdevice     *Device;
280
299
 
281
300
    pContext = GetContextSuspended();
282
301
    if(!pContext) return;
283
302
 
284
 
    if(alIsDatabufferEXT(uiBuffer) && uiBuffer != 0)
 
303
    Device = pContext->Device;
 
304
    if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
285
305
    {
286
 
        pBuffer = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(uiBuffer);
287
 
 
288
 
        if(length >= 0 && start+length <= pBuffer->size)
 
306
        if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
289
307
        {
290
308
            if(pBuffer->state == UNMAPPED)
291
309
                memcpy(data, pBuffer->data+start, length);
292
310
            else
293
 
                alSetError(AL_INVALID_OPERATION);
 
311
                alSetError(pContext, AL_INVALID_OPERATION);
294
312
        }
295
313
        else
296
 
            alSetError(AL_INVALID_VALUE);
 
314
            alSetError(pContext, AL_INVALID_VALUE);
297
315
    }
298
316
    else
299
 
        alSetError(AL_INVALID_NAME);
 
317
        alSetError(pContext, AL_INVALID_NAME);
300
318
 
301
319
    ProcessContext(pContext);
302
320
}
303
321
 
304
322
 
305
 
ALvoid ALAPIENTRY alDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat flValue)
 
323
AL_API ALvoid AL_APIENTRY alDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat flValue)
306
324
{
307
325
    ALCcontext    *pContext;
 
326
    ALCdevice     *Device;
308
327
 
309
328
    (void)flValue;
310
329
 
311
330
    pContext = GetContextSuspended();
312
331
    if(!pContext) return;
313
332
 
314
 
    if(alIsDatabufferEXT(buffer) && buffer != 0)
 
333
    Device = pContext->Device;
 
334
    if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
315
335
    {
316
336
        switch(eParam)
317
337
        {
318
338
        default:
319
 
            alSetError(AL_INVALID_ENUM);
 
339
            alSetError(pContext, AL_INVALID_ENUM);
320
340
            break;
321
341
        }
322
342
    }
323
343
    else
324
 
        alSetError(AL_INVALID_NAME);
 
344
        alSetError(pContext, AL_INVALID_NAME);
325
345
 
326
346
    ProcessContext(pContext);
327
347
}
328
348
 
329
 
ALvoid ALAPIENTRY alDatabufferfvEXT(ALuint buffer, ALenum eParam, const ALfloat* flValues)
 
349
AL_API ALvoid AL_APIENTRY alDatabufferfvEXT(ALuint buffer, ALenum eParam, const ALfloat* flValues)
330
350
{
331
351
    ALCcontext    *pContext;
 
352
    ALCdevice     *Device;
332
353
 
333
354
    (void)flValues;
334
355
 
335
356
    pContext = GetContextSuspended();
336
357
    if(!pContext) return;
337
358
 
338
 
    if(alIsDatabufferEXT(buffer) && buffer != 0)
 
359
    Device = pContext->Device;
 
360
    if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
339
361
    {
340
362
        switch(eParam)
341
363
        {
342
364
        default:
343
 
            alSetError(AL_INVALID_ENUM);
 
365
            alSetError(pContext, AL_INVALID_ENUM);
344
366
            break;
345
367
        }
346
368
    }
347
369
    else
348
 
        alSetError(AL_INVALID_NAME);
 
370
        alSetError(pContext, AL_INVALID_NAME);
349
371
 
350
372
    ProcessContext(pContext);
351
373
}
352
374
 
353
375
 
354
 
ALvoid ALAPIENTRY alDatabufferiEXT(ALuint buffer, ALenum eParam, ALint lValue)
 
376
AL_API ALvoid AL_APIENTRY alDatabufferiEXT(ALuint buffer, ALenum eParam, ALint lValue)
355
377
{
356
378
    ALCcontext    *pContext;
 
379
    ALCdevice     *Device;
357
380
 
358
381
    (void)lValue;
359
382
 
360
383
    pContext = GetContextSuspended();
361
384
    if(!pContext) return;
362
385
 
363
 
    if(alIsDatabufferEXT(buffer) && buffer != 0)
 
386
    Device = pContext->Device;
 
387
    if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
364
388
    {
365
389
        switch(eParam)
366
390
        {
367
391
        default:
368
 
            alSetError(AL_INVALID_ENUM);
 
392
            alSetError(pContext, AL_INVALID_ENUM);
369
393
            break;
370
394
        }
371
395
    }
372
396
    else
373
 
        alSetError(AL_INVALID_NAME);
 
397
        alSetError(pContext, AL_INVALID_NAME);
374
398
 
375
399
    ProcessContext(pContext);
376
400
}
377
401
 
378
 
ALvoid ALAPIENTRY alDatabufferivEXT(ALuint buffer, ALenum eParam, const ALint* plValues)
 
402
AL_API ALvoid AL_APIENTRY alDatabufferivEXT(ALuint buffer, ALenum eParam, const ALint* plValues)
379
403
{
380
404
    ALCcontext    *pContext;
 
405
    ALCdevice     *Device;
381
406
 
382
407
    (void)plValues;
383
408
 
384
409
    pContext = GetContextSuspended();
385
410
    if(!pContext) return;
386
411
 
387
 
    if(alIsDatabufferEXT(buffer) && buffer != 0)
 
412
    Device = pContext->Device;
 
413
    if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
388
414
    {
389
415
        switch(eParam)
390
416
        {
391
417
        default:
392
 
            alSetError(AL_INVALID_ENUM);
 
418
            alSetError(pContext, AL_INVALID_ENUM);
393
419
            break;
394
420
        }
395
421
    }
396
422
    else
397
 
        alSetError(AL_INVALID_NAME);
 
423
        alSetError(pContext, AL_INVALID_NAME);
398
424
 
399
425
    ProcessContext(pContext);
400
426
}
401
427
 
402
428
 
403
 
ALvoid ALAPIENTRY alGetDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat *pflValue)
 
429
AL_API ALvoid AL_APIENTRY alGetDatabufferfEXT(ALuint buffer, ALenum eParam, ALfloat *pflValue)
404
430
{
405
431
    ALCcontext    *pContext;
 
432
    ALCdevice     *Device;
406
433
 
407
434
    pContext = GetContextSuspended();
408
435
    if(!pContext) return;
409
436
 
410
437
    if(pflValue)
411
438
    {
412
 
        if(alIsDatabufferEXT(buffer) && buffer != 0)
 
439
        Device = pContext->Device;
 
440
        if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
413
441
        {
414
442
            switch(eParam)
415
443
            {
416
444
            default:
417
 
                alSetError(AL_INVALID_ENUM);
 
445
                alSetError(pContext, AL_INVALID_ENUM);
418
446
                break;
419
447
            }
420
448
        }
421
449
        else
422
 
            alSetError(AL_INVALID_NAME);
 
450
            alSetError(pContext, AL_INVALID_NAME);
423
451
    }
424
452
    else
425
 
        alSetError(AL_INVALID_VALUE);
 
453
        alSetError(pContext, AL_INVALID_VALUE);
426
454
 
427
455
    ProcessContext(pContext);
428
456
}
429
457
 
430
 
ALvoid ALAPIENTRY alGetDatabufferfvEXT(ALuint buffer, ALenum eParam, ALfloat* pflValues)
 
458
AL_API ALvoid AL_APIENTRY alGetDatabufferfvEXT(ALuint buffer, ALenum eParam, ALfloat* pflValues)
431
459
{
432
460
    ALCcontext    *pContext;
 
461
    ALCdevice     *Device;
433
462
 
434
463
    pContext = GetContextSuspended();
435
464
    if(!pContext) return;
436
465
 
437
466
    if(pflValues)
438
467
    {
439
 
        if(alIsDatabufferEXT(buffer) && buffer != 0)
 
468
        Device = pContext->Device;
 
469
        if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
440
470
        {
441
471
            switch(eParam)
442
472
            {
443
473
            default:
444
 
                alSetError(AL_INVALID_ENUM);
 
474
                alSetError(pContext, AL_INVALID_ENUM);
445
475
                break;
446
476
            }
447
477
        }
448
478
        else
449
 
            alSetError(AL_INVALID_NAME);
 
479
            alSetError(pContext, AL_INVALID_NAME);
450
480
    }
451
481
    else
452
 
        alSetError(AL_INVALID_VALUE);
 
482
        alSetError(pContext, AL_INVALID_VALUE);
453
483
 
454
484
    ProcessContext(pContext);
455
485
}
456
486
 
457
 
ALvoid ALAPIENTRY alGetDatabufferiEXT(ALuint buffer, ALenum eParam, ALint *plValue)
 
487
AL_API ALvoid AL_APIENTRY alGetDatabufferiEXT(ALuint buffer, ALenum eParam, ALint *plValue)
458
488
{
459
489
    ALCcontext    *pContext;
460
490
    ALdatabuffer  *pBuffer;
 
491
    ALCdevice     *Device;
461
492
 
462
493
    pContext = GetContextSuspended();
463
494
    if(!pContext) return;
464
495
 
465
496
    if(plValue)
466
497
    {
467
 
        if(alIsDatabufferEXT(buffer) && buffer != 0)
 
498
        Device = pContext->Device;
 
499
        if((pBuffer=VerifyDatabuffer(Device->DatabufferList, buffer)) != NULL)
468
500
        {
469
 
            pBuffer = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(buffer);
470
 
 
471
501
            switch(eParam)
472
502
            {
473
503
            case AL_SIZE:
474
 
                *plValue = pBuffer->size;
 
504
                *plValue = (ALint)pBuffer->size;
475
505
                break;
476
506
 
477
507
            default:
478
 
                alSetError(AL_INVALID_ENUM);
 
508
                alSetError(pContext, AL_INVALID_ENUM);
479
509
                break;
480
510
            }
481
511
        }
482
512
        else
483
 
            alSetError(AL_INVALID_NAME);
 
513
            alSetError(pContext, AL_INVALID_NAME);
484
514
    }
485
515
    else
486
 
        alSetError(AL_INVALID_VALUE);
 
516
        alSetError(pContext, AL_INVALID_VALUE);
487
517
 
488
518
    ProcessContext(pContext);
489
519
}
490
520
 
491
 
ALvoid ALAPIENTRY alGetDatabufferivEXT(ALuint buffer, ALenum eParam, ALint* plValues)
 
521
AL_API ALvoid AL_APIENTRY alGetDatabufferivEXT(ALuint buffer, ALenum eParam, ALint* plValues)
492
522
{
493
523
    ALCcontext    *pContext;
 
524
    ALCdevice     *Device;
494
525
 
495
526
    pContext = GetContextSuspended();
496
527
    if(!pContext) return;
497
528
 
498
529
    if(plValues)
499
530
    {
500
 
        if(alIsDatabufferEXT(buffer) && buffer != 0)
 
531
        Device = pContext->Device;
 
532
        if(VerifyDatabuffer(Device->DatabufferList, buffer) != NULL)
501
533
        {
502
534
            switch (eParam)
503
535
            {
506
538
                break;
507
539
 
508
540
            default:
509
 
                alSetError(AL_INVALID_ENUM);
 
541
                alSetError(pContext, AL_INVALID_ENUM);
510
542
                break;
511
543
            }
512
544
        }
513
545
        else
514
 
            alSetError(AL_INVALID_NAME);
 
546
            alSetError(pContext, AL_INVALID_NAME);
515
547
    }
516
548
    else
517
 
        alSetError(AL_INVALID_VALUE);
 
549
        alSetError(pContext, AL_INVALID_VALUE);
518
550
 
519
551
    ProcessContext(pContext);
520
552
}
521
553
 
522
554
 
523
 
ALvoid ALAPIENTRY alSelectDatabufferEXT(ALenum target, ALuint uiBuffer)
 
555
AL_API ALvoid AL_APIENTRY alSelectDatabufferEXT(ALenum target, ALuint uiBuffer)
524
556
{
525
557
    ALCcontext    *pContext;
526
 
    ALdatabuffer  *pBuffer;
 
558
    ALdatabuffer  *pBuffer = NULL;
 
559
    ALCdevice     *Device;
527
560
 
528
561
    pContext = GetContextSuspended();
529
562
    if(!pContext) return;
530
563
 
531
 
    if(alIsDatabufferEXT(uiBuffer))
 
564
    Device = pContext->Device;
 
565
    if(uiBuffer == 0 ||
 
566
       (pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
532
567
    {
533
 
        pBuffer = (ALdatabuffer*)(uiBuffer ? ALTHUNK_LOOKUPENTRY(uiBuffer) : NULL);
534
568
        if(target == AL_SAMPLE_SOURCE_EXT)
535
569
            pContext->SampleSource = pBuffer;
536
570
        else if(target == AL_SAMPLE_SINK_EXT)
537
571
            pContext->SampleSink = pBuffer;
538
572
        else
539
 
            alSetError(AL_INVALID_VALUE);
 
573
            alSetError(pContext, AL_INVALID_VALUE);
540
574
    }
541
575
    else
542
 
        alSetError(AL_INVALID_NAME);
 
576
        alSetError(pContext, AL_INVALID_NAME);
543
577
 
544
578
    ProcessContext(pContext);
545
579
}
546
580
 
547
581
 
548
 
ALvoid* ALAPIENTRY alMapDatabufferEXT(ALuint uiBuffer, ALuint start, ALsizei length, ALenum access)
 
582
AL_API ALvoid* AL_APIENTRY alMapDatabufferEXT(ALuint uiBuffer, ALintptrEXT start, ALsizeiptrEXT length, ALenum access)
549
583
{
550
584
    ALCcontext    *pContext;
551
585
    ALdatabuffer  *pBuffer;
552
586
    ALvoid        *ret = NULL;
 
587
    ALCdevice     *Device;
553
588
 
554
589
    pContext = GetContextSuspended();
555
590
    if(!pContext) return NULL;
556
591
 
557
 
    if(alIsDatabufferEXT(uiBuffer) && uiBuffer != 0)
 
592
    Device = pContext->Device;
 
593
    if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
558
594
    {
559
 
        pBuffer = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(uiBuffer);
560
 
 
561
 
        if(length >= 0 && start+length <= pBuffer->size)
 
595
        if(start >= 0 && length >= 0 && start+length <= pBuffer->size)
562
596
        {
563
597
            if(access == AL_READ_ONLY_EXT || access == AL_WRITE_ONLY_EXT ||
564
598
               access == AL_READ_WRITE_EXT)
569
603
                    pBuffer->state = MAPPED;
570
604
                }
571
605
                else
572
 
                    alSetError(AL_INVALID_OPERATION);
 
606
                    alSetError(pContext, AL_INVALID_OPERATION);
573
607
            }
574
608
            else
575
 
                alSetError(AL_INVALID_ENUM);
 
609
                alSetError(pContext, AL_INVALID_ENUM);
576
610
        }
577
611
        else
578
 
            alSetError(AL_INVALID_VALUE);
 
612
            alSetError(pContext, AL_INVALID_VALUE);
579
613
    }
580
614
    else
581
 
        alSetError(AL_INVALID_NAME);
 
615
        alSetError(pContext, AL_INVALID_NAME);
582
616
 
583
617
    ProcessContext(pContext);
584
618
 
585
619
    return ret;
586
620
}
587
621
 
588
 
ALvoid ALAPIENTRY alUnmapDatabufferEXT(ALuint uiBuffer)
 
622
AL_API ALvoid AL_APIENTRY alUnmapDatabufferEXT(ALuint uiBuffer)
589
623
{
590
624
    ALCcontext    *pContext;
591
625
    ALdatabuffer  *pBuffer;
 
626
    ALCdevice     *Device;
592
627
 
593
628
    pContext = GetContextSuspended();
594
629
    if(!pContext) return;
595
630
 
596
 
    if(alIsDatabufferEXT(uiBuffer) && uiBuffer != 0)
 
631
    Device = pContext->Device;
 
632
    if((pBuffer=VerifyDatabuffer(Device->DatabufferList, uiBuffer)) != NULL)
597
633
    {
598
 
        pBuffer = (ALdatabuffer*)ALTHUNK_LOOKUPENTRY(uiBuffer);
599
 
 
600
634
        if(pBuffer->state == MAPPED)
601
635
            pBuffer->state = UNMAPPED;
602
636
        else
603
 
            alSetError(AL_INVALID_OPERATION);
 
637
            alSetError(pContext, AL_INVALID_OPERATION);
604
638
    }
605
639
    else
606
 
        alSetError(AL_INVALID_NAME);
 
640
        alSetError(pContext, AL_INVALID_NAME);
607
641
 
608
642
    ProcessContext(pContext);
609
643
}
616
650
*/
617
651
ALvoid ReleaseALDatabuffers(ALCdevice *device)
618
652
{
619
 
    ALdatabuffer *ALBuffer;
620
 
    ALdatabuffer *ALBufferTemp;
621
 
 
622
 
    ALBuffer = device->Databuffers;
623
 
    while(ALBuffer)
 
653
    while(device->DatabufferList)
624
654
    {
625
 
        // Release sample data
626
 
        free(ALBuffer->data);
 
655
        ALdatabuffer *temp = device->DatabufferList;
 
656
        device->DatabufferList = temp->next;
 
657
 
 
658
        // Release buffer data
 
659
        free(temp->data);
627
660
 
628
661
        // Release Buffer structure
629
 
        ALBufferTemp = ALBuffer;
630
 
        ALBuffer = ALBuffer->next;
631
 
        memset(ALBufferTemp, 0, sizeof(ALdatabuffer));
632
 
        free(ALBufferTemp);
 
662
        ALTHUNK_REMOVEENTRY(temp->databuffer);
 
663
        memset(temp, 0, sizeof(ALdatabuffer));
 
664
        free(temp);
633
665
    }
634
 
    device->Databuffers = NULL;
635
666
    device->DatabufferCount = 0;
636
667
}