Core samples

Hello world

Our favorite test, it probably is the simplest test with Audiostack and should be used to test if the SDK is working properly.

[...]

AudiostackContext context;
context.setLicenseKeyFromFile("LICENSE_FILE.aslc");

int helloId = 0;
int outputId = 1;

context.createInput(helloId,HelloInput);
context.createOutput(outputId,WindowsCoreAudioOutput,false);
// Output is mono, in order to accept mono microphone.

context.connect(helloId,outputId);
// No need of bus in this sample.
			
context.play();

char c;
std::cout<<"Aspic Audiostack says Hello. Press q to quit."<<std::endl;
do{
	std::cin>>c;
} while(c!='q');			

context.stop();

	
[...]

OpenAL (mic and output)

This sample connects microphone to computer output using OpenAL drivers.

Please note this sample doesn’t handle errors, please go direclty to the next sample for error handling.

[...]

enum:int{micId, outputId };

AudiostackContext context;
context.setLicenseKeyFromFile("LICENSE_FILE.aslc");

context.createInput(micId,OpenALInput);
context.createOutput(outputId,OpenALOutput,false);
// Output is mono, in order to accept mono microphone.

context.connect(micId,outputId);
// No need of bus in this sample.

context.play();

char c;
std::cout<<"Mic capture in progress. Press q to quit."<<std::endl;
do{
	std::cin>>c;
} while(c!='q');    

context.stop();

[...]

OpenAL (mic and output) with Error handling

The previous sample doesn’t catch any error, here is the sample application with error handling.

void err(const AudiostackContext& _context){
	if(_context.getError())
		throw std::runtime_error(_context.getLastErrorMessage());
} 

[...]

try{
	enum:int{micId, outputId };

	AudiostackContext context;
	context.setLicenseKeyFromFile("LICENSE_FILE.aslc");
	err(context);

	context.createInput(micId,OpenALInput);
	context.createOutput(outputId,OpenALOutput,false); 
	err(context);

	context.connect(micId,outputId);
	err(context);

	context.play();
	err(context);

	char c;
	std::cout<<"Mic capture in progress. Press q to quit."<<std::endl;
	do{ std::cin>>c;} while(c!='q');  

	context.stop();
	err(context);

}catch(std::exception& e){
	std::cout<<e.what()<<std::endl;
	
}catch(...){
	std::cout<<"Unhandled error"<<std::endl;
	
}

	
[...]

Gain

[...]

enum:int{helloId = 0, outputId = 1, busId, gainId};

AudiostackContext context;
context.setLicenseKeyFromFile("LICENSE_FILE.aslc");

context.createInput(helloId, HelloInput);
context.createOutput(outputId, WindowsCoreAudioOutput,true);					
// We use a stereo output

context.createBus(busId);										

context.createEffect(gainId, busId, MultiChannelSimpleGain,(unsigned int)2);	
// We add a gain with the ability to split the signal in 2 subchannels

context.connect(helloId,busId);									
context.connect(busId,outputId);								
// Connections are matching, because subchannel equality rule is observed

context.play();

context.setParameter("source/0/gain",0.5f);
context.setParameter("source/0/mute",true);

[...]

Sound rolloff over distance

The following samples uses AttenuationEffect and introduces source and listener position modification.

[...]

enum:int{helloId = 0, outputId = 1, busId, attenuationId};

AudiostackContext context;
context.setLicenseKeyFromFile("LICENSE_FILE.aslc");

context.createInput(helloId, HelloInput);
context.createOutput(outputId, WindowsCoreAudioOutput,false);
// We use a mono output

context.createBus(busId);                                       
context.createEffect(attenuationId,busId,AttenuationEffect,0U,1U);
// Effect apply a linear attenuation on mono channels.

context.connect(helloId,busId);                                   
context.connect(busId,outputId);        

float sourcePos[] = {0.0, 0.0, -1.0};
context.setParameter("source/0/position",sourcePos);
// The variable %src_id on our Input is automatically set, therefore we can use it in patterns on connected effects

float listenerPos[] = {0.0, 0.0, 0.0};
context.setParameter("listener/1/position",listenerPos);
// The variable %list_id on our Output is automatically set, therefore we can use it in patterns on connected effects

context.play();

char c;
do{
	std::cout<<"Press f or b to move the source forward/backward. Press q to quit."<<std::endl;
	std::cin>>c;

	switch(c){
	case 'f':
		sourcePos[2]-=1.0;
		context.setParameter("source/0/position",sourcePos);
		break;
	case 'b':
		sourcePos[2]+=1.0;
		context.setParameter("source/0/position",sourcePos);
		break;
	}
}while(c!='q');

context.stop();
		
[...]