diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index b2195baef404717060839f7b9c40fb011acbb75d..48e2126ba6473d3ed700e48da721285b9c866148 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -21,12 +21,14 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
+
 #include "avcodec.h"
+#include "bitstream.h"
 #include "bswapdsp.h"
-#include "get_bits.h"
 #include "internal.h"
 
 #include "truespeech_data.h"
+
 /**
  * @file
  * TrueSpeech decoder.
@@ -77,50 +79,50 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
 
 static void truespeech_read_frame(TSContext *dec, const uint8_t *input)
 {
-    GetBitContext gb;
+    BitstreamContext bc;
 
     dec->bdsp.bswap_buf((uint32_t *) dec->buffer, (const uint32_t *) input, 8);
-    init_get_bits(&gb, dec->buffer, 32 * 8);
-
-    dec->vector[7] = ts_codebook[7][get_bits(&gb, 3)];
-    dec->vector[6] = ts_codebook[6][get_bits(&gb, 3)];
-    dec->vector[5] = ts_codebook[5][get_bits(&gb, 3)];
-    dec->vector[4] = ts_codebook[4][get_bits(&gb, 4)];
-    dec->vector[3] = ts_codebook[3][get_bits(&gb, 4)];
-    dec->vector[2] = ts_codebook[2][get_bits(&gb, 4)];
-    dec->vector[1] = ts_codebook[1][get_bits(&gb, 5)];
-    dec->vector[0] = ts_codebook[0][get_bits(&gb, 5)];
-    dec->flag      = get_bits1(&gb);
-
-    dec->offset1[0] = get_bits(&gb, 4) << 4;
-    dec->offset2[3] = get_bits(&gb, 7);
-    dec->offset2[2] = get_bits(&gb, 7);
-    dec->offset2[1] = get_bits(&gb, 7);
-    dec->offset2[0] = get_bits(&gb, 7);
-
-    dec->offset1[1]  = get_bits(&gb, 4);
-    dec->pulseval[1] = get_bits(&gb, 14);
-    dec->pulseval[0] = get_bits(&gb, 14);
-
-    dec->offset1[1] |= get_bits(&gb, 4) << 4;
-    dec->pulseval[3] = get_bits(&gb, 14);
-    dec->pulseval[2] = get_bits(&gb, 14);
-
-    dec->offset1[0] |= get_bits1(&gb);
-    dec->pulsepos[0] = get_bits_long(&gb, 27);
-    dec->pulseoff[0] = get_bits(&gb, 4);
-
-    dec->offset1[0] |= get_bits1(&gb) << 1;
-    dec->pulsepos[1] = get_bits_long(&gb, 27);
-    dec->pulseoff[1] = get_bits(&gb, 4);
-
-    dec->offset1[0] |= get_bits1(&gb) << 2;
-    dec->pulsepos[2] = get_bits_long(&gb, 27);
-    dec->pulseoff[2] = get_bits(&gb, 4);
-
-    dec->offset1[0] |= get_bits1(&gb) << 3;
-    dec->pulsepos[3] = get_bits_long(&gb, 27);
-    dec->pulseoff[3] = get_bits(&gb, 4);
+    bitstream_init(&bc, dec->buffer, 32 * 8);
+
+    dec->vector[7] = ts_codebook[7][bitstream_read(&bc, 3)];
+    dec->vector[6] = ts_codebook[6][bitstream_read(&bc, 3)];
+    dec->vector[5] = ts_codebook[5][bitstream_read(&bc, 3)];
+    dec->vector[4] = ts_codebook[4][bitstream_read(&bc, 4)];
+    dec->vector[3] = ts_codebook[3][bitstream_read(&bc, 4)];
+    dec->vector[2] = ts_codebook[2][bitstream_read(&bc, 4)];
+    dec->vector[1] = ts_codebook[1][bitstream_read(&bc, 5)];
+    dec->vector[0] = ts_codebook[0][bitstream_read(&bc, 5)];
+    dec->flag      = bitstream_read_bit(&bc);
+
+    dec->offset1[0] = bitstream_read(&bc, 4) << 4;
+    dec->offset2[3] = bitstream_read(&bc, 7);
+    dec->offset2[2] = bitstream_read(&bc, 7);
+    dec->offset2[1] = bitstream_read(&bc, 7);
+    dec->offset2[0] = bitstream_read(&bc, 7);
+
+    dec->offset1[1]  = bitstream_read(&bc, 4);
+    dec->pulseval[1] = bitstream_read(&bc, 14);
+    dec->pulseval[0] = bitstream_read(&bc, 14);
+
+    dec->offset1[1] |= bitstream_read(&bc, 4) << 4;
+    dec->pulseval[3] = bitstream_read(&bc, 14);
+    dec->pulseval[2] = bitstream_read(&bc, 14);
+
+    dec->offset1[0] |= bitstream_read_bit(&bc);
+    dec->pulsepos[0] = bitstream_read(&bc, 27);
+    dec->pulseoff[0] = bitstream_read(&bc, 4);
+
+    dec->offset1[0] |= bitstream_read_bit(&bc) << 1;
+    dec->pulsepos[1] = bitstream_read(&bc, 27);
+    dec->pulseoff[1] = bitstream_read(&bc, 4);
+
+    dec->offset1[0] |= bitstream_read_bit(&bc) << 2;
+    dec->pulsepos[2] = bitstream_read(&bc, 27);
+    dec->pulseoff[2] = bitstream_read(&bc, 4);
+
+    dec->offset1[0] |= bitstream_read_bit(&bc) << 3;
+    dec->pulsepos[3] = bitstream_read(&bc, 27);
+    dec->pulseoff[3] = bitstream_read(&bc, 4);
 }
 
 static void truespeech_correlate_filter(TSContext *dec)