WhiteNoiseAudioSource


#1

A handy little class for testing audio setups.

#ifndef __WHITENOISEAUDIOSOURCE__
#define __WHITENOISEAUDIOSOURCE__

#include "juce.h"


class WhiteNoiseAudioSource : public AudioSource {
public:
	float gain;

	WhiteNoiseAudioSource(){
		gain = 0.3f;
	}
	
	
	~WhiteNoiseAudioSource(){}
	
	
	void prepareToPlay(int blockSize, double samplerate){}	
	
	
	void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill){
		
		int numChannels = (bufferToFill.buffer)->getNumChannels();
		
		for(int channel = 0; channel < numChannels; channel++){
			
			float* outBuffer = (bufferToFill.buffer)->getSampleData(channel, bufferToFill.startSample);
		
			for(int i = 0; i < bufferToFill.numSamples; i++ ){
				outBuffer[i] = ((Random::getSystemRandom().nextFloat() * 2.0f) - 1.0f) * gain;
			}
		}
		
	}
	
	
	void releaseResources(){}
	
	
};


#endif

#2

Make sure you turn your speakers down first…


#3