Example #1
0
//--------------------------------------------------------------
aubioAnalyzer::~aubioAnalyzer(){
	  del_aubio_pitchdetection(pitch_output);
	  del_fvec(in);
      del_fvec(beats);
      del_aubio_beattracking(tracker);
	  aubio_cleanup();
}
AubioPitch::~AubioPitch(){
	del_aubio_pitchdetection(pitchDetect);
	del_fvec(vec);
	aubio_cleanup();
	//delk fvec
	
}
Example #3
0
// Main
int main(int argc, char * argv[]) {
	// User supplied correct vals? Otherwise show usage...
	// TODO: Allow a minimum of <image path> to be provided and default
	// 	 the rest.
	if (argc < 8) {
		fprintf(stderr, "usage: sonify <client name> <image path> <freq scale> <lowest freq> <sin | sq | tri | saw> <window scale>\ni.e. sonify sfy img.png 10000 1000 1 sin\n");
		exit(1);
	}
	jack_client_t * client;
	const char ** ports;
	char file_name[100];
	int window_scale;
	init_vars(argv, file_name, &window_scale);

	// Init Jack Client
	if ((client = jack_client_open(argv[1], JackNullOption, NULL)) == 0) {
		fprintf (stderr, "Jack server not running?\n");
		return 1;
	}
	jack_set_process_callback(client, process, 0);
	jack_set_sample_rate_callback(client, srate, 0);
	input_port = jack_port_register(client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
	output_port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

	// Get Sample Rate & Init Aubio
	sample_rate = jack_get_sample_rate(client);
	init_aubio(sample_rate);
	
	// Init SDL Surfaces
	source_image = IMG_Load(file_name);
	if (source_image == NULL) {
		fprintf(stderr, "Load failes: %s\n", IMG_GetError());
		exit(1);
	}
	//   Generate Tones From Pixels
	generate_tone_array(source_image);
	dest_image = SDL_CreateRGBSurface (SDL_SWSURFACE, source_image->w, source_image->h, 32, 0, 0, 0, 0);
	if(dest_image == NULL) {
		fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
		exit(1);
    	}
	SDL_FreeSurface(source_image);

	// Build Tone
	build_tone(image_tones[image_tones_index], image_tones_amp[image_tones_index], waveform_type);

	// Activate Jack Client
	if (jack_activate(client)) {
		fprintf(stderr, "cannot activate client\n");
		return 1;
	}

	// Init SDL Window
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		fprintf(stderr, "Init failed: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_Surface * display;
	display = SDL_SetVideoMode(dest_image->w * window_scale, dest_image->h * window_scale, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	if (display == NULL) { 
		fprintf(stderr, "SetVideoMode failed: %s\n", SDL_GetError()); 
		exit(1);
	}
	SDL_WM_SetCaption("Sonify", "Sonify");
	SDL_Event event;

	// GUI Loop
	// TODO: Implement a fullscreen mode that can be toggled with a keypress.
	// TODO: The larger the window_scale, the slower SDL_ResizeFactor runs.
	//       Consider writing a function that only redraws a particular portion
	//       of dub_image instead. This will improve performance in fullscreen
	//       mode down the line. 
	// TODO: Can we introduce some simple menu items for changing the transcoding
	//       algorithm on the fly?
	while(1) {
		if (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT) {
				break;
			}
		}
		// TODO: Optimize this...
		dub_image = SDL_DisplayFormat(dest_image);
		if (SDL_BlitSurface(SDL_ResizeFactor(dub_image, window_scale, 1), NULL, display, NULL) != 0) {
			fprintf(stderr, "SDL_BlitSurface() Failed.");
			exit(1);
		}
		SDL_Flip(display);
	}

	// Cleanup
	jack_client_close(client);
	del_aubio_pitchdetection(aubio);
	SDL_FreeSurface(display);
	SDL_FreeSurface(dub_image);
	SDL_FreeSurface(dest_image);
	SDL_Quit();
	free(cycle);
	free(image_tones);
	free(image_tones_amp);
	exit(0);
}
//--------------------------------------------------------------
aubioAnalyzer::~aubioAnalyzer(){
	del_aubio_pitchdetection(pitch_output);
	del_fvec(in);
	aubio_cleanup();
}