<commit_before>/* 
 * TTBlue Audio Engine
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#ifndef __TT_AUDIOENGINE_H__
#define __TT_AUDIOENGINE_H__

#include "TTObject.h"
#include "TTAudioSignal.h"
#include "portaudio.h"


/**	TTAudioEngine is a class that is used to drive realtime audio and scheduling operations in the TTBlue environment.
	It is currently implemented as a wrapper around PortAudio.	
 
 
 QUESTIONS
 - should this be a singleton, like the environment object?
 - how do we properly clean-up the environment from something like Max?  I guess we need a quittask?
 
 
 THOUGHTS
 - a TTAudioOutput class will work by writing to the TTAudioEngine's output buffer.
 - likewise a TTAudioInput class will work by retrieving from the TTAudioEngine's input buffer.
 - the scheduler, and others like the Lydbaer output class, will subscribe to this class for notifications on each call from PortAudio.
 
 */
class TTEXPORT TTAudioEngine : public TTObject {
	TTUInt16			numInputChannels;
	TTUInt16			numOutputChannels;
	TTUInt16			vectorSize;			///< framesPerBuffer
	TTUInt32			sampleRate;
    PaStream*			stream;
	TTListPtr			callbackObservers;
	TTSymbolPtr			inputDevice;
	TTSymbolPtr			outputDevice;
	const PaDeviceInfo*	inputDeviceInfo;
	const PaDeviceInfo*	outputDeviceInfo;
	TTInt16				inputDeviceIndex;
	TTInt16				outputDeviceIndex;
	TTBoolean			isRunning;
public:
	TTAudioSignalPtr	inputBuffer;
	TTAudioSignalPtr	outputBuffer;

	

	TTAudioEngine();
	virtual ~TTAudioEngine();
	
	TTErr initStream();
	
	TTErr start();
	TTErr stop();
	
	TTErr getCpuLoad(TTValue& returnedValue);
	
	TTErr getAvailableInputDevices(TTValue& returnedDeviceNames);
	TTErr getAvailableOutputDevices(TTValue& returnedDeviceNames);

	// Attribute Accessors
	TTErr setinputDevice(TTValue& newDeviceName);
	TTErr setoutputDevice(TTValue& newDeviceName);
	TTErr setvectorSize(TTValue& newVectorSize);
	TTErr setsampleRate(TTValue& newSampleRate);
	
	TTErr addCallbackObserver(const TTValue& objectToReceiveNotifications);
	TTErr removeCallbackObserver(const TTValue& objectCurrentlyReceivingNotifications);
	
	/**	This is called repeatedly by PortAudio every time a new vector of audio is needed.	*/
	TTInt32 callback(const TTFloat32*					input, 
					 TTFloat32*							output, 
					 TTUInt32							frameCount, 
					 const PaStreamCallbackTimeInfo*	timeInfo, 
					 PaStreamCallbackFlags				statusFlags);
	
};

typedef TTAudioEngine* TTAudioEnginePtr;



TTErr					TTAudioEngineCreate();
TTErr					TTAudioEngineFree();
TTEXPORT TTObjectPtr	TTAudioEngineReference();
TTAudioSignalPtr		TTAudioEngineGetInputSignalReference();
TTAudioSignalPtr		TTAudioEngineGetOutputSignalReference();
TTErr					TTAudioEngineStart();
TTErr					TTAudioEngineStop();


/** A C-function used for the callback from PortAudio.  
	This simply passes the call to the callback method in the TTAudioEngine object.		*/
int TTAudioEngineStreamCallback(const void*						input,
								void*							output,
								unsigned long					frameCount,
								const PaStreamCallbackTimeInfo*	timeInfo,
								PaStreamCallbackFlags			statusFlags,
								void*							userData ) ;



#endif // __TT_AUDIOENGINE_H__
<commit_msg>TTAudioEngine: exporting a couple of important methods<commit_after>/* 
 * TTBlue Audio Engine
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#ifndef __TT_AUDIOENGINE_H__
#define __TT_AUDIOENGINE_H__

#include "TTObject.h"
#include "TTAudioSignal.h"
#include "portaudio.h"


/**	TTAudioEngine is a class that is used to drive realtime audio and scheduling operations in the TTBlue environment.
	It is currently implemented as a wrapper around PortAudio.	
 
 
 QUESTIONS
 - should this be a singleton, like the environment object?
 - how do we properly clean-up the environment from something like Max?  I guess we need a quittask?
 
 
 THOUGHTS
 - a TTAudioOutput class will work by writing to the TTAudioEngine's output buffer.
 - likewise a TTAudioInput class will work by retrieving from the TTAudioEngine's input buffer.
 - the scheduler, and others like the Lydbaer output class, will subscribe to this class for notifications on each call from PortAudio.
 
 */
class TTEXPORT TTAudioEngine : public TTObject {
	TTUInt16			numInputChannels;
	TTUInt16			numOutputChannels;
	TTUInt16			vectorSize;			///< framesPerBuffer
	TTUInt32			sampleRate;
    PaStream*			stream;
	TTListPtr			callbackObservers;
	TTSymbolPtr			inputDevice;
	TTSymbolPtr			outputDevice;
	const PaDeviceInfo*	inputDeviceInfo;
	const PaDeviceInfo*	outputDeviceInfo;
	TTInt16				inputDeviceIndex;
	TTInt16				outputDeviceIndex;
	TTBoolean			isRunning;
public:
	TTAudioSignalPtr	inputBuffer;
	TTAudioSignalPtr	outputBuffer;

	

	TTAudioEngine();
	virtual ~TTAudioEngine();
	
	TTErr initStream();
	
	TTErr start();
	TTErr stop();
	
	TTErr getCpuLoad(TTValue& returnedValue);
	
	TTErr getAvailableInputDevices(TTValue& returnedDeviceNames);
	TTErr getAvailableOutputDevices(TTValue& returnedDeviceNames);

	// Attribute Accessors
	TTErr setinputDevice(TTValue& newDeviceName);
	TTErr setoutputDevice(TTValue& newDeviceName);
	TTErr setvectorSize(TTValue& newVectorSize);
	TTErr setsampleRate(TTValue& newSampleRate);
	
	TTErr addCallbackObserver(const TTValue& objectToReceiveNotifications);
	TTErr removeCallbackObserver(const TTValue& objectCurrentlyReceivingNotifications);
	
	/**	This is called repeatedly by PortAudio every time a new vector of audio is needed.	*/
	TTInt32 callback(const TTFloat32*					input, 
					 TTFloat32*							output, 
					 TTUInt32							frameCount, 
					 const PaStreamCallbackTimeInfo*	timeInfo, 
					 PaStreamCallbackFlags				statusFlags);
	
};

typedef TTAudioEngine* TTAudioEnginePtr;



TTErr						TTAudioEngineCreate();
TTErr						TTAudioEngineFree();
TTEXPORT TTObjectPtr		TTAudioEngineReference();
TTEXPORT TTAudioSignalPtr	TTAudioEngineGetInputSignalReference();
TTEXPORT TTAudioSignalPtr	TTAudioEngineGetOutputSignalReference();
TTErr						TTAudioEngineStart();
TTErr						TTAudioEngineStop();


/** A C-function used for the callback from PortAudio.  
	This simply passes the call to the callback method in the TTAudioEngine object.		*/
int TTAudioEngineStreamCallback(const void*						input,
								void*							output,
								unsigned long					frameCount,
								const PaStreamCallbackTimeInfo*	timeInfo,
								PaStreamCallbackFlags			statusFlags,
								void*							userData ) ;



#endif // __TT_AUDIOENGINE_H__

{'fraction_non_alphanumeric': 0.06253785584494245, 'fraction_numerical': 0.0072683222289521504, 'mean_word_length': 4.309485530546624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2335821', 'n_tokens_mistral': 2353, 'n_tokens_neox': 1957, 'n_words': 600}