Add files via upload

master
Wojciech Kaczmarski 2020-08-30 10:14:23 +02:00 committed by GitHub
parent 4e46f713d0
commit ec501f3170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# Project: codec2 # Project: M17_UDP_listener
CPP = g++ CPP = g++
CC = gcc CC = gcc
@ -8,7 +8,7 @@ LINKOBJ = main.o codebook.o codebookd.o codebookdt.o codebookge.o codebookjvm.o
LIBS = -static-libgcc -lm LIBS = -static-libgcc -lm
INCS = INCS =
CXXINCS = CXXINCS =
BIN = m17_udp BIN = m17_udp_listener
CXXFLAGS = $(CXXINCS) -march=native -msse3 -O2 -std=gnu99 CXXFLAGS = $(CXXINCS) -march=native -msse3 -O2 -std=gnu99
CFLAGS = $(INCS) -march=native -msse3 -O2 -std=gnu99 CFLAGS = $(INCS) -march=native -msse3 -O2 -std=gnu99
RM = rm -f RM = rm -f

31
main.c
View File

@ -13,10 +13,10 @@
#include "codec2.h" #include "codec2.h"
//port //port
#define PORT 7777 uint16_t port_num=17000; //default port
//UDP packet //UDP packet
uint8_t bits[32]; uint8_t bits[40];
//for reconstructed speech samples, 2x160 (2x20ms) //for reconstructed speech samples, 2x160 (2x20ms)
uint16_t speech_buff[320]; uint16_t speech_buff[320];
@ -33,9 +33,19 @@ int s, i, slen = sizeof(si_other) , rcv_len;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(argc==2)
{
port_num=atoi(argv[1]);
}
else
{
fprintf(stderr, "Not enough args\n");
return 1;
}
//init //init
cod = codec2_create(CODEC2_MODE_3200); cod = codec2_create(CODEC2_MODE_3200);
memset(bits, 0, 16); memset(bits, 0, 40);
memset(speech_buff, 0, 320); memset(speech_buff, 0, 320);
s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@ -49,24 +59,25 @@ int main(int argc, char *argv[])
memset((char*)&si_me, 0, sizeof(si_me)); memset((char*)&si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET; si_me.sin_family = AF_INET;
si_me.sin_port = htons(PORT); si_me.sin_port = htons(port_num);
si_me.sin_addr.s_addr = htonl(INADDR_ANY); si_me.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(s, (struct sockaddr*)&si_me, sizeof(si_me))==-1) if(bind(s, (struct sockaddr*)&si_me, sizeof(si_me))==-1)
{ {
return 1; return 1;
} }
while(1) while(1)
{ {
//receive packet via UDP //receive packet via UDP
if((rcv_len=recvfrom(s, bits, 32, 0, (struct sockaddr*)&si_other, &slen))==-1) if((rcv_len=recvfrom(s, bits, 40, 0, (struct sockaddr*)&si_other, &slen))==-1)
{ {
return 1; return 1;
} }
if(rcv_len==16) if(rcv_len==34)
{ {/*
//reconstruct speech //reconstruct speech
codec2_decode(cod, &speech_buff[0], &bits[0]); codec2_decode(cod, &speech_buff[0], &bits[0]);
codec2_decode(cod, &speech_buff[160], &bits[8]); codec2_decode(cod, &speech_buff[160], &bits[8]);
@ -83,6 +94,12 @@ int main(int argc, char *argv[])
/*fp=fopen("out.raw", "a"); /*fp=fopen("out.raw", "a");
fwrite(speech_buff, 2, 160, fp); fwrite(speech_buff, 2, 160, fp);
fclose(fp);*/ fclose(fp);*/
printf("Frame recv'd!\n");
}
else if(rcv_len==40)
{
printf("LICH recv'd!\n");
} }
} }