summaryrefslogtreecommitdiff
path: root/apps/codecs/libatrac/atrac3.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libatrac/atrac3.c')
-rw-r--r--apps/codecs/libatrac/atrac3.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c
index 26bffd42d4..9e61db1686 100644
--- a/apps/codecs/libatrac/atrac3.c
+++ b/apps/codecs/libatrac/atrac3.c
@@ -36,7 +36,6 @@
36#include <stddef.h> 36#include <stddef.h>
37#include <stdio.h> 37#include <stdio.h>
38 38
39#include "bytestream.h"
40#include "atrac3.h" 39#include "atrac3.h"
41#include "atrac3data.h" 40#include "atrac3data.h"
42#include "atrac3data_fixed.h" 41#include "atrac3data_fixed.h"
@@ -48,6 +47,20 @@
48 47
49#define AVERROR(...) -1 48#define AVERROR(...) -1
50 49
50/* FFMAX/MIN/SWAP and av_clip were taken from libavutil/common.h */
51#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
52#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
53#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
54
55/**
56 * Clips a signed integer value into the -32768,32767 range.
57 */
58static inline int16_t av_clip_int16(int a)
59{
60 if ((a+32768) & ~65535) return (a>>31) ^ 32767;
61 else return a;
62}
63
51static int32_t qmf_window[48]; 64static int32_t qmf_window[48];
52static VLC spectral_coeff_tab[7]; 65static VLC spectral_coeff_tab[7];
53static channel_unit channel_units[2]; 66static channel_unit channel_units[2];
@@ -169,7 +182,7 @@ static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
169} 182}
170 183
171 184
172static av_cold void init_atrac3_transforms(ATRAC3Context *q) { 185static void init_atrac3_transforms(ATRAC3Context *q) {
173 int32_t s; 186 int32_t s;
174 int i; 187 int i;
175 188
@@ -830,7 +843,7 @@ int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q,
830int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) 843int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
831{ 844{
832 int i; 845 int i;
833 const uint8_t *edata_ptr = rmctx->codec_extradata; 846 uint8_t *edata_ptr = rmctx->codec_extradata;
834 static VLC_TYPE atrac3_vlc_table[4096][2]; 847 static VLC_TYPE atrac3_vlc_table[4096][2];
835 static int vlcs_initialized = 0; 848 static int vlcs_initialized = 0;
836 849
@@ -844,12 +857,12 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
844 /* Take care of the codec-specific extradata. */ 857 /* Take care of the codec-specific extradata. */
845 if (rmctx->extradata_size == 14) { 858 if (rmctx->extradata_size == 14) {
846 /* Parse the extradata, WAV format */ 859 /* Parse the extradata, WAV format */
847 DEBUGF("[0-1] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown value always 1 860 DEBUGF("[0-1] %d\n",rm_get_uint16le(&edata_ptr[0])); //Unknown value always 1
848 q->samples_per_channel = bytestream_get_le32(&edata_ptr); 861 q->samples_per_channel = rm_get_uint32le(&edata_ptr[2]);
849 q->codingMode = bytestream_get_le16(&edata_ptr); 862 q->codingMode = rm_get_uint16le(&edata_ptr[6]);
850 DEBUGF("[8-9] %d\n",bytestream_get_le16(&edata_ptr)); //Dupe of coding mode 863 DEBUGF("[8-9] %d\n",rm_get_uint16le(&edata_ptr[8])); //Dupe of coding mode
851 q->frame_factor = bytestream_get_le16(&edata_ptr); //Unknown always 1 864 q->frame_factor = rm_get_uint16le(&edata_ptr[10]); //Unknown always 1
852 DEBUGF("[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0 865 DEBUGF("[12-13] %d\n",rm_get_uint16le(&edata_ptr[12])); //Unknown always 0
853 866
854 /* setup */ 867 /* setup */
855 q->samples_per_frame = 1024 * q->channels; 868 q->samples_per_frame = 1024 * q->channels;
@@ -869,10 +882,10 @@ int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx)
869 882
870 } else if (rmctx->extradata_size == 10) { 883 } else if (rmctx->extradata_size == 10) {
871 /* Parse the extradata, RM format. */ 884 /* Parse the extradata, RM format. */
872 q->atrac3version = bytestream_get_be32(&edata_ptr); 885 q->atrac3version = rm_get_uint32be(&edata_ptr[0]);
873 q->samples_per_frame = bytestream_get_be16(&edata_ptr); 886 q->samples_per_frame = rm_get_uint16be(&edata_ptr[4]);
874 q->delay = bytestream_get_be16(&edata_ptr); 887 q->delay = rm_get_uint16be(&edata_ptr[6]);
875 q->codingMode = bytestream_get_be16(&edata_ptr); 888 q->codingMode = rm_get_uint16be(&edata_ptr[8]);
876 889
877 q->samples_per_channel = q->samples_per_frame / q->channels; 890 q->samples_per_channel = q->samples_per_frame / q->channels;
878 q->scrambled_stream = 1; 891 q->scrambled_stream = 1;