[Csnd] generating loopable (zero crossing) soundfiles
Date | 2014-05-20 15:47 |
From | Dave Seidel |
Subject | [Csnd] generating loopable (zero crossing) soundfiles |
I've been using an Android app called LAS-9 lately. It's a very useful tool that allows one to load a set of nine WAV files, and then to loops them in any combination using a very simple interface. I use it in live work to play back loops of field recording to accompany live electronic.
I am now also using it to loop single-tone drones created in Csound, both for live playback and as tuning references (i.e., for tuning a set of hardware oscillators to a complex just intonation chord prior to performance). For these purposes, I generally use simple square or triangle waves using vco2.
Creating the individual WAV files is trivial, but one thing I can't quite figure out: is there a technique for generating a file containing a simple oscillator tone that can be seamlessly looped? I have been using a very short linen envelope to avoid clicks, but of course it introduces a discontinuity when looped. I've been dealing with this by editing the loops in Audacity and trimming the files so so that they start and end at a point of zero crossing, but it would save a lot of time and trouble if I could just do this within Csound itself. Can it be done?
- Dave |
Date | 2014-05-20 16:29 |
From | Rory Walsh |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
If you make sure to play N full cycles then you can simply copy and paste without the need to fade in or out? Sounds like it might be easier to use the CsoundAndroid player to do all of this rather than LAS-9? On 20 May 2014 15:47, Dave Seidel |
Date | 2014-05-20 16:38 |
From | luis jure |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
if i understand correctly what you want to do, you could redefine p3 in your instrument to an integer multiple of periods. something like: instr 1 idur = p3 iamp = p4 ifreq = p5 it = 1/ifreq ; period in seconds inumt = round(idur*ifreq) ; number of periods, rounded p3 = it*inumt ; redefine p3 a1 vco2 iamp, ifreq out a1 endin does that help, or did i completely miss the point? |
Date | 2014-05-20 17:02 |
From | Richard Dobson |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
The problem is when (as will typically be the case) the required frequency does not exactly fit into N samples (most easily seen with high frequencies). Not all zero crossings are the same, and there will be some fraction of a period at the end discontinuous with the (zero-sample) start. In effect it is the same problem as that of the truncated rectangular window used for an FFT. Looping on zero-crossings narrows the possible error down, but rarely eliminates it completely. The notion that looping on zero crossings ensures a glitch-free result is a bit of a myth, I fear. Richard Dobson On 20/05/2014 16:38, luis jure wrote: > > > if i understand correctly what you want to do, you could redefine p3 in > your instrument to an integer multiple of periods. something like: > > > instr 1 > > idur = p3 > iamp = p4 > ifreq = p5 > it = 1/ifreq ; period in seconds > inumt = round(idur*ifreq) ; number of periods, rounded > p3 = it*inumt ; redefine p3 > > a1 vco2 iamp, ifreq > out a1 > > endin > > does that help, or did i completely miss the point? > > > Send bugs reports to > https://github.com/csound/csound/issues > Discussions of bugs and features can be posted here > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound" > > > > |
Date | 2014-05-20 18:41 |
From | Forrest Cahoon |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
You need to make the length of the loop commensurate with both the period of the waveform and the sample rate. I think I have the calculations right, using ruby (which has a nice gcd function) here: That is, if your sample rate is 48000 samples per second, and your frequency is 110 Hz, you need a sample length of 0.1 seconds (or some multiple thereof) because this has _exactly_ 11 periods of the waveform in _exactly_ 4800 samples.irb(main):001:0> sr = 48000 => 48000 irb(main):002:0> freq = 110 => 110 irb(main):003:0> 1.0 / sr.gcd(freq) # required sample length in seconds => 0.1 irb(main):001:0> sr = 48000 => 48000 irb(main):002:0> freq = 374 => 374 irb(main):003:0> 1.0 / sr.gcd(freq) => 0.5 If your sample rate is 48000 and your freq is 374, your sample needs to be some multiple of 0.5 seconds, which contains _exactly_ 187 cycles in _exactly_ 24000 samples. I hope I'm not being overly pedantic; I'm actually trying to convince myself I've got this right :-)
On Tue, May 20, 2014 at 9:47 AM, Dave Seidel <dave.seidel@gmail.com> wrote:
|
Date | 2014-05-20 21:54 |
From | mskala@ansuz.sooke.bc.ca |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
On Tue, 20 May 2014, Forrest Cahoon wrote: > You need to make the length of the loop commensurate with both the period of > the waveform and the sample rate. I think I have the calculations right, > using ruby (which has a nice gcd function) here: Is it also necessary to have an integer number of control periods? -- Matthew Skala mskala@ansuz.sooke.bc.ca People before principles. http://ansuz.sooke.bc.ca/ |
Date | 2014-05-20 22:03 |
From | Steven Yi |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
I wonder, would a crossfade be enough to do the job here, overlapping the wave with a copy of itself? I've got some code in the waveseq udo here: http://kunstmusik.com/2012/11/02/waveseq-wave-sequencing-user-defined-opcode-for-csound/ That might be handy for this. Not as nice as having exact periods and zero-crossings, but might be usable for long samples. On Tue, May 20, 2014 at 12:02 PM, Richard Dobson |
Date | 2014-05-20 22:11 |
From | Dave Seidel |
Subject | Re: [Csnd] generating loopable (zero crossing) soundfiles |
Thanks for all the thoughtful responses! I'm not sure which approach will be best, but I'l let you know which one I settle on. - Dave
On Tue, May 20, 2014 at 5:03 PM, Steven Yi <stevenyi@gmail.com> wrote: I wonder, would a crossfade be enough to do the job here, overlapping |