Use multiple sample rates simultaneously

coollofty
Posts: 16
Joined: Thu Feb 14, 2019 10:09 am

Use multiple sample rates simultaneously

Postby coollofty » Tue Feb 19, 2019 9:08 am

Code: Select all

	esp_audio_cfg_t cfg = {
		.in_stream_buf_size = 10 * 1024,
		.out_stream_buf_size = 6 * 1024,
		.evt_que = NULL,
		.resample_rate = 0,
		.hal = NULL,
	};
	
	audio_hal_codec_config_t audio_hal_codec_cfg =  AUDIO_HAL_ES8388_DEFAULT();
	audio_hal_codec_cfg.i2s_iface.samples = AUDIO_HAL_16K_SAMPLES;

	cfg.hal = audio_hal_init(&audio_hal_codec_cfg, 0);
	cfg.evt_que = xQueueCreate(3, sizeof(esp_audio_state_t));	
	audio_hal_ctrl_codec(cfg.hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);
	player = esp_audio_create(&cfg);
	
	wav_encoder_cfg_t wav_enc_cfg = DEFAULT_WAV_ENCODER_CONFIG();
	audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
	recorder = audio_pipeline_init(&pipeline_cfg);

	audio_pipeline_register(recorder, i2s_stream_reader, "i2s");
	audio_pipeline_register(recorder, wav_encoder_init(&wav_enc_cfg), "wav");
	audio_pipeline_register(recorder, fs_stream_writer, "file");
	audio_pipeline_link(recorder, (const char *[]) {"i2s", "wav", "file"}, 3);
	audio_element_set_uri(fs_stream_writer, "/sdcard/rec.wav");
The above is my initialization code. After playing a AMR-WB format audio, I started the pipeline to recorded by WAV, but the recorded format is sampling rate of 44.1KHz. Why?

coollofty
Posts: 16
Joined: Thu Feb 14, 2019 10:09 am

Re: Use multiple sample rates simultaneously

Postby coollofty » Tue Feb 19, 2019 10:54 am

I found a solution:

Code: Select all

	audio_element_info_t info;
	audio_element_getinfo(i2s_stream_reader, &info);
	info.sample_rates = 16000, info.channels = 1;
	audio_element_setinfo(i2s_stream_reader, &info);

Who is online

Users browsing this forum: No registered users and 31 guests