How to make the Slider Control the Frequency
The generated application contains an example slider control but the control is not yet controlling a generated C Code function.
So how do we know what functions are available to control?
1.We could return to AnadigmDesigner®2 and select the menu item" Dynamic Config." then "Visual C++ Prototype" to bring up the Visual C++ Prototype window. Then select "C Code Options", then "CAM Functions" to bring up the "Global C Code Functions Window ". This window allows you to see all available functions.
2.An alternative is to examine the files in the CCode project’s Source Files that are listed in Visual Studio.
From its name, the file "chip1_OscillatorSine1.cpp" looks like it might contain the function that will control the behavior of the oscillator. If we look inside that file, we see that it contains a C Code function that looks like this:
//-----------------------------------------------------------
// This function controls the frequency (Fo) and peak amplitude
// (A) of this module.
//-----------------------------------------------------------
void chip1_OscillatorSine1::setOscillatorSine(long Fo, double A)
{
an_setOscillatorSine(m_instance, Fo, A);
}
We know from our Sinewave Oscillator settings in AnadigmDesigner®2 that the Peak Amplitude can range from 1.44 to 4.00 and the Frequency can range from 1.00 to 8.00 kHz. (To see the settings panel again, double left-click on the Oscillator CAM that we placed and set in AnadigmDesigner®2.)
We notice that Fo is a "long" integer. This means that its values are in Hz rather than kHz so the range for this parameter is really 1000 Hz to 8000 Hz.
We will use the setOscillatorSine function to control the frequency. We can control the frequency by calling the function with different values of "Fo". We do not want to change the amplitude however so we will always call the function with "A" set to 1.44.
So, we now know which function to call and what the range of its values can be.
We now look at the UpdateSampleControls function in OscDlg.cpp which contains the following comment lines:
// NOTE:
//
// This would be the spot to perform C Code updates
// based on m_sampleValue.
//
// At this point, m_sampleValue holds the value that is
// displayed on the sample slider and edit box.
//
// To change the range of values of the slider change the
// following lines found in the OnInitialUpdate function above:
//
// m_sampleMin = 2.0;
// m_sampleMax = 8.5;
//
// EXAMPLE:
//
// m_chip1.GainHalf1.setGain(m_sampleValue);
// m_chip1.ExecuteReconfig();
//
}
Right before the right bracket, we add the following two lines of code:
m_chip1.OscillatorSine1.setOscillatorSine((long) m_sampleValue, 1.44);
m_chip1.ExecuteReconfig();
We also heed the advice to readjust the slider range values in the OnInitialUpdate function. We comment out the old values and substitute new values:
// Initialize the sample slider\edit controls
//m_sampleMin = 2.0;
//m_sampleMax = 8.5;
//m_sampleValue = 5.0;
m_sampleMin = 1000.0;
m_sampleMax = 8000.0;
m_sampleValue = 1000.0;
We now recompile and run the Osc project.
The slider is now functional and controls the frequency of the Oscillator as it is repositioned!