[Csnd] How to write this as a loop?
Date | 2014-04-18 06:23 |
From | Forrest Cahoon |
Subject | [Csnd] How to write this as a loop? |
Hello, all. Forgive me for not distilling this down to a more 'hello, world' version before asking my question, but I'm not quite sure how. I have 8 different buzz-like sounds I'm reading in from wav files, then I put their table numbers in an array:giBuzzV1 ftgen 0, 0, -4800, 1, "buzz110v1loop.wav", 0, 0, 0 giBuzzV2 ftgen 0, 0, -4800, 1, "buzz110v2loop.wav", 0, 0, 0 giBuzzV3 ftgen 0, 0, -4800, 1, "buzz110v3loop.wav", 0, 0, 0 giBuzzV4 ftgen 0, 0, -4800, 1, "buzz110v4loop.wav", 0, 0, 0 giBuzzV5 ftgen 0, 0, -4800, 1, "buzz110v5loop.wav", 0, 0, 0 giBuzzV6 ftgen 0, 0, -4800, 1, "buzz110v6loop.wav", 0, 0, 0 giBuzzV7 ftgen 0, 0, -4800, 1, "buzz110v7loop.wav", 0, 0, 0 giBuzzV8 ftgen 0, 0, -4800, 1, "buzz110v8loop.wav", 0, 0, 0 giBuzz [] array giBuzzV1, giBuzzV2, giBuzzV3, giBuzzV4, giBuzzV5, giBuzzV6, giBuzzV7, giBuzzV8 I have an envelope in a table with one peak and mostly silence. I will use this envelope shifted for each buzz tone, to create a continuous sound (I'd call it "granular" but the changes can be much slower than that typically implies):
giGrainEnv ftgen 0, 0, 8, 7, 0, 1, 1, 1, 0, 6, 0 My instrument to use these looks like this:
instr 1 iBuzzCycle = p6 aPhasor = phasor(p5/11) + poscil(p7, p5) aBuzz = 0
aBuzz = aBuzz + table3:a(aPhasor, giBuzz[0], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 0/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[1], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 1/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[2], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 2/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[3], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 3/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[4], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 4/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[5], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 5/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[6], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 6/8) aBuzz = aBuzz + table3:a(aPhasor, giBuzz[7], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, 7/8) aOut butterlp aBuzz, p5 * p8 kRms rms aOut out aOut * (ampdbfs(p4)/kRms) endin Obviously the "aBuzz = aBuzz + (another buzz sound with a phase-shifted envelope)" lines have a lot of repetition, and it seems like I should be able to use some sort of loop construct here. The problem is that this needs to execute every k-cycle, but the variable I want to iterate over (the the phase shift for poscil) is not k-rate. I've tried:
iIdx = 0 aBuzz = 0 sum_grains: aBuzz = aBuzz + table3:a(aPhasor, giBuzz[iIdx], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, iIdx/8) loop_lt iIdx, 1, 8, sum_grains and I get some weird bloops and blips but not a continuous tone. That (I'm pretty sure) is because it's i-rate and I need k-rate. Changing iIdx to kIdx, though, gives me this error: error: Unable to find opcode entry for 'poscil' with matching argument types: That's because poscil won't accept a k-rate argument for phase shift, even though it's not going to change. This is where I'm stuck. Any help would be most appreciated. Forrest |
Date | 2014-04-18 08:02 |
From | Rory Walsh |
Subject | Re: [Csnd] How to write this as a loop? |
Why not just use an i-rate array for the phase shift and then you can use a k-rate loop: iPhase fillarray 1, 2, 3, 4, 5, 6, 7, 8 kIdx = 0 aBuzz = 0 sum_grains: aBuzz = aBuzz + table3:a(aPhasor, giBuzz[kIdx], 1, 0, 1) * poscil:k(1, 1/iBuzzCycle, giGrainEnv, iPhase[kIdx]/8) loop_lt kIdx, 1, 8, sum_grains On 18 April 2014 07:23, Forrest Cahoon |
Date | 2014-04-19 16:48 |
From | Forrest Cahoon |
Subject | Re: [Csnd] How to write this as a loop? |
That sounds like a great idea, Rory, but it doesn't work. Csound gives a very weird runtime error when you try to use a k-rate index into an i-rate array. I've made a hello-world example to illustrate the issue: <CsoundSynthesizer> <CsInstruments> sr=48000 ksmps=24 nchnls=1 giSine ftgen 0, 0, 2^16, 10, 1 giTables [] fillarray giSine instr 1 kIdx = 0 aOut oscil ampdbfs(p4), p5, giTables[kIdx] out aOut endin </CsInstruments> <CsScore> i1 0 4 -1 200 </CsScore> </CsoundSynthesizer> forrest@makemake:~/csound/buzz$ csound -d -odac hello_kidx.csd virtual_keyboard real time MIDI plugin for Csound 0dBFS level = 32768.0 Csound version 6.02.0 (double samples) Mar 18 2014 libsndfile-1.0.25 UnifiedCSD: hello_kidx.csd STARTING FILE Creating orchestra Creating score rtaudio: ALSA module enabled rtmidi: ALSA Raw MIDI module enabled Elapsed time at end of orchestra compile: real: 0.002s, CPU: 0.002s sorting score ... ... done Elapsed time at end of score sort: real: 0.002s, CPU: 0.002s Csound version 6.02.0 (double samples) Mar 18 2014 displays suppressed 0dBFS level = 32768.0 ftable 101: orch now loaded audio buffered in 256 sample-frame blocks ALSA output: total buffer size: 1024, period size: 256 writing 256 sample blks of 64-bit floats to dac SECTION 1: new alloc for instr 1: INIT ERROR in instr 1: Invalid ftable no. 0.000000 aOut oscil.a #i1 p5 #i2 0 B 0.000 - note deleted. i1 had 1 init errors Score finished in csoundPerform(). inactive allocs returned to freespace end of score. overall amps: 0.0 overall samples out of range: 0 1 errors in performance Elapsed time at end of performance: real: 0.011s, CPU: 0.008s 0 256 sample blks of 64-bit floats written to dac "Invalid ftable no. 0.000000" is the same error I'm getting in my real code when I try following your suggestion. It looks to me like a k-variable is not available at i-time, but the error sure is cryptic. On Fri, Apr 18, 2014 at 2:02 AM, Rory Walsh <rorywalsh@ear.ie> wrote: Why not just use an i-rate array for the phase shift and then you can |
Date | 2014-04-19 16:57 |
From | Rory Walsh |
Subject | Re: [Csnd] How to write this as a loop? |
This runs fine for me. My version of Csound is quite up to date with latest developments which might explain why we get different results. I think there is a new release planned shortly. On 19 April 2014 17:48, Forrest Cahoon |