Exemplo n.º 1
0
static void playNextAudioFrame(struct nodeInstanceData *context, VuoOutputTrigger(decodedAudio, VuoList_VuoAudioSamples))
{
	if(context->lastAudioSamples)
	{
		// Send Audio
		if(VuoListGetCount_VuoAudioSamples(context->lastAudioSamples) > 0)
		{
			VuoAudioSamples as = VuoListGetValueAtIndex_VuoAudioSamples(context->lastAudioSamples, 1);
			decodedAudio(context->lastAudioSamples);
		}

		VuoRelease(context->lastAudioSamples);
		context->lastAudioSamples = NULL;
	}

	uint64_t cur_time = dispatch_time(DISPATCH_TIME_NOW, 0);

	if(!context->movie) return;

	context->lastAudioSamples = VuoListCreate_VuoAudioSamples();

	double frameTimestampInSecs = 0;

	bool gotFrame = VuoMovie_getNextAudioSample(context->movie, context->lastAudioSamples, &frameTimestampInSecs);
	if(gotFrame)
	{
		VuoRetain(context->lastAudioSamples);
		context->lastAudioTimestamp = frameTimestampInSecs;
	}
	else
	{
		VLog("bad");

		if(context->lastAudioSamples)
			VuoRelease(context->lastAudioSamples);

		context->lastAudioSamples = NULL;
	}

	uint64_t presentationTime = (cur_time + NSEC_PER_SEC * AUDIO_SEC_PER_SAMPLE - 100000);
	dispatch_source_set_timer(context->audio_timer, presentationTime, DISPATCH_TIME_FOREVER, NSEC_PER_SEC / 100000 );
}
Exemplo n.º 2
0
					 "dependencies" : [
						 "VuoAudio"
					 ],
					 "node": {
						 "isInterface" : false,
						 "exampleCompositions" : [ "PanAudio.vuo" ],
					 }
				 });

void nodeEvent
(
		VuoInputData(VuoList_VuoAudioSamples) audioSamples,
		VuoOutputData(VuoAudioSamples) mixedSamples
)
{
	unsigned int channelCount = VuoListGetCount_VuoAudioSamples(audioSamples);

	*mixedSamples = VuoAudioSamples_alloc(VuoAudioSamples_bufferSize);

	for(unsigned int n = 0; n < (*mixedSamples).sampleCount; n++)
		(*mixedSamples).samples[n] = 0.;

	for(unsigned int i = 0; i < channelCount; i++)
	{
		VuoAudioSamples as = VuoListGetValueAtIndex_VuoAudioSamples(audioSamples, i+1);

		for(unsigned int n = 0; n < as.sampleCount; n++)
			(*mixedSamples).samples[n] += as.samples[n];
	}
}
Exemplo n.º 3
0
#include <OpenGL/CGLMacro.h>

VuoModuleMetadata({
					 "title" : "Make Image from Channels",
					 "keywords" : [ "waveform", "amplitudes" ],
					 "version" : "1.0.0"
				 });

void nodeEvent
(
		VuoInputData(VuoList_VuoAudioSamples) channels,
		VuoOutputData(VuoImage) image
)
{
	VuoInteger rows = VuoListGetCount_VuoAudioSamples(channels);
	if (!rows)
	{
		*image = NULL;
		return;
	}

	VuoInteger columns = VuoListGetValueAtIndex_VuoAudioSamples(channels, 1).sampleCount;

	unsigned char *pixels = (unsigned char *)calloc(1, rows*columns);
	for (VuoInteger row = 0; row < rows; ++row)
	{
		VuoAudioSamples rowSamples = VuoListGetValueAtIndex_VuoAudioSamples(channels, row+1);
		for (VuoInteger column = 0; column < MIN(columns, rowSamples.sampleCount); ++column)
			pixels[row*columns + column] = 127.5 + rowSamples.samples[column]*127.5;
	}