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


/**
 * @brief  Upsampling of 16-bit audio to 32-bit slots at a target frequency of 32 kHz.
 * 
 * @param src           Pointer to 16-bit source data (int16_t).
 * @param dst           Pointer to 32-bit destination data (int32_t).
 * @param src_channels  Number of channels (1 or 2).
 * @param src_framerate Input sample rate (e.g., 16000).
 */
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++) {
		for (uint32_t rep = 0; rep < factor; rep++) {
			
			if (src_channels == 2) {
				/* STEREO: Конвертируем в int32_t и сдвигаем в MSB */
				dst[dst_idx]     = ((int32_t)src[f * 2]) << 16;     // Left
				dst[dst_idx + 1] = ((int32_t)src[f * 2 + 1]) << 16; // Right
				dst_idx += 2;
			} else {
				/* MONO: Дублируем моно-сигнал в оба 32-битных канала */
				int32_t mono_sample = ((int32_t)src[f]) << 16;
				dst[dst_idx]     = mono_sample; // Left
				dst[dst_idx + 1] = mono_sample; // Right
				dst_idx += 2;
			}
		}
	}
}