コード例 #1
0
ファイル: test_main.c プロジェクト: lundburgerr/workspace
void test_lec(void) {
#if USE_DEBUG_PLOT
	static int iFirstTime = 1;
	int i,j;
	int speechIndex=0;
	bool bUseSpeech = true;
	bool bUseTrueVoice = true;
	t_echo_handler clt_echo_handler;
	t_echo_handler ftn_echo_handler;

	// Initialize time indices
	if(iFirstTime) {
		subband_init();
		plot_init();
		iFirstTime = 0;
		for(i=0; i<(N_RX + N_MIC); i++) {
			uiSineTimeIndex[i] = 0;
		}

		clt_echo_handler = createEchoHandler();
		ftn_echo_handler = createEchoHandler();

		true_voice_clt_mode(1);
		//true_voice_module_enable(LEC, 0);
	}

	short* pMicIn = bUseTrueVoice ? mic.psPilotCable : tx.psCltToLine;
	short* pMicIn2 = bUseTrueVoice ? 0 : tx.psFtnToLine;
	for(j=0; j<7; j++) {
		speechIndex = 0;
		while(speechIndex < TV_PLOT_LENGTH/7) {
		if (bUseSpeech) {
			if (bUseTrueVoice)
			{
				for (i=0; i<BUFLEN_8KHZ; i++){
					if (i+speechIndex<11311 && j != 0){
						pMicIn[i] =maleSpeech[i+speechIndex];
					}
					else{
						pMicIn[i] = 0;
					}
				}
			}
			else
			{
				for (i=0; i<BUFLEN_8KHZ; i++){
					if (i+speechIndex<11311 && j != 0){
						pMicIn[i] =maleSpeech[i+speechIndex];
						pMicIn2[i] =femaleSpeech[i+speechIndex];
					}
					else{
						pMicIn[i] = 0;
						pMicIn2[i] = 0;
					}
				}
			}

		}
		else {
			sin_block(pMicIn, (0+1)*200, &uiSineTimeIndex[0]);
			if (!bUseTrueVoice) sin_block(pMicIn2, (0+1)*200, &uiSineTimeIndex[1]);
			vecmultq15xScalar(pMicIn, pMicIn, (q15)(INT16_MAX*0.99), 15 ,BUFLEN_8KHZ);
			if (!bUseTrueVoice) vecmultq15xScalar(pMicIn2, pMicIn2, (q15)(INT16_MAX*0.99), 15 ,BUFLEN_8KHZ);
		}

		if (bUseTrueVoice) {
			true_voice(rx, mic, tx, ls);
			write_plot_data(rx.psFtn,    &plot6, BUFLEN_8KHZ);
			if (j>=4) {
				create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true, &clt_echo_handler);
				create_echo(tx.psFtnToLine, &femaleSpeech[speechIndex], rx.psFtn, true, &ftn_echo_handler);
			}
			else {
				create_echo(tx.psCltToLine, 0, rx.psClt2wire, false, &clt_echo_handler);
				create_echo(tx.psFtnToLine, 0, rx.psFtn, false, &ftn_echo_handler);
			}

			write_plot_data(rx.psFtn,    &plot4, BUFLEN_8KHZ);
		}
		else {
			if (j>=4) {
				create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true, &clt_echo_handler);
				create_echo(tx.psFtnToLine, &maleSpeech[speechIndex], rx.psFtn, true, &ftn_echo_handler);
			}
			else {
				create_echo(tx.psCltToLine, 0, rx.psClt2wire, false, &clt_echo_handler);
				create_echo(tx.psFtnToLine, 0, rx.psFtn, false, &ftn_echo_handler);
			}

			write_plot_data(rx.psFtn,    &plot4, BUFLEN_8KHZ);

			internal_lec(rx.psClt2wire, tx.psCltToLine, rx.psClt);
			internal_lec_2(rx.psFtn, tx.psFtnToLine, rx.psFtn);

			write_plot_data(rx.psFtn,    &plot6, BUFLEN_8KHZ);
		}

		write_plot_data(rx.psClt2wire,    &plot1, BUFLEN_8KHZ);
		write_plot_data(tx.psCltToLine,    &plot2, BUFLEN_8KHZ);
		write_plot_data(rx.psClt,    &plot3, BUFLEN_8KHZ);

		write_plot_data(tx.psFtnToLine,    &plot5, BUFLEN_8KHZ);

		speechIndex=speechIndex+BUFLEN_8KHZ;
	}
	}
	write_plot_buffer_to_file("lineIn.dat",  &plot1);
	write_plot_buffer_to_file("lineOut.dat",  &plot2);
	write_plot_buffer_to_file("lineInProcessed.dat", &plot3);

	write_plot_buffer_to_file("FtnIn.dat",  &plot4);
	write_plot_buffer_to_file("FtnOut.dat",  &plot5);
	write_plot_buffer_to_file("FtnInProcessed.dat", &plot6);

#endif //USE_DEBUG_PLOT
}
コード例 #2
0
ファイル: echo.c プロジェクト: dmeearm/libuinet
int main (int argc, char **argv)
{
	int ch;
	char *progname = argv[0];
#define MIN_INTERFACES 1
#define MAX_INTERFACES 64
	struct interface_config interfaces[MAX_INTERFACES];
#define MIN_SERVERS 1
#define MAX_SERVERS 64	
	struct server_config servers[MAX_SERVERS];
	int num_interfaces = 0;
	int num_servers = 0;
	int interface_server_count = 0;
	int verbose = 0;
	unsigned int i;
	int error;
	struct uinet_in_addr tmpinaddr;
	int ifnetmap_count = 0;
	int ifpcap_count = 0;

	memset(interfaces, 0, sizeof(interfaces));
	memset(servers, 0, sizeof(servers));

	for (i = 0; i < MAX_INTERFACES; i++) {
		interfaces[i].type = UINET_IFTYPE_NETMAP;
	}

	for (i = 0; i < MAX_SERVERS; i++) {
		servers[i].listen_port = -1;
	}

	while ((ch = getopt(argc, argv, "hi:l:Pp:t:v")) != -1) {
		switch (ch) {
		case 'h':
			usage(progname);
			return (0);
		case 'i':
			if (MAX_INTERFACES == num_interfaces) {
				printf("Maximum number of interfaces is %u\n", MAX_INTERFACES);
				return (1);
			} else {
				interfaces[num_interfaces].ifname = optarg;
				interfaces[num_interfaces].cdom = num_interfaces + 1;
				num_interfaces++;
				interface_server_count = 0;
			}
			break;
		case 'l':
			if (0 == num_interfaces) {
				printf("No interface specified\n");
				return (1);
			} else if (MAX_SERVERS == num_servers) {
				printf("Maximum number of servers is %u\n", MAX_SERVERS);
				return (1);
			} else {
				servers[num_servers].listen_addr = optarg;
				servers[num_servers].interface = &interfaces[num_interfaces - 1];
				num_servers++;
				interface_server_count++;
			}
			break;
		case 'P':
			if (0 == num_interfaces) {
				printf("No interface specified\n");
				return (1);
			} else {
				interfaces[num_interfaces - 1].promisc = 1;
			}
			break;
		case 'p':
			if (0 == interface_server_count) {
				printf("No listen address specified\n");
				return (1);
			} else {
				servers[num_servers - 1].listen_port = strtoul(optarg, NULL, 10);
			}
			break;
		case 't':
			if (0 == num_interfaces) {
				printf("No interface specified\n");
				return (1);
			} else if (0 == strcmp(optarg, "netmap")) {
				interfaces[num_interfaces - 1].type = UINET_IFTYPE_NETMAP;
			} else if (0 == strcmp(optarg, "pcap")) {
				interfaces[num_interfaces - 1].type = UINET_IFTYPE_PCAP;
			} else {
				printf("Unknown interface type %s\n", optarg);
				return (1);
			}
			break;
		case 'v':
			verbose++;
			break;
		default:
			printf("Unknown option \"%c\"\n", ch);
		case '?':
			usage(progname);
			return (1);
		}
	}
	argc -= optind;
	argv += optind;

	if (num_interfaces < MIN_INTERFACES) {
		printf("Specify at least %u interface%s\n", MIN_INTERFACES, MIN_INTERFACES == 1 ? "" : "s");
		return (1);
	}

	if (num_servers < MIN_SERVERS) {
		printf("Specify at least %u listen address%s\n", MIN_SERVERS, MIN_SERVERS == 1 ? "" : "es");
		return (1);
	}

	for (i = 0; i < num_servers; i++) {
		if (-1 == servers[i].listen_port) {
			printf("No listen port specified for interface %s, listen address %s\n",
			       servers[i].interface->ifname, servers[i].listen_addr);
			return (1);
		}

		if (servers[i].listen_port < 0 || servers[i].listen_port > 65535) {
			printf("Listen port for interface %s, listen address %s is out of range [0, 65535]\n",
			       servers[i].interface->ifname, servers[i].listen_addr);
			return (1);
		}

		if (0 == servers[i].listen_port)
			servers[i].interface->promisc = 1;

		if (uinet_inet_pton(UINET_AF_INET, servers[i].listen_addr, &tmpinaddr) <= 0) {
			printf("%s is not a valid listen address\n", servers[i].listen_addr);
			return (1);
		}

		if (tmpinaddr.s_addr == UINET_INADDR_ANY) {
			servers[i].addrany = 1;
			servers[i].interface->promisc = 1;
		}
	}
	
	
	uinet_init(1, 128*1024, 0);

	for (i = 0; i < num_interfaces; i++) {
		switch (interfaces[i].type) {
		case UINET_IFTYPE_NETMAP:
			interfaces[i].alias_prefix = "netmap";
			interfaces[i].instance = ifnetmap_count;
			ifnetmap_count++;
			break;
		case UINET_IFTYPE_PCAP:
			interfaces[i].alias_prefix = "pcap";
			interfaces[i].instance = ifpcap_count;
			ifpcap_count++;
			break;
		default:
			printf("Unknown interface type %d\n", interfaces[i].type);
			return (1);
			break;
		}

		snprintf(interfaces[i].alias, UINET_IF_NAMESIZE, "%s%d", interfaces[i].alias_prefix, interfaces[i].instance);

		if (verbose) {
			printf("Creating interface %s, Promiscuous INET %s, cdom=%u\n",
			       interfaces[i].alias, interfaces[i].promisc ? "enabled" : "disabled",
			       interfaces[i].promisc ? interfaces[i].cdom : 0);
		}

		error = uinet_ifcreate(interfaces[i].type, interfaces[i].ifname, interfaces[i].alias,
				       interfaces[i].promisc ? interfaces[i].cdom : 0,
				       0, NULL);
		if (0 != error) {
			printf("Failed to create interface %s (%d)\n", interfaces[i].alias, error);
		}

		interfaces[i].loop = ev_loop_new(EVFLAG_AUTO);
		if (NULL == interfaces[i].loop) {
			printf("Failed to create event loop interface %s\n", interfaces[i].alias);
			break;
		}
		
	}
	
	for (i = 0; i < num_servers; i++) {
		if (!servers[i].addrany) {
			if (verbose) {
				printf("Adding address %s to interface %s\n", servers[i].listen_addr, servers[i].interface->alias);
			}
			
			error = uinet_interface_add_alias(servers[i].interface->alias, servers[i].listen_addr, "", "");
			if (error) {
				printf("Adding alias %s to interface %s failed (%d)\n", servers[i].listen_addr, servers[i].interface->alias, error);
			}
		}
	}

	for (i = 0; i < num_servers; i++) {
		if (verbose) {
			printf("Creating echo server at %s:%d on interface %s\n",
			       servers[i].listen_addr, servers[i].listen_port,
			       servers[i].interface->alias);
		}

		servers[i].verbose = verbose;

		servers[i].echo = create_echo(servers[i].interface->loop, &servers[i]);
		if (NULL == servers[i].echo) {
			printf("Failed to create echo server at %s:%d on interface %s\n",
			       servers[i].listen_addr, servers[i].listen_port,
			       servers[i].interface->alias);
			break;
		}
	}

	for (i = 0; i < num_interfaces; i++) {
		if (verbose) {
			printf("Bringing up interface %s\n", interfaces[i].alias);
		}

		error = uinet_interface_up(interfaces[i].alias, 1, interfaces[i].promisc);
		if (0 != error) {
			printf("Failed to bring up interface %s (%d)\n", interfaces[i].alias, error);
		}

		if (verbose)
			printf("Creating interface thread for interface %s\n", interfaces[i].alias);

		interfaces[i].thread_create_result = pthread_create(&interfaces[i].thread, NULL,
								    interface_thread_start, &interfaces[i]);
	}

	for (i = 0; i < num_interfaces; i++) {
		if (0 == interfaces[i].thread_create_result)
			pthread_join(interfaces[i].thread, NULL);
	}

	for (i = 0; i < num_interfaces; i++) {
		uinet_ifdestroy_byname(interfaces[i].ifname);
	}

	return (0);
}
コード例 #3
0
ファイル: test_main.c プロジェクト: lundburgerr/workspace
void test_all_lec(void) {
#if USE_DEBUG_PLOT
	static int iFirstTime = 1;
	int i,j,k;
	int speechIndex=0;
	t_echo_handler clt_echo_handler;
	t_echo_handler ftn_echo_handler;
	t_echo_handler pilot_echo_handler;

	// Initialize time indices
	if(iFirstTime) {
		subband_init();
		plot_init();
		iFirstTime = 0;
		for(i=0; i<(N_RX + N_MIC); i++) {
			uiSineTimeIndex[i] = 0;
		}

		clt_echo_handler = createEchoHandler();
		ftn_echo_handler = createEchoHandler();
		pilot_echo_handler = createEchoHandler();

		//true_voice_module_enable(AGC, 0);
		//true_voice_module_enable(LS_LIMITER, 0);
		//true_voice_module_enable(NOISE_REDUCTION, 0);
		//true_voice_module_enable(LEC, 0);

		true_voice_module_enable(LEC, 1);
		true_voice_clt_mode(1);
	}

	for (j=0; j<2; j++) {
		memset(mic.psPilotCltCable,0,sizeof(short)*BUFLEN_8KHZ);
		memset(mic.psPilotCable,0,sizeof(short)*BUFLEN_8KHZ);
		memset(mic.psTechHeadset,0,sizeof(short)*BUFLEN_8KHZ);

		short* pMicIn = j==0 ? mic.psPilotCltCable : mic.psPilotCable;
		short* pMicIn2 = mic.psTechHeadset;

		for(i=0; i<7; i++) {
			speechIndex = 0;
			while(speechIndex < TV_PLOT_LENGTH/(2*7)) {
				for (k=0; k<BUFLEN_8KHZ; k++){
					if (k+speechIndex<11311 && i != 0){
						pMicIn[k] = j==0 ? maleSpeech[k+speechIndex] : femaleSpeech[k+speechIndex];
						pMicIn2[k] =femaleSpeech[k+speechIndex];
					}
					else{
						pMicIn[k] = 0;
						pMicIn2[k] = 0;
					}
				}

				if (i>=4) {
					create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true, &clt_echo_handler);
					create_echo(tx.psFtnToLine, &maleSpeech[speechIndex], rx.psFtn, true, &ftn_echo_handler);
					if (j==1) {
						short temp[BUFLEN_8KHZ];
						memcpy(temp, mic.psPilotCable, sizeof(short)*BUFLEN_8KHZ);
						create_echo(ls.psPilotMonoCable, temp, mic.psPilotCable, true, &pilot_echo_handler);
					}
				}
				else {
					create_echo(tx.psCltToLine, 0, rx.psClt2wire, false, &clt_echo_handler);
					create_echo(tx.psFtnToLine, 0, rx.psFtn, false, &ftn_echo_handler);
					if (j==1) {
						short temp[BUFLEN_8KHZ];
						memcpy(temp, mic.psPilotCable, sizeof(short)*BUFLEN_8KHZ);
						create_echo(ls.psPilotMonoCable, temp, mic.psPilotCable, true, &pilot_echo_handler);
					}
				}

				write_plot_data(rx.psFtn,    &plot5, BUFLEN_8KHZ);

				write_plot_data(ls.psPilotMonoCable,    &plot7, BUFLEN_8KHZ);
				write_plot_data(mic.psPilotCable,    &plot8, BUFLEN_8KHZ);

				true_voice(rx, mic, tx, ls);

				write_plot_data(mic.psPilotCltCable,    &plot1, BUFLEN_8KHZ);
				write_plot_data(rx.psClt2wire,    &plot2, BUFLEN_8KHZ);
				write_plot_data(rx.psClt,    &plot3, BUFLEN_8KHZ);

				write_plot_data(mic.psTechHeadset,    &plot4, BUFLEN_8KHZ);
				write_plot_data(rx.psFtn,    &plot6, BUFLEN_8KHZ);

				write_plot_data(mic.psPilotCable,    &plot9, BUFLEN_8KHZ);

				speechIndex=speechIndex+BUFLEN_8KHZ;
			}
		}
	}

	write_plot_buffer_to_file("lineIn.dat",  &plot1);
	write_plot_buffer_to_file("lineOut.dat",  &plot2);
	write_plot_buffer_to_file("lineInProcessed.dat", &plot3);

	write_plot_buffer_to_file("FtnIn.dat",  &plot4);
	write_plot_buffer_to_file("FtnOut.dat",  &plot5);
	write_plot_buffer_to_file("FtnInProcessed.dat", &plot6);

	write_plot_buffer_to_file("PilotIn.dat",  &plot7);
	write_plot_buffer_to_file("PilotOut.dat",  &plot8);
	write_plot_buffer_to_file("PilotInProcessed.dat", &plot9);

#endif //USE_DEBUG_PLOT
}
コード例 #4
0
ファイル: test_main.c プロジェクト: lundburgerr/workspace
void test_lec(void) {
#if USE_DEBUG_PLOT
	static int iFirstTime = 1;
	int i,j;
	int speechIndex=0;
	bool bUseSpeech = true;
	bool bUseTrueVoice = false;

	// Initialize time indices
	if(iFirstTime) {
		subband_init();
		plot_init();
		iFirstTime = 0;
		for(i=0; i<(N_RX + N_MIC); i++) {
			uiSineTimeIndex[i] = 0;
		}
	}

	short* pMicIn = bUseTrueVoice ? mic.psPilotCable : tx.psCltToLine;
	for(j=0; j<7; j++) {
		speechIndex = 0;
		while(speechIndex < TV_PLOT_LENGTH/7) {
		if (bUseSpeech) {
			for (i=0; i<BUFLEN_8KHZ; i++){
					if (i+speechIndex<11311 && j != 0){
					pMicIn[i] =maleSpeech[i+speechIndex];
				}
				else{
					pMicIn[i] = 0;
				}
			}

		}
		else {
			sin_block(pMicIn, (0+1)*200, &uiSineTimeIndex[0]);
			vecmultq15xScalar(pMicIn, pMicIn, (q15)(INT16_MAX*0.99), 15 ,BUFLEN_8KHZ);
		}

		if (bUseTrueVoice) {
			true_voice(rx, mic, tx, ls);
			if (j>=4) {
				create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true);
			}
			else {
				create_echo(tx.psCltToLine, 0, rx.psClt2wire, false);
			}
		}
		else {
			if (j>=4) {
				create_echo(tx.psCltToLine, &femaleSpeech[speechIndex], rx.psClt2wire, true);
			}
			else {
				create_echo(tx.psCltToLine, 0, rx.psClt2wire, false);
			}

//			clock_t t_start, t_stop, t_overhead;
//			t_start = clock();
//			t_stop = clock();
//			t_overhead = t_stop - t_start;
//			t_start = clock();

			internal_lec(rx.psClt2wire, tx.psCltToLine, rx.psClt);

//			t_stop  = clock();
//			printf("LEC took: %f ms\n", (t_stop-t_start-t_overhead)/300E6*1000); //Enable clock first while in debug: Run->Clock->Enable
		}

		write_plot_data(rx.psClt2wire,    &plot1, BUFLEN_8KHZ);
		write_plot_data(tx.psCltToLine,    &plot2, BUFLEN_8KHZ);
		write_plot_data(rx.psClt,    &plot3, BUFLEN_8KHZ);

		speechIndex=speechIndex+BUFLEN_8KHZ;
	}
	}
	write_plot_buffer_to_file("lineIn.dat",  &plot1);
	write_plot_buffer_to_file("lineOut.dat",  &plot2);
	write_plot_buffer_to_file("lineInProcessed.dat", &plot3);

#endif //USE_DEBUG_PLOT
}