Загрузка данных


void audio_upsample_to_32k(const int16_t *src, int32_t *dst, uint8_t src_channels, uint32_t src_framerate)
{
	const uint32_t target_framerate = 32000;
	uint32_t factor = target_framerate / src_framerate;
	uint32_t src_frames = (src_framerate / 10); 
	uint32_t dst_idx = 0;

	for (uint32_t f = 0; f < src_frames; f++) {
		// Берем текущий и следующий сэмплы для интерполяции
		uint32_t next_f = (f + 1 < src_frames) ? f + 1 : f;

		if (src_channels == 2) {
			int32_t curr_l = ((int32_t)src[f * 2]) << 16;
			int32_t curr_r = ((int32_t)src[f * 2 + 1]) << 16;
			int32_t next_l = ((int32_t)src[next_f * 2]) << 16;
			int32_t next_r = ((int32_t)src[next_f * 2 + 1]) << 16;

			for (uint32_t rep = 0; rep < factor; rep++) {
				// Плавно переходим от curr к next
				dst[dst_idx]     = curr_l + ((next_l - curr_l) * (int32_t)rep / (int32_t)factor);
				dst[dst_idx + 1] = curr_r + ((next_r - curr_r) * (int32_t)rep / (int32_t)factor);
				dst_idx += 2;
			}
		} else {
			int32_t curr_m = ((int32_t)src[f]) << 16;
			int32_t next_m = ((int32_t)src[next_f]) << 16;

			for (uint32_t rep = 0; rep < factor; rep++) {
				int32_t mono_sample = curr_m + ((next_m - curr_m) * (int32_t)rep / (int32_t)factor);
				dst[dst_idx]     = mono_sample;
				dst[dst_idx + 1] = mono_sample;
				dst_idx += 2;
			}
		}
	}
}