login

online now

We have 122 guests and no members online

search

 
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Changing Frequency in Synth Mode Agony

Changing Frequency in Synth Mode Agony 2 years 11 months ago #595

Okay I made an account here because I'm ripping my hair out over here trying to figure out something that I feel is way more simple than I'm making it to be; I get really frustrated because the GinSing online documentation doesn't give any examples, it just goes 'heres the syntax, here's this and that - and there you go'; no 'help help' other than this forum anyway..

Regardless, I come here because it's been almost half a month and I have to submit something in a maker's fair by next month, and right now I haven't even figured out how to make a potentiometer change the value of the frequency of the sound; I feel like an idiot.

I've had to relearn a bunch about bread boards, circuitry, programming; all of that - I'm not a complete idiot, but I certainly am not a genius at this either. Trying to relearn all these things as well as make something for a competition/fair thing is putting SO much pressure on me that I feel like I'm going to explode or collapse.

Here is the code:

#include <GinSing.h>

GinSing GS;
GinSingSynth *s;

int analogPin = 5;
int val = 0;
float sFreq = 200.0f;

#define rcvPin 4
#define sndPin 3
#define ovfPin 2

void setup()
{
Serial.begin(9600); // setup serial
GS.begin(rcvPin, sndPin, ovfPin);
}

void pwModulation()
{
s->begin(); // start with a clean slate
s->selectBank ( BANK_A ); // set up bank A
s->setPatch ( OSC_B1_PWM_OSC_1 | OSC_1_TO_MIXER ); // set the PWM oscillator (B1) to link to bank A's FM oscillator (A1)
s->setWaveform ( OSC_1 , PULSE ); // set the tone oscillator (1) as a pulse wave (to be modulated)
s->setFrequency ( OSC_1 , sFreq ); // set the tone oscillator (1) to 200 Hz
s->setAmplitude ( OSC_1 , 0.5f ); // set the tone oscillator (1) volume to 50%
s->selectBank ( BANK_B ); // set up bank B
s->setPatch ( OSC_B1_PWM_OSC_1 ); // set the PWM oscillator (B1) to link to bank A's FM oscillator (A1)
s->setWaveform ( OSC_1 , SINE ); // set the PWM oscillator (B1) as a sine wave
s->setWavemode ( OSC_1 , POSITIVE ); // set the PWM oscillator (B1) to go from zero to full (no zero crossing)
s->setFrequency ( OSC_1 , 200.0f ); // set the PWM oscillator (B1) period to 2 seconds
s->setAmplitude ( OSC_1 , 1.0f ); // set the PWM oscillator (B1) to full modulation range
delay ( 50 ); // listen for x amount length
s->selectBank ( BANK_A ); s->setAmplitude ( OSC_1 , 0.0f ); // zero output for tone oscillator
s->selectBank ( BANK_B ); s->setAmplitude ( OSC_1 , 0.0f ); // zero output for PWM oscillator
delay ( 50 ); // one second of silence
}

void loop()
{
val = analogRead(analogPin); // read the input pin
if (val == (val + 1)) // I would use the parentheses. it prevents errors in interpretation.
{
sFreq += 10.0; // adding 10.0
}
else if (val == (val - 1)) // again the paren.
{
sFreq -= 10.0; // again here you are subtracting 10.0
}
s = GS.getSynth();
s->begin ();
pwModulation(); // pulse width modulate one oscillator with another
GS.end(); // end the device
}

It's messy, idc - but anyway,
the problem is, is that when the potentiometer's value is altered, it doesnt even change the tone of the frequency, it just keeps 'beeping' the same tone.
To me, the code part:

val = analogRead(analogPin); // read the input pin
if (val == (val + 1)) // I would use the parentheses. it prevents errors in interpretation.
{
sFreq += 10.0; // adding 10.0
}
else if (val == (val - 1)) // again the paren.
{
sFreq -= 10.0; // again here you are subtracting 10.0
}

looks absolutely fine, but I know that it's not working the way I want so...
Can anyone please help me? I'm loosing my mind.
The GinSing people really need to make a better guide, because I can't understand jack s**t and I'm also confused on doing something super super simple.

Thanks.
The administrator has disabled public write access.

Re: Changing Frequency in Synth Mode Agony 2 years 11 months ago #596

Sorry for your trouble, we hope nobody gets this far into a project to get frustrated before posting here. The included sample programs that get placed into the IDE should have provided an early testbed for this but its fine to search out on your own.

I suspect the problem is that you are re-initializing the system via begin() on every update. Try doing that first and lets see if the behavior changes.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.330 seconds