[Csnd] Table as circular buffer
Date | 2020-07-12 04:13 |
From | Alex Weiss |
Subject | [Csnd] Table as circular buffer |
I'm trying to use a table as a FIFO recording buffer so that only the most current n samples are kept. Table reads and writes never happen at the same time; the instrument is either in record mode and records input into the table, or in playback mode where various opcodes read, process and/or play the table back.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
The only two ways I can think of both have downsides: 1) During recording, once the table is full, shift its contents back by ksmps to make room for another ksmps worth of recorded samples at the end. Repeat for each k-cycle. Obviously very inefficient. 2) Record into the table in a loop and keep a pointer to the current start of the recording (i.e. the oldest sample). The problem with this is that it makes table reads no longer straightforward -- every instrument/opcode that needs access to the table has to take this pointer into account as well as wrapping around the table. Ideally, I would like for the whole process to be completely invisible, meaning that from the outside it appears like a normal table and any opcode that needs to read from it can simply start at the beginning and read till the end. Is something like that possible? Alex |
Date | 2020-07-12 10:07 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
Why don't you use an avar array? It would simplify the reading and writing.
Prof. Victor Lazzarini
Maynooth University
Ireland
On 12 Jul 2020, at 04:14, Alex Weiss <alexweiss86@gmail.com> wrote:
|
Date | 2020-07-12 11:06 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
Something like this? Untested
Opcode Fifo,a,ai
asig,ilen xin
isiz = round(ilen/ksmps)
aMem[] init isiz
kp init 0
xout aMem[kp]
aMem[kp] = asig
kp = kp != isiz-1 ? kp+1 : 0
endop
length will be rounded to nearest multiple of ksmps. You can set it to 1 locally in the opcode.
An advantage over tables is that you can have separate instances of the fifo without
having to create an ftable for each.
Prof. Victor Lazzarini
Maynooth University
Ireland
On 12 Jul 2020, at 10:08, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2020-07-12 21:02 |
From | Alex Weiss |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
Wow -- I have to admit I've been away from csound for long enough to have missed arrays! Looks like I have some reading up to do. Your solution works well for instruments that read directly from tables (since that can easily be replaced with array lookup) but it leaves out opcodes that internally require table access. As a solution, I was hoping to implement some sort of meta-table or view of a table in the API that allows for non-regular reading and writing (such as FIFO) to an underlying table while having the same interface as a regular table. However, looking at the sources it appears tables are implemented internally as an array, and that implementation is exposed in the API. So I don't think that would work. Is there a way to treat an a-array as a table (since presumably their internal representation is the same)? On Sun, Jul 12, 2020 at 3:06 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2020-07-12 21:30 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
I can't recall exactly what we did but we were supposed to have implemented oscillators that could read from i or k arrays.
You can do FIFOs with tables, using tablew to write and table to read. Code is similar but maybe not so handy as in the array case.
John ffitch and Steven Yi may remember what we have done. I'd have to look at the sources.
Prof. Victor Lazzarini
Maynooth University
Ireland
On 12 Jul 2020, at 21:03, Alex Weiss <alexweiss86@gmail.com> wrote:
|
Date | 2020-07-12 21:36 |
From | John ff |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
All I remember is that we did something to make arrtays like tables but not sure how far we got.
On 12 Jul 2020, at 21:31, Victor Lazzarini <victor.lazzarini@mu.ie> wrote: I can't recall exactly what we did but we were supposed to have implemented oscillators that could read from i or k arrays. |
Date | 2020-07-12 22:32 |
From | kelly hirai |
Subject | Re: [Csnd] Table as circular buffer |
i've been able to make method 2 work with phasor and tab to write
and read. i also got variable speed reading working with poscil
and careful manipulations of offset with triggered reading
instruments. i'm still flummoxed how to do variable writing rates with tab and
phasor since the a-rate blocks come in at 1:1 but you need to
write them at a different block size. i suppose they could be
shingled. i did hack another parameter into tab for this but the
project ran out of steam. k. On 7/11/20 11:13 PM, Alex Weiss wrote:
|
Date | 2020-07-13 04:54 |
From | Alex Weiss |
Subject | Re: [Csnd] Table as circular buffer |
I think for my particular use case I've come up with a simple solution that avoids the problem altogether and exploits the fact that a) recording and playback/processing never happen simultaneously and b) recording happens fairly infrequently compared to playback/processing. During recording I save into an a-array while keeping track of the start and end pointer of the FIFO (similar to Victor's UDO). After recording, I just copy the contents of the array (starting from the start pointer, wrapping around at the end to the end pointer) into a table. There's only one piece of the puzzle missing: What's the most efficient way to zero out a table? On Sun, Jul 12, 2020 at 2:32 PM kelly hirai <khirai@hiraimusic.net> wrote:
|
Date | 2020-07-13 09:36 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
To zero once, you can use a GEN like GEN 2 etc. To zero regularly, maybe a zero k-rate array that you copy to the table using copya2ftab. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 13 Jul 2020, at 04:54, Alex Weiss |
Date | 2020-07-13 09:42 |
From | Eduardo Moguillansky |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
To zero a table use ftset. if kzeronow == 1 then ftset itab, k(0) ; if any of the args are k-rate, the opcode runs at k-time endif On 13.07.20 10:36, Victor Lazzarini
wrote:
To zero once, you can use a GEN like GEN 2 etc. To zero regularly, maybe a zero k-rate array that you copy to the table using copya2ftab. ======================== Prof. Victor Lazzarini Maynooth University IrelandOn 13 Jul 2020, at 04:54, Alex Weiss <alexweiss86@GMAIL.COM> wrote: WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe. I think for my particular use case I've come up with a simple solution that avoids the problem altogether and exploits the fact that a) recording and playback/processing never happen simultaneously and b) recording happens fairly infrequently compared to playback/processing. During recording I save into an a-array while keeping track of the start and end pointer of the FIFO (similar to Victor's UDO). After recording, I just copy the contents of the array (starting from the start pointer, wrapping around at the end to the end pointer) into a table. There's only one piece of the puzzle missing: What's the most efficient way to zero out a table? On Sun, Jul 12, 2020 at 2:32 PM kelly hirai <khirai@hiraimusic.net> wrote: i've been able to make method 2 work with phasor and tab to write and read. i also got variable speed reading working with poscil and careful manipulations of offset with triggered reading instruments. i'm still flummoxed how to do variable writing rates with tab and phasor since the a-rate blocks come in at 1:1 but you need to write them at a different block size. i suppose they could be shingled. i did hack another parameter into tab for this but the project ran out of steam. k. On 7/11/20 11:13 PM, Alex Weiss wrote:I'm trying to use a table as a FIFO recording buffer so that only the most current n samples are kept. Table reads and writes never happen at the same time; the instrument is either in record mode and records input into the table, or in playback mode where various opcodes read, process and/or play the table back. The only two ways I can think of both have downsides: 1) During recording, once the table is full, shift its contents back by ksmps to make room for another ksmps worth of recorded samples at the end. Repeat for each k-cycle. Obviously very inefficient. 2) Record into the table in a loop and keep a pointer to the current start of the recording (i.e. the oldest sample). The problem with this is that it makes table reads no longer straightforward -- every instrument/opcode that needs access to the table has to take this pointer into account as well as wrapping around the table. Ideally, I would like for the whole process to be completely invisible, meaning that from the outside it appears like a normal table and any opcode that needs to read from it can simply start at the beginning and read till the end. Is something like that possible? Alex Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2020-07-13 10:17 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
That is if he can build Csound from sources, as this was added post 6.14. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 13 Jul 2020, at 09:42, Eduardo Moguillansky |
Date | 2020-07-13 15:00 |
From | kelly hirai |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Table as circular buffer |
or if these are big regions and you want to avoid sudden changes in cpu load, manage valid region boundaries and clean as you go. k. On 7/13/20 5:17 AM, Victor Lazzarini wrote: > That is if he can build Csound from sources, as this was added post 6.14. > ======================== > Prof. Victor Lazzarini > Maynooth University > Ireland > >> On 13 Jul 2020, at 09:42, Eduardo Moguillansky |