Csound Csound-dev Csound-tekno Search About

[Csnd] Problems with pitch in sndwarpst

Date2023-01-07 00:28
FromScott Daughtrey
Subject[Csnd] Problems with pitch in sndwarpst
I've been tinkering with sndwarpst. I'm finding that with the resample value set at 1 it's not playing samples at the original pitch as one would assume (given the manual suggests 2 would raise the pitch one octave).

I've tried numerous long, pitched samples with the same result. In all cases the pitch appears to be approx. 1 tone higher than the original.

I'm using Csound for Android which uses Csound 6.16.

Here's an example code. I've also posted the csd and example wave file (see links below). Any help or suggestions, or perhaps if anyone has time to confirm the issue by testing this regardless of OS or version, would be appreciated. It may be required to restart the file if the initial sound isn't a solid tone but more of a filtered noise like timbre. 

https://www.dropbox.com/s/9035of0m1fupsym/sndwarpst_harp1.csd?dl=0
 
https://www.dropbox.com/s/ug3rsbcy6ixkww4/HarpC1shrt.wav?dl=0
  


-odac



sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

gSfile = "HarpC1shrt.wav"

; waveform used for granulation
giSound ftgen 1,0,0,1,gSfile,0,0,0

; window function - used as an amplitude envelope for each grain
giWFn   ftgen 2,0,16384,9,0.5,1,0

        seed 0 
gaSendL init 0  ; initialize global audio variables
gaSendR init 0

  instr Trigger ; triggers instrument 2
ktrigger    metro       1/8.5
kRand     = trandom(ktrigger,10,16)
schedkwhen ktrigger,0,0,"Granular",0,kRand ;trigger instr. 2
  endin

  instr Granular ; generates granular synthesis textures
                                    
ifn1      = giSound
ilen      = nsamp(ifn1)/sr
iPtrStart = random(1,ilen-1)
iPtrTrav  = random(-1,1)
ktimewarp = line(iPtrStart,p3,iPtrStart+iPtrTrav)
kamp      = linsegr(0,2,0.1,p3-4,0.1, 4, 0)
iresample = 1
ifn2      = giWFn
ibeg      = 0
iwsize    = random(400,10000)
irandw    = iwsize/3
ioverlap  = 14
itimemode = .2 ; default 1
; create a stereo granular synthesis texture using sndwarp
aSigL,aSigR sndwarpst  kamp*.6,ktimewarp,iresample,ifn1,ibeg,\
                              iwsize,irandw,ioverlap,ifn2,itimemode
gaSendL  += aSigL*0.48
gaSendR  += aSigR*0.6
            outs       aSigL*.8,aSigR
  endin

  instr Reverb
aRvbL,aRvbR reverbsc   gaSendL,gaSendR,0.92,12000
            outs       aRvbL,aRvbR
            clear      gaSendL,gaSendR
  endin

  instr Record ;read the stereo csound output buffer
allL, allR  monitor
; write the output of csound to an audio file
; wav file: 16 bits with header
            fout "/sdcard/sndwarpst18.wav", 16, allL, allR
  endin



;    p1     p2   p3
i"Trigger"   0   30 ; triggers instr 2
i"Reverb"    0   50 ; reverb instrument
; i Record 0  51 ; record instrument


; original example written by Iain McCurdy

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-01-07 00:46
FromIain McCurdy
SubjectRe: [Csnd] Problems with pitch in sndwarpst
Hi Scott,

I think it could be a sample rate mismatch. Your sound file is 44100 Hz but you have sr = 48000 in the csd. It plays the correct pitch for me when corrected.

Regards,
Iain

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: 07 January 2023 00:28
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: [Csnd] Problems with pitch in sndwarpst
 
I've been tinkering with sndwarpst. I'm finding that with the resample value set at 1 it's not playing samples at the original pitch as one would assume (given the manual suggests 2 would raise the pitch one octave).

I've tried numerous long, pitched samples with the same result. In all cases the pitch appears to be approx. 1 tone higher than the original.

I'm using Csound for Android which uses Csound 6.16.

Here's an example code. I've also posted the csd and example wave file (see links below). Any help or suggestions, or perhaps if anyone has time to confirm the issue by testing this regardless of OS or version, would be appreciated. It may be required to restart the file if the initial sound isn't a solid tone but more of a filtered noise like timbre.

https://www.dropbox.com/s/9035of0m1fupsym/sndwarpst_harp1.csd?dl=0
 
https://www.dropbox.com/s/ug3rsbcy6ixkww4/HarpC1shrt.wav?dl=0
 
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

gSfile = "HarpC1shrt.wav"

; waveform used for granulation
giSound ftgen 1,0,0,1,gSfile,0,0,0

; window function - used as an amplitude envelope for each grain
giWFn   ftgen 2,0,16384,9,0.5,1,0

        seed 0
gaSendL init 0  ; initialize global audio variables
gaSendR init 0

  instr Trigger ; triggers instrument 2
ktrigger    metro       1/8.5
kRand     = trandom(ktrigger,10,16)
schedkwhen ktrigger,0,0,"Granular",0,kRand ;trigger instr. 2
  endin

  instr Granular ; generates granular synthesis textures
                                   
ifn1      = giSound
ilen      = nsamp(ifn1)/sr
iPtrStart = random(1,ilen-1)
iPtrTrav  = random(-1,1)
ktimewarp = line(iPtrStart,p3,iPtrStart+iPtrTrav)
kamp      = linsegr(0,2,0.1,p3-4,0.1, 4, 0)
iresample = 1
ifn2      = giWFn
ibeg      = 0
iwsize    = random(400,10000)
irandw    = iwsize/3
ioverlap  = 14
itimemode = .2 ; default 1
; create a stereo granular synthesis texture using sndwarp
aSigL,aSigR sndwarpst  kamp*.6,ktimewarp,iresample,ifn1,ibeg,\
                              iwsize,irandw,ioverlap,ifn2,itimemode
gaSendL  += aSigL*0.48
gaSendR  += aSigR*0.6
            outs       aSigL*.8,aSigR
  endin

  instr Reverb
aRvbL,aRvbR reverbsc   gaSendL,gaSendR,0.92,12000
            outs       aRvbL,aRvbR
            clear      gaSendL,gaSendR
  endin

  instr Record ;read the stereo csound output buffer
allL, allR  monitor
; write the output of csound to an audio file
; wav file: 16 bits with header
            fout "/sdcard/sndwarpst18.wav", 16, allL, allR
  endin

</CsInstruments>
<CsScore>
;    p1     p2   p3
i"Trigger"   0   30 ; triggers instr 2
i"Reverb"    0   50 ; reverb instrument
; i Record 0  51 ; record instrument
</CsScore>
</CsoundSynthesizer>
; original example written by Iain McCurdy

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here