143
143
ALBufferList = ALSource->queue;
144
144
// Decrement buffer's reference counter
145
if(ALBufferList->buffer != 0)
146
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--;
145
if(ALBufferList->buffer != NULL)
146
ALBufferList->buffer->refcount--;
147
147
// Update queue to point to next element in list
148
148
ALSource->queue = ALBufferList->next;
149
149
// Release memory allocated for buffer list item
504
503
if(lValue == AL_FALSE || lValue == AL_TRUE)
506
504
pSource->bLooping = (ALboolean)lValue;
508
pALBufferListItem = pSource->queue;
509
for(i = 0;pALBufferListItem != NULL;i++)
511
if(lValue == AL_FALSE && i <= pSource->BuffersPlayed)
512
pALBufferListItem->bufferstate = PROCESSED;
514
pALBufferListItem->bufferstate = PENDING;
515
pALBufferListItem = pALBufferListItem->next;
519
506
alSetError(AL_INVALID_VALUE);
525
512
if(alIsBuffer(lValue))
514
ALbuffer *buffer = NULL;
527
516
// Remove all elements in the queue
528
517
while(pSource->queue != NULL)
530
519
pALBufferListItem = pSource->queue;
531
520
pSource->queue = pALBufferListItem->next;
532
521
// Decrement reference counter for buffer
533
if (pALBufferListItem->buffer)
534
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(pALBufferListItem->buffer)))->refcount--;
522
if(pALBufferListItem->buffer)
523
pALBufferListItem->buffer->refcount--;
535
524
// Release memory for buffer list item
536
525
free(pALBufferListItem);
537
526
// Decrement the number of buffers in the queue
541
530
// Add the buffer to the queue (as long as it is NOT the NULL buffer)
533
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(lValue);
544
535
// Source is now in STATIC mode
545
536
pSource->lSourceType = AL_STATIC;
547
538
// Add the selected buffer to the queue
548
539
pALBufferListItem = malloc(sizeof(ALbufferlistitem));
549
pALBufferListItem->buffer = lValue;
550
pALBufferListItem->bufferstate = PENDING;
551
pALBufferListItem->flag = 0;
540
pALBufferListItem->buffer = buffer;
552
541
pALBufferListItem->next = NULL;
554
543
pSource->queue = pALBufferListItem;
555
544
pSource->BuffersInQueue = 1;
557
546
// Increment reference counter for buffer
558
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(lValue)))->refcount++;
1320
1309
if(pSource->state != AL_PAUSED)
1322
1311
pSource->state = AL_PLAYING;
1323
pSource->inuse = AL_TRUE;
1324
pSource->play = AL_TRUE;
1325
1312
pSource->position = 0;
1326
1313
pSource->position_fraction = 0;
1327
1314
pSource->BuffersPlayed = 0;
1329
pSource->ulBufferID = pSource->queue->buffer;
1331
// Make sure all the Buffers in the queue are marked as PENDING
1332
ALBufferList = pSource->queue;
1335
ALBufferList->bufferstate = PENDING;
1336
ALBufferList = ALBufferList->next;
1316
pSource->Buffer = pSource->queue->buffer;
1341
1319
pSource->state = AL_PLAYING;
1342
pSource->inuse = AL_TRUE;
1343
pSource->play = AL_TRUE;
1346
1321
// Check if an Offset has been set
1347
1322
if(pSource->lOffset)
1357
1332
if(!pContext->Device->Connected)
1359
1334
pSource->state = AL_STOPPED;
1360
pSource->inuse = AL_FALSE;
1361
1335
pSource->BuffersPlayed = pSource->BuffersInQueue;
1362
ALBufferList = pSource->queue;
1363
while(ALBufferList != NULL)
1365
ALBufferList->bufferstate = PROCESSED;
1366
ALBufferList = ALBufferList->next;
1368
1336
pSource->position = 0;
1369
1337
pSource->position_fraction = 0;
1374
// If there is a queue (must all be NULL or Zero length Buffers) mark them all as processed
1375
ALBufferList = pSource->queue;
1378
ALBufferList->bufferstate = PROCESSED;
1379
ALBufferList = ALBufferList->next;
1382
1341
pSource->BuffersPlayed = pSource->BuffersInQueue;
1482
1436
if(Source->state != AL_INITIAL)
1484
1438
Source->state = AL_STOPPED;
1485
Source->inuse = AL_FALSE;
1486
1439
Source->BuffersPlayed = Source->BuffersInQueue;
1487
ALBufferListItem = Source->queue;
1488
while(ALBufferListItem != NULL)
1490
ALBufferListItem->bufferstate = PROCESSED;
1491
ALBufferListItem = ALBufferListItem->next;
1494
1441
Source->lOffset = 0;
1542
1488
if(Source->state != AL_INITIAL)
1544
1490
Source->state = AL_INITIAL;
1545
Source->inuse = AL_FALSE;
1546
1491
Source->position = 0;
1547
1492
Source->position_fraction = 0;
1548
1493
Source->BuffersPlayed = 0;
1549
ALBufferListItem = Source->queue;
1550
while(ALBufferListItem != NULL)
1552
ALBufferListItem->bufferstate = PENDING;
1553
ALBufferListItem = ALBufferListItem->next;
1555
1494
if(Source->queue)
1556
Source->ulBufferID = Source->queue->buffer;
1495
Source->Buffer = Source->queue->buffer;
1558
1497
Source->lOffset = 0;
1606
1545
if (ALBufferList->buffer)
1608
iFrequency = ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->frequency;
1609
iFormat = ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->format;
1547
iFrequency = ALBufferList->buffer->frequency;
1548
iFormat = ALBufferList->buffer->format;
1612
1551
ALBufferList = ALBufferList->next;
1615
1554
for(i = 0; i < n; i++)
1617
if(alIsBuffer(buffers[i]))
1621
if((iFrequency == -1) && (iFormat == -1))
1623
iFrequency = ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[i])))->frequency;
1624
iFormat = ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[i])))->format;
1628
if((iFrequency != ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[i])))->frequency) ||
1629
(iFormat != ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[i])))->format))
1631
alSetError(AL_INVALID_OPERATION);
1632
bBuffersValid = AL_FALSE;
1558
if(!alIsBuffer(buffers[i]))
1640
1560
alSetError(AL_INVALID_NAME);
1641
1561
bBuffersValid = AL_FALSE;
1567
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[i]);
1568
if(iFrequency == -1 && iFormat == -1)
1570
iFrequency = buffer->frequency;
1571
iFormat = buffer->format;
1573
else if(iFrequency != buffer->frequency ||
1574
iFormat != buffer->format)
1576
alSetError(AL_INVALID_OPERATION);
1577
bBuffersValid = AL_FALSE;
1646
1582
if(bBuffersValid)
1584
ALbuffer *buffer = NULL;
1648
1586
// Change Source Type
1649
1587
ALSource->lSourceType = AL_STREAMING;
1589
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[0]);
1651
1591
// All buffers are valid - so add them to the list
1652
1592
ALBufferListStart = malloc(sizeof(ALbufferlistitem));
1653
ALBufferListStart->buffer = buffers[0];
1654
ALBufferListStart->bufferstate = PENDING;
1655
ALBufferListStart->flag = 0;
1593
ALBufferListStart->buffer = buffer;
1656
1594
ALBufferListStart->next = NULL;
1658
1596
// Increment reference counter for buffer
1660
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[0])))->refcount++;
1597
if(buffer) buffer->refcount++;
1662
1599
ALBufferList = ALBufferListStart;
1664
1601
for(i = 1; i < n; i++)
1603
buffer = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffers[i]);
1666
1605
ALBufferList->next = malloc(sizeof(ALbufferlistitem));
1667
ALBufferList->next->buffer = buffers[i];
1668
ALBufferList->next->bufferstate = PENDING;
1669
ALBufferList->next->flag = 0;
1606
ALBufferList->next->buffer = buffer;
1670
1607
ALBufferList->next->next = NULL;
1672
1609
// Increment reference counter for buffer
1674
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(buffers[i])))->refcount++;
1610
if(buffer) buffer->refcount++;
1676
1612
ALBufferList = ALBufferList->next;
1736
1671
ALSource = (ALsource*)ALTHUNK_LOOKUPENTRY(source);
1738
// Check that all 'n' buffers have been processed
1739
ALBufferList = ALSource->queue;
1740
for(i = 0; i < n; i++)
1742
if(ALBufferList != NULL && ALBufferList->bufferstate == PROCESSED)
1744
ALBufferList = ALBufferList->next;
1748
bBuffersProcessed = AL_FALSE;
1753
1673
// If all 'n' buffers have been processed, remove them from the queue
1754
if(bBuffersProcessed)
1674
if(!ALSource->bLooping && (ALuint)n <= ALSource->BuffersPlayed)
1756
1676
for(i = 0; i < n; i++)
1760
1680
ALSource->queue = ALBufferList->next;
1761
1681
// Record name of buffer
1762
buffers[i] = ALBufferList->buffer;
1682
buffers[i] = ALBufferList->buffer->buffer;
1763
1683
// Decrement buffer reference counter
1764
1684
if(ALBufferList->buffer)
1765
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--;
1685
ALBufferList->buffer->refcount--;
1767
1687
// Release memory for buffer list item
1768
1688
free(ALBufferList);
1772
1692
if(ALSource->state != AL_PLAYING)
1774
if (ALSource->queue)
1775
BufferID = ALSource->queue->buffer;
1695
ALSource->Buffer = ALSource->queue->buffer;
1779
ALSource->ulBufferID = BufferID;
1697
ALSource->Buffer = NULL;
1782
if((ALuint)n > ALSource->BuffersPlayed)
1783
ALSource->BuffersPlayed = 0;
1785
ALSource->BuffersPlayed -= n;
1700
ALSource->BuffersPlayed -= n;
1856
1771
ALenum eOriginalFormat;
1857
1772
ALboolean bReturn = AL_TRUE;
1858
1773
ALint lTotalBufferDataSize;
1860
if (((pSource->state == AL_PLAYING) || (pSource->state == AL_PAUSED)) && (pSource->ulBufferID))
1776
if((pSource->state == AL_PLAYING || pSource->state == AL_PAUSED) && pSource->Buffer)
1862
pBuffer = ALTHUNK_LOOKUPENTRY(pSource->ulBufferID);
1778
pBuffer = pSource->Buffer;
1863
1779
// Get Current Buffer Size and frequency (in milliseconds)
1864
1780
flBufferFreq = (ALfloat)pBuffer->frequency;
1865
1781
eOriginalFormat = pBuffer->eOriginalFormat;
1869
1785
readPos = pSource->position * lChannels * 2; // NOTE : This is the byte offset into the *current* buffer
1870
1786
// Add byte length of any processed buffers in the queue
1871
1787
pBufferList = pSource->queue;
1872
while ((pBufferList) && (pBufferList->bufferstate == PROCESSED))
1788
for(i = 0;i < pSource->BuffersPlayed && pBufferList;i++)
1874
readPos += ((ALbuffer*)ALTHUNK_LOOKUPENTRY(pBufferList->buffer))->size;
1790
readPos += pBufferList->buffer->size;
1875
1791
pBufferList = pBufferList->next;
2004
1920
pSource->BuffersPlayed = 0;
2005
1921
while (pBufferList)
2007
pBuffer = ALTHUNK_LOOKUPENTRY(pBufferList->buffer);
1923
pBuffer = pBufferList->buffer;
2008
1924
lBufferSize = pBuffer ? pBuffer->size : 0;
2010
1926
if ((lTotalBufferSize + lBufferSize) <= lByteOffset)
2012
// Offset is past this buffer so increment BuffersPlayed and if the Source is NOT looping
2013
// update the state to PROCESSED
1928
// Offset is past this buffer so increment BuffersPlayed
2014
1929
pSource->BuffersPlayed++;
2016
if (!pSource->bLooping)
2017
pBufferList->bufferstate = PROCESSED;
2019
1931
else if (lTotalBufferSize <= lByteOffset)
2021
1933
// Offset is within this buffer
2022
pBufferList->bufferstate = PENDING;
2024
// Set Current Buffer ID
2025
pSource->ulBufferID = pBufferList->buffer;
1934
// Set Current Buffer
1935
pSource->Buffer = pBufferList->buffer;
2027
1937
// SW Mixer Positions are in Samples
2028
1938
pSource->position = (lByteOffset - lTotalBufferSize) /
2029
1939
aluBytesFromFormat(pBuffer->format) /
2030
1940
aluChannelsFromFormat(pBuffer->format);
2034
// Offset is before this buffer, so mark as pending
2035
pBufferList->bufferstate = PENDING;
2038
1943
// Increment the TotalBufferSize
2039
1944
lTotalBufferSize += lBufferSize;
2159
2064
ALvoid ReleaseALSources(ALCcontext *Context)
2161
2068
while(Context->Source)
2163
2070
ALsource *temp = Context->Source;
2164
Context->Source = Context->Source->next;
2071
Context->Source = temp->next;
2073
// For each buffer in the source's queue, decrement its reference counter and remove it
2074
while(temp->queue != NULL)
2076
ALbufferlistitem *ALBufferList = temp->queue;
2077
// Decrement buffer's reference counter
2078
if(ALBufferList->buffer != NULL)
2079
ALBufferList->buffer->refcount--;
2080
// Update queue to point to next element in list
2081
temp->queue = ALBufferList->next;
2082
// Release memory allocated for buffer list item
2086
for(j = 0;j < MAX_SENDS;++j)
2088
if(temp->Send[j].Slot)
2089
temp->Send[j].Slot->refcount--;
2166
2092
// Release source structure
2167
2093
ALTHUNK_REMOVEENTRY(temp->source);