Hi, Ive done the test modifying the helloworldcomponent of the sample project.
The problem is still there in this simple framework. I post below the cource code of the modified Helloworld component (that’s the only thing I have change in the sample project).
It shows 2 buttons :
B1 -> start the sinewave generator.
B2 -> stop it… on my setup it leads to the tone+some noise…
Any hints ?
Sylvain
[code]
class HelloWorldContentComponent : public Component, public ButtonListener, public AudioIODeviceCallback
{
private:
AudioDeviceManager audioDeviceManager;
AudioSourcePlayer audioSourcePlayer;
ToneGeneratorAudioSource *ToneGenerator;
Button *Btn1;
Button *Btn2;
public:
HelloWorldContentComponent()
{
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
const String error (audioDeviceManager.initialise (0, /* number of input channels /
2, / number of output channels /
0, / no XML settings… /
true / select default device on failure */));
ToneGenerator=NULL;
addAndMakeVisible (Btn1 = new TextButton (T("B1")));
Btn1->setButtonText (T("B1"));
Btn1->addButtonListener (this);
Btn1->setBounds (10,20,50,50);
addAndMakeVisible (Btn2= new TextButton (T("B2")));
Btn2->setButtonText (T("B2"));
Btn2->addButtonListener (this);
Btn2->setBounds (60,60,100,30);
}
~HelloWorldContentComponent()
{
deleteAndZero(Btn1);
deleteAndZero(Btn2);
if (ToneGenerator!=NULL) deleteAndZero(ToneGenerator);
}
void buttonClicked (Button* buttonThatWasClicked)
{
if (buttonThatWasClicked == Btn1)
{
ToneGenerator=new ToneGeneratorAudioSource();
ToneGenerator->setAmplitude(.8);
ToneGenerator->setFrequency(1000.0);
audioSourcePlayer.setSource(ToneGenerator);
audioDeviceManager.setAudioCallback (this);
}
else if (buttonThatWasClicked == Btn2)
{
audioDeviceManager.setAudioCallback(0);
audioSourcePlayer.setSource(0);
if (ToneGenerator!=NULL) deleteAndZero(ToneGenerator);
}
}
void paint (Graphics& g)
{
// clear the background with solid white
g.fillAll (Colours::white);
// set our drawing colour to black..
g.setColour (Colours::black);
// choose a suitably sized font
g.setFont (20.0f, Font::bold);
// and draw the text, centred in this component
g.drawText (T("Hello World!"),
0, 0, getWidth(), getHeight(),
Justification::centred, false);
}
void audioDeviceIOCallback (const float** inputChannelData,
int totalNumInputChannels,
float** outputChannelData,
int totalNumOutputChannels,
int numSamples)
{
audioSourcePlayer.audioDeviceIOCallback (inputChannelData, totalNumInputChannels, outputChannelData, totalNumOutputChannels, numSamples);
}
void audioDeviceAboutToStart (double sampleRate, int numSamplesPerBlock)
{
audioSourcePlayer.audioDeviceAboutToStart (sampleRate, numSamplesPerBlock);
}
void audioDeviceStopped()
{
audioSourcePlayer.audioDeviceStopped();
}
};
[/code][/code]