diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/doc/examples/resampling_audio.c | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'ffmpeg/doc/examples/resampling_audio.c')
| -rw-r--r-- | ffmpeg/doc/examples/resampling_audio.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/ffmpeg/doc/examples/resampling_audio.c b/ffmpeg/doc/examples/resampling_audio.c index dd128e8..a15e042 100644 --- a/ffmpeg/doc/examples/resampling_audio.c +++ b/ffmpeg/doc/examples/resampling_audio.c @@ -62,7 +62,7 @@ static int get_format_from_sample_fmt(const char **fmt, /** * Fill dst buffer with nb_samples, generated starting from t. */ -void fill_samples(double *dst, int nb_samples, int nb_channels, int sample_rate, double *t) +static void fill_samples(double *dst, int nb_samples, int nb_channels, int sample_rate, double *t) { int i, j; double tincr = 1.0 / sample_rate, *dstp = dst; @@ -78,18 +78,6 @@ void fill_samples(double *dst, int nb_samples, int nb_channels, int sample_rate, } } -int alloc_samples_array_and_data(uint8_t ***data, int *linesize, int nb_channels, - int nb_samples, enum AVSampleFormat sample_fmt, int align) -{ - int nb_planes = av_sample_fmt_is_planar(sample_fmt) ? nb_channels : 1; - - *data = av_malloc(sizeof(*data) * nb_planes); - if (!*data) - return AVERROR(ENOMEM); - return av_samples_alloc(*data, linesize, nb_channels, - nb_samples, sample_fmt, align); -} - int main(int argc, char **argv) { int64_t src_ch_layout = AV_CH_LAYOUT_STEREO, dst_ch_layout = AV_CH_LAYOUT_SURROUND; @@ -149,8 +137,8 @@ int main(int argc, char **argv) /* allocate source and destination samples buffers */ src_nb_channels = av_get_channel_layout_nb_channels(src_ch_layout); - ret = alloc_samples_array_and_data(&src_data, &src_linesize, src_nb_channels, - src_nb_samples, src_sample_fmt, 0); + ret = av_samples_alloc_array_and_samples(&src_data, &src_linesize, src_nb_channels, + src_nb_samples, src_sample_fmt, 0); if (ret < 0) { fprintf(stderr, "Could not allocate source samples\n"); goto end; @@ -164,8 +152,8 @@ int main(int argc, char **argv) /* buffer is going to be directly written to a rawaudio file, no alignment */ dst_nb_channels = av_get_channel_layout_nb_channels(dst_ch_layout); - ret = alloc_samples_array_and_data(&dst_data, &dst_linesize, dst_nb_channels, - dst_nb_samples, dst_sample_fmt, 0); + ret = av_samples_alloc_array_and_samples(&dst_data, &dst_linesize, dst_nb_channels, + dst_nb_samples, dst_sample_fmt, 0); if (ret < 0) { fprintf(stderr, "Could not allocate destination samples\n"); goto end; @@ -196,6 +184,10 @@ int main(int argc, char **argv) } dst_bufsize = av_samples_get_buffer_size(&dst_linesize, dst_nb_channels, ret, dst_sample_fmt, 1); + if (dst_bufsize < 0) { + fprintf(stderr, "Could not get sample buffer size\n"); + goto end; + } printf("t:%f in:%d out:%d\n", t, src_nb_samples, ret); fwrite(dst_data[0], 1, dst_bufsize, dst_file); } while (t < 10); |
