2 * Simple free lossless/lossy audio codec
3 * Copyright (c) 2004 Alex Beregszaszi
5 * This file is part of FFmpeg.
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.
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.
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
28 * Simple free lossless/lossy audio codec
29 * Based on Paul Francis Harrison's Bonk (http://www.logarithmic.net/pfh/bonk)
30 * Written and designed by Alex Beregszaszi
33 * - CABAC put/get_symbol
34 * - independent quantizer for channels
35 * - >2 channels support
36 * - more decorrelation types
37 * - more tap_quant tests
38 * - selectable intlist writers/readers (bonk-style, golomb, cabac)
41 #define MAX_CHANNELS 2
47 typedef struct SonicContext {
48 int lossless, decorrelation;
50 int num_taps, downsampling;
53 int channels, samplerate, block_align, frame_size;
57 int *coded_samples[MAX_CHANNELS];
67 int *predictor_state[MAX_CHANNELS];
70 #define LATTICE_SHIFT 10
71 #define SAMPLE_SHIFT 4
72 #define LATTICE_FACTOR (1 << LATTICE_SHIFT)
73 #define SAMPLE_FACTOR (1 << SAMPLE_SHIFT)
75 #define BASE_QUANT 0.6
76 #define RATE_VARIATION 3.0
78 static inline int shift(int a,int b)
80 return (a+(1<<(b-1))) >> b;
83 static inline int shift_down(int a,int b)
89 static inline int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
93 for (i = 0; i < entries; i++)
94 set_se_golomb(pb, buf[i]);
99 static inline int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
103 for (i = 0; i < entries; i++)
104 buf[i] = get_se_golomb(gb);
111 #define ADAPT_LEVEL 8
113 static int bits_to_store(uint64_t x)
125 static void write_uint_max(PutBitContext *pb, unsigned int value, unsigned int max)
132 bits = bits_to_store(max);
134 for (i = 0; i < bits-1; i++)
135 put_bits(pb, 1, value & (1 << i));
137 if ( (value | (1 << (bits-1))) <= max)
138 put_bits(pb, 1, value & (1 << (bits-1)));
141 static unsigned int read_uint_max(GetBitContext *gb, int max)
143 int i, bits, value = 0;
148 bits = bits_to_store(max);
150 for (i = 0; i < bits-1; i++)
154 if ( (value | (1<<(bits-1))) <= max)
156 value += 1 << (bits-1);
161 static int intlist_write(PutBitContext *pb, int *buf, int entries, int base_2_part)
163 int i, j, x = 0, low_bits = 0, max = 0;
164 int step = 256, pos = 0, dominant = 0, any = 0;
167 copy = av_calloc(entries, sizeof(*copy));
169 return AVERROR(ENOMEM);
175 for (i = 0; i < entries; i++)
176 energy += abs(buf[i]);
178 low_bits = bits_to_store(energy / (entries * 2));
182 put_bits(pb, 4, low_bits);
185 for (i = 0; i < entries; i++)
187 put_bits(pb, low_bits, abs(buf[i]));
188 copy[i] = abs(buf[i]) >> low_bits;
193 bits = av_calloc(entries*max, sizeof(*bits));
197 return AVERROR(ENOMEM);
200 for (i = 0; i <= max; i++)
202 for (j = 0; j < entries; j++)
204 bits[x++] = copy[j] > i;
210 int steplet = step >> 8;
212 if (pos + steplet > x)
215 for (i = 0; i < steplet; i++)
216 if (bits[i+pos] != dominant)
219 put_bits(pb, 1, any);
224 step += step / ADAPT_LEVEL;
230 while (((pos + interloper) < x) && (bits[pos + interloper] == dominant))
234 write_uint_max(pb, interloper, (step >> 8) - 1);
236 pos += interloper + 1;
237 step -= step / ADAPT_LEVEL;
243 dominant = !dominant;
248 for (i = 0; i < entries; i++)
250 put_bits(pb, 1, buf[i] < 0);
258 static int intlist_read(GetBitContext *gb, int *buf, int entries, int base_2_part)
260 int i, low_bits = 0, x = 0;
261 int n_zeros = 0, step = 256, dominant = 0;
262 int pos = 0, level = 0;
263 int *bits = av_calloc(entries, sizeof(*bits));
266 return AVERROR(ENOMEM);
270 low_bits = get_bits(gb, 4);
273 for (i = 0; i < entries; i++)
274 buf[i] = get_bits(gb, low_bits);
277 // av_log(NULL, AV_LOG_INFO, "entries: %d, low bits: %d\n", entries, low_bits);
279 while (n_zeros < entries)
281 int steplet = step >> 8;
285 for (i = 0; i < steplet; i++)
286 bits[x++] = dominant;
291 step += step / ADAPT_LEVEL;
295 int actual_run = read_uint_max(gb, steplet-1);
297 // av_log(NULL, AV_LOG_INFO, "actual run: %d\n", actual_run);
299 for (i = 0; i < actual_run; i++)
300 bits[x++] = dominant;
302 bits[x++] = !dominant;
305 n_zeros += actual_run;
309 step -= step / ADAPT_LEVEL;
315 dominant = !dominant;
319 // reconstruct unsigned values
321 for (i = 0; n_zeros < entries; i++)
328 level += 1 << low_bits;
331 if (buf[pos] >= level)
338 buf[pos] += 1 << low_bits;
347 for (i = 0; i < entries; i++)
348 if (buf[i] && get_bits1(gb))
351 // av_log(NULL, AV_LOG_INFO, "zeros: %d pos: %d\n", n_zeros, pos);
357 static void predictor_init_state(int *k, int *state, int order)
361 for (i = order-2; i >= 0; i--)
363 int j, p, x = state[i];
365 for (j = 0, p = i+1; p < order; j++,p++)
367 int tmp = x + shift_down(k[j] * state[p], LATTICE_SHIFT);
368 state[p] += shift_down(k[j]*x, LATTICE_SHIFT);
374 static int predictor_calc_error(int *k, int *state, int order, int error)
376 int i, x = error - shift_down(k[order-1] * state[order-1], LATTICE_SHIFT);
379 int *k_ptr = &(k[order-2]),
380 *state_ptr = &(state[order-2]);
381 for (i = order-2; i >= 0; i--, k_ptr--, state_ptr--)
383 int k_value = *k_ptr, state_value = *state_ptr;
384 x -= shift_down(k_value * state_value, LATTICE_SHIFT);
385 state_ptr[1] = state_value + shift_down(k_value * x, LATTICE_SHIFT);
388 for (i = order-2; i >= 0; i--)
390 x -= shift_down(k[i] * state[i], LATTICE_SHIFT);
391 state[i+1] = state[i] + shift_down(k[i] * x, LATTICE_SHIFT);
395 // don't drift too far, to avoid overflows
396 if (x > (SAMPLE_FACTOR<<16)) x = (SAMPLE_FACTOR<<16);
397 if (x < -(SAMPLE_FACTOR<<16)) x = -(SAMPLE_FACTOR<<16);
404 #if CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER
405 // Heavily modified Levinson-Durbin algorithm which
406 // copes better with quantization, and calculates the
407 // actual whitened result as it goes.
409 static void modified_levinson_durbin(int *window, int window_entries,
410 int *out, int out_entries, int channels, int *tap_quant)
413 int *state = av_calloc(window_entries, sizeof(*state));
415 memcpy(state, window, 4* window_entries);
417 for (i = 0; i < out_entries; i++)
419 int step = (i+1)*channels, k, j;
420 double xx = 0.0, xy = 0.0;
422 int *x_ptr = &(window[step]);
423 int *state_ptr = &(state[0]);
424 j = window_entries - step;
425 for (;j>0;j--,x_ptr++,state_ptr++)
427 double x_value = *x_ptr;
428 double state_value = *state_ptr;
429 xx += state_value*state_value;
430 xy += x_value*state_value;
433 for (j = 0; j <= (window_entries - step); j++);
435 double stepval = window[step+j];
436 double stateval = window[j];
437 // xx += (double)window[j]*(double)window[j];
438 // xy += (double)window[step+j]*(double)window[j];
439 xx += stateval*stateval;
440 xy += stepval*stateval;
446 k = (int)(floor(-xy/xx * (double)LATTICE_FACTOR / (double)(tap_quant[i]) + 0.5));
448 if (k > (LATTICE_FACTOR/tap_quant[i]))
449 k = LATTICE_FACTOR/tap_quant[i];
450 if (-k > (LATTICE_FACTOR/tap_quant[i]))
451 k = -(LATTICE_FACTOR/tap_quant[i]);
457 x_ptr = &(window[step]);
458 state_ptr = &(state[0]);
459 j = window_entries - step;
460 for (;j>0;j--,x_ptr++,state_ptr++)
462 int x_value = *x_ptr;
463 int state_value = *state_ptr;
464 *x_ptr = x_value + shift_down(k*state_value,LATTICE_SHIFT);
465 *state_ptr = state_value + shift_down(k*x_value, LATTICE_SHIFT);
468 for (j=0; j <= (window_entries - step); j++)
470 int stepval = window[step+j];
471 int stateval=state[j];
472 window[step+j] += shift_down(k * stateval, LATTICE_SHIFT);
473 state[j] += shift_down(k * stepval, LATTICE_SHIFT);
481 static inline int code_samplerate(int samplerate)
485 case 44100: return 0;
486 case 22050: return 1;
487 case 11025: return 2;
488 case 96000: return 3;
489 case 48000: return 4;
490 case 32000: return 5;
491 case 24000: return 6;
492 case 16000: return 7;
495 return AVERROR(EINVAL);
498 static av_cold int sonic_encode_init(AVCodecContext *avctx)
500 SonicContext *s = avctx->priv_data;
504 if (avctx->channels > MAX_CHANNELS)
506 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
507 return AVERROR(EINVAL); /* only stereo or mono for now */
510 if (avctx->channels == 2)
511 s->decorrelation = MID_SIDE;
513 s->decorrelation = 3;
515 if (avctx->codec->id == AV_CODEC_ID_SONIC_LS)
520 s->quantization = 0.0;
526 s->quantization = 1.0;
530 if (s->num_taps < 32 || s->num_taps > 1024 || s->num_taps % 32) {
531 av_log(avctx, AV_LOG_ERROR, "Invalid number of taps\n");
532 return AVERROR_INVALIDDATA;
536 s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
537 for (i = 0; i < s->num_taps; i++)
538 s->tap_quant[i] = ff_sqrt(i+1);
540 s->channels = avctx->channels;
541 s->samplerate = avctx->sample_rate;
543 s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
544 s->frame_size = s->channels*s->block_align*s->downsampling;
546 s->tail_size = s->num_taps*s->channels;
547 s->tail = av_calloc(s->tail_size, sizeof(*s->tail));
549 return AVERROR(ENOMEM);
551 s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k) );
553 return AVERROR(ENOMEM);
555 for (i = 0; i < s->channels; i++)
557 s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
558 if (!s->coded_samples[i])
559 return AVERROR(ENOMEM);
562 s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
564 s->window_size = ((2*s->tail_size)+s->frame_size);
565 s->window = av_calloc(s->window_size, sizeof(*s->window));
567 return AVERROR(ENOMEM);
569 avctx->extradata = av_mallocz(16);
570 if (!avctx->extradata)
571 return AVERROR(ENOMEM);
572 init_put_bits(&pb, avctx->extradata, 16*8);
574 put_bits(&pb, 2, version); // version
577 put_bits(&pb, 2, s->channels);
578 put_bits(&pb, 4, code_samplerate(s->samplerate));
580 put_bits(&pb, 1, s->lossless);
582 put_bits(&pb, 3, SAMPLE_SHIFT); // XXX FIXME: sample precision
583 put_bits(&pb, 2, s->decorrelation);
584 put_bits(&pb, 2, s->downsampling);
585 put_bits(&pb, 5, (s->num_taps >> 5)-1); // 32..1024
586 put_bits(&pb, 1, 0); // XXX FIXME: no custom tap quant table
589 avctx->extradata_size = put_bits_count(&pb)/8;
591 av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
592 version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
594 avctx->frame_size = s->block_align*s->downsampling;
599 static av_cold int sonic_encode_close(AVCodecContext *avctx)
601 SonicContext *s = avctx->priv_data;
604 for (i = 0; i < s->channels; i++)
605 av_freep(&s->coded_samples[i]);
607 av_freep(&s->predictor_k);
609 av_freep(&s->tap_quant);
610 av_freep(&s->window);
611 av_freep(&s->int_samples);
616 static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
617 const AVFrame *frame, int *got_packet_ptr)
619 SonicContext *s = avctx->priv_data;
621 int i, j, ch, quant = 0, x = 0;
623 const short *samples = (const int16_t*)frame->data[0];
625 if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size * 5 + 1000)) < 0)
628 init_put_bits(&pb, avpkt->data, avpkt->size);
631 for (i = 0; i < s->frame_size; i++)
632 s->int_samples[i] = samples[i];
635 for (i = 0; i < s->frame_size; i++)
636 s->int_samples[i] = s->int_samples[i] << SAMPLE_SHIFT;
638 switch(s->decorrelation)
641 for (i = 0; i < s->frame_size; i += s->channels)
643 s->int_samples[i] += s->int_samples[i+1];
644 s->int_samples[i+1] -= shift(s->int_samples[i], 1);
648 for (i = 0; i < s->frame_size; i += s->channels)
649 s->int_samples[i+1] -= s->int_samples[i];
652 for (i = 0; i < s->frame_size; i += s->channels)
653 s->int_samples[i] -= s->int_samples[i+1];
657 memset(s->window, 0, 4* s->window_size);
659 for (i = 0; i < s->tail_size; i++)
660 s->window[x++] = s->tail[i];
662 for (i = 0; i < s->frame_size; i++)
663 s->window[x++] = s->int_samples[i];
665 for (i = 0; i < s->tail_size; i++)
668 for (i = 0; i < s->tail_size; i++)
669 s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
672 modified_levinson_durbin(s->window, s->window_size,
673 s->predictor_k, s->num_taps, s->channels, s->tap_quant);
674 if ((ret = intlist_write(&pb, s->predictor_k, s->num_taps, 0)) < 0)
677 for (ch = 0; ch < s->channels; ch++)
680 for (i = 0; i < s->block_align; i++)
683 for (j = 0; j < s->downsampling; j++, x += s->channels)
685 s->coded_samples[ch][i] = sum;
689 // simple rate control code
692 double energy1 = 0.0, energy2 = 0.0;
693 for (ch = 0; ch < s->channels; ch++)
695 for (i = 0; i < s->block_align; i++)
697 double sample = s->coded_samples[ch][i];
698 energy2 += sample*sample;
699 energy1 += fabs(sample);
703 energy2 = sqrt(energy2/(s->channels*s->block_align));
704 energy1 = sqrt(2.0)*energy1/(s->channels*s->block_align);
706 // increase bitrate when samples are like a gaussian distribution
707 // reduce bitrate when samples are like a two-tailed exponential distribution
709 if (energy2 > energy1)
710 energy2 += (energy2-energy1)*RATE_VARIATION;
712 quant = (int)(BASE_QUANT*s->quantization*energy2/SAMPLE_FACTOR);
713 // av_log(avctx, AV_LOG_DEBUG, "quant: %d energy: %f / %f\n", quant, energy1, energy2);
715 quant = av_clip(quant, 1, 65534);
717 set_ue_golomb(&pb, quant);
719 quant *= SAMPLE_FACTOR;
722 // write out coded samples
723 for (ch = 0; ch < s->channels; ch++)
726 for (i = 0; i < s->block_align; i++)
727 s->coded_samples[ch][i] = ROUNDED_DIV(s->coded_samples[ch][i], quant);
729 if ((ret = intlist_write(&pb, s->coded_samples[ch], s->block_align, 1)) < 0)
733 // av_log(avctx, AV_LOG_DEBUG, "used bytes: %d\n", (put_bits_count(&pb)+7)/8);
736 avpkt->size = (put_bits_count(&pb)+7)/8;
740 #endif /* CONFIG_SONIC_ENCODER || CONFIG_SONIC_LS_ENCODER */
742 #if CONFIG_SONIC_DECODER
743 static const int samplerate_table[] =
744 { 44100, 22050, 11025, 96000, 48000, 32000, 24000, 16000, 8000 };
746 static av_cold int sonic_decode_init(AVCodecContext *avctx)
748 SonicContext *s = avctx->priv_data;
752 s->channels = avctx->channels;
753 s->samplerate = avctx->sample_rate;
755 if (!avctx->extradata)
757 av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
758 return AVERROR_INVALIDDATA;
761 init_get_bits8(&gb, avctx->extradata, avctx->extradata_size);
763 version = get_bits(&gb, 2);
766 av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
767 return AVERROR_INVALIDDATA;
772 s->channels = get_bits(&gb, 2);
773 s->samplerate = samplerate_table[get_bits(&gb, 4)];
774 av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
775 s->channels, s->samplerate);
778 if (s->channels > MAX_CHANNELS)
780 av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
781 return AVERROR_INVALIDDATA;
784 s->lossless = get_bits1(&gb);
786 skip_bits(&gb, 3); // XXX FIXME
787 s->decorrelation = get_bits(&gb, 2);
788 if (s->decorrelation != 3 && s->channels != 2) {
789 av_log(avctx, AV_LOG_ERROR, "invalid decorrelation %d\n", s->decorrelation);
790 return AVERROR_INVALIDDATA;
793 s->downsampling = get_bits(&gb, 2);
794 if (!s->downsampling) {
795 av_log(avctx, AV_LOG_ERROR, "invalid downsampling value\n");
796 return AVERROR_INVALIDDATA;
799 s->num_taps = (get_bits(&gb, 5)+1)<<5;
800 if (get_bits1(&gb)) // XXX FIXME
801 av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
803 s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
804 s->frame_size = s->channels*s->block_align*s->downsampling;
805 // avctx->frame_size = s->block_align;
807 av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
808 version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
811 s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
812 for (i = 0; i < s->num_taps; i++)
813 s->tap_quant[i] = ff_sqrt(i+1);
815 s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k));
817 for (i = 0; i < s->channels; i++)
819 s->predictor_state[i] = av_calloc(s->num_taps, sizeof(**s->predictor_state));
820 if (!s->predictor_state[i])
821 return AVERROR(ENOMEM);
824 for (i = 0; i < s->channels; i++)
826 s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples));
827 if (!s->coded_samples[i])
828 return AVERROR(ENOMEM);
830 s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
832 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
836 static av_cold int sonic_decode_close(AVCodecContext *avctx)
838 SonicContext *s = avctx->priv_data;
841 av_freep(&s->int_samples);
842 av_freep(&s->tap_quant);
843 av_freep(&s->predictor_k);
845 for (i = 0; i < s->channels; i++)
847 av_freep(&s->predictor_state[i]);
848 av_freep(&s->coded_samples[i]);
854 static int sonic_decode_frame(AVCodecContext *avctx,
855 void *data, int *got_frame_ptr,
858 const uint8_t *buf = avpkt->data;
859 int buf_size = avpkt->size;
860 SonicContext *s = avctx->priv_data;
862 int i, quant, ch, j, ret;
864 AVFrame *frame = data;
866 if (buf_size == 0) return 0;
868 frame->nb_samples = s->frame_size / avctx->channels;
869 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
871 samples = (int16_t *)frame->data[0];
873 // av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size);
875 init_get_bits8(&gb, buf, buf_size);
877 intlist_read(&gb, s->predictor_k, s->num_taps, 0);
880 for (i = 0; i < s->num_taps; i++)
881 s->predictor_k[i] *= s->tap_quant[i];
886 quant = get_ue_golomb(&gb) * SAMPLE_FACTOR;
888 // av_log(NULL, AV_LOG_INFO, "quant: %d\n", quant);
890 for (ch = 0; ch < s->channels; ch++)
894 predictor_init_state(s->predictor_k, s->predictor_state[ch], s->num_taps);
896 intlist_read(&gb, s->coded_samples[ch], s->block_align, 1);
898 for (i = 0; i < s->block_align; i++)
900 for (j = 0; j < s->downsampling - 1; j++)
902 s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, 0);
906 s->int_samples[x] = predictor_calc_error(s->predictor_k, s->predictor_state[ch], s->num_taps, s->coded_samples[ch][i] * quant);
910 for (i = 0; i < s->num_taps; i++)
911 s->predictor_state[ch][i] = s->int_samples[s->frame_size - s->channels + ch - i*s->channels];
914 switch(s->decorrelation)
917 for (i = 0; i < s->frame_size; i += s->channels)
919 s->int_samples[i+1] += shift(s->int_samples[i], 1);
920 s->int_samples[i] -= s->int_samples[i+1];
924 for (i = 0; i < s->frame_size; i += s->channels)
925 s->int_samples[i+1] += s->int_samples[i];
928 for (i = 0; i < s->frame_size; i += s->channels)
929 s->int_samples[i] += s->int_samples[i+1];
934 for (i = 0; i < s->frame_size; i++)
935 s->int_samples[i] = shift(s->int_samples[i], SAMPLE_SHIFT);
938 for (i = 0; i < s->frame_size; i++)
939 samples[i] = av_clip_int16(s->int_samples[i]);
945 return (get_bits_count(&gb)+7)/8;
948 AVCodec ff_sonic_decoder = {
950 .type = AVMEDIA_TYPE_AUDIO,
951 .id = AV_CODEC_ID_SONIC,
952 .priv_data_size = sizeof(SonicContext),
953 .init = sonic_decode_init,
954 .close = sonic_decode_close,
955 .decode = sonic_decode_frame,
956 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_EXPERIMENTAL,
957 .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
959 #endif /* CONFIG_SONIC_DECODER */
961 #if CONFIG_SONIC_ENCODER
962 AVCodec ff_sonic_encoder = {
964 .type = AVMEDIA_TYPE_AUDIO,
965 .id = AV_CODEC_ID_SONIC,
966 .priv_data_size = sizeof(SonicContext),
967 .init = sonic_encode_init,
968 .encode2 = sonic_encode_frame,
969 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
970 .capabilities = CODEC_CAP_EXPERIMENTAL,
971 .close = sonic_encode_close,
972 .long_name = NULL_IF_CONFIG_SMALL("Sonic"),
976 #if CONFIG_SONIC_LS_ENCODER
977 AVCodec ff_sonic_ls_encoder = {
979 .type = AVMEDIA_TYPE_AUDIO,
980 .id = AV_CODEC_ID_SONIC_LS,
981 .priv_data_size = sizeof(SonicContext),
982 .init = sonic_encode_init,
983 .encode2 = sonic_encode_frame,
984 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
985 .capabilities = CODEC_CAP_EXPERIMENTAL,
986 .close = sonic_encode_close,
987 .long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"),