原型机实现基本功能;


录音代码:

void adc_half(void)
{

	if(page_index<page_length){
		for(x=0;x<DMA_size/2-1;x++)
			{
			wave_buffer_a[wavIndex]=adc_val[x]*255/4096;
			wavIndex+=1;
			}
	}
	else
	{
		  record_flag=3;
		  printf("record to end\r\n");
	}

}
void adc_all(void)
{
//	uint16_t temp;
	if(page_index<page_length){
		for(x=DMA_size/2-1;x<DMA_size-1;x++)
			{
			wave_buffer_a[wavIndex]=adc_val[x]*255/4096;
			wavIndex+=1;
			}
//			EncodeB();
			wavIndex=0;
			Audio_write();
	}
	else
	{
		  record_flag=3;
		  printf("record to end\r\n");
	}

	
}


void record_pdm(void)
{
		if(record_flag==1)
		{
			if(buff_flag==3){ 	
        page_index=0;		
        page_length=40;			
				HAL_TIM_Base_Start(&htim3);
				HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);	
//				__HAL_DMA_ENABLE_IT(hdma_adc1, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
				HAL_ADC_Start_DMA(&hadc1, (uint32_t *)(&adc_val), DMA_size);
				HAL_ADCEx_Calibration_Start(&hadc1);
				wavIndex=0;
				buff_flag=0;
			}

	 }
	if(record_flag==3)
		{	
			record_flag =0;
//		  	HAL_TIM_PWM_Stop(&htim4,TIM_CHANNEL_1);
			
			HAL_TIM_Base_Stop_IT(&htim3);	
			HAL_ADC_Stop_DMA(&hadc1);
  		printf("record to end\r\n");
			page_length=page_index;
			lora_send_init();
		}
			
}
void Audio_write(void)
{
	U8_U64();
	writeFlash(page_index);
	page_index++;

}


void U8_U64(void){
	int i;
	
	for(i=0;i<wave_buffer_size/4;i++)
			{
			  WriteBuffer[i]=wave_buffer_a[i*4+3];
				WriteBuffer[i]=WriteBuffer[i]|wave_buffer_a[i*4+2]<<8;
				WriteBuffer[i]=WriteBuffer[i]|wave_buffer_a[i*4+1]<<16;
				WriteBuffer[i]=WriteBuffer[i]|wave_buffer_a[i*4]<<24;
			}
}

播音代码

void audio_PCM(void)
{	
	if(play_flag ==1){
		
		if(buff_flag==3){ 
			page_index=0;
			write_flag=0;
			Audio_read();
			page_index++;	
			write_flag=1;
			Audio_read();
			page_index++;	
			buff_flag=0;
			start_addr=0x0800F000;
			HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_1);
			__HAL_TIM_CLEAR_IT(&htim1, TIM_IT_UPDATE);
			HAL_TIM_Base_Start_IT(&htim1); 	
		}
		if(buff_flag==1){ 
			buff_flag=0;
			Audio_read();	
			page_index++;
			if(page_index>page_length){
				play_flag=3;
			}

		}
			
	}
	
	if(play_flag==3){
			play_flag =0;
			cont=0;

			TIM4->CCR1=0;
			HAL_TIM_PWM_Stop(&htim4,TIM_CHANNEL_1);	
			HAL_TIM_Base_Stop_IT(&htim1); 
//			HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);	
			printf("play to end \r\n");
		
	}

}

void Audio_read(void){
	
	int i=0;
	
	for(i=0;i<wave_buffer_size/4;i++){

	 WriteBuffer[i]=readFlash(start_addr)<<16|readFlash(start_addr+2);
	 start_addr+=4;
	}

	 U64_U8();
}



void U64_U8(void){
	int i=0;
	if(write_flag==1){
	   for(i=0;i<wave_buffer_size/4;i++)
			{ 
				wave_buffer_b[i*4]=WriteBuffer[i]>>16;
				wave_buffer_b[i*4+1]=WriteBuffer[i]>>24;
				wave_buffer_b[i*4+2]=WriteBuffer[i];
				wave_buffer_b[i*4+3]=WriteBuffer[i]>>8;
			}
		}else{
			for(i=0;i<wave_buffer_size/4;i++)
			{
				wave_buffer_a[i*4]=WriteBuffer[i]>>16;
				wave_buffer_a[i*4+1]=WriteBuffer[i]>>24;
				wave_buffer_a[i*4+2]=WriteBuffer[i];
				wave_buffer_a[i*4+3]=WriteBuffer[i]>>8;
				
			}
		}
	
}

lora处理函数

void Ebyte_Port_ReceiveCallback( uint16e_t state, uint8e_t* buffer, uint8e_t length )
{
    if( state &= 0x0001 )
    {

			int i;
			if(buffer[0]=='r'){
				start_flag=1;
				end_flag=1;
				for(i=0;i<13;i++){
				if(buffer[i]!=head_start[i])start_flag=0;
				}
				for(i=0;i<13;i++){
				if(buffer[i]!=head_stop[i])end_flag=0;
				}
			}
			if(start_flag==1){
				start_flag=0;
				printf("start to recieve\r\n");
			  page_index=0;	}
			
			if(end_flag==1){
				page_length=page_index;
				end_flag=0;
			  play_flag=1;	
				record_flag=0;
				buff_flag=3;
			  printf("start to play\r\n");}
			
				
			for(i=0;i<length;i++,buffer++){
				wave_buffer_a[write_cont]=*buffer;
				if(write_cont>wave_buffer_size){
					write_cont=0;
					if(page_index<40){
						Audio_write();}
				}else{
				write_cont++;}
			}
			E32x_GoReceive();
			SPI_select=1;
			
    }

}

样机测试发现如下缺陷,待优化提升:

提升lora传输速率(扩频,频宽调制)时,通话距离下降严重;

使用的STM32F103C8T6内存不足,运行SPEEX后内存经常溢出;

使用8KHz采样率,音质差强人意。

源代码下载链接:

https://download.csdn.net/download/qiang129/85163421