# sin_wave_gen **Repository Path**: yocop/sin_wave_gen ## Basic Information - **Project Name**: sin_wave_gen - **Description**: 可生成不同频率的正弦波及扫频波 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-23 - **Last Updated**: 2024-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 概述 用于动态生成不同频率的 示例代码: ``` #include #define RATE 48000 #define RATE_DIV 100 int16_t *buffer = malloc(RATE / RATE_DIV * 2); if(buffer == NULL) { return; } sin_wave_handle_t handle = sin_wave_new(start_freq, end_freq, RATE, time, db); ao_conf_t ao_cnf; sf_t sf = sf_make_channel(1) | sf_make_rate(RATE) | sf_make_bit(16) | sf_make_signed(1); unsigned char *eqcfg = NULL; unsigned int eqcfg_size = 0; // board_audio_get_eqconfig(&eqcfg, &eqcfg_size, -1); ao_conf_init(&ao_cnf); ao_cnf.name = "alsa"; ao_cnf.period_ms = 15; ao_cnf.aef_conf = eqcfg; ao_cnf.aef_conf_size = eqcfg_size; ao_cls_t *dev_handle = ao_open(sf, &ao_cnf); if (dev_handle == NULL) { return ; } ao_start(dev_handle); for (int i = 0; i < time * RATE_DIV; i ++) { sin_wave_gen(handle, buffer, RATE / RATE_DIV); ao_write(dev_handle, (uint8_t*)buffer, RATE / RATE_DIV * 2); } sin_wave_destory(handle); ao_stop(dev_handle); ao_close(dev_handle); ```