Exemplo n.º 1
0
AudioIn::AudioIn(const int numChannels) throw()
{
	ugen_assert(numChannels > 0);
	
	initInternal(numChannels);
	generateFromProxyOwner(new RawInputUGenInternal(numChannels));
}
Exemplo n.º 2
0
BufferValues::BufferValues(Buffer const& buffer) throw()
{
	ugen_assert(buffer.size() > 0);
	ugen_assert(buffer.getNumChannels() > 0);
	
	initInternal(buffer.size());
	generateFromProxyOwner(new BufferValuesUGenInternal(buffer));
	
	for(int i = 0; i < buffer.size(); i++)
	{
		internalUGens[i]->initValue(buffer.getSampleUnchecked(i));
	}
}
Exemplo n.º 3
0
RecordBuf::RecordBuf(UGen const& input,
					 Buffer const& buffer, 
					 UGen const& recLevel,
					 UGen const& preLevel,
					 UGen const& loop, 
					 const UGen::DoneAction doneAction) throw()
{
	ugen_assert(buffer.size() > 0);
	ugen_assert(buffer.getNumChannels() > 0);

	const int numChannels = ugen::max(buffer.getNumChannels(), input.getNumChannels());
	initInternal(numChannels);
	generateFromProxyOwner(new RecordBufUGenInternal(input, buffer, recLevel, preLevel, loop.mix(), doneAction));
}
FFTMagnitudeSelection::FFTMagnitudeSelection(UGen const& input, 
											 FFTEngine const& fft, 
											 const int overlap, 
											 IntArray const& bins) throw()
{
	int overlapChecked = Bits::isPowerOf2(overlap) ? overlap : Bits::nextPowerOf2(overlap);
	
	ugen_assert(overlap != overlapChecked); // should be power of 2

	FFTMagnitudeSelectionUGenInternal *fftMag = new FFTMagnitudeSelectionUGenInternal(input.mix(), 
																					  fft, 
																					  overlapChecked, 
																					  bins);
		
	initInternal(fftMag->getNumBins());
	generateFromProxyOwner(fftMag);
}
bool DiskOut::initWithAudioFileAiff32(const char *audioFilePath, 
									  UGen const& input, 
									  bool overwriteExisitingFile) throw()
{
	Text path; // this needs to be here so it doesn't get garbage collected too early
	
	if(audioFilePath[0] != '/')
	{	
		path = NSUtilities::pathInDirectory(NSUtilities::Documents, audioFilePath);
		audioFilePath = path.getArray();
	}
	
	CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation(NULL, 
															   (UInt8*)audioFilePath, 
															   strlen(audioFilePath), 
															   false);
	
	AudioStreamBasicDescription format;
	
	const int numChannels = input.getNumChannels();
	
	format.mChannelsPerFrame	= numChannels;
	format.mSampleRate			= UGen::getSampleRate();
	format.mFormatID			= kAudioFormatLinearPCM;
	format.mFormatFlags			= kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
	format.mBitsPerChannel		= 32;
	format.mBytesPerFrame		= format.mChannelsPerFrame * format.mBitsPerChannel / 8;
	format.mFramesPerPacket		= 1;
	format.mBytesPerPacket		= format.mBytesPerFrame * format.mFramesPerPacket;
	
	AudioFileID	audioFile;
	OSStatus status = AudioFileCreateWithURL(fileURL,
											 kAudioFileAIFFType,
											 &format,
											 overwriteExisitingFile ? kAudioFileFlags_EraseFile : 0,
											 &audioFile);
	
	if(status != noErr) return false;
	
	initInternal(numChannels);
	generateFromProxyOwner(new DiskOutUGenInternalAiff32(audioFile, format, input));
	
	return true;	
}
Exemplo n.º 6
0
void DiskOut::initWithJuceFile(File const& file, UGen const& input, bool overwriteExisitingFile, int bitDepth) throw()
{
	DiskOutUGenInternal* internal;
	
	if(file.isDirectory()) 
	{
		internal = new DiskOutUGenInternal(file.getChildFile(getFileNameWithTimeIdentifier("DiskOut")), 
										   input, 
										   overwriteExisitingFile, 
										   bitDepth);
	}
	else
	{
		internal = new DiskOutUGenInternal(file, input, overwriteExisitingFile, bitDepth);
	}
	
	initInternal(input.getNumChannels());
	generateFromProxyOwner(internal);
}
Exemplo n.º 7
0
void DiskIn::initWithJuceFile(File const& file, 
							  bool loopFlag, 
							  const double startTime, 
							  const int numFrames,
							  const UGen::DoneAction doneAction) throw()
{
	AudioFormatManager formatManager;
	formatManager.registerBasicFormats();
	
	AudioFormatReader* reader = formatManager.createReaderFor (file);
	int numChannels = reader->numChannels;
	delete reader;
	
	initInternal(numChannels);
	generateFromProxyOwner(new DiskInUGenInternal(file, 
												  numChannels, 
												  loopFlag, 
												  startTime, 
												  numFrames, 
												  doneAction));	
}
Exemplo n.º 8
0
PlayBuf::PlayBuf(Buffer const& buffer, 
				 UGen const& rate, 
				 UGen const& trigger, 
				 UGen const& startPos, 
				 UGen const& loop, 
				 const UGen::DoneAction doneAction,
				 MetaData const& metaData) throw()
{	
	// just mix the input ugens, they should be mono
	// mix() will just return the original UGen if it has only one channel anyway
	
	const int numChannels = buffer.getNumChannels();
	
	if(numChannels > 0 && buffer.size() > 0)
	{
		initInternal(numChannels);
		
		UGen startPosChecked = startPos.mix();
		generateFromProxyOwner(new PlayBufUGenInternal(buffer, 
													   rate.mix(), 
													   trigger.mix(), 
													   startPosChecked, 
													   loop.mix(), 
													   doneAction,
													   metaData));

		for(int i = 0; i < numChannels; i++)
		{
			internalUGens[i]->initValue(buffer.getSample(i, startPosChecked.getValue(0)));
		}
	}	
	else
	{ 
		//?? what was I thinking here?
	}
}
void DiskIn::initWithAudioFile(const char* audioFilePath, 
							   const bool loopFlag, 
							   const double startTime,
							   const UGen::DoneAction doneAction) throw()
{
	Text path; // this needs to be here so it doesn't get garbage collected too early
	
	if(audioFilePath[0] != '/')
	{	
		path = NSUtilities::pathInDirectory(NSUtilities::Bundle, audioFilePath);
		audioFilePath = path.getArray();
	}
	
	OSStatus result;
	UInt32 dataSize;
	
	CFURLRef audioFileURL;
	audioFileURL = CFURLCreateFromFileSystemRepresentation(NULL,
														   (const UInt8*)audioFilePath, 
														   strlen(audioFilePath), 
														   false);
	
	AudioFileID	audioFile = 0;
	result = AudioFileOpenURL (audioFileURL, kAudioFileReadPermission, 0, &audioFile);
	CFRelease(audioFileURL);
	if (result != noErr) 
	{
		printf("DiskIn: error: Could not open file: %s err=%d\n", audioFilePath, (int)result);
		audioFile = 0;
	}
	
	if(audioFile)
	{
		AudioStreamBasicDescription format;
		dataSize = sizeof(format);
		result = AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &dataSize, &format);
		if (result != noErr) 
		{
			printf("DiskIn: error: Could not get data format: %s err=%d\n", audioFilePath, (int)result);
			AudioFileClose(audioFile);
			audioFile = 0;
		}
		else if(format.mFormatID != kAudioFormatLinearPCM)
		{
			printf("DiskIn: error: Only PCM formats supported\\n");
			AudioFileClose(audioFile);
			audioFile = 0;
		}
		else
		{
			if(format.mSampleRate != UGen::getSampleRate())
			{
				printf("DiskIn: warning: Sample rate mismatch - resampling is not yet implemented\\n");
			}
			
			if((format.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
			{
				initInternal(format.mChannelsPerFrame);
				
				if((format.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0)
				{
					generateFromProxyOwner(new DiskInUGenInternalFloatBigEndian(audioFile, 
																				format, 
																				loopFlag, 
																				startTime, 
																				doneAction));
					return;
				}
				else
				{
					generateFromProxyOwner(new DiskInUGenInternalFloatLittleEndian(audioFile, 
																				   format, 
																				   loopFlag, 
																				   startTime, 
																				   doneAction));
					return;
				}
			}
			else if((format.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0)
			{
				// aif and other big edian?
				if(format.mBitsPerChannel == 16)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalAiff16(audioFile, 
																		format, 
																		loopFlag, 
																		startTime, 
																		doneAction));
					return;
				}
				else if(format.mBitsPerChannel == 32)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalAiff32(audioFile, 
																		format, 
																		loopFlag, 
																		startTime, 
																		doneAction));			
					return;
				}
				else if(format.mBitsPerChannel == 24)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalAiff24(audioFile, 
																		format, 
																		loopFlag, 
																		startTime, 
																		doneAction));	
					return;
				}
				else
				{
					printf("DiskIn: error: Sound file format not yet supported.");
					AudioFileClose(audioFile);
					audioFile = 0;
				}
			}
			else
			{
				// wav and other little edian?
				if(format.mBitsPerChannel == 16)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalWav16(audioFile, 
																	   format, 
																	   loopFlag, 
																	   startTime, 
																	   doneAction));
					return;					
				}
				else if(format.mBitsPerChannel == 32)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalWav32(audioFile, 
																	   format, 
																	   loopFlag, 
																	   startTime, 
																	   doneAction));
					return;					
				}
				else if(format.mBitsPerChannel == 24)
				{
					initInternal(format.mChannelsPerFrame);
					generateFromProxyOwner(new DiskInUGenInternalWav24(audioFile, 
																	   format, 
																	   loopFlag, 
																	   startTime, 
																	   doneAction));
					return;					
				}
				else
				{
					printf("DiskIn: error: Sound file format not yet supported.");
					AudioFileClose(audioFile);
					audioFile = 0;
				}
			}
		}
	}
}
Exemplo n.º 10
0
MultiSliderUGen::MultiSliderUGen(UGen const& input, MultiSlider *sliders) throw()
{
	MultiSliderUGenInternal *internal = new MultiSliderUGenInternal(input, sliders);
	initInternal(input.getNumChannels());
	generateFromProxyOwner(internal);
}