/**
 * @brief [calculate equalized output samples]
 * @details [this routine uses fir lowpass filters and delays to split off the spectrum
 * into the specified bands. 
 * The input signal is low pass filtered to split the spectrum, and also separately delayed to 
 * keep the input in phase with the output of the filters. This delayed input is used to find the 
 * rest of the spectrum not being filtered, by subtracting the input by the filtered samples. So using
 * two filters allows us to split off 3 different bands: the band below and the band above the first lowpass 
 * filter, and the band below and the band above the second lowpass filter. The band above the first lowpass
 * and the band below the second lowpass is the same band.]
 * 
 * @param D1 [pointer to the delay struct]
 * @param D2 [pointer to the delay struct]
 * @param D3 [pointer to the delay struct]
 * @param Q [pointer to the eq struct]
 * @param input [buffer containing samples to work on]
 */
void calc_eq(DELAY_T * D1, DELAY_T * D2, DELAY_T * D3, EQ_T * Q, float * input) {

	int i, j, k;
	float mid_input[Q->block_size];

	// LOW BAND ------------------------------------------------------------------------------------------------
	// calculate low band output with no gain
	// lowpass with cutoff of 350Hz
	arm_fir_f32(&(Q->S_low), input, Q->low_band_out, Q->block_size);

	// delay filter output to stay in phase with mid and high band for reconstructing output
	calc_delay(0, D1, Q->low_band_out);	// D1->output is now the final low band output to be reconstructed


	// MID BAND ------------------------------------------------------------------------------------------------
	// delay input signal to stay in phase for mid band calculation
	calc_delay(0, D2, input);	// 0 is to output just the delayed signal

	// input for mid band is the delayed signal minus the low band
	// this gives the samples for the rest of the spectrum that the low band doesn't cover
	for(j = 0; j < Q->block_size; j++) {
		mid_input[j] = D2->output[j] - Q->low_band_out[j];
	}
	// lowpass with cutoff of 1050Hz
	// this contains the band from the cutoff of the low band, to 1050Hz
	arm_fir_f32(&(Q->S_mid), mid_input, Q->mid_band_out, Q->block_size);


	// HIGH BAND -----------------------------------------------------------------------------------------------
	// delay signal to stay in phase for high band calculation (note the input was already delayed once for the mid band calc)
	calc_delay(0, D3, mid_input);	// delay the input to the mid filter once more 

	// the high band is the input going into the mid filter delayed, and then subtracted from the mid filter output
	// this gives the samples for the rest of the spectrum that the low and mid band doesn't cover
	for(k = 0; k < Q->block_size; k++) {
		Q->high_band_out[k] = D3->output[k] - Q->mid_band_out[k];
	}


	// calculate block of equalized output samples -------------------------------------------------------------
	for(i = 0; i < Q->block_size; i++) {
		// output is the output of each band scaled by the band gain and added together 
		Q->output[i] = 0.6 * ((Q->low_scale * D1->output[i]) + (Q->mid_scale * Q->mid_band_out[i]) + (Q->high_scale * Q->high_band_out[i]));
	}
	
}
Example #2
0
static gboolean timeout_info_req(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    dhcp->RT = calc_delay(dhcp->RT, INF_MAX_RT);

    DBG("info RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Example #3
0
static gboolean timeout_solicitation(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    dhcp->RT = calc_delay(dhcp->RT, SOL_MAX_RT);

    DBG("solicit RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Example #4
0
static gboolean timeout_renew(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    if (check_restart(dhcp) < 0)
        return FALSE;

    dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);

    DBG("renew RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Example #5
0
int main(int argc, char* argv[])
{
	struct timespec delay;
	int i, ret;

	if (argc < 2) {
		g_error("specify file [ file2 file3 .. ]\n");
		return -1;
	}

	pthread_cond_init(&g_cb_cond, NULL);
	pthread_mutex_init(&g_cb_mut, NULL);

	GStreamer_init(NULL);
	GStreamer_regStateCallback(&my_state_callback);

	for (i = 1; i < argc; i++) { 
		ret = GStreamer_setMedia(argv[i]);
		assert(ret == 0);

		do {
			ret = pthread_cond_wait(&g_cb_cond, &g_cb_mut);

			if (my_state == MY_PLAY) {
				delay = calc_delay(3);
				ret = pthread_cond_timedwait(&g_cb_cond, &g_cb_mut, &delay);
				if (ret == ETIMEDOUT)
					break;
			}
		} while (my_state != MY_EOS && my_state != MY_NULL);
		g_printf("GStreamer: asset done\n");

		if (ret == ETIMEDOUT) {
			GStreamer_stop();
			pthread_cond_wait(&g_cb_cond, &g_cb_mut);
		}
	}

	GStreamer_destroy();
	pthread_cond_destroy(&g_cb_cond);
	pthread_mutex_destroy(&g_cb_mut);

	g_printf("GStreamer: exit normally\n");
	return 0;
}
Example #6
0
bool retreiver::ondelay(int count, bool offline) {
	bool ret = false;
	time(&m_now);
	int wait = calc_delay((m_now - m_then), m_nsleeper);
	unsigned long qlen = length();
	if(offline == true) {
		LOG4CXX_INFO("batch = " << m_batch << " count = " << count << " wait = " << wait << "s qlength = " << qlen
				<< " (" << m_goodlevel << "," << m_modpoint << "," << m_overloaded << "," << m_overavg << ")");
	} else {
		LOG4CXX_INFO("batch = " << m_batch << " count = " << count << " wait = " << wait << "s qlength = " << qlen
				<< " (reloaded)");
	}
	m_overavg = ((m_overloaded)*1.0)/(m_batch*1.0);
	if(wait > 0)
		ret = true;
	sleep(wait);
	time(&m_then);
	sched_yield();
	return ret;
}
Example #7
0
static gboolean timeout_request(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    if (dhcp->request_count >= REQ_MAX_RC) {
        DBG("max request retry attempts %d", dhcp->request_count);
        dhcp->request_count = 0;
        if (dhcp->callback != NULL)
            dhcp->callback(dhcp->network, FALSE);
        return FALSE;
    }

    dhcp->request_count++;

    dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
    DBG("request RT timeout %d msec", dhcp->RT);
    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}