Exemple #1
0
void radio_init(void)
{
    tuner_init();
    radio_off();
#ifdef HAVE_ALBUMART
    radioart_init(false);
#endif
}
Exemple #2
0
int tune_single_tuner_and_demod_channel(struct dibTuner *tuner, struct dibDemod *demod, struct dibChannel *ch)
{
    int time, ret;

    if (demod_init(demod) != 0) {
        DibDbgPrint("-E-  Demod init failed\n");
        return 1;
    }
    
    if (tuner_init(tuner) != 0) {
        DibDbgPrint("-E-  Tuner init failed\n");
        return 1;
    }

    if (tuner_set_bandwidth_ex(tuner, ch) != 0) {
        DibDbgPrint("-E-  Tuner set_bandwidth failed\n");
        return 1;
    }

    if (tuner_tune(tuner, ch) != 0) {
        DibDbgPrint("-E-  Tuner tune_digital failed\n");
        return 1;
    }

    /* prepare the agc startup loop */
    demod_agc_restart(demod);

    do {
        time = -1;

        ret = demod_agc_startup_ex(demod, ch);
        if (ret > time)
            time = ret;

        if (time != -1)
            DibMSleep(time);
    } while (time != -1);

    if ((ch->type == STANDARD_DVBT && (ch->u.dvbt.nfft == FFT_AUTO || ch->u.dvbt.guard == GUARD_INTERVAL_AUTO || ch->u.dvbt.constellation == QAM_AUTO ||
        ch->u.dvbt.intlv_native == INTLV_NATIVE_AUTO || ch->u.dvbt.hrch == VIT_HRCH_AUTO || ch->u.dvbt.select_hp == VIT_PRIORITY_AUTO ||
        ch->u.dvbt.alpha == VIT_ALPHA_AUTO || ch->u.dvbt.code_rate_hp == VIT_CODERATE_AUTO ||
        ((ch->u.dvbt.hrch == VIT_HRCH_ON && ch->u.dvbt.code_rate_lp == VIT_CODERATE_AUTO)))) ||
        ((ch->type == STANDARD_ISDBT) && (ch->u.isdbt.nfft == FFT_AUTO || ch->u.isdbt.guard == GUARD_INTERVAL_AUTO)))
        if (single_do_autosearch(demod, ch) != 0) {
            DibDbgPrint("-W-  autosearching parameters failed.\n");
            return 1;
        }

    dump_dvb_channel_params(ch);

    if (demod_tune_ex(demod,ch) != 0){
        DibDbgPrint("-W-  tuning failed for demod - this is just a warning could be normal in diversity.\n");
        return 1;
    }

    return 0;
}
Exemple #3
0
Fichier : app.c Projet : FoxVK/DFMT
inline void app_init()
{
    debug_uart_init();
    static char * run = "\n\rReseted\n\r";
    debug_uart_write(run);
    
    tuner_init();
    tuner_audio_init();
    tuner_control_pwr(true);

    config.event_callback = usb_event;
    config.ct_request_callback = &app_usb_ct_handler;
    usb_init(&config);

    static Usb_audio_iface uai;
    audio_if = &uai;
    usb_audio_init(audio_if, 1, NULL);
    Usb_audio_add_ep(audio_if, USB_EP01, USB_EP_IN, app_usb_audio_td0_handler);   
    
    tunnel_init();
    
    static char *initd = "init done\n\r";  
    debug_uart_write(initd);
}
Exemple #4
0
void APP_Initialize ( void )
{
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;
    
    appData.suspended = false;
    appData.tuner_ready = 0;

    appData.usbDevHandle = -1;
    appData.audio_play = false;
    appData.noAudioData = 1;
    appData.reading = 0;
    appData.pingRequest = 0;
    appData.tuner_request = 0;
    appData.tuner_wait_for_reply = 0;

    appData.tunnel_write_handle = USB_DEVICE_TRANSFER_HANDLE_INVALID;

    int i = 0;
    for(;i<AUDIO_HANDLES;i++)
        audio_handle[i]=HANDLE_INVALID;

    tuner_init();
}
int main(int argc, char **argv)
{
	sp_session *sp;
	sp_error err;
	int next_timeout = 0;
	const char *username = NULL;
	const char *password = NULL;
	const char *serialdevice = NULL;
	int opt;

	mtrace();

	while ((opt = getopt(argc, argv, "u:p:s:")) != EOF) {
		switch (opt) {
		case 'u':
			username = optarg;
			break;

		case 'p':
			password = optarg;
			break;

		case 's':
			serialdevice = optarg;
			break;

		default:
			exit(1);
		}
	}

	if (!username || !password) {
		usage(basename(argv[0]));
		exit(1);
	}

	srand(time(NULL));

	audio_fifo_reset(&g_musicfifo);
	audio_fifo_reset(&g_gaplessfifo);
	audio_fifo_reset(&g_staticfifo1);
	audio_fifo_reset(&g_staticfifo2);
	audio_fifo_reset(&g_audiofifo);
	
	printf("music fifo: %X\n", &g_musicfifo);
	printf("gapless fifo: %X\n", &g_gaplessfifo);
	printf("static1 fifo: %X\n", &g_staticfifo1);
	printf("static2 fifo: %X\n", &g_staticfifo2);
	printf("audio fifo: %X\n", &g_audiofifo);

	hardware_start(serialdevice);

	hardware_banner("welcome.", 200);
	hardware_set_callback(_hardware_event);

	g_static1 = static_init(BROWN_NOISE, "static1.raw");
	g_static2 = static_init(PINK_NOISE, "static2.raw");
	g_static3 = static_init(WHITE_NOISE, "static3.raw");

	g_tuner = tuner_init();
	tuner_addchannel(g_tuner, 130 + rand()%100, "Channel 1", "spotify:user:possan:playlist:4g17smZvFZqg4dN74XMBYH");
	tuner_addchannel(g_tuner, 410 + rand()%100, "Channel 2", "spotify:user:possan:playlist:2BBVnBjG4Cynww1mnjfV0v");
	tuner_addchannel(g_tuner, 700 + rand()%100, "Channel 3", "spotify:user:possan:playlist:72weZVptgKfYFyzafxBdO5");
	tuner_goto(g_tuner, rand() % tuner_numchannels(g_tuner));
	tuner_tune_by(g_tuner, -70 + rand()%150);

	printf("Start loop...\n");

	spconfig.application_key_size = g_appkey_size;

	audio_init(&g_audiofifo);
	// audio_init(&g_gaplessfifo);

	err = sp_session_create(&spconfig, &sp);

	if (SP_ERROR_OK != err) {
		fprintf(stderr, "Unable to create session: %s\n", sp_error_message(err));
		exit(1);
	}

	g_sess = sp;

	pthread_mutex_init(&g_notify_mutex, NULL);
	pthread_cond_init(&g_notify_cond, NULL);

	sp_session_login(sp, username, password, 0, NULL);
	pthread_mutex_lock(&g_notify_mutex);

	static pthread_t id;
	pthread_create(&id, NULL, inputloop, NULL);

	static pthread_t id2;
	pthread_create(&id2, NULL, gaplessloop, NULL);

	static pthread_t id3;
	pthread_create(&id3, NULL, static1loop, NULL);

	static pthread_t id4;
	pthread_create(&id4, NULL, static2loop, NULL);

	static pthread_t id5;
	pthread_create(&id5, NULL, static3loop, NULL);

	for (;;) {
		// printf("In loop\n");
		if (next_timeout == 0) {
			while(!g_notify_do) {
				pthread_cond_wait(&g_notify_cond, &g_notify_mutex);
			}
		} else {
			struct timespec ts;

#if _POSIX_TIMERS > 0
			clock_gettime(CLOCK_REALTIME, &ts);
#else
			struct timeval tv;
			gettimeofday(&tv, NULL);
			TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif
			ts.tv_sec += next_timeout / 1000;
			ts.tv_nsec += (next_timeout % 1000) * 1000000;
			pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		}

		g_notify_do = 0;
		pthread_mutex_unlock(&g_notify_mutex);

		if (g_playback_done) {
			track_ended(1);
			g_playback_done = 0;
		}

		do {
			sp_session_process_events(sp, &next_timeout);
		} while (next_timeout == 0);

		pthread_mutex_lock(&g_notify_mutex);
	}

	return 0;
}
Exemple #6
0
LOWERCODESIZE void tuner_tuneSynth(void)
{
	int8_t i;
	
	BLOCK_INT
	{
		// reinit tuner
		
		tuner_init();
		
		// prepare synth for tuning
		
		prepareSynth();
		
		// tune oscs
			
			// init
		
		sh_setCV(pcResonance,0,0);
		for(i=0;i<SYNTH_VOICE_COUNT;++i)
		{
			sh_setCV(pcAmp1+i,0,0);
			sh_setCV(pcFil1+i,UINT16_MAX,0);
		}
	
			// A oscs

		sh_setGate(pgASaw,1);

		sh_setCV(pcVolA,UINT16_MAX,0);
		sh_setCV(pcVolB,0,0);

		for(i=0;i<SYNTH_VOICE_COUNT;++i)
			tuneCV(pcOsc1A+i,pcAmp1+i);

		sh_setGate(pgASaw,0);
		
			// B oscs

		sh_setGate(pgBSaw,1);

		sh_setCV(pcVolA,0,0);
		sh_setCV(pcVolB,UINT16_MAX,0);

		for(i=0;i<SYNTH_VOICE_COUNT;++i)
			tuneCV(pcOsc1B+i,pcAmp1+i);

		sh_setGate(pgBSaw,0);

		// tune filters
			
			// init
		
		sh_setCV(pcVolA,0,0);
		sh_setCV(pcVolB,0,0);
		sh_setCV(pcResonance,UINT16_MAX,0);

		for(i=0;i<SYNTH_VOICE_COUNT;++i)
			sh_setCV(pcFil1+i,0,0);
	
			// filters
		
		for(i=0;i<SYNTH_VOICE_COUNT;++i)
			tuneCV(pcFil1+i,pcAmp1+i);

		// finish
		
		sh_setCV(pcResonance,0,0);
		for(i=0;i<SYNTH_VOICE_COUNT;++i)
			sh_setCV(pcAmp1+i,0,0);
		
		sh_update();

		display_clear();
		
		settings_save();
	}
}
Exemple #7
0
/* tune (do autosearch in case of unknown parameters) */
void tune_diversity_tuner_and_demod_channel(struct dibTuner *tuner[], struct dibDemod *demod[], int num, struct dibChannel *ch)
{
    int i, time, ret;

    for (i = 0; i < num; i++) {
        if (demod_init(demod[i]) != 0) {
            DibDbgPrint("-E-  Tuner init failed\n");
            return;
        }
        if (tuner_init(tuner[i]) != 0) {
            DibDbgPrint("-E-  Tuner init failed\n");
            return;
        }
    }

    for (i = 0; i < num; i++) {
        if (tuner_set_bandwidth_ex(tuner[i], ch) != 0) {
            DibDbgPrint("-E-  Tuner set_bandwidth failed\n");
            return;
        }

        if (tuner_tune(tuner[i], ch) != 0) {
            DibDbgPrint("-E-  Tuner tune_digital failed\n");
            return;
        }

        /* prepare the agc startup loop */
        demod_agc_restart(demod[i]);
    }

    do {
        time = -1;
        for (i = 0; i < num; i++) {
            ret = demod_agc_startup_ex(demod[i], ch);
            if (ret > time)
                time = ret;
        }
        if (time != -1)
            DibMSleep(time);
    } while (time != -1);

    if ((ch->type == STANDARD_DVBT && (ch->u.dvbt.nfft == FFT_AUTO || ch->u.dvbt.guard == GUARD_INTERVAL_AUTO || ch->u.dvbt.constellation == QAM_AUTO ||
                                       ch->u.dvbt.intlv_native == INTLV_NATIVE_AUTO || ch->u.dvbt.hrch == VIT_HRCH_AUTO || ch->u.dvbt.select_hp == VIT_PRIORITY_AUTO ||
                                       ch->u.dvbt.alpha == VIT_ALPHA_AUTO || ch->u.dvbt.code_rate_hp == VIT_CODERATE_AUTO ||
                                       ((ch->u.dvbt.hrch == VIT_HRCH_ON && ch->u.dvbt.code_rate_lp == VIT_CODERATE_AUTO)))))
        if (do_autosearch(demod, num, ch) != 0) {
            DibDbgPrint("-W-  autosearching parameters failed.\n");
            return;
        }

    dump_dvb_channel_params(ch);

    for (i = 0; i < num; i++) {
        if (demod_tune_ex(demod[i],ch) != 0)
            DibDbgPrint("-W-  tuning failed for demod - this is just a warning could be normal in diversity.\n");
    }

    for (i = 0; i < num; i++) {
        if (i == num-1) { // last demod in a diversity chain - turn off div-in combination
            DibDbgPrint("-D-  setting diversity in off for demod %d\n",i);
            demod_set_diversity_in(demod[i], 0);
        } else {
            DibDbgPrint("-D-  setting diversity in on  for demod %d\n",i);
            demod_set_diversity_in(demod[i], 1);
        }

        if (i == 0) { // first demod in a diversity chain - no diversity output
            DibDbgPrint("-D-  setting normal output for demod %d\n",i);
            demod_set_output_mode(demod[i], OUTMODE_MPEG2_PAR_GATED_CLK);
        } else {
            DibDbgPrint("-D-  setting diversity out on for demod %d\n",i);
            demod_set_output_mode(demod[i], OUTMODE_DIVERSITY);
        }
    }
    return;
}
uint16_t frontend_get_isdbt_sb_channels(struct dibFrontend *fe[], uint32_t freq , uint32_t bw, int num, struct dibChannel ch[])
{
    uint16_t seg_bw_khz = 429;
    int16_t rf_offset_khz = 0;
    uint16_t total_segment_number = (uint16_t)((bw / seg_bw_khz) - 1); // 1 is the freq guard
    int segment_index = 0, channel_index = 0, subch_id = -1;
    int i;

    dbgpl(NULL, "will search SB on %d potential segment(s) inside a bandwidth of %dkhz arround FR freq %dkhz", total_segment_number, bw, freq);

    for (i = 0; i < num; i++) {
        if (demod_init(fe[i]) != 0) {
            DibDbgPrint("-E-  Tuner init failed\n");
            return 0;
        }
        if (tuner_init(fe[i]) != 0) {
            DibDbgPrint("-E-  Tuner init failed\n");
            return 0;
        }
    }

    for (segment_index = 1; segment_index <= total_segment_number; segment_index++) {
        int success, fe_fail_count;

        channel_init(&ch[channel_index], STANDARD_ISDBT);

        /* compute segment center freq */
        rf_offset_khz = seg_bw_khz * (segment_index - (total_segment_number/2) - (total_segment_number%2));
        dbgpl(NULL,"rf_offset_khz = %d",rf_offset_khz);
        /* add a half of seg BW offset is total number of connected seg is even */
        if((total_segment_number%2) == 0) {
            dbgpl(NULL,"compensate for 1/2 seg (%d khz) tune freq because sb_conn_total_seg is even = %d",seg_bw_khz, total_segment_number);
            rf_offset_khz-=(seg_bw_khz/2);
        }
        dbgpl(NULL,"rf_offset_khz = %d",rf_offset_khz);

        ch[channel_index].RF_kHz = freq + rf_offset_khz;
        ch[channel_index].bandwidth_kHz = bw;
        ch[channel_index].u.isdbt.sb_mode = 1;

        if (subch_id != -1)
            subch_id += 3;

        ch[channel_index].u.isdbt.sb_subchannel = subch_id;

        dbgpl(NULL,"---------------------- Start search on segment #%d center freq = %dkhz (%d+%d, %d)--------------------- ",
                segment_index,ch[channel_index].RF_kHz, freq, rf_offset_khz, subch_id);

        for (i = 0; i < num; i++)
            frontend_tune_restart(fe[i], FE_RESTART_TUNE_PROCESS_FROM_TUNER, &ch[channel_index]);

        do {
            success = 0;
            fe_fail_count = 0;
            for (i = 0; i < num; i++) {
                frontend_tune(fe[i], &ch[channel_index]);

                if (fe[i]->status_has_changed && (frontend_get_status(fe[i]) == FE_STATUS_DEMOD_SUCCESS || frontend_get_status(fe[i]) == FE_STATUS_FFT_SUCCESS)) {
                    //dbgpl(&adapter_dbg, "Autosearch succeeded on FE %d", fe[i]->id);

                    frontend_get_channel(fe[i], &ch[channel_index]); /* we read the channel parameters from the frontend which was successful */

                    if (ch[channel_index].u.isdbt.partial_reception == 1) {
                        ch[channel_index].bandwidth_kHz = seg_bw_khz * 3; /* bandwidth is for 3 segments */
                        segment_index++; /* no need to check the next segment */
                    } else
                        ch[channel_index].bandwidth_kHz = seg_bw_khz;

#ifdef DIBCOM_EXTENDED_MONITORING
                        dump_digital_channel_params(&ch[channel_index]);
#endif
                }

                if (frontend_get_status(fe[i]) == FE_STATUS_LOCKED) {
                    subch_id = ch[channel_index].u.isdbt.sb_subchannel;
                    channel_index++;
                    success = 1;
                    break;
                } else if(frontend_get_status(fe[i]) == FE_STATUS_TUNE_FAILED) {
                    fe_fail_count++;

                }
            }
        } while (!success && fe_fail_count != num);

        if (success)
            DibDbgPrint("-I-  Autosearch succeeded for demod %d channel_index = %d - done.\n",i, channel_index);
        else
            DibDbgPrint("-I-  Autosearch failled for demod %d channel_index = %d - done. %d/%d\n",i, channel_index, fe_fail_count, num);
     }

    return channel_index;
}