Example #1
0
static int allocate_internal_mem(void) {
    u32 i;

	c_amplitudes = (REAL *)malloc(BPM_DETECT_FFT_POINTS / 2 * sizeof(REAL));
	c_samples = (complex_t *)malloc(BPM_DETECT_FFT_POINTS * sizeof(complex_t));
	c_pfl_window = (REAL *)malloc(BPM_DETECT_FFT_POINTS * sizeof(REAL));
	c_pn_offset = (u16 *)malloc((BPM_DETECT_MAX_BPM + BPM_DETECT_MAX_MARGIN + 2) * sizeof(u16));

	if (c_amplitudes == 0 || c_samples == 0 || c_pfl_window == 0 || c_pn_offset == 0) {
		free_internal_mem();
		return -1;
	}

	memset(c_amplitudes, 0, BPM_DETECT_FFT_POINTS / 2 * sizeof(REAL));
	memset(c_samples, 0, BPM_DETECT_FFT_POINTS * sizeof(complex_t));
	memset(c_pfl_window, 0, BPM_DETECT_FFT_POINTS * sizeof(REAL));
	memset(c_pn_offset, 0, (BPM_DETECT_MAX_BPM + BPM_DETECT_MAX_MARGIN + 2) * sizeof(u16));

    c_pSubBand = (struct subband_t *)malloc(BPM_NUMBER_OF_SUBBANDS * sizeof(struct subband_t));
	if (c_pSubBand == 0) {
		free_internal_mem();
		return -1;
	}
	memset(c_pSubBand, 0, BPM_NUMBER_OF_SUBBANDS * sizeof(struct subband_t));

    for (i = 0; i < BPM_NUMBER_OF_SUBBANDS; i++) {
        c_pSubBand[i].buffer = (REAL *)malloc(c_buffer_size * sizeof(REAL));
        if (c_pSubBand[i].buffer == 0) {
		    free_internal_mem();
            return -1;
        }
        memset(c_pSubBand[i].buffer, 0, c_buffer_size * sizeof(REAL));

	    c_pSubBand[i].BPM_history_hit = (u16 *)malloc((BPM_DETECT_MAX_BPM + 2) * sizeof(u16));
		if (c_pSubBand[i].BPM_history_hit == 0) {
		    free_internal_mem();
            return -1;
		}

    }

    /* 
     * create COSINE window
     */
    for (i = 0; i < BPM_DETECT_FFT_POINTS; i++) {
        c_pfl_window[i] = (REAL)(sin((PI * i) / (BPM_DETECT_FFT_POINTS - 1.0))); 
    }
    DEBUG("c_pfl_window:\n");
    for (i = 1; i < BPM_DETECT_FFT_POINTS; i++) {
        if (i % 5 == 0) DEBUG("\n");
        DEBUG("%f, ", c_pfl_window[i]);
    }
    DEBUG("\n");


    c_ready = 1;

    return 0;
}
static void
pin_stats_tree_free (PinStatAddress *node)
{
	if (!node)
		return;
	pin_stats_tree_free (node->left);
	pin_stats_tree_free (node->right);
	free_internal_mem (node, INTERNAL_MEM_STATISTICS);
}
Example #3
0
/*
 * de-initialize of BPM detetion algorithm
 *
 * PARAMETERS:
 *     None
 *
 * RETURN VALUES:
 *     None
 *
 * REMARKS:
 *     Call this function if you do not need the BPM detection algorythm
 *
 */
void BPM_release(void) {
    free_internal_mem();
}