Csound Csound-dev Csound-tekno Search About

[Csnd] csound API clicks/cracks

Date2021-10-01 09:19
FromS=?UTF-8?Q?=C3=B8ren?=
Subject[Csnd] csound API clicks/cracks
Perhaps someone can help me troubleshoot the following C# code? I am hearing some random clicks and cracks, not just at the beginning but usually also 1-3 times while the tone is playing. I guess .NET may be not be the best language for realtime processing, but I am actually experiencing similar problems with PureBasic (which is very low-level and C-like), and on other computers.

using System;
using System.Runtime.InteropServices;

class Program
{
    [DllImport(@"csound64.dll")] private static extern IntPtr csoundCreate();
    [DllImport(@"csound64.dll")] private static extern long csoundSetOption(IntPtr csound, string option);
    [DllImport(@"csound64.dll")] private static extern long csoundCompileOrc(IntPtr csound, string option);
    [DllImport(@"csound64.dll")] private static extern void csoundStart(IntPtr csound);
    [DllImport(@"csound64.dll")] private static extern void csoundStop(IntPtr csound);
    [DllImport(@"csound64.dll")] private static extern long csoundPerformKsmps(IntPtr csound);
    [DllImport(@"csound64.dll")] private static extern long csoundReadScore(IntPtr csound, string option);

    static void Main(string[] args)
    {
        IntPtr csound = csoundCreate();
        csoundSetOption(csound, "-odac0");
        csoundSetOption(csound, "-b2048");
        csoundSetOption(csound, "-B2048");
        csoundCompileOrc(csound, @"
            sr=44100
            ksmps=10
            nchnls=2
            0dbfs=1
            ga init 1
            instr 1
                ga poscil 0.5, 400
                outs ga, ga
            endin
        ");
        csoundReadScore(csound, "i 1 0 5");
        csoundStart(csound);
        while (csoundPerformKsmps(csound) == 0) ;
        csoundStop(csound);
    }
}

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

Date2021-10-01 10:26
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] csound API clicks/cracks
Might not be related, but why are you using a global variable in the instrument?
I presumed you tested this code in your computer just using the csound command (or another frontend) and you are
not getting the same problems.

It could be related to -b and -B. Try just using -b, you can see if it works then you can try lowering it to -b 128 or something like that. I assume portaudio can
use the better drivers, but make sure you are not using the legacy sound libraries (MME) by not selecting that output
but something else.

What you are describing sounds like dropouts which are probably caused by the buffering not doing the job correctly. The language does not really matter
in this case because you are just using it to run the engine, which is a binary library.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 1 Oct 2021, at 09:19, Søren  wrote:
> 
> *Warning*
> 
> This 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.
> 
> Perhaps someone can help me troubleshoot the following C# code? I am hearing some random clicks and cracks, not just at the beginning but usually also 1-3 times while the tone is playing. I guess .NET may be not be the best language for realtime processing, but I am actually experiencing similar problems with PureBasic (which is very low-level and C-like), and on other computers.
> 
> using System;
> using System.Runtime.InteropServices;
> 
> class Program
> {
>    [DllImport(@"csound64.dll")] private static extern IntPtr csoundCreate();
>    [DllImport(@"csound64.dll")] private static extern long csoundSetOption(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern long csoundCompileOrc(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern void csoundStart(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern void csoundStop(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundPerformKsmps(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundReadScore(IntPtr csound, string option);
> 
>    static void Main(string[] args)
>    {
>        IntPtr csound = csoundCreate();
>        csoundSetOption(csound, "-odac0");
>        csoundSetOption(csound, "-b2048");
>        csoundSetOption(csound, "-B2048");
>        csoundCompileOrc(csound, @"
>            sr=44100
>            ksmps=10
>            nchnls=2
>            0dbfs=1
>            ga init 1
>            instr 1
>                ga poscil 0.5, 400
>                outs ga, ga
>            endin
>        ");
>        csoundReadScore(csound, "i 1 0 5");
>        csoundStart(csound);
>        while (csoundPerformKsmps(csound) == 0) ;
>        csoundStop(csound);
>    }
> }
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=H9to4ELlPdX48JwjbcEIZnc1zfzdlhflaWtjWg7VGgQ%3D&reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Nz6ogffLtid%2BupmbajVgqjQ5LFw5Gc6ve0f64uP6ccs%3D&reserved=0
> 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 here

Date2021-10-01 11:53
FromRory Walsh
SubjectRe: [Csnd] [EXTERNAL] [Csnd] csound API clicks/cracks
You can also try increasing ksmps to something higher than 10, and power of 2 is preferable.  

On Fri, 1 Oct 2021 at 10:26, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Might not be related, but why are you using a global variable in the instrument?
I presumed you tested this code in your computer just using the csound command (or another frontend) and you are
not getting the same problems.

It could be related to -b and -B. Try just using -b, you can see if it works then you can try lowering it to -b 128 or something like that. I assume portaudio can
use the better drivers, but make sure you are not using the legacy sound libraries (MME) by not selecting that output
but something else.

What you are describing sounds like dropouts which are probably caused by the buffering not doing the job correctly. The language does not really matter
in this case because you are just using it to run the engine, which is a binary library.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 1 Oct 2021, at 09:19, Søren <sorenkj@GMAIL.COM> wrote:
>
> *Warning*
>
> This 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.
>
> Perhaps someone can help me troubleshoot the following C# code? I am hearing some random clicks and cracks, not just at the beginning but usually also 1-3 times while the tone is playing. I guess .NET may be not be the best language for realtime processing, but I am actually experiencing similar problems with PureBasic (which is very low-level and C-like), and on other computers.
>
> using System;
> using System.Runtime.InteropServices;
>
> class Program
> {
>    [DllImport(@"csound64.dll")] private static extern IntPtr csoundCreate();
>    [DllImport(@"csound64.dll")] private static extern long csoundSetOption(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern long csoundCompileOrc(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern void csoundStart(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern void csoundStop(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundPerformKsmps(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundReadScore(IntPtr csound, string option);
>
>    static void Main(string[] args)
>    {
>        IntPtr csound = csoundCreate();
>        csoundSetOption(csound, "-odac0");
>        csoundSetOption(csound, "-b2048");
>        csoundSetOption(csound, "-B2048");
>        csoundCompileOrc(csound, @"
>            sr=44100
>            ksmps=10
>            nchnls=2
>            0dbfs=1
>            ga init 1
>            instr 1
>                ga poscil 0.5, 400
>                outs ga, ga
>            endin
>        ");
>        csoundReadScore(csound, "i 1 0 5");
>        csoundStart(csound);
>        while (csoundPerformKsmps(csound) == 0) ;
>        csoundStop(csound);
>    }
> }
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=H9to4ELlPdX48JwjbcEIZnc1zfzdlhflaWtjWg7VGgQ%3D&amp;reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Nz6ogffLtid%2BupmbajVgqjQ5LFw5Gc6ve0f64uP6ccs%3D&amp;reserved=0
> 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 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 here

Date2021-10-01 13:42
FromSøren Jakobsen
SubjectRe: [Csnd] [EXTERNAL] [Csnd] csound API clicks/cracks
Thanks for the help! If I remove the -B option I can not get good latency without ASIO, but it does indeed seem to help now.
I thought .NET might sometimes delay the thread so that csoundPerformKsmps would not be called in time, but I guess there is no problem with that then.
The global variable was a 'typo'.

On Fri, 1 Oct 2021 at 13:53, Rory Walsh <rorywalsh@ear.ie> wrote:
You can also try increasing ksmps to something higher than 10, and power of 2 is preferable.  

On Fri, 1 Oct 2021 at 10:26, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Might not be related, but why are you using a global variable in the instrument?
I presumed you tested this code in your computer just using the csound command (or another frontend) and you are
not getting the same problems.

It could be related to -b and -B. Try just using -b, you can see if it works then you can try lowering it to -b 128 or something like that. I assume portaudio can
use the better drivers, but make sure you are not using the legacy sound libraries (MME) by not selecting that output
but something else.

What you are describing sounds like dropouts which are probably caused by the buffering not doing the job correctly. The language does not really matter
in this case because you are just using it to run the engine, which is a binary library.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 1 Oct 2021, at 09:19, Søren <sorenkj@GMAIL.COM> wrote:
>
> *Warning*
>
> This 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.
>
> Perhaps someone can help me troubleshoot the following C# code? I am hearing some random clicks and cracks, not just at the beginning but usually also 1-3 times while the tone is playing. I guess .NET may be not be the best language for realtime processing, but I am actually experiencing similar problems with PureBasic (which is very low-level and C-like), and on other computers.
>
> using System;
> using System.Runtime.InteropServices;
>
> class Program
> {
>    [DllImport(@"csound64.dll")] private static extern IntPtr csoundCreate();
>    [DllImport(@"csound64.dll")] private static extern long csoundSetOption(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern long csoundCompileOrc(IntPtr csound, string option);
>    [DllImport(@"csound64.dll")] private static extern void csoundStart(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern void csoundStop(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundPerformKsmps(IntPtr csound);
>    [DllImport(@"csound64.dll")] private static extern long csoundReadScore(IntPtr csound, string option);
>
>    static void Main(string[] args)
>    {
>        IntPtr csound = csoundCreate();
>        csoundSetOption(csound, "-odac0");
>        csoundSetOption(csound, "-b2048");
>        csoundSetOption(csound, "-B2048");
>        csoundCompileOrc(csound, @"
>            sr=44100
>            ksmps=10
>            nchnls=2
>            0dbfs=1
>            ga init 1
>            instr 1
>                ga poscil 0.5, 400
>                outs ga, ga
>            endin
>        ");
>        csoundReadScore(csound, "i 1 0 5");
>        csoundStart(csound);
>        while (csoundPerformKsmps(csound) == 0) ;
>        csoundStop(csound);
>    }
> }
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=H9to4ELlPdX48JwjbcEIZnc1zfzdlhflaWtjWg7VGgQ%3D&amp;reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&amp;data=04%7C01%7CVictor.Lazzarini%40mu.ie%7Ca9b7712c2a744c34d34c08d984b44825%7C1454f5ccbb354685bbd98621fd8055c9%7C1%7C1%7C637686732131670476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Nz6ogffLtid%2BupmbajVgqjQ5LFw5Gc6ve0f64uP6ccs%3D&amp;reserved=0
> 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 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 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 here