Beispiel #1
0
long Nes_Rewinder::read_samples( short* out, long out_size )
{
	int count = samples_avail();
	if ( count )
	{
		if ( count > out_size )
		{
			count = out_size;
		}
		
		if ( !reverse_enabled )
		{
			memcpy( out, frames [current_frame].samples, count * sizeof *out );
		}
		else
		{
			int step = samples_per_frame();
			for ( int i = step; i-- > 0; )
				copy_reverse( frames [current_frame].samples + i, count, out + i, step );
		}
		
		if ( fade_sound_in )
		{
			fade_sound_in = false;
			fade_samples_( out, count, 1 );
		}
		
		if ( frames [current_frame].fade_out )
		{
			fade_sound_in = true;
			fade_samples_( out, count, -1 );
		}
	}
	return count;
}
Beispiel #2
0
int
FindOptimalWarpingPath(double *cost_matrix, int *query_path, int *data_path, int max_path_size, int query_size, int data_size, int i, int j, int *step_list, int step_list_size)
{
	int path_size = 1;
	int step_max_i = -1;
	int step_max_j = -1;

	for(int k=0; k < step_list_size; k++)
	{
		step_max_i = std::max(step_max_i, step_list[k*2]);
		step_max_j = std::max(step_max_j, step_list[k*2+1]);
	}

	query_path[0] = i;
	data_path[0] = j;

	while ((i-step_max_i > 0) || (j-step_max_j > 0))
	{
		double cost_list[step_list_size];
		for(int k = 0; k < step_list_size; k++)
			cost_list[k] = DBL_MAX;
		for(int k = 0; k < step_list_size; k++)
		{
			int step_i = i-step_list[2*k];
			int step_j = j-step_list[2*k+1];
			if ( (step_i >= 0) and (step_j >= 0) )
				cost_list[k] = cost_matrix[index2D(step_i, step_j, query_size, data_size)];
		}
		int k = argminOfN(cost_list, step_list_size);
		i = i - step_list[2*k];
		j = j - step_list[2*k+1];

		if ( (i >= 0) && (j >= 0) && (path_size < max_path_size) )
		{
			query_path[path_size] = i;
			data_path[path_size] = j;
			path_size++;
		}
	}

	copy_reverse(query_path, path_size);
	copy_reverse(data_path, path_size);

	return path_size;
}
Beispiel #3
0
__EXPORT void board_crashdump(uintptr_t currentsp, FAR void *tcb, FAR const uint8_t *filename, int lineno)
{
	/* We need a chunk of ram to save the complete context in.
	 * Since we are going to reboot we will use &_sdata
	 * which is the lowest memory and the amount we will save
	 * _should be_ below any resources we need herein.
	 * Unfortunately this is hard to test. See dead below
	 */

	fullcontext_s *pdump = (fullcontext_s *)&_sdata;

	(void)enter_critical_section();

	struct tcb_s *rtcb = (struct tcb_s *)tcb;

	/* Zero out everything */

	memset(pdump, 0, sizeof(fullcontext_s));

	/* Save Info */

	pdump->info.lineno = lineno;

	if (filename) {

		int offset = 0;
		unsigned int len = strlen((char *)filename) + 1;

		if (len > sizeof(pdump->info.filename)) {
			offset = len - sizeof(pdump->info.filename) ;
		}

		strncpy(pdump->info.filename, (char *)&filename[offset], sizeof(pdump->info.filename));
	}

	/* Save the value of the pointer for current_regs as debugging info.
	 * It should be NULL in case of an ASSERT and will aid in cross
	 * checking the validity of system memory at the time of the
	 * fault.
	 */

	pdump->info.current_regs = (uintptr_t) CURRENT_REGS;

	/* Save Context */


#if CONFIG_TASK_NAME_SIZE > 0
	strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
#endif

	pdump->info.pid = rtcb->pid;


	/* If  current_regs is not NULL then we are in an interrupt context
	 * and the user context is in current_regs else we are running in
	 * the users context
	 */

	if (CURRENT_REGS) {
		pdump->info.stacks.interrupt.sp = currentsp;

		pdump->info.flags |= (eRegsPresent | eUserStackPresent | eIntStackPresent);
		memcpy(pdump->info.regs, (void *)CURRENT_REGS, sizeof(pdump->info.regs));
		pdump->info.stacks.user.sp = pdump->info.regs[REG_R13];

	} else {

		/* users context */
		pdump->info.flags |= eUserStackPresent;

		pdump->info.stacks.user.sp = currentsp;
	}

	if (pdump->info.pid == 0) {

		pdump->info.stacks.user.top = g_idle_topstack - 4;
		pdump->info.stacks.user.size = CONFIG_IDLETHREAD_STACKSIZE;

	} else {
		pdump->info.stacks.user.top = (uint32_t) rtcb->adj_stack_ptr;
		pdump->info.stacks.user.size = (uint32_t) rtcb->adj_stack_size;;
	}

#if CONFIG_ARCH_INTERRUPTSTACK > 3

	/* Get the limits on the interrupt stack memory */

	pdump->info.stacks.interrupt.top = (uint32_t)&g_intstackbase;
	pdump->info.stacks.interrupt.size  = (CONFIG_ARCH_INTERRUPTSTACK & ~3);

	/* If In interrupt Context save the interrupt stack data centered
	 * about the interrupt stack pointer
	 */

	if ((pdump->info.flags & eIntStackPresent) != 0) {
		stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
		copy_reverse(pdump->istack, &ps[arraySize(pdump->istack) / 2], arraySize(pdump->istack));
	}

	/* Is it Invalid? */

	if (!(pdump->info.stacks.interrupt.sp <= pdump->info.stacks.interrupt.top &&
	      pdump->info.stacks.interrupt.sp > pdump->info.stacks.interrupt.top - pdump->info.stacks.interrupt.size)) {
		pdump->info.flags |= eInvalidIntStackPrt;
	}

#endif

	/* If In interrupt context or User save the user stack data centered
	 * about the user stack pointer
	 */
	if ((pdump->info.flags & eUserStackPresent) != 0) {
		stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
		copy_reverse(pdump->ustack, &ps[arraySize(pdump->ustack) / 2], arraySize(pdump->ustack));
	}

	/* Is it Invalid? */

	if (!(pdump->info.stacks.user.sp <= pdump->info.stacks.user.top &&
	      pdump->info.stacks.user.sp > pdump->info.stacks.user.top - pdump->info.stacks.user.size)) {
		pdump->info.flags |= eInvalidUserStackPtr;
	}

	int rv = stm32_bbsram_savepanic(HARDFAULT_FILENO, (uint8_t *)pdump, sizeof(fullcontext_s));

	/* Test if memory got wiped because of using _sdata */

	if (rv == -ENXIO) {
		char *dead = "Memory wiped - dump not saved!";

		while (*dead) {
			up_lowputc(*dead++);
		}

	} else if (rv == -ENOSPC) {

		/* hard fault again */

		up_lowputc('!');
	}


#if defined(CONFIG_BOARD_RESET_ON_CRASH)
	px4_systemreset(false);
#endif
}