electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Popping sounds from oscillator volume change
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [15 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Tue Feb 25, 2014 11:29 am    Post subject: Popping sounds from oscillator volume change Reply with quote  Mark this post and the followings unread

Hey ya'll. Been using ChucK for a few months, making simple programs which manipulate oscillators. One problem I've come across is when I change the volume of an oscillator, I get a popping sound. Using envelopes can help, but the faster I change the volume, the more difficult it becomes to eradicate the popping. In fact it's always kind of there in the background. What's more, I made my own envelopes to troubleshoot the problem, to get a better sense of what's happening, and I found that, somehow, changing the volume of an oscillator was affecting the frequency!
Basically what I'm doing is switching an oscillator's volume between 0.0 and 1.0, with the frequency staying the same. I feel like there's something here I am not grasping. I've tried changing speakers and different computers, no change. Just so you know, I'm a noob to electronic music. Thanks!
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Thu Feb 27, 2014 12:06 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi and welcome

Would it be possible to post a code example that shows the problem here? I don't think it should behave the way you describe it, especially if you use envelopes.

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Sun Mar 02, 2014 10:10 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for responding!
Here is some code to show the basic problem:
Code:


SinOsc oscillator => dac;
0.0 => oscillator.gain;
300.0 => oscillator.freq;

1.0 => float volume_1;
0.0 => float volume_2;

0.05 => float timing_variable;

// This loop will simply cause the oscillator to fluctuate between the two volume values stored in the 'volume_1' and 'volume_2' variables.
// You can hear a somewhat subtle popping sound as the oscillator changes between volume values. This becomes especially apparent, however, if you make the
// 'timing_variable' smaller. Change it to 0.05 and it the popping sound becomes especially apparent.
for(0 => int i; i < 20 ; i++)
{
    volume_1 => oscillator.gain;
    timing_variable::second => now;
   
    volume_2 => oscillator.gain;
    timing_variable::second => now;   
}



Do you hear the popping sound? If so, do you know why this popping sound happens? My sound designer girlfriend didn't have any experience with this problem, and I'm at a loss.
Obviously it has something to do with changing between volumes very quickly, but...is it just a Chuck thing, or is it a general audio thing? I would like to solve this problem, but I would just as much like to understand it.

Anyway, here is me using envelopes to fix the problem. However, the problem comes back if the envelope is transitioning between volumes very quickly.
Code:

SinOsc oscillator => Envelope envelope => dac;

// Set up the oscillator.
1.0 => oscillator.gain;
300.0 => oscillator.freq;

// Determine two volumes for the oscillator to fluctuate between.
1.0 => float volume_1;
0.0 => float volume_2;

// Set up the envelope. If the duration is greater than 0.001, the popping sound is not particularly apparent, but it is definitely apparent at this value or lower.
0.001::second => envelope.duration;

// Create a variable for managing the speed of fluctuation between the two volumes.
0.1 => float timing_variable;

for(0 => int i; i < 200; i++)
{
   
    volume_1 => envelope.target;
    timing_variable::second => now;
   
    volume_2 => envelope.target;
    timing_variable::second => now;
   
}
Back to top
View user's profile Send private message
varice



Joined: Dec 29, 2004
Posts: 961
Location: Northeastern shore of Toledo Bend
Audio files: 29
G2 patch files: 54

PostPosted: Mon Mar 03, 2014 4:51 am    Post subject: Reply with quote  Mark this post and the followings unread

heliocentric wrote:
...Obviously it has something to do with changing between volumes very quickly, but...is it just a Chuck thing, or is it a general audio thing?...

I’m not a ChucKer, but I have experienced this popping and clicking noise with synthesizers when using the fastest envelope generator settings to modulate the VCA, similar to what you are doing with instant volume changes in your ChucK code. This noise is especially noticeable with low frequency (bass) patches that use sine and triangle waveforms. But this noise is a natural acoustic phenomenon, and is not caused by some fault with the synth (or ChucK code). Fast changes in the volume of a waveform will create a transient if the waveform is not near the zero crossing point, and this fast transient will generate some high frequency overtones which are perceived as a pop or click. But, as you have noticed, slowing the rate of change in volume reduces this noise, so that is ultimately the correct solution. Even slewing the EG rate of attack/decay/release to several milliseconds for bass patches should still sound fast enough while greatly reducing the unwanted popping/clicking noise.

_________________
varice
Back to top
View user's profile Send private message
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Mon Mar 03, 2014 9:41 am    Post subject: Reply with quote  Mark this post and the followings unread

Wow thanks Varice! Very informative, exactly the kind of info I am looking for. Whenever I searched the net I could only find info about clipping, as I guess this is a much more common noise problem. I've never heard of a transient before, but yes, it looks like that's what's happening here. It's nice to know that this is a general acoustic phenomenon, and not just something to do with ChucK. Again thanks, this has been bothering for a few weeks, really driving me nuts.

Well, I still have the problem of how to fix this. It's nice that using an envelope reduces the problem, but I still get the popping when the envelopes duration is set to 0.001 seconds or less. Granted, this is pretty fast, but in my mind I think "computers can solve any technical problem." I want to go as fast as possible!

@ Antimon: do you think there is anything I can do to make my volume transitions even faster while still avoiding the popping? Oh and thanks for the warm welcome! First forum I have ever signed up to!
Back to top
View user's profile Send private message
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Mon Mar 03, 2014 10:11 am    Post subject: Reply with quote  Mark this post and the followings unread

One thing I would like to understand better is the 'rate' method for the Envelope unit generator. I tried chucking different values to this method, and I can't tell what it does. I took the class on ChucK on Coursera, and I've looked through the ChucK manual and online, but all I can glean from this is that the method takes a float. Perhaps this this method is the key to my problem?
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24083
Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320

PostPosted: Mon Mar 03, 2014 10:13 am    Post subject: Reply with quote  Mark this post and the followings unread

This is not something a computer can fix .. a fast volume change just /is/ a plop or click ... in fact no device can fix it ... and it is not a problem either ... its just how nature works ...
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Mon Mar 03, 2014 10:28 am    Post subject: Reply with quote  Mark this post and the followings unread

Yeah what Jan said.

In fact, when I look at and listen to your first piece of code, what you're doing is changing the gain of an oscillator between complete silence and full volume with a rate of 20 Hz (once every 0.05 seconds), producing a fluttering sound. It sounds a bit like a helicopter, which is about what I'd expect. Modulating something wildly on/off like this can't be expected to produce any kind of "smooth" sound as I see it.

Might I ask what you're trying to do: what kind of sound are you trying to accomplish?

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Mon Mar 03, 2014 10:51 am    Post subject: Reply with quote  Mark this post and the followings unread

heliocentric wrote:
One thing I would like to understand better is the 'rate' method for the Envelope unit generator. I tried chucking different values to this method, and I can't tell what it does. I took the class on ChucK on Coursera, and I've looked through the ChucK manual and online, but all I can glean from this is that the method takes a float. Perhaps this this method is the key to my problem?


Yeah ChucK's documentation isn't extremely thorough in places...

The rate field in Envelope is read/write, so one thing you can try is to chuck some values into duration and then read the rate and try to figure it out. Here's one try I did, see if you can figure out the pattern. :)

Code:
Step v => Envelope e => SinOsc s => dac;

440 => s.freq;
1 => v.next;


while (true) {
        0 => e.target;
        1::ms => e.duration;
        1::ms => now;
        1000 => e.target;
        1::second => e.duration;
        1::second => now;

        <<< "Rate: ", e.rate(), (e.rate() * 44100) >>>;
}


Note that you often need to connect UGens to dac before you can do stuff like this - a UGen doesn't set itself up completely until it's used to actually produce sound.

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
fretless



Joined: Nov 29, 2009
Posts: 19
Location: Boston

PostPosted: Tue Mar 04, 2014 6:47 pm    Post subject: Reply with quote  Mark this post and the followings unread

I suppose the 1 sample loop is a bit of a problem.


class ZCrossGain extends Chubgraph {
inlet => Gain g => outlet;

static float oldGain;
0.0 => oldGain;
0.0 => g.gain;

fun void setZCrossGain(float newGain) {
float theRange, theDiv;
0.001 => theRange;
theRange * -1.0 => float minusRange;

if (newGain != oldGain) {
(newGain - oldGain)/16.0 => theDiv;
for (0 => int i; i < 16; i++){
while ((outlet.last() < minusRange ) || (outlet.last() > theRange) ) 1::samp => now;
g.gain() + theDiv => g.gain; 1::samp => now;
}
g.gain() => oldGain;
<<<newGain, g.gain()>>>;
}
}
}

SinOsc oscillator => ZCrossGain eee => dac;
1.0 => oscillator.gain;
300.0 => oscillator.freq;

0.05 => float timing_variable;

while(true)
{
Math.random2f(0.1, 0.9) => eee.setZCrossGain;
timing_variable::second => now;
}


ChangeGain.ck
 Description:

Download
 Filename:  ChangeGain.ck
 Filesize:  960 Bytes
 Downloaded:  535 Time(s)

Back to top
View user's profile Send private message
fretless



Joined: Nov 29, 2009
Posts: 19
Location: Boston

PostPosted: Tue Mar 04, 2014 7:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

It looks like SqrOsc and SawOsc get stuck in the 1 sample loop, so this seems only useful for SinOsc and TriOsc. I think the STK instruments that take an intensity parameter for noteOn and similar don't have the clicking problem.
Back to top
View user's profile Send private message
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Tue Mar 04, 2014 9:47 pm    Post subject: Reply with quote  Mark this post and the followings unread

@ Antimon + fretless: Wow! I'm really in over my head now! Shocked

Thanks for your replies! I'm going to examine both sets of code you have given me and attempt to understand them better, but I'm afraid I'm far too ignorant at this point to really grasp what's going on with them.

I took the coursera course on ChucK last october - december, and basically I didn't know almost anything about programming or electronic music prior to this, so I obviously have a lot to learn. Thank you both for taking the time to consider this problem though, I'm really appreciative!

@ Antimon: the reason this problem came up in the first place was because I read that every sound can be understood as a collection of sine waves. So I thought to myself: "Oh, so if I just make programs that manipulate the frequency, amplitude and temporal patterns of sine waves, I should, theoretically, be able to make any sound." This has been my big programming project since the beginning of the year, my first real programming project. Obviously being able to make any sound at all is way too ambitious, but I was just curious to see where the project would take me. I was very surprised when I came across this popping/clicking thing. In my mind I was like: "Hmm, shouldn't I just hear the frequency of the sine wave at different amplitudes, or just becoming silent?" What I wanted was simply to hear a single pure tone changing in amplitude, and then make programs where I could have a number of oscillators all changing the amplitudes of sine waves. Anyway, this probably sounds all a bit naive, but that's what brought me to this problem. I love the idea of just building sounds from the ground up, one sine wave at a time, and thus having a deep understanding of how the sound is structured, especially since I have programmed how the sound plays using just oscillators. Heh.
Back to top
View user's profile Send private message
varice



Joined: Dec 29, 2004
Posts: 961
Location: Northeastern shore of Toledo Bend
Audio files: 29
G2 patch files: 54

PostPosted: Tue Mar 04, 2014 11:27 pm    Post subject: Reply with quote  Mark this post and the followings unread

varice wrote:
heliocentric wrote:
...Obviously it has something to do with changing between volumes very quickly...

...But, as you have noticed, slowing the rate of change in volume reduces this noise, so that is ultimately the correct solution. Even slewing the EG rate of attack/decay/release to several milliseconds for bass patches should still sound fast enough while greatly reducing the unwanted popping/clicking noise.

heliocentric wrote:
...Well, I still have the problem of how to fix this. It's nice that using an envelope reduces the problem, but I still get the popping when the envelopes duration is set to 0.001 seconds or less...

You can lead a thirsty horse to water, but you can’t make it take a drink… Oh well… Rolling Eyes

_________________
varice
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Wed Mar 05, 2014 1:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

heliocentric wrote:
In my mind I was like: "Hmm, shouldn't I just hear the frequency of the sine wave at different amplitudes, or just becoming silent?"


In this case, you also hear the frequency at which you are switching the sound on and off.

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
heliocentric



Joined: Feb 25, 2014
Posts: 7
Location: Canada

PostPosted: Thu Mar 06, 2014 8:11 am    Post subject: Reply with quote  Mark this post and the followings unread

@ varice: sorry, you're right, using an envelope is a really good solution.

@ Antimon: Ahh, I see. Thanks, that also helps me understand this much more. You've been a big help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [15 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use