Getting basic audio output


#1

I’m having some trouble getting sound. I followed the “White noise Generator” tutorial and generated both a GUI window, and no command line +plus no sound. Anything missing?

//==============================================================================
MainComponent::MainComponent()
{
// Make sure you set the size of the component after
// you add any child components.
setSize (800, 600);

    // specify the number of input and output channels that we want to open
    setAudioChannels (0, 2);
}




//==============================================================================
void MainComponent::prepareToPlay(int samplesPerBlockExpected, double sampleRate)  
{
	String message;
	message << "Preparing to play audio" << newLine; 
	message << "Samples per-block expected =" << samplesPerBlockExpected << newLine; 
	message << "Sample Rate =" << sampleRate; 
	Logger::getCurrentLogger()->writeToLog(message);
}

void MainComponent::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) 
{
	for (auto channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
	{
		auto* buffer = bufferToFill.buffer->getWritePointer(channel, bufferToFill.startSample);
		
		for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
			buffer[sample] = random.nextFloat()* 0.25f - 0.125f; 
	}
	bufferToFill.clearActiveBufferRegion();
}

void MainComponent::releaseResources()
{
    // This will be called when the audio device stops, or when it is being
    // restarted due to a setting change.

    // For more details, see the help for AudioProcessor::releaseResources()
}

//==============================================================================
void MainComponent::paint (Graphics& g)
{
	float x = 60;
	float y = 50;
	float h = 30;

	float w = 50;
	float c = 40;
	float T = 30;
	g.fillAll(Colours::brown);   // clear the background

	g.setColour(Colours::cornflowerblue);
	g.Graphics::drawRoundedRectangle(x, y, h, w, c, T);   // draw an outline around the component


	g.setFont(50.0f);
	g.drawText("GUI IS STILL UGLY", getLocalBounds(),
		Justification::centred, true);
}
MainComponent::~MainComponent()
{
	shutdownAudio(); 
   };
void MainComponent::resized()
{
    // This is called when the MainContentComponent is resized.
    // If you add any child components, this is where you should
    // update their positions.
}

#2

OT But in the sample code on Roli’s site/zip/pip ‘between’ is spelled ‘betweem’.

Line 86 SimpleSynthNoiseTutorial


#3

In getNextAudioBlock you clear the buffer (that is, make it silent) after filling in the samples.


#4

https://docs.juce.com/master/structAudioSourceChannelInfo.html#a6246ca9f1f6ef86dab31fc0eeaacb7a3
that will clear out the buffer completely, giving you no sound.

edit: snap @Xenakios :smiley:


#5

Okay. So I’ll have to clear the samples at some point correct? So should I lift the clear buffer and add it to perhaps the destructor?

Thanks,

William Raezer.


#6

Also, can I disable the GUI and just do straight command line if this is a simple noise maker?


#7

You don’t need to do the buffer clearing at all if you just replace all the audio in the given buffer section. But it’s useful if you use the buffer for a processing that needs to start from a silent buffer. (The clearing is just about silencing it, not about memory management which you don’t have to worry about with that buffer instance.)


#8

You need to do a separate command line project, I think. (The Projucer has a template project for that.)


#9

Fantastic. So I remove the clear buffer line hit f5 and then when it runs I’ll have my first audio app