首页 > 编程知识 正文

地的使用方法,avision capture tool

时间:2023-05-04 08:54:05 阅读:59275 作者:2060

关于使用音频重采样库lib样本速率

有关resample的库,有多个,例如ffmpeg的libswresample。 alsa使用一个名为libsamplerate的库,github链接目标为: https://github.com/erikd/lib sample rate在alsaloop和aplay中都广泛使用。 今天写DEMO来解决实际问题。 实际问题是如何将16bit 2通道的48000采样率的PCM转换成16bit 2通道的44100采样率

再废话一点,为什么要转换不同的采样率呢? 因为如果同时播放不同采样率的音频文件,声卡实际上只是采样率设置,需要将多个不同的采样率转换为相同的采样率,混合后传递给声卡播放。 这就是这个问题的来源。

1 .在1. Ubuntu 14.04上安装libsampleratesudoapt-getinstalllibsamplerate-dev后,您可以参考以下信息:

大胆的小海豚@大胆的小海豚- e 431:~$ find/usr/- name sample rate.h/usr/include/sample rate.h大胆的小海豚@大胆的小海豚- e 4313360 ~

(1) src_new初始化;2 ) src_process转换开始;3 ) src_delete反向初始化完整源

/* *版权所有(c ) 2002-2011 erikdecastrolopoerikd @ mega-nerd.com * * * thisprogramisfreesoftware; youcanredistributeitand/or modify * * itunderthetermsofthegnugeneralpubliclicenseaspublishedby * * thefreesoftwarefoundation either版本2 of the license, or** (at your option ) anylaterversion.* * * thisprogramisdistributedinthehopethatitwithouteventheimpliedwarrantyyuser merchantabilityorfitnessforaparticularpurpose.see the * * gnugeneralpubliclicenseformorededition * youshouldhavereceivedacopytion if not,writetothefreesoftware * * foundation,Inc .59模板放置,Suite 330,Boston,MA 02111-1307, USA.*//* * thiscodeispartofsecretrabbitcodeakalibsamplerate.a commercial * * uselicenseforthiscodeisavailable, pleasesee : * * http://www.mega-nerd.com/src/procedure.html */* * * apidocumentationisavailablehere 3360 * * * * * ifdef _ _ cplusplus extern ' c ' { # endif/* _ cplusplus */* opaque }/* src _ dataisusedtopassdatatosrc _ simple (atosrc ) long input_frames_used,output_frames_gen; int end_of_input; 双精度src _ ratio; } SRC_DATA;/* src _ CB _ dataisusedwithcallbackbasedapi.*/typedef struct { long frames; float *data_in; } SRC_CB_DATA; /**

User supplied callback function type for use with src_callback_new()** and src_callback_read(). First parameter is the same pointer that was** passed into src_callback_new(). Second parameter is pointer to a** pointer. The user supplied callback function must modify *data to** point to the start of the user supplied float array. The user supplied** function must return the number of frames that **data points to.*/typedef long (*src_callback_t) (void *cb_data, float **data) ;/*** Standard initialisation function : return an anonymous pointer to the** internal state of the converter. Choose a converter from the enums below.** Error returned in *error.*/SRC_STATE* src_new (int converter_type, int channels, int *error) ;/*** Initilisation for callback based API : return an anonymous pointer to the** internal state of the converter. Choose a converter from the enums below.** The cb_data pointer can point to any data or be set to NULL. Whatever the** value, when processing, user supplied function "func" gets called with** cb_data as first parameter.*/SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels, int *error, void* cb_data) ;/*** Cleanup all internal allocations.** Always returns NULL.*/SRC_STATE* src_delete (SRC_STATE *state) ;/*** Standard processing function.** Returns non zero on error.*/int src_process (SRC_STATE *state, SRC_DATA *data) ;/*** Callback based processing function. Read up to frames worth of data from** the converter int *data and return frames read or -1 on error.*/long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;/*** Simple interface for performing a single conversion from input buffer to** output buffer at a fixed conversion ratio.** Simple interface does not require initialisation as it can only operate on** a single buffer worth of audio.*/int src_simple (SRC_DATA *data, int converter_type, int channels) ;/*** This library contains a number of different sample rate converters,** numbered 0 through N.**** Return a string giving either a name or a more full description of each** sample rate converter or NULL if no sample rate converter exists for** the given value. The converters are sequentially numbered from 0 to N.*/const char *src_get_name (int converter_type) ;const char *src_get_description (int converter_type) ;const char *src_get_version (void) ;/*** Set a new SRC ratio. This allows step responses** in the conversion ratio.** Returns non zero on error.*/int src_set_ratio (SRC_STATE *state, double new_ratio) ;/*** Reset the internal SRC state.** Does not modify the quality settings.** Does not free any memory allocations.** Returns non zero on error.*/int src_reset (SRC_STATE *state) ;/*** Return TRUE if ratio is a valid conversion ratio, FALSE** otherwise.*/int src_is_valid_ratio (double ratio) ;/*** Return an error number.*/int src_error (SRC_STATE *state) ;/*** Convert the error number into a string.*/const char* src_strerror (int error) ;/*** The following enums can be used to set the interpolator type** using the function src_set_converter().*/enum{ SRC_SINC_BEST_QUALITY = 0, SRC_SINC_MEDIUM_QUALITY = 1, SRC_SINC_FASTEST = 2, SRC_ZERO_ORDER_HOLD = 3, SRC_LINEAR = 4,} ;/*** Extra helper functions for converting from short to float and** back again.*/void src_short_to_float_array (const short *in, float *out, int len) ;void src_float_to_short_array (const float *in, short *out, int len) ;void src_int_to_float_array (const int *in, float *out, int len) ;void src_float_to_int_array (const float *in, int *out, int len) ;#ifdef __cplusplus} /* extern "C" */#endif /* __cplusplus */#endif /* SAMPLERATE_H */ 3. 转换音频文件例子 sudo apt-get install samplerate-programs

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。