*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
#include "vorbis.h"
#include "vorbis_enc_data.h"
+#define BITSTREAM_WRITER_LE
+#include "bitstream.h"
+
#undef NDEBUG
#include <assert.h>
int nmodes;
vorbis_mode_t * modes;
-} venc_context_t;
-
-typedef struct {
- int total;
- int total_pos;
- int pos;
- uint8_t * buf_ptr;
-} PutBitContext;
-
-static inline void init_put_bits(PutBitContext * pb, uint8_t * buf, int buffer_len) {
- pb->total = buffer_len * 8;
- pb->total_pos = 0;
- pb->pos = 0;
- pb->buf_ptr = buf;
-}
-
-static void put_bits(PutBitContext * pb, int bits, uint64_t val) {
- if ((pb->total_pos += bits) >= pb->total) return;
- if (!bits) return;
- if (pb->pos) {
- if (pb->pos > bits) {
- *pb->buf_ptr |= val << (8 - pb->pos);
- pb->pos -= bits;
- bits = 0;
- } else {
- *pb->buf_ptr++ |= (val << (8 - pb->pos)) & 0xFF;
- val >>= pb->pos;
- bits -= pb->pos;
- pb->pos = 0;
- }
- }
- for (; bits >= 8; bits -= 8) {
- *pb->buf_ptr++ = val & 0xFF;
- val >>= 8;
- }
- if (bits) {
- *pb->buf_ptr = val;
- pb->pos = 8 - bits;
- }
-}
-static inline void flush_put_bits(PutBitContext * pb) {
-}
-
-static inline int put_bits_count(PutBitContext * pb) {
- return pb->total_pos;
-}
+ int64_t sample_count;
+} venc_context_t;
static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) {
assert(entry >= 0);
venc->sample_rate = avccontext->sample_rate;
venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
- venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]);
+ venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks);
// codebook 0..14 - floor1 book, values 0..255
int maxval = 1;
if (c->books[l] != -1)
maxval = venc->codebooks[c->books[l]].nentries;
- // coded could be -1, but this still works, cause thats 0
+ // coded could be -1, but this still works, cause that is 0
if (coded[counter + k] < maxval) break;
}
assert(l != csub);
float * offset = venc->samples + channel*window_len*2 + window_len;
j = channel;
for (i = 0; i < samples; i++, j += venc->channels)
- offset[i] = audio[j] / 32768. / n * win[window_len - i - 1];
+ offset[i] = -audio[j] / 32768. / n * win[window_len - i - 1]; //FIXME find out why the sign has to be fliped
}
} else {
for (channel = 0; channel < venc->channels; channel++) {
}
for (channel = 0; channel < venc->channels; channel++) {
- ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2, venc->floor/*tmp*/);
+ ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2);
}
if (samples) {
float * offset = venc->saved + channel*window_len;
j = channel;
for (i = 0; i < samples; i++, j += venc->channels)
- offset[i] = audio[j] / 32768. / n * win[i];
+ offset[i] = -audio[j] / 32768. / n * win[i]; //FIXME find out why the sign has to be fliped
}
venc->have_saved = 1;
} else {
return 1;
}
-static int vorbis_encode_init(AVCodecContext * avccontext)
+static av_cold int vorbis_encode_init(AVCodecContext * avccontext)
{
venc_context_t * venc = avccontext->priv_data;
residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels);
+ avccontext->coded_frame->pts = venc->sample_count;
+ venc->sample_count += avccontext->frame_size;
flush_put_bits(&pb);
return (put_bits_count(&pb) + 7) / 8;
}
-static int vorbis_encode_close(AVCodecContext * avccontext)
+static av_cold int vorbis_encode_close(AVCodecContext * avccontext)
{
venc_context_t * venc = avccontext->priv_data;
int i;
vorbis_encode_frame,
vorbis_encode_close,
.capabilities= CODEC_CAP_DELAY,
+ .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+ .long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
};