electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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
Unexpected behavior with Impulse UGen
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
JamesO



Joined: Nov 05, 2018
Posts: 1
Location: Colorado

PostPosted: Mon Nov 05, 2018 10:28 am    Post subject: Unexpected behavior with Impulse UGen Reply with quote  Mark this post and the followings unread

Hello! I hope someone can help me. I am new to ChucK and to these forums.

There is something I want to do which would require that I work with the Impulse UGen rather than a standard oscillator. I was experimenting with it to make sure I understand how to use it at a basic level. So I wrote a simple program to generate a sine wave with it, calculating each sample one at a time in an infinite loop using a sine function. This worked as expected. I tried to then modulate the frequency of this sine wave using another sine function and got unexpected results. Here is my code. See what you think.

Quote:
//Why does this program unexpectedly generate a tone that oscillates in pitch with ever increasing
//amplitude when it seemingly should vary in pitch consistently at a 1Hz rate with only a 2Hz range
//around 440Hz? Here, pitch should never go above 441Hz and never below 439Hz.

//declare theta variable for use in sine functions, starting it at zero.
float theta;
0 => theta;

//declare a frequency variable for use in our sine function to set the pitch of the sound wave.
float freQ;
440 => freQ;

//Connect an Impulse UGen to the dac.
Impulse z => dac;
0.5 => z.gain;

//infinite loop
while( true )
{
//The following line is intended to compute a frequency value for use in main sine function.
//This should generate an oscillating frequency value centered on 440 and varying between
//439 and 441, since a sine function only outputs a value between -1 and 1.
440 + Math.sin(theta) => freQ;

//Now we use another sine function to set the value of our Impulse UGen. This generates a
//simple sine tone. If, instead of 'freQ', we use 440, we will get a standard 440Hz sine wave.
Math.sin(freQ * theta) => z.next;

//Advance time one sample each loop cycle.
samp => now;

//For each loop cycle, increase the value of theta for use in our sine functions by an
//increment of 1 second divided by sample rate of 44100 and multiplied by 2*pi. This is
//so that our freQ value will correspond to standard wave cycles per second.
theta + 0.000142475857 => theta;
}

//I can't seem to figure out why this program generates the behavior that it does. Please 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 [1 Post]
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
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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