Mercurial > hg > svcore
comparison base/Resampler.cpp @ 928:6a94bb528e9d warnfix_no_size_t
Remove size_t's, fix compiler warnings
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 13:52:07 +0100 |
parents | e802e550a1f2 |
children | cc27f35aa75c |
comparison
equal
deleted
inserted
replaced
917:49618f39ff09 | 928:6a94bb528e9d |
---|---|
29 #include "Debug.h" | 29 #include "Debug.h" |
30 | 30 |
31 class Resampler::D | 31 class Resampler::D |
32 { | 32 { |
33 public: | 33 public: |
34 D(Quality quality, size_t channels, size_t chunkSize); | 34 D(Quality quality, int channels, int chunkSize); |
35 ~D(); | 35 ~D(); |
36 | 36 |
37 size_t resample(float **in, float **out, | 37 int resample(float **in, float **out, |
38 size_t incount, float ratio, | 38 int incount, float ratio, |
39 bool final); | 39 bool final); |
40 | 40 |
41 size_t resampleInterleaved(float *in, float *out, | 41 int resampleInterleaved(float *in, float *out, |
42 size_t incount, float ratio, | 42 int incount, float ratio, |
43 bool final); | 43 bool final); |
44 | 44 |
45 void reset(); | 45 void reset(); |
46 | 46 |
47 protected: | 47 protected: |
48 SRC_STATE *m_src; | 48 SRC_STATE *m_src; |
49 float *m_iin; | 49 float *m_iin; |
50 float *m_iout; | 50 float *m_iout; |
51 size_t m_channels; | 51 int m_channels; |
52 size_t m_iinsize; | 52 int m_iinsize; |
53 size_t m_ioutsize; | 53 int m_ioutsize; |
54 }; | 54 }; |
55 | 55 |
56 Resampler::D::D(Quality quality, size_t channels, size_t chunkSize) : | 56 Resampler::D::D(Quality quality, int channels, int chunkSize) : |
57 m_src(0), | 57 m_src(0), |
58 m_iin(0), | 58 m_iin(0), |
59 m_iout(0), | 59 m_iout(0), |
60 m_channels(channels), | 60 m_channels(channels), |
61 m_iinsize(0), | 61 m_iinsize(0), |
87 if (m_ioutsize > 0) { | 87 if (m_ioutsize > 0) { |
88 free(m_iout); | 88 free(m_iout); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 size_t | 92 int |
93 Resampler::D::resample(float **in, float **out, | 93 Resampler::D::resample(float **in, float **out, |
94 size_t incount, float ratio, | 94 int incount, float ratio, |
95 bool final) | 95 bool final) |
96 { | 96 { |
97 if (m_channels == 1) { | 97 if (m_channels == 1) { |
98 return resampleInterleaved(*in, *out, incount, ratio, final); | 98 return resampleInterleaved(*in, *out, incount, ratio, final); |
99 } | 99 } |
100 | 100 |
101 size_t outcount = lrintf(ceilf(incount * ratio)); | 101 int outcount = lrintf(ceilf(incount * ratio)); |
102 | 102 |
103 if (incount * m_channels > m_iinsize) { | 103 if (incount * m_channels > m_iinsize) { |
104 m_iinsize = incount * m_channels; | 104 m_iinsize = incount * m_channels; |
105 m_iin = (float *)realloc(m_iin, m_iinsize * sizeof(float)); | 105 m_iin = (float *)realloc(m_iin, m_iinsize * sizeof(float)); |
106 } | 106 } |
107 if (outcount * m_channels > m_ioutsize) { | 107 if (outcount * m_channels > m_ioutsize) { |
108 m_ioutsize = outcount * m_channels; | 108 m_ioutsize = outcount * m_channels; |
109 m_iout = (float *)realloc(m_iout, m_ioutsize * sizeof(float)); | 109 m_iout = (float *)realloc(m_iout, m_ioutsize * sizeof(float)); |
110 } | 110 } |
111 for (size_t i = 0; i < incount; ++i) { | 111 for (int i = 0; i < incount; ++i) { |
112 for (size_t c = 0; c < m_channels; ++c) { | 112 for (int c = 0; c < m_channels; ++c) { |
113 m_iin[i * m_channels + c] = in[c][i]; | 113 m_iin[i * m_channels + c] = in[c][i]; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 size_t gen = resampleInterleaved(m_iin, m_iout, incount, ratio, final); | 117 int gen = resampleInterleaved(m_iin, m_iout, incount, ratio, final); |
118 | 118 |
119 for (size_t i = 0; i < gen; ++i) { | 119 for (int i = 0; i < gen; ++i) { |
120 for (size_t c = 0; c < m_channels; ++c) { | 120 for (int c = 0; c < m_channels; ++c) { |
121 out[c][i] = m_iout[i * m_channels + c]; | 121 out[c][i] = m_iout[i * m_channels + c]; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 return gen; | 125 return gen; |
126 } | 126 } |
127 | 127 |
128 size_t | 128 int |
129 Resampler::D::resampleInterleaved(float *in, float *out, | 129 Resampler::D::resampleInterleaved(float *in, float *out, |
130 size_t incount, float ratio, | 130 int incount, float ratio, |
131 bool final) | 131 bool final) |
132 { | 132 { |
133 SRC_DATA data; | 133 SRC_DATA data; |
134 | 134 |
135 size_t outcount = lrintf(ceilf(incount * ratio)); | 135 int outcount = lrintf(ceilf(incount * ratio)); |
136 | 136 |
137 data.data_in = in; | 137 data.data_in = in; |
138 data.data_out = out; | 138 data.data_out = out; |
139 data.input_frames = incount; | 139 data.input_frames = incount; |
140 data.output_frames = outcount; | 140 data.output_frames = outcount; |
141 data.src_ratio = ratio; | 141 data.src_ratio = ratio; |
142 data.end_of_input = (final ? 1 : 0); | 142 data.end_of_input = (final ? 1 : 0); |
143 | 143 |
144 int err = src_process(m_src, &data); | 144 int err = src_process(m_src, &data); |
145 | 145 |
146 //!!! check err, respond appropriately | 146 if (err) { |
147 cerr << "Resampler: ERROR: src_process returned error: " << | |
148 src_strerror(err) << endl; | |
149 return 0; | |
150 } | |
147 | 151 |
148 if (data.input_frames_used != incount) { | 152 if (data.input_frames_used != (int)incount) { |
149 cerr << "Resampler: NOTE: input_frames_used == " << data.input_frames_used << " (while incount = " << incount << ")" << endl; | 153 cerr << "Resampler: NOTE: input_frames_used == " << data.input_frames_used << " (while incount = " << incount << ")" << endl; |
150 } | 154 } |
151 | 155 |
152 return data.output_frames_gen; | 156 return data.output_frames_gen; |
153 } | 157 } |
156 Resampler::D::reset() | 160 Resampler::D::reset() |
157 { | 161 { |
158 src_reset(m_src); | 162 src_reset(m_src); |
159 } | 163 } |
160 | 164 |
161 Resampler::Resampler(Quality quality, size_t channels, size_t chunkSize) | 165 Resampler::Resampler(Quality quality, int channels, int chunkSize) |
162 { | 166 { |
163 m_d = new D(quality, channels, chunkSize); | 167 m_d = new D(quality, channels, chunkSize); |
164 } | 168 } |
165 | 169 |
166 Resampler::~Resampler() | 170 Resampler::~Resampler() |
167 { | 171 { |
168 delete m_d; | 172 delete m_d; |
169 } | 173 } |
170 | 174 |
171 size_t | 175 int |
172 Resampler::resample(float **in, float **out, | 176 Resampler::resample(float **in, float **out, |
173 size_t incount, float ratio, | 177 int incount, float ratio, |
174 bool final) | 178 bool final) |
175 { | 179 { |
176 return m_d->resample(in, out, incount, ratio, final); | 180 return m_d->resample(in, out, incount, ratio, final); |
177 } | 181 } |
178 | 182 |
179 size_t | 183 int |
180 Resampler::resampleInterleaved(float *in, float *out, | 184 Resampler::resampleInterleaved(float *in, float *out, |
181 size_t incount, float ratio, | 185 int incount, float ratio, |
182 bool final) | 186 bool final) |
183 { | 187 { |
184 return m_d->resampleInterleaved(in, out, incount, ratio, final); | 188 return m_d->resampleInterleaved(in, out, incount, ratio, final); |
185 } | 189 } |
186 | 190 |