📄 buffer.c
字号:
// // Determine the number of sample that can be stored at this offset. // if(lRead > psBuffer->lWritePtr) { // // We can write up to the read pointer. // *plLength = lRead - psBuffer->lWritePtr - 4; } else if(lRead == 0) { // // We can write almost to the end of the buffer. // *plLength = psBuffer->lLength - psBuffer->lWritePtr - 4; } else { // // We can write up to the end of the buffer. // *plLength = psBuffer->lLength - psBuffer->lWritePtr; } // // Success. // lRet = 1; } // // Return to the caller. // return(lRet);}//****************************************************************************//// BufferUpdateWritePointer advances the write pointer for the buffer by the// specified number of samples.////****************************************************************************longBufferUpdateWritePointer(BufferState *psBuffer, long lLength){ long lRet, lRead, lMaxLength; // // Send the update write pointer request to the entry point for this // buffer. // if(psBuffer->pfnIoctl) { lRet = (psBuffer->pfnIoctl)(IOCTL_BUFFER_UPDATEWRITEPOINTER, psBuffer, (unsigned long)lLength, 0, 0); } else { lRet = -1; } // // If the return value is -1, then we should handle the request. // if(lRet == -1) { // // Get the current read pointer. // lRead = psBuffer->lReadPtr; // // Determine the maximum number of samples we can write. // if(lRead > psBuffer->lWritePtr) { // // The maximum we can write is up to the read pointer. // lMaxLength = lRead - psBuffer->lWritePtr - 4; } else if(lRead == 0) { // // The maximum we can write is almost to the end of the buffer. // lMaxLength = psBuffer->lLength - psBuffer->lWritePtr - 4; } else { // // The maximum we can write is to the end of the buffer. // lMaxLength = psBuffer->lLength - psBuffer->lWritePtr; } // // See if the specified length is valid. // if(lLength > lMaxLength) { // // An invalid length was specified. // lRet = 0; } else { // // Update the write poitner. // psBuffer->lWritePtr += lLength; if(psBuffer->lWritePtr == psBuffer->lLength) { psBuffer->lWritePtr = 0; } // // Success. // lRet = 1; } } // // Return to the caller. // return(lRet);}//****************************************************************************//// BufferGetReadPointer provides pointers into the circular buffer where data// can be read.////****************************************************************************longBufferGetReadPointer(BufferState *psBuffer, short **ppsLeft, short **ppsRight, long *plLength){ long lRet, lWrite; // // Send the get read pointer request to the entry point for this buffer. // if(psBuffer->pfnIoctl) { lRet = (psBuffer->pfnIoctl)(IOCTL_BUFFER_GETREADPOINTER, psBuffer, (unsigned long)ppsLeft, (unsigned long)ppsRight, (unsigned long)plLength); } else { lRet = -1; } // // If the return value is -1, then we should handle the request. // if(lRet == -1) { // // Get the current write pointer. // lWrite = psBuffer->lWritePtr; // // Get pointers to the next read position within the circular buffer. // *ppsLeft = psBuffer->psLeft + psBuffer->lReadPtr; *ppsRight = psBuffer->psRight + psBuffer->lReadPtr; // // Determine the number of sample that can be read at this offset. // if(lWrite >= psBuffer->lReadPtr) { // // We can read up to the write pointer. // *plLength = lWrite - psBuffer->lReadPtr; } else { // // We can read up to the end of the buffer. // *plLength = psBuffer->lLength - psBuffer->lReadPtr; } // // Success. // lRet = 1; } // // Return to the caller. // return(lRet);}//****************************************************************************//// BufferUpdateReadPointer advances the read pointer for the buffer by the// specified number of samples.////****************************************************************************longBufferUpdateReadPointer(BufferState *psBuffer, long lLength){ long lRet, lWrite, lMaxLength; // // Send the update read pointer request to the entry point for this buffer. // if(psBuffer->pfnIoctl) { lRet = (psBuffer->pfnIoctl)(IOCTL_BUFFER_UPDATEREADPOINTER, psBuffer, (unsigned long)lLength, 0, 0); } else { lRet = -1; } // // If the return value is -1, then we should handle the request. // if(lRet == -1) { // // Get the current write pointer. // lWrite = psBuffer->lWritePtr; // // Determine the maximum number of samples we can read. // if(lWrite >= psBuffer->lReadPtr) { // // The maximum we can read is up to the write pointer. // lMaxLength = lWrite - psBuffer->lReadPtr; } else { // // The maximum we can read is up to the end of the buffer. // lMaxLength = psBuffer->lLength - psBuffer->lReadPtr; } // // See if the specified length is valid. // if(lLength > lMaxLength) { // // An invalid length was specified. // lRet = 0; } else { // // Update the read pointer. // psBuffer->lReadPtr += lLength; if(psBuffer->lReadPtr == psBuffer->lLength) { psBuffer->lReadPtr = 0; } // // Success. // lRet = 1; } } // // Return to the caller. // return(lRet);}//****************************************************************************//// BufferSetSampleRate specifies the sample rate of the data in the buffer.////****************************************************************************longBufferSetSampleRate(BufferState *psBuffer, long lSampleRate, long lActualRate){ long lRet; // // Send the set sample rate request to the entry point for this buffer. // if(psBuffer->pfnIoctl) { // // Call the entry point for this buffer. // lRet = (psBuffer->pfnIoctl)(IOCTL_BUFFER_SETSAMPLERATE, psBuffer, (unsigned long)lSampleRate, (unsigned long)lActualRate, 0); // // If the return code was not -1, then return it now. // if(lRet != -1) { return(lRet); } } // // Success. // return(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -