Lines Matching +full:n +full:- +full:factor
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 double factor; /* 1 for no change, < 1 for slower, > 1 for faster. */ member
47 /* Waveform Similarity by least squares; works across multi-channels */
53 #define _ diff += sqr(a[i] - b[i]), ++i; /* Loop optimisation */ in difference()
54 do {_ _ _ _ _ _ _ _} while (i < length); /* N.B. length ≡ 0 (mod 8) */ in difference()
62 float * f = t->overlap_buf; in tempo_best_overlap_position()
63 size_t j, best_pos, prev_best_pos = (t->search + 1) >> 1, step = 64; in tempo_best_overlap_position()
64 size_t i = best_pos = t->quick_search? prev_best_pos : 0; in tempo_best_overlap_position()
65 float diff, least_diff = difference(new_win + t->channels * i, f, t->channels * t->overlap); in tempo_best_overlap_position()
68 if (t->quick_search) do { /* hierarchical search */ in tempo_best_overlap_position()
69 for (k = -1; k <= 1; k += 2) for (j = 1; j < 4 || step == 64; ++j) { in tempo_best_overlap_position()
71 if ((int)i < 0 || i >= t->search) in tempo_best_overlap_position()
73 diff = difference(new_win + t->channels * i, f, t->channels * t->overlap); in tempo_best_overlap_position()
79 else for (i = 1; i < t->search; i++) { /* linear search */ in tempo_best_overlap_position()
80 diff = difference(new_win + t->channels * i, f, t->channels * t->overlap); in tempo_best_overlap_position()
91 float fade_step = 1.0f / (float) t->overlap; in tempo_overlap()
93 for (i = 0; i < t->overlap; ++i) { in tempo_overlap()
95 float fade_out = 1.0f - fade_in; in tempo_overlap()
96 for (j = 0; j < t->channels; ++j, ++k) in tempo_overlap()
103 while (fifo_occupancy(&t->input_fifo) >= t->process_size) { in tempo_process()
107 if (!t->segments_total) { in tempo_process()
108 offset = t->search / 2; in tempo_process()
109 …fifo_write(&t->output_fifo, t->overlap, (float *) fifo_read_ptr(&t->input_fifo) + t->channels * of… in tempo_process()
111 offset = tempo_best_overlap_position(t, fifo_read_ptr(&t->input_fifo)); in tempo_process()
112 tempo_overlap(t, t->overlap_buf, in tempo_process()
113 (float *) fifo_read_ptr(&t->input_fifo) + t->channels * offset, in tempo_process()
114 fifo_write(&t->output_fifo, t->overlap, NULL)); in tempo_process()
117 fifo_write(&t->output_fifo, t->segment - 2 * t->overlap, in tempo_process()
118 (float *) fifo_read_ptr(&t->input_fifo) + in tempo_process()
119 t->channels * (offset + t->overlap)); in tempo_process()
123 memcpy(t->overlap_buf, in tempo_process()
124 (float *) fifo_read_ptr(&t->input_fifo) + in tempo_process()
125 t->channels * (offset + t->segment - t->overlap), in tempo_process()
126 t->channels * t->overlap * sizeof(*(t->overlap_buf))); in tempo_process()
129 skip = t->factor * (++t->segments_total * (t->segment - t->overlap)) + 0.5; in tempo_process()
130 t->skip_total += skip -= t->skip_total; in tempo_process()
131 fifo_read(&t->input_fifo, skip, NULL); in tempo_process()
135 static float * tempo_input(tempo_t * t, float const * samples, size_t n) in tempo_input() argument
137 t->samples_in += n; in tempo_input()
138 return fifo_write(&t->input_fifo, n, samples); in tempo_input()
141 static float const * tempo_output(tempo_t * t, float * samples, size_t * n) in tempo_output() argument
143 t->samples_out += *n = min(*n, fifo_occupancy(&t->output_fifo)); in tempo_output()
144 return fifo_read(&t->output_fifo, *n, samples); in tempo_output()
150 uint64_t samples_out = t->samples_in / t->factor + .5; in tempo_flush()
151 size_t remaining = samples_out > t->samples_out ? in tempo_flush()
152 (size_t)(samples_out - t->samples_out) : 0; in tempo_flush()
153 float * buff = lsx_calloc(128 * t->channels, sizeof(*buff)); in tempo_flush()
156 while (fifo_occupancy(&t->output_fifo) < remaining) { in tempo_flush()
160 fifo_trim_to(&t->output_fifo, remaining); in tempo_flush()
161 t->samples_in = 0; in tempo_flush()
167 double sample_rate, sox_bool quick_search, double factor, in tempo_setup() argument
171 t->quick_search = quick_search; in tempo_setup()
172 t->factor = factor; in tempo_setup()
173 t->segment = sample_rate * segment_ms / 1000 + .5; in tempo_setup()
174 t->search = sample_rate * search_ms / 1000 + .5; in tempo_setup()
175 t->overlap = max(sample_rate * overlap_ms / 1000 + 4.5, 16); in tempo_setup()
176 t->overlap &= ~7; /* Make divisible by 8 for loop optimisation */ in tempo_setup()
177 if (t->overlap * 2 > t->segment) in tempo_setup()
178 t->overlap -= 8; in tempo_setup()
179 t->overlap_buf = lsx_malloc(t->overlap * t->channels * sizeof(*t->overlap_buf)); in tempo_setup()
180 max_skip = ceil(factor * (t->segment - t->overlap)); in tempo_setup()
181 t->process_size = max(max_skip + t->overlap, t->segment) + t->search; in tempo_setup()
182 …memset(fifo_reserve(&t->input_fifo, t->search / 2), 0, (t->search / 2) * t->channels * sizeof(floa… in tempo_setup()
187 free(t->overlap_buf); in tempo_delete()
188 fifo_delete(&t->output_fifo); in tempo_delete()
189 fifo_delete(&t->input_fifo); in tempo_delete()
196 t->channels = channels; in tempo_create()
197 fifo_create(&t->input_fifo, t->channels * sizeof(float)); in tempo_create()
198 fifo_create(&t->output_fifo, t->channels * sizeof(float)); in tempo_create()
202 /*------------------------------- SoX Wrapper --------------------------------*/
207 double factor, segment_ms, search_ms, overlap_ms; member
212 priv_t * p = (priv_t *)effp->priv; in getopts()
222 p->segment_ms = p->search_ms = p->overlap_ms = HUGE_VAL; in getopts()
223 while ((c = lsx_getopt(&optstate)) != -1) switch (c) { in getopts()
224 case 'q': p->quick_search = sox_true; break; in getopts()
227 case 'l': profile = Linear; p->search_ms = 0; break; in getopts()
228 default: lsx_fail("unknown option `-%c'", optstate.opt); return lsx_usage(effp); in getopts()
230 argc -= optstate.ind, argv += optstate.ind; in getopts()
231 do { /* break-able block */ in getopts()
232 NUMERIC_PARAMETER(factor ,0.1 , 100 ) in getopts()
238 if (p->segment_ms == HUGE_VAL) in getopts()
239 p->segment_ms = max(10, segments_ms[profile] / max(pow(p->factor, segments_pow[profile]), 1)); in getopts()
240 if (p->overlap_ms == HUGE_VAL) in getopts()
241 p->overlap_ms = p->segment_ms / overlaps_div[profile]; in getopts()
242 if (p->search_ms == HUGE_VAL) in getopts()
243 p->search_ms = p->segment_ms / searches_div[profile]; in getopts()
245 p->overlap_ms = min(p->overlap_ms, p->segment_ms / 2); in getopts()
246 lsx_report("quick_search=%u factor=%g segment=%g search=%g overlap=%g", in getopts()
247 p->quick_search, p->factor, p->segment_ms, p->search_ms, p->overlap_ms); in getopts()
253 priv_t * p = (priv_t *)effp->priv; in start()
255 if (p->factor == 1) in start()
258 p->tempo = tempo_create((size_t)effp->in_signal.channels); in start()
259 tempo_setup(p->tempo, effp->in_signal.rate, p->quick_search, p->factor, in start()
260 p->segment_ms, p->search_ms, p->overlap_ms); in start()
262 effp->out_signal.length = SOX_UNKNOWN_LEN; in start()
263 if (effp->in_signal.length != SOX_UNKNOWN_LEN) { in start()
264 uint64_t in_length = effp->in_signal.length / effp->in_signal.channels; in start()
265 uint64_t out_length = in_length / p->factor + .5; in start()
266 effp->out_signal.length = out_length * effp->in_signal.channels; in start()
275 priv_t * p = (priv_t *)effp->priv; in flow()
276 size_t i, odone = *osamp /= effp->in_signal.channels; in flow()
277 float const * s = tempo_output(p->tempo, NULL, &odone); in flow()
280 for (i = 0; i < odone * effp->in_signal.channels; ++i) in flow()
281 *obuf++ = SOX_FLOAT_32BIT_TO_SAMPLE(*s++, effp->clips); in flow()
284 float * t = tempo_input(p->tempo, NULL, *isamp / effp->in_signal.channels); in flow()
285 for (i = *isamp; i; --i) in flow()
286 *t++ = SOX_SAMPLE_TO_FLOAT_32BIT(*ibuf++, effp->clips); in flow()
287 tempo_process(p->tempo); in flow()
291 *osamp = odone * effp->in_signal.channels; in flow()
297 priv_t * p = (priv_t *)effp->priv; in drain()
299 tempo_flush(p->tempo); in drain()
305 priv_t * p = (priv_t *)effp->priv; in stop()
306 tempo_delete(p->tempo); in stop()
313 "tempo", "[-q] [-m | -s | -l] factor [segment-ms [search-ms [overlap-ms]]]", in lsx_tempo_effect_fn()
320 /*---------------------------------- pitch -----------------------------------*/
326 int result, pos = (argc > 1 && !strcmp(argv[1], "-q"))? 2 : 1; in pitch_getopts()
331 d = pow(2., d / 1200); /* cents --> factor */ in pitch_getopts()
342 priv_t * p = (priv_t *) effp->priv; in pitch_start()
345 effp->out_signal.rate = effp->in_signal.rate / p->factor; in pitch_start()
354 handler.usage = "[-q] shift-in-cents [segment-ms [search-ms [overlap-ms]]]", in lsx_pitch_effect_fn()