gpt4 book ai didi

objective-c - 错误的值被复制到TPCircularBuffer

转载 作者:行者123 更新时间:2023-12-03 01:58:44 25 4
gpt4 key购买 nike

TPCircularBuffer有点麻烦。

当我直接从回调缓冲区中打印出样本时,我会看到正确的值,但是一旦将它们复制到TPCircularBuffer中,它们就是不正确的。

有任何想法吗?

我已经在测试应用程序中使用了TPCircularBuffer,并且一切正常。

提前非常感谢您的帮助!

这些是代码的相关部分:

//  Declare and initialize TPCircularBuffer
TPCircularBuffer circularBuffer;
TPCircularBufferInit(&circularBuffer, 4096);

// Callback stores signed integers in inBuffer->mAudioData.
SInt16 * buffer = (SInt16*) inBuffer->mAudioData;

int32_t availableBytes;

// Each SInt16 is 2 bytes.
// So, this should place 512 SInt16 values from the buffer
// into the circularBuffer, right?
TPCircularBufferProduceBytes(&circularBuffer, &buffer, 1024);

SInt16 *ptr2 = TPCircularBufferTail(&circularBuffer, &availableBytes);
printf("Total byte size of buffer: %i\n", (int)availableBytes);
printf("circularBuffer[0] = %i\n", ptr2[0]);
printf("buffer[0] = %i\n", buffer[0]);

这是打印输出:
Total byte size of buffer: 1024
circularBuffer[0] = -16384
buffer[0] = 0

最佳答案

我不太确定您要问什么,所以这里有个简单的例子。

初始化:

TPCircularBuffer tpBuffer;
int secondsOfBuffer = 8;
float sampleRate = 44100.0;
int bufferByteSize = secondsOfBuffer * sampleRate * sizeof(SInt16);
TPCircularBufferInit(&tpBuffer, bufferByteSize);

写到头上:
int32_t availableBytes;
SInt16 *head = TPCircularBufferHead(&tpBuffer, &availableBytes);
int sampleCount = 1024;
for (int i = 0; i < 1024; i++) {
head[i] = i;
}
TPCircularBufferProduce(&tpBuffer, sampleCount * sizeof(SInt16));

从尾读:
SInt16 *tail = TPCircularBufferTail(&tpBuffer, &availableBytes);
int32_t availableBytes;
int availableSamples = availableBytes / sizeof(SInt16);
for (int i = 0; i < availableSamples; i++) {
printf("%i\n",tail[i]);
}
TPCircularBufferConsume(&tpBuffer, sizeof(SInt16) * sampleCount);

关于objective-c - 错误的值被复制到TPCircularBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33443386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com