Code samples

Here is our simplest Hello world sample

[...]

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

enum:int{helloId,outputId};

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();

[...]

Extension specific samples

Each API Extension section contains samples, however, you can also use this list to direclty jump to specific samples:

Error handling

A wide majority of code samples in this documentation does not include any error handling, for readability.

The following sample detects context errors and provides exceptions.

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

[...]
	
try{
	int micId = 0;
	int outputId = 1;
	
	AudiostackContext context;
	context.setLicenseKeyFromFile("LICENSE_FILE.aslc");
	err(context);	// Get license errors
	
	context.createInput(micId,WindowsCoreAudioInput);
	context.createOutput(outputId,WindowsCoreAudioOutput,false);
	err(context);	// Get last error, raised by createInput or createOutput
	
	context.connect(micId,outputId);			
	err(context);	// Get potentiel connection errors
	
	context.play();
	err(context);	// Get errors raised at startup

	char c;
	do{
		std::cin>>c;
	} while(c!='q');		

	context.stop();
	err(context);	// Get errors raised when shutting down audio

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

[...]