| ... | ... |
@@ -143,10 +143,10 @@ int swr_init(struct SwrContext *s){
|
| 143 | 143 |
swri_audio_convert_free(&s->out_convert); |
| 144 | 144 |
swri_audio_convert_free(&s->full_convert); |
| 145 | 145 |
|
| 146 |
- s-> in.planar= s-> in_sample_fmt >= 0x100; |
|
| 147 |
- s->out.planar= s->out_sample_fmt >= 0x100; |
|
| 148 |
- s-> in_sample_fmt &= 0xFF; |
|
| 149 |
- s->out_sample_fmt &= 0xFF; |
|
| 146 |
+ s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt); |
|
| 147 |
+ s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt); |
|
| 148 |
+ s-> in_sample_fmt= av_get_alt_sample_fmt(s-> in_sample_fmt, 0); |
|
| 149 |
+ s->out_sample_fmt= av_get_alt_sample_fmt(s->out_sample_fmt, 0); |
|
| 150 | 150 |
|
| 151 | 151 |
if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
|
| 152 | 152 |
av_log(s, AV_LOG_ERROR, "Requested sample format %s is invalid\n", av_get_sample_fmt_name(s->in_sample_fmt)); |
| ... | ... |
@@ -30,7 +30,7 @@ |
| 30 | 30 |
#include "libavutil/samplefmt.h" |
| 31 | 31 |
|
| 32 | 32 |
#define LIBSWRESAMPLE_VERSION_MAJOR 0 |
| 33 |
-#define LIBSWRESAMPLE_VERSION_MINOR 4 |
|
| 33 |
+#define LIBSWRESAMPLE_VERSION_MINOR 5 |
|
| 34 | 34 |
#define LIBSWRESAMPLE_VERSION_MICRO 0 |
| 35 | 35 |
|
| 36 | 36 |
#define SWR_CH_MAX 16 ///< Maximum number of channels |
| ... | ... |
@@ -69,10 +69,10 @@ int swr_init(struct SwrContext *s); |
| 69 | 69 |
* |
| 70 | 70 |
* @param s Swr context, can be NULL |
| 71 | 71 |
* @param out_ch_layout output channel layout (AV_CH_LAYOUT_*) |
| 72 |
- * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*). Use +0x100 for planar audio |
|
| 72 |
+ * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*). |
|
| 73 | 73 |
* @param out_sample_rate output sample rate (frequency in Hz) |
| 74 | 74 |
* @param in_ch_layout input channel layout (AV_CH_LAYOUT_*) |
| 75 |
- * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*). Use +0x100 for planar audio |
|
| 75 |
+ * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*). |
|
| 76 | 76 |
* @param in_sample_rate input sample rate (frequency in Hz) |
| 77 | 77 |
* @param log_offset logging level offset |
| 78 | 78 |
* @param log_ctx parent logging context, can be NULL |
| ... | ... |
@@ -30,8 +30,8 @@ |
| 30 | 30 |
|
| 31 | 31 |
static double get(const uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
|
| 32 | 32 |
const uint8_t *p; |
| 33 |
- if(f>=0x100){
|
|
| 34 |
- f&=0xFF; |
|
| 33 |
+ if(av_sample_fmt_is_planar(f)){
|
|
| 34 |
+ f= av_get_alt_sample_fmt(f, 0); |
|
| 35 | 35 |
p= a[ch]; |
| 36 | 36 |
}else{
|
| 37 | 37 |
p= a[0]; |
| ... | ... |
@@ -50,8 +50,8 @@ static double get(const uint8_t *a[], int ch, int index, int ch_count, enum AVSa |
| 50 | 50 |
|
| 51 | 51 |
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
|
| 52 | 52 |
uint8_t *p; |
| 53 |
- if(f>=0x100){
|
|
| 54 |
- f&=0xFF; |
|
| 53 |
+ if(av_sample_fmt_is_planar(f)){
|
|
| 54 |
+ f= av_get_alt_sample_fmt(f, 0); |
|
| 55 | 55 |
p= a[ch]; |
| 56 | 56 |
}else{
|
| 57 | 57 |
p= a[0]; |
| ... | ... |
@@ -86,7 +86,7 @@ AV_CH_LAYOUT_7POINT1_WIDE , |
| 86 | 86 |
}; |
| 87 | 87 |
|
| 88 | 88 |
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){
|
| 89 |
- if(format >= 0x100){
|
|
| 89 |
+ if(av_sample_fmt_is_planar(format)){
|
|
| 90 | 90 |
int i; |
| 91 | 91 |
int plane_size= av_get_bytes_per_sample(format&0xFF)*samples; |
| 92 | 92 |
format&=0xFF; |
| ... | ... |
@@ -109,7 +109,6 @@ int main(int argc, char **argv){
|
| 109 | 109 |
uint8_t *ain[SWR_CH_MAX]; |
| 110 | 110 |
uint8_t *aout[SWR_CH_MAX]; |
| 111 | 111 |
uint8_t *amid[SWR_CH_MAX]; |
| 112 |
- int planar_in=256, planar_out=256; |
|
| 113 | 112 |
|
| 114 | 113 |
struct SwrContext * forw_ctx= NULL; |
| 115 | 114 |
struct SwrContext *backw_ctx= NULL; |
| ... | ... |
@@ -130,11 +129,11 @@ int main(int argc, char **argv){
|
| 130 | 130 |
in_ch_count, out_ch_count, |
| 131 | 131 |
in_sample_rate, out_sample_rate, |
| 132 | 132 |
av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt)); |
| 133 |
- forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt+planar_out, out_sample_rate, |
|
| 134 |
- in_ch_layout, in_sample_fmt+planar_in , in_sample_rate, |
|
| 133 |
+ forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, av_get_alt_sample_fmt(out_sample_fmt, 1), out_sample_rate, |
|
| 134 |
+ in_ch_layout, av_get_alt_sample_fmt( in_sample_fmt, 1), in_sample_rate, |
|
| 135 | 135 |
0, 0); |
| 136 | 136 |
backw_ctx = swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate, |
| 137 |
- out_ch_layout, out_sample_fmt+planar_out, out_sample_rate, |
|
| 137 |
+ out_ch_layout, av_get_alt_sample_fmt(out_sample_fmt, 1), out_sample_rate, |
|
| 138 | 138 |
0, 0); |
| 139 | 139 |
if(swr_init( forw_ctx) < 0) |
| 140 | 140 |
fprintf(stderr, "swr_init(->) failed\n"); |
| ... | ... |
@@ -145,12 +144,12 @@ int main(int argc, char **argv){
|
| 145 | 145 |
if(!backw_ctx) |
| 146 | 146 |
fprintf(stderr, "Failed to init backw_ctx\n"); |
| 147 | 147 |
//FIXME test planar |
| 148 |
- setup_array(ain , array_in , in_sample_fmt+planar_in , SAMPLES); |
|
| 149 |
- setup_array(amid, array_mid, out_sample_fmt+planar_out, 3*SAMPLES); |
|
| 148 |
+ setup_array(ain , array_in , av_get_alt_sample_fmt( in_sample_fmt, 1), SAMPLES); |
|
| 149 |
+ setup_array(amid, array_mid, av_get_alt_sample_fmt(out_sample_fmt, 1), 3*SAMPLES); |
|
| 150 | 150 |
setup_array(aout, array_out, in_sample_fmt , SAMPLES); |
| 151 | 151 |
for(ch=0; ch<in_ch_count; ch++){
|
| 152 | 152 |
for(i=0; i<SAMPLES; i++) |
| 153 |
- set(ain, ch, i, in_ch_count, in_sample_fmt+planar_in, sin(i*i*3/SAMPLES)); |
|
| 153 |
+ set(ain, ch, i, in_ch_count, av_get_alt_sample_fmt(in_sample_fmt, 1), sin(i*i*3/SAMPLES)); |
|
| 154 | 154 |
} |
| 155 | 155 |
mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, ain, SAMPLES); |
| 156 | 156 |
out_count= swr_convert(backw_ctx,aout, SAMPLES, amid, mid_count); |
| ... | ... |
@@ -163,7 +162,7 @@ int main(int argc, char **argv){
|
| 163 | 163 |
double sum_bb= 0; |
| 164 | 164 |
double sum_ab= 0; |
| 165 | 165 |
for(i=0; i<out_count; i++){
|
| 166 |
- double a= get(ain , ch, i, in_ch_count, in_sample_fmt+planar_in); |
|
| 166 |
+ double a= get(ain , ch, i, in_ch_count, av_get_alt_sample_fmt(in_sample_fmt, 1)); |
|
| 167 | 167 |
double b= get(aout, ch, i, in_ch_count, in_sample_fmt); |
| 168 | 168 |
sum_a += a; |
| 169 | 169 |
sum_b += b; |
| ... | ... |
@@ -188,7 +187,7 @@ int main(int argc, char **argv){
|
| 188 | 188 |
double sum_bb= 0; |
| 189 | 189 |
double sum_ab= 0; |
| 190 | 190 |
for(i=0; i<flush_count; i++){
|
| 191 |
- double a= get(ain , ch, i+out_count, in_ch_count, in_sample_fmt+planar_in); |
|
| 191 |
+ double a= get(ain , ch, i+out_count, in_ch_count, av_get_alt_sample_fmt(in_sample_fmt, 1)); |
|
| 192 | 192 |
double b= get(aout, ch, i, in_ch_count, in_sample_fmt); |
| 193 | 193 |
sum_a += a; |
| 194 | 194 |
sum_b += b; |