forked from FFmpeg/FFmpeg
samplefmt: add a function for filling a buffer with silence.
This commit is contained in:
parent
142e740d1e
commit
6d7f617700
2 changed files with 31 additions and 0 deletions
|
@ -204,3 +204,22 @@ int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
|
||||
int nb_channels, enum AVSampleFormat sample_fmt)
|
||||
{
|
||||
int planar = av_sample_fmt_is_planar(sample_fmt);
|
||||
int planes = planar ? nb_channels : 1;
|
||||
int block_align = av_get_bytes_per_sample(sample_fmt) * (planar ? 1 : nb_channels);
|
||||
int data_size = nb_samples * block_align;
|
||||
int fill_char = (sample_fmt == AV_SAMPLE_FMT_U8 ||
|
||||
sample_fmt == AV_SAMPLE_FMT_U8P) ? 0x80 : 0x00;
|
||||
int i;
|
||||
|
||||
offset *= block_align;
|
||||
|
||||
for (i = 0; i < planes; i++)
|
||||
memset(audio_data[i] + offset, fill_char, data_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -209,4 +209,16 @@ int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
|
|||
int src_offset, int nb_samples, int nb_channels,
|
||||
enum AVSampleFormat sample_fmt);
|
||||
|
||||
/**
|
||||
* Fill an audio buffer with silence.
|
||||
*
|
||||
* @param audio_data array of pointers to data planes
|
||||
* @param offset offset in samples at which to start filling
|
||||
* @param nb_samples number of samples to fill
|
||||
* @param nb_channels number of audio channels
|
||||
* @param sample_fmt audio sample format
|
||||
*/
|
||||
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
|
||||
int nb_channels, enum AVSampleFormat sample_fmt);
|
||||
|
||||
#endif /* AVUTIL_SAMPLEFMT_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue