1 /*
2 * audio resampling with soxr
3 * Copyright (c) 2012 Rob Sykes <robs@users.sourceforge.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * audio resampling with soxr
25 */
26
29
30 #include <soxr.h>
31
35
36 soxr_datatype_t
type =
45
46 soxr_io_spec_t io_spec = soxr_io_spec(
type,
type);
47
48 soxr_quality_spec_t q_spec = soxr_quality_spec((int)((precision-2)/4), (SOXR_HI_PREC_CLOCK|SOXR_ROLLOFF_NONE)*!!cheby);
49 q_spec.precision = precision;
50 #if !defined SOXR_VERSION /* Deprecated @ March 2013: */
51 q_spec.bw_pc = cutoff?
FFMAX(
FFMIN(cutoff,.995),.8)*100 : q_spec.bw_pc;
52 #else
53 q_spec.passband_end = cutoff?
FFMAX(
FFMIN(cutoff,.995),.8) : q_spec.passband_end;
54 #endif
55
56 soxr_delete((soxr_t)
c);
58 soxr_create(in_rate, out_rate, 0, &
error, &io_spec, &q_spec, 0);
62 }
63
65 soxr_delete((soxr_t)*
c);
67 }
68
70 s->delayed_samples_fixup = soxr_delay((soxr_t)
s->resample);
71
73
74 {
76 size_t idone, odone;
77 soxr_process((soxr_t)
s->resample, &
f, 0, &idone, &
f, 0, &odone);
78 s->delayed_samples_fixup -= soxr_delay((soxr_t)
s->resample);
79 }
80
81 return 0;
82 }
83
87 size_t idone, odone;
88 soxr_error_t
error = soxr_set_error((soxr_t)
c, soxr_set_num_channels((soxr_t)
c,
src->ch_count));
90 error = soxr_process((soxr_t)
c,
src->ch, (
size_t)src_size,
91 &idone, dst->
ch, (
size_t)dst_size, &odone);
92 else
93 idone = 0;
94
95 *consumed = (
int)idone;
96 return error? -1 : odone;
97 }
98
100 double delayed_samples = soxr_delay((soxr_t)
s->resample);
101 double delay_s;
102
104 delayed_samples +=
s->delayed_samples_fixup;
105
106 delay_s = delayed_samples /
s->out_sample_rate;
107
109 }
110
112 int in_count, int *out_idx, int *out_sz){
113 return 0;
114 }
115
117 double out_samples = (
double)
s->out_sample_rate /
s->in_sample_rate * in_samples;
118 double delayed_samples = soxr_delay((soxr_t)
s->resample);
119
121 delayed_samples +=
s->delayed_samples_fixup;
122
123 return (
int64_t)(out_samples + delayed_samples + 1 + .5);
124 }
125
129 };
130