881
|
1 // sndstretch.h
|
|
2 //
|
|
3 // sndstretch - algorithm for adjusting pitch and speed of s16le data
|
|
4 // Copyright (C) 2000 Florian Berger
|
|
5 // Email: florian.berger@jk.uni-linz.ac.at
|
|
6 //
|
|
7 // This program is free software; you can redistribute it and/or modify
|
|
8 // it under the terms of the GNU General Public License Version 2 as
|
|
9 // published by the Free Software Foundation;
|
|
10 //
|
|
11 // This program is distributed in the hope that it will be useful,
|
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 // GNU General Public License for more details.
|
|
15 //
|
|
16 // You should have received a copy of the GNU General Public License
|
|
17 // along with this program; if not, write to the Free Software
|
|
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19 //
|
|
20 //
|
|
21
|
|
22 #ifndef SNDSTRETCH_H
|
|
23 #define SNDSTRETCH_H
|
|
24
|
|
25
|
|
26 #ifdef __cplusplus
|
|
27 extern "C" {
|
|
28 #endif
|
|
29
|
|
30
|
|
31 typedef short int s16;
|
|
32
|
|
33
|
|
34 typedef struct{
|
|
35 int is_initialized; // init me = 0
|
|
36 int snr_o_prod;
|
|
37 int snr_i_act;
|
|
38 int snr_o_act;
|
|
39 int pos_act;
|
|
40 int dsnr;
|
|
41 double snr_rest; // init me = 0.0
|
|
42
|
|
43 int _RESMAX_div_max, _RESMAX_mod_max;
|
|
44 int fade_in_i, fade_out_i, fade_rest_i;
|
|
45 } StretchJob;
|
|
46
|
|
47 typedef struct{
|
|
48 s16 last_samp[10]; /* 10 channels maximum ;) */
|
|
49 int pos_rest;
|
|
50
|
|
51 int snr;
|
|
52 int pos1, pos2;
|
|
53 int ch;
|
|
54 int ratio1_i;
|
|
55 int ds_li, ds_li_c, ds_rest;
|
|
56 int snr_proc_m_chnr;
|
|
57 } ScaleJob;
|
|
58
|
|
59 typedef struct{
|
|
60 s16 * ring_buff; // init me = (s16*)0
|
|
61 s16 * ring_buff_old; // init me = (s16*)0
|
|
62 s16 * buff_help; // init me = (s16*)0
|
|
63 int ring_size; // init me = 1
|
|
64 int ring_size_old; // init me = 0
|
|
65 int ring_pos_w; // init me = 0
|
|
66 int ring_pos_r; // init me = 0
|
|
67 int snr_scale_i;
|
|
68 int snr_scale_o;
|
|
69 int snr_stretch_i;
|
|
70 int snr_stretch_o;
|
|
71 int snr_proc_scale;
|
|
72 int snr_proc_stretch;
|
|
73 int is_init; // init me = 0
|
|
74 int dsnr;
|
|
75 double speed_act; // init me = 0
|
|
76 double pitch_act; // init me = 0
|
|
77 int fade_shift_act;
|
|
78 StretchJob stretch_job;
|
|
79 ScaleJob scale_job;
|
|
80 } PitchSpeedJob;
|
|
81
|
|
82
|
|
83
|
|
84 int sndstretch(
|
|
85 // stretches the sound (not changing pitch !!!)
|
|
86 // returns number of output samples produced
|
|
87 s16 * buffer, int buff_size, // ring buffer
|
|
88 int pos_init, // only initial pos in ringbuffer
|
|
89 int snr_i, int snr_o, // enlarge - spec
|
|
90 int chnr, /* # of channels */
|
|
91 s16 * outbuff, // output
|
|
92 int * out_prod, // # of output-samples produced
|
|
93 int snr_proc, // # of in-samples to process
|
|
94 int initialize // bool
|
|
95 );
|
|
96
|
|
97
|
|
98 int sndscale(
|
|
99 // rescales the sound (including pitch)
|
|
100 // returns number of output samples produced
|
|
101 s16 * buffer, // ring buffer
|
|
102 int snr_i, int snr_o, // enlarge - specification
|
|
103 // (snr_o may not exceed 2^16 for
|
|
104 // integer optimized version)
|
|
105 int chnr, // # of channels
|
|
106 s16 * outbuff, // output
|
|
107 int * out_prod, // # of output-samples produced
|
|
108 int snr_proc, // # of in-samples to process
|
|
109 int initialize // bool
|
|
110 );
|
|
111
|
|
112
|
|
113 int snd_pitch_speed(
|
|
114 /* input */
|
|
115 s16 *buff_i, int channels, int snr_proc,
|
|
116 /* algorihm parameters */
|
|
117 int initialize, double pitch, double speed, int fade_shift,
|
|
118 /* output */
|
|
119 s16 * buff_o, int * snr_produced
|
|
120 );
|
|
121
|
|
122
|
|
123 int snd_stretch_scale(s16 *buff_i, s16 * buff_o,
|
|
124 double pitch, double speed, int channels,
|
|
125 int snr_proc, int * snr_produced, int initialize );
|
|
126
|
|
127
|
|
128 void InitPitchSpeedJob( PitchSpeedJob * job );
|
|
129
|
|
130 int snd_pitch_speed_job(
|
|
131 /* input */
|
|
132 s16 *buff_i, int channels, int snr_proc,
|
|
133 /* algorihm parameters */
|
|
134 int initialize, double pitch, double speed, int fade_shift,
|
|
135 /* output */
|
|
136 s16 * buff_o, int * snr_produced, PitchSpeedJob * job,
|
|
137 int vol_corr
|
|
138 );
|
|
139
|
|
140 int snd_stretch_scale_job(s16 *buff_i, s16 * buff_o,
|
|
141 double pitch, double speed, int channels,
|
|
142 int snr_proc, int * snr_produced, int initialize,
|
|
143 PitchSpeedJob * job, int init_job);
|
|
144
|
|
145 void CleanupPitchSpeedJob( PitchSpeedJob * job );
|
|
146 /* cleaning up the allocated mess would be a good idea */
|
|
147
|
|
148 #ifdef __cplusplus
|
|
149 }
|
|
150 #endif
|
|
151
|
|
152 #endif // SNDSTRETCH_H
|