Csound Csound-dev Csound-tekno Search About

Keeping Csound open in Python without grabbing an audio device?

Date2015-04-28 12:41
FromChuckk Hubbard
SubjectKeeping Csound open in Python without grabbing an audio device?
AttachmentsNone  None  
Hello.

I'm once again trying to make Csound work somehow calling Python callables from within the Python csnd6 module. I'm using Python 2.7.8 and Csound 6.04 with doubles on Windows 7.

Oeyvind offered me an example last year, but on attempting to work with it now, I see that, on running, it prints everything expected and closes very quickly, instead of remaining open. OK, I added "c.SetOption("-+rtaudio=portaudio") and another such line choosing an output, and it stays open.
Unfortunately, I want to use this program to send MIDI and other messages to another audio program which will be exclusively controlling my soundcard. If I start it (Cubase, but maybe other users of my program will use something else) and activate its audio output, and then run my Python script using -+rtaudio=portaudio -odac0, I get crashes; if I take out the -+rtaudio and -o flags, Csound runs quickly and ends. Is there another way to keep Csound open and running in real time without actually taking over a real audio output? I tried "-+rtaudio=null", I also tried just "-+rtaudio=portaudio" without an "-o" flag, neither works.
If I use portaudio and name an output being used by Cubase, I get:

 *** PortAudio: error: -9985: Device unavailable
closing device
Failed to initialise real time audio output
Fatal Python error: (pygame parachute) Segmentation Fault

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
......................................

Can anyone offer any suggestions?
Here is the script I'm trying:

#!/usr/bin/env python

import csnd6
import pygame.midi as md

player = csnd6.CppSound()
md.init()
player.mout = md.Output(6)

def midisendon(n, b, v, c):
    inn = int(n)
    fb = float(b)
    iv = int(v)
    ic = int(c)
    player.mout.note_on(inn, iv, ic)


def midisendoff(n, b, v, c):
    inn = int(n)
    fb = float(b)
    iv = int(v)
    ic = int(c)
    player.mout.note_off(inn, iv, ic)

orc = '''
sr = 44100
ksmps = 16
nchnls = 2

pyinit

instr MIDIon
inn = p4
ivel = p5
ichn = p6

pycalli "midisendon", inn, 0, ivel, ichn

endin

instr MIDIoff
inn = p4
ivel = p5
ichn = p6

pycalli "midisendoff", inn, 0, ivel, ichn

endin

'''

sco = '''
f0 10

i "MIDIon" 0 .2 69 110 2
i "MIDIoff" 2 .2 60 0 2
'''

player.SetOption("-m0d")  # Using SetOption() to configure Csound
player.SetOption("-+rtaudio=portaudio")
player.SetOption("-odac0")
player.CompileOrc(orc)
player.ReadScore(sco)
player.Start()
while (player.PerformKsmps() == 0):
  pass
player.Perform()
#player.Stop()
del player.mout

Date2015-04-29 21:55
FromOeyvind Brandtsegg
SubjectRe: Keeping Csound open in Python without grabbing an audio device?
Hi Chuckk,
Perhaps you could try using ASIO4ALL to allow several programs to
share the audio device?
Jack could also be an alternative. Or you could use Rearoute (Reaper)
or another virtual sound card as your "dummy" device.
There might be some sourcery that I am unaware of, but I *think* you
will need an audio device connected to allow correct timing for Csound
running in realtime.
Oeyvind

2015-04-28 13:41 GMT+02:00 Chuckk Hubbard :
> Hello.
>
> I'm once again trying to make Csound work somehow calling Python callables
> from within the Python csnd6 module. I'm using Python 2.7.8 and Csound 6.04
> with doubles on Windows 7.
>
> Oeyvind offered me an example last year, but on attempting to work with it
> now, I see that, on running, it prints everything expected and closes very
> quickly, instead of remaining open. OK, I added
> "c.SetOption("-+rtaudio=portaudio") and another such line choosing an
> output, and it stays open.
> Unfortunately, I want to use this program to send MIDI and other messages to
> another audio program which will be exclusively controlling my soundcard. If
> I start it (Cubase, but maybe other users of my program will use something
> else) and activate its audio output, and then run my Python script using
> -+rtaudio=portaudio -odac0, I get crashes; if I take out the -+rtaudio and
> -o flags, Csound runs quickly and ends. Is there another way to keep Csound
> open and running in real time without actually taking over a real audio
> output? I tried "-+rtaudio=null", I also tried just "-+rtaudio=portaudio"
> without an "-o" flag, neither works.
> If I use portaudio and name an output being used by Cubase, I get:
>
>  *** PortAudio: error: -9985: Device unavailable
> closing device
> Failed to initialise real time audio output
> Fatal Python error: (pygame parachute) Segmentation Fault
>
> This application has requested the Runtime to terminate it in an unusual
> way.
> Please contact the application's support team for more information.
> ......................................
>
> Can anyone offer any suggestions?
> Here is the script I'm trying:
>
> #!/usr/bin/env python
>
> import csnd6
> import pygame.midi as md
>
> player = csnd6.CppSound()
> md.init()
> player.mout = md.Output(6)
>
> def midisendon(n, b, v, c):
>     inn = int(n)
>     fb = float(b)
>     iv = int(v)
>     ic = int(c)
>     player.mout.note_on(inn, iv, ic)
>
>
> def midisendoff(n, b, v, c):
>     inn = int(n)
>     fb = float(b)
>     iv = int(v)
>     ic = int(c)
>     player.mout.note_off(inn, iv, ic)
>
> orc = '''
> sr = 44100
> ksmps = 16
> nchnls = 2
>
> pyinit
>
> instr MIDIon
> inn = p4
> ivel = p5
> ichn = p6
>
> pycalli "midisendon", inn, 0, ivel, ichn
>
> endin
>
> instr MIDIoff
> inn = p4
> ivel = p5
> ichn = p6
>
> pycalli "midisendoff", inn, 0, ivel, ichn
>
> endin
>
> '''
>
> sco = '''
> f0 10
>
> i "MIDIon" 0 .2 69 110 2
> i "MIDIoff" 2 .2 60 0 2
> '''
>
> player.SetOption("-m0d")  # Using SetOption() to configure Csound
> player.SetOption("-+rtaudio=portaudio")
> player.SetOption("-odac0")
> player.CompileOrc(orc)
> player.ReadScore(sco)
> player.Start()
> while (player.PerformKsmps() == 0):
>   pass
> player.Perform()
> #player.Stop()
> del player.mout
>
> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> 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
>


Date2015-05-04 13:08
FromChuckk Hubbard
SubjectRe: Keeping Csound open in Python without grabbing an audio device?
AttachmentsNone  None  
OK, thanks, Oeyvind. I downloaded and tried a virtual cable program and it's working for the time being as a dummy output.
I'm curious about ASIO4ALL. I haven't yet seen it showing up as a Csound output, though I have it installed. I'll take a look now.

-Chuckk

On Wed, Apr 29, 2015 at 11:55 PM, Oeyvind Brandtsegg <oyvind.brandtsegg@ntnu.no> wrote:
Hi Chuckk,
Perhaps you could try using ASIO4ALL to allow several programs to
share the audio device?
Jack could also be an alternative. Or you could use Rearoute (Reaper)
or another virtual sound card as your "dummy" device.
There might be some sourcery that I am unaware of, but I *think* you
will need an audio device connected to allow correct timing for Csound
running in realtime.
Oeyvind

2015-04-28 13:41 GMT+02:00 Chuckk Hubbard <badmuthahubbard@gmail.com>:
> Hello.
>
> I'm once again trying to make Csound work somehow calling Python callables
> from within the Python csnd6 module. I'm using Python 2.7.8 and Csound 6.04
> with doubles on Windows 7.
>
> Oeyvind offered me an example last year, but on attempting to work with it
> now, I see that, on running, it prints everything expected and closes very
> quickly, instead of remaining open. OK, I added
> "c.SetOption("-+rtaudio=portaudio") and another such line choosing an
> output, and it stays open.
> Unfortunately, I want to use this program to send MIDI and other messages to
> another audio program which will be exclusively controlling my soundcard. If
> I start it (Cubase, but maybe other users of my program will use something
> else) and activate its audio output, and then run my Python script using
> -+rtaudio=portaudio -odac0, I get crashes; if I take out the -+rtaudio and
> -o flags, Csound runs quickly and ends. Is there another way to keep Csound
> open and running in real time without actually taking over a real audio
> output? I tried "-+rtaudio=null", I also tried just "-+rtaudio=portaudio"
> without an "-o" flag, neither works.
> If I use portaudio and name an output being used by Cubase, I get:
>
>  *** PortAudio: error: -9985: Device unavailable
> closing device
> Failed to initialise real time audio output
> Fatal Python error: (pygame parachute) Segmentation Fault
>
> This application has requested the Runtime to terminate it in an unusual
> way.
> Please contact the application's support team for more information.
> ......................................
>
> Can anyone offer any suggestions?
> Here is the script I'm trying:
>
> #!/usr/bin/env python
>
> import csnd6
> import pygame.midi as md
>
> player = csnd6.CppSound()
> md.init()
> player.mout = md.Output(6)
>
> def midisendon(n, b, v, c):
>     inn = int(n)
>     fb = float(b)
>     iv = int(v)
>     ic = int(c)
>     player.mout.note_on(inn, iv, ic)
>
>
> def midisendoff(n, b, v, c):
>     inn = int(n)
>     fb = float(b)
>     iv = int(v)
>     ic = int(c)
>     player.mout.note_off(inn, iv, ic)
>
> orc = '''
> sr = 44100
> ksmps = 16
> nchnls = 2
>
> pyinit
>
> instr MIDIon
> inn = p4
> ivel = p5
> ichn = p6
>
> pycalli "midisendon", inn, 0, ivel, ichn
>
> endin
>
> instr MIDIoff
> inn = p4
> ivel = p5
> ichn = p6
>
> pycalli "midisendoff", inn, 0, ivel, ichn
>
> endin
>
> '''
>
> sco = '''
> f0 10
>
> i "MIDIon" 0 .2 69 110 2
> i "MIDIoff" 2 .2 60 0 2
> '''
>
> player.SetOption("-m0d")  # Using SetOption() to configure Csound
> player.SetOption("-+rtaudio=portaudio")
> player.SetOption("-odac0")
> player.CompileOrc(orc)
> player.ReadScore(sco)
> player.Start()
> while (player.PerformKsmps() == 0):
>   pass
> player.Perform()
> #player.Stop()
> del player.mout
>
> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> 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

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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



--