spell-music / csound-expression

Haskell Framework for Electronic Music
320 stars 31 forks source link

Division by zero #58

Closed asheshambasta closed 4 years ago

asheshambasta commented 4 years ago

Deps:

- csound-expression-5.3.2@sha256:ae99c0581e179ebdf94dda796635f058865a3d9c286636981ce38f16a814879b,4430
- csound-expression-dynamic-0.3.3@sha256:03f99c095a1876fd1166ebf0f7e00834110d47765922774d625268c354c11c42,1375
- csound-catalog-0.7.3@sha256:f151ff49ae4f009174db60dd4114be25967d693edecea1462a17c399a8032e40,1731
- csound-sampler-0.0.9.0@sha256:068c18b12d449c8acbf488c79b53cfa8a7cfc6c6275b8231d76ec10e49c3a4a7,1294
- sharc-timbre-0.2@sha256:b6bc95680069e6962d683d1cc214045c5eea6277e7383cb99656c85bdcef822f,2725
- csound-expression-opcodes-0.0.4.0@sha256:9920f962790b8e58884914474a2c10719d685eaf6a5b14873001308b053901a6,1584
- csound-expression-typed-0.2.2.0@sha256:ae5e024b832d0f43694582734c557158d31942a8d33833e9251b4458df07422b,4113
- temporal-media-0.6.3@sha256:7a27d711a786c3dc9163433627e51efcc4b3fce3a947b71c29f3e388f37cae59,857
- data-fix-cse-0.0.2@sha256:18fcb64d0fe1866bf1032f3ca9c7b20d3702aa35f5a383f33c84de849bb18a88,972
- wl-pprint-1.2.1@sha256:aea676cff4a062d7d912149d270e33f5bb0c01b68a9db46ff13b438141ff4b7c,734

Relevant code:


kick = osc (100 * linloop [1, 0.1 * takt 1, 0, 0.9 * takt 1, 0])
snare =
  at (hp 500 23) . mul (sqrSeq [0, 0, 1, 0, 0, 0, 0.5, 0.2] (syn 4)) $ pink

ampBpmKnobs maxBpm
  = let
      bpmKnob = uknob 1
      ampKnob = uknob 0.5
      instr   = hlift2
        $ \amp bpm -> setBpm (maxBpm * bpm) >> mul amp (return kick + snare)
    in
      dac (instr ampKnob bpmKnob)

Repro:

Turn the BPM knob all the way to 0;


Output:

λ> ampBpmKnobs 180
0dBFS level = 32768.0
--Csound version 6.13 (double samples) Jan  1 1970
[commit: none]
libsndfile-1.0.28
UnifiedCSD:  tmp.csd
STARTING FILE
Creating options
Creating orchestra
closing tag
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
displays suppressed
0dBFS level = 1.0
orch now loaded
audio buffered in 256 sample-frame blocks
ALSA input: total buffer size: 1024, period size: 256
reading 512-byte blks of shorts from adc (RAW)
ALSA output: total buffer size: 1024, period size: 256
writing 256 sample blks of 64-bit floats to dac
SECTION 1:
ftable 2:
new alloc for instr 18:
WARNING: loop opcode: wrong argument count
new alloc for instr 20:
new alloc for instr 21:
WARNING: Division by zero
WARNING: Division by zero
WARNING: Division by zero
... (continues for many lines)

The kick stops playing; but the snare keeps playing when I bring the BPM back to non-zero.


This seems to be an issue where we're rendering something in csound that causes a div. by zero error; but at this stage I'm not sure what that is.

anton-k commented 4 years ago

Sorry, for late reply, I'm ill right now. I'll try to investigate when I recover.

anton-k commented 4 years ago

This is not a bug. It's fine behaviour! BPM is a part of functions takt and syn. There is global parameter BPM that is read by those functions and it is updated with setBpm. And some of them uses BPM in denominator. You can use +1 or even more to your bpm value to make it stable prior to the setBpm function.

anton-k commented 4 years ago

If kick stops playing that means that takt uses BPM in denominator and the process that runs this instrument was killed with exception.

anton-k commented 4 years ago

So we can write it like this:

 \amp bpm -> setBpm (1 + (maxBpm - 1) * bpm) >> mul amp (return kick + snare)

or like this:

 \amp bpm -> setBpm (maxB 1 $ maxBpm * bpm) >> mul amp (return kick + snare)