1. Install source code on Github
https://github.com/TeddyWiz/pico_audio_streaming_Test.git
2. Connect the device to the mic module.
- pin map
pico 3v3 - mic VDD
pico GND - mic GND
pico GPIO26_A0 - mic OUT
3. ADC setting
- Define data
Adc clock setting value is 5999.
adc sampling rate = 48Mhz /(1+ 5999) = 8kS/s.
#define ADC_NUM 0
#define ADC_PIN (26 + ADC_NUM)
#define ADC_VREF 3.3
#define ADC_RANGE (1 << 12)
#define ADC_CONVERT (ADC_VREF / (ADC_RANGE - 1))
#define ADC_CLK_VAL 5999//5999=8kS/s
- ADC Initialize
//adc init
bi_decl(bi_program_description("Analog microphone example for Raspberry Pi Pico")); // for picotool
bi_decl(bi_1pin_with_name(ADC_PIN, "ADC input pin"));
sleep_ms(1000);
printf("Starting Program\n");
adc_init();
adc_gpio_init( ADC_PIN);
adc_select_input( ADC_NUM);
//sleep_ms(1000);
printf("Ready ADC Program\n");
//adc fifo
adc_fifo_setup(
true, // Write each completed conversion to the sample FIFO
true, // Enable DMA data request (DREQ)
1, // DREQ (and IRQ) asserted when at least 1 sample present
true, // We won't see the ERR bit because of 8 bit reads; disable.
false // Shift each sample to 8 bits when pushing to FIFO
);
adc_set_clkdiv(ADC_CLK_VAL);//2999= 16kS/s (1+999)/48Mhz = 48kS/s 199=240kS/s 239=200kS/s 1087=44118S/s
sleep_ms(1000);
printf("Starting capture\n");
adc_run(true);
4. RTC setting
RTC was set because time data was required in RTP packets.
datetime_t t = {
.year = 2022,
.month = 05,
.day = 24,
.dotw = 5, // 0 is Sunday, so 5 is Friday
.hour = 11,
.min = 40,
.sec = 00
};
// Start the RTC
rtc_init();
rtc_set_datetime(&t);
5. Ethernet setting
- set parameter
#define TCP_S_SOCKET 0
#define TCP_S_PORT 20000
#define UDP_SOCKET 1
#define UDP_PORT 30000
#define UDP_SPORT 30002
#define TCP_C_SOCKET 2
static wiz_NetInfo g_net_info =
{
.mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x68}, // MAC address
.ip = {192, 168, 15, 125}, // IP address
.sn = {255, 255, 255, 0}, // Subnet Mask
.gw = {192, 168, 0, 1}, // Gateway
.dns = {8, 8, 8, 8}, // DNS server
#ifdef _DHCP
.dhcp = NETINFO_DHCP // DHCP enable/disable
#else
// this example uses static IP
.dhcp = NETINFO_STATIC
#endif
};
uint8_t UDP_BroadIP[4] = {255,255,255,255};
uint8_t UDP_TestIP[4] = {192,168,15,2};
uint16_t udp_send_port = 30001;
You must set "define _DHCP" to use DHCP.
#define _DHCP
- Init function
wizchip_spi_initialize();
wizchip_cris_initialize();
wizchip_reset();
wizchip_initialize();
wizchip_check();
wizchip_1ms_timer_initialize(repeating_timer_callback);
5. SDP & RTP
- fill the parameter
SDP_Data session_data;
session_data.from_data.display_info = "wiznet";
session_data.from_data.user_part = 0x3796CB71;
session_data.from_data.host_part = "sip.wiznet.io";
session_data.from_data.tag = 0xb56e6e;
session_data.to_data.user_part = 0x35104723;
session_data.to_data.host_part = "sip.wiznet.io";
session_data.method = "INVITE";
session_data.branch = "z9hG4bKnp10144774-4725f980";
session_data.rport = "rport";
session_data.call_ID = "11894297-4432a9f8";
session_data.cseq = 1;
session_data.content_type = "application/sdp";
//session_data.content_length = 270;
session_data.date = "WED 25 May 2022 10:54:25 GMT";
session_data.max_forward = 70;
session_data.user_agent = "wiznet Version 0.0.0.0";
session_data.allow = "INVITE, ACK, CANCEL, BYE, REFER, OPTiONS, NOTIFY, INFO";
session_data.address[0]=192;
session_data.address[1]=168;
session_data.address[2]=15;
session_data.address[3]=125;
session_data.expires = 120;
session_data.message_body.version = 0;
session_data.message_body.owner_username = "WIZNET";
session_data.message_body.session_information ="the session test protocol of wiznet";
session_data.message_body.session_ID = 24466424;
session_data.message_body.session_version = 24466418;
session_data.message_body.address_type = "IP4";
session_data.message_body.network_type = "IN";
session_data.message_body.start_time = 0;
session_data.message_body.stop_time = 0;
session_data.message_body.media_type = "audio";
session_data.message_body.media_port = UDP_PORT;
session_data.message_body.media_protocol = "RTP/AVP";
session_data.message_body.session_name = "WIZNET Test";
session_data.message_body.media_format = 8;//11;//0;//11;
session_data.message_body.media_attr_fieldname = "rtpmap";
session_data.message_body.media_attr_mime_type = "PCMA";//"PCMU";//"L16";
session_data.message_body.media_attr_sample_rate = 8000;//16000;
session_data.message_body.fmtp_type = 78;
- Init SDP function
set IP and port to send data and set input ADC data function.
SDP_init(&session_data, UDP_SOCKET, UDP_BroadIP, UDP_SPORT);
adc_func_set(adc_fifo_get_blocking);
- socket
The tcp server receives the start and stop messages to decide whether to start or stop RTP transmission.
Send Invite command to SDP protocol when "start". When you stop, send a "bye" command.
UDP_S_status = udps_status(UDP_SOCKET, UDP_buff, UDP_PORT);
TCP_S_status = TCP_Server(TCP_S_SOCKET, TCP_S_PORT);
if(TCP_S_status == 17)
{
tcp_rcv_data = TCP_S_Recv(TCP_S_SOCKET, &tcp_rcv_size);
if(tcp_rcv_data != 0)
{
printf("rcv[%d] : %s \r\n",tcp_rcv_size, tcp_rcv_data);
if(UDP_S_status == 0x22)
{
if(UDP_ret < 0)
{
printf("sendto Error \r\n");
}
}
if(strncmp(tcp_rcv_data, "start", 5) == 0)
{
printf("data send start\r\n");
printf("recv port = %d \r\n", UDP_SPORT);
send(TCP_S_SOCKET, "START RTP Streaming\r\n", strlen("START RTP Streaming\r\n"));
adc_run(true);
adc_fifo_drain();
data_send_status = 1;
rtc_get_datetime(&t);
get_date_data(&t);
SDP_INVITE_Send();
adc_data.sendStatus = 1;
}
else if(strncmp(tcp_rcv_data, "stop", 4) == 0)
{
printf("data send stop \r\n");
data_send_status = 0;
//adc_data.sendStatus = 0;
adc_run(false);
send(TCP_S_SOCKET, "STOP RTP Streaming\r\n", strlen("STOP RTP Streaming\r\n"));
rtc_get_datetime(&t);
get_date_data(&t);
SDP_BYE_Send();
}
free(tcp_rcv_data);
}
}
6. audio data send
Sends RTP data and stores the transfer delay time.
if(data_send_status == 1)
{
UDP_ret=RTP_Data_Send();
now_time_stamp = time_us_64();
printf("data send : %d[%lld]\r\n",UDP_ret, now_time_stamp - pre_time_stamp);
get_time_stamp(now_time_stamp - pre_time_stamp);
pre_time_stamp = now_time_stamp;
}
7. Run Program
- teraterm
select the packet and push play streams button. and view the waveform.
hear audio data to push play botton.
8. Run pot player
- Under open, open the URL.
Listen to the audio data that is being streamed.
Comments