Csound Csound-dev Csound-tekno Search About

[Csnd] Aliasing when reading stereo-file from table?

Date2019-05-06 10:06
FromJan Jacob Hofmann
Subject[Csnd] Aliasing when reading stereo-file from table?
Dear list,

lately I wanted to transform a stereo-file taken from a CD via a table-reading based opcode like granule or table3. I found out that it comes to an aliasing-like sound artefact when reading both channels into the table and replaying the sound with slower speed. The problem vanishes

- if I store just one of the stereo-channels into the table
- if I do create a soundffile of a sine-wave using instrument 1
- if I do use diskin2 for reading the soundfile directly instead of using a table

Still I do have no explanation for the origin of that unwanted sound under the described circumstances. Maybe someone from the list can explain what is going on? I created a .csd for testing, which I do post below.

Cheers,

Jan Jacob









sr = 44100
ksmps = 10
nchnls = 2
0dbfs = 1.0

; TO USE THIS TESTING INSTRUMENTS JUST PUT AN ARBITRARY SOUNDFILE FROM A CD INTO THE SAME FOLDER OF THE .CSD AND CHANGE THE STRING „stereo-file.aif“ TO THE NAME OF YOUR CHOSEN SOUNDFILE



instr 1	;  SOUNDFILE CREATION - using this soundfile will give no artefacts - you may try this for comparison


; CREATING AN AUDIO SIGNAL (SINE, 440 HZ)

asig	poscil	1, 440	; create audio signal

fout	"sine440.wav", 4, asig, asig	; write the a-signal to a file

endin



instr 2 ; GRANULE

kamp	=	.2	; amplitunde
ivoice	= 4	; number of voices
ispeed	=	1	; speed of scan trough the soundfile
imode	=	1	; direction of movement through the soundfile
ithd	=	0	; threshhold
ifn	=	p4	; function table number of sound source
ipshift	=	4	; number of shifted voices
iskip	=	10	; skiptime [s]
igskip_os	=	0	; random ofset of the scan-pointer
ilength	=	1	; length of the table
kgap	=	0	; gap between grains
igap_os	=	100	; random ofset of gapsize
kgsize	=	.3	; grain duration [s]
igsize_os	=	100	; random ofset of grainsize
iatt	=	1	; attack time [% of grain]
idec	=	1	; decay time [% of grain]
iseed	=	0	; seed
ipch_1	=	p5	; pitch of voice 1
ipch_2	=	p6	; pitch of voice 2
ipch_3	=	p7	; pitch of voice 3
ipch_4	=	p8	; pitch of voice 4
ienvfn	=	1	; function of grain envelope

iftlen	=	ftlen(p4)
print	iftlen
adry granule	kamp, ivoice, ispeed, imode, ithd, ifn, ipshift, iskip, igskip_os, ilength, kgap, igap_os, kgsize , igsize_os, iatt, idec, iseed, ipch_1, ipch_2, ipch_3, ipch_4, ienvfn

outs	adry, adry	; output
endin




instr 3	; SOUNDFILE READER

iamp	init	.6
iwrap	=	1	; wrap soundfile [0=no, 1=yes]
kpitch	=	p4	; get pitch from score
ilength	filelen	"stereo-file.aif"	; querry for soundfile length
print	ilength	; print length of the soundfile
adry1, adry2	diskin2	"stereo-file.aif", kpitch, 10, iwrap	; generate sound
outs	adry1 * iamp, adry2 * iamp	; scale and output sound
endin




instr 4	; TABLE READER


ifn	=	p4	; function number to play
iamp	init	.8	; amplitude
kspeed	=	p5	; speed (pitch of function)


; CALCULATION OF SAMPLE LENGTH


ifnchnl	=	ftchnls(ifn)	; number of chnls if the table?
iftlength	=	ftlen(ifn) / sr * ifnchnl	; calculation of lenth of the used tabele [sec]
print	iftlength

aindx	phasor	1 / iftlength	; create a moving index

aindx	=	aindx * kspeed * ifnchnl + 0.05	; alter speed of scan
adry table3	aindx, ifn, 1	; table reader
adry	=	adry * iamp	; apply amp onto signal

outs	adry, adry	; output sound
endin





f1	0	32769	19	0.5	0.5	270	0.5	/*	envelope: sigmoid	rising	*/
f2	1	0	1	"stereo-file.aif"	10	4	0	/*	reading both channels */
f3	1	0	1	"stereo-file.aif"	10	4	1	/*	reading one channel */

i1	0	1

i2 2	3	2	1	1	1	1	; clean sound
i2 6	3	2	.5	.5	.5	.5	; sound with aliasing
i2 10	3	3	1	1	1	1	; clean sound
i2 14	3	3	.5	.5	.5	.5	; clean sound

i3	18	3	1	; clean sound
i3	22	3	.5	; clean sound

i4	26	3	2	1	; clean sound
i4	30	3	2	.5	; sound with aliasing


i4	34	3	3	1	; clean sound
i4	38	3	3	.5	; clean sound

e








sound         |         movement         |         object         |        space
sonic architecture       |        site: http://www.sonicarchitecture.de
spatial electronic composition   |    higher order ambisonic music

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

Date2019-05-06 13:55
FromJohn ff
SubjectRe: [Csnd] Aliasing when reading stereo-file from table?
In your use of table3 I see no evidence of the stereo affect.  Table3 uses cubic interpretation so will read neighbouring samples not frames.  Could that be an explanation?  Not at a real computer yet to test.

==John ff

⁣Sent from TypeApp ​

On May 6, 2019, 10:08, at 10:08, Jan Jacob Hofmann  wrote:
>Dear list,
>
>lately I wanted to transform a stereo-file taken from a CD via a
>table-reading based opcode like granule or table3. I found out that it
>comes to an aliasing-like sound artefact when reading both channels
>into the table and replaying the sound with slower speed. The problem
>vanishes
>
>- if I store just one of the stereo-channels into the table
>- if I do create a soundffile of a sine-wave using instrument 1
>- if I do use diskin2 for reading the soundfile directly instead of
>using a table
>
>Still I do have no explanation for the origin of that unwanted sound
>under the described circumstances. Maybe someone from the list can
>explain what is going on? I created a .csd for testing, which I do post
>below.
>
>Cheers,
>
>Jan Jacob
>
>
>
>
>
>
>
>
>
>sr = 44100
>ksmps = 10
>nchnls = 2
>0dbfs = 1.0
>
>; TO USE THIS TESTING INSTRUMENTS JUST PUT AN ARBITRARY SOUNDFILE FROM
>A CD INTO THE SAME FOLDER OF THE .CSD AND CHANGE THE STRING
>„stereo-file.aif“ TO THE NAME OF YOUR CHOSEN SOUNDFILE
>
>
>
>instr 1	;  SOUNDFILE CREATION - using this soundfile will give no
>artefacts - you may try this for comparison
>
>
>; CREATING AN AUDIO SIGNAL (SINE, 440 HZ)
>
>asig	poscil	1, 440	; create audio signal
>
>fout	"sine440.wav", 4, asig, asig	; write the a-signal to a file
>
>endin
>
>
>
>instr 2 ; GRANULE
>
>kamp	=	.2	; amplitunde
>ivoice	= 4	; number of voices
>ispeed	=	1	; speed of scan trough the soundfile
>imode	=	1	; direction of movement through the soundfile
>ithd	=	0	; threshhold
>ifn	=	p4	; function table number of sound source
>ipshift	=	4	; number of shifted voices
>iskip	=	10	; skiptime [s]
>igskip_os	=	0	; random ofset of the scan-pointer
>ilength	=	1	; length of the table
>kgap	=	0	; gap between grains
>igap_os	=	100	; random ofset of gapsize
>kgsize	=	.3	; grain duration [s]
>igsize_os	=	100	; random ofset of grainsize
>iatt	=	1	; attack time [% of grain]
>idec	=	1	; decay time [% of grain]
>iseed	=	0	; seed
>ipch_1	=	p5	; pitch of voice 1
>ipch_2	=	p6	; pitch of voice 2
>ipch_3	=	p7	; pitch of voice 3
>ipch_4	=	p8	; pitch of voice 4
>ienvfn	=	1	; function of grain envelope
>
>iftlen	=	ftlen(p4)
>print	iftlen
>adry granule	kamp, ivoice, ispeed, imode, ithd, ifn, ipshift, iskip,
>igskip_os, ilength, kgap, igap_os, kgsize , igsize_os, iatt, idec,
>iseed, ipch_1, ipch_2, ipch_3, ipch_4, ienvfn
>
>outs	adry, adry	; output
>endin
>
>
>
>
>instr 3	; SOUNDFILE READER
>
>iamp	init	.6
>iwrap	=	1	; wrap soundfile [0=no, 1=yes]
>kpitch	=	p4	; get pitch from score
>ilength	filelen	"stereo-file.aif"	; querry for soundfile length
>print	ilength	; print length of the soundfile
>adry1, adry2	diskin2	"stereo-file.aif", kpitch, 10, iwrap	; generate
>sound
>outs	adry1 * iamp, adry2 * iamp	; scale and output sound
>endin
>
>
>
>
>instr 4	; TABLE READER
>
>
>ifn	=	p4	; function number to play
>iamp	init	.8	; amplitude
>kspeed	=	p5	; speed (pitch of function)
>
>
>; CALCULATION OF SAMPLE LENGTH
>
>
>ifnchnl	=	ftchnls(ifn)	; number of chnls if the table?
>iftlength	=	ftlen(ifn) / sr * ifnchnl	; calculation of lenth of the
>used tabele [sec]
>print	iftlength
>
>aindx	phasor	1 / iftlength	; create a moving index
>
>aindx	=	aindx * kspeed * ifnchnl + 0.05	; alter speed of scan
>adry table3	aindx, ifn, 1	; table reader
>adry	=	adry * iamp	; apply amp onto signal
>
>outs	adry, adry	; output sound
>endin
>
>
>
>
>
>f1	0	32769	19	0.5	0.5	270	0.5	/*	envelope: sigmoid	rising	*/
>f2	1	0	1	"stereo-file.aif"	10	4	0	/*	reading both channels */
>f3	1	0	1	"stereo-file.aif"	10	4	1	/*	reading one channel */
>
>i1	0	1
>
>i2 2	3	2	1	1	1	1	; clean sound
>i2 6	3	2	.5	.5	.5	.5	; sound with aliasing
>i2 10	3	3	1	1	1	1	; clean sound
>i2 14	3	3	.5	.5	.5	.5	; clean sound
>
>i3	18	3	1	; clean sound
>i3	22	3	.5	; clean sound
>
>i4	26	3	2	1	; clean sound
>i4	30	3	2	.5	; sound with aliasing
>
>
>i4	34	3	3	1	; clean sound
>i4	38	3	3	.5	; clean sound
>
>e
>
>
>
>
>
>
>
>
>sound         |         movement         |         object         |    
>   space
>sonic architecture       |        site: http://www.sonicarchitecture.de
>spatial electronic composition   |    higher order ambisonic music
>
>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

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