# appending lines to get an audio signal Classic List Threaded 5 messages Open this post in threaded view
|

## appending lines to get an audio signal

 # Hello,# I couldn't figure out how to implement an instrument in Csound. I'll be glad if anyone helps this newbie.# First, two numbers from a random number generator are taken (say a and b). a and b are y values of two points (p1 and p2) on a coordinate system of integers. Their distance on x axis is determined with another parameter L. L is the number of samples between two points. Then a line is drawn from p1 to p2, whose slope is m=(b-a)/L # Then another number (c) is taken from random number generator, and p3's coordinates are (2*L, c) and another line from p2 to p3 is drawn. and so on... # I want to send this graph to sound card. I know that rand opcode produces random numbers, and line opcode produces linear interpolation between two points, but I can't find how to append successive lines and get an audio stream. # If I can carry out this version successfully, I'll replace random generator with difference equations and replace linear interpolation with other kinds of interpolations. May be interesting sounds can be obtained with difference equations of which behaviour are chaotic, eg: y_i+1 = r * y_i * (1 - y_i)-ugur guney-  ps: Here is a nice ascii art :-) to explain my question without using bad English. b|..../\ .|.../..\ .|../....\ a|./......\ .|.........\../ c|..........\/ --------------  |..L..|..L..|
Open this post in threaded view
|

## Re: appending lines to get an audio signal

 The randi opcode does exactly what you describe (connecting ranom numbers generated at some interval with lines), however, you can also implement similar functionality as shown below (an example is attached):          opcode RandomLines, a, kkko          setksmps 1 kmin, kmax, kL, iseed   xin kcnt    init 1000000 kB      init 0 kcnt    =  kcnt + 1          if (kcnt >= kL) then          if (kcnt >= 1000000) then kB      rnd31 (kmax - kmin) * 0.5, 0, iseed kB      =  kB + (kmax + kmin) * 0.5 kval    =  kB          endif kA      =  kB kB      rnd31 (kmax - kmin) * 0.5, 0, iseed kB      =  kB + (kmax + kmin) * 0.5 kinc =  (kB - kA) / kL kcnt    =  0          endif aout upsamp kval kval    =  kval + kinc          xout aout          endop sokratesla wrote: > # Hello, > # I couldn't figure out how to implement an instrument in Csound. I'll > be glad if anyone helps this newbie. > # First, two numbers from a random number generator are taken (say a and b). > a and b are y values of two points (p1 and p2) on a coordinate system of > integers. Their distance on x axis is > determined with another parameter L. L is the number of samples between > two points. > Then a line is drawn from p1 to p2, whose slope is m=(b-a)/L > # Then another number (c) is taken from random number generator, and > p3's coordinates > are (2*L, c) and another line from p2 to p3 is drawn. and so on... > # I want to send this graph to sound card. I know that rand opcode > produces random numbers, and > line opcode produces linear interpolation between two points, but I > can't find how to append > successive lines and get an audio stream. > # If I can carry out this version successfully, I'll replace random > generator with difference > equations and replace linear interpolation with other kinds of > interpolations. May be interesting > sounds can be obtained with difference equations of which behaviour are > chaotic, eg: > y_i+1 = r * y_i * (1 - y_i) > -ugur guney- >   > ps: Here is a nice ascii art :-) to explain my question without using > bad English. > > b|..../\ > .|.../..\ > .|../....\ > a|./......\ > .|.........\../ > c|..........\/ > -------------- >  |..L..|..L..| sr =  48000 ksmps =  32 nchnls =  1 0dbfs =  1         opcode RandomLines, a, kkko         setksmps 1 kmin, kmax, kL, iseed   xin kcnt    init 1000000 kB      init 0 kcnt    =  kcnt + 1         if (kcnt >= kL) then         if (kcnt >= 1000000) then kB      rnd31 (kmax - kmin) * 0.5, 0, iseed kB      =  kB + (kmax + kmin) * 0.5 kval    =  kB         endif kA      =  kB kB      rnd31 (kmax - kmin) * 0.5, 0, iseed kB      =  kB + (kmax + kmin) * 0.5 kinc =  (kB - kA) / kL kcnt    =  0         endif aout upsamp kval kval    =  kval + kinc         xout aout         endop         instr 1 a1 RandomLines -0.75, 0.75, 100         out a1         endin i 1 0 1 e
Open this post in threaded view
|

## Re: appending lines to get an audio signal

 On Tue, 16 Aug 2005, Istvan Varga wrote: > The randi opcode does exactly what you describe (connecting ranom numbers > generated at some interval with lines), however, you can also implement > similar functionality as shown below (an example is attached): Or this works at the audio rate and I think generalizes to higher order interpolation with somthing like aA <- aB aB <- aC get new aC aRamp <- phasor aQuad <- aRamp^2 aOut <- aB + (aC-aA)/2*aRamp + (aA+2*aB+aC)/2*aQuad for quadratic (I've not tried it yet). Something similar might even work for non-polynomial interpolation schemes. csound -W  -o 0091.wav ; interpolate between noise samples per list request      sr = 44100      kr = 4410      ksmps = 10      nchnls = 2 instr 1 ; aA and aB are the values at the start and end of an interval ; I'll be setting aA to aB each period so I need an initial aB aB init 0 ; aRamp sets the interval for the random changes aRamp phasor p4 ; delay aRamp by one sample. Then the difference between aRamp and ; aRampD is something like -p4/sr except where aRamp resets where it ; is almost 1. I look that up in a table to force almost 0 to be ; zero and almost 1 to be 1 aRampD delay1 aRamp aGate table  aRampD-aRamp-.5,1,1,.5,0 ;Get some noise aNoise gauss 1 ; Set aA to the old aB value aA samphold aB, aGate ; and get a new aB aB samphold aNoise, aGate ; Now at the first of the interval aRamp is zero so this outputs ; aA and at the end aRamp is 1 so it outputs aB as requested aOut =aA+(aB-aA)*aRamp ; Output aA as well as aOut for comparison outs 30000*aOut,30000*aA endin ;this table is probably bigger than it needs to be f1 0 4097 7 0 2048 0 0 1 2048 1 1 0 ;square i1 0 1 440          e    CR -- Send bugs reports to this list. To unsubscribe, send email to [hidden email]