Csound Csound-dev Csound-tekno Search About

Appling glissando to looped sample

Date2005-10-17 14:30
From"Barry Griffin (sent by Nabble.com)"
SubjectAppling glissando to looped sample
Hi all,

I was wondering if there is a function in csound which allows one to apply a glissando to a sound sample. The sound sample I wish to use is as follows -

http://baz.perlmonk.org/noise1.mp3

Its generated using a distorted guitar. What I'm hoping to do is define my instrument as starting at one pitch and ending on another, with a linear slide between the starting and finish pitch, with respect to this noise signal. Can this be done in csound? I've only ever used the line function for slides in the past. I'd image some kind of resampling process would be involved where more and more samples are discarded as the end of the note is reached.

Would it be very difficult to synthise this sound using csound? I'm a relative new comer to csound, but I have synthesised instruments in csound previously. To do this, I took a spertrogram of one of its notes and examined each harmonic to see how its amplitude varied over time. I also examined how the frequency of each harmonic varied in time. I then used to linseg and oscili to recreate this note. I also had to synthesis multiple notes for different note ranges. I've never tries to synthesis an ambient noise signal before and I'm wondering if it is possible to get a usable representation.

Here's an example of a glissando I applied to my noise source example using an audio editor -

http://baz.perlmonk.org/noise2.mp3

Thanks very much for your help,

Barry.

Sent from the Csound - General forum at Nabble.com.

Date2005-10-17 19:19
FromDavid Akbari
SubjectRe: Appling glissando to looped sample
Hi Barry,

On Oct 17, 2005, at 9:30 AM, Barry Griffin (sent by Nabble.com) wrote:

> I was wondering if there is a function in csound which allows one to 
> apply a glissando to a sound sample.

Of course there are many unit generators which allow a user to do this 
in Csound, but the beauty and elegance of the program is in the fact 
that none of these modules are pre-connected to any other modules, as 
they should not be.


>  The sound sample I wish to use is as follows -
>
> http://baz.perlmonk.org/noise1.mp3
>
> Its generated using a distorted guitar.

One thing to mention right away is that I do not believe libsndfile or 
the Csound4.xx API support the implicit reading of MP3 encoded audio. 
It's likely you will want to convert to a linear PCM type file before 
attempting any Csound. For the purposes of the following example, I 
have converted this MP3 to .aiff.

> Here's an example of a glissando I applied to my noise source example 
> using an audio editor -
>
> http://baz.perlmonk.org/noise2.mp3

I noticed that just by listening, it appears the second file goes from 
about +1 semitone from the noise1.mp3 pitch to -1 semitone from it's 
original pitch.

> What I'm hoping to do is define my instrument as starting at one pitch 
> and ending on another, with a linear slide between the starting and 
> finish pitch, with respect to this noise signal.

OK. What follows is a Csound file that implements three ways to do what 
you have proposed.

The first method is simply using diskin's kpitch argument as defined in 
the manual. An additional formula is used:

2 ^ (n / 12)

where n is deviation in half steps from original pitch. I prefer to 
think this way from a musical standpoint sometimes.

The second method uses a phase vocoder analysis algorithm and pvscale 
is doing the change in pitch. A slight difference in timbre can be 
noticed.

The third method is using freqShift which is a UDO and can be found at 
http://www.csounds.com/udo

It is worth noting that these examples were written and tested with a 
csoundlib corresponding to Csound version 4 (MacCsound) as that is 
officially the current canonical release.

As one Csound Developer suggests, if you were using Csound5 for this, 
then in instruments 2 & 3 you may want to replace diskin with soundins.





sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2

/*------*/

		opcode freqShift, a, ak

         ain, kfreq      xin

         ; Phase quadrature output derived from input signal.
         areal, aimag hilbert ain

         ; Sine table for quadrature oscillator.
         iSineTable ftgen        0, 0, 16384, 10, 1

         ; Quadrature oscillator.
         asin oscili 1, kfreq, iSineTable
         acos oscili 1, kfreq, iSineTable, .25

         ; Use a trigonometric identity.
         ; See the references for further details.
         amod1 = areal * acos
         amod2 = aimag * asin

         ; Both sum and difference frequencies can be
         ; output at once.
         ; aupshift corresponds to the sum frequencies.
         aupshift = (amod1 + amod2) * 0.7
         ; adownshift corresponds to the difference frequencies.
         adownshift = (amod1 - amod2) * 0.7

         ; Notice that the adding of the two together is
         ; identical to the output of ring modulation.

	xout aupshift
		endop

/*--- ---*/

		instr	1	;  diskin to change pitch

kshift	line	3, p3, -3	;  plus or minus a minor third over duration

kpitch	=	(2 ^ (kshift / 12))

al, ar	diskin	"noise1.aif", kpitch, 0, 1

	outs	al, ar

		endin

/*--- ---*/

		instr	2	;  pvsanal, analysis data changing pitch

kpitch	line	-3, p3, 3	;  minus to plus a semitone over duration
					;  goes the other way

kshift	=	(2 ^ (kpitch / 12))

al, ar	diskin	"noise1.aif", 1, 0, 1

fl	pvsanal	al, 1024, 256, 1024, 1
fr	pvsanal	ar, 1024, 256, 1024, 1

fscl	pvscale	fl, kshift
fscr	pvscale	fr, kshift

a0l	pvsynth	fscl
a0r	pvsynth	fscr

	outs	a0l, a0r

		endin

/*--- ---*/

		instr	3	;  freqShift UDO

kpitch	line	-420, p3, 420	;  minus 420 Hz to +420 Hz of original pitch
						;  over note duration

al, ar	diskin	"noise1.aif", 1, 0, 1

a0l	freqShift	al, kpitch
a0r	freqShift	ar, kpitch

	outs	a0l, a0r

		endin

/*--- ---*/


i1	0	3.89
s

i2	0	3.89
s

i3	0	3.89


e





Hope this helps!


-David

Date2005-10-18 00:47
FromPrent Rodgers
SubjectRe: Appling glissando to looped sample
Barry,
David's very complete answer is probably all you need, but I wanted to 
add another idea. I do this all the time in my use of Csound to create a 
sampling orchestra. I use loscil, and read the sample in using GEN01. 
David is correct that MP3 is not supported. I prefer AIF, since you can 
put loop points into an AIF format file. The following is a fragment to 
get you going.

f14 0 0 1 "McGill/Partition B/FLUTTERFLUTE/FLUTTERC4.aif" 0 4 0

; This reads into function table 14 the sample file, and automatically
; calculates the size.

;Then you need a function table that moves up:

f383 0 256 -7 1 64 1 128 1.0714286 64 1.0714286 ; 15 : 14 82

;This defines sloping up by 15:14 ratio.
; get a pitch in frequency
kcps = cpspch(ioct+ipitch) ; convert oct.fract to Hz
; apply that table to the input to loscil:
kcpsm oscili 1, 1/p3, 383 ; create an set of shift multiplicands from
;                 table number 383 - glissandi

; Shift the frequency
  kcps2 = kcps * kcpsm ; shift the frequency by values in glissando table
; call loscil with the appropriate frequencies
ifno = 14
ibascps = 400
a3,a4 loscil 1, kcps2, ifno, ibascps; stereo sample with looping
a1 = a3 * kamp_l ; shift left or right during the note - give it an
;  envelope
a2 = a4 * kamp_r
  outs a1 * kpan_l ,a2 * kpan_r

I also use some more complex frequency tables, including vibrato. Here's 
one that starts at 1:1 and drops down and shakes a small amount, like a 
guitar player might do. It uses GEN06, which generates a function 
comprsed of segments of cubic polynomials, spanning specified points 
just three at a time. Imagine bending a note up, then plucking the 
string, and bending it back down and applying some vibrato. I use this a 
lot in my "Resolution in Blue" for microtonal slide piano.

f314 0 129 -6 1 4 1 4 1 16 1.0000 16 1.0000 4 0.9900 4 0.9800 4 0.9900 4 
1.0000 4 0.9900 4 0.9800 4 0.9900 4 1.0000 4 0.9900 4 0.9800 4 0.9900 4 
1.0000 4 0.9900 4 0.9800 4 0.9900 4 1.0000 4 0.9900 4 0.9800 4
  0.9900 4 1.0000 4 0.9900 4 0.9800 ;

Barry Griffin (sent by Nabble.com) wrote:
> Hi all,
> 
> I was wondering if there is a function in csound which allows one to 
> apply a glissando to a sound sample. The sound sample I wish to use is 
> as follows -
> 
> http://baz.perlmonk.org/noise1.mp3
> 
> Its generated using a distorted guitar. What I'm hoping to do is define 
> my instrument as starting at one pitch and ending on another, with a 
> linear slide between the starting and finish pitch, with respect to this 
> noise signal. Can this be done in csound? I've only ever used the line 
> function for slides in the past. I'd image some kind of resampling 
> process would be involved where more and more samples are discarded as 
> the end of the note is reached.
> 
> Would it be very difficult to synthise this sound using csound? I'm a 
> relative new comer to csound, but I have synthesised instruments in 
> csound previously. To do this, I took a spertrogram of one of its notes 
> and examined each harmonic to see how its amplitude varied over time. I 
> also examined how the frequency of each harmonic varied in time. I then 
> used to linseg and oscili to recreate this note. I also had to synthesis 
> multiple notes for different note ranges. I've never tries to synthesis 
> an ambient noise signal before and I'm wondering if it is possible to 
> get a usable representation.
> 
> Here's an example of a glissando I applied to my noise source example 
> using an audio editor -
> 
> http://baz.perlmonk.org/noise2.mp3
> 
> Thanks very much for your help,
> 
> Barry.
> ------------------------------------------------------------------------
> Sent from the Csound - General 
>  
> forum at Nabble.com.

-- 
Music that's "Fake but Accurate"!
Web page: http://prodgers13.home.comcast.net
Podcast: http://podcast1024.libsyn.com
Another Podcast: http://BumperMusic.blogspot.com
Music: http://www.soundclick.com/PrentRodgers

Date2005-10-18 13:13
From"Barry Griffin (sent by Nabble.com)"
SubjectRe: Appling glissando to looped sample
Great replies guys, thanks very much for your help.

Sent from the Csound - General forum at Nabble.com.