forked from morningstar1/spdif-decoder
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresample.c
More file actions
36 lines (31 loc) · 1.01 KB
/
Copy pathresample.c
File metadata and controls
36 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* resample.c
*
* Created on: 20.04.2015
* Author: sebastian
*/
#include "resample.h"
#include <libavutil/opt.h>
SwrContext* resample_init(){
return swr_alloc();
}
void resample_deinit(SwrContext* swr){
swr_free(&swr);
}
void resample_loadFromCodec(SwrContext *swr, AVCodecContext* audioCodec){
// Set up SWR context once you've got codec information
av_opt_set_int(swr, "in_channel_layout", audioCodec->channel_layout, 0);
av_opt_set_int(swr, "out_channel_layout", audioCodec->channel_layout, 0);
av_opt_set_int(swr, "in_sample_rate", audioCodec->sample_rate, 0);
av_opt_set_int(swr, "out_sample_rate", audioCodec->sample_rate, 0);
av_opt_set_sample_fmt(swr, "in_sample_fmt", audioCodec->sample_fmt, 0);
av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
swr_init(swr);
}
void resample_do(SwrContext* swr, AVFrame *audioFrame, uint8_t* outputBuffer){
swr_convert(swr,
&outputBuffer,
audioFrame->nb_samples,
(const uint8_t**)audioFrame->data,
audioFrame->nb_samples);
}