MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / sonic_encode_init

Function sonic_encode_init

libavcodec/sonic.c:170–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170static av_cold int sonic_encode_init(AVCodecContext *avctx)
171{
172 SonicContext *s = avctx->priv_data;
173 int *coded_samples;
174 PutBitContext pb;
175 int i;
176
177 s->version = 2;
178
179 if (avctx->ch_layout.nb_channels > MAX_CHANNELS)
180 {
181 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
182 return AVERROR(EINVAL); /* only stereo or mono for now */
183 }
184
185 if (avctx->ch_layout.nb_channels == 2)
186 s->decorrelation = MID_SIDE;
187 else
188 s->decorrelation = 3;
189
190 if (avctx->codec->id == AV_CODEC_ID_SONIC_LS)
191 {
192 s->lossless = 1;
193 s->num_taps = 32;
194 s->downsampling = 1;
195 s->quantization = 0.0;
196 }
197 else
198 {
199 s->num_taps = 128;
200 s->downsampling = 2;
201 s->quantization = 1.0;
202 }
203
204 // max tap 2048
205 if (s->num_taps < 32 || s->num_taps > 1024 || s->num_taps % 32) {
206 av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
207 return AVERROR_INVALIDDATA;
208 }
209
210 // generate taps
211 s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
212 if (!s->tap_quant)
213 return AVERROR(ENOMEM);
214
215 for (i = 0; i < s->num_taps; i++)
216 s->tap_quant[i] = ff_sqrt(i+1);
217
218 s->channels = avctx->ch_layout.nb_channels;
219 s->samplerate = avctx->sample_rate;
220
221 s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
222 s->frame_size = s->channels*s->block_align*s->downsampling;
223
224 s->tail_size = s->num_taps*s->channels;
225 s->tail = av_calloc(s->tail_size, sizeof(*s->tail));
226 if (!s->tail)
227 return AVERROR(ENOMEM);

Callers

nothing calls this directly

Calls 9

av_logFunction · 0.85
av_callocFunction · 0.85
ff_sqrtFunction · 0.85
init_put_bitsFunction · 0.85
code_samplerateFunction · 0.85
flush_put_bitsFunction · 0.85
put_bytes_outputFunction · 0.85
put_bitsFunction · 0.70
av_malloczFunction · 0.50

Tested by

no test coverage detected