Beispiel #1
0
void *trode_filter_data(void *t){

  int n_spikes;

  filter_buffer( ((Trode *)t)->my_buffer );

  ((Trode*)t)->my_buffer->write_buffers();

  // We only look for spikes once the buffer ts has come to positive values
  if( ((Trode*)t)->my_buffer->my_daq->buffer_timestamp > 0){
    n_spikes = find_spikes( (Trode*)t );
  }

  if(n_spikes > 0){
    for(int n = 0; n < n_spikes; n++){
      //printf("FOUND SPIKE!\n");
      if( (((Trode*)t)->spike_array[n].ts >= ((Trode*)t)->next_ok_spike_ts) |
	  (  ((Trode*)t)->spike_array[n].ts < ((Trode*)t)->next_ok_spike_ts - 5000 )){

	// The first case admits spikes that happened after next_ok_spike_ts (last spike time + refractory)
	// The second case admits spikes that are more than half a millisecond OLDER than next_ok
	// This allows through spikes that came after a clock_restart

	//if( ((Trode*)t)->name == 0 & true){
	  //printf("next_ok_ts: %d  this_ts called ok: %d\n", ((Trode*)t)->next_ok_spike_ts, ((Trode*)t)->spike_array[n].ts);
	  //printf("*************SENDING A SPIKE***************\n");
	//}
	
	if(false & ((Trode*)t)->name == 0)
	  printf("Got inside the if block.\n");

	((Trode*)t)->spike_array[n].seq_num = ((Trode*)t)->total_spikes;
	((Trode*)t)->total_spikes++;

	spike_to_disk(&((Trode*)t)->spike_array[n]);
	spike_to_net(&((Trode*)t)->spike_array[n], (Trode*)t);
	((Trode*)t)->next_ok_spike_ts = ((Trode*)t)->spike_array[n].ts + ((Trode*)t)->refractory_period_tics;
	
	//if( ((Trode*)t)->name == 0 & true){
	// printf("sent the spike at %d.  Now next_ok_ts is %d.\n",n, ((Trode*)t)->next_ok_spike_ts);
	//}

      }
    }
  }

//if( ((Trode*)t)->name == 0 & n_spikes > 0)
//   printf("Found %d spikes.\n",n_spikes);

}
Beispiel #2
0
mulk_type_return_t close_buffer(CURL *id, const char *base_url, CURLcode err_code, long resp_code, int *file_completed)
{
#ifdef ENABLE_METALINK
	double length_double;
	off_t length, byte_downloaded = 0, byte_total = 0;
	int chunk_completed = 0, chunk_total = 0, single_chunk = 0, is_file_ok = 0;
	metalink_file_list_t *metalink;
#endif /* ENABLE_METALINK */
	int i, valid_res = 0;
	mulk_type_return_t ret = MULK_RET_OK;
	buffer_t *buffer;

	if ((i = get_buffer(id)) < 0)
		return MULK_RET_ERR;

	if (file_completed)
		*file_completed = 0;

	MULK_INFO((_("Close link #%d\n"), i));

	buffer = buffer_array + i;

#ifdef ENABLE_METALINK
	metalink = buffer->url->metalink_uri;

	if (metalink) {
		metalink->header = 0;

		if (metalink->size < 0) {
			valid_res = is_valid_response(buffer->uri, err_code, resp_code, NULL, 0);

		   	if (valid_res) {
				if (curl_easy_getinfo(id, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &length_double) == CURLE_OK)
					length = (off_t) length_double;
				else
					length = 0;

				if (length > 0) {
					metalink->size = length;

					goto Exit;
				}
				else
					valid_res = 0;
			}
		}
		else {
			single_chunk = buffer->chunk && (metalink->chunk_number == 1);
			valid_res = is_valid_response(buffer->uri, err_code, resp_code, buffer->chunk, single_chunk);
		}

		/* actual URL no more used, decrement assignement counter */
		if (buffer->used_res) {
			buffer->used_res->assigned--;
			if (buffer->used_res->assigned < 0)
				buffer->used_res->assigned = 0;
		}

		if (buffer->chunk) {
			buffer->chunk->used_res = NULL;

			if (!valid_res)
				reset_chunk(buffer->chunk);

			if (file_statistics(metalink, &chunk_completed, &chunk_total,
				&byte_downloaded, &byte_total) == MULK_RET_OK) {
				MULK_INFO((_("Downloaded %d/%d chunks, %" PRIdMAX "/%" PRIdMAX " bytes\n"), chunk_completed, chunk_total,
					(intmax_t) byte_downloaded, (intmax_t) byte_total));
			}

			is_file_ok = (chunk_completed == chunk_total);
		}

		/* remove URL that returns an error from the list of usable URLs */
		if (!valid_res && buffer->used_res)
			remove_metalink_resource(metalink, buffer->used_res);

		if (buffer->chunk && is_file_ok)
			MULK_NOTE((_("RESULT: Metalink downloaded successfully, Filename:\"%s\" Size:%" PRIdMAX "\n"),
				metalink->file->name, (intmax_t) byte_downloaded));
		else if (!is_resource_available(metalink, (metalink->size < 0)))
			MULK_NOTE((_("RESULT: Metalink error, no more usable URLs for downloading, Filename:\"%s\"\n"),
				metalink->file->name));
	}
	else
		valid_res = is_valid_response(buffer->uri, err_code, resp_code, NULL, 0);
#else /* not ENABLE_METALINK */
	valid_res = is_valid_response(buffer->uri, err_code, resp_code);
#endif /* ENABLE_METALINK */

	/* is the last chunk? */
	if (get_buffer_by_url(buffer->url, i) < 0) {
#ifdef ENABLE_METALINK
		if (metalink) {
			if (!is_file_ok && is_resource_available(metalink, (metalink->size < 0)))
				goto Exit;

			valid_res = is_file_ok;
		}
#endif /* ENABLE_METALINK */

		if (buffer->file_pt)
			fclose(buffer->file_pt);
		buffer->file_pt = NULL;

		if ((ret = filter_buffer(i, valid_res, base_url, err_code, resp_code)) == MULK_RET_OK && file_completed)
			*file_completed = 1;
	}
	
#ifdef ENABLE_METALINK
Exit:
	buffer->chunk = NULL;
	buffer->used_res = NULL;
#endif
	buffer->file_pt = NULL;
	buffer->id = NULL;
	buffer->url = NULL;
	buffer->uri = NULL;
	string_free(&buffer->filename);

	return ret;
}
Beispiel #3
0
void
filter(int width, int height, uint8_t * const input[], uint8_t *output[])
{
	if (param_fast)
	{
		if( interlace )
		{
			filter_buffer_fast(width, height/2, width*2, 
						  radius_luma, threshold_luma, 
						  input[0], output[0]);
			filter_buffer_fast(width, height/2, width*2, 
						  radius_luma, threshold_luma, 
						  input[0]+width, output[0]+width);
	
			filter_buffer_fast(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[1], output[1]);
			filter_buffer_fast(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[1]+width/SS_H, output[1]+width/SS_H);
	
			filter_buffer_fast(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[2], output[2]);
			filter_buffer_fast(width/SS_H, (height/SS_V)/2, (width/SS_H)*2,
						  radius_chroma, threshold_chroma, 
						  input[2]+width/SS_H, output[2]+width/SS_H);
		}
		else
		{
			filter_buffer_fast(width, height, width, 
							  radius_luma, threshold_luma, 
							  input[0], output[0]);
			filter_buffer_fast(width/SS_H, height/SS_V, width/SS_H, 
						  radius_chroma, threshold_chroma, 
						  input[1], output[1]);
			filter_buffer_fast(width/SS_H, height/SS_V, width/SS_H, 
						  radius_chroma, threshold_chroma, 
						  input[2], output[2]);
		}
	}
	else
	{
		if( interlace )
		{
			filter_buffer(width, height/2, width*2, 
						  radius_luma, threshold_luma, 
						  input[0], output[0]);
			filter_buffer(width, height/2, width*2, 
						  radius_luma, threshold_luma, 
						  input[0]+width, output[0]+width);
	
			filter_buffer(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[1], output[1]);
			filter_buffer(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[1]+width/SS_H, output[1]+width/SS_H);
	
			filter_buffer(width/SS_H, (height/SS_V)/2, (width/SS_H)*2, 
						  radius_chroma, threshold_chroma, 
						  input[2], output[2]);
			filter_buffer(width/SS_H, (height/SS_V)/2, (width/SS_H)*2,
						  radius_chroma, threshold_chroma, 
						  input[2]+width/SS_H, output[2]+width/SS_H);
		}
		else
		{
			filter_buffer(width, height, width, 
							  radius_luma, threshold_luma, 
							  input[0], output[0]);
			filter_buffer(width/SS_H, height/SS_V, width/SS_H, 
						  radius_chroma, threshold_chroma, 
						  input[1], output[1]);
			filter_buffer(width/SS_H, height/SS_V, width/SS_H, 
						  radius_chroma, threshold_chroma, 
						  input[2], output[2]);
		}
	}
}