Audio 如何修剪PCM数据以确定要馈送的样本计数或帧数?

Audio 如何修剪PCM数据以确定要馈送的样本计数或帧数?,audio,pcm,audio-fingerprinting,downsampling,Audio,Pcm,Audio Fingerprinting,Downsampling,我想为libsamplerate(一个向下采样音频数据的库,需要填充以下结构: typedef struct { float *data_in, *data_out ; long input_frames, output_frames ; long input_frames_used, output_frames_gen ; int end_of_input ; double src_ratio ; } SRC_D

我想为libsamplerate(一个向下采样音频数据的库,需要填充以下结构:

typedef struct
  {   float  *data_in, *data_out ;

      long   input_frames, output_frames ;
      long   input_frames_used, output_frames_gen ;

      int    end_of_input ;

      double src_ratio ;
  } SRC_DATA ;
调用方必须填写的此结构的字段有:

  data_in       : A pointer to the input data samples.
  input_frames  : The number of frames of data pointed to by data_in.
  data_out      : A pointer to the output data samples.
  output_frames : Maximum number of frames pointer to by data_out.
  src_ratio     : Equal to output_sample_rate / input_sample_rate.
  end_of_input  : Equal to 0 if more input data is available and 1 
                  otherwise.

要填充此结构,我有数据,但我不知道帧计数,因此无法定义输入帧。 有没有一种简单的方法来修剪PCM字节流?这样我就可以用正确的帧数将它输入到这个函数中。
(所以这个问题与libsamplerate没有直接关系)

我想你打算一次分块音频,比如说1024帧(因此结构中输入的
end\u
成员)。显然,当你知道你在流的末尾时,你最后的调用可能会更少。“我有数据,但我不知道帧数”你有一个输入样本数组,但你不知道你有多少样本?@BjornRoche好的,我想我可以通过将数据的字节大小除以2来计算样本(对于44100 16位单声道cpm,乘以8(位)再除以16(位),对于立体声,再除以2……)但我可能不在一帧的开头。所以我想我必须先丢弃这些字节,然后再将它们作为输入。这就是为什么我认为我需要找到那个点来修剪音频。我错了吗?不要将16位数组放入libsamplerate。data\u in和data\u out都清楚地标记为类型float,所以你必须首先转换为该类型。我想你不需要o阅读一些基本知识: