aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-05-08 13:56:37 +0200
committerAnton Khirnov <anton@khirnov.net>2012-05-09 17:44:56 +0200
commit6d7f61770094cc80ca2d93c4784c0091411d8242 (patch)
tree3d49d468cfa07f34bc53b3b44d02135de4de6fd2
parent142e740d1ecc6059556f2748a18757d399ee061f (diff)
downloadffmpeg-6d7f61770094cc80ca2d93c4784c0091411d8242.tar.gz
samplefmt: add a function for filling a buffer with silence.
-rw-r--r--libavutil/samplefmt.c19
-rw-r--r--libavutil/samplefmt.h12
2 files changed, 31 insertions, 0 deletions
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 4d94fa69be..b6e785cb67 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 9011889e68..e3aa6a9c36 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 */