[Csound] Variable-sized tables and segfault
Date | 2015-10-09 20:51 |
From | Guillermo Senna |
Subject | [Csound] Variable-sized tables and segfault |
Hi, I am toying with Partikkel Audio's Hadron Synth. The code runs well in Windows with Csound5, but I have to tweak it a bit in Linux (Csound6). By the way, is “instance” a new undocumented opcode? They use it as a name for an i-variable and I am getting 'unexpected T_OPCODE (token "instance")'. Anyway, I am not writing because of that. There is a part in an included file where the code goes: iAmpFtno ftgen 0, 0, 2, 2, 0 ftload Sampfile, 1, iAmpFtno ; Sampfile is the name of a file containing a table Each file contains a variable-sized table saved with ftsave. So the code creates a table with size 2, and then loads the table with the one saved in the file. In Windows/Csound5 that works, but in Linux/Csound6 (unless, by chance, loaded tables are of the same size of generated ones) you get a Segfault. It occurred to me that you could solve the problem by scanning/greping the file to find out the size of the table in the metadata. As I couldn't find a quick way to do that, I decided to go for something like this: iDummytable ftgen 99999, 0, 0, -23, Sampfile iSizeofdtable = ftlen(99999) - 62 ftfree 99999, 0 iAmpFtno ftgen 0, 0, iSizeofdtable, -2, 0 ftload Sampfile, 1, iAmpFtno ; Sampfile is the name of a file containing a table It works. But I think there must be a better way of creating a variable-sized, GEN02 type of table and also load it on the fly. Otherwise I am allocating and constructing a table just to find out its size each time that instrument is called. What's the right way to do it? Thanks. ------------------------------------------------------------------------------ _______________________________________________ Csound-users mailing list Csound-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/csound-users Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2015-10-10 00:40 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csound] [Csound] Variable-sized tables and segfault |
Hi, Nice to hear that someone is digging into the code for Hadron! I did some revisions of the code to run under Csound6 as well, and it will work if you just allocate a bigger ftable size first. It seems sizing down is less of a problem than sizing up. This should work iAmpFtno ftgen 0, 0, 65536, 2, 0 ; allocate table for importing table data from file (size is just an estimate) then ftload Sampfile, 1, iAmpFtno should load fine. A more proper way would perhaps be to read the ftable file and find the actual size. The file starts like this ======= TABLE 135 size: 2048 values ====== flen: 2048 ... and so on To get to the ftlen value, I think one would need to use Python opcodes to open and parse the text file. I did not want to rely on Python for Hadron to work across all platforms, hence the workaround. best Oeyvind 2015-10-09 21:51 GMT+02:00 Guillermo Senna |
Date | 2015-10-10 11:08 |
From | Victor Lazzarini |
Subject | Re: [Csound] [Csound] [Csound] Variable-sized tables and segfault |
we need to make sure that the code that ran on Csound 5 still runs on 6. Is that the case, if not we need to fix it. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland > On 10 Oct 2015, at 00:40, Oeyvind Brandtsegg |
Date | 2015-10-10 21:31 |
From | Guillermo Senna |
Subject | Re: [Csound] [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Thank YOU very much, Oeyvind! Your software is great, and it's such a great thing that you let us have the code. Now, I tried Csound 6.02 and then 6.06. The exact same steps were required to make Hadron run. Here is a pdf with what I had to do: https://drive.google.com/file/d/0B3HppEiCAar1bmo3UkE3dkdxeWM/view?usp=sharing First thing is a upper/lowercase typo and fixing the name of the instance variable. Second, the inch opcode produces a segmentation fault. I tried the same code in Linux/Csound 5.19 and it works. Third, there is a string called gSpath which I am guessing is for setting a path to the Hadron directory. Works fine in 5.19, but segfaults with 'strlen.S: No such file or directory' in 6.02 and 6.06. Fourth, by just looking at the replacements I had to do, it appears that when the output of strcat is the same as the second input argument, what you get is the first input argument repeated. Code: Sline = "there" Sline strcat "Hi, ", Sline puts Sline,1 Csound 5.19 result: Hi, there Csound 6.06 result: Hi, Hi, Now that I think about it, Third and Fourth may be the same thing. Finally, whenever ftload resizes a table -> Segmentation fault. It doesn't matter if you use a large number to create the table in the first place. Even if your table is bigger than the one about to be loaded, it still tries to resize it and segfaults. On 10/10/15 07:08, Victor Lazzarini wrote: > we need to make sure that the code that ran on Csound 5 still runs on 6. Is that the case, if not we need to fix it. > > Victor Lazzarini > Dean of Arts, Celtic Studies, and Philosophy > Maynooth University > Ireland > >> On 10 Oct 2015, at 00:40, Oeyvind Brandtsegg |
Date | 2015-10-11 05:37 |
From | Guillermo Senna |
Subject | Re: [Csound] [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Well apparently a lot of the errors in Hadron were due to the implementation of strcat in 6.02. I spent a lot of time debugging 6.06 to see why the code I was reading didn't match the execution of the program. It turns out that when I built 6.06 in /opt, I changed terminals and of course forgot to export LD_LIBRARY_PATH in the last one. It was picking libcsound64.so from /usr/lib/ instead of /opt/. I have been running 6.02 all afternoon thinking it was 6.06. But the strcat fix should work in 6.06 as i tested the cases in a new, simple .csd. But now I can't compile Hadron in 6.06 because of a problem with macros. I think it's because of bad substitutions: For example: #define PartikkelTables(N) # gifreqstartmasks$N_A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 # $PartikkelTables(1) Result: defining argument _PartikkelTables__N as...#1# Undefined macro: '$_PartikkelTables__N_A' Also, the inch opcode produced an error in 6.02 and may well produce it in 6.06, as well as the ftload thing. P.S. I sent an e-mail before containing a link to a .pdf and I am not seeing it in any of the archives. Could it be that it got marked as spam because of that link? Are links allowed? On 10/10/15 07:08, Victor Lazzarini wrote: > we need to make sure that the code that ran on Csound 5 still runs on 6. Is that the case, if not we need to fix it. > > Victor Lazzarini > Dean of Arts, Celtic Studies, and Philosophy > Maynooth University > Ireland > >> On 10 Oct 2015, at 00:40, Oeyvind Brandtsegg |
Date | 2015-10-11 06:07 |
From | Guillermo Senna |
Subject | Re: [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Well apparently a lot of the errors in Hadron were due to the
implementation of strcat in 6.02. I spent a lot of time debugging
6.06 to see why the code I was reading didn't match the execution of
the program. It turns out that when I built 6.06 in /opt, I changed
terminals and of course forgot to export LD_LIBRARY_PATH in the last
one. It was picking libcsound64.so from /usr/lib/
instead of /opt/. I have been running 6.02 all
afternoon thinking it was 6.06.
But the strcat fix should work in 6.06 as i tested the cases in a new, simple .csd. But now I can't compile Hadron in 6.06 because of a problem with macros. I think it's because of bad substitutions: For example: #define PartikkelTables(N) # gifreqstartmasks$N_A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 # $PartikkelTables(1) Result: defining argument _PartikkelTables__N as...#1# Undefined macro: '$_PartikkelTables__N_A' Also, the inch opcode produced an error in 6.02 and may well produce it in 6.06, as well as the ftload thing. P.S. I sent an e-mail before containing a link to a .pdf and I am not seeing it in any of the archives. Could it be that it got marked as spam because of that link? Are links allowed? On 10/10/15 07:08, Victor Lazzarini
wrote:
we need to make sure that the code that ran on Csound 5 still runs on 6. Is that the case, if not we need to fix it. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University IrelandOn 10 Oct 2015, at 00:40, Oeyvind Brandtsegg <oyvind.brandtsegg@NTNU.NO> wrote: Hi, Nice to hear that someone is digging into the code for Hadron! I did some revisions of the code to run under Csound6 as well, and it will work if you just allocate a bigger ftable size first. It seems sizing down is less of a problem than sizing up. This should work iAmpFtno ftgen 0, 0, 65536, 2, 0 ; allocate table for importing table data from file (size is just an estimate) then ftload Sampfile, 1, iAmpFtno should load fine. A more proper way would perhaps be to read the ftable file and find the actual size. The file starts like this ======= TABLE 135 size: 2048 values ====== flen: 2048 ... and so on To get to the ftlen value, I think one would need to use Python opcodes to open and parse the text file. I did not want to rely on Python for Hadron to work across all platforms, hence the workaround. best Oeyvind 2015-10-09 21:51 GMT+02:00 Guillermo Senna <gsenna@gmail.com>:Hi, I am toying with Partikkel Audio's Hadron Synth. The code runs well in Windows with Csound5, but I have to tweak it a bit in Linux (Csound6). By the way, is “instance” a new undocumented opcode? They use it as a name for an i-variable and I am getting 'unexpected T_OPCODE (token "instance")'. Anyway, I am not writing because of that. There is a part in an included file where the code goes: iAmpFtno ftgen 0, 0, 2, 2, 0 ftload Sampfile, 1, iAmpFtno ; Sampfile is the name of a file containing a table Each file contains a variable-sized table saved with ftsave. So the code creates a table with size 2, and then loads the table with the one saved in the file. In Windows/Csound5 that works, but in Linux/Csound6 (unless, by chance, loaded tables are of the same size of generated ones) you get a Segfault. It occurred to me that you could solve the problem by scanning/greping the file to find out the size of the table in the metadata. As I couldn't find a quick way to do that, I decided to go for something like this: iDummytable ftgen 99999, 0, 0, -23, Sampfile iSizeofdtable = ftlen(99999) - 62 ftfree 99999, 0 iAmpFtno ftgen 0, 0, iSizeofdtable, -2, 0 ftload Sampfile, 1, iAmpFtno ; Sampfile is the name of a file containing a table It works. But I think there must be a better way of creating a variable-sized, GEN02 type of table and also load it on the fly. Otherwise I am allocating and constructing a table just to find out its size each time that instrument is called. What's the right way to do it? Thanks. ------------------------------------------------------------------------------ _______________________________________________ Csound-users mailing list Csound-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/csound-users Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here-- Oeyvind Brandtsegg Professor of Music Technology NTNU 7491 Trondheim Norway Cell: +47 92 203 205 http://flyndresang.no/ http://www.partikkelaudio.com/ http://soundcloud.com/brandtsegg http://soundcloud.com/t-emp ------------------------------------------------------------------------------ _______________________________________________ Csound-users mailing list Csound-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/csound-users Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here------------------------------------------------------------------------------ _______________________________________________ Csound-users mailing list Csound-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/csound-users Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2015-10-11 20:56 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csound] [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Oh , thanks for your work in looking into it, and very sorry I have neglected to distribute the code I did change to make it run under csound6. Here is a version that should work under Csound 6. http://oeyvind.teks.no/ftp/Hadron/hadron_standalone_cs6.zip The macros now require proper termination, but a more relaxed parsing of macros was allowed in csound5. So , from your example #define PartikkelTables(N) # gifreqstartmasks$N_A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 # must be #define PartikkelTables(N) # gifreqstartmasks$N._A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 # (note the dot after $N) This is done ok in the zip file linked above. Again, sorry for your trouble. And thanks for bringing it up. best Oeyvind 2015-10-11 6:37 GMT+02:00 Guillermo Senna |
Date | 2015-10-12 19:42 |
From | Guillermo Senna |
Subject | Re: [Csound] [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Hi Oeyvind, thanks for the patched code. It works fine in 6.06. The only thing I had to do is 'mv inc/setModfuncTable.inc inc/setModFuncTable.inc'. You work in case-insensitive Windows, don't you? I was going to start debugging the 'inch' thing. But I uncommented the lines and in 6.06 there is no segfault now (of course I also changed to live input so that the inputFollow.inc instrument is called). I'll try to study the code and see what each instrument does and how it all works. Maybe I should get that Curtis Roads book. On 11/10/15 16:56, Oeyvind Brandtsegg wrote: > Oh , thanks for your work in looking into it, and very sorry I have > neglected to distribute the code I did change to make it run under > csound6. > Here is a version that should work under Csound 6. > http://oeyvind.teks.no/ftp/Hadron/hadron_standalone_cs6.zip > > The macros now require proper termination, but a more relaxed parsing > of macros was allowed in csound5. > So , from your example > #define PartikkelTables(N) # > gifreqstartmasks$N_A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 > # > must be > #define PartikkelTables(N) # > gifreqstartmasks$N._A ftgen 0, 0, giMaskSize, -2, 0, 0, 1 > # > (note the dot after $N) > This is done ok in the zip file linked above. > > Again, sorry for your trouble. And thanks for bringing it up. > best > Oeyvind > > 2015-10-11 6:37 GMT+02:00 Guillermo Senna |
Date | 2015-10-12 20:32 |
From | Oeyvind Brandtsegg |
Subject | Re: [Csound] [Csound] [Csound] [Csound] Variable-sized tables and segfault |
Good to hear that it worked for you, and thanks for the reminder regarding case for the filename. Curtis Roads' Microsound definitely recommended. It also has a very nice chapter on time. And another reference is http://lac.linuxaudio.org/2011/papers/39.pdf 2015-10-12 20:42 GMT+02:00 Guillermo Senna |