Csound Csound-dev Csound-tekno Search About

[Csnd] Re: Re: simple example sought for controlling sound by numbers in file

Date2008-02-05 00:51
From"Michael Gogins"
Subject[Csnd] Re: Re: simple example sought for controlling sound by numbers in file
I am sure there are many ways of doing this. Tim's way of doing this may be 
best. Another one that springs to mind is:

1. Write a Csound orchestra in which each type of film cue to be received is 
a global control channel, and the instruments have the appropriate 
parameters controlled by these channels. In resposne the instruments can do 
anything: change sound, start and stop, spawn other notes, etc.

2. Write a Python script to compile this orchestra.

3. Have the script run Csound one kperiod (which could be just 1 sample) at 
a time.

3. In between samples, have the script read the film cue file, look up the 
pending film cues for that sample, and set the relevant global control 
channels.

If the orchestra is simple enough and the cues simple enough this should 
work in real time. But it will certainly work for any complexity with 
off-line rendering.

Hope this helps,
Mike

----- Original Message ----- 
From: "Tim Mortimer" 
To: 
Sent: Monday, February 04, 2008 6:31 PM
Subject: [Csnd] Re: simple example sought for controlling sound by numbers 
in file


>
> Yes, well, Im very confused - but also no stranger to the pursuit of far
> flung & esoteric ideas....
>
> you might want to look at opcodes like schedkwhen, event etc - they will
> allow for triggering & retriggering of score like statements within the
> orchestra itself at any krate (or division thereof) you specify.
>
> it may seem slightly counter intuitive, but using one instrument to 
> schedule
> a second instrument that continually rewrites the value of a global k
> variable that is accessed by a third instrument (to provide something like
> reverbmix..)  is not an uncomon practice! ; ) & that might be the type of
> model you are looking for...
>
> or you could load values in an ftable via gen23 & sucessively look up the
> index points at the desired rate...???
>
> in terms of example code, well, how new are you to csound? have a look at
> Dr. Boulangers "toots" to get across some basic modus operandi - & i know
> there is a good chapter in the csound book that illustrates the schedkwhen 
> &
> conditional retriggering of events from within the orchestra itself... 
> with
> this in mind, (conditionals..) look for Steven Yi's article about if
> statements in the Csound Journal (from 2006 i believe...)
>
> but on the upside, the process you are describing is potentially seen as 
> so
> 'generic" at it's core that ther may be many, many alternate ways to 
> address
> it. After all, "controlling sound by numbers" is a reasonable analogy for
> 99.9% of csound full stop. But hopefully i've given you some starting 
> ideas
> for not having to score every single event in sco syntax....
>
>
> Lee Spector wrote:
>>
>> I apologize for what is probably a simple question -- I am new at this --
>> but I haven't found the answer in any of the tutorials or references or
>> archives and I'd appreciate some help -- even if it's just pointing out
>> that I missed something obvious in one of the tutorials.
>>
>> I want features of my sound to be controlled by a list of numbers that I
>> have in a text file. The numbers come from a movie, with one number per
>> frame (actually derived from the frame), and I want them to be applied to
>> the sound at the same rate as they occur in the movie, so that I can 
>> later
>> add the sound back to the movie and have the frames and their audio
>> correlates be synchronized (or close -- I'm not worried about exact
>> synchronization). If it helps I could generate an "expanded" version of
>> the data file so that it represents a signal at k-rate, e.g. by just
>> duplicating each value k-rate/frame-rate many times.  I could also
>> pre-scale the numbers to any range, e.g. 0-1.
>>
>> What I'm looking for is a simple example that reads such a file and uses
>> the numbers to control some aspect of a sound at the right rate; any
>> aspect would do as an example, e.g. amplitude, pitch, filter values,
>> global reverb amount, etc. The "fink" opcode seems possibly useful but it
>> doesn't look like it expects a file in text format. And I'm not sure how
>> to use it in any event -- I can't find any examples. Is there a more
>> appropriate opcode? Or should this be approached in some completely
>> different way? I could even paste the numbers directly into the orc or 
>> scr
>> file (where? there won't generally be an even power of 2 of them),
>> although that could be a lot of numbers. I'd like to start with short
>> movies of about 15 seconds at 25 frames/second which means I'll have 
>> about
>> 375 numbers -- or a lot more if I duplicate them to run at k-rate.
>>
>> One thing that I do know how to do is to process my numbers externally to
>> produce note events that I could paste into a score file, and I could do
>> this in a way that synchronizes some audio events with some of the events
>> in the movie... but I'm looking for finer-grained effects. I see examples
>> of the kind of effects that I want being controlled from MIDI inputs or
>> from computed wave forms, but not from arbitrary numbers in a text file.
>>
>> I'd appreciate any code, pointers, comments, etc. I'm new enough at this
>> that a complete example (orc file + score file) would be especially
>> helpful, even if it's very simple, but I'll be grateful for any advice
>> anyone can provide.
>>
>> Thanks,
>>
>>  -Lee (lspector@hampshire.edu)
>>
>>
>>
>>
>>
>>
>
>
> -----
> *******************
> www.phasetransitions.net
> hermetic music * python * csound * possibly mindless ranting
> various werk in perpetual delusions of progress....
> coming soon.....
>
> -- 
> View this message in context: 
> http://www.nabble.com/simple-example-sought-for-controlling-sound-by-numbers-in-file-tp15262115p15280314.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
> csound" 


Date2008-02-05 19:28
FromAnthony Kozar
Subject[Csnd] Re: Re: Re: simple example sought for controlling sound by numbers in file
I think that the readk opcode is exactly what Lee is looking for -- writing
a Python host or using schedkwhen both seem like overkill.

The Csound 5.07 documentation for readk is here:

http://csounds.com/manual/html/readk.html

You will want to use iformat = 7 or 8 (text integers or text floating-point
numbers).  And set the "iprd" parameter to the frame period (1 /
frame-rate).

Note that the current online version of the readk manual page is a little
confusing and does not give a good example.  It has been rewritten for the
forthcoming Csound 5.08 manual.

Here is the updated manual page along with a new example written by Andres
Cabrera:

    readk
    
    Periodically reads an orchestra control-signal value from an
    external file.


    Description
    
    Periodically reads an orchestra control-signal value to a named
    external file in a specific format.


    Syntax 
       kres readk ifilname, iformat, iprd

    Initialization
    
    ifilname -- an integer N denoting a file named "readk.N" or a
    character string (in double quotes, spaces permitted) denoting the
    external file name. For a string, it may either be a full path name
    with directory specified or a simple filename.  In the later case,
    the file is sought first in the current directory, then in SSDIR,
    and finally in SFDIR.

    iformat -- specifies the input data format:

        1 = 8-bit signed integers (char)

        4 = 16-bit short integers

        5 = 32-bit long integers

        6 = 32-bit floats

        7 = ASCII long integers (plain text)

        8 = ASCII floats (plain text)

    Note that A-law and U-law formats are not available, and that all
    formats except the last two are binary. The input file should be a
    "raw", headerless data file.

    iprd -- the rate (period) in seconds, rounded to the nearest
    orchestra control period, at which the signal is read from the
    input file.  A value of 0 implies one control period (the enforced
    minimum), which will read new values at the orchestra control rate.
    Longer periods will cause the same values to repeat for more than
    one control period unless interpolation is used.

    Performance

    kres -- output of the signal read from ifilname.

    This opcode allows a generated control signal value to be read from
    a named external file. The file should contain no header information
    but it should contain a regularly sampled time series of control
    values. For ASCII text formats, the values are assumed to be
    separated by at least one whitespace character. There may be any
    number of readk opcodes in an instrument or orchestra and they may
    read from the same or different files.

    Examples
    Here is an example of the readk opcode.  (see below)

    See Also
    dumpk, dumpk2, dumpk3, dumpk4, readk2, readk3, readk4

    Credits By: John ffitch Feb 14 1999

-------------------



; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o readk.wav -W ;;; for file output any platform



; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

0dbfs = 1
; By Andres Cabrera 2008

instr 1
; Read a number from the file every 0.5 seconds
  kfibo readk "fibonacci.txt", 7, 0.5
  kpitchclass = 8 +  ((kfibo % 12)/100)
  printk2 kpitchclass
  kcps = cpspch( kpitchclass )
  printk2 kcps
  a1 oscil 0.5, kcps, 1
  out a1
endin




f 1 0 1024 10 1
i 1 0 10
e





-------------------

fibonacci.txt:

1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765


-------------------

Michael Gogins wrote on 2/4/08 7:51 PM:

> 3. Have the script run Csound one kperiod (which could be just 1 sample) at
> a time.
> 
> 3. In between samples, have the script read the film cue file, look up the
> pending film cues for that sample, and set the relevant global control
> channels.

> ----- Original Message -----
> From: "Tim Mortimer" 
> To: 
> Sent: Monday, February 04, 2008 6:31 PM
> Subject: [Csnd] Re: simple example sought for controlling sound by numbers
> in file

>> it may seem slightly counter intuitive, but using one instrument to
>> schedule
>> a second instrument that continually rewrites the value of a global k
>> variable that is accessed by a third instrument (to provide something like
>> reverbmix..)  is not an uncomon practice! ; ) & that might be the type of
>> model you are looking for...

>> Lee Spector wrote:

>>> I want features of my sound to be controlled by a list of numbers that I
>>> have in a text file. The numbers come from a movie, with one number per
>>> frame (actually derived from the frame), and I want them to be applied to
>>> the sound at the same rate as they occur in the movie, so that I can
>>> later
>>> add the sound back to the movie and have the frames and their audio
>>> correlates be synchronized (or close -- I'm not worried about exact
>>> synchronization). If it helps I could generate an "expanded" version of
>>> the data file so that it represents a signal at k-rate, e.g. by just
>>> duplicating each value k-rate/frame-rate many times.  I could also
>>> pre-scale the numbers to any range, e.g. 0-1.
>>> 
>>> What I'm looking for is a simple example that reads such a file and uses
>>> the numbers to control some aspect of a sound at the right rate; any
>>> aspect would do as an example, e.g. amplitude, pitch, filter values,
>>> global reverb amount, etc.


Date2008-02-06 00:01
FromLee Spector
Subject[Csnd] Re: Re: Re: Re: simple example sought for controlling sound by numbers in file
Thanks so much Anthony -- this does indeed look like exactly what I  
need.

Thanks also TIm and Michael -- your replies also provide food for  
thought (and thanks for pointing out gen23, which I had somehow  
overlooked).

  -Lee



On Feb 5, 2008, at 2:28 PM, Anthony Kozar wrote:

> I think that the readk opcode is exactly what Lee is looking for --  
> writing
> a Python host or using schedkwhen both seem like overkill.
>
> The Csound 5.07 documentation for readk is here:
>
> http://csounds.com/manual/html/readk.html
>
> You will want to use iformat = 7 or 8 (text integers or text  
> floating-point
> numbers).  And set the "iprd" parameter to the frame period (1 /
> frame-rate).
>
> Note that the current online version of the readk manual page is a  
> little
> confusing and does not give a good example.  It has been rewritten  
> for the
> forthcoming Csound 5.08 manual.
>
> Here is the updated manual page along with a new example written by  
> Andres
> Cabrera:
>
>     readk
>
>     Periodically reads an orchestra control-signal value from an
>     external file.
>
>
>     Description
>
>     Periodically reads an orchestra control-signal value to a named
>     external file in a specific format.
>
>
>     Syntax
>        kres readk ifilname, iformat, iprd
>
>     Initialization
>
>     ifilname -- an integer N denoting a file named "readk.N" or a
>     character string (in double quotes, spaces permitted) denoting the
>     external file name. For a string, it may either be a full path  
> name
>     with directory specified or a simple filename.  In the later case,
>     the file is sought first in the current directory, then in SSDIR,
>     and finally in SFDIR.
>
>     iformat -- specifies the input data format:
>
>         1 = 8-bit signed integers (char)
>
>         4 = 16-bit short integers
>
>         5 = 32-bit long integers
>
>         6 = 32-bit floats
>
>         7 = ASCII long integers (plain text)
>
>         8 = ASCII floats (plain text)
>
>     Note that A-law and U-law formats are not available, and that all
>     formats except the last two are binary. The input file should be a
>     "raw", headerless data file.
>
>     iprd -- the rate (period) in seconds, rounded to the nearest
>     orchestra control period, at which the signal is read from the
>     input file.  A value of 0 implies one control period (the enforced
>     minimum), which will read new values at the orchestra control  
> rate.
>     Longer periods will cause the same values to repeat for more than
>     one control period unless interpolation is used.
>
>     Performance
>
>     kres -- output of the signal read from ifilname.
>
>     This opcode allows a generated control signal value to be read  
> from
>     a named external file. The file should contain no header  
> information
>     but it should contain a regularly sampled time series of control
>     values. For ASCII text formats, the values are assumed to be
>     separated by at least one whitespace character. There may be any
>     number of readk opcodes in an instrument or orchestra and they may
>     read from the same or different files.
>
>     Examples
>     Here is an example of the readk opcode.  (see below)
>
>     See Also
>     dumpk, dumpk2, dumpk3, dumpk4, readk2, readk3, readk4
>
>     Credits By: John ffitch Feb 14 1999
>
> -------------------
>
> 
> 
> ; Select audio/midi flags here according to platform
> ; Audio out   Audio in
> -odac           -iadc    ;;;RT audio I/O
> ; For Non-realtime ouput leave only the line below:
> ; -o readk.wav -W ;;; for file output any platform
> 
> 
>
> ; Initialize the global variables.
> sr = 44100
> kr = 4410
> ksmps = 10
> nchnls = 1
>
> 0dbfs = 1
> ; By Andres Cabrera 2008
>
> instr 1
> ; Read a number from the file every 0.5 seconds
>   kfibo readk "fibonacci.txt", 7, 0.5
>   kpitchclass = 8 +  ((kfibo % 12)/100)
>   printk2 kpitchclass
>   kcps = cpspch( kpitchclass )
>   printk2 kcps
>   a1 oscil 0.5, kcps, 1
>   out a1
> endin
>
>
> 
> 
> f 1 0 1024 10 1
> i 1 0 10
> e
>
>
> 
> 
>
> -------------------
>
> fibonacci.txt:
>
> 1
> 1
> 2
> 3
> 5
> 8
> 13
> 21
> 34
> 55
> 89
> 144
> 233
> 377
> 610
> 987
> 1597
> 2584
> 4181
> 6765
>
>
> -------------------
>
> Michael Gogins wrote on 2/4/08 7:51 PM:
>
>> 3. Have the script run Csound one kperiod (which could be just 1  
>> sample) at
>> a time.
>>
>> 3. In between samples, have the script read the film cue file,  
>> look up the
>> pending film cues for that sample, and set the relevant global  
>> control
>> channels.
>
>> ----- Original Message -----
>> From: "Tim Mortimer" 
>> To: 
>> Sent: Monday, February 04, 2008 6:31 PM
>> Subject: [Csnd] Re: simple example sought for controlling sound by  
>> numbers
>> in file
>
>>> it may seem slightly counter intuitive, but using one instrument to
>>> schedule
>>> a second instrument that continually rewrites the value of a  
>>> global k
>>> variable that is accessed by a third instrument (to provide  
>>> something like
>>> reverbmix..)  is not an uncomon practice! ; ) & that might be the  
>>> type of
>>> model you are looking for...
>
>>> Lee Spector wrote:
>
>>>> I want features of my sound to be controlled by a list of  
>>>> numbers that I
>>>> have in a text file. The numbers come from a movie, with one  
>>>> number per
>>>> frame (actually derived from the frame), and I want them to be  
>>>> applied to
>>>> the sound at the same rate as they occur in the movie, so that I  
>>>> can
>>>> later
>>>> add the sound back to the movie and have the frames and their audio
>>>> correlates be synchronized (or close -- I'm not worried about exact
>>>> synchronization). If it helps I could generate an "expanded"  
>>>> version of
>>>> the data file so that it represents a signal at k-rate, e.g. by  
>>>> just
>>>> duplicating each value k-rate/frame-rate many times.  I could also
>>>> pre-scale the numbers to any range, e.g. 0-1.
>>>>
>>>> What I'm looking for is a simple example that reads such a file  
>>>> and uses
>>>> the numbers to control some aspect of a sound at the right rate;  
>>>> any
>>>> aspect would do as an example, e.g. amplitude, pitch, filter  
>>>> values,
>>>> global reverb amount, etc.
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438


Date2008-02-06 04:08
FromDavidW
Subject[Csnd] Re: Re: simple example sought for controlling sound by numbers in file
On 06/02/2008, at 6:28 AM, Anthony Kozar wrote:
...
> Here is the updated manual page along with a new example written by  
> Andres
> Cabrera:
>
>    readk
>
>    Periodically reads an orchestra control-signal value from an
>    external file.
>
>
>    Description
>
>    Periodically reads an orchestra control-signal value to a named
>    external file in a specific format.
>
>
surely that shoud say ... " from a named external file"..

________________________________________________
David Worrall.
- Experimental Polymedia:	www.avatar.com.au
- Education for Financial Independence: www.mindthemarkets.com.au
Australian research affiliations:
- Capital Markets Cooperative Research Centre: www.cmcrc.com
- Sonic Communications Research Group:	creative.canberra.edu.au/scrg



Date2008-02-06 05:03
FromAnthony Kozar
Subject[Csnd] Re: Re: Re: simple example sought for controlling sound by numbers in file
Yes.  Thank you, I missed that one.

At least the entry no longer talks about an "output file".  ^_^

Anthony

DavidW wrote on 2/5/08 11:08 PM:

> On 06/02/2008, at 6:28 AM, Anthony Kozar wrote:
> ...
>> Periodically reads an orchestra control-signal value to a named
>> external file in a specific format.
>> 
>> 
> surely that shoud say ... " from a named external file"..