Csound Csound-dev Csound-tekno Search About

[Csnd] freeze.csd

Date2014-08-23 13:56
FromMatti Koskinen
Subject[Csnd] freeze.csd
hi all,

I sort of succeeded of making a video, recording the sound and freezing it. I mean sort of, because the drift is horrible. The usleep doesn’t seem to be very accurate first, then the delay in csound. I took 120 frames, each lasting 5 secs, which should mean, that the whole recording and video should last 10mins 5secs. For some drift or latency, the total time is 11mins and 35 secs. Of course it’s possible, that in my c++ code are bugs.

but here is the csd. The UDO tanh compression looks like working very well, maybe someone could use it.



-iadc -odac -B4096 -b400

;
; realtime read and pvsfreeze using OSC
; csd formatted with stef's elisp
; if-sections formatted bit strangly?
; Matt Koskinen 2014
;

  sr        =  44100
  ksmps     =  100
  nchnls    =  2
  0dbfs     =  1

    opcode tanhcompr,a,ak ; compress using tanh as in audacity nyquist-plugin
  ain,ktanh xin       
  aout      init      0
  ksign     =  1
  kain      downsamp  ain
if(abs(kain) > 0.95) then                         ; check levels and adjust
if(kain > 0) then
  ksign     =  1 ; there may be sign opcode?
            else      
  ksign     =  -1
endif
  ain       =  0.95*ain*ksign
endif
if(ktanh < 0.05) then ; not to blow output
  ktanh     =  0.05
endif
  aret      =  tanh(ktanh*ain)/tanh(ktanh)
  kret      downsamp  aret
if(abs(kret) > 0.95) then
if(kret > 0) then
  ksign     =  1
            else      
  ksign     =  -1
endif
  aret      =  0.95*aret*ksign
endif
            xout      aret
    endop 

  gihandle  OSCinit   7770 ; use whatever
  ga1       init      0
  gfsig     pvsinit   1024

            turnon    1 ; turn on osc-reader
            turnon    3 ; turn on input to fsig instr

    instr 1
  kflen     init      0 ; sound freeze length
  kid       init      0 ; dummy
  kex       init      0 ; exit
  ksnd      init      0 ; freeze
  kwrite    init      0 ; start output to file
      
nxtmsg:
  kk        OSClisten   gihandle,"/wh","ifiii",kid,kflen,kex,ksnd,kwrite
if(kk==0) goto ex
            printk    0,ksnd
            schedkwhen  ksnd,0,1,2,0,kflen
            schedkwhen  kex,0,1,99,0,1
            schedkwhen  kwrite,0,1,98,0,-1
            kgoto     nxtmsg
ex:
    endin



    instr 2
      
      ;fim   pvsanal   asig, 1024, 256, 1024, 1      ; pvoc analysis 
      ;fblur pvsblur gfsig,0.5,1
  ktr       linseg    0,0.01,1,p3-0.02,1,0.01,1 ; to de-click and trigger pvsfreeze
  ktrig     =  0
if(ktr > 0) then
  ktrig     =  1
            else      
  ktrig     =  0
endif
  ff        pvsfreeze   gfsig, ktrig, ktrig       ; regular 'freeze' of spectra 
  aout      pvsynth   ff                          ; pvoc synthesis
  ac        tanhcompr   aout,0.2 ; compress also output
            outs      ac*ktr,ac*ktr
    endin

    instr 98
  a1,a2     monitor   
            fout      "file.wav",14,a1,a2 ; write to file
    endin

    instr 3
  asig      inch      1 ; read input
  acompr    tanhcompr   asig,0.5 ; compress
  gfsig     pvsanal   acompr,1024,256,1024,1 ; analyse
    endin

    instr 99
      
            exitnow   ; stop csound
    endin


f0 3600 ; run for one hour
f1 0 8192 10 1 1 1 ; dummy table

e



best,

-m