static bool_t senddata(WAVEHDR *pwh) { GDataBuffer *paud; // Get the next data block to send gfxSystemLock(); paud = gaudioPlayGetDataBlockI(); if (!paud && !nQueuedBuffers) gaudioPlayDoneI(); gfxSystemUnlock(); if (!paud) return FALSE; // Prepare the wave header for Windows pwh->dwUser = (DWORD_PTR)paud; pwh->lpData = (LPSTR)(paud+1); // The data is on the end of the structure pwh->dwBufferLength = paud->len; pwh->dwFlags = 0; pwh->dwLoops = 0; if (waveOutPrepareHeader(ah, pwh, sizeof(WAVEHDR))) { fprintf(stderr, "GAUDIO: Failed to prepare a play buffer"); exit(-1); } // Send it to windows if (waveOutWrite(ah, pwh, sizeof(WAVEHDR))) { fprintf(stderr, "GAUDIO: Failed to write the play buffer"); exit(-1); } nQueuedBuffers++; return TRUE; }
bool_t gfxQueueFSyncInsert(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, gfxQueueASyncItem *pafter, delaytime_t ms) { if (!pitem) return; // Safety gfxSemInit(&pitem->sem, 0, 1); gfxSystemLock(); if (pafter && gfxQueueGSyncIsInI(pqueue, pafter)) { pitem->next = pafter->next; pafter->next = pitem; if (pqueue->tail == pafter) pqueue->tail = pitem; } else { pitem->next = 0; if (!pqueue->head) { pqueue->head = pqueue->tail = pitem; } else { pqueue->tail->next = pitem; pqueue->tail = pitem; } } gfxSystemUnlock(); gfxSemSignal(&pqueue->sem); return gfxSemWait(&pitem->sem, ms); }
static bool_t getbuffer(WAVEHDR *pwh) { GDataBuffer *paud; // Get the next data block to send gfxSystemLock(); paud = gaudioRecordGetFreeBlockI(); if (!paud && !nQueuedBuffers) gaudioRecordDoneI(); gfxSystemUnlock(); if (!paud) return FALSE; // Prepare the wave header for Windows pwh->dwUser = (DWORD_PTR)paud; pwh->lpData = (LPSTR)(paud+1); // The data is on the end of the structure pwh->dwBufferLength = paud->size; pwh->dwFlags = 0; if (waveInPrepareHeader(ah, pwh, sizeof(WAVEHDR))) { fprintf(stderr, "GAUDIO: Failed to prepare a record buffer"); exit(-1); } // Send it to windows if (waveInAddBuffer(ah, pwh, sizeof(WAVEHDR))) { fprintf(stderr, "GAUDIO: Failed to add the record buffer"); exit(-1); } nQueuedBuffers++; return TRUE; }
void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem) { gfxQueueFSyncItem *pi; if (!pitem) return; // Safety gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; found: pitem->next = 0; gfxSystemUnlock(); gfxSemSignal(&pitem->sem); gfxSemDestroy(&pitem->sem); return; } for(pi = pqueue->head; pi->next; pi = pi->next) { if (pi->next == pitem) { pi->next = pitem->next; if (pqueue->tail == pitem) pqueue->tail = pi; goto found; } } } gfxSystemUnlock(); }
void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxSystemLock(); pitem->next = pqueue->head; pqueue->head = pitem; if (!pitem->next) pqueue->tail = pitem; gfxSystemUnlock(); }
bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, const gfxQueueFSyncItem *pitem) { bool_t res; gfxSystemLock(); res = gfxQueueFSyncIsInI(pqueue, pitem); gfxSystemUnlock(); return res; }
gfxQueueGSyncItem *gfxQueueGSyncGet(gfxQueueGSync *pqueue, delaytime_t ms) { gfxQueueGSyncItem *pi; if (!gfxSemWait(&pqueue->sem, ms)) return 0; gfxSystemLock(); pi = pqueue->head; pqueue->head = pi->next; gfxSytemUnlock(); return pi; }
gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue) { gfxQueueASyncItem *pi; if (!pqueue->head) return 0; gfxSystemLock(); if ((pi = pqueue->head)) pqueue->head = pi->next; gfxSytemUnlock(); return pi; }
bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxSystemLock(); for(gfxQueueASyncItem *pi = pqueue->head; pi; pi = pi->next) { if (pi == pitem) { gfxSystemUnlock(); return TRUE; } } gfxSystemUnlock(); return FALSE; }
static DWORD WINAPI waveProc(LPVOID arg) { MSG msg; WAVEHDR *pwh; GDataBuffer *paud; (void) arg; while (GetMessage(&msg, 0, 0, 0)) { switch (msg.message) { case MM_WIM_DATA: pwh = (WAVEHDR *)msg.lParam; // Windows - Let go! waveInUnprepareHeader(ah, pwh, sizeof(WAVEHDR)); // Save the buffer in the audio record list paud = (GDataBuffer *)pwh->dwUser; paud->len = pwh->dwBytesRecorded; gfxSystemLock(); gaudioRecordSaveDataBlockI(paud); gfxSystemUnlock(); pwh->lpData = 0; nQueuedBuffers--; // Are we stopping? if (!isRunning) { // Have we finished yet? if (!nQueuedBuffers) { gfxSystemLock(); gaudioRecordDoneI(); gfxSystemUnlock(); } break; } // Try and get a new block getbuffer(pwh); break; } } return 0; }
void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { pitem->next = 0; gfxSystemLock(); if (!pqueue->head) { pqueue->head = pqueue->tail = pitem; } else { pqueue->tail->next = pitem; pqueue->tail = pitem; } gfxSystemUnlock(); }
bool_t gfxQueueFSyncPush(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms) { gfxSemInit(&pitem->sem, 0, 1); gfxSystemLock(); pitem->next = pqueue->head; pqueue->head = pitem; if (!pitem->next) pqueue->tail = pitem; gfxSystemUnlock(); gfxSemSignal(&pqueue->sem); return gfxSemWait(&pitem->sem, ms); }
gfxQueueASyncItem *gfxQueueASyncGet(gfxQueueASync *pqueue) { gfxQueueASyncItem *pi; // This is just a shortcut to speed execution if (!pqueue->head) return 0; gfxSystemLock(); pi = gfxQueueASyncGetI(pqueue); gfxSystemUnlock(); return pi; }
static DWORD WINAPI waveProc(LPVOID arg) { MSG msg; WAVEHDR *pwh; (void) arg; while (GetMessage(&msg, 0, 0, 0)) { switch (msg.message) { case MM_WOM_DONE: pwh = (WAVEHDR *)msg.lParam; // Windows - Let go! waveOutUnprepareHeader(ah, pwh, sizeof(WAVEHDR)); // Give the buffer back to the Audio Free List gfxSystemLock(); gaudioPlayReleaseDataBlockI((GDataBuffer *)pwh->dwUser); gfxSystemUnlock(); pwh->lpData = 0; nQueuedBuffers--; // Are we stopping? if (!isRunning) { // Have we finished yet? if (!nQueuedBuffers) { gfxSystemLock(); gaudioPlayDoneI(); gfxSystemUnlock(); } break; } // Try and get a new block senddata(pwh); break; } } return 0; }
gfxQueueFSyncItem *gfxQueueFSyncGet(gfxQueueFSync *pqueue, delaytime_t ms) { gfxQueueFSyncItem *pi; if (!gfxSemWait(&pqueue->sem, ms)) return 0; gfxSystemLock(); pi = pqueue->head; pqueue->head = pi->next; pi->next = 0; gfxSystemUnlock(); gfxSemSignal(&pi->sem); gfxSemDestroy(&pi->sem); return pi; }
bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delaytime_t ms) { if (!pitem) return; // Safety gfxSemInit(&pitem->sem, 0, 1); pitem->next = 0; gfxSystemLock(); if (!pqueue->head) { pqueue->head = pqueue->tail = pitem; } else { pqueue->tail->next = pitem; pqueue->tail = pitem; } gfxSystemUnlock(); gfxSemSignal(&pqueue->sem); return gfxSemWait(&pitem->sem, ms); }
void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { if (!pitem) return; gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; } else { for(gfxQueueASyncItem *pi = pqueue->head; pi->next; pi = pi->next) { if (pi->next == pitem) { pi->next = pitem->next; if (pqueue->tail == pitem) pqueue->tail = pi; break; } } } } gfxSystemUnlock(); }
void gfxQueueGSyncPut(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { gfxSystemLock(); gfxQueueGSyncPutI(pqueue, pitem); gfxSystemUnlock(); }
void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { gfxSystemLock(); gfxQueueGSyncRemoveI(pqueue, pitem); gfxSystemUnlock(); }
void gaudinSetBSem(gfxSem *pbsem, GEventAudioIn *pEvent) { gfxSystemLock(); paudSem = pbsem; paudEvent = pEvent; gfxSystemUnlock(); }
void gfxQueueASyncInsert(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem, gfxQueueASyncItem *pafter) { gfxSystemLock(); gfxQueueASyncInsertI(pqueue, pitem, pafter); gfxSystemUnlock(); }
void gfxQueueASyncPush(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { gfxSystemLock(); gfxQueueASyncPushI(pqueue, pitem); gfxSystemUnlock(); }