# Getting basic audio output

**URL:** <https://forum.juce.com/t/getting-basic-audio-output/30506>\
**Category:** General JUCE discussion\
**Created:** [November 23, 2018, 9:17pm UTC](https://forum.juce.com/t/getting-basic-audio-output/30506 "2018-11-23T21:17:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Willogical](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@Willogical](https://forum.juce.com/u/Willogical)\
**Post date:** [November 23, 2018, 9:17pm UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/1 "2018-11-23T21:17:27Z")

</div>

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.
}

```

---

<div class="post-metadata">

**Author:** ![TeotiGraphix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/teotigraphix/32/2016_2.png) [@TeotiGraphix](https://forum.juce.com/u/TeotiGraphix)\
**Post date:** [November 23, 2018, 10:44pm UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/2 "2018-11-23T22:44:34Z")

</div>

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

Line 86 SimpleSynthNoiseTutorial

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [November 23, 2018, 11:31pm UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/3 "2018-11-23T23:31:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [November 23, 2018, 11:33pm UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/4 "2018-11-23T23:33:22Z")

</div>

> [@Willogical](#):
>
> ```auto
> bufferToFill.clearActiveBufferRegion();
> 
> ```

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

edit: snap @Xenakios 😃

---

<div class="post-metadata">

**Author:** ![Willogical](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@Willogical](https://forum.juce.com/u/Willogical)\
**Post date:** [November 24, 2018, 12:53am UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/5 "2018-11-24T00:53:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Willogical](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@Willogical](https://forum.juce.com/u/Willogical)\
**Post date:** [November 24, 2018, 12:55am UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/6 "2018-11-24T00:55:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [November 24, 2018, 12:58am UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/7 "2018-11-24T00:58:38Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [November 24, 2018, 1:00am UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/8 "2018-11-24T01:00:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Willogical](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@Willogical](https://forum.juce.com/u/Willogical)\
**Post date:** [November 24, 2018, 2:15am UTC](https://forum.juce.com/t/getting-basic-audio-output/30506/9 "2018-11-24T02:15:55Z")

</div>

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