Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Csound circularBuffer

Date2016-12-19 18:47
FromEd Costello
Subject[Csnd-dev] Csound circularBuffer
Hi,

I was just wondering if I understand the csound circularBuffer correctly. 

I have the following code:

    const int N = 5;
    CSOUND *csound = csoundCreate(NULL);
    void *circularBuffer = csoundCreateCircularBuffer(csound, N, sizeof(MYFLT));
    
    MYFLT inputData[N] = {1., 2., 3., 4., 5.};
    MYFLT outputData[N] = {0};
    csoundWriteCircularBuffer(csound, circularBuffer, inputData, N);
    csoundPeekCircularBuffer(csound, circularBuffer, outputData, N);
    
    for (int i = 0; i < N; ++i) {
        
        printf("%f ", outputData[i]);
    }

I was expecting the print output to be = 1, 2, 3, 4, 5
However, the output I'm getting is = 1, 2, 3, 4, 0
Do you need to create the ringbuffer with N + 1 elements? 
Ed

Date2016-12-19 18:54
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Csound circularBuffer
Not sure about Peek. I have never used that function, Andrés added it. Try csoundReadCircular buffer

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

> On 19 Dec 2016, at 18:47, Ed Costello  wrote:
> 
> Hi,
> 
> I was just wondering if I understand the csound circularBuffer correctly. 
> 
> I have the following code:
> 
>     const int N = 5;
>     CSOUND *csound = csoundCreate(NULL);
>     void *circularBuffer = csoundCreateCircularBuffer(csound, N, sizeof(MYFLT));
>     
>     MYFLT inputData[N] = {1., 2., 3., 4., 5.};
>     MYFLT outputData[N] = {0};
>     csoundWriteCircularBuffer(csound, circularBuffer, inputData, N);
>     csoundPeekCircularBuffer(csound, circularBuffer, outputData, N);
>     
>     for (int i = 0; i < N; ++i) {
>         
>         printf("%f ", outputData[i]);
>     }
> 
> I was expecting the print output to be = 1, 2, 3, 4, 5
> However, the output I'm getting is = 1, 2, 3, 4, 0
> Do you need to create the ringbuffer with N + 1 elements?