[FFmpeg-cvslog] samplefmt: add a function for filling a buffer with silence.
Anton Khirnov
git at videolan.org
Thu May 10 02:33:20 CEST 2012
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue May 8 13:56:37 2012 +0200| [6d7f61770094cc80ca2d93c4784c0091411d8242] | committer: Anton Khirnov
samplefmt: add a function for filling a buffer with silence.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6d7f61770094cc80ca2d93c4784c0091411d8242
---
libavutil/samplefmt.c | 19 +++++++++++++++++++
libavutil/samplefmt.h | 12 ++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 4d94fa6..b6e785c 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -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;
+}
diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
index 9011889..e3aa6a9 100644
--- a/libavutil/samplefmt.h
+++ b/libavutil/samplefmt.h
@@ -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 */
More information about the ffmpeg-cvslog
mailing list