Merge pull request #17 from dumganhar/mp3-ogg-decoder
Adds source code of tremolo(for decoding ogg), pvmp3dec source code
This commit is contained in:
commit
fc07c78083
|
|
@ -0,0 +1,64 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
src/pvmp3_normalize.cpp \
|
||||
src/pvmp3_alias_reduction.cpp \
|
||||
src/pvmp3_crc.cpp \
|
||||
src/pvmp3_decode_header.cpp \
|
||||
src/pvmp3_decode_huff_cw.cpp \
|
||||
src/pvmp3_getbits.cpp \
|
||||
src/pvmp3_dequantize_sample.cpp \
|
||||
src/pvmp3_framedecoder.cpp \
|
||||
src/pvmp3_get_main_data_size.cpp \
|
||||
src/pvmp3_get_side_info.cpp \
|
||||
src/pvmp3_get_scale_factors.cpp \
|
||||
src/pvmp3_mpeg2_get_scale_data.cpp \
|
||||
src/pvmp3_mpeg2_get_scale_factors.cpp \
|
||||
src/pvmp3_mpeg2_stereo_proc.cpp \
|
||||
src/pvmp3_huffman_decoding.cpp \
|
||||
src/pvmp3_huffman_parsing.cpp \
|
||||
src/pvmp3_tables.cpp \
|
||||
src/pvmp3_imdct_synth.cpp \
|
||||
src/pvmp3_mdct_6.cpp \
|
||||
src/pvmp3_dct_6.cpp \
|
||||
src/pvmp3_poly_phase_synthesis.cpp \
|
||||
src/pvmp3_equalizer.cpp \
|
||||
src/pvmp3_seek_synch.cpp \
|
||||
src/pvmp3_stereo_proc.cpp \
|
||||
src/pvmp3_reorder.cpp \
|
||||
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += \
|
||||
src/asm/pvmp3_polyphase_filter_window_gcc.s \
|
||||
src/asm/pvmp3_mdct_18_gcc.s \
|
||||
src/asm/pvmp3_dct_9_gcc.s \
|
||||
src/asm/pvmp3_dct_16_gcc.s
|
||||
else
|
||||
LOCAL_SRC_FILES += \
|
||||
src/pvmp3_polyphase_filter_window.cpp \
|
||||
src/pvmp3_mdct_18.cpp \
|
||||
src/pvmp3_dct_9.cpp \
|
||||
src/pvmp3_dct_16.cpp
|
||||
endif
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/src \
|
||||
$(LOCAL_PATH)/include
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/src \
|
||||
$(LOCAL_PATH)/include
|
||||
|
||||
LOCAL_CFLAGS := \
|
||||
-D"OSCL_UNUSED_ARG(x)=(void)(x)"
|
||||
|
||||
LOCAL_CFLAGS += -Werror
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_SANITIZE := signed-integer-overflow
|
||||
|
||||
LOCAL_MODULE := libpvmp3dec
|
||||
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*! \file mp3_decoder_selection.h
|
||||
* \brief select mp3 decoder
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MP3_DECODER_SELECTION_H
|
||||
#define MP3_DECODER_SELECTION_H
|
||||
|
||||
|
||||
#define NEW_PV_MP3_DECODER 1 // 1 == PV mp3 decoder
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_audio_type_defs.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This file was derived from a number of standards bodies. The type
|
||||
definitions below were created from some of the best practices observed
|
||||
in the standards bodies.
|
||||
|
||||
This file is dependent on limits.h for defining the bit widths. In an
|
||||
ANSI C environment limits.h is expected to always be present and contain
|
||||
the following definitions:
|
||||
|
||||
SCHAR_MIN
|
||||
SCHAR_MAX
|
||||
UCHAR_MAX
|
||||
|
||||
INT_MAX
|
||||
INT_MIN
|
||||
UINT_MAX
|
||||
|
||||
SHRT_MIN
|
||||
SHRT_MAX
|
||||
USHRT_MAX
|
||||
|
||||
LONG_MIN
|
||||
LONG_MAX
|
||||
ULONG_MAX
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PVMP3_AUDIO_TYPE_DEFS_H
|
||||
#define PVMP3_AUDIO_TYPE_DEFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef uint8_t uint8;
|
||||
typedef int16_t int16;
|
||||
typedef uint16_t uint16;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
typedef int32_t Int32;
|
||||
|
||||
#endif /* PVMP3_AUDIO_TYPE_DEFS_H */
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3decoder_api.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines the structure tPVMP3DecoderExternal
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3DECODER_API_H
|
||||
#define PVMP3DECODER_API_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
flat = 0,
|
||||
bass_boost = 1,
|
||||
rock = 2,
|
||||
pop = 3,
|
||||
jazz = 4,
|
||||
classical = 5,
|
||||
talk = 6,
|
||||
flat_ = 7
|
||||
|
||||
} e_equalization;
|
||||
|
||||
|
||||
|
||||
typedef enum ERROR_CODE
|
||||
{
|
||||
NO_DECODING_ERROR = 0,
|
||||
UNSUPPORTED_LAYER = 1,
|
||||
UNSUPPORTED_FREE_BITRATE = 2,
|
||||
FILE_OPEN_ERROR = 3, /* error opening file */
|
||||
CHANNEL_CONFIG_ERROR = 4, /* error in channel configuration */
|
||||
SYNTHESIS_WINDOW_ERROR = 5, /* error in synthesis window table */
|
||||
READ_FILE_ERROR = 6, /* error reading input file */
|
||||
SIDE_INFO_ERROR = 7, /* error in side info */
|
||||
HUFFMAN_TABLE_ERROR = 8, /* error in Huffman table */
|
||||
COMMAND_LINE_ERROR = 9, /* error in command line */
|
||||
MEMORY_ALLOCATION_ERROR = 10, /* error allocating memory */
|
||||
NO_ENOUGH_MAIN_DATA_ERROR = 11,
|
||||
SYNCH_LOST_ERROR = 12,
|
||||
OUTPUT_BUFFER_TOO_SMALL = 13 /* output buffer can't hold output */
|
||||
} ERROR_CODE;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
#ifdef __cplusplus
|
||||
tPVMP3DecoderExternal
|
||||
#endif
|
||||
{
|
||||
|
||||
/*
|
||||
* INPUT:
|
||||
* Pointer to the input buffer that contains the encoded bistream data.
|
||||
* The data is filled in such that the first bit transmitted is
|
||||
* the most-significant bit (MSB) of the first array element.
|
||||
* The buffer is accessed in a linear fashion for speed, and the number of
|
||||
* bytes consumed varies frame to frame.
|
||||
* The calling environment can change what is pointed to between calls to
|
||||
* the decode function, library, as long as the inputBufferCurrentLength,
|
||||
* and inputBufferUsedLength are updated too. Also, any remaining bits in
|
||||
* the old buffer must be put at the beginning of the new buffer.
|
||||
*/
|
||||
uint8 *pInputBuffer;
|
||||
|
||||
/*
|
||||
* INPUT:
|
||||
* Number of valid bytes in the input buffer, set by the calling
|
||||
* function. After decoding the bitstream the library checks to
|
||||
* see if it when past this value; it would be to prohibitive to
|
||||
* check after every read operation. This value is not modified by
|
||||
* the MP3 library.
|
||||
*/
|
||||
int32 inputBufferCurrentLength;
|
||||
|
||||
/*
|
||||
* INPUT/OUTPUT:
|
||||
* Number of elements used by the library, initially set to zero by
|
||||
* the function pvmp3_resetDecoder(), and modified by each
|
||||
* call to pvmp3_framedecoder().
|
||||
*/
|
||||
int32 inputBufferUsedLength;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* holds the predicted frame size. It used on the test console, for parsing
|
||||
* purposes.
|
||||
*/
|
||||
uint32 CurrentFrameLength;
|
||||
|
||||
/*
|
||||
* INPUT:
|
||||
* This variable holds the type of equalization used
|
||||
*
|
||||
*
|
||||
*/
|
||||
e_equalization equalizerType;
|
||||
|
||||
|
||||
/*
|
||||
* INPUT:
|
||||
* The actual size of the buffer.
|
||||
* This variable is not used by the library, but is used by the
|
||||
* console test application. This parameter could be deleted
|
||||
* if this value was passed into these function.
|
||||
*/
|
||||
int32 inputBufferMaxLength;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* The number of channels decoded from the bitstream.
|
||||
*/
|
||||
int16 num_channels;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* The number of channels decoded from the bitstream.
|
||||
*/
|
||||
int16 version;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* The sampling rate decoded from the bitstream, in units of
|
||||
* samples/second.
|
||||
*/
|
||||
int32 samplingRate;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* This value is the bitrate in units of bits/second. IT
|
||||
* is calculated using the number of bits consumed for the current frame,
|
||||
* and then multiplying by the sampling_rate, divided by points in a frame.
|
||||
* This value can changes frame to frame.
|
||||
*/
|
||||
int32 bitRate;
|
||||
|
||||
/*
|
||||
* INPUT/OUTPUT:
|
||||
* In: Inform decoder how much more room is available in the output buffer in int16 samples
|
||||
* Out: Size of the output frame in 16-bit words, This value depends on the mp3 version
|
||||
*/
|
||||
int32 outputFrameSize;
|
||||
|
||||
/*
|
||||
* INPUT:
|
||||
* Flag to enable/disable crc error checking
|
||||
*/
|
||||
int32 crcEnabled;
|
||||
|
||||
/*
|
||||
* OUTPUT:
|
||||
* This value is used to accumulate bit processed and compute an estimate of the
|
||||
* bitrate. For debugging purposes only, as it will overflow for very long clips
|
||||
*/
|
||||
uint32 totalNumberOfBitsUsed;
|
||||
|
||||
|
||||
/*
|
||||
* INPUT: (but what is pointed to is an output)
|
||||
* Pointer to the output buffer to hold the 16-bit PCM audio samples.
|
||||
* If the output is stereo, both left and right channels will be stored
|
||||
* in this one buffer.
|
||||
*/
|
||||
|
||||
int16 *pOutputBuffer;
|
||||
|
||||
} tPVMP3DecoderExternal;
|
||||
|
||||
uint32 pvmp3_decoderMemRequirements(void);
|
||||
|
||||
void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem);
|
||||
|
||||
void pvmp3_resetDecoder(void *pMem);
|
||||
|
||||
ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,476 @@
|
|||
@ ------------------------------------------------------------------
|
||||
@ Copyright (C) 1998-2009 PacketVideo
|
||||
@
|
||||
@ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ you may not use this file except in compliance with the License.
|
||||
@ You may obtain a copy of the License at
|
||||
@
|
||||
@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
@
|
||||
@ Unless required by applicable law or agreed to in writing, software
|
||||
@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
@ express or implied.
|
||||
@ See the License for the specific language governing permissions
|
||||
@ and limitations under the License.
|
||||
@ -------------------------------------------------------------------
|
||||
|
||||
@
|
||||
@
|
||||
@ Filename: pvmp3_dct_16_gcc.s
|
||||
@
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
@ REVISION HISTORY
|
||||
@
|
||||
@
|
||||
@ Who: Date: MM/DD/YYYY
|
||||
@ Description:
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.arm
|
||||
|
||||
.align 4
|
||||
|
||||
.text
|
||||
|
||||
.extern pvmp3_dct_16
|
||||
.extern pvmp3_merge_in_place_N32
|
||||
.extern pvmp3_split
|
||||
|
||||
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_dct_16
|
||||
|
||||
pvmp3_dct_16:
|
||||
stmfd sp!,{r0,r1,r4-r11,lr}
|
||||
ldr r1,[r0]
|
||||
ldr r3,[r0,#0x3c]
|
||||
ldr r12,constant1
|
||||
sub r2,r1,r3
|
||||
smull lr,r2,r12,r2
|
||||
sub sp,sp,#0x1c
|
||||
str r2,[sp,#0x14]
|
||||
ldr r2,[r0,#0x1c]
|
||||
ldr r12,[r0,#0x20]
|
||||
add r1,r1,r3
|
||||
sub r3,r2,r12
|
||||
ldr lr,constant2
|
||||
mov r3,r3,lsl #3
|
||||
smull r4,r3,lr,r3
|
||||
ldr r6,constant5
|
||||
str r3,[sp]
|
||||
add r3,r2,r12
|
||||
sub r2,r1,r3
|
||||
ldr r12,constant3
|
||||
add r3,r1,r3
|
||||
smull lr,r2,r12,r2
|
||||
ldr r12,[r0,#0x38]
|
||||
ldr r1,[r0,#4]
|
||||
ldr lr,constant4
|
||||
sub r4,r1,r12
|
||||
add r1,r1,r12
|
||||
ldr r12,[r0,#0x18]
|
||||
smull r4,r5,lr,r4
|
||||
ldr lr,[r0,#0x24]
|
||||
ldr r10,constant10
|
||||
sub r4,r12,lr
|
||||
mov r4,r4,lsl #1
|
||||
smull r7,r4,r6,r4
|
||||
add r12,r12,lr
|
||||
add r7,r1,r12
|
||||
sub r12,r1,r12
|
||||
ldr r1,constant6
|
||||
str r4,[sp,#4]
|
||||
smull r12,r4,r1,r12
|
||||
ldr r1,[r0,#8]
|
||||
ldr r12,[r0,#0x34]
|
||||
ldr r6,constant7
|
||||
sub lr,r1,r12
|
||||
smull r8,lr,r6,lr
|
||||
add r1,r1,r12
|
||||
str lr,[sp,#0x10]
|
||||
ldr r12,[r0,#0x14]
|
||||
ldr lr,[r0,#0x28]
|
||||
ldr r8,constant8
|
||||
sub r6,r12,lr
|
||||
mov r6,r6,lsl #1
|
||||
smull r9,r6,r8,r6
|
||||
add r12,r12,lr
|
||||
ldr r9,constant9
|
||||
add r8,r1,r12
|
||||
sub r12,r1,r12
|
||||
smull r12,lr,r9,r12
|
||||
ldr r12,[r0,#0x30]
|
||||
ldr r1,[r0,#0xc]
|
||||
sub r9,r1,r12
|
||||
smull r11,r9,r10,r9
|
||||
add r12,r1,r12
|
||||
str r9,[sp,#0xc]
|
||||
ldr r9,[r0,#0x10]
|
||||
ldr r10,constant11
|
||||
str r9,[sp,#0x18]
|
||||
ldr r1,[r0,#0x2c]
|
||||
sub r9,r9,r1
|
||||
smull r11,r9,r10,r9
|
||||
ldr r10,constant12
|
||||
str r9,[sp,#8]
|
||||
ldr r9,[sp,#0x18]
|
||||
ldr r11,constant14
|
||||
add r9,r9,r1
|
||||
add r1,r12,r9
|
||||
sub r12,r12,r9
|
||||
mov r12,r12,lsl #2
|
||||
smull r9,r12,r10,r12
|
||||
ldr r10,constant13
|
||||
add r9,r3,r1
|
||||
sub r1,r3,r1
|
||||
smull r1,r3,r10,r1
|
||||
sub r1,r7,r8
|
||||
mov r1,r1,lsl #1
|
||||
smull r1,r10,r11,r1
|
||||
add r1,r7,r8
|
||||
add r8,r9,r1
|
||||
sub r7,r9,r1
|
||||
mov r8,r8,asr #1
|
||||
ldr r1,constant15
|
||||
str r8,[r0]
|
||||
smull r7,r8,r1,r7
|
||||
sub r7,r3,r10
|
||||
str r8,[r0,#0x20]
|
||||
mov r7,r7,lsl #1
|
||||
smull r8,r7,r1,r7
|
||||
add r3,r3,r10
|
||||
add r3,r3,r7
|
||||
str r3,[r0,#0x10]
|
||||
sub r3,r2,r12
|
||||
str r7,[r0,#0x30]
|
||||
add r2,r2,r12
|
||||
ldr r7,constant13
|
||||
sub r12,r4,lr
|
||||
mov r3,r3,lsl #1
|
||||
smull r8,r3,r7,r3
|
||||
add lr,r4,lr
|
||||
sub r4,r2,lr
|
||||
mov r12,r12,lsl #2
|
||||
smull r7,r12,r11,r12
|
||||
add lr,lr,r2
|
||||
sub r2,r3,r12
|
||||
mov r2,r2,lsl #1
|
||||
smull r7,r2,r1,r2
|
||||
mov r4,r4,lsl #1
|
||||
add r12,r12,r2
|
||||
add r3,r12,r3
|
||||
smull r7,r4,r1,r4
|
||||
add r12,r3,lr
|
||||
add r3,r3,r4
|
||||
str r3,[r0,#0x18]
|
||||
add r3,r2,r4
|
||||
str r2,[r0,#0x38]
|
||||
str r3,[r0,#0x28]
|
||||
str r12,[r0,#8]
|
||||
ldr r2,[sp,#0x14]
|
||||
ldr r3,[sp,#0]
|
||||
ldr lr,[sp,#4]
|
||||
sub r2,r2,r3
|
||||
ldr r3,constant3
|
||||
mov r2,r2,lsl #1
|
||||
smull r12,r2,r3,r2
|
||||
ldr r3,[sp,#0x14]
|
||||
ldr r12,[sp,#0]
|
||||
ldr r4,constant6
|
||||
add r12,r3,r12
|
||||
ldr r3,[sp,#4]
|
||||
sub lr,r5,lr
|
||||
mov lr,lr,lsl #1
|
||||
add r3,r5,r3
|
||||
smull r5,lr,r4,lr
|
||||
ldr r4,[sp,#0x10]
|
||||
ldr r5,[sp,#0x10]
|
||||
add r4,r4,r6
|
||||
sub r5,r5,r6
|
||||
ldr r6,constant9
|
||||
mov r5,r5,lsl #1
|
||||
smull r7,r5,r6,r5
|
||||
ldr r6,[sp,#8]
|
||||
ldr r9,[sp,#0xc]
|
||||
ldr r10,constant12
|
||||
sub r6,r9,r6
|
||||
mov r6,r6,lsl #3
|
||||
smull r7,r6,r10,r6
|
||||
ldr r8,[sp,#0x20]
|
||||
ldr r7,[sp,#8]
|
||||
cmp r8,#0
|
||||
add r7,r9,r7
|
||||
|
||||
bne no_flag_proc
|
||||
rsb r12,r12,#0
|
||||
rsb r2,r2,#0
|
||||
rsb r3,r3,#0
|
||||
rsb lr,lr,#0
|
||||
rsb r4,r4,#0
|
||||
rsb r5,r5,#0
|
||||
rsb r7,r7,#0
|
||||
rsb r6,r6,#0
|
||||
no_flag_proc:
|
||||
|
||||
sub r8,r2,r6
|
||||
add r2,r6,r2
|
||||
sub r6,r12,r7
|
||||
ldr r9,constant13
|
||||
add r12,r12,r7
|
||||
sub r7,r3,r4
|
||||
mov r6,r6,lsl #1
|
||||
mov r8,r8,lsl #1
|
||||
smull r10,r8,r9,r8
|
||||
add r3,r3,r4
|
||||
smull r10,r6,r9,r6
|
||||
sub r4,lr,r5
|
||||
mov r7,r7,lsl #2
|
||||
smull r9,r7,r11,r7
|
||||
add lr,lr,r5
|
||||
sub r5,r6,r7
|
||||
add r6,r6,r7
|
||||
sub r7,r12,r3
|
||||
add r3,r12,r3
|
||||
sub r12,r2,lr
|
||||
mov r4,r4,lsl #2
|
||||
smull r9,r4,r11,r4
|
||||
add lr,r2,lr
|
||||
sub r2,r8,r4
|
||||
mov r2,r2,lsl #1
|
||||
mov r5,r5,lsl #1
|
||||
mov r12,r12,lsl #1
|
||||
mov r7,r7,lsl #1
|
||||
smull r9,r5,r1,r5
|
||||
smull r9,r2,r1,r2
|
||||
add r6,r6,r5
|
||||
smull r9,r7,r1,r7
|
||||
smull r9,r12,r1,r12
|
||||
add r1,r4,r2
|
||||
add r1,r1,r8
|
||||
add lr,lr,r1
|
||||
add r3,r3,lr
|
||||
str r3,[r0,#4]
|
||||
add r3,r6,lr
|
||||
str r3,[r0,#0xc]
|
||||
add r1,r1,r12
|
||||
add r3,r6,r1
|
||||
add r1,r7,r1
|
||||
str r1,[r0,#0x1c]
|
||||
str r3,[r0,#0x14]
|
||||
add r1,r12,r2
|
||||
add r3,r7,r1
|
||||
add r1,r5,r1
|
||||
str r1,[r0,#0x2c]
|
||||
str r3,[r0,#0x24]!
|
||||
add r1,r5,r2
|
||||
str r1,[r0,#0x10]
|
||||
str r2,[r0,#0x18]
|
||||
add sp,sp,#0x24
|
||||
ldmfd sp!,{r4-r11,pc}
|
||||
|
||||
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_merge_in_place_N32
|
||||
|
||||
|
||||
|
||||
pvmp3_merge_in_place_N32:
|
||||
stmfd sp!,{r4,lr}
|
||||
ldr r1,[r0,#0x1c]
|
||||
ldr r2,[r0,#0x38]
|
||||
str r1,[r0,#0x38]
|
||||
ldr r1,[r0,#0x18]
|
||||
ldr r3,[r0,#0x30]
|
||||
str r1,[r0,#0x30]
|
||||
ldr r12,[r0,#0x14]
|
||||
ldr r1,[r0,#0x28]
|
||||
str r12,[r0,#0x28]
|
||||
ldr r12,[r0,#0x10]
|
||||
ldr lr,[r0,#0x20]
|
||||
str r12,[r0,#0x20]
|
||||
ldr r12,[r0,#0xc]
|
||||
str r12,[r0,#0x18]
|
||||
ldr r12,[r0,#8]
|
||||
str r12,[r0,#0x10]
|
||||
ldr r12,[r0,#4]
|
||||
str r12,[r0,#8]
|
||||
ldr r4,[r0,#0x40]
|
||||
ldr r12,[r0,#0x44]
|
||||
add r4,r4,r12
|
||||
str r4,[r0,#4]
|
||||
str lr,[r0,#0x40]
|
||||
ldr lr,[r0,#0x48]
|
||||
add r12,lr,r12
|
||||
str r12,[r0,#0xc]
|
||||
ldr r12,[r0,#0x4c]
|
||||
add lr,r12,lr
|
||||
str lr,[r0,#0x14]
|
||||
ldr lr,[r0,#0x24]
|
||||
str lr,[r0,#0x48]
|
||||
ldr lr,[r0,#0x50]
|
||||
add r12,lr,r12
|
||||
str r12,[r0,#0x1c]
|
||||
ldr r12,[r0,#0x54]
|
||||
str r1,[r0,#0x50]
|
||||
add lr,r12,lr
|
||||
str lr,[r0,#0x24]
|
||||
ldr r1,[r0,#0x58]
|
||||
ldr r4,[r0,#0x2c]
|
||||
ldr lr,[r0,#0x34]
|
||||
add r12,r1,r12
|
||||
str r12,[r0,#0x2c]
|
||||
ldr r12,[r0,#0x5c]
|
||||
add r1,r12,r1
|
||||
str r1,[r0,#0x34]
|
||||
str r4,[r0,#0x58]
|
||||
ldr r1,[r0,#0x60]
|
||||
ldr r4,[r0,#0x3c]
|
||||
add r12,r1,r12
|
||||
str r12,[r0,#0x3c]
|
||||
ldr r12,[r0,#0x64]
|
||||
add r1,r12,r1
|
||||
str r1,[r0,#0x44]
|
||||
ldr r1,[r0,#0x68]
|
||||
add r12,r1,r12
|
||||
str r12,[r0,#0x4c]
|
||||
ldr r12,[r0,#0x6c]
|
||||
add r1,r12,r1
|
||||
str r1,[r0,#0x54]
|
||||
ldr r1,[r0,#0x70]
|
||||
str r3,[r0,#0x60]
|
||||
add r12,r1,r12
|
||||
str r12,[r0,#0x5c]
|
||||
ldr r3,[r0,#0x74]
|
||||
add r1,r3,r1
|
||||
str r1,[r0,#0x64]
|
||||
str lr,[r0,#0x68]
|
||||
ldr r1,[r0,#0x78]
|
||||
str r2,[r0,#0x70]
|
||||
add r3,r1,r3
|
||||
str r3,[r0,#0x6c]
|
||||
ldr r2,[r0,#0x7c]
|
||||
add r1,r1,r2
|
||||
str r1,[r0,#0x74]
|
||||
str r4,[r0,#0x78]
|
||||
ldmfd sp!,{r4,pc}
|
||||
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_split
|
||||
|
||||
|
||||
pvmp3_split:
|
||||
stmfd sp!,{r4,r5,lr}
|
||||
adr r1,constant16
|
||||
ldr r2,[r1]
|
||||
add r2,r1
|
||||
sub r1,r0,#4
|
||||
mov r3,#3
|
||||
loop1:
|
||||
ldr r12,[r0]
|
||||
ldr lr,[r1]
|
||||
ldr r4,[r2],#-4
|
||||
add r5,lr,r12
|
||||
sub r12,lr,r12
|
||||
smull r12,lr,r4,r12
|
||||
str r5,[r1],#-4
|
||||
mov r12,r12,lsr #27
|
||||
add r12,r12,lr,lsl #5
|
||||
str r12,[r0],#4
|
||||
ldr r12,[r0]
|
||||
ldr lr,[r1]
|
||||
ldr r4,[r2],#-4
|
||||
add r5,lr,r12
|
||||
sub r12,lr,r12
|
||||
smull r12,lr,r4,r12
|
||||
str r5,[r1],#-4
|
||||
mov r12,r12,lsr #27
|
||||
add r12,r12,lr,lsl #5
|
||||
str r12,[r0],#4
|
||||
subs r3,r3,#1
|
||||
bne loop1
|
||||
mov r3,#5
|
||||
loop2:
|
||||
ldr r12,[r0]
|
||||
ldr lr,[r1]
|
||||
ldr r4,[r2],#-4
|
||||
add r5,lr,r12
|
||||
sub r12,lr,r12
|
||||
mov r12,r12,lsl #1
|
||||
smull lr,r12,r4,r12
|
||||
str r5,[r1],#-4
|
||||
str r12,[r0],#4
|
||||
ldr r12,[r0]
|
||||
ldr lr,[r1]
|
||||
ldr r4,[r2],#-4
|
||||
add r5,lr,r12
|
||||
sub r12,lr,r12
|
||||
mov r12,r12,lsl #1
|
||||
smull lr,r12,r4,r12
|
||||
str r5,[r1],#-4
|
||||
str r12,[r0],#4
|
||||
subs r3,r3,#1
|
||||
bne loop2
|
||||
ldmfd sp!,{r4,r5,pc}
|
||||
constant1:
|
||||
.word 0x404f4680
|
||||
constant2:
|
||||
.word 0x519e4e00
|
||||
constant3:
|
||||
.word 0x4140fb80
|
||||
constant4:
|
||||
.word 0x42e13c00
|
||||
constant5:
|
||||
.word 0x6e3c9300
|
||||
constant6:
|
||||
.word 0x4cf8de80
|
||||
constant7:
|
||||
.word 0x48919f80
|
||||
constant8:
|
||||
.word 0x43e22480
|
||||
constant9:
|
||||
.word 0x73326b80
|
||||
constant10:
|
||||
.word 0x52cb0e80
|
||||
constant11:
|
||||
.word 0x64e24000
|
||||
constant12:
|
||||
.word 0x52036780
|
||||
constant13:
|
||||
.word 0x4545ea00
|
||||
constant14:
|
||||
.word 0x539eba80
|
||||
constant15:
|
||||
.word 0x5a827980
|
||||
constant16:
|
||||
.word (CosTable_dct32 + 60)-constant16
|
||||
|
||||
|
||||
|
||||
CosTable_dct32:
|
||||
.word 0x4013c280
|
||||
.word 0x40b34580
|
||||
.word 0x41fa2d80
|
||||
.word 0x43f93400
|
||||
.word 0x46cc1c00
|
||||
.word 0x4a9d9d00
|
||||
.word 0x4fae3700
|
||||
.word 0x56601e80
|
||||
.word 0x5f4cf700
|
||||
.word 0x6b6fcf00
|
||||
.word 0x07c7d1d8
|
||||
.word 0x095b0350
|
||||
.word 0x0bdf91b0
|
||||
.word 0x107655e0
|
||||
.word 0x1b42c840
|
||||
.word 0x51852300
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
@ ------------------------------------------------------------------
|
||||
@ Copyright (C) 1998-2009 PacketVideo
|
||||
@
|
||||
@ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ you may not use this file except in compliance with the License.
|
||||
@ You may obtain a copy of the License at
|
||||
@
|
||||
@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
@
|
||||
@ Unless required by applicable law or agreed to in writing, software
|
||||
@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
@ express or implied.
|
||||
@ See the License for the specific language governing permissions
|
||||
@ and limitations under the License.
|
||||
@ -------------------------------------------------------------------
|
||||
|
||||
@
|
||||
@
|
||||
@ Filename: pvmp3_dct_9_gcc.s
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
@ REVISION HISTORY
|
||||
@
|
||||
@
|
||||
@ Who: Date: MM/DD/YYYY
|
||||
@ Description:
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.arm
|
||||
|
||||
.align 4
|
||||
|
||||
.text
|
||||
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_dct_9
|
||||
|
||||
pvmp3_dct_9:
|
||||
stmfd sp!,{r4-r11,lr}
|
||||
ldr r2, [r0, #0x20]
|
||||
ldr r3, [r0, #0]
|
||||
ldr r12,[r0, #4]
|
||||
add r1,r2,r3
|
||||
sub lr,r2,r3
|
||||
ldr r3,[r0, #0x1c]
|
||||
ldr r4,[r0, #0x18]
|
||||
add r2,r3,r12
|
||||
ldr r5,[r0,#8]
|
||||
sub r3,r3,r12
|
||||
add r12,r4,r5
|
||||
sub r4,r4,r5
|
||||
ldr r5,[r0, #0x14]
|
||||
ldr r7,[r0, #0xc]
|
||||
ldr r9,[r0, #0x10]
|
||||
add r6,r5,r7
|
||||
sub r5,r5,r7
|
||||
add r7,r1,r12
|
||||
add r8,r9,r2
|
||||
add r7,r7,r6
|
||||
add r10,r7,r8
|
||||
rsb r7,r8,r7,asr #1
|
||||
str r7,[r0, #0x18]
|
||||
rsb r2,r9,r2,asr #1
|
||||
str r10,[r0,#0]
|
||||
ldr r11,cos_2pi_9
|
||||
rsb r7,r2,#0
|
||||
|
||||
ldr r10,cos_4pi_9
|
||||
mov r9,r1,lsl #1
|
||||
mov r8,r7
|
||||
|
||||
@ vec[4] = fxp_mac32_Q32( vec[4], tmp0<<1, cos_2pi_9)@
|
||||
|
||||
smlal r1,r8,r11,r9
|
||||
ldr r11,cos_pi_9
|
||||
mov r1,r9 @@@@@@ !!!!!!
|
||||
|
||||
@ vec[8] = fxp_mac32_Q32( vec[8], tmp0<<1, cos_4pi_9)@
|
||||
|
||||
smlal r1,r7,r10,r9
|
||||
|
||||
mov r1,r12,lsl #1
|
||||
|
||||
|
||||
@ vec[2] = fxp_mac32_Q32( vec[2], tmp0<<1, cos_pi_9)@
|
||||
|
||||
smlal r9,r2,r11,r9
|
||||
rsb r9,r10,#0
|
||||
ldr r11,cos_5pi_9
|
||||
|
||||
smlal r12,r2,r9,r1
|
||||
|
||||
|
||||
|
||||
@ vec[2] = fxp_mac32_Q32( vec[2], tmp2<<1, cos_5pi_9)@
|
||||
|
||||
ldr r9,cos_2pi_9
|
||||
mov r12,r1 @@@@@@ !!!!!!
|
||||
smlal r12,r8,r11,r1
|
||||
|
||||
|
||||
@ vec[8] = fxp_mac32_Q32( vec[8], tmp2<<1, cos_2pi_9)@
|
||||
|
||||
smlal r1,r7,r9,r1
|
||||
mov r1,r6,lsl #1
|
||||
smlal r12,r7,r11,r1
|
||||
and r6,r10,r11,asr #14
|
||||
smlal r12,r8,r6,r1
|
||||
ldr r10,cos_11pi_18
|
||||
add r12,r11,r6
|
||||
smlal r1,r2,r12,r1
|
||||
ldr r9,cos_8pi_9
|
||||
str r2,[r0,#8]
|
||||
mov r1,r5,lsl #1
|
||||
|
||||
@ vec[8] = fxp_mac32_Q32( vec[8], tmp3<<1, cos_8pi_9)@
|
||||
|
||||
smull r2,r6,r9,r1
|
||||
str r7,[r0,#0x20]
|
||||
mov r2,r4,lsl #1
|
||||
ldr r7,cos_13pi_18
|
||||
smlal r12,r6,r10,r2
|
||||
|
||||
mov r3,r3,lsl #1
|
||||
|
||||
@ vec[5] = fxp_mac32_Q32( vec[5], tmp8<<1, cos_13pi_18)@
|
||||
|
||||
smlal r12,r6,r7,r3
|
||||
add r4,r5,r4
|
||||
mov r12,lr,lsl #1
|
||||
sub lr,r4,lr
|
||||
ldr r7,cos_17pi_18
|
||||
str r8,[r0, #0x10]
|
||||
ldr r4,cos_pi_6
|
||||
|
||||
mov lr,lr,lsl #1
|
||||
|
||||
@ vec[1] = fxp_mac32_Q32( vec[1], tmp8<<1, cos_17pi_18)@
|
||||
|
||||
smlal r8,r6,r7,r12
|
||||
|
||||
@ vec[3] = fxp_mul32_Q32((tmp5 + tmp6 - tmp8)<<1, cos_pi_6)@
|
||||
|
||||
smull r5,lr,r4,lr
|
||||
str r6,[r0, #4]
|
||||
str lr,[r0, #0xc]
|
||||
|
||||
|
||||
@ vec[5] = fxp_mul32_Q32(tmp5<<1, cos_17pi_18)@
|
||||
smull r5,lr,r7,r1
|
||||
rsb r6,r9,#0
|
||||
@ vec[5] = fxp_mac32_Q32( vec[5], tmp6<<1, cos_7pi_18)@
|
||||
smlal r5,lr,r6,r2
|
||||
@ vec[5] = fxp_mac32_Q32( vec[5], tmp7<<1, cos_pi_6)@
|
||||
smlal r5,lr,r4,r3
|
||||
@ vec[5] = fxp_mac32_Q32( vec[5], tmp8<<1, cos_13pi_18)@
|
||||
smlal r5,lr,r10,r12
|
||||
str lr,[r0, #0x14]
|
||||
rsb lr,r10,#0
|
||||
|
||||
@ vec[7] = fxp_mul32_Q32(tmp5<<1, cos_5pi_18)@
|
||||
smull r5,r1,lr,r1
|
||||
@ vec[7] = fxp_mac32_Q32( vec[7], tmp6<<1, cos_17pi_18)@
|
||||
smlal r2,r1,r7,r2
|
||||
@ vec[7] = fxp_mac32_Q32( vec[7], tmp7<<1, cos_pi_6)@
|
||||
smlal r3,r1,r4,r3
|
||||
@ vec[7] = fxp_mac32_Q32( vec[7], tmp8<<1, cos_11pi_18)@
|
||||
smlal r12,r1,r9,r12
|
||||
str r1,[r0, #0x1c]
|
||||
ldmfd sp!,{r4-r11,pc}
|
||||
cos_2pi_9:
|
||||
.word 0x620dbe80
|
||||
cos_4pi_9:
|
||||
.word 0x163a1a80
|
||||
cos_pi_9:
|
||||
.word 0x7847d900
|
||||
cos_5pi_9:
|
||||
.word 0x87b82700
|
||||
cos_8pi_9:
|
||||
.word 0xd438af00
|
||||
cos_11pi_18:
|
||||
.word 0xadb92280
|
||||
cos_13pi_18:
|
||||
.word 0x91261480
|
||||
cos_17pi_18:
|
||||
.word 0x81f1d200
|
||||
cos_pi_6:
|
||||
.word 0x6ed9eb80
|
||||
|
||||
|
|
@ -0,0 +1,357 @@
|
|||
@ ------------------------------------------------------------------
|
||||
@ Copyright (C) 1998-2009 PacketVideo
|
||||
@
|
||||
@ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ you may not use this file except in compliance with the License.
|
||||
@ You may obtain a copy of the License at
|
||||
@
|
||||
@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
@
|
||||
@ Unless required by applicable law or agreed to in writing, software
|
||||
@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
@ express or implied.
|
||||
@ See the License for the specific language governing permissions
|
||||
@ and limitations under the License.
|
||||
@ -------------------------------------------------------------------
|
||||
|
||||
@
|
||||
@
|
||||
@ Filename: pvmp3_dct_18_gcc.s
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
@ REVISION HISTORY
|
||||
@
|
||||
@
|
||||
@ Who: Date: MM/DD/YYYY
|
||||
@ Description:
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.arm
|
||||
|
||||
.align 4
|
||||
|
||||
.text
|
||||
|
||||
.extern pvmp3_dct_9
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_mdct_18
|
||||
|
||||
pvmp3_mdct_18:
|
||||
stmfd sp!,{r4-r11,lr}
|
||||
mov r7,r2
|
||||
adr r2,constdata$1
|
||||
mov r6,r1
|
||||
add r3,r2,#0x24
|
||||
add r12,r3,#0x44
|
||||
add r1,r0,#0x44
|
||||
mov r5,r0
|
||||
|
||||
@ for ( i=9@ i!=0@ i--)
|
||||
@ {
|
||||
|
||||
mov r4,#9
|
||||
Loop_1:
|
||||
|
||||
@ tmp = *(pt_vec)
|
||||
@ tmp1 = *(pt_vec_o)
|
||||
|
||||
ldr lr,[r0] @@ tmp == lr
|
||||
ldr r8,[r3],#4 @@ tmp1 == r8
|
||||
|
||||
@ tmp = fxp_mul32_Q32( tmp<<1, *(pt_cos++ ))
|
||||
@ tmp1 = fxp_mul32_Q27( tmp1, *(pt_cos_x--))
|
||||
|
||||
mov lr,lr,lsl #1
|
||||
smull r10,lr,r8,lr
|
||||
ldr r8,[r12],#-4
|
||||
ldr r9,[r1]
|
||||
subs r4,r4,#1
|
||||
smull r9,r10,r8,r9
|
||||
mov r8,r9,lsr #27
|
||||
add r8,r8,r10,lsl #5
|
||||
|
||||
@ *(pt_vec++) = tmp + tmp1
|
||||
@ *(pt_vec_o--) = fxp_mul32_Q28( (tmp - tmp1), *(pt_cos_split++))
|
||||
|
||||
add r9,lr,r8
|
||||
sub r8,lr,r8
|
||||
ldr lr,[r2],#4
|
||||
str r9,[r0],#4
|
||||
smull r8,r9,lr,r8
|
||||
mov lr,r8,lsr #28
|
||||
add lr,lr,r9,lsl #4
|
||||
str lr,[r1],#-4
|
||||
bne Loop_1
|
||||
|
||||
@ }
|
||||
|
||||
mov r0,r5 @@ r0 = vec
|
||||
bl pvmp3_dct_9
|
||||
add r0,r5,#0x24 @@ r0 = &vec[9]
|
||||
bl pvmp3_dct_9
|
||||
|
||||
ldr r0,[r5,#0x20]
|
||||
ldr r2,[r5,#0x40]
|
||||
str r0,[r5,#0x40]
|
||||
ldr r0,[r5,#0x1c]
|
||||
ldr r3,[r5,#0x38]
|
||||
str r0,[r5,#0x38]
|
||||
ldr r1,[r5,#0x18]
|
||||
ldr r0,[r5,#0x30]
|
||||
str r1,[r5,#0x30]
|
||||
ldr r12,[r5,#0x14]
|
||||
ldr r1,[r5,#0x28]
|
||||
str r12,[r5,#0x28]
|
||||
ldr r12,[r5,#0x10]
|
||||
str r12,[r5,#0x20]
|
||||
ldr r12,[r5,#0xc]
|
||||
str r12,[r5,#0x18]
|
||||
ldr r12,[r5,#8]
|
||||
str r12,[r5,#0x10]
|
||||
ldr r12,[r5,#4]
|
||||
str r12,[r5,#8]
|
||||
ldr r12,[r5,#0x24]
|
||||
sub r12,r12,r1
|
||||
str r12,[r5,#4]
|
||||
ldr r12,[r5,#0x2c]
|
||||
sub r1,r12,r1
|
||||
str r1,[r5,#0xc]
|
||||
sub r1,r12,r0
|
||||
str r1,[r5,#0x14]
|
||||
ldr r1,[r5,#0x34]
|
||||
sub r0,r1,r0
|
||||
str r0,[r5,#0x1c]
|
||||
sub r0,r1,r3
|
||||
str r0,[r5,#0x24]
|
||||
ldr r1,[r5,#0x3c]
|
||||
sub r3,r1,r3
|
||||
sub r1,r1,r2
|
||||
str r1,[r5,#0x34]
|
||||
str r3,[r5,#0x2c]
|
||||
ldr r1,[r5,#0x44]
|
||||
sub r1,r1,r2
|
||||
str r1,[r5,#0x3c]
|
||||
ldr r12,[r5,#0]
|
||||
|
||||
Loop_2:
|
||||
add r1,r5,r4,lsl #2
|
||||
ldr r2,[r1,#0x28]
|
||||
ldr r3,[r6,r4,lsl #2]
|
||||
add r0,r0,r2
|
||||
str r0,[r1,#0x28]
|
||||
ldr lr,[r7,r4,lsl #2]
|
||||
ldr r1,[r1,#4]
|
||||
smlal r0,r3,lr,r0
|
||||
mov r0,r2
|
||||
add r2,r12,r1
|
||||
rsb r2,r2,#0
|
||||
str r3,[r5,r4,lsl #2]
|
||||
str r2,[r6,r4,lsl #2]
|
||||
add r4,r4,#1
|
||||
cmp r4,#6
|
||||
mov r12,r1
|
||||
|
||||
blt Loop_2
|
||||
|
||||
ldr r1,[r5,#0x40]
|
||||
ldr r2,[r6,#0x18]
|
||||
add r3,r0,r1
|
||||
str r3,[r5,#0x40]
|
||||
ldr lr,[r7,r4,lsl #2]
|
||||
mov r3,r3,lsl #1
|
||||
ldr r0,[r5,#0x1c]
|
||||
smlal r3,r2,lr,r3
|
||||
add r3,r12,r0
|
||||
str r2,[r5,#0x18]
|
||||
ldr r2,[r6,#0x1c]
|
||||
rsb r3,r3,#0
|
||||
str r3,[r6,#0x18]
|
||||
ldr r3,[r5,#0x20]
|
||||
add r0,r3,r0
|
||||
rsb r0,r0,#0
|
||||
str r0,[r6,#0x1c]
|
||||
ldr r3,[r5,#0x44]
|
||||
ldr r0,[r6,#0x20]
|
||||
add r3,r3,r1
|
||||
mov r1,r2
|
||||
ldr r10,[r7,#0x1c]
|
||||
mov r2,r3,lsl #1
|
||||
smlal r12,r1,r10,r2
|
||||
str r1,[r5,#0x1c]
|
||||
ldr r1,[r5,#0x20]
|
||||
ldr r3,[r5,#0x24]
|
||||
add r1,r1,r3
|
||||
rsb r1,r1,#0
|
||||
str r1,[r6,#0x20]
|
||||
ldr r1,[r5,#0x44]
|
||||
ldr r3,[r7,#0x20]
|
||||
mov r1,r1,lsl #1
|
||||
smlal r12,r0,r3,r1
|
||||
ldr lr,[r7,#0x24]
|
||||
ldr r3,[r6,#0x24]
|
||||
str r0,[r5,#0x20]
|
||||
smlal r1,r3,lr,r1
|
||||
ldr r0,[r6,#0x40]
|
||||
ldr r12,[r6,#0x44]
|
||||
str r3,[r5,#0x24]
|
||||
ldr r1,[r5,#0x28]
|
||||
ldr r3,[r7,#0x44]
|
||||
mov r1,r1,lsl #1
|
||||
smlal r1,r12,r3,r1
|
||||
ldr r1,[r5,#0x40]
|
||||
str r12,[r5,#0x44]
|
||||
rsb r8,r1,#0
|
||||
str r8,[r5,#0x28]
|
||||
ldr r1,[r5,#0x2c]
|
||||
ldr r3,[r7,#0x40]
|
||||
mov r1,r1,lsl #1
|
||||
smlal r1,r0,r3,r1
|
||||
str r0,[r5,#0x40]
|
||||
ldr r0,[r5,#0x3c]
|
||||
ldr r1,[r6,#0x38]
|
||||
ldr r3,[r6,#0x3c]
|
||||
rsb r9,r0,#0
|
||||
str r9,[r5,#0x2c]
|
||||
ldr r0,[r5,#0x30]
|
||||
ldr r12,[r7,#0x3c]
|
||||
mov r0,r0,lsl #1
|
||||
smlal r0,r3,r12,r0
|
||||
str r3,[r5,#0x3c]
|
||||
ldr r0,[r5,#0x38]
|
||||
rsb r0,r0,#0
|
||||
str r0,[r5,#0x30]
|
||||
ldr r3,[r5,#0x34]
|
||||
ldr r12,[r7,#0x38]
|
||||
mov r3,r3,lsl #1
|
||||
smlal r3,r1,r12,r3
|
||||
mov r0,r0,lsl #1
|
||||
str r1,[r5,#0x38]
|
||||
ldr r4,[r7,#0x34]
|
||||
ldr r1,[r6,#0x34]
|
||||
ldr r3,[r6,#0x30]
|
||||
smlal r0,r1,r4,r0
|
||||
ldr r12,[r6,#0x2c]
|
||||
ldr lr,[r6,#0x28]
|
||||
str r1,[r5,#0x34]
|
||||
ldr r1,[r7,#0x30]
|
||||
mov r0,r9,lsl #1
|
||||
smlal r0,r3,r1,r0
|
||||
mov r0,r8,lsl #1
|
||||
ldr r1,[r7,#0x2c]
|
||||
str r3,[r5,#0x30]
|
||||
smlal r0,r12,r1,r0
|
||||
ldr r0,[r7,#0x28]
|
||||
str r12,[r5,#0x2c]
|
||||
smlal r2,lr,r0,r2
|
||||
str lr,[r5,#0x28]
|
||||
ldr r1,[r6,#4]
|
||||
ldr r12,[r7,#0x48]
|
||||
mov r2,r1,lsl #1
|
||||
ldr r1,[r6,#0x20]
|
||||
ldr r0,[r6,#0]
|
||||
mov r1,r1,lsl #1
|
||||
smull r4,lr,r12,r1
|
||||
ldr r3,[r6,#0x1c]
|
||||
str lr,[r6,#0]
|
||||
ldr r12,[r7,#0x4c]
|
||||
mov r3,r3,lsl #1
|
||||
smull r4,lr,r12,r3
|
||||
mov r0,r0,lsl #1
|
||||
ldr r12,[r7,#0x64]
|
||||
str lr,[r6,#4]
|
||||
smull r4,lr,r12,r2
|
||||
ldr r12,[r7,#0x68]
|
||||
str lr,[r6,#0x1c]
|
||||
smull r4,lr,r12,r0
|
||||
ldr r12,[r7,#0x6c]
|
||||
str lr,[r6,#0x20]
|
||||
smull lr,r0,r12,r0
|
||||
ldr r12,[r7,#0x70]
|
||||
str r0,[r6,#0x24]
|
||||
smull r0,r2,r12,r2
|
||||
ldr r0,[r7,#0x88]
|
||||
str r2,[r6,#0x28]
|
||||
smull r3,r2,r0,r3
|
||||
ldr r0,[r7,#0x8c]
|
||||
str r2,[r6,#0x40]
|
||||
smull r2,r1,r0,r1
|
||||
str r1,[r6,#0x44]
|
||||
ldr r0,[r6,#0x18]
|
||||
ldr lr,[r7,#0x50]
|
||||
mov r1,r0,lsl #1
|
||||
ldr r0,[r6,#0x14]
|
||||
smull r5,r4,lr,r1
|
||||
mov r3,r0,lsl #1
|
||||
ldr r0,[r6,#0x10]
|
||||
mov r12,r0,lsl #1
|
||||
ldr r0,[r6,#0xc]
|
||||
mov r2,r0,lsl #1
|
||||
ldr r0,[r6,#8]
|
||||
str r4,[r6,#8]
|
||||
ldr lr,[r7,#0x54]
|
||||
mov r0,r0,lsl #1
|
||||
smull r5,r4,lr,r3
|
||||
ldr lr,[r7,#0x58]
|
||||
str r4,[r6,#0xc]
|
||||
smull r5,r4,lr,r12
|
||||
ldr lr,[r7,#0x5c]
|
||||
str r4,[r6,#0x10]
|
||||
smull r5,r4,lr,r2
|
||||
ldr lr,[r7,#0x60]
|
||||
str r4,[r6,#0x14]
|
||||
smull r5,r4,lr,r0
|
||||
ldr lr,[r7,#0x74]
|
||||
str r4,[r6,#0x18]
|
||||
smull r4,r0,lr,r0
|
||||
ldr lr,[r7,#0x78]
|
||||
str r0,[r6,#0x2c]
|
||||
smull r0,r2,lr,r2
|
||||
ldr r0,[r7,#0x7c]
|
||||
str r2,[r6,#0x30]
|
||||
smull r12,r2,r0,r12
|
||||
ldr r0,[r7,#0x80]
|
||||
str r2,[r6,#0x34]
|
||||
smull r3,r2,r0,r3
|
||||
ldr r0,[r7,#0x84]
|
||||
str r2,[r6,#0x38]
|
||||
smull r2,r1,r0,r1
|
||||
str r1,[r6,#0x3c]
|
||||
ldmfd sp!,{r4-r11,pc}
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
constdata$1:
|
||||
cosTerms_dct18:
|
||||
.word 0x0807d2b0
|
||||
.word 0x08483ee0
|
||||
.word 0x08d3b7d0
|
||||
.word 0x09c42570
|
||||
.word 0x0b504f30
|
||||
.word 0x0df29440
|
||||
.word 0x12edfb20
|
||||
.word 0x1ee8dd40
|
||||
.word 0x5bca2a00
|
||||
cosTerms_1_ov_cos_phi:
|
||||
.word 0x400f9c00
|
||||
.word 0x408d6080
|
||||
.word 0x418dcb80
|
||||
.word 0x431b1a00
|
||||
.word 0x4545ea00
|
||||
.word 0x48270680
|
||||
.word 0x4be25480
|
||||
.word 0x50ab9480
|
||||
.word 0x56ce4d80
|
||||
.word 0x05ebb630
|
||||
.word 0x06921a98
|
||||
.word 0x0771d3a8
|
||||
.word 0x08a9a830
|
||||
.word 0x0a73d750
|
||||
.word 0x0d4d5260
|
||||
.word 0x127b1ca0
|
||||
.word 0x1ea52b40
|
||||
.word 0x5bb3cc80
|
||||
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
@ ------------------------------------------------------------------
|
||||
@ Copyright (C) 1998-2009 PacketVideo
|
||||
@
|
||||
@ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ you may not use this file except in compliance with the License.
|
||||
@ You may obtain a copy of the License at
|
||||
@
|
||||
@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
@
|
||||
@ Unless required by applicable law or agreed to in writing, software
|
||||
@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
@ express or implied.
|
||||
@ See the License for the specific language governing permissions
|
||||
@ and limitations under the License.
|
||||
@ -------------------------------------------------------------------
|
||||
|
||||
@
|
||||
@
|
||||
@ Filename: pvmp3_polyphase_filter_window.s
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
@ REVISION HISTORY
|
||||
@
|
||||
@
|
||||
@ Who: Date: MM/DD/YYYY
|
||||
@ Description:
|
||||
@
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.arm
|
||||
|
||||
.align 4
|
||||
|
||||
.text
|
||||
|
||||
.extern pqmfSynthWin
|
||||
.hidden pqmfSynthWin
|
||||
|
||||
|
||||
|
||||
@------------------------------------------------------------------------------
|
||||
|
||||
.global pvmp3_polyphase_filter_window
|
||||
|
||||
pvmp3_polyphase_filter_window:
|
||||
stmfd sp!,{r0-r2,r4-r11,lr}
|
||||
|
||||
sub sp,sp,#4
|
||||
adr r2,PolyPh_filter_coeff
|
||||
ldr r1,[r2]
|
||||
add r1,r2
|
||||
ldr r2,[sp,#0xc]
|
||||
|
||||
sub r2,r2,#1
|
||||
mov r10,#1
|
||||
str r2,[sp]
|
||||
|
||||
@ Accumulators r9, r11::> Initialization
|
||||
|
||||
Loop_j:
|
||||
mov r9, #0x20
|
||||
mov r11, #0x20
|
||||
mov r4, #0x10
|
||||
Loop_i:
|
||||
add r2,r4,r10
|
||||
add r3,r0,r2,lsl #2
|
||||
sub r2,r4,r10
|
||||
ldr r5,[r3]
|
||||
ldr lr,[r1]
|
||||
add r12,r0,r2,lsl #2
|
||||
ldr r6,[r12,#0x780]
|
||||
smlal r2,r9,lr,r5
|
||||
smlal r2,r11,lr,r6
|
||||
ldr r2,[r1,#4]
|
||||
ldr r7,[r12,#0x80]
|
||||
smlal r5,r11,r2,r5
|
||||
smull r6,r5,r2,r6
|
||||
sub r9,r9,r5
|
||||
ldr r5,[r1,#8]
|
||||
ldr r8,[r3,#0x700]
|
||||
add r4,r4,#0x200
|
||||
smlal r6,r9,r5,r7
|
||||
smull r6,r2,r5,r8
|
||||
ldr r5,[r1,#0xc]
|
||||
sub r11,r11,r2
|
||||
smlal r8,r9,r5,r8
|
||||
smlal r7,r11,r5,r7
|
||||
ldr r5,[r3,#0x100]
|
||||
ldr r2,[r1,#0x10]
|
||||
ldr r6,[r12,#0x680]
|
||||
smlal lr,r9,r2,r5
|
||||
smlal lr,r11,r2,r6
|
||||
ldr r2,[r1,#0x14]
|
||||
ldr r7,[r12,#0x180]
|
||||
smlal r5,r11,r2,r5
|
||||
smull r6,r5,r2,r6
|
||||
ldr r6,[r1,#0x18]
|
||||
ldr r8,[r3,#0x600]
|
||||
sub r9,r9,r5
|
||||
smlal r5,r9,r6,r7
|
||||
smull r2,r5,r6,r8
|
||||
ldr r6,[r1,#0x1c]
|
||||
sub r11,r11,r5
|
||||
smlal r8,r9,r6,r8
|
||||
ldr r2,[r1,#0x20]
|
||||
ldr r5,[r3,#0x200]
|
||||
smlal r7,r11,r6,r7
|
||||
ldr r6,[r12,#0x580]
|
||||
smlal lr,r9,r2,r5
|
||||
smlal lr,r11,r2,r6
|
||||
ldr r2,[r1,#0x24]
|
||||
ldr r7,[r12,#0x280]
|
||||
smlal r5,r11,r2,r5
|
||||
smull r6,r5,r2,r6
|
||||
ldr r6,[r1,#0x28]
|
||||
ldr r8,[r3,#0x500]
|
||||
sub r9,r9,r5
|
||||
smlal r5,r9,r6,r7
|
||||
smull r2,r5,r6,r8
|
||||
ldr r6,[r1,#0x2c]
|
||||
sub r11,r11,r5
|
||||
|
||||
smlal r8,r9,r6,r8
|
||||
smlal r7,r11,r6,r7
|
||||
ldr r5,[r3,#0x300]
|
||||
ldr r8,[r1,#0x30]
|
||||
ldr r6,[r12,#0x480]
|
||||
smlal r7,r9,r8,r5
|
||||
smlal r7,r11,r8,r6
|
||||
ldr r8,[r1,#0x34]
|
||||
ldr r12,[r12,#0x380]
|
||||
smlal r5,r11,r8,r5
|
||||
smull r6,r5,r8,r6
|
||||
ldr r6,[r1,#0x38]
|
||||
|
||||
|
||||
ldr r3,[r3,#0x400]
|
||||
sub r9,r9,r5
|
||||
smlal r7,r9,r6,r12
|
||||
smull r8,r7,r6,r3
|
||||
cmp r4,#0x210
|
||||
sub r11,r11,r7
|
||||
|
||||
ldr r2,[r1,#0x3c]
|
||||
add r1,r1,#0x40
|
||||
smlal r3,r9,r2,r3
|
||||
smlal r12,r11,r2,r12
|
||||
|
||||
blt Loop_i
|
||||
|
||||
mov r3,r9, asr #6
|
||||
mov r4,r3, asr #15
|
||||
teq r4,r3, asr #31
|
||||
ldr r12,LOW_16BITS
|
||||
ldr r2,[sp]
|
||||
eorne r3,r12,r3,asr #31
|
||||
ldr r4,[sp,#8]
|
||||
mov r2,r10,lsl r2
|
||||
add r4,r4,r2,lsl #1
|
||||
strh r3,[r4]
|
||||
|
||||
mov r3,r11,asr #6
|
||||
mov r4,r3,asr #15
|
||||
teq r4,r3,asr #31
|
||||
eorne r3,r12,r3,asr #31
|
||||
ldr r12,[sp,#0xc]
|
||||
ldr r11,[sp,#8]
|
||||
rsb r2,r2,r12,lsl #5
|
||||
add r2,r11,r2,lsl #1
|
||||
strh r3,[r2]
|
||||
|
||||
add r10,r10,#1
|
||||
cmp r10,#0x10
|
||||
blt Loop_j
|
||||
|
||||
@ Accumulators r4, r5 Initialization
|
||||
|
||||
mov r4,#0x20
|
||||
mov r5,#0x20
|
||||
mov r3,#0x10
|
||||
PolyPh_filter_loop2:
|
||||
add r2,r0,r3,lsl #2
|
||||
ldr r12,[r2]
|
||||
ldr r8,[r1]
|
||||
ldr r6,[r2,#0x80]
|
||||
smlal r12,r4,r8,r12
|
||||
ldr r12,[r1,#4]
|
||||
ldr r7,[r2,#0x40]
|
||||
smlal r6,r4,r12,r6
|
||||
|
||||
ldr r12,[r1,#8]
|
||||
ldr r6,[r2,#0x180]
|
||||
smlal r7,r5,r12,r7
|
||||
ldr r12,[r2,#0x100]
|
||||
ldr r7,[r1,#0xc]
|
||||
ldr r2,[r2,#0x140]
|
||||
smlal r12,r4,r7,r12
|
||||
ldr r12,[r1,#0x10]
|
||||
add r3,r3,#0x80
|
||||
smlal r6,r4,r12,r6
|
||||
ldr r6,[r1,#0x14]
|
||||
cmp r3,#0x210
|
||||
smlal r2,r5,r6,r2
|
||||
add r1,r1,#0x18
|
||||
|
||||
blt PolyPh_filter_loop2
|
||||
mov r0,r4,asr #6
|
||||
mov r2,r0,asr #15
|
||||
teq r2,r0,asr #31
|
||||
ldrne r12,LOW_16BITS
|
||||
ldr r1,[sp,#8]
|
||||
eorne r0,r12,r0,asr #31
|
||||
strh r0,[r1,#0]
|
||||
mov r0,r5,asr #6
|
||||
mov r2,r0,asr #15
|
||||
teq r2,r0,asr #31
|
||||
ldrne r12,LOW_16BITS
|
||||
ldr r2,[sp]
|
||||
mov r1,#0x10
|
||||
eorne r0,r12,r0,asr #31
|
||||
ldr r12,[sp,#8]
|
||||
mov r1,r1,lsl r2
|
||||
add r1,r12,r1,lsl #1
|
||||
strh r0,[r1]
|
||||
add sp,sp,#0x10
|
||||
ldmfd sp!,{r4-r11,pc}
|
||||
|
||||
PolyPh_filter_coeff:
|
||||
.word pqmfSynthWin-PolyPh_filter_coeff
|
||||
LOW_16BITS:
|
||||
.word 0x00007fff
|
||||
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: mp3_mem_funcs.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef MP3_MEM_FUNCS_H
|
||||
#define MP3_MEM_FUNCS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES AND SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#define pv_memset(to, c, n) memset(to, c, n)
|
||||
|
||||
|
||||
#define pv_memcpy(to, from, n) memcpy(to, from, n)
|
||||
#define pv_memmove(to, from, n) memmove(to, from, n)
|
||||
#define pv_memcmp(p, q, n) memcmp(p, q, n)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pv_mp3_huffman.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PV_MP3_HUFFMAN_H
|
||||
#define PV_MP3_HUFFMAN_H
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
#include "s_tmp3dec_file.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES AND SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int32 pvmp3_huffman_parsing(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
granuleInfo *grInfo,
|
||||
tmp3dec_file *pVars,
|
||||
int32 part2_start,
|
||||
mp3Header *info);
|
||||
|
||||
|
||||
void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
void pvmp3_huffman_pair_decoding(struct huffcodetab *h,
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
|
||||
void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h,
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pv_mp3dec_fxd_op.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This file select the associated fixed point functions with the OS/ARCH.
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PV_MP3DEC_FXD_OP_H
|
||||
#define PV_MP3DEC_FXD_OP_H
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
|
||||
|
||||
#include "pv_mp3dec_fxd_op_arm.h"
|
||||
|
||||
#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
|
||||
|
||||
#include "pv_mp3dec_fxd_op_arm_gcc.h"
|
||||
|
||||
#elif (defined(PV_ARM_MSC_EVC_V5)||defined(PV_ARM_MSC_EVC_V4))
|
||||
|
||||
#include "pv_mp3dec_fxd_op_msc_evc.h"
|
||||
|
||||
#else
|
||||
|
||||
#ifndef C_EQUIVALENT
|
||||
#define C_EQUIVALENT
|
||||
#endif
|
||||
|
||||
#include "pv_mp3dec_fxd_op_c_equivalent.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* PV_MP3DEC_FXD_OP_H */
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./cpp/include/pv_mp3dec_fxd_op_arm.h
|
||||
|
||||
Date: 08/20/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This file select the associated fixed point functions with the OS/ARCH.
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PV_MP3DEC_FXD_OP_ARM
|
||||
#define PV_MP3DEC_FXD_OP_ARM
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
|
||||
#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q30(const Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
mov result64_lo, result64_lo, lsr #30
|
||||
add result64_hi, result64_lo, result64_hi, asl #2
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mac32_Q30(const Int32 L_var1, const Int32 L_var2, Int32 L_add)
|
||||
{
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
add L_add, L_add, result64_hi, asl #2
|
||||
add L_add, L_add, result64_lo, lsr #30
|
||||
}
|
||||
return (L_add);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define Qfmt_31(a) (Int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
|
||||
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q32(Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
Int32 result64_hi;
|
||||
__asm
|
||||
{
|
||||
smull L_var1, result64_hi, L_var2, L_var1
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mul32_Q28(const Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
mov result64_lo, result64_lo, lsr #28
|
||||
add result64_hi, result64_lo, result64_hi, asl #4
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q27(const Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
mov result64_lo, result64_lo, lsr #27
|
||||
add result64_hi, result64_lo, result64_hi, asl #5
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q26(Int32 L_var1, Int32 L_var2)
|
||||
{
|
||||
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
mov result64_lo, result64_lo, lsr #26
|
||||
add result64_hi, result64_lo, result64_hi, asl #6
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline Int32 fxp_mac32_Q32(Int32 L_add, Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
smlal L_var1, L_add, L_var2, L_var1
|
||||
}
|
||||
return L_add;
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_msb32_Q32(Int32 L_sub, Int32 L_var1, Int32 L_var2)
|
||||
{
|
||||
|
||||
__asm
|
||||
{
|
||||
smull L_var2, L_var1, L_var2, L_var1
|
||||
sub L_sub, L_sub, L_var1
|
||||
}
|
||||
return L_sub;
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q29(const Int32 L_var1, const Int32 L_var2)
|
||||
{
|
||||
Int32 result64_hi;
|
||||
Int32 result64_lo;
|
||||
__asm
|
||||
{
|
||||
smull result64_lo, result64_hi, L_var2, L_var1
|
||||
mov result64_lo, result64_lo, lsr #29
|
||||
add result64_hi, result64_lo, result64_hi, asl #3
|
||||
}
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
__inline int32 pv_abs(int32 a)
|
||||
{
|
||||
Int32 b;
|
||||
/*
|
||||
b = a - (a<0);
|
||||
a = b ^ sign(b)
|
||||
*/
|
||||
__asm
|
||||
{
|
||||
sub b, a, a, lsr #31
|
||||
eor a, b, b, asr #31
|
||||
}
|
||||
return (a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* PV_MP3DEC_FXD_OP_ARM */
|
||||
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./cpp/include/pv_mp3dec_fxd_op_arm_gcc.h
|
||||
|
||||
Date: 08/20/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This file select the associated fixed point functions with the OS/ARCH.
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PV_MP3DEC_FXD_OP_ARM_GCC_H
|
||||
#define PV_MP3DEC_FXD_OP_ARM_GCC_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
|
||||
#if (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
|
||||
|
||||
#define Qfmt_31(a) (int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
|
||||
|
||||
#define Qfmt15(x) (Int16)(x*((int32)1<<15) + (x>=0?0.5F:-0.5F))
|
||||
|
||||
static inline int32 fxp_mul32_Q30(const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"mov %1, %1, lsr #30\n\t"
|
||||
"add %0, %1, %0, asl #2"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
static inline int32 fxp_mac32_Q30(const int32 a, const int32 b, int32 L_add)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
register int32 rc = (int32)L_add;
|
||||
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"add %4, %4, %0, asl #2\n\t"
|
||||
"add %0, %4, %1, lsr #30"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb),
|
||||
"r"(rc));
|
||||
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline int32 fxp_mul32_Q32(const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile(
|
||||
"smull %1, %0, %2, %3"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
static inline int32 fxp_mul32_Q29(const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"mov %1, %1, lsr #29\n\t"
|
||||
"add %0, %1, %0, asl #3"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
return (result64_hi);
|
||||
|
||||
}
|
||||
|
||||
static inline int32 fxp_mul32_Q28(const int32 a, const int32 b)
|
||||
{
|
||||
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"mov %1, %1, lsr #28\n\t"
|
||||
"add %0, %1, %0, asl #4"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
return (result64_hi);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline int32 fxp_mul32_Q27(const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"mov %1, %1, lsr #27\n\t"
|
||||
"add %0, %1, %0, asl #5"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
return (result64_hi);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline int32 fxp_mul32_Q26(const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"mov %1, %1, lsr #26\n\t"
|
||||
"add %0, %1, %0, asl #6"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb));
|
||||
return (result64_hi);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline int32 fxp_mac32_Q32(int32 L_add, const int32 a, const int32 b)
|
||||
{
|
||||
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
register int32 rc = (int32)L_add;
|
||||
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"add %0, %0, %4"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb),
|
||||
"r"(rc));
|
||||
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
static inline int32 fxp_msb32_Q32(int32 L_sub, const int32 a, const int32 b)
|
||||
{
|
||||
int32 result64_hi;
|
||||
int32 result64_lo;
|
||||
register int32 ra = (int32)a;
|
||||
register int32 rb = (int32)b;
|
||||
register int32 rc = (int32)L_sub;
|
||||
|
||||
asm volatile("smull %1, %0, %2, %3\n\t"
|
||||
"sub %0, %4, %0"
|
||||
: "=&r*i"(result64_hi),
|
||||
"=&r*i"(result64_lo)
|
||||
: "r"(ra),
|
||||
"r"(rb),
|
||||
"r"(rc));
|
||||
|
||||
|
||||
return (result64_hi);
|
||||
}
|
||||
|
||||
|
||||
__inline int32 pv_abs(int32 x)
|
||||
{
|
||||
register int32 z;
|
||||
register int32 y;
|
||||
register int32 ra = x;
|
||||
asm volatile(
|
||||
"sub %0, %2, %2, lsr #31\n\t"
|
||||
"eor %1, %0, %0, asr #31"
|
||||
: "=&r*i"(z),
|
||||
"=&r*i"(y)
|
||||
: "r"(ra));
|
||||
|
||||
return (y);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* PV_MP3DEC_FXD_OP_ARM_GCC_H */
|
||||
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./cpp/include/pv_mp3dec_fxd_op_c_equivalent.h
|
||||
|
||||
Date: 12/06/2005
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PV_MP3DEC_FXD_OP_C_EQUIVALENT
|
||||
#define PV_MP3DEC_FXD_OP_C_EQUIVALENT
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#define Qfmt_31(a) (Int32)((float)a*0x7FFFFFFF)
|
||||
|
||||
#define Qfmt15(x) (Int16)(x*((Int32)1<<15) + (x>=0?0.5F:-0.5F))
|
||||
|
||||
|
||||
|
||||
__inline int32 pv_abs(int32 a)
|
||||
{
|
||||
int32 b = (a < 0) ? -a : a;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q30(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 30);
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mac32_Q30(const Int32 a, const Int32 b, Int32 L_add)
|
||||
{
|
||||
return (L_add + (Int32)(((int64)(a) * b) >> 30));
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mul32_Q32(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 32);
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q28(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 28);
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mul32_Q27(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 27);
|
||||
}
|
||||
|
||||
__inline Int32 fxp_mul32_Q26(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 26);
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mac32_Q32(Int32 L_add, const Int32 a, const Int32 b)
|
||||
{
|
||||
return (L_add + (Int32)(((int64)(a) * b) >> 32));
|
||||
}
|
||||
|
||||
__inline Int32 fxp_msb32_Q32(Int32 L_sub, const Int32 a, const Int32 b)
|
||||
{
|
||||
return (L_sub - ((Int32)(((int64)(a) * b) >> 32)));
|
||||
}
|
||||
|
||||
|
||||
__inline Int32 fxp_mul32_Q29(const Int32 a, const Int32 b)
|
||||
{
|
||||
return (Int32)(((int64)(a) * b) >> 29);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* PV_MP3DEC_FXD_OP_C_EQUIVALENT */
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./cpp/include/pv_mp3dec_fxd_op_msc_evc.h
|
||||
|
||||
Date: 08/20/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This file select the associated fixed point functions with the OS/ARCH.
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PV_MP3DEC_FXD_OP_MSC_EVC_H
|
||||
#define PV_MP3DEC_FXD_OP_MSC_EVC_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
|
||||
#if (defined(PV_ARM_MSC_EVC_V5)||defined(PV_ARM_MSC_EVC_V4))
|
||||
#include "armintr.h"
|
||||
#include "cmnintrin.h"
|
||||
|
||||
|
||||
__inline int32 fxp_mul32_Q30(const int32 a, const int32 b)
|
||||
{
|
||||
return (int32)(((int64)(a) * b) >> 30);
|
||||
}
|
||||
|
||||
|
||||
__inline int32 fxp_mac32_Q30(const int32 a, const int32 b, int32 L_add)
|
||||
{
|
||||
return (L_add + (int32)(((int64)(a) * b) >> 30));
|
||||
}
|
||||
|
||||
|
||||
#define Qfmt_31(a) (int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
|
||||
|
||||
#define Qfmt15(x) (Int16)(x*((int32)1<<15) + (x>=0?0.5F:-0.5F))
|
||||
|
||||
#define fxp_mul32_Q32( a, b) _MulHigh( b, a)
|
||||
|
||||
|
||||
|
||||
__inline int32 fxp_mul32_Q28(const int32 a, const int32 b)
|
||||
{
|
||||
return (int32)(((int64)(a) * b) >> 28);
|
||||
}
|
||||
|
||||
|
||||
__inline int32 fxp_mul32_Q27(const int32 a, const int32 b)
|
||||
{
|
||||
return (int32)(((int64)(a) * b) >> 27);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline int32 fxp_mul32_Q26(const int32 a, const int32 b)
|
||||
{
|
||||
return (int32)(((int64)(a) * b) >> 26);
|
||||
}
|
||||
|
||||
|
||||
__inline int32 fxp_mac32_Q32(int32 L_add, const int32 a, const int32 b)
|
||||
{
|
||||
return (L_add + _MulHigh(b, a));
|
||||
}
|
||||
|
||||
|
||||
__inline int32 fxp_msb32_Q32(int32 L_sub, const int32 a, const int32 b)
|
||||
{
|
||||
return (L_sub - _MulHigh(b, a));
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline int32 fxp_mul32_Q29(const int32 a, const int32 b)
|
||||
{
|
||||
return (int32)(((int64)(a) * b) >> 29);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__inline int32 pv_abs(int32 a)
|
||||
{
|
||||
int32 b = (a < 0) ? -a : a;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* PV_MP3DEC_FXD_OP_MSC_EVC_H */
|
||||
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_alias_reduction.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 *input_buffer, Ptr to fequency lines of current channel
|
||||
struct gr_info_s *gr_info, structure with granuke information for the
|
||||
input
|
||||
mp3Header *info mp3 header information
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Alias Reduction
|
||||
|
||||
|
||||
|
||||
Alias reduction before processing by the IMDCT
|
||||
|
||||
Csi +
|
||||
>---------0---------0-------->
|
||||
\ / -
|
||||
Cai \ /
|
||||
\ /
|
||||
\ /
|
||||
\
|
||||
/ \
|
||||
Cai / \
|
||||
/ \ +
|
||||
>--------0---------0---------->
|
||||
Csi +
|
||||
|
||||
Aliasing Butterfly
|
||||
Alias reduction is not applied to short blocks
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
1 ci
|
||||
csi = ---------------- csi = ----------------
|
||||
sqrt( 1 + (ci^2)) sqrt( 1 + (ci^2))
|
||||
|
||||
|
||||
ci = -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_alias_reduction.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define NUM_BUTTERFLIES 8
|
||||
|
||||
#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 c_signal [ NUM_BUTTERFLIES ] =
|
||||
{
|
||||
|
||||
Q31_fmt(0.85749292571254f), Q31_fmt(0.88174199731771f),
|
||||
Q31_fmt(0.94962864910273f), Q31_fmt(0.98331459249179f),
|
||||
Q31_fmt(0.99551781606759f), Q31_fmt(0.99916055817815f),
|
||||
Q31_fmt(0.99989919524445f), Q31_fmt(0.99999315507028f)
|
||||
|
||||
};
|
||||
|
||||
|
||||
const int32 c_alias [ NUM_BUTTERFLIES ] =
|
||||
{
|
||||
|
||||
Q31_fmt(-0.51449575542753f), Q31_fmt(-0.47173196856497f),
|
||||
Q31_fmt(-0.31337745420390f), Q31_fmt(-0.18191319961098f),
|
||||
Q31_fmt(-0.09457419252642f), Q31_fmt(-0.04096558288530f),
|
||||
Q31_fmt(-0.01419856857247f), Q31_fmt(-0.00369997467376f)
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_alias_reduction(int32 *input_buffer, /* Ptr to spec values of current channel */
|
||||
granuleInfo *gr_info,
|
||||
int32 *used_freq_lines,
|
||||
mp3Header *info)
|
||||
{
|
||||
int32 *ptr1;
|
||||
int32 *ptr2;
|
||||
int32 *ptr3;
|
||||
int32 *ptr4;
|
||||
const int32 *ptr_csi;
|
||||
const int32 *ptr_csa;
|
||||
int32 sblim;
|
||||
|
||||
int32 i, j;
|
||||
|
||||
*used_freq_lines = fxp_mul32_Q32(*used_freq_lines << 16, (int32)(0x7FFFFFFF / (float)18 - 1.0f)) >> 15;
|
||||
|
||||
|
||||
if (gr_info->window_switching_flag && gr_info->block_type == 2)
|
||||
{
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
sblim = ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2)) ? 3 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return; /* illegal parameter */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sblim = *used_freq_lines + 1;
|
||||
|
||||
if (sblim > SUBBANDS_NUMBER - 1)
|
||||
{
|
||||
sblim = SUBBANDS_NUMBER - 1; /* default */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ptr3 = &input_buffer[17];
|
||||
ptr4 = &input_buffer[18];
|
||||
ptr_csi = c_signal;
|
||||
ptr_csa = c_alias;
|
||||
|
||||
/* NUM_BUTTERFLIES (=8) butterflies between each pair of sub-bands*/
|
||||
|
||||
for (i = NUM_BUTTERFLIES >> 1; i != 0; i--)
|
||||
{
|
||||
int32 csi1 = *ptr_csi++;
|
||||
int32 csi2 = *ptr_csi++;
|
||||
int32 csa1 = *ptr_csa++;
|
||||
int32 csa2 = *ptr_csa++;
|
||||
|
||||
ptr1 = ptr3;
|
||||
ptr3 -= 2;
|
||||
ptr2 = ptr4;
|
||||
ptr4 += 2;
|
||||
|
||||
/*
|
||||
* "sblim" alias-reduction operations between each
|
||||
* pair of sub-bands
|
||||
*/
|
||||
|
||||
for (j = sblim >> 1; j != 0; j--)
|
||||
{
|
||||
int32 y = *ptr2;
|
||||
int32 x = *ptr1 << 1;
|
||||
*ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
|
||||
*ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
|
||||
y = *ptr2;
|
||||
x = *ptr1 << 1;
|
||||
*ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
|
||||
*ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
|
||||
ptr1 += 19;
|
||||
ptr2 += 17;
|
||||
y = *ptr2;
|
||||
x = *ptr1 << 1;
|
||||
*ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
|
||||
*ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
|
||||
y = *ptr2;
|
||||
x = *ptr1 << 1;
|
||||
*ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
|
||||
*ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
|
||||
ptr1 += 19;
|
||||
ptr2 += 17;
|
||||
|
||||
}
|
||||
|
||||
if (sblim & 1)
|
||||
{
|
||||
int32 x = *ptr1 << 1;
|
||||
int32 y = *ptr2;
|
||||
*ptr1-- = fxp_msb32_Q32(fxp_mul32_Q32(x, csi1), y << 1, csa1);
|
||||
*ptr2++ = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi1), x, csa1);
|
||||
|
||||
x = *ptr1 << 1;
|
||||
y = *ptr2;
|
||||
*ptr1 = fxp_msb32_Q32(fxp_mul32_Q32(x, csi2), y << 1, csa2);
|
||||
*ptr2 = fxp_mac32_Q32(fxp_mul32_Q32(y << 1, csi2), x, csa2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_alias_reduction.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_ALIAS_REDUCTION_H
|
||||
#define PVMP3_ALIAS_REDUCTION_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_alias_reduction(int32 *input_buffer,
|
||||
granuleInfo *gr_info,
|
||||
int32 *used_freq_lines,
|
||||
mp3Header *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_crc.cpp
|
||||
|
||||
Functions:
|
||||
getbits_crc
|
||||
calculate_crc
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
getbits_crc
|
||||
|
||||
Input
|
||||
tbits *inputStream, bit stream structure
|
||||
int32 neededBits, number of bits to read from the bit stream
|
||||
uint32 *crc, memory location holding calculated crc value
|
||||
uint32 crc_enabled flag to enable/disable crc checking
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
calculate_crc
|
||||
|
||||
Input
|
||||
uint32 data, data vector
|
||||
uint32 length, number of element upon the crc will be calculated
|
||||
uint32 *crc, memory location holding calculated crc value
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "pvmp3_crc.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint32 getbits_crc(tmp3Bits *inputStream, /* bit stream structure */
|
||||
int32 neededBits, /* number of bits to read from the bit stream */
|
||||
uint32 *crc,
|
||||
uint32 crc_enabled)
|
||||
{
|
||||
uint32 bits = getNbits(inputStream, neededBits);
|
||||
|
||||
if (crc_enabled)
|
||||
{
|
||||
calculate_crc(bits, neededBits, crc);
|
||||
}
|
||||
return(bits);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void calculate_crc(uint32 data,
|
||||
uint32 length,
|
||||
uint32 *crc)
|
||||
{
|
||||
uint32 carry;
|
||||
uint32 masking = 1 << length;
|
||||
|
||||
while ((masking >>= 1))
|
||||
{
|
||||
carry = *crc & 0x8000;
|
||||
*crc <<= 1;
|
||||
if (!carry ^ !(data & masking))
|
||||
{
|
||||
*crc ^= CRC16_POLYNOMIAL;
|
||||
}
|
||||
}
|
||||
*crc &= 0xffff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_crc.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_CRC_H
|
||||
#define PVMP3_CRC_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define CRC16_POLYNOMIAL 0x8005
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
uint32 getbits_crc(tmp3Bits *inputStream,
|
||||
int32 neededBits,
|
||||
uint32 *crc,
|
||||
uint32 crc_enabled);
|
||||
|
||||
|
||||
void calculate_crc(uint32 data,
|
||||
uint32 length,
|
||||
uint32 *crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,410 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dct_16.cpp
|
||||
|
||||
Functions:
|
||||
dct_16
|
||||
pv_merge_in_place_N32
|
||||
pv_split
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
dct_16
|
||||
|
||||
Input
|
||||
int32 vec[], input vector length 16
|
||||
Int flag processing direction: forward (1), backward ( 0)
|
||||
Returns
|
||||
|
||||
int32 vec[], dct length 16
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
pv_merge_in_place_N32
|
||||
|
||||
Input
|
||||
int32 vec[], input vector length 16
|
||||
|
||||
Returns
|
||||
|
||||
int32 vec[], merged output of two dct 16 to create a dct 32
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
pv_split
|
||||
|
||||
Input
|
||||
int32 vec[], input vector length 16
|
||||
|
||||
Returns
|
||||
|
||||
int32 vec[], splitted even/odd and pre processing rotation
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
dct 16 and tools to assemble a dct32 output
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) )
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dct_16.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt(a) (int32)(a*((int32)1<<27))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 CosTable_dct32[16] =
|
||||
{
|
||||
Qfmt_31(0.50060299823520F) , Qfmt_31(0.50547095989754F) ,
|
||||
Qfmt_31(0.51544730992262F) , Qfmt_31(0.53104259108978F) ,
|
||||
Qfmt_31(0.55310389603444F) , Qfmt_31(0.58293496820613F) ,
|
||||
Qfmt_31(0.62250412303566F) , Qfmt_31(0.67480834145501F) ,
|
||||
Qfmt_31(0.74453627100230F) , Qfmt_31(0.83934964541553F) ,
|
||||
|
||||
Qfmt(0.97256823786196F) , Qfmt(1.16943993343288F) ,
|
||||
Qfmt(1.48416461631417F) , Qfmt(2.05778100995341F) ,
|
||||
Qfmt(3.40760841846872F) , Qfmt(10.19000812354803F)
|
||||
};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_dct_16(int32 vec[], int32 flag)
|
||||
{
|
||||
int32 tmp0;
|
||||
int32 tmp1;
|
||||
int32 tmp2;
|
||||
int32 tmp3;
|
||||
int32 tmp4;
|
||||
int32 tmp5;
|
||||
int32 tmp6;
|
||||
int32 tmp7;
|
||||
int32 tmp_o0;
|
||||
int32 tmp_o1;
|
||||
int32 tmp_o2;
|
||||
int32 tmp_o3;
|
||||
int32 tmp_o4;
|
||||
int32 tmp_o5;
|
||||
int32 tmp_o6;
|
||||
int32 tmp_o7;
|
||||
int32 itmp_e0;
|
||||
int32 itmp_e1;
|
||||
int32 itmp_e2;
|
||||
|
||||
/* split input vector */
|
||||
|
||||
tmp_o0 = fxp_mul32_Q32((vec[ 0] - vec[15]), Qfmt_31(0.50241928618816F));
|
||||
tmp0 = vec[ 0] + vec[15];
|
||||
|
||||
tmp_o7 = fxp_mul32_Q32((vec[ 7] - vec[ 8]) << 3, Qfmt_31(0.63764357733614F));
|
||||
tmp7 = vec[ 7] + vec[ 8];
|
||||
|
||||
itmp_e0 = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.50979557910416F));
|
||||
tmp7 = (tmp0 + tmp7);
|
||||
|
||||
tmp_o1 = fxp_mul32_Q32((vec[ 1] - vec[14]), Qfmt_31(0.52249861493969F));
|
||||
tmp1 = vec[ 1] + vec[14];
|
||||
|
||||
tmp_o6 = fxp_mul32_Q32((vec[ 6] - vec[ 9]) << 1, Qfmt_31(0.86122354911916F));
|
||||
tmp6 = vec[ 6] + vec[ 9];
|
||||
|
||||
|
||||
|
||||
itmp_e1 = (tmp1 + tmp6);
|
||||
tmp6 = fxp_mul32_Q32((tmp1 - tmp6), Qfmt_31(0.60134488693505F));
|
||||
|
||||
|
||||
|
||||
tmp_o2 = fxp_mul32_Q32((vec[ 2] - vec[13]), Qfmt_31(0.56694403481636F));
|
||||
tmp2 = vec[ 2] + vec[13];
|
||||
tmp_o5 = fxp_mul32_Q32((vec[ 5] - vec[10]) << 1, Qfmt_31(0.53033884299517F));
|
||||
tmp5 = vec[ 5] + vec[10];
|
||||
|
||||
itmp_e2 = (tmp2 + tmp5);
|
||||
tmp5 = fxp_mul32_Q32((tmp2 - tmp5), Qfmt_31(0.89997622313642F));
|
||||
|
||||
tmp_o3 = fxp_mul32_Q32((vec[ 3] - vec[12]), Qfmt_31(0.64682178335999F));
|
||||
tmp3 = vec[ 3] + vec[12];
|
||||
tmp_o4 = fxp_mul32_Q32((vec[ 4] - vec[11]), Qfmt_31(0.78815462345125F));
|
||||
tmp4 = vec[ 4] + vec[11];
|
||||
|
||||
tmp1 = (tmp3 + tmp4);
|
||||
tmp4 = fxp_mul32_Q32((tmp3 - tmp4) << 2, Qfmt_31(0.64072886193538F));
|
||||
|
||||
/* split even part of tmp_e */
|
||||
|
||||
tmp0 = (tmp7 + tmp1);
|
||||
tmp1 = fxp_mul32_Q32((tmp7 - tmp1), Qfmt_31(0.54119610014620F));
|
||||
|
||||
tmp3 = fxp_mul32_Q32((itmp_e1 - itmp_e2) << 1, Qfmt_31(0.65328148243819F));
|
||||
tmp7 = (itmp_e1 + itmp_e2);
|
||||
|
||||
vec[ 0] = (tmp0 + tmp7) >> 1;
|
||||
vec[ 8] = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.70710678118655F));
|
||||
tmp0 = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
|
||||
vec[ 4] = tmp1 + tmp3 + tmp0;
|
||||
vec[12] = tmp0;
|
||||
|
||||
/* split odd part of tmp_e */
|
||||
|
||||
tmp1 = fxp_mul32_Q32((itmp_e0 - tmp4) << 1, Qfmt_31(0.54119610014620F));
|
||||
tmp7 = itmp_e0 + tmp4;
|
||||
|
||||
tmp3 = fxp_mul32_Q32((tmp6 - tmp5) << 2, Qfmt_31(0.65328148243819F));
|
||||
tmp6 += tmp5;
|
||||
|
||||
tmp4 = fxp_mul32_Q32((tmp7 - tmp6) << 1, Qfmt_31(0.70710678118655F));
|
||||
tmp6 += tmp7;
|
||||
tmp7 = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
|
||||
|
||||
tmp1 += tmp3 + tmp7;
|
||||
vec[ 2] = tmp1 + tmp6;
|
||||
vec[ 6] = tmp1 + tmp4;
|
||||
vec[10] = tmp7 + tmp4;
|
||||
vec[14] = tmp7;
|
||||
|
||||
|
||||
// dct8;
|
||||
|
||||
tmp1 = fxp_mul32_Q32((tmp_o0 - tmp_o7) << 1, Qfmt_31(0.50979557910416F));
|
||||
tmp7 = tmp_o0 + tmp_o7;
|
||||
|
||||
tmp6 = tmp_o1 + tmp_o6;
|
||||
tmp_o1 = fxp_mul32_Q32((tmp_o1 - tmp_o6) << 1, Qfmt_31(0.60134488693505F));
|
||||
|
||||
tmp5 = tmp_o2 + tmp_o5;
|
||||
tmp_o5 = fxp_mul32_Q32((tmp_o2 - tmp_o5) << 1, Qfmt_31(0.89997622313642F));
|
||||
|
||||
tmp0 = fxp_mul32_Q32((tmp_o3 - tmp_o4) << 3, Qfmt_31(0.6407288619354F));
|
||||
tmp4 = tmp_o3 + tmp_o4;
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
tmp7 = -tmp7;
|
||||
tmp1 = -tmp1;
|
||||
tmp6 = -tmp6;
|
||||
tmp_o1 = -tmp_o1;
|
||||
tmp5 = -tmp5;
|
||||
tmp_o5 = -tmp_o5;
|
||||
tmp4 = -tmp4;
|
||||
tmp0 = -tmp0;
|
||||
}
|
||||
|
||||
|
||||
tmp2 = fxp_mul32_Q32((tmp1 - tmp0) << 1, Qfmt_31(0.54119610014620F));
|
||||
tmp0 += tmp1;
|
||||
tmp1 = fxp_mul32_Q32((tmp7 - tmp4) << 1, Qfmt_31(0.54119610014620F));
|
||||
tmp7 += tmp4;
|
||||
tmp4 = fxp_mul32_Q32((tmp6 - tmp5) << 2, Qfmt_31(0.65328148243819F));
|
||||
tmp6 += tmp5;
|
||||
tmp5 = fxp_mul32_Q32((tmp_o1 - tmp_o5) << 2, Qfmt_31(0.65328148243819F));
|
||||
tmp_o1 += tmp_o5;
|
||||
|
||||
|
||||
vec[13] = fxp_mul32_Q32((tmp1 - tmp4) << 1, Qfmt_31(0.70710678118655F));
|
||||
vec[ 5] = tmp1 + tmp4 + vec[13];
|
||||
|
||||
vec[ 9] = fxp_mul32_Q32((tmp7 - tmp6) << 1, Qfmt_31(0.70710678118655F));
|
||||
vec[ 1] = tmp7 + tmp6;
|
||||
|
||||
tmp4 = fxp_mul32_Q32((tmp0 - tmp_o1) << 1, Qfmt_31(0.70710678118655F));
|
||||
tmp0 += tmp_o1;
|
||||
tmp6 = fxp_mul32_Q32((tmp2 - tmp5) << 1, Qfmt_31(0.70710678118655F));
|
||||
tmp2 += tmp5 + tmp6;
|
||||
tmp0 += tmp2;
|
||||
|
||||
vec[ 1] += tmp0;
|
||||
vec[ 3] = tmp0 + vec[ 5];
|
||||
tmp2 += tmp4;
|
||||
vec[ 5] = tmp2 + vec[ 5];
|
||||
vec[ 7] = tmp2 + vec[ 9];
|
||||
tmp4 += tmp6;
|
||||
vec[ 9] = tmp4 + vec[ 9];
|
||||
vec[11] = tmp4 + vec[13];
|
||||
vec[13] = tmp6 + vec[13];
|
||||
vec[15] = tmp6;
|
||||
|
||||
}
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
void pvmp3_merge_in_place_N32(int32 vec[])
|
||||
{
|
||||
|
||||
|
||||
int32 temp0;
|
||||
int32 temp1;
|
||||
int32 temp2;
|
||||
int32 temp3;
|
||||
|
||||
temp0 = vec[14];
|
||||
vec[14] = vec[ 7];
|
||||
temp1 = vec[12];
|
||||
vec[12] = vec[ 6];
|
||||
temp2 = vec[10];
|
||||
vec[10] = vec[ 5];
|
||||
temp3 = vec[ 8];
|
||||
vec[ 8] = vec[ 4];
|
||||
vec[ 6] = vec[ 3];
|
||||
vec[ 4] = vec[ 2];
|
||||
vec[ 2] = vec[ 1];
|
||||
|
||||
vec[ 1] = (vec[16] + vec[17]);
|
||||
vec[16] = temp3;
|
||||
vec[ 3] = (vec[18] + vec[17]);
|
||||
vec[ 5] = (vec[19] + vec[18]);
|
||||
vec[18] = vec[9];
|
||||
|
||||
vec[ 7] = (vec[20] + vec[19]);
|
||||
vec[ 9] = (vec[21] + vec[20]);
|
||||
vec[20] = temp2;
|
||||
temp2 = vec[13];
|
||||
temp3 = vec[11];
|
||||
vec[11] = (vec[22] + vec[21]);
|
||||
vec[13] = (vec[23] + vec[22]);
|
||||
vec[22] = temp3;
|
||||
temp3 = vec[15];
|
||||
|
||||
vec[15] = (vec[24] + vec[23]);
|
||||
vec[17] = (vec[25] + vec[24]);
|
||||
vec[19] = (vec[26] + vec[25]);
|
||||
vec[21] = (vec[27] + vec[26]);
|
||||
vec[23] = (vec[28] + vec[27]);
|
||||
vec[24] = temp1;
|
||||
vec[25] = (vec[29] + vec[28]);
|
||||
vec[26] = temp2;
|
||||
vec[27] = (vec[30] + vec[29]);
|
||||
vec[28] = temp0;
|
||||
vec[29] = (vec[30] + vec[31]);
|
||||
vec[30] = temp3;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
void pvmp3_split(int32 *vect)
|
||||
{
|
||||
|
||||
int32 i;
|
||||
const int32 *pt_cosTerms = &CosTable_dct32[15];
|
||||
int32 *pt_vect = vect;
|
||||
int32 *pt_vect_2 = pt_vect - 1;
|
||||
|
||||
for (i = 3; i != 0; i--)
|
||||
{
|
||||
int32 tmp2 = *(pt_vect);
|
||||
int32 tmp1 = *(pt_vect_2);
|
||||
int32 cosx = *(pt_cosTerms--);
|
||||
*(pt_vect_2--) = (tmp1 + tmp2);
|
||||
*(pt_vect++) = fxp_mul32_Q27((tmp1 - tmp2), cosx);
|
||||
|
||||
tmp2 = *(pt_vect);
|
||||
tmp1 = *(pt_vect_2);
|
||||
cosx = *(pt_cosTerms--);
|
||||
*(pt_vect_2--) = (tmp1 + tmp2);
|
||||
*(pt_vect++) = fxp_mul32_Q27((tmp1 - tmp2), cosx);
|
||||
|
||||
}
|
||||
|
||||
for (i = 5; i != 0; i--)
|
||||
{
|
||||
int32 tmp2 = *(pt_vect);
|
||||
int32 tmp1 = *(pt_vect_2);
|
||||
int32 cosx = *(pt_cosTerms--);
|
||||
*(pt_vect_2--) = (tmp1 + tmp2);
|
||||
*(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
|
||||
|
||||
tmp2 = *(pt_vect);
|
||||
tmp1 = *(pt_vect_2);
|
||||
cosx = *(pt_cosTerms--);
|
||||
*(pt_vect_2--) = (tmp1 + tmp2);
|
||||
*(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dct_16.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_DCT_16_H
|
||||
#define PVMP3_DCT_16_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_dct_16(int32 vec[], int32 flag);
|
||||
|
||||
void pvmp3_merge_in_place_N32(int32 vec[]);
|
||||
|
||||
void pvmp3_split(int32 *vect);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dct6.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
Int32 vec[] vector of 6 32-bit integers
|
||||
Returns
|
||||
Int32 vec[] dct computation in-place
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Returns the dct of length 6 of the input vector
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_mdct_6.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt30(a) (Int32)(a*((Int32)1<<30) + (a>=0?0.5F:-0.5F))
|
||||
|
||||
#define cos_pi_6 Qfmt30( 0.86602540378444f)
|
||||
#define cos_2_pi_6 Qfmt30( 0.5f)
|
||||
#define cos_7_pi_12 Qfmt30( -0.25881904510252f)
|
||||
#define cos_3_pi_12 Qfmt30( 0.70710678118655f)
|
||||
#define cos_11_pi_12 Qfmt30( -0.96592582628907f)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_dct_6(int32 vec[])
|
||||
{
|
||||
|
||||
Int32 tmp0;
|
||||
Int32 tmp1;
|
||||
Int32 tmp2;
|
||||
Int32 tmp3;
|
||||
Int32 tmp4;
|
||||
Int32 tmp5;
|
||||
|
||||
|
||||
/* split input vector */
|
||||
|
||||
tmp0 = vec[5] + vec[0];
|
||||
tmp5 = vec[5] - vec[0];
|
||||
tmp1 = vec[4] + vec[1];
|
||||
tmp4 = vec[4] - vec[1];
|
||||
tmp2 = vec[3] + vec[2];
|
||||
tmp3 = vec[3] - vec[2];
|
||||
|
||||
vec[0] = tmp0 + tmp2 ;
|
||||
vec[2] = fxp_mul32_Q30(tmp0 - tmp2, cos_pi_6);
|
||||
vec[4] = (vec[0] >> 1) - tmp1;
|
||||
vec[0] += tmp1;
|
||||
|
||||
tmp0 = fxp_mul32_Q30(tmp3, cos_7_pi_12);
|
||||
tmp0 = fxp_mac32_Q30(tmp4, -cos_3_pi_12, tmp0);
|
||||
vec[1] = fxp_mac32_Q30(tmp5, cos_11_pi_12, tmp0);
|
||||
|
||||
vec[3] = fxp_mul32_Q30((tmp3 + tmp4 - tmp5), cos_3_pi_12);
|
||||
tmp0 = fxp_mul32_Q30(tmp3, cos_11_pi_12);
|
||||
tmp0 = fxp_mac32_Q30(tmp4, cos_3_pi_12, tmp0);
|
||||
vec[5] = fxp_mac32_Q30(tmp5, cos_7_pi_12, tmp0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dct_9.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 vec[] vector of 9 32-bit integers
|
||||
Returns
|
||||
int32 vec[] dct computation in-place
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Returns the dct of length 9 of the input vector
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_mdct_18.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt31(a) (int32)(a*(0x7FFFFFFF))
|
||||
|
||||
#define cos_pi_9 Qfmt31( 0.93969262078591f)
|
||||
#define cos_2pi_9 Qfmt31( 0.76604444311898f)
|
||||
#define cos_4pi_9 Qfmt31( 0.17364817766693f)
|
||||
#define cos_5pi_9 Qfmt31(-0.17364817766693f)
|
||||
#define cos_7pi_9 Qfmt31(-0.76604444311898f)
|
||||
#define cos_8pi_9 Qfmt31(-0.93969262078591f)
|
||||
#define cos_pi_6 Qfmt31( 0.86602540378444f)
|
||||
#define cos_5pi_6 Qfmt31(-0.86602540378444f)
|
||||
#define cos_5pi_18 Qfmt31( 0.64278760968654f)
|
||||
#define cos_7pi_18 Qfmt31( 0.34202014332567f)
|
||||
#define cos_11pi_18 Qfmt31(-0.34202014332567f)
|
||||
#define cos_13pi_18 Qfmt31(-0.64278760968654f)
|
||||
#define cos_17pi_18 Qfmt31(-0.98480775301221f)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_dct_9(int32 vec[])
|
||||
{
|
||||
|
||||
/* split input vector */
|
||||
|
||||
int32 tmp0 = vec[8] + vec[0];
|
||||
int32 tmp8 = vec[8] - vec[0];
|
||||
int32 tmp1 = vec[7] + vec[1];
|
||||
int32 tmp7 = vec[7] - vec[1];
|
||||
int32 tmp2 = vec[6] + vec[2];
|
||||
int32 tmp6 = vec[6] - vec[2];
|
||||
int32 tmp3 = vec[5] + vec[3];
|
||||
int32 tmp5 = vec[5] - vec[3];
|
||||
|
||||
vec[0] = (tmp0 + tmp2 + tmp3) + (tmp1 + vec[4]);
|
||||
vec[6] = ((tmp0 + tmp2 + tmp3) >> 1) - (tmp1 + vec[4]);
|
||||
vec[2] = (tmp1 >> 1) - vec[4];
|
||||
vec[4] = -vec[2];
|
||||
vec[8] = -vec[2];
|
||||
vec[4] = fxp_mac32_Q32(vec[4], tmp0 << 1, cos_2pi_9);
|
||||
vec[8] = fxp_mac32_Q32(vec[8], tmp0 << 1, cos_4pi_9);
|
||||
vec[2] = fxp_mac32_Q32(vec[2], tmp0 << 1, cos_pi_9);
|
||||
vec[2] = fxp_mac32_Q32(vec[2], tmp2 << 1, cos_5pi_9);
|
||||
vec[4] = fxp_mac32_Q32(vec[4], tmp2 << 1, cos_8pi_9);
|
||||
vec[8] = fxp_mac32_Q32(vec[8], tmp2 << 1, cos_2pi_9);
|
||||
vec[8] = fxp_mac32_Q32(vec[8], tmp3 << 1, cos_8pi_9);
|
||||
vec[4] = fxp_mac32_Q32(vec[4], tmp3 << 1, cos_4pi_9);
|
||||
vec[2] = fxp_mac32_Q32(vec[2], tmp3 << 1, cos_7pi_9);
|
||||
|
||||
vec[1] = fxp_mul32_Q32(tmp5 << 1, cos_11pi_18);
|
||||
vec[1] = fxp_mac32_Q32(vec[1], tmp6 << 1, cos_13pi_18);
|
||||
vec[1] = fxp_mac32_Q32(vec[1], tmp7 << 1, cos_5pi_6);
|
||||
vec[1] = fxp_mac32_Q32(vec[1], tmp8 << 1, cos_17pi_18);
|
||||
vec[3] = fxp_mul32_Q32((tmp5 + tmp6 - tmp8) << 1, cos_pi_6);
|
||||
vec[5] = fxp_mul32_Q32(tmp5 << 1, cos_17pi_18);
|
||||
vec[5] = fxp_mac32_Q32(vec[5], tmp6 << 1, cos_7pi_18);
|
||||
vec[5] = fxp_mac32_Q32(vec[5], tmp7 << 1, cos_pi_6);
|
||||
vec[5] = fxp_mac32_Q32(vec[5], tmp8 << 1, cos_13pi_18);
|
||||
vec[7] = fxp_mul32_Q32(tmp5 << 1, cos_5pi_18);
|
||||
vec[7] = fxp_mac32_Q32(vec[7], tmp6 << 1, cos_17pi_18);
|
||||
vec[7] = fxp_mac32_Q32(vec[7], tmp7 << 1, cos_pi_6);
|
||||
vec[7] = fxp_mac32_Q32(vec[7], tmp8 << 1, cos_11pi_18);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // If not assembly
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dec_defs.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file has the mp3 decoder common defines.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_DEC_DEFS_H
|
||||
#define PVMP3_DEC_DEFS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
#define module(x, POW2) ((x)&(POW2-1))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define BUFSIZE 8192 // big enough to hold 4608 bytes == biggest mp3 frame
|
||||
|
||||
#define CHAN 2
|
||||
#define GRAN 2
|
||||
|
||||
|
||||
#define SUBBANDS_NUMBER 32
|
||||
#define FILTERBANK_BANDS 18
|
||||
#define HAN_SIZE 512
|
||||
|
||||
|
||||
/* MPEG Header Definitions - ID Bit Values */
|
||||
|
||||
#define MPEG_1 0
|
||||
#define MPEG_2 1
|
||||
#define MPEG_2_5 2
|
||||
#define INVALID_VERSION -1
|
||||
|
||||
/* MPEG Header Definitions - Mode Values */
|
||||
|
||||
#define MPG_MD_STEREO 0
|
||||
#define MPG_MD_JOINT_STEREO 1
|
||||
#define MPG_MD_DUAL_CHANNEL 2
|
||||
#define MPG_MD_MONO 3
|
||||
|
||||
|
||||
|
||||
#define LEFT 0
|
||||
#define RIGHT 1
|
||||
|
||||
|
||||
#define SYNC_WORD (int32)0x7ff
|
||||
#define SYNC_WORD_LNGTH 11
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/* Header Information Structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32 version_x;
|
||||
int32 layer_description;
|
||||
int32 error_protection;
|
||||
int32 bitrate_index;
|
||||
int32 sampling_frequency;
|
||||
int32 padding;
|
||||
int32 extension;
|
||||
int32 mode;
|
||||
int32 mode_ext;
|
||||
int32 copyright;
|
||||
int32 original;
|
||||
int32 emphasis;
|
||||
} mp3Header;
|
||||
|
||||
|
||||
/* Layer III side information. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 part2_3_length;
|
||||
uint32 big_values;
|
||||
int32 global_gain;
|
||||
uint32 scalefac_compress;
|
||||
uint32 window_switching_flag;
|
||||
uint32 block_type;
|
||||
uint32 mixed_block_flag;
|
||||
uint32 table_select[3];
|
||||
uint32 subblock_gain[3];
|
||||
uint32 region0_count;
|
||||
uint32 region1_count;
|
||||
uint32 preflag;
|
||||
uint32 scalefac_scale;
|
||||
uint32 count1table_select;
|
||||
|
||||
} granuleInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 scfsi[4];
|
||||
granuleInfo gran[2];
|
||||
|
||||
} channelInfo;
|
||||
|
||||
/* Layer III side info. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 main_data_begin;
|
||||
uint32 private_bits;
|
||||
channelInfo ch[2];
|
||||
|
||||
} mp3SideInfo;
|
||||
|
||||
/* Layer III scale factors. */
|
||||
typedef struct
|
||||
{
|
||||
int32 l[23]; /* [cb] */
|
||||
int32 s[3][13]; /* [window][cb] */
|
||||
|
||||
} mp3ScaleFactors;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_decode_header.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
tbits *inputStream, bit stream
|
||||
mp3Header *info,
|
||||
uint32 *crc
|
||||
Returns
|
||||
|
||||
mp3Header *info, structure holding the parsed mp3 header info
|
||||
uint32 *crc initialized crc computation
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
gets mp3 header information
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_decode_header.h"
|
||||
#include "pvmp3_crc.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "pvmp3_seek_synch.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
ERROR_CODE pvmp3_decode_header(tmp3Bits *inputStream,
|
||||
mp3Header *info,
|
||||
uint32 *crc)
|
||||
{
|
||||
|
||||
ERROR_CODE err = NO_DECODING_ERROR;
|
||||
uint32 temp;
|
||||
|
||||
/*
|
||||
* Verify that at least the header is complete
|
||||
* Note that SYNC_WORD_LNGTH is in unit of bits, but inputBufferCurrentLength
|
||||
* is in unit of bytes.
|
||||
*/
|
||||
if (inputStream->inputBufferCurrentLength < ((SYNC_WORD_LNGTH + 21) >> 3))
|
||||
{
|
||||
return NO_ENOUGH_MAIN_DATA_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* MPEG Audio Version ID
|
||||
*/
|
||||
temp = getUpTo17bits(inputStream, SYNC_WORD_LNGTH);
|
||||
if ((temp & SYNC_WORD) != SYNC_WORD)
|
||||
{
|
||||
err = pvmp3_header_sync(inputStream);
|
||||
|
||||
if (err != NO_DECODING_ERROR)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
temp = getNbits(inputStream, 21); // to avoid multiple bitstream accesses
|
||||
|
||||
|
||||
switch (temp >> 19) /* 2 */
|
||||
{
|
||||
case 0:
|
||||
info->version_x = MPEG_2_5;
|
||||
break;
|
||||
case 2:
|
||||
info->version_x = MPEG_2;
|
||||
break;
|
||||
case 3:
|
||||
info->version_x = MPEG_1;
|
||||
break;
|
||||
default:
|
||||
info->version_x = INVALID_VERSION;
|
||||
err = UNSUPPORTED_LAYER;
|
||||
break;
|
||||
}
|
||||
|
||||
info->layer_description = 4 - ((temp << 13) >> 30); /* 2 */
|
||||
info->error_protection = !((temp << 15) >> 31); /* 1 */
|
||||
|
||||
if (info->error_protection)
|
||||
{
|
||||
*crc = 0xffff; /* CRC start value */
|
||||
calculate_crc((temp << 16) >> 16, 16, crc);
|
||||
}
|
||||
|
||||
info->bitrate_index = (temp << 16) >> 28; /* 4 */
|
||||
info->sampling_frequency = (temp << 20) >> 30; /* 2 */
|
||||
info->padding = (temp << 22) >> 31; /* 1 */
|
||||
info->extension = (temp << 23) >> 31; /* 1 */
|
||||
info->mode = (temp << 24) >> 30; /* 2 */
|
||||
info->mode_ext = (temp << 26) >> 30; /* 2 */
|
||||
info->copyright = (temp << 27) >> 31; /* 1 */
|
||||
info->original = (temp << 28) >> 31; /* 1 */
|
||||
info->emphasis = (temp << 30) >> 30; /* 2 */
|
||||
|
||||
|
||||
if (!info->bitrate_index || info->sampling_frequency == 3)
|
||||
{
|
||||
err = UNSUPPORTED_FREE_BITRATE;
|
||||
}
|
||||
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_decode_header.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_DECODE_HEADER_H
|
||||
#define PVMP3_DECODE_HEADER_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
ERROR_CODE pvmp3_decode_header(tmp3Bits *inputStream,
|
||||
mp3Header *info,
|
||||
uint32 *crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,758 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_decode_huff_cw.cpp
|
||||
|
||||
Funtions:
|
||||
pvmp3_decode_huff_cw_tab0
|
||||
pvmp3_decode_huff_cw_tab1
|
||||
pvmp3_decode_huff_cw_tab2
|
||||
pvmp3_decode_huff_cw_tab3
|
||||
pvmp3_decode_huff_cw_tab5
|
||||
pvmp3_decode_huff_cw_tab6
|
||||
pvmp3_decode_huff_cw_tab7
|
||||
pvmp3_decode_huff_cw_tab8
|
||||
pvmp3_decode_huff_cw_tab9
|
||||
pvmp3_decode_huff_cw_tab10
|
||||
pvmp3_decode_huff_cw_tab11
|
||||
pvmp3_decode_huff_cw_tab12
|
||||
pvmp3_decode_huff_cw_tab13
|
||||
pvmp3_decode_huff_cw_tab15
|
||||
pvmp3_decode_huff_cw_tab16
|
||||
pvmp3_decode_huff_cw_tab24
|
||||
pvmp3_decode_huff_cw_tab32
|
||||
pvmp3_decode_huff_cw_tab33
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Inputs:
|
||||
BITS *pMainData = pointer to input mp3 Main data bit stream
|
||||
|
||||
|
||||
Outputs:
|
||||
cw = bit field extracted from a leaf entry of packed mp3 Huffman Tables
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
These functions are used to decode huffman codewords from the input
|
||||
bitstream using combined binary search and look-up table approach.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
[2] Introduction to Algorithms,
|
||||
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest.
|
||||
The MIT press, 1990
|
||||
|
||||
[3] "Selecting an Optimal Huffman Decoder for AAC",
|
||||
Vladimir Z. Mesarovic, et al.
|
||||
AES 111th Convention, September 21-24, 2001, New York, USA
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_tables.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "pvmp3_decode_huff_cw.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint16 pvmp3_decode_huff_cw_tab0(tmp3Bits *pMainData)
|
||||
{
|
||||
OSCL_UNUSED_ARG(pMainData);
|
||||
return(0);
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab1(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 3); /* hufftable1 */
|
||||
|
||||
cw = *(huffTable_1 + tmp);
|
||||
pMainData->usedBits -= (3 - (cw & 0xFF));
|
||||
return(cw >> 8);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab2(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 6); /* huffTable_2,3 */
|
||||
|
||||
if (tmp >> 3)
|
||||
{
|
||||
tmp = (tmp >> 3) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = tmp + 7;
|
||||
}
|
||||
|
||||
cw = *(huffTable_2 + tmp);
|
||||
pMainData->usedBits -= (6 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab3(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 6); /* huffTable_2,3 */
|
||||
|
||||
if (tmp >> 3)
|
||||
{
|
||||
tmp = (tmp >> 3) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = tmp + 7;
|
||||
}
|
||||
|
||||
cw = *(huffTable_3 + tmp);
|
||||
pMainData->usedBits -= (6 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab5(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 8); /* huffTable_5 */
|
||||
|
||||
if ((tmp >> 5))
|
||||
{
|
||||
tmp = (tmp >> 5) - 1;
|
||||
}
|
||||
else if ((tmp >> 1) >= 2)
|
||||
{
|
||||
tmp = (tmp >> 1) - 2 + 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 3) + 21;
|
||||
}
|
||||
|
||||
cw = *(huffTable_5 + tmp);
|
||||
pMainData->usedBits -= (8 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab6(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 7); /* huffTable_6 */
|
||||
if ((tmp >> 3) >= 3)
|
||||
{
|
||||
tmp = (tmp >> 3) - 3;
|
||||
}
|
||||
else if (tmp >> 1)
|
||||
{
|
||||
tmp = (tmp >> 1) - 1 + 13;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = tmp + 24;
|
||||
}
|
||||
|
||||
cw = *(huffTable_6 + tmp);
|
||||
pMainData->usedBits -= (7 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab7(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 10); /* huffTable_7 */
|
||||
if ((tmp >> 7) >= 2)
|
||||
{
|
||||
tmp = (tmp >> 7) - 2;
|
||||
}
|
||||
else if ((tmp >> 4) >= 7)
|
||||
{
|
||||
tmp = (tmp >> 4) - 7 + 6;
|
||||
}
|
||||
else if ((tmp >> 1) >= 2)
|
||||
{
|
||||
tmp = (tmp >> 1) - 2 + 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 3) + 69;
|
||||
}
|
||||
|
||||
cw = *(huffTable_7 + tmp);
|
||||
pMainData->usedBits -= (10 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab8(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 11); /* huffTable_8 */
|
||||
if ((tmp >> 7) >= 2)
|
||||
{
|
||||
tmp = (tmp >> 7) - 2;
|
||||
}
|
||||
else if ((tmp >> 5) >= 5)
|
||||
{
|
||||
tmp = (tmp >> 5) - 5 + 14;
|
||||
}
|
||||
else if ((tmp >> 2) >= 3)
|
||||
{
|
||||
tmp = (tmp >> 2) - 3 + 17;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp) + 54;
|
||||
}
|
||||
|
||||
cw = *(huffTable_8 + tmp);
|
||||
pMainData->usedBits -= (11 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab9(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo9bits(pMainData, 9); /* huffTable_9 */
|
||||
if ((tmp >> 5) >= 5)
|
||||
{
|
||||
tmp = (tmp >> 5) - 5;
|
||||
}
|
||||
else if ((tmp >> 3) >= 6)
|
||||
{
|
||||
tmp = (tmp >> 3) - 6 + 11;
|
||||
}
|
||||
else if ((tmp >> 1) >= 4)
|
||||
{
|
||||
tmp = (tmp >> 1) - 4 + 25;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = tmp + 45;
|
||||
}
|
||||
|
||||
cw = *(huffTable_9 + tmp);
|
||||
pMainData->usedBits -= (9 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab10(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 11); /* huffTable_10 */
|
||||
if (tmp >> 10)
|
||||
{
|
||||
tmp = (tmp >> 10) - 1;
|
||||
}
|
||||
else if ((tmp >> 7) >= 3)
|
||||
{
|
||||
tmp = (tmp >> 7) - 3 + 1;
|
||||
}
|
||||
else if ((tmp >> 5) >= 8)
|
||||
{
|
||||
tmp = (tmp >> 5) - 8 + 6;
|
||||
}
|
||||
else if ((tmp >> 3) >= 18)
|
||||
{
|
||||
tmp = (tmp >> 3) - 18 + 10;
|
||||
}
|
||||
else if ((tmp >> 2) >= 24)
|
||||
{
|
||||
tmp = (tmp >> 2) - 24 + 24;
|
||||
}
|
||||
else if ((tmp >> 1) >= 12)
|
||||
{
|
||||
tmp = (tmp >> 1) - 12 + 36;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp) + 72;
|
||||
}
|
||||
|
||||
cw = *(huffTable_10 + tmp);
|
||||
pMainData->usedBits -= (11 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab11(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 11); /* huffTable_11 */
|
||||
if ((tmp >> 8) >= 3)
|
||||
{
|
||||
tmp = (tmp >> 8) - 3;
|
||||
}
|
||||
else if ((tmp >> 6) >= 7)
|
||||
{
|
||||
tmp = (tmp >> 6) - 7 + 5;
|
||||
}
|
||||
else if ((tmp >> 3) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 3) - 32 + 10;
|
||||
}
|
||||
else if ((tmp >> 2) >= 10)
|
||||
{
|
||||
tmp = (tmp >> 2) - 10 + 34;
|
||||
}
|
||||
else if ((tmp >> 1) >= 8)
|
||||
{
|
||||
tmp = (tmp >> 1) - 8 + 88;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 0xFF) + 100;
|
||||
}
|
||||
cw = *(huffTable_11 + tmp);
|
||||
pMainData->usedBits -= (11 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab12(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 10); /* huffTable_12 */
|
||||
if ((tmp >> 7) >= 5)
|
||||
{
|
||||
tmp = (tmp >> 7) - 5;
|
||||
}
|
||||
else if ((tmp >> 5) >= 12)
|
||||
{
|
||||
tmp = (tmp >> 5) - 12 + 3;
|
||||
}
|
||||
else if ((tmp >> 4) >= 17)
|
||||
{
|
||||
tmp = (tmp >> 4) - 17 + 11;
|
||||
}
|
||||
else if ((tmp >> 2) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 2) - 32 + 18;
|
||||
}
|
||||
else if ((tmp >> 1) >= 16)
|
||||
{
|
||||
tmp = (tmp >> 1) - 16 + 54;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 0x1F) + 102;
|
||||
|
||||
}
|
||||
cw = *(huffTable_12 + tmp);
|
||||
pMainData->usedBits -= (10 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab13(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getNbits(pMainData, 19); /* huffTable_13 */
|
||||
if (tmp >> 18)
|
||||
{
|
||||
tmp = 0;
|
||||
}
|
||||
else if ((tmp >> 15) >= 4)
|
||||
{
|
||||
tmp = (tmp >> 15) - 4 + 1;
|
||||
}
|
||||
else if ((tmp >> 11) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 11) - 32 + 5;
|
||||
}
|
||||
else if ((tmp >> 9) >= 64)
|
||||
{
|
||||
tmp = (tmp >> 9) - 64 + 37;
|
||||
}
|
||||
else if ((tmp >> 8) >= 64)
|
||||
{
|
||||
tmp = (tmp >> 8) - 64 + 101;
|
||||
}
|
||||
else if ((tmp >> 7) >= 64)
|
||||
{
|
||||
tmp = (tmp >> 7) - 64 + 165;
|
||||
}
|
||||
else if ((tmp >> 6) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 6) - 32 + 229;
|
||||
}
|
||||
else if ((tmp >> 5) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 5) - 32 + 325;
|
||||
}
|
||||
else if ((tmp >> 4) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 4) - 32 + 357;
|
||||
}
|
||||
else if ((tmp >> 3) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 3) - 32 + 389;
|
||||
}
|
||||
else if ((tmp >> 2) >= 2)
|
||||
{
|
||||
tmp = (tmp >> 2) - 2 + 421;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 0x7) + 483;
|
||||
}
|
||||
|
||||
cw = *(huffTable_13 + tmp);
|
||||
pMainData->usedBits -= (19 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab15(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 13); /* huffTable_15 */
|
||||
if ((tmp >> 9) >= 10)
|
||||
{
|
||||
tmp = (tmp >> 9) - 10;
|
||||
}
|
||||
else if ((tmp >> 6) >= 39)
|
||||
{
|
||||
tmp = (tmp >> 6) - 39 + 6;
|
||||
}
|
||||
else if ((tmp >> 4) >= 62)
|
||||
{
|
||||
tmp = (tmp >> 4) - 62 + 47;
|
||||
}
|
||||
else if ((tmp >> 3) >= 60)
|
||||
{
|
||||
tmp = (tmp >> 3) - 60 + 141;
|
||||
}
|
||||
else if ((tmp >> 2) >= 64)
|
||||
{
|
||||
tmp = (tmp >> 2) - 64 + 205;
|
||||
}
|
||||
else if ((tmp >> 1) >= 32)
|
||||
{
|
||||
tmp = (tmp >> 1) - 32 + 261;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp & 0x3f) + 357;
|
||||
}
|
||||
|
||||
cw = *(huffTable_15 + tmp);
|
||||
pMainData->usedBits -= (13 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab16(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 17); /* huffTable_16 */
|
||||
if (tmp >> 16)
|
||||
{
|
||||
tmp = 0;
|
||||
}
|
||||
else if ((tmp >> 13) >= 4)
|
||||
{
|
||||
tmp = (tmp >> 13) - 4 + 1;
|
||||
}
|
||||
else if ((tmp >> 9) >= 38)
|
||||
{
|
||||
tmp = (tmp >> 9) - 38 + 5;
|
||||
}
|
||||
else if ((tmp >> 7) >= 94)
|
||||
{
|
||||
tmp = (tmp >> 7) - 94 + 31;
|
||||
}
|
||||
else if ((tmp >> 5) >= 214)
|
||||
{
|
||||
tmp = (tmp >> 5) - 214 + 89;
|
||||
}
|
||||
else if ((tmp >> 3) >= 704)
|
||||
{
|
||||
if ((tmp >> 4) >= 384)
|
||||
{
|
||||
tmp = (tmp >> 4) - 384 + 315;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp >> 3) - 704 + 251;
|
||||
}
|
||||
}
|
||||
else if ((tmp >> 8) >= 14)
|
||||
{
|
||||
tmp = (tmp >> 8) - 14 + 359;
|
||||
}
|
||||
else if ((tmp) >= 3456)
|
||||
{
|
||||
if ((tmp >> 2) >= 868)
|
||||
{
|
||||
tmp = (tmp >> 2) - 868 + 383;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp) - 3456 + 367;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = ((tmp >> 6) & 0x3f) + 411;
|
||||
}
|
||||
|
||||
cw = *(huffTable_16 + tmp);
|
||||
pMainData->usedBits -= (17 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab24(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp;
|
||||
uint16 cw;
|
||||
|
||||
tmp = getUpTo17bits(pMainData, 12); /* huffTable_24 */
|
||||
if ((tmp >> 6) >= 41)
|
||||
{
|
||||
tmp = (tmp >> 6) - 41;
|
||||
}
|
||||
else if ((tmp >> 3) >= 218)
|
||||
{
|
||||
tmp = (tmp >> 3) - 218 + 23;
|
||||
}
|
||||
else if ((tmp >> 2) >= 336)
|
||||
{
|
||||
tmp = (tmp >> 2) - 336 + 133;
|
||||
}
|
||||
else if ((tmp >> 1) >= 520)
|
||||
{
|
||||
tmp = (tmp >> 1) - 520 + 233;
|
||||
}
|
||||
else if ((tmp) >= 1024)
|
||||
{
|
||||
tmp = (tmp) - 1024 + 385;
|
||||
}
|
||||
else if ((tmp >> 1) >= 352)
|
||||
{
|
||||
if ((tmp >> 8) == 3)
|
||||
{
|
||||
tmp = (tmp >> 8) - 3 + 433;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (tmp >> 1) - 352 + 401;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = ((tmp >> 4) & 0x3f) + 434;
|
||||
}
|
||||
|
||||
cw = *(huffTable_24 + tmp);
|
||||
pMainData->usedBits -= (12 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
uint16 pvmp3_decode_huff_cw_tab32(tmp3Bits *pMainData)
|
||||
{
|
||||
uint32 tmp = getUpTo9bits(pMainData, 6); /* huffTable_32 */
|
||||
if ((tmp >> 5))
|
||||
{
|
||||
pMainData->usedBits -= 5;
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16 cw = *(huffTable_32 + (tmp & 0x1f));
|
||||
pMainData->usedBits -= (6 - (cw & 0xFF));
|
||||
|
||||
return(cw >> 8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint16 pvmp3_decode_huff_cw_tab33(tmp3Bits *pMainData)
|
||||
{
|
||||
|
||||
uint16 tmp = getUpTo9bits(pMainData, 4); /* huffTable_33 */
|
||||
|
||||
return((0x0f - tmp));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_decode_huff_cw.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_DECODE_HUFF_CW_H
|
||||
#define PVMP3_DECODE_HUFF_CW_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
uint16 pvmp3_decode_huff_cw_tab0(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab1(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab2(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab3(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab5(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab6(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab7(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab8(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab9(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab10(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab11(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab12(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab13(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab15(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab16(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab24(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab32(tmp3Bits *);
|
||||
uint16 pvmp3_decode_huff_cw_tab33(tmp3Bits *);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,452 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dequantize_sample.cpp
|
||||
|
||||
Functions:
|
||||
power_1_third
|
||||
pvmp3_dequantize_sample
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
power_1_third
|
||||
int32 power_1_third( int32 xx)
|
||||
|
||||
Input
|
||||
int32 xx, int32 in the [0, 8192] range
|
||||
|
||||
Returns
|
||||
|
||||
int32 xx^(1/3) int32 Q26 number representing
|
||||
the 1/3 power of the input
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
pvmp3_dequantize_sample
|
||||
|
||||
Input
|
||||
int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac, scale factor structure
|
||||
struct gr_info_s *gr_info, granule structure informatiom
|
||||
mp3Header *info mp3 header info
|
||||
|
||||
Returns
|
||||
|
||||
int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS], dequantize output as (.)^(4/3)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
dequantize sample
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_dequantize_sample.h"
|
||||
#include "pvmp3_normalize.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
#include "pvmp3_tables.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Q30_fmt(a)(int32(double(0x40000000)*a))
|
||||
#define Q29_fmt(a)(int32(double(0x20000000)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 pretab[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0};
|
||||
|
||||
const int32 pow_2_1_fourth[4] =
|
||||
{
|
||||
Q30_fmt(1.0), Q30_fmt(1.18920711500272),
|
||||
Q30_fmt(1.41421356237310), Q30_fmt(1.68179283050743)
|
||||
};
|
||||
|
||||
const int32 two_cubic_roots[7] =
|
||||
{
|
||||
Q29_fmt(0), Q29_fmt(1.25992104989487),
|
||||
Q29_fmt(1.58740105196820), Q29_fmt(2.00000000000000),
|
||||
Q29_fmt(2.51984209978975), Q29_fmt(3.17480210393640),
|
||||
Q29_fmt(3.99999999999999)
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
int32 power_1_third(int32 xx)
|
||||
{
|
||||
|
||||
if (xx <= 512)
|
||||
{
|
||||
return (power_one_third[xx] >> 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xx >> 15)
|
||||
{
|
||||
return 0x7FFFFFFF; /* saturate any value over 32767 */
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 x = xx;
|
||||
int32 m = 22 - pvmp3_normalize(xx);
|
||||
|
||||
xx >>= m;
|
||||
xx = (power_one_third[xx]) + (((power_one_third[xx+1] - power_one_third[xx]) >> m) * (x & ((1 << m) - 1)));
|
||||
return (fxp_mul32_Q30(xx, two_cubic_roots[m]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
void pvmp3_dequantize_sample(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac,
|
||||
granuleInfo *gr_info,
|
||||
int32 used_freq_lines,
|
||||
mp3Header *info)
|
||||
{
|
||||
int32 ss;
|
||||
int32 cb = 0;
|
||||
int32 global_gain;
|
||||
int32 sfreq = info->sampling_frequency + info->version_x + (info->version_x << 1);
|
||||
|
||||
/* apply formula per block type */
|
||||
|
||||
if (gr_info->window_switching_flag && (gr_info->block_type == 2))
|
||||
{
|
||||
int32 next_cb_boundary;
|
||||
int32 cb_begin = 0;
|
||||
int32 cb_width = 0;
|
||||
int32 mixstart = 8; /* added 2003/08/21 efs */
|
||||
|
||||
if (info->version_x != MPEG_1)
|
||||
{
|
||||
mixstart = 6; /* different value in MPEG2 LSF */
|
||||
}
|
||||
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].l[1]; /* LONG blocks: 0,1,3 */
|
||||
}
|
||||
else
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].s[1] * 3; /* pure SHORT block */
|
||||
cb_width = 0;
|
||||
}
|
||||
|
||||
global_gain = gr_info->global_gain;
|
||||
int32 two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
|
||||
global_gain = 12 + (global_gain >> 2);
|
||||
|
||||
for (ss = 0 ; ss < used_freq_lines ; ss++)
|
||||
{
|
||||
if (ss == next_cb_boundary)
|
||||
{
|
||||
cb++; /* critical band counter */
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
if (next_cb_boundary == mp3_sfBandIndex[sfreq].l[mixstart])
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].s[4] * 3;
|
||||
|
||||
cb_begin = mp3_sfBandIndex[sfreq].s[3] * 3;
|
||||
cb_width = 3;
|
||||
cb = 3;
|
||||
}
|
||||
else if (ss < mp3_sfBandIndex[sfreq].l[mixstart])
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].l[cb+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].s[cb+1] * 3;
|
||||
|
||||
cb_width = cb;
|
||||
cb_begin = mp3_sfBandIndex[sfreq].s[cb] * 3;
|
||||
}
|
||||
|
||||
if (ss < 2*FILTERBANK_BANDS)
|
||||
{ /* 1st 2 subbands of switched blocks */
|
||||
global_gain = (gr_info->global_gain);
|
||||
global_gain -= (1 + gr_info->scalefac_scale) *
|
||||
(scalefac->l[cb] + gr_info->preflag * pretab[cb]) << 1;
|
||||
|
||||
two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
|
||||
global_gain = 12 + (global_gain >> 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
next_cb_boundary = mp3_sfBandIndex[sfreq].s[cb+1] * 3;
|
||||
cb_width = cb;
|
||||
cb_begin = mp3_sfBandIndex[sfreq].s[cb] * 3;
|
||||
}
|
||||
|
||||
} /* end-if ( ss == next_cb_boundary) */
|
||||
|
||||
/* Do long/short dependent scaling operations. */
|
||||
if ((gr_info->mixed_block_flag == 0) || (gr_info->mixed_block_flag && (ss >= 2*FILTERBANK_BANDS)))
|
||||
{
|
||||
int32 temp2 = fxp_mul32_Q32((ss - cb_begin) << 16, mp3_shortwindBandWidths[sfreq][cb_width]);
|
||||
temp2 = (temp2 + 1) >> 15;
|
||||
|
||||
global_gain = (gr_info->global_gain);
|
||||
global_gain -= gr_info->subblock_gain[temp2] << 3;
|
||||
global_gain -= (1 + gr_info->scalefac_scale) * (scalefac->s[temp2][cb] << 1);
|
||||
|
||||
two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
|
||||
global_gain = 12 + (global_gain >> 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* xr[sb][ss] = 2^(global_gain/4)
|
||||
*/
|
||||
|
||||
/* Scale quantized value. */
|
||||
|
||||
/* 0 < abs(is[ss]) < 8192 */
|
||||
|
||||
int32 tmp = fxp_mul32_Q30((is[ss] << 16), power_1_third(pv_abs(is[ ss])));
|
||||
|
||||
tmp = fxp_mul32_Q30(tmp, two_raise_one_fourth);
|
||||
|
||||
if (global_gain < 0)
|
||||
{
|
||||
int32 temp = - global_gain;
|
||||
if (temp < 32)
|
||||
{
|
||||
is[ss] = (tmp >> temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
is[ss] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is[ss] = (tmp << global_gain);
|
||||
}
|
||||
|
||||
} /* for (ss=0 ; ss < used_freq_lines ; ss++) */
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (cb = 0 ; cb < 22 ; cb++)
|
||||
{
|
||||
|
||||
/* Compute overall (global) scaling. */
|
||||
|
||||
global_gain = (gr_info->global_gain);
|
||||
|
||||
global_gain -= (1 + gr_info->scalefac_scale) *
|
||||
(scalefac->l[cb] + gr_info->preflag * pretab[cb]) << 1;
|
||||
|
||||
|
||||
int32 two_raise_one_fourth = pow_2_1_fourth[global_gain&0x3];
|
||||
global_gain = 12 + (global_gain >> 2);
|
||||
|
||||
/*
|
||||
* xr[sb][ss] = 2^(global_gain/4)
|
||||
*/
|
||||
|
||||
/* Scale quantized value. */
|
||||
|
||||
if (used_freq_lines >= mp3_sfBandIndex[sfreq].l[cb+1])
|
||||
{
|
||||
if (global_gain <= 0)
|
||||
{
|
||||
global_gain = - global_gain;
|
||||
if (global_gain < 32)
|
||||
{
|
||||
for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < mp3_sfBandIndex[sfreq].l[cb+1]; ss += 2)
|
||||
{
|
||||
int32 tmp = is[ss];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
|
||||
}
|
||||
tmp = is[ss+1];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pv_memset(&is[ mp3_sfBandIndex[sfreq].l[cb]],
|
||||
0,
|
||||
(mp3_sfBandIndex[sfreq].l[cb+1] - mp3_sfBandIndex[sfreq].l[cb])*sizeof(*is));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < mp3_sfBandIndex[sfreq].l[cb+1]; ss += 2)
|
||||
{
|
||||
int32 tmp = is[ss];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
|
||||
}
|
||||
|
||||
tmp = is[ss+1];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (global_gain <= 0)
|
||||
{
|
||||
global_gain = - global_gain;
|
||||
if (global_gain < 32)
|
||||
{
|
||||
for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < used_freq_lines; ss += 2)
|
||||
{
|
||||
int32 tmp = is[ss];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
|
||||
}
|
||||
tmp = is[ss+1];
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss+1] = fxp_mul32_Q30(tmp, two_raise_one_fourth) >> global_gain;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pv_memset(&is[ mp3_sfBandIndex[sfreq].l[cb]],
|
||||
0,
|
||||
(mp3_sfBandIndex[sfreq].l[cb+1] - mp3_sfBandIndex[sfreq].l[cb])*sizeof(*is));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ss = mp3_sfBandIndex[sfreq].l[cb]; ss < used_freq_lines; ss++)
|
||||
{
|
||||
int32 tmp = is[ss];
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
tmp = fxp_mul32_Q30((tmp << 16), power_1_third(pv_abs(tmp)));
|
||||
is[ss] = fxp_mul32_Q30(tmp, two_raise_one_fourth) << global_gain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cb = 22; // force breaking out of the loop
|
||||
|
||||
} /* if ( used_freq_lines >= mp3_sfBandIndex[sfreq].l[cb+1]) */
|
||||
|
||||
} /* for (cb=0 ; cb < 22 ; cb++) */
|
||||
|
||||
} /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
|
||||
|
||||
|
||||
pv_memset(&is[used_freq_lines],
|
||||
0,
|
||||
(FILTERBANK_BANDS*SUBBANDS_NUMBER - used_freq_lines)*sizeof(*is));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_dequantize_sample.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_DEQUANTIZE_SAMPLE_H
|
||||
#define PVMP3_DEQUANTIZE_SAMPLE_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int32 power_1_third(int32 xx);
|
||||
|
||||
void pvmp3_dequantize_sample(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac,
|
||||
granuleInfo *gr_info,
|
||||
int32 num_lines,
|
||||
mp3Header *info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,415 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_equalizer.cpp
|
||||
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 *inData, pointer to the spectrum frequency-line
|
||||
e_equalization equalizerType, equalization mode
|
||||
int32 *pt_work_buff
|
||||
|
||||
Output
|
||||
int32 *pt_work_buff pointer to the equalized frequency-line
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Equalizer
|
||||
Each subband sample is scaled according to a spectrum shape setting
|
||||
defined by "equalizerType"
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_equalizer.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define LEVEL__0__dB 0.999999970f
|
||||
#define LEVEL__1_5dB 0.841395142f
|
||||
#define LEVEL__3__dB 0.707106781f
|
||||
#define LEVEL__4_5dB 0.595662143f
|
||||
#define LEVEL__6__dB 0.500000000f
|
||||
#define LEVEL__7_5dB 0.421696503f
|
||||
#define LEVEL__9__dB 0.353553393f
|
||||
#define LEVEL_12__dB 0.250000000f
|
||||
#define LEVEL_15__dB 0.176776695f
|
||||
#define LEVEL_18__dB 0.125000000f
|
||||
#define LEVEL_21__dB 0.088388347f
|
||||
#define LEVEL_30__dB 0.031250000f
|
||||
#define LEVEL_45__dB 0.005524271f
|
||||
#define LEVEL_60__dB 0.000976562f
|
||||
|
||||
#define Qmf31( x) (int32)(x*(float)0x7FFFFFFF)
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
const int32 equalizerTbl[8][SUBBANDS_NUMBER] =
|
||||
{
|
||||
/* FLAT */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB)
|
||||
},
|
||||
/* BASS BOOST */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
|
||||
|
||||
Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB)
|
||||
},
|
||||
/* ROCK */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__3__dB),
|
||||
|
||||
Qmf31(LEVEL__4_5dB), Qmf31(LEVEL__6__dB),
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB)
|
||||
},
|
||||
/* POP */
|
||||
{
|
||||
Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
|
||||
Qmf31(LEVEL__1_5dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB)
|
||||
},
|
||||
/* JAZZ */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB)
|
||||
},
|
||||
/* CLASSICAL */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
Qmf31(LEVEL__9__dB), Qmf31(LEVEL__9__dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__1_5dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB)
|
||||
},
|
||||
/* TALK */
|
||||
{
|
||||
Qmf31(LEVEL__9__dB),
|
||||
|
||||
Qmf31(LEVEL__6__dB), Qmf31(LEVEL__6__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__1_5dB),
|
||||
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB), Qmf31(LEVEL__3__dB),
|
||||
Qmf31(LEVEL__3__dB)
|
||||
},
|
||||
/* FLAT */
|
||||
{
|
||||
Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB), Qmf31(LEVEL__0__dB),
|
||||
Qmf31(LEVEL__0__dB)
|
||||
}
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_equalizer(int32 *circ_buffer,
|
||||
e_equalization equalizerType,
|
||||
int32 *work_buff)
|
||||
{
|
||||
|
||||
if (equalizerType == flat)
|
||||
{
|
||||
for (int32 band = 0; band < FILTERBANK_BANDS; band += 2)
|
||||
{
|
||||
|
||||
int32 *pt_work_buff = &work_buff[band];
|
||||
int32 *inData = &circ_buffer[544 - (band<<5)];
|
||||
|
||||
int32 i;
|
||||
for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
|
||||
{
|
||||
int32 temp1 = (pt_work_buff[ i ]);
|
||||
int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
|
||||
int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
|
||||
int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
|
||||
*(inData++) = temp1;
|
||||
*(inData++) = temp2;
|
||||
*(inData++) = temp3;
|
||||
*(inData++) = temp4;
|
||||
}
|
||||
|
||||
inData -= SUBBANDS_NUMBER << 1;
|
||||
pt_work_buff++;
|
||||
|
||||
for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
|
||||
{
|
||||
int32 temp1 = (pt_work_buff[ i ]);
|
||||
int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
|
||||
int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
|
||||
int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
|
||||
*(inData++) = temp1;
|
||||
*(inData++) = temp2;
|
||||
*(inData++) = temp3;
|
||||
*(inData++) = temp4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const int32 *pt_equalizer = equalizerTbl[equalizerType&7];
|
||||
|
||||
|
||||
for (int32 band = 0; band < FILTERBANK_BANDS; band += 3)
|
||||
{
|
||||
int32 *inData = &circ_buffer[544 - (band<<5)];
|
||||
|
||||
int32 *pt_work_buff = &work_buff[band];
|
||||
int32 i;
|
||||
|
||||
for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
|
||||
{
|
||||
int32 temp1 = (pt_work_buff[ i ]);
|
||||
int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
|
||||
int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
|
||||
int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
|
||||
*(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
|
||||
}
|
||||
|
||||
pt_equalizer -= SUBBANDS_NUMBER;
|
||||
|
||||
inData -= SUBBANDS_NUMBER << 1;
|
||||
pt_work_buff++;
|
||||
|
||||
for (i = 0; i < SUBBANDS_NUMBER*FILTERBANK_BANDS; i += FILTERBANK_BANDS << 2)
|
||||
{
|
||||
int32 temp1 = (pt_work_buff[ i ]);
|
||||
int32 temp2 = (pt_work_buff[ i + FILTERBANK_BANDS ]);
|
||||
int32 temp3 = (pt_work_buff[ i + 2*FILTERBANK_BANDS ]);
|
||||
int32 temp4 = (pt_work_buff[ i + 3*FILTERBANK_BANDS ]);
|
||||
*(inData++) = fxp_mul32_Q32(temp1 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp2 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp3 << 1, *(pt_equalizer++));
|
||||
*(inData++) = fxp_mul32_Q32(temp4 << 1, *(pt_equalizer++));
|
||||
}
|
||||
pt_equalizer -= SUBBANDS_NUMBER;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_equalizer.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_EQUALIZER_H
|
||||
#define PVMP3_EQUALIZER_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_equalizer(int32 *inData,
|
||||
e_equalization equalizerType,
|
||||
int32 *pt_work_buff);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,834 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_framedecoder.cpp
|
||||
|
||||
Functions:
|
||||
pvmp3_framedecoder
|
||||
pvmp3_InitDecoder
|
||||
pvmp3_resetDecoder
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
pExt = pointer to the external interface structure. See the file
|
||||
pvmp3decoder_api.h for a description of each field.
|
||||
Data type of pointer to a tPVMP3DecoderExternal
|
||||
structure.
|
||||
|
||||
pMem = void pointer to hide the internal implementation of the library
|
||||
It is cast back to a tmp3dec_file structure. This structure
|
||||
contains information that needs to persist between calls to
|
||||
this function, or is too big to be placed on the stack, even
|
||||
though the data is only needed during execution of this function
|
||||
Data type void pointer, internally pointer to a tmp3dec_file
|
||||
structure.
|
||||
|
||||
|
||||
Outputs:
|
||||
status = ERROR condition. see structure ERROR_CODE
|
||||
|
||||
Pointers and Buffers Modified:
|
||||
pMem contents are modified.
|
||||
pExt: (more detail in the file pvmp3decoder_api.h)
|
||||
inputBufferUsedLength - number of array elements used up by the stream.
|
||||
samplingRate - sampling rate in samples per sec
|
||||
bitRate - bit rate in bits per second, varies frame to frame.
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTIONS DESCRIPTION
|
||||
|
||||
pvmp3_framedecoder
|
||||
frame decoder library driver
|
||||
pvmp3_InitDecoder
|
||||
Decoder Initialization
|
||||
pvmp3_resetDecoder
|
||||
Reset Decoder
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "pvmp3_framedecoder.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_poly_phase_synthesis.h"
|
||||
#include "pvmp3_tables.h"
|
||||
#include "pvmp3_imdct_synth.h"
|
||||
#include "pvmp3_alias_reduction.h"
|
||||
#include "pvmp3_reorder.h"
|
||||
#include "pvmp3_dequantize_sample.h"
|
||||
#include "pvmp3_stereo_proc.h"
|
||||
#include "pvmp3_mpeg2_stereo_proc.h"
|
||||
#include "pvmp3_get_side_info.h"
|
||||
#include "pvmp3_get_scale_factors.h"
|
||||
#include "pvmp3_mpeg2_get_scale_factors.h"
|
||||
#include "pvmp3_decode_header.h"
|
||||
#include "pvmp3_get_main_data_size.h"
|
||||
#include "s_tmp3dec_file.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem)
|
||||
{
|
||||
|
||||
ERROR_CODE errorCode = NO_DECODING_ERROR;
|
||||
|
||||
int32 crc_error_count = 0;
|
||||
uint32 sent_crc = 0;
|
||||
uint32 computed_crc = 0;
|
||||
|
||||
tmp3dec_chan *pChVars[CHAN];
|
||||
tmp3dec_file *pVars = (tmp3dec_file *)pMem;
|
||||
|
||||
mp3Header info_data;
|
||||
mp3Header *info = &info_data;
|
||||
|
||||
pVars->inputStream.pBuffer = pExt->pInputBuffer;
|
||||
|
||||
|
||||
pVars->inputStream.usedBits = pExt->inputBufferUsedLength << 3;
|
||||
pVars->inputStream.inputBufferCurrentLength = pExt->inputBufferCurrentLength;
|
||||
|
||||
|
||||
errorCode = pvmp3_decode_header(&pVars->inputStream,
|
||||
info,
|
||||
&computed_crc);
|
||||
|
||||
if (errorCode != NO_DECODING_ERROR)
|
||||
{
|
||||
pExt->outputFrameSize = 0;
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
pVars->num_channels = (info->mode == MPG_MD_MONO) ? 1 : 2;
|
||||
pExt->num_channels = pVars->num_channels;
|
||||
|
||||
int32 outputFrameSize = (info->version_x == MPEG_1) ?
|
||||
2 * SUBBANDS_NUMBER * FILTERBANK_BANDS :
|
||||
SUBBANDS_NUMBER * FILTERBANK_BANDS;
|
||||
|
||||
outputFrameSize = (info->mode == MPG_MD_MONO) ? outputFrameSize : outputFrameSize << 1;
|
||||
|
||||
|
||||
/*
|
||||
* Check if output buffer has enough room to hold output PCM
|
||||
*/
|
||||
if (pExt->outputFrameSize >= outputFrameSize)
|
||||
{
|
||||
pExt->outputFrameSize = outputFrameSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExt->outputFrameSize = 0;
|
||||
return OUTPUT_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
|
||||
pChVars[ LEFT] = &pVars->perChan[ LEFT];
|
||||
pChVars[RIGHT] = &pVars->perChan[RIGHT];
|
||||
|
||||
|
||||
|
||||
|
||||
if (info->error_protection)
|
||||
{
|
||||
/*
|
||||
* Get crc content
|
||||
*/
|
||||
sent_crc = getUpTo17bits(&pVars->inputStream, 16);
|
||||
}
|
||||
|
||||
|
||||
if (info->layer_description == 3)
|
||||
{
|
||||
int32 gr;
|
||||
int32 ch;
|
||||
uint32 main_data_end;
|
||||
int32 bytes_to_discard;
|
||||
int16 *ptrOutBuffer = pExt->pOutputBuffer;
|
||||
|
||||
/*
|
||||
* Side Information must be extracted from the bitstream and store for use
|
||||
* during the decoded of the associated frame
|
||||
*/
|
||||
|
||||
errorCode = pvmp3_get_side_info(&pVars->inputStream,
|
||||
&pVars->sideInfo,
|
||||
info,
|
||||
&computed_crc);
|
||||
|
||||
if (errorCode != NO_DECODING_ERROR)
|
||||
{
|
||||
pExt->outputFrameSize = 0;
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/*
|
||||
* If CRC was sent, check that matches the one got while parsing data
|
||||
* disable crc if this is the desired mode
|
||||
*/
|
||||
if (info->error_protection)
|
||||
{
|
||||
if ((computed_crc != sent_crc) && pExt->crcEnabled)
|
||||
{
|
||||
crc_error_count++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* main data (scalefactors, Huffman coded, etc,) are not necessarily located
|
||||
* adjacent to the side-info. Beginning of main data is located using
|
||||
* field "main_data_begin" of the current frame. The length does not include
|
||||
* header and side info.
|
||||
* "main_data_begin" points to the first bit of main data of a frame. It is a negative
|
||||
* offset in bytes from the first byte of the sync word
|
||||
* main_data_begin = 0 <===> main data start rigth after side info.
|
||||
*/
|
||||
|
||||
int32 temp = pvmp3_get_main_data_size(info, pVars);
|
||||
|
||||
|
||||
/*
|
||||
* Check if available data holds a full frame, if not flag an error
|
||||
*/
|
||||
|
||||
if ((uint32)pVars->predicted_frame_size > pVars->inputStream.inputBufferCurrentLength)
|
||||
{
|
||||
pExt->outputFrameSize = 0;
|
||||
return NO_ENOUGH_MAIN_DATA_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in internal circular buffer
|
||||
*/
|
||||
fillMainDataBuf(pVars, temp);
|
||||
|
||||
|
||||
main_data_end = pVars->mainDataStream.usedBits >> 3; /* in bytes */
|
||||
if ((main_data_end << 3) < pVars->mainDataStream.usedBits)
|
||||
{
|
||||
main_data_end++;
|
||||
pVars->mainDataStream.usedBits = main_data_end << 3;
|
||||
}
|
||||
|
||||
|
||||
bytes_to_discard = pVars->frame_start - pVars->sideInfo.main_data_begin - main_data_end;
|
||||
|
||||
|
||||
if (main_data_end > BUFSIZE) /* check overflow on the buffer */
|
||||
{
|
||||
pVars->frame_start -= BUFSIZE;
|
||||
|
||||
pVars->mainDataStream.usedBits -= (BUFSIZE << 3);
|
||||
}
|
||||
|
||||
pVars->frame_start += temp;
|
||||
|
||||
|
||||
if (bytes_to_discard < 0 || crc_error_count)
|
||||
{
|
||||
/*
|
||||
* Not enough data to decode, then we should avoid reading this
|
||||
* data ( getting/ignoring sido info and scale data)
|
||||
* Main data could be located in the previous frame, so an unaccounted
|
||||
* frame can cause incorrect processing
|
||||
* Just run the polyphase filter to "clean" the history buffer
|
||||
*/
|
||||
errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
|
||||
|
||||
/*
|
||||
* Clear the input to these filters
|
||||
*/
|
||||
|
||||
pv_memset((void*)pChVars[RIGHT]->work_buf_int32,
|
||||
0,
|
||||
SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[RIGHT]->work_buf_int32[0]));
|
||||
|
||||
pv_memset((void*)pChVars[LEFT]->work_buf_int32,
|
||||
0,
|
||||
SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[LEFT]->work_buf_int32[0]));
|
||||
|
||||
/* clear circular buffers, to avoid any glitch */
|
||||
pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
|
||||
0,
|
||||
480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
|
||||
pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
|
||||
0,
|
||||
480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
|
||||
|
||||
pChVars[ LEFT]->used_freq_lines = 575;
|
||||
pChVars[RIGHT]->used_freq_lines = 575;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pVars->mainDataStream.usedBits += (bytes_to_discard << 3);
|
||||
}
|
||||
|
||||
/*
|
||||
* if (fr_ps->header->version_x == MPEG_1), use 2 granules, otherwise just 1
|
||||
*/
|
||||
for (gr = 0; gr < (1 + !(info->version_x)); gr++)
|
||||
{
|
||||
if (errorCode != NO_ENOUGH_MAIN_DATA_ERROR)
|
||||
{
|
||||
for (ch = 0; ch < pVars->num_channels; ch++)
|
||||
{
|
||||
int32 part2_start = pVars->mainDataStream.usedBits;
|
||||
|
||||
if (info->version_x == MPEG_1)
|
||||
{
|
||||
|
||||
pvmp3_get_scale_factors(&pVars->scaleFactors[ch],
|
||||
&pVars->sideInfo,
|
||||
gr,
|
||||
ch,
|
||||
&pVars->mainDataStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 * tmp = pVars->Scratch_mem;
|
||||
pvmp3_mpeg2_get_scale_factors(&pVars->scaleFactors[ch],
|
||||
&pVars->sideInfo,
|
||||
gr,
|
||||
ch,
|
||||
info,
|
||||
(uint32 *)tmp,
|
||||
&pVars->mainDataStream);
|
||||
}
|
||||
|
||||
pChVars[ch]->used_freq_lines = pvmp3_huffman_parsing(pChVars[ch]->work_buf_int32,
|
||||
&pVars->sideInfo.ch[ch].gran[gr],
|
||||
pVars,
|
||||
part2_start,
|
||||
info);
|
||||
|
||||
|
||||
pvmp3_dequantize_sample(pChVars[ch]->work_buf_int32,
|
||||
&pVars->scaleFactors[ch],
|
||||
&pVars->sideInfo.ch[ch].gran[gr],
|
||||
pChVars[ch]->used_freq_lines,
|
||||
info);
|
||||
|
||||
|
||||
|
||||
|
||||
} /* for (ch=0; ch<stereo; ch++) */
|
||||
|
||||
if (pVars->num_channels == 2)
|
||||
{
|
||||
|
||||
int32 used_freq_lines = (pChVars[ LEFT]->used_freq_lines >
|
||||
pChVars[RIGHT]->used_freq_lines) ?
|
||||
pChVars[ LEFT]->used_freq_lines :
|
||||
pChVars[RIGHT]->used_freq_lines;
|
||||
|
||||
pChVars[ LEFT]->used_freq_lines = used_freq_lines;
|
||||
pChVars[RIGHT]->used_freq_lines = used_freq_lines;
|
||||
|
||||
if (info->version_x == MPEG_1)
|
||||
{
|
||||
pvmp3_stereo_proc(pChVars[ LEFT]->work_buf_int32,
|
||||
pChVars[RIGHT]->work_buf_int32,
|
||||
&pVars->scaleFactors[RIGHT],
|
||||
&pVars->sideInfo.ch[LEFT].gran[gr],
|
||||
used_freq_lines,
|
||||
info);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 * tmp = pVars->Scratch_mem;
|
||||
pvmp3_mpeg2_stereo_proc(pChVars[ LEFT]->work_buf_int32,
|
||||
pChVars[RIGHT]->work_buf_int32,
|
||||
&pVars->scaleFactors[RIGHT],
|
||||
&pVars->sideInfo.ch[ LEFT].gran[gr],
|
||||
&pVars->sideInfo.ch[RIGHT].gran[gr],
|
||||
(uint32 *)tmp,
|
||||
used_freq_lines,
|
||||
info);
|
||||
}
|
||||
}
|
||||
|
||||
} /* if ( errorCode != NO_ENOUGH_MAIN_DATA_ERROR) */
|
||||
|
||||
for (ch = 0; ch < pVars->num_channels; ch++)
|
||||
{
|
||||
|
||||
pvmp3_reorder(pChVars[ch]->work_buf_int32,
|
||||
&pVars->sideInfo.ch[ch].gran[gr],
|
||||
&pChVars[ ch]->used_freq_lines,
|
||||
info,
|
||||
pVars->Scratch_mem);
|
||||
|
||||
pvmp3_alias_reduction(pChVars[ch]->work_buf_int32,
|
||||
&pVars->sideInfo.ch[ch].gran[gr],
|
||||
&pChVars[ ch]->used_freq_lines,
|
||||
info);
|
||||
|
||||
|
||||
/*
|
||||
* IMDCT
|
||||
*/
|
||||
/* set mxposition
|
||||
* In case of mixed blocks, # of bands with long
|
||||
* blocks (2 or 4) else 0
|
||||
*/
|
||||
uint16 mixedBlocksLongBlocks = 0; /* 0 = long or short, 2=mixed, 4=mixed 2.5@8000 */
|
||||
if (pVars->sideInfo.ch[ch].gran[gr].mixed_block_flag &&
|
||||
pVars->sideInfo.ch[ch].gran[gr].window_switching_flag)
|
||||
{
|
||||
if ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2))
|
||||
{
|
||||
mixedBlocksLongBlocks = 4; /* mpeg2.5 @ 8 KHz */
|
||||
}
|
||||
else
|
||||
{
|
||||
mixedBlocksLongBlocks = 2;
|
||||
}
|
||||
}
|
||||
|
||||
pvmp3_imdct_synth(pChVars[ch]->work_buf_int32,
|
||||
pChVars[ch]->overlap,
|
||||
pVars->sideInfo.ch[ch].gran[gr].block_type,
|
||||
mixedBlocksLongBlocks,
|
||||
pChVars[ ch]->used_freq_lines,
|
||||
pVars->Scratch_mem);
|
||||
|
||||
|
||||
/*
|
||||
* Polyphase synthesis
|
||||
*/
|
||||
|
||||
pvmp3_poly_phase_synthesis(pChVars[ch],
|
||||
pVars->num_channels,
|
||||
pExt->equalizerType,
|
||||
&ptrOutBuffer[ch]);
|
||||
|
||||
|
||||
}/* end ch loop */
|
||||
|
||||
ptrOutBuffer += pVars->num_channels * SUBBANDS_NUMBER * FILTERBANK_BANDS;
|
||||
} /* for (gr=0;gr<Max_gr;gr++) */
|
||||
|
||||
/* skip ancillary data */
|
||||
if (info->bitrate_index > 0)
|
||||
{ /* if not free-format */
|
||||
|
||||
int32 ancillary_data_lenght = pVars->predicted_frame_size << 3;
|
||||
|
||||
ancillary_data_lenght -= pVars->inputStream.usedBits;
|
||||
|
||||
/* skip ancillary data */
|
||||
if (ancillary_data_lenght > 0)
|
||||
{
|
||||
pVars->inputStream.usedBits += ancillary_data_lenght;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* This overrides a possible NO_ENOUGH_MAIN_DATA_ERROR
|
||||
*/
|
||||
errorCode = NO_DECODING_ERROR;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* The info on the header leads to an unsupported layer, more data
|
||||
* will not fix this, so this is a bad frame,
|
||||
*/
|
||||
|
||||
pExt->outputFrameSize = 0;
|
||||
return UNSUPPORTED_LAYER;
|
||||
}
|
||||
|
||||
pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3;
|
||||
pExt->totalNumberOfBitsUsed += pVars->inputStream.usedBits;
|
||||
pExt->version = info->version_x;
|
||||
pExt->samplingRate = mp3_s_freq[info->version_x][info->sampling_frequency];
|
||||
pExt->bitRate = mp3_bitrate[pExt->version][info->bitrate_index];
|
||||
|
||||
|
||||
/*
|
||||
* Always verify buffer overrun condition
|
||||
*/
|
||||
|
||||
if (pExt->inputBufferUsedLength > pExt->inputBufferCurrentLength)
|
||||
{
|
||||
pExt->outputFrameSize = 0;
|
||||
errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
__inline void fillDataBuf(tmp3Bits *pMainData,
|
||||
uint32 val) /* val to write into the buffer */
|
||||
{
|
||||
pMainData->pBuffer[module(pMainData->offset++, BUFSIZE)] = (uint8)val;
|
||||
}
|
||||
|
||||
|
||||
void fillMainDataBuf(void *pMem, int32 temp)
|
||||
{
|
||||
tmp3dec_file *pVars = (tmp3dec_file *)pMem;
|
||||
|
||||
|
||||
int32 offset = (pVars->inputStream.usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
|
||||
|
||||
/*
|
||||
* Check if input circular buffer boundaries need to be enforced
|
||||
*/
|
||||
if ((offset + temp) < BUFSIZE)
|
||||
{
|
||||
uint8 * ptr = pVars->inputStream.pBuffer + offset;
|
||||
|
||||
offset = pVars->mainDataStream.offset;
|
||||
|
||||
/*
|
||||
* Check if main data circular buffer boundaries need to be enforced
|
||||
*/
|
||||
if ((offset + temp) < BUFSIZE)
|
||||
{
|
||||
pv_memcpy((pVars->mainDataStream.pBuffer + offset), ptr, temp*sizeof(uint8));
|
||||
pVars->mainDataStream.offset += temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 tmp1 = *(ptr++);
|
||||
for (int32 nBytes = temp >> 1; nBytes != 0; nBytes--) /* read main data. */
|
||||
{
|
||||
int32 tmp2 = *(ptr++);
|
||||
fillDataBuf(&pVars->mainDataStream, tmp1);
|
||||
fillDataBuf(&pVars->mainDataStream, tmp2);
|
||||
tmp1 = *(ptr++);
|
||||
}
|
||||
|
||||
if (temp&1)
|
||||
{
|
||||
fillDataBuf(&pVars->mainDataStream, tmp1);
|
||||
}
|
||||
|
||||
/* adjust circular buffer counter */
|
||||
pVars->mainDataStream.offset = module(pVars->mainDataStream.offset, BUFSIZE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int32 nBytes = temp >> 1; nBytes != 0; nBytes--) /* read main data. */
|
||||
{
|
||||
fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset++ , BUFSIZE)));
|
||||
fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset++ , BUFSIZE)));
|
||||
}
|
||||
if (temp&1)
|
||||
{
|
||||
fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset , BUFSIZE)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pVars->inputStream.usedBits += (temp) << INBUF_ARRAY_INDEX_SHIFT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint32 pvmp3_decoderMemRequirements(void)
|
||||
{
|
||||
uint32 size;
|
||||
|
||||
size = (uint32) sizeof(tmp3dec_file);
|
||||
return (size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_decode_huff_cw.h"
|
||||
|
||||
void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem)
|
||||
{
|
||||
|
||||
tmp3dec_file *pVars;
|
||||
huffcodetab *pHuff;
|
||||
|
||||
pVars = (tmp3dec_file *)pMem;
|
||||
|
||||
pVars->num_channels = 0;
|
||||
|
||||
pExt->totalNumberOfBitsUsed = 0;
|
||||
pExt->inputBufferCurrentLength = 0;
|
||||
pExt->inputBufferUsedLength = 0;
|
||||
|
||||
pVars->mainDataStream.offset = 0;
|
||||
|
||||
pv_memset((void*)pVars->mainDataBuffer,
|
||||
0,
|
||||
BUFSIZE*sizeof(*pVars->mainDataBuffer));
|
||||
|
||||
|
||||
pVars->inputStream.pBuffer = pExt->pInputBuffer;
|
||||
|
||||
/*
|
||||
* Initialize huffman decoding table
|
||||
*/
|
||||
|
||||
pHuff = pVars->ht;
|
||||
pHuff[0].linbits = 0;
|
||||
pHuff[0].pdec_huff_tab = pvmp3_decode_huff_cw_tab0;
|
||||
pHuff[1].linbits = 0;
|
||||
pHuff[1].pdec_huff_tab = pvmp3_decode_huff_cw_tab1;
|
||||
pHuff[2].linbits = 0;
|
||||
pHuff[2].pdec_huff_tab = pvmp3_decode_huff_cw_tab2;
|
||||
pHuff[3].linbits = 0;
|
||||
pHuff[3].pdec_huff_tab = pvmp3_decode_huff_cw_tab3;
|
||||
pHuff[4].linbits = 0;
|
||||
pHuff[4].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 4 is not used */
|
||||
pHuff[5].linbits = 4;
|
||||
pHuff[5].pdec_huff_tab = pvmp3_decode_huff_cw_tab5;
|
||||
pHuff[6].linbits = 0;
|
||||
pHuff[6].pdec_huff_tab = pvmp3_decode_huff_cw_tab6;
|
||||
pHuff[7].linbits = 0;
|
||||
pHuff[7].pdec_huff_tab = pvmp3_decode_huff_cw_tab7;
|
||||
pHuff[8].linbits = 0;
|
||||
pHuff[8].pdec_huff_tab = pvmp3_decode_huff_cw_tab8;
|
||||
pHuff[9].linbits = 0;
|
||||
pHuff[9].pdec_huff_tab = pvmp3_decode_huff_cw_tab9;
|
||||
pHuff[10].linbits = 0;
|
||||
pHuff[10].pdec_huff_tab = pvmp3_decode_huff_cw_tab10;
|
||||
pHuff[11].linbits = 0;
|
||||
pHuff[11].pdec_huff_tab = pvmp3_decode_huff_cw_tab11;
|
||||
pHuff[12].linbits = 0;
|
||||
pHuff[12].pdec_huff_tab = pvmp3_decode_huff_cw_tab12;
|
||||
pHuff[13].linbits = 0;
|
||||
pHuff[13].pdec_huff_tab = pvmp3_decode_huff_cw_tab13;
|
||||
pHuff[14].linbits = 0;
|
||||
pHuff[14].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 14 is not used */
|
||||
pHuff[15].linbits = 0;
|
||||
pHuff[15].pdec_huff_tab = pvmp3_decode_huff_cw_tab15;
|
||||
pHuff[16].linbits = 1;
|
||||
pHuff[16].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[17].linbits = 2;
|
||||
pHuff[17].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[18].linbits = 3;
|
||||
pHuff[18].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[19].linbits = 4;
|
||||
pHuff[19].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[20].linbits = 6;
|
||||
pHuff[20].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[21].linbits = 8;
|
||||
pHuff[21].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[22].linbits = 10;
|
||||
pHuff[22].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[23].linbits = 13;
|
||||
pHuff[23].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
|
||||
pHuff[24].linbits = 4;
|
||||
pHuff[24].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[25].linbits = 5;
|
||||
pHuff[25].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[26].linbits = 6;
|
||||
pHuff[26].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[27].linbits = 7;
|
||||
pHuff[27].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[28].linbits = 8;
|
||||
pHuff[28].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[29].linbits = 9;
|
||||
pHuff[29].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[30].linbits = 11;
|
||||
pHuff[30].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[31].linbits = 13;
|
||||
pHuff[31].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
|
||||
pHuff[32].linbits = 0;
|
||||
pHuff[32].pdec_huff_tab = pvmp3_decode_huff_cw_tab32;
|
||||
pHuff[33].linbits = 0;
|
||||
pHuff[33].pdec_huff_tab = pvmp3_decode_huff_cw_tab33;
|
||||
|
||||
/*
|
||||
* Initialize polysynthesis circular buffer mechanism
|
||||
*/
|
||||
/* clear buffers */
|
||||
|
||||
pvmp3_resetDecoder(pMem);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void pvmp3_resetDecoder(void *pMem)
|
||||
{
|
||||
|
||||
tmp3dec_file *pVars;
|
||||
tmp3dec_chan *pChVars[CHAN];
|
||||
|
||||
pVars = (tmp3dec_file *)pMem;
|
||||
pChVars[ LEFT] = &pVars->perChan[ LEFT];
|
||||
pChVars[RIGHT] = &pVars->perChan[RIGHT];
|
||||
|
||||
pVars->frame_start = 0;
|
||||
|
||||
pVars->mainDataStream.offset = 0;
|
||||
|
||||
pVars->mainDataStream.pBuffer = pVars->mainDataBuffer;
|
||||
pVars->mainDataStream.usedBits = 0;
|
||||
|
||||
|
||||
pVars->inputStream.usedBits = 0; // in bits
|
||||
|
||||
|
||||
pChVars[ LEFT]->used_freq_lines = 575;
|
||||
pChVars[RIGHT]->used_freq_lines = 575;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize polysynthesis circular buffer mechanism
|
||||
*/
|
||||
|
||||
pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
|
||||
0,
|
||||
480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
|
||||
pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
|
||||
0,
|
||||
480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
|
||||
|
||||
|
||||
pv_memset((void*)pChVars[ LEFT]->overlap,
|
||||
0,
|
||||
SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ LEFT]->overlap[0]));
|
||||
|
||||
|
||||
pv_memset((void*)pChVars[ RIGHT]->overlap,
|
||||
0,
|
||||
SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ RIGHT]->overlap[0]));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Clear all the structures
|
||||
*/
|
||||
|
||||
|
||||
pv_memset((void*)&pVars->scaleFactors[RIGHT],
|
||||
0,
|
||||
sizeof(mp3ScaleFactors));
|
||||
|
||||
pv_memset((void*)&pVars->scaleFactors[LEFT],
|
||||
0,
|
||||
sizeof(mp3ScaleFactors));
|
||||
|
||||
pv_memset((void*)&pVars->sideInfo,
|
||||
0,
|
||||
sizeof(mp3SideInfo));
|
||||
|
||||
pv_memset((void*)&pVars->sideInfo,
|
||||
0,
|
||||
sizeof(mp3SideInfo));
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_framedecoder.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_FRAMEDECODER_H
|
||||
#define PVMP3_FRAMEDECODER_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem);
|
||||
|
||||
|
||||
|
||||
uint32 pvmp3_decoderMemRequirements(void);
|
||||
|
||||
void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem);
|
||||
|
||||
|
||||
void pvmp3_resetDecoder(void *pMem);
|
||||
|
||||
|
||||
void fillMainDataBuf(void *pMem, int32 temp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_main_data_size.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
mp3Header *info, pointer to mp3 header info structure
|
||||
tmp3dec_file *pVars
|
||||
contains information that needs to persist
|
||||
between calls to this function, or is too big to
|
||||
be placed on the stack, even though the data is
|
||||
only needed during execution of this function
|
||||
|
||||
Returns
|
||||
|
||||
main data frame size
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
get main data frame size
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_tables.h"
|
||||
#include "pvmp3_get_main_data_size.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
int32 pvmp3_get_main_data_size(mp3Header *info,
|
||||
tmp3dec_file *pVars)
|
||||
{
|
||||
|
||||
|
||||
int32 numBytes = fxp_mul32_Q28(mp3_bitrate[info->version_x][info->bitrate_index] << 20,
|
||||
inv_sfreq[info->sampling_frequency]);
|
||||
|
||||
|
||||
numBytes >>= (20 - info->version_x);
|
||||
|
||||
/*
|
||||
* Remove the size of the side information from the main data total
|
||||
*/
|
||||
if (info->version_x == MPEG_1)
|
||||
{
|
||||
pVars->predicted_frame_size = numBytes;
|
||||
if (info->mode == MPG_MD_MONO)
|
||||
{
|
||||
numBytes -= 17;
|
||||
}
|
||||
else
|
||||
{
|
||||
numBytes -= 32;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
numBytes >>= 1;
|
||||
pVars->predicted_frame_size = numBytes;
|
||||
|
||||
if (info->mode == MPG_MD_MONO)
|
||||
{
|
||||
numBytes -= 9;
|
||||
}
|
||||
else
|
||||
{
|
||||
numBytes -= 17;
|
||||
}
|
||||
}
|
||||
|
||||
if (info->padding)
|
||||
{
|
||||
numBytes++;
|
||||
pVars->predicted_frame_size++;
|
||||
}
|
||||
|
||||
if (info->error_protection)
|
||||
{
|
||||
numBytes -= 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
numBytes -= 4;
|
||||
}
|
||||
|
||||
|
||||
if (numBytes < 0)
|
||||
{
|
||||
numBytes = 0;
|
||||
}
|
||||
|
||||
return(numBytes);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_main_data_size.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_GET_MAIN_DATA_SIZE_H
|
||||
#define PVMP3_GET_MAIN_DATA_SIZE_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_tmp3dec_file.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int32 pvmp3_get_main_data_size(mp3Header *info,
|
||||
tmp3dec_file *pVars);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_scale_factors.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si, side info
|
||||
int32 gr, granule
|
||||
int32 ch, channel
|
||||
tbits *pMainData bit stream
|
||||
|
||||
Returns
|
||||
|
||||
mp3ScaleFactors *scalefac, scale factors
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
get scale factors
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_get_scale_factors.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt_28(a)(int32(double(0x10000000)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 slen[2][16] =
|
||||
{
|
||||
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
|
||||
{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
|
||||
};
|
||||
|
||||
const struct
|
||||
{
|
||||
int32 l[5];
|
||||
int32 s[3];
|
||||
} sfbtable =
|
||||
{
|
||||
{0, 6, 11, 16, 21},
|
||||
{0, 6, 12}
|
||||
};
|
||||
|
||||
const int32 long_sfbtable[4] = { 6, 5, 5, 5};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_get_scale_factors(mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
int32 sfb;
|
||||
int32 i;
|
||||
int32 window;
|
||||
granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
|
||||
|
||||
if (gr_info->window_switching_flag && (gr_info->block_type == 2))
|
||||
{
|
||||
if (gr_info->mixed_block_flag)
|
||||
{ /* MIXED */
|
||||
for (sfb = 0; sfb < 8; sfb++)
|
||||
{
|
||||
scalefac->l[sfb] = getNbits(pMainData, slen[0][gr_info->scalefac_compress]);
|
||||
}
|
||||
|
||||
for (sfb = 3; sfb < 6; sfb++)
|
||||
{
|
||||
for (window = 0; window < 3; window++)
|
||||
{
|
||||
scalefac->s[window][sfb] = getNbits(pMainData, slen[0][gr_info->scalefac_compress]);
|
||||
}
|
||||
}
|
||||
for (sfb = 6; sfb < 12; sfb++)
|
||||
{
|
||||
for (window = 0; window < 3; window++)
|
||||
{
|
||||
scalefac->s[window][sfb] = getNbits(pMainData, slen[1][gr_info->scalefac_compress]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* SHORT*/
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
for (sfb = sfbtable.s[i]; sfb < sfbtable.s[i+1]; sfb++)
|
||||
{
|
||||
for (window = 0; window < 3; window++)
|
||||
{
|
||||
scalefac->s[window][sfb] = getNbits(pMainData, slen[i][gr_info->scalefac_compress]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scalefac->s[0][12] = 0; /* sfb = 12 win= 0 */
|
||||
scalefac->s[1][12] = 0; /* sfb = 12 win= 1 */
|
||||
scalefac->s[2][12] = 0; /* sfb = 12 win= 2 */
|
||||
}
|
||||
else
|
||||
{ /* LONG types 0,1,3 */
|
||||
|
||||
int32 *ptr = &scalefac->l[0];
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
int32 tmp4 = long_sfbtable[i];
|
||||
|
||||
if ((si->ch[ch].scfsi[i] == 0) || (gr == 0))
|
||||
{
|
||||
int32 tmp1 = slen[(i>>1)][gr_info->scalefac_compress];
|
||||
|
||||
if (tmp1)
|
||||
{
|
||||
int32 tmp2 = tmp1 * tmp4;
|
||||
uint32 tmp3 = getNbits(pMainData, tmp2);
|
||||
tmp4 = 32 - tmp1;
|
||||
for (; tmp2 > 0; tmp2 -= tmp1)
|
||||
{
|
||||
*(ptr++) = (tmp3 << (32 - tmp2)) >> tmp4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (sfb = tmp4; sfb != 0; sfb--)
|
||||
{
|
||||
*(ptr++) = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr += tmp4;
|
||||
}
|
||||
}
|
||||
scalefac->l[21] = 0;
|
||||
scalefac->l[22] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_scale_factors.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_GET_SCALE_FACTORS_H
|
||||
#define PVMP3_GET_SCALE_FACTORS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_get_scale_factors(mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_side_info.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
mp3SideInfo *si,
|
||||
mp3Header *info, mp3 header information
|
||||
uint32 *crc initialized crc value (if enabled)
|
||||
|
||||
|
||||
Returns
|
||||
|
||||
mp3SideInfo *si, side information
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
acquires side information
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_get_side_info.h"
|
||||
#include "pvmp3_crc.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
ERROR_CODE pvmp3_get_side_info(tmp3Bits *inputStream,
|
||||
mp3SideInfo *si,
|
||||
mp3Header *info,
|
||||
uint32 *crc)
|
||||
{
|
||||
int32 ch, gr;
|
||||
uint32 tmp;
|
||||
|
||||
int stereo = (info->mode == MPG_MD_MONO) ? 1 : 2;
|
||||
|
||||
if (info->version_x == MPEG_1)
|
||||
{
|
||||
if (stereo == 1)
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 14, crc, info->error_protection);
|
||||
si->main_data_begin = (tmp << 18) >> 23; /* 9 */
|
||||
si->private_bits = (tmp << 23) >> 27; /* 5 */
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 12, crc, info->error_protection);
|
||||
si->main_data_begin = (tmp << 20) >> 23; /* 9 */
|
||||
si->private_bits = (tmp << 23) >> 29; /* 3 */
|
||||
|
||||
}
|
||||
|
||||
for (ch = 0; ch < stereo; ch++)
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 4, crc, info->error_protection);
|
||||
si->ch[ch].scfsi[0] = (tmp << 28) >> 31; /* 1 */
|
||||
si->ch[ch].scfsi[1] = (tmp << 29) >> 31; /* 1 */
|
||||
si->ch[ch].scfsi[2] = (tmp << 30) >> 31; /* 1 */
|
||||
si->ch[ch].scfsi[3] = tmp & 1; /* 1 */
|
||||
}
|
||||
|
||||
for (gr = 0; gr < 2 ; gr++)
|
||||
{
|
||||
for (ch = 0; ch < stereo; ch++)
|
||||
{
|
||||
si->ch[ch].gran[gr].part2_3_length = getbits_crc(inputStream, 12, crc, info->error_protection);
|
||||
tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
|
||||
|
||||
si->ch[ch].gran[gr].big_values = (tmp << 10) >> 23; /* 9 */
|
||||
si->ch[ch].gran[gr].global_gain = ((tmp << 19) >> 24) - 210; /* 8 */
|
||||
si->ch[ch].gran[gr].scalefac_compress = (tmp << 27) >> 28; /* 4 */
|
||||
si->ch[ch].gran[gr].window_switching_flag = tmp & 1; /* 1 */
|
||||
|
||||
if (si->ch[ch].gran[gr].window_switching_flag)
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
|
||||
|
||||
si->ch[ch].gran[gr].block_type = (tmp << 10) >> 30; /* 2 */;
|
||||
si->ch[ch].gran[gr].mixed_block_flag = (tmp << 12) >> 31; /* 1 */;
|
||||
|
||||
si->ch[ch].gran[gr].table_select[0] = (tmp << 13) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[gr].table_select[1] = (tmp << 18) >> 27; /* 5 */;
|
||||
|
||||
si->ch[ch].gran[gr].subblock_gain[0] = (tmp << 23) >> 29; /* 3 */;
|
||||
si->ch[ch].gran[gr].subblock_gain[1] = (tmp << 26) >> 29; /* 3 */;
|
||||
si->ch[ch].gran[gr].subblock_gain[2] = (tmp << 29) >> 29; /* 3 */;
|
||||
|
||||
/* Set region_count parameters since they are implicit in this case. */
|
||||
|
||||
if (si->ch[ch].gran[gr].block_type == 0)
|
||||
{
|
||||
return(SIDE_INFO_ERROR);
|
||||
}
|
||||
else if ((si->ch[ch].gran[gr].block_type == 2)
|
||||
&& (si->ch[ch].gran[gr].mixed_block_flag == 0))
|
||||
{
|
||||
si->ch[ch].gran[gr].region0_count = 8; /* MI 9; */
|
||||
si->ch[ch].gran[gr].region1_count = 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
si->ch[ch].gran[gr].region0_count = 7; /* MI 8; */
|
||||
si->ch[ch].gran[gr].region1_count = 13;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
|
||||
|
||||
si->ch[ch].gran[gr].table_select[0] = (tmp << 10) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[gr].table_select[1] = (tmp << 15) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[gr].table_select[2] = (tmp << 20) >> 27; /* 5 */;
|
||||
|
||||
si->ch[ch].gran[gr].region0_count = (tmp << 25) >> 28; /* 4 */;
|
||||
si->ch[ch].gran[gr].region1_count = (tmp << 29) >> 29; /* 3 */;
|
||||
|
||||
si->ch[ch].gran[gr].block_type = 0;
|
||||
}
|
||||
|
||||
tmp = getbits_crc(inputStream, 3, crc, info->error_protection);
|
||||
si->ch[ch].gran[gr].preflag = (tmp << 29) >> 31; /* 1 */
|
||||
si->ch[ch].gran[gr].scalefac_scale = (tmp << 30) >> 31; /* 1 */
|
||||
si->ch[ch].gran[gr].count1table_select = tmp & 1; /* 1 */
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* Layer 3 LSF */
|
||||
{
|
||||
si->main_data_begin = getbits_crc(inputStream, 8, crc, info->error_protection);
|
||||
si->private_bits = getbits_crc(inputStream, stereo, crc, info->error_protection);
|
||||
|
||||
for (ch = 0; ch < stereo; ch++)
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 21, crc, info->error_protection);
|
||||
si->ch[ch].gran[0].part2_3_length = (tmp << 11) >> 20; /* 12 */
|
||||
si->ch[ch].gran[0].big_values = (tmp << 23) >> 23; /* 9 */
|
||||
|
||||
tmp = getbits_crc(inputStream, 18, crc, info->error_protection);
|
||||
si->ch[ch].gran[0].global_gain = ((tmp << 14) >> 24) - 210; /* 8 */
|
||||
si->ch[ch].gran[0].scalefac_compress = (tmp << 22) >> 23; /* 9 */
|
||||
si->ch[ch].gran[0].window_switching_flag = tmp & 1; /* 1 */
|
||||
|
||||
if (si->ch[ch].gran[0].window_switching_flag)
|
||||
{
|
||||
|
||||
tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
|
||||
|
||||
si->ch[ch].gran[0].block_type = (tmp << 10) >> 30; /* 2 */;
|
||||
si->ch[ch].gran[0].mixed_block_flag = (tmp << 12) >> 31; /* 1 */;
|
||||
|
||||
si->ch[ch].gran[0].table_select[0] = (tmp << 13) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[0].table_select[1] = (tmp << 18) >> 27; /* 5 */;
|
||||
|
||||
si->ch[ch].gran[0].subblock_gain[0] = (tmp << 23) >> 29; /* 3 */;
|
||||
si->ch[ch].gran[0].subblock_gain[1] = (tmp << 26) >> 29; /* 3 */;
|
||||
si->ch[ch].gran[0].subblock_gain[2] = (tmp << 29) >> 29; /* 3 */;
|
||||
|
||||
/* Set region_count parameters since they are implicit in this case. */
|
||||
|
||||
if (si->ch[ch].gran[0].block_type == 0)
|
||||
{
|
||||
return(SIDE_INFO_ERROR);
|
||||
}
|
||||
else if ((si->ch[ch].gran[0].block_type == 2)
|
||||
&& (si->ch[ch].gran[0].mixed_block_flag == 0))
|
||||
{
|
||||
si->ch[ch].gran[0].region0_count = 8; /* MI 9; */
|
||||
si->ch[ch].gran[0].region1_count = 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
si->ch[ch].gran[0].region0_count = 7; /* MI 8; */
|
||||
si->ch[ch].gran[0].region1_count = 13;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = getbits_crc(inputStream, 22, crc, info->error_protection);
|
||||
|
||||
si->ch[ch].gran[0].table_select[0] = (tmp << 10) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[0].table_select[1] = (tmp << 15) >> 27; /* 5 */;
|
||||
si->ch[ch].gran[0].table_select[2] = (tmp << 20) >> 27; /* 5 */;
|
||||
|
||||
si->ch[ch].gran[0].region0_count = (tmp << 25) >> 28; /* 4 */;
|
||||
si->ch[ch].gran[0].region1_count = (tmp << 29) >> 29; /* 3 */;
|
||||
|
||||
si->ch[ch].gran[0].block_type = 0;
|
||||
}
|
||||
|
||||
tmp = getbits_crc(inputStream, 2, crc, info->error_protection);
|
||||
si->ch[ch].gran[0].scalefac_scale = tmp >> 1; /* 1 */
|
||||
si->ch[ch].gran[0].count1table_select = tmp & 1; /* 1 */
|
||||
|
||||
}
|
||||
}
|
||||
return (NO_DECODING_ERROR);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_get_side_info.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_GET_SIDE_INFO_H
|
||||
#define PVMP3_GET_SIDE_INFO_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
ERROR_CODE pvmp3_get_side_info(tmp3Bits *inputStream,
|
||||
mp3SideInfo *si,
|
||||
mp3Header *info,
|
||||
uint32 *crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,257 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_getbits.cpp
|
||||
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Inputs:
|
||||
|
||||
tmp3Bits *inputStream, structure holding the input stream parameters
|
||||
int32 neededBits number of bits to read from the bit stream
|
||||
|
||||
Outputs:
|
||||
|
||||
word parsed from teh bitstream, with size neededBits-bits,
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_getbits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint32 getNbits(tmp3Bits *ptBitStream,
|
||||
int32 neededBits) /* number of bits to read from the bitstream (up to 25) */
|
||||
{
|
||||
|
||||
uint32 offset;
|
||||
uint32 bitIndex;
|
||||
uint8 Elem; /* Needs to be same type as pInput->pBuffer */
|
||||
uint8 Elem1;
|
||||
uint8 Elem2;
|
||||
uint8 Elem3;
|
||||
uint32 returnValue = 0;
|
||||
|
||||
if (!neededBits)
|
||||
{
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
|
||||
|
||||
Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
|
||||
Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
|
||||
Elem2 = *(ptBitStream->pBuffer + module(offset + 2, BUFSIZE));
|
||||
Elem3 = *(ptBitStream->pBuffer + module(offset + 3, BUFSIZE));
|
||||
|
||||
|
||||
returnValue = (((uint32)(Elem)) << 24) |
|
||||
(((uint32)(Elem1)) << 16) |
|
||||
(((uint32)(Elem2)) << 8) |
|
||||
((uint32)(Elem3));
|
||||
|
||||
/* Remove extra high bits by shifting up */
|
||||
bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
|
||||
|
||||
/* This line is faster than to mask off the high bits. */
|
||||
returnValue <<= bitIndex;
|
||||
|
||||
/* Move the field down. */
|
||||
returnValue >>= (32 - neededBits);
|
||||
|
||||
ptBitStream->usedBits += neededBits;
|
||||
|
||||
return (returnValue);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint16 getUpTo9bits(tmp3Bits *ptBitStream,
|
||||
int32 neededBits) /* number of bits to read from the bit stream 2 to 9 */
|
||||
{
|
||||
|
||||
uint32 offset;
|
||||
uint32 bitIndex;
|
||||
uint8 Elem; /* Needs to be same type as pInput->pBuffer */
|
||||
uint8 Elem1;
|
||||
uint16 returnValue;
|
||||
|
||||
offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
|
||||
|
||||
Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
|
||||
Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
|
||||
|
||||
|
||||
returnValue = (((uint16)(Elem)) << 8) |
|
||||
((uint16)(Elem1));
|
||||
|
||||
/* Remove extra high bits by shifting up */
|
||||
bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
|
||||
|
||||
ptBitStream->usedBits += neededBits;
|
||||
/* This line is faster than to mask off the high bits. */
|
||||
returnValue = (returnValue << (bitIndex));
|
||||
|
||||
/* Move the field down. */
|
||||
|
||||
return (uint16)(returnValue >> (16 - neededBits));
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint32 getUpTo17bits(tmp3Bits *ptBitStream,
|
||||
int32 neededBits) /* number of bits to read from the bit stream 2 to 8 */
|
||||
{
|
||||
|
||||
uint32 offset;
|
||||
uint32 bitIndex;
|
||||
uint8 Elem; /* Needs to be same type as pInput->pBuffer */
|
||||
uint8 Elem1;
|
||||
uint8 Elem2;
|
||||
uint32 returnValue;
|
||||
|
||||
offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
|
||||
|
||||
Elem = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
|
||||
Elem1 = *(ptBitStream->pBuffer + module(offset + 1, BUFSIZE));
|
||||
Elem2 = *(ptBitStream->pBuffer + module(offset + 2, BUFSIZE));
|
||||
|
||||
|
||||
returnValue = (((uint32)(Elem)) << 16) |
|
||||
(((uint32)(Elem1)) << 8) |
|
||||
((uint32)(Elem2));
|
||||
|
||||
/* Remove extra high bits by shifting up */
|
||||
bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
|
||||
|
||||
ptBitStream->usedBits += neededBits;
|
||||
/* This line is faster than to mask off the high bits. */
|
||||
returnValue = 0xFFFFFF & (returnValue << (bitIndex));
|
||||
|
||||
/* Move the field down. */
|
||||
|
||||
return (uint32)(returnValue >> (24 - neededBits));
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
uint8 get1bit(tmp3Bits *ptBitStream) /* number of bits to read from the bit stream */
|
||||
{
|
||||
|
||||
uint32 offset;
|
||||
uint32 bitIndex;
|
||||
uint8 returnValue;
|
||||
|
||||
offset = (ptBitStream->usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
|
||||
|
||||
returnValue = *(ptBitStream->pBuffer + module(offset , BUFSIZE));
|
||||
|
||||
/* Remove extra high bits by shifting up */
|
||||
bitIndex = module(ptBitStream->usedBits, INBUF_BIT_WIDTH);
|
||||
ptBitStream->usedBits++;
|
||||
|
||||
/* This line is faster than to mask off the high bits. */
|
||||
returnValue = (returnValue << (bitIndex));
|
||||
|
||||
return (uint8)(returnValue >> 7);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_getbits.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_GETBITS_H
|
||||
#define PVMP3_GETBITS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define INBUF_ARRAY_INDEX_SHIFT (3)
|
||||
#define INBUF_BIT_WIDTH (1<<(INBUF_ARRAY_INDEX_SHIFT))
|
||||
#define INBUF_BIT_MODULO_MASK ((INBUF_BIT_WIDTH)-1)
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
uint32 getNbits(tmp3Bits *pMainData,
|
||||
int32 neededBits);
|
||||
|
||||
uint16 getUpTo9bits(tmp3Bits *pMainData,
|
||||
int32 neededBits);
|
||||
|
||||
uint32 getUpTo17bits(tmp3Bits *pMainData,
|
||||
int32 neededBits);
|
||||
|
||||
uint8 get1bit(tmp3Bits *pMainData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,304 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_huffman_decoding.cpp
|
||||
|
||||
Funtions:
|
||||
pvmp3_huffman_quad_decoding
|
||||
pvmp3_huffman_pair_decoding
|
||||
pvmp3_huffman_pair_decoding_linbits
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Inputs:
|
||||
struct huffcodetab *h, pointer to huffman code record
|
||||
int32 *x, returns decoded x value
|
||||
int32 *y, returns decoded y value
|
||||
int32 *v, returns decoded v value (only in quad function)
|
||||
int32 *w, returns decoded w value (only in quad function)
|
||||
tbits *pMainData bit stream
|
||||
|
||||
Outputs:
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
These functions are used to decode huffman codewords from the input
|
||||
bitstream using combined binary search and look-up table approach.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pv_mp3_huffman.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
|
||||
int32 x;
|
||||
int32 y;
|
||||
int32 v;
|
||||
int32 w;
|
||||
|
||||
y = (*h->pdec_huff_tab)(pMainData);
|
||||
|
||||
|
||||
if (y)
|
||||
{
|
||||
v = (y >> 3);
|
||||
|
||||
if (v)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
v = -v;
|
||||
}
|
||||
}
|
||||
w = (y >> 2) & 1;
|
||||
if (w)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
w = -w;
|
||||
}
|
||||
}
|
||||
x = (y >> 1) & 1;
|
||||
if (x)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
y = y & 1;
|
||||
if (y)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
y = -y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
v = 0;
|
||||
w = 0;
|
||||
x = 0;
|
||||
|
||||
}
|
||||
|
||||
*is = v;
|
||||
*(is + 1) = w;
|
||||
*(is + 2) = x;
|
||||
*(is + 3) = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pvmp3_huffman_pair_decoding(struct huffcodetab *h, /* pointer to huffman code record */
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
/* Lookup in Huffman table. */
|
||||
int32 x;
|
||||
int32 y;
|
||||
|
||||
uint16 cw = (*h->pdec_huff_tab)(pMainData);
|
||||
|
||||
/* Process sign and escape encodings for dual tables. */
|
||||
|
||||
|
||||
if (cw)
|
||||
{
|
||||
x = cw >> 4;
|
||||
|
||||
if (x)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
x = -x;
|
||||
}
|
||||
y = cw & 0xf;
|
||||
if (y && get1bit(pMainData))
|
||||
{
|
||||
y = -y;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
y = cw & 0xf;
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
y = -y;
|
||||
}
|
||||
}
|
||||
|
||||
*is = x;
|
||||
*(is + 1) = y;
|
||||
}
|
||||
else
|
||||
{
|
||||
*is = 0;
|
||||
*(is + 1) = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h, /* pointer to huffman code record */
|
||||
int32 *is,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
int32 x;
|
||||
int32 y;
|
||||
|
||||
uint16 cw;
|
||||
/* Lookup in Huffman table. */
|
||||
|
||||
|
||||
cw = (*h->pdec_huff_tab)(pMainData);
|
||||
x = cw >> 4;
|
||||
|
||||
/* Process sign and escape encodings for dual tables. */
|
||||
|
||||
|
||||
if (15 == (uint32)x)
|
||||
{
|
||||
int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
|
||||
x += tmp >> 1;
|
||||
if (tmp&1)
|
||||
{
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
else if (x)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
x = -x;
|
||||
}
|
||||
}
|
||||
|
||||
y = cw & 0xf;
|
||||
if (15 == (uint32)y)
|
||||
{
|
||||
int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
|
||||
y += tmp >> 1;
|
||||
if (tmp&1)
|
||||
{
|
||||
y = -y;
|
||||
}
|
||||
}
|
||||
else if (y)
|
||||
{
|
||||
if (get1bit(pMainData))
|
||||
{
|
||||
y = -y;
|
||||
}
|
||||
}
|
||||
|
||||
*is = x;
|
||||
*(is + 1) = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,328 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_huffman_decoding.cpp
|
||||
|
||||
Funtions:
|
||||
pvmp3_huffman_quad_decoding
|
||||
pvmp3_huffman_pair_decoding
|
||||
pvmp3_huffman_pair_decoding_linbits
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Inputs:
|
||||
int32 is[],
|
||||
granuleInfo *grInfo, information for the given channel and granule
|
||||
tmp3dec_file *pVars, decoder state structure
|
||||
int32 part2_start, index to beginning of part 2 data
|
||||
mp3Header *info mp3 header info
|
||||
|
||||
Outputs:
|
||||
int32 is[], uncompressed data
|
||||
|
||||
Return:
|
||||
non zero frequency lines
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
These functions are used to decode huffman codewords from the input
|
||||
bitstream using combined binary search and look-up table approach.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pv_mp3_huffman.h"
|
||||
#include "s_mp3bits.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
#include "pvmp3_tables.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
int32 pvmp3_huffman_parsing(int32 is[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
granuleInfo *grInfo,
|
||||
tmp3dec_file *pVars,
|
||||
int32 part2_start,
|
||||
mp3Header *info)
|
||||
|
||||
|
||||
{
|
||||
int32 i;
|
||||
int32 region1Start;
|
||||
int32 region2Start;
|
||||
int32 sfreq;
|
||||
uint32 grBits;
|
||||
void(*pt_huff)(struct huffcodetab *, int32 *, tmp3Bits *);
|
||||
struct huffcodetab *h;
|
||||
|
||||
tmp3Bits *pMainData = &pVars->mainDataStream;
|
||||
|
||||
|
||||
/*int32 bt = (*si).ch[ch].gr[gr].window_switching_flag && ((*si).ch[ch].gr[gr].block_type == 2);*/
|
||||
|
||||
sfreq = info->sampling_frequency + info->version_x + (info->version_x << 1);
|
||||
|
||||
/* Find region boundary for short block case. */
|
||||
|
||||
|
||||
if ((grInfo->window_switching_flag) && (grInfo->block_type == 2))
|
||||
{
|
||||
if (info->version_x == MPEG_1)
|
||||
{
|
||||
/* Region2. */
|
||||
region1Start = 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Region2. */
|
||||
i = grInfo->region0_count + 1;
|
||||
region1Start = mp3_sfBandIndex[sfreq].s[i/3];
|
||||
}
|
||||
|
||||
region1Start += region1Start << 1;
|
||||
region2Start = 576; /* No Region2 for short block case. */
|
||||
}
|
||||
else
|
||||
{ /* Find region boundary for long block case. */
|
||||
i = grInfo->region0_count + 1;
|
||||
region1Start = mp3_sfBandIndex[sfreq].l[i];
|
||||
region2Start = mp3_sfBandIndex[sfreq].l[i + grInfo->region1_count + 1];
|
||||
}
|
||||
|
||||
/* Read bigvalues area. */
|
||||
|
||||
|
||||
if (grInfo->big_values > (FILTERBANK_BANDS*SUBBANDS_NUMBER >> 1))
|
||||
{
|
||||
grInfo->big_values = (FILTERBANK_BANDS * SUBBANDS_NUMBER >> 1);
|
||||
}
|
||||
|
||||
if ((grInfo->big_values << 1) > (uint32)region2Start)
|
||||
{
|
||||
h = &(pVars->ht[grInfo->table_select[0]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
|
||||
for (i = 0; i < region1Start; i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
|
||||
h = &(pVars->ht[grInfo->table_select[1]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
|
||||
for (; i < region2Start; i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
|
||||
h = &(pVars->ht[grInfo->table_select[2]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
|
||||
for (; (uint32)i < (grInfo->big_values << 1); i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
}
|
||||
else if ((grInfo->big_values << 1) > (uint32)region1Start)
|
||||
{
|
||||
h = &(pVars->ht[grInfo->table_select[0]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
for (i = 0; i < region1Start; i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
|
||||
h = &(pVars->ht[grInfo->table_select[1]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
for (; (uint32)i < (grInfo->big_values << 1); i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
h = &(pVars->ht[grInfo->table_select[0]]);
|
||||
if (h->linbits)
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding_linbits;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt_huff = pvmp3_huffman_pair_decoding;
|
||||
}
|
||||
|
||||
for (i = 0; (uint32)i < (grInfo->big_values << 1); i += 2)
|
||||
{
|
||||
(*pt_huff)(h, &is[i], pMainData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Read count1 area. */
|
||||
h = &(pVars->ht[grInfo->count1table_select+32]);
|
||||
|
||||
grBits = part2_start + grInfo->part2_3_length;
|
||||
|
||||
while ((pMainData->usedBits < grBits) &&
|
||||
(i < FILTERBANK_BANDS*SUBBANDS_NUMBER - 4))
|
||||
{
|
||||
pvmp3_huffman_quad_decoding(h, &is[i], pMainData);
|
||||
i += 4;
|
||||
}
|
||||
|
||||
if ((pMainData->usedBits < grBits) &&
|
||||
(i < FILTERBANK_BANDS*SUBBANDS_NUMBER))
|
||||
{
|
||||
pvmp3_huffman_quad_decoding(h, &is[i], pMainData);
|
||||
i += 4;
|
||||
|
||||
if ((i - 2) >= FILTERBANK_BANDS*SUBBANDS_NUMBER)
|
||||
{
|
||||
i -= 2;
|
||||
is[i] = 0;
|
||||
is[(i+1)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pMainData->usedBits > grBits)
|
||||
{
|
||||
i -= 4;
|
||||
|
||||
if (i < 0 || i > FILTERBANK_BANDS*SUBBANDS_NUMBER - 4)
|
||||
{
|
||||
/* illegal parameters may cause invalid access, set i to 0 */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
is[i] = 0;
|
||||
is[(i+1)] = 0;
|
||||
is[(i+2)] = 0;
|
||||
is[(i+3)] = 0;
|
||||
|
||||
}
|
||||
|
||||
pMainData->usedBits = grBits;
|
||||
|
||||
return (i);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,376 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_imdct_synth.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 in[], Pointer to spec values of current channel
|
||||
int32 overlap[], Pointer to overlap values of current channel
|
||||
uint32 blk_type, Block type
|
||||
int16 mx_band, In case of mixed blocks, # of bands with long
|
||||
blocks (2 or 4) else 0
|
||||
int32 *Scratch_mem
|
||||
Returns
|
||||
|
||||
int32 in[],
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
The frequency lines are preprocessed by the "alias reduction" scheme
|
||||
and fed into the IMDCT matrix, each 18 into one transform block.
|
||||
The first half of the output values are added to the stored overlap
|
||||
values from the last block. These values are new output values and
|
||||
are input values for the polyphase filterbank. The second half of the
|
||||
output values is stored for overlap with the next data granule.
|
||||
The number of windowed samples is 12 for short blocks, and 36 for long
|
||||
blocks
|
||||
|
||||
Windowing
|
||||
|
||||
Depending on window_switching_flag[gr][ch], block_type[gr][ch] and
|
||||
mixed_block_flag[gr][ch] different shapes of windows are used.
|
||||
normal window
|
||||
start window
|
||||
stop window
|
||||
short windows
|
||||
Each of the three short blocks is windowed separately.
|
||||
The windowed short blocks must be overlapped and concatenated.
|
||||
|
||||
Overlapping and adding with previous block
|
||||
|
||||
The first half (18 values) of the current block (36 values) has to be
|
||||
overlapped with the second half of the previous block. The second half
|
||||
of the current block has to be stored for overlapping with the next block
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_imdct_synth.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_mdct_18.h"
|
||||
#include "pvmp3_mdct_6.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define LONG 0
|
||||
#define START 1
|
||||
#define SHORT 2
|
||||
#define STOP 3
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
/*
|
||||
* sin(pi/36*(k+0.5)),k=0..35
|
||||
*/
|
||||
|
||||
const int32 normal_win[36] =
|
||||
{
|
||||
Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
|
||||
Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
|
||||
Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
|
||||
Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
|
||||
Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
|
||||
Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
|
||||
Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
|
||||
Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
|
||||
Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
|
||||
Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
|
||||
Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
|
||||
Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
|
||||
};
|
||||
|
||||
|
||||
const int32 start_win[36] =
|
||||
{
|
||||
/* k=0..17 sin(pi/36*(k+0.5)), */
|
||||
Qfmt_31(0.08723877473068f), Qfmt_31(0.26105238444010f), Qfmt_31(0.43287922787620f),
|
||||
Qfmt_31(0.60141159900854f), Qfmt_31(0.76536686473018f), Qfmt_31(0.92349722647006f),
|
||||
Qfmt_31(0.53729960834682f), Qfmt_31(0.60876142900872f), Qfmt_31(0.67559020761566f),
|
||||
Qfmt_31(-0.73727733681012f), Qfmt_31(-0.79335334029124f), Qfmt_31(0.84339144581289f),
|
||||
Qfmt_31(0.88701083317822f), Qfmt_31(0.92387953251129f), Qfmt_31(-0.95371695074823f),
|
||||
Qfmt_31(-0.97629600711993f), Qfmt_31(-0.99144486137381f), Qfmt_31(-0.99904822158186f),
|
||||
|
||||
Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
|
||||
Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f),
|
||||
/* k=24..29; sin(pi/12*(k-18+0.5)) */
|
||||
Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
|
||||
Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
|
||||
|
||||
Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
|
||||
Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f)
|
||||
};
|
||||
|
||||
|
||||
const int32 stop_win[36] =
|
||||
{
|
||||
Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
|
||||
Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f), Qfmt_31(0.00000000000000f),
|
||||
/* k=6..11; sin(pi/12*(k-6+0.5)) */
|
||||
Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
|
||||
Qfmt_31(-0.79335334029124f), Qfmt_31(-0.92387953251129f), Qfmt_31(0.99144486137381f),
|
||||
|
||||
Qfmt_31(0.99999990000000f), Qfmt_31(0.99999990000000f), Qfmt_31(-0.99999990000000f),
|
||||
Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f), Qfmt_31(-0.99999990000000f),
|
||||
/* k=18..35 sin(pi/36*(k+0.5)), */
|
||||
Qfmt_31(0.99904822158186f), Qfmt_31(0.99144486137381f), Qfmt_31(0.97629600711993f),
|
||||
Qfmt_31(0.95371695074823f), Qfmt_31(0.92387953251129f), Qfmt_31(0.88701083317822f),
|
||||
Qfmt_31(0.84339144581289f), Qfmt_31(0.79335334029124f), Qfmt_31(0.73727733681012f),
|
||||
Qfmt_31(0.67559020761566f), Qfmt_31(0.60876142900872f), Qfmt_31(0.53729960834682f),
|
||||
Qfmt_31(0.46174861323503f), Qfmt_31(0.38268343236509f), Qfmt_31(0.30070579950427f),
|
||||
Qfmt_31(0.21643961393810f), Qfmt_31(0.13052619222005f), Qfmt_31(0.04361938736534f)
|
||||
};
|
||||
|
||||
|
||||
const int32 short_win[12] =
|
||||
{
|
||||
/* k=0..11; sin(pi/12*(k+0.5)) */
|
||||
Qfmt_31(0.13052619222005f), Qfmt_31(0.38268343236509f), Qfmt_31(0.60876142900872f),
|
||||
Qfmt_31(0.79335334029124f), Qfmt_31(0.92387953251129f), Qfmt_31(0.99144486137381f),
|
||||
Qfmt_31(0.99144486137381f), Qfmt_31(0.92387953251129f), Qfmt_31(0.79335334029124f),
|
||||
Qfmt_31(0.60876142900872f), Qfmt_31(0.38268343236509f), Qfmt_31(0.13052619222005f),
|
||||
};
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_imdct_synth(int32 in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
uint32 blk_type,
|
||||
int16 mx_band,
|
||||
int32 used_freq_lines,
|
||||
int32 *Scratch_mem)
|
||||
{
|
||||
|
||||
int32 band;
|
||||
int32 bands2process = used_freq_lines + 2;
|
||||
|
||||
if (bands2process > SUBBANDS_NUMBER)
|
||||
{
|
||||
bands2process = SUBBANDS_NUMBER; /* default */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* in case of mx_poly_band> 0, do
|
||||
* long transforms
|
||||
*/
|
||||
|
||||
|
||||
for (band = 0; band < bands2process; band++)
|
||||
{
|
||||
uint32 current_blk_type = (band < mx_band) ? LONG : blk_type;
|
||||
|
||||
int32 * out = in + (band * FILTERBANK_BANDS);
|
||||
int32 * history = overlap + (band * FILTERBANK_BANDS);
|
||||
|
||||
switch (current_blk_type)
|
||||
{
|
||||
case LONG:
|
||||
|
||||
pvmp3_mdct_18(out, history, normal_win);
|
||||
|
||||
break;
|
||||
|
||||
case START:
|
||||
|
||||
pvmp3_mdct_18(out, history, start_win);
|
||||
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
|
||||
pvmp3_mdct_18(out, history, stop_win);
|
||||
|
||||
break;
|
||||
|
||||
case SHORT:
|
||||
{
|
||||
int32 *tmp_prev_ovr = &Scratch_mem[FILTERBANK_BANDS];
|
||||
int32 i;
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
Scratch_mem[i ] = out[(i*3)];
|
||||
Scratch_mem[6 +i] = out[(i*3) + 1];
|
||||
Scratch_mem[12 +i] = out[(i*3) + 2];
|
||||
}
|
||||
|
||||
pvmp3_mdct_6(&Scratch_mem[ 0], &tmp_prev_ovr[ 0]);
|
||||
pvmp3_mdct_6(&Scratch_mem[ 6], &tmp_prev_ovr[ 6]);
|
||||
pvmp3_mdct_6(&Scratch_mem[12], &tmp_prev_ovr[12]);
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
int32 temp = history[i];
|
||||
/* next iteration overlap */
|
||||
history[i] = fxp_mul32_Q32(tmp_prev_ovr[ 6+i] << 1, short_win[6+i]);
|
||||
history[i] += fxp_mul32_Q32(Scratch_mem[12+i] << 1, short_win[ i]);
|
||||
out[i] = temp;
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
out[i+6] = fxp_mul32_Q32(Scratch_mem[i] << 1, short_win[i]);
|
||||
out[i+6] += history[i+6];
|
||||
/* next iteration overlap */
|
||||
history[i+6] = fxp_mul32_Q32(tmp_prev_ovr[12+i] << 1, short_win[6+i]);
|
||||
|
||||
}
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
out[i+12] = fxp_mul32_Q32(tmp_prev_ovr[ i] << 1, short_win[6+i]);
|
||||
out[i+12] += fxp_mul32_Q32(Scratch_mem[6+i] << 1, short_win[ i]);
|
||||
out[i+12] += history[i+12];
|
||||
history[12+i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compensation for frequency inversion of polyphase filterbank
|
||||
* every odd time sample of every odd odd subband is mulitplied by -1 before
|
||||
* processing by the polyphase filter
|
||||
*/
|
||||
|
||||
if (band & 1)
|
||||
{
|
||||
for (int32 slot = 1; slot < FILTERBANK_BANDS; slot += 6)
|
||||
{
|
||||
int32 temp1 = out[slot ];
|
||||
int32 temp2 = out[slot+2];
|
||||
int32 temp3 = out[slot+4];
|
||||
out[slot ] = -temp1;
|
||||
out[slot+2] = -temp2;
|
||||
out[slot+4] = -temp3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (band = bands2process; band < SUBBANDS_NUMBER; band++)
|
||||
{
|
||||
int32 * out = in + (band * FILTERBANK_BANDS);
|
||||
int32 * history = overlap + (band * FILTERBANK_BANDS);
|
||||
int32 slot;
|
||||
|
||||
if (band & 1)
|
||||
{
|
||||
for (slot = 0; slot < FILTERBANK_BANDS; slot += 6)
|
||||
{
|
||||
int32 temp1 = history[slot ];
|
||||
int32 temp2 = history[slot+1];
|
||||
int32 temp3 = history[slot+2];
|
||||
out[slot ] = temp1;
|
||||
out[slot+1] = -temp2;
|
||||
out[slot+2] = temp3;
|
||||
|
||||
temp1 = history[slot+3];
|
||||
temp2 = history[slot+4];
|
||||
temp3 = history[slot+5];
|
||||
out[slot+3] = -temp1;
|
||||
out[slot+4] = temp2;
|
||||
out[slot+5] = -temp3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (slot = 0; slot < FILTERBANK_BANDS; slot += 3)
|
||||
{
|
||||
int32 temp1 = history[slot ];
|
||||
int32 temp2 = history[slot+1];
|
||||
int32 temp3 = history[slot+2];
|
||||
out[slot ] = temp1;
|
||||
out[slot+1] = temp2;
|
||||
out[slot+2] = temp3;
|
||||
}
|
||||
}
|
||||
|
||||
pv_memset(history, 0, FILTERBANK_BANDS*sizeof(*overlap));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_imdct_synth.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PVMP3_IMDCT_SYNTH_H
|
||||
#define PVMP3_IMDCT_SYNTH_H
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES AND SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_imdct_synth(int32 in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
uint32 blk_type,
|
||||
int16 mx_band,
|
||||
int32 used_freq_lines,
|
||||
int32 *Scratch_mem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,289 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: mdct_18.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 vec[], input vector of length 18
|
||||
int32 *history input for overlap and add, vector updated with
|
||||
next overlap and add values
|
||||
const int32 *window sine window used in the mdct, three types are allowed
|
||||
noraml, start and stop
|
||||
Returns
|
||||
none mdct computation in-place
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Returns the mdct of length 18 of the input vector, as well as the overlap
|
||||
vector for next iteration ( on history[])
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_mdct_18.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 cosTerms_dct18[9] =
|
||||
{
|
||||
Qfmt(0.50190991877167f), Qfmt(0.51763809020504f), Qfmt(0.55168895948125f),
|
||||
Qfmt(0.61038729438073f), Qfmt(0.70710678118655f), Qfmt(0.87172339781055f),
|
||||
Qfmt(1.18310079157625f), Qfmt(1.93185165257814f), Qfmt(5.73685662283493f)
|
||||
};
|
||||
|
||||
|
||||
const int32 cosTerms_1_ov_cos_phi[18] =
|
||||
{
|
||||
|
||||
Qfmt1(0.50047634258166f), Qfmt1(0.50431448029008f), Qfmt1(0.51213975715725f),
|
||||
Qfmt1(0.52426456257041f), Qfmt1(0.54119610014620f), Qfmt1(0.56369097343317f),
|
||||
Qfmt1(0.59284452371708f), Qfmt1(0.63023620700513f), Qfmt1(0.67817085245463f),
|
||||
|
||||
Qfmt2(0.74009361646113f), Qfmt2(0.82133981585229f), Qfmt2(0.93057949835179f),
|
||||
Qfmt2(1.08284028510010f), Qfmt2(1.30656296487638f), Qfmt2(1.66275476171152f),
|
||||
Qfmt2(2.31011315767265f), Qfmt2(3.83064878777019f), Qfmt2(11.46279281302667f)
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window)
|
||||
{
|
||||
int32 i;
|
||||
int32 tmp;
|
||||
int32 tmp1;
|
||||
int32 tmp2;
|
||||
int32 tmp3;
|
||||
int32 tmp4;
|
||||
|
||||
|
||||
|
||||
const int32 *pt_cos_split = cosTerms_dct18;
|
||||
const int32 *pt_cos = cosTerms_1_ov_cos_phi;
|
||||
const int32 *pt_cos_x = &cosTerms_1_ov_cos_phi[17];
|
||||
int32 *pt_vec = vec;
|
||||
int32 *pt_vec_o = &vec[17];
|
||||
|
||||
|
||||
for (i = 9; i != 0; i--)
|
||||
{
|
||||
tmp = *(pt_vec);
|
||||
tmp1 = *(pt_vec_o);
|
||||
tmp = fxp_mul32_Q32(tmp << 1, *(pt_cos++));
|
||||
tmp1 = fxp_mul32_Q27(tmp1, *(pt_cos_x--));
|
||||
*(pt_vec++) = tmp + tmp1 ;
|
||||
*(pt_vec_o--) = fxp_mul32_Q28((tmp - tmp1), *(pt_cos_split++));
|
||||
}
|
||||
|
||||
|
||||
pvmp3_dct_9(vec); // Even terms
|
||||
pvmp3_dct_9(&vec[9]); // Odd terms
|
||||
|
||||
|
||||
tmp3 = vec[16]; //
|
||||
vec[16] = vec[ 8];
|
||||
tmp4 = vec[14]; //
|
||||
vec[14] = vec[ 7];
|
||||
tmp = vec[12];
|
||||
vec[12] = vec[ 6];
|
||||
tmp2 = vec[10]; // vec[10]
|
||||
vec[10] = vec[ 5];
|
||||
vec[ 8] = vec[ 4];
|
||||
vec[ 6] = vec[ 3];
|
||||
vec[ 4] = vec[ 2];
|
||||
vec[ 2] = vec[ 1];
|
||||
vec[ 1] = vec[ 9] - tmp2; // vec[9] + vec[10]
|
||||
vec[ 3] = vec[11] - tmp2;
|
||||
vec[ 5] = vec[11] - tmp;
|
||||
vec[ 7] = vec[13] - tmp;
|
||||
vec[ 9] = vec[13] - tmp4;
|
||||
vec[11] = vec[15] - tmp4;
|
||||
vec[13] = vec[15] - tmp3;
|
||||
vec[15] = vec[17] - tmp3;
|
||||
|
||||
|
||||
/* overlap and add */
|
||||
|
||||
tmp2 = vec[0];
|
||||
tmp3 = vec[9];
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
tmp = history[ i];
|
||||
tmp4 = vec[i+10];
|
||||
vec[i+10] = tmp3 + tmp4;
|
||||
tmp1 = vec[i+1];
|
||||
vec[ i] = fxp_mac32_Q32(tmp, (vec[i+10]), window[ i]);
|
||||
tmp3 = tmp4;
|
||||
history[i ] = -(tmp2 + tmp1);
|
||||
tmp2 = tmp1;
|
||||
}
|
||||
|
||||
tmp = history[ 6];
|
||||
tmp4 = vec[16];
|
||||
vec[16] = tmp3 + tmp4;
|
||||
tmp1 = vec[7];
|
||||
vec[ 6] = fxp_mac32_Q32(tmp, vec[16] << 1, window[ i]);
|
||||
tmp = history[ 7];
|
||||
history[6] = -(tmp2 + tmp1);
|
||||
history[7] = -(tmp1 + vec[8]);
|
||||
|
||||
tmp1 = history[ 8];
|
||||
tmp4 = vec[17] + tmp4;
|
||||
vec[ 7] = fxp_mac32_Q32(tmp, tmp4 << 1, window[ 7]);
|
||||
history[8] = -(vec[8] + vec[9]);
|
||||
vec[ 8] = fxp_mac32_Q32(tmp1, vec[17] << 1, window[ 8]);
|
||||
|
||||
tmp = history[9];
|
||||
tmp1 = history[17];
|
||||
tmp2 = history[16];
|
||||
vec[ 9] = fxp_mac32_Q32(tmp, vec[17] << 1, window[ 9]);
|
||||
|
||||
vec[17] = fxp_mac32_Q32(tmp1, vec[10] << 1, window[17]);
|
||||
vec[10] = -vec[ 16];
|
||||
vec[16] = fxp_mac32_Q32(tmp2, vec[11] << 1, window[16]);
|
||||
tmp1 = history[15];
|
||||
tmp2 = history[14];
|
||||
vec[11] = -vec[ 15];
|
||||
vec[15] = fxp_mac32_Q32(tmp1, vec[12] << 1, window[15]);
|
||||
vec[12] = -vec[ 14];
|
||||
vec[14] = fxp_mac32_Q32(tmp2, vec[13] << 1, window[14]);
|
||||
|
||||
tmp = history[13];
|
||||
tmp1 = history[12];
|
||||
tmp2 = history[11];
|
||||
tmp3 = history[10];
|
||||
vec[13] = fxp_mac32_Q32(tmp, vec[12] << 1, window[13]);
|
||||
vec[12] = fxp_mac32_Q32(tmp1, vec[11] << 1, window[12]);
|
||||
vec[11] = fxp_mac32_Q32(tmp2, vec[10] << 1, window[11]);
|
||||
vec[10] = fxp_mac32_Q32(tmp3, tmp4 << 1, window[10]);
|
||||
|
||||
|
||||
/* next iteration overlap */
|
||||
|
||||
tmp1 = history[ 8];
|
||||
tmp3 = history[ 7];
|
||||
tmp2 = history[ 1];
|
||||
tmp = history[ 0];
|
||||
tmp1 <<= 1;
|
||||
tmp3 <<= 1;
|
||||
|
||||
history[ 0] = fxp_mul32_Q32(tmp1, window[18]);
|
||||
history[17] = fxp_mul32_Q32(tmp1, window[35]);
|
||||
history[ 1] = fxp_mul32_Q32(tmp3, window[19]);
|
||||
history[16] = fxp_mul32_Q32(tmp3, window[34]);
|
||||
|
||||
tmp2 <<= 1;
|
||||
tmp <<= 1;
|
||||
history[ 7] = fxp_mul32_Q32(tmp2, window[25]);
|
||||
history[10] = fxp_mul32_Q32(tmp2, window[28]);
|
||||
history[ 8] = fxp_mul32_Q32(tmp, window[26]);
|
||||
history[ 9] = fxp_mul32_Q32(tmp, window[27]);
|
||||
|
||||
tmp1 = history[ 6];
|
||||
tmp3 = history[ 5];
|
||||
tmp4 = history[ 4];
|
||||
tmp2 = history[ 3];
|
||||
tmp = history[ 2];
|
||||
|
||||
tmp1 <<= 1;
|
||||
tmp3 <<= 1;
|
||||
tmp4 <<= 1;
|
||||
|
||||
history[ 2] = fxp_mul32_Q32(tmp1, window[20]);
|
||||
history[15] = fxp_mul32_Q32(tmp1, window[33]);
|
||||
history[ 3] = fxp_mul32_Q32(tmp3, window[21]);
|
||||
history[14] = fxp_mul32_Q32(tmp3, window[32]);
|
||||
history[ 4] = fxp_mul32_Q32(tmp4, window[22]);
|
||||
history[13] = fxp_mul32_Q32(tmp4, window[31]);
|
||||
tmp2 <<= 1;
|
||||
tmp <<= 1;
|
||||
history[ 5] = fxp_mul32_Q32(tmp2, window[23]);
|
||||
history[12] = fxp_mul32_Q32(tmp2, window[30]);
|
||||
history[ 6] = fxp_mul32_Q32(tmp, window[24]);
|
||||
history[11] = fxp_mul32_Q32(tmp, window[29]);
|
||||
}
|
||||
|
||||
#endif // If not assembly
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./include/pvmp3_mdct_18.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines function mdct_18, dct9, mdct_6 and dct_6
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef MDCT_18_H
|
||||
#define MDCT_18_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt(a) (Int32)(a*((Int32)1<<28) )
|
||||
#define Qfmt1(a) (Int32)(a*((Int32)0x7FFFFFFF))
|
||||
#define Qfmt2(a) (Int32)(a*((Int32)1<<27))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window);
|
||||
|
||||
void pvmp3_dct_9(int32 vec[]);
|
||||
|
||||
void pvmp3_mdct_6(int32 vec[], int32 *overlap);
|
||||
|
||||
void pvmp3_dct_6(int32 vec[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
Filename: mdct_18.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
int32 vec[], input vector of length 6
|
||||
int32 *history input for overlap and add, vector updated with
|
||||
next overlap and add values
|
||||
Returns
|
||||
none mdct computation in-place
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Returns the mdct of length 6 of the input vector, as well as the overlap
|
||||
vector for next iteration ( on history[])
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_mdct_6.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define QFORMAT 29
|
||||
#define Qfmt29(a) (int32)(a*((int32)1<<QFORMAT) + (a>=0?0.5F:-0.5F))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
/*
|
||||
* (1./(2*cos((pi/(2*N))*(2*i+1)))), N = 12, i = [0:N/2-1]
|
||||
*/
|
||||
|
||||
const int32 cosTerms_1_ov_cos_phi_N6[6] =
|
||||
{
|
||||
|
||||
Qfmt29(0.50431448029008f), Qfmt29(0.54119610014620f),
|
||||
Qfmt29(0.63023620700513f), Qfmt29(0.82133981585229f),
|
||||
Qfmt29(1.30656296487638f), Qfmt29(3.83064878777019f)
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void pvmp3_mdct_6(int32 vec[], int32 *history)
|
||||
{
|
||||
int32 i;
|
||||
int32 tmp;
|
||||
int32 tmp1;
|
||||
int32 tmp2;
|
||||
|
||||
int32 *pt_vec = vec;
|
||||
int32 *pt_vec_o = vec;
|
||||
const int32 *pt_cos = cosTerms_1_ov_cos_phi_N6;
|
||||
|
||||
for (i = 2; i != 0; i--)
|
||||
{
|
||||
tmp = *(pt_vec++);
|
||||
tmp1 = *(pt_vec++);
|
||||
tmp2 = *(pt_vec++);
|
||||
*(pt_vec_o++) = fxp_mul32_Q29(tmp, *(pt_cos++));
|
||||
*(pt_vec_o++) = fxp_mul32_Q29(tmp1, *(pt_cos++));
|
||||
*(pt_vec_o++) = fxp_mul32_Q29(tmp2, *(pt_cos++));
|
||||
}
|
||||
|
||||
|
||||
pvmp3_dct_6(vec); // Even terms
|
||||
|
||||
|
||||
tmp = -(vec[0] + vec[1]);
|
||||
history[3] = tmp;
|
||||
history[2] = tmp;
|
||||
tmp = -(vec[1] + vec[2]);
|
||||
vec[0] = vec[3] + vec[4];
|
||||
vec[1] = vec[4] + vec[5];
|
||||
history[4] = tmp;
|
||||
history[1] = tmp;
|
||||
tmp = -(vec[2] + vec[3]);
|
||||
vec[4] = -vec[1];
|
||||
history[5] = tmp;
|
||||
history[0] = tmp;
|
||||
|
||||
vec[2] = vec[5];
|
||||
vec[3] = -vec[5];
|
||||
vec[5] = -vec[0];
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Pathname: ./include/pvmp3_mdct_6.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines function mdct_18, dct9, mdct_6 and dct_6
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_MDCT_6_H
|
||||
#define PVMP3_MDCT_6_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt(a) (Int32)(a*((Int32)1<<28) )
|
||||
#define Qfmt1(a) (Int32)(a*((Int32)0x7FFFFFFF))
|
||||
#define Qfmt2(a) (Int32)(a*((Int32)1<<27))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
void pvmp3_mdct_6(int32 vec[], int32 *overlap);
|
||||
|
||||
void pvmp3_dct_6(int32 vec[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_get_scale_data.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
mp3SideInfo *si, side information
|
||||
int32 gr, granule
|
||||
int32 ch, channel
|
||||
mp3Header *info, mp3 header information
|
||||
uint32 *scalefac_buffer,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
tbits *pMainData bit stream Data
|
||||
|
||||
Returns
|
||||
|
||||
uint32 *scalefac_buffer, acquired scale band data
|
||||
uint32 *scalefac_IIP_buffer, auxiliary scale data
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
get scale data for mpeg2 layer III LSF extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_mpeg2_get_scale_data.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
const uint32 nr_of_sfb_block[6][3][4] =
|
||||
{ {{ 6, 5, 5, 5}, { 9, 9, 9, 9}, { 6, 9, 9, 9}},
|
||||
{{ 6, 5, 7, 3}, { 9, 9, 12, 6}, { 6, 9, 12, 6}},
|
||||
{{11, 10, 0, 0}, { 18, 18, 0, 0}, {15, 18, 0, 0}},
|
||||
{{ 7, 7, 7, 0}, { 12, 12, 12, 0}, { 6, 15, 12, 0}},
|
||||
{{ 6, 6, 6, 3}, { 12, 9, 9, 6}, { 6, 12, 9, 6}},
|
||||
{{ 8, 8, 5, 0}, { 15, 12, 9, 0}, { 6, 18, 9, 0}}
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_mpeg2_get_scale_data(mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
mp3Header *info,
|
||||
uint32 *scalefac_buffer,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
int16 i;
|
||||
int16 j;
|
||||
int16 k;
|
||||
int16 blocktypenumber = 0;
|
||||
int16 blocknumber = 0;
|
||||
|
||||
granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
|
||||
uint32 scalefac_comp, int_scalefac_comp, new_slen[4] = { 0,0,0,0 };
|
||||
|
||||
scalefac_comp = gr_info->scalefac_compress;
|
||||
|
||||
|
||||
|
||||
if ((((info->mode_ext &1)) && (ch == 1)))
|
||||
{
|
||||
/* intensity_scale = scalefac_comp %2; */
|
||||
int_scalefac_comp = scalefac_comp >> 1;
|
||||
|
||||
if (int_scalefac_comp < 180)
|
||||
{
|
||||
new_slen[0] = int_scalefac_comp / 36;
|
||||
new_slen[1] = (int_scalefac_comp % 36) / 6;
|
||||
new_slen[2] = int_scalefac_comp % 6;
|
||||
blocknumber = 3;
|
||||
}
|
||||
else if (int_scalefac_comp < 244)
|
||||
{
|
||||
int_scalefac_comp -= 180;
|
||||
new_slen[0] = (int_scalefac_comp & 63) >> 4;
|
||||
new_slen[1] = (int_scalefac_comp & 15) >> 2;
|
||||
new_slen[2] = int_scalefac_comp & 3;
|
||||
blocknumber = 4;
|
||||
}
|
||||
else if (int_scalefac_comp <= 255)
|
||||
{
|
||||
int_scalefac_comp -= 244;
|
||||
new_slen[0] = (int_scalefac_comp) / 3;
|
||||
new_slen[1] = (int_scalefac_comp) % 3;
|
||||
new_slen[2] = 0;
|
||||
blocknumber = 5;
|
||||
}
|
||||
new_slen[3] = 0;
|
||||
si->ch[ch].gran[gr].preflag = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scalefac_comp < 400)
|
||||
{
|
||||
new_slen[0] = (scalefac_comp >> 4) / 5;
|
||||
new_slen[1] = (scalefac_comp >> 4) % 5;
|
||||
new_slen[2] = (scalefac_comp & 15) >> 2 ;
|
||||
new_slen[3] = (scalefac_comp & 3);
|
||||
si->ch[ch].gran[gr].preflag = 0;
|
||||
|
||||
blocknumber = 0;
|
||||
}
|
||||
else if (scalefac_comp < 500)
|
||||
{
|
||||
scalefac_comp -= 400;
|
||||
new_slen[0] = (scalefac_comp >> 2) / 5;
|
||||
new_slen[1] = (scalefac_comp >> 2) % 5;
|
||||
new_slen[2] = scalefac_comp & 3;
|
||||
new_slen[3] = 0;
|
||||
si->ch[ch].gran[gr].preflag = 0;
|
||||
blocknumber = 1;
|
||||
}
|
||||
else if (scalefac_comp < 512)
|
||||
{
|
||||
scalefac_comp -= 500;
|
||||
new_slen[0] = scalefac_comp / 3;
|
||||
new_slen[1] = scalefac_comp % 3;
|
||||
new_slen[2] = 0 ;
|
||||
new_slen[3] = 0;
|
||||
si->ch[ch].gran[gr].preflag = 1;
|
||||
blocknumber = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (gr_info->block_type == 2)
|
||||
{
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
blocktypenumber = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
blocktypenumber = 1;
|
||||
}
|
||||
}
|
||||
|
||||
k = 0;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (new_slen[i])
|
||||
{
|
||||
for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
|
||||
{
|
||||
scalefac_buffer[k] = getNbits(pMainData, new_slen[i]);
|
||||
scalefac_IIP_buffer[k] = (1L << new_slen[i]) - 1;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
|
||||
{
|
||||
scalefac_buffer[k] = 0;
|
||||
scalefac_IIP_buffer[k] = 0;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_get_scale_data.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_MPEG2_GET_SCALE_DATA_H
|
||||
#define PVMP3_MPEG2_GET_SCALE_DATA_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_mpeg2_get_scale_data(mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
mp3Header *info,
|
||||
uint32 *scalefac_buffer,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_get_scale_factors.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si, side information
|
||||
int32 gr, granule
|
||||
int32 ch, channel
|
||||
mp3Header *info, mp3 header information
|
||||
uint32 *scalefac_IIP_buffer, auxiliary scale data
|
||||
tbits *pMainData bit stream Data
|
||||
|
||||
Returns
|
||||
|
||||
III_scalefac_t *scalefac, scale factor
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
get scale factor for mpe2 layer III LSF extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_mpeg2_get_scale_factors.h"
|
||||
#include "pvmp3_mpeg2_get_scale_data.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_mpeg2_get_scale_factors(mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
mp3Header *info,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
tmp3Bits *pMainData)
|
||||
{
|
||||
|
||||
int32 sfb;
|
||||
int32 k = 0;
|
||||
int32 window;
|
||||
uint32 *scalefac_buffer = &scalefac_IIP_buffer[56];
|
||||
|
||||
granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
|
||||
|
||||
pvmp3_mpeg2_get_scale_data(si,
|
||||
gr,
|
||||
ch,
|
||||
info,
|
||||
(uint32 *)scalefac_buffer,
|
||||
(uint32 *)scalefac_IIP_buffer,
|
||||
pMainData);
|
||||
|
||||
|
||||
if (gr_info->window_switching_flag && (gr_info->block_type == 2))
|
||||
{
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
for (sfb = 0; sfb < 6; sfb++)
|
||||
{
|
||||
scalefac->l[sfb] = scalefac_buffer[sfb];
|
||||
}
|
||||
|
||||
|
||||
k = 6;
|
||||
for (sfb = 3; sfb < 12; sfb++)
|
||||
{
|
||||
for (window = 0; window < 3; window++)
|
||||
{
|
||||
scalefac->s[window][sfb] = scalefac_buffer[k];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* adjust position of "illegal position" information in scalefac_IIP_buffer[] */
|
||||
/* in mixed blocks mode for short sfb, move them 3 places up. efs 3002-07-04 */
|
||||
for (sfb = 11; sfb >= 3; sfb--)
|
||||
{
|
||||
scalefac_IIP_buffer[3*sfb + 2] = scalefac_IIP_buffer[3*sfb - 1];
|
||||
scalefac_IIP_buffer[3*sfb + 1] = scalefac_IIP_buffer[3*sfb - 2];
|
||||
scalefac_IIP_buffer[3*sfb ] = scalefac_IIP_buffer[3*sfb - 3];
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* SHORT*/
|
||||
for (sfb = 0; sfb < 12; sfb++)
|
||||
{
|
||||
for (window = 0; window < 3; window++)
|
||||
{
|
||||
scalefac->s[window][sfb] = scalefac_buffer[k];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scalefac->s[0][12] = 0;
|
||||
scalefac->s[1][12] = 0;
|
||||
scalefac->s[2][12] = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{ /* LONG types 0,1,3 */
|
||||
for (sfb = 0; sfb < 21; sfb++)
|
||||
{
|
||||
scalefac->l[sfb] = scalefac_buffer[sfb];
|
||||
}
|
||||
scalefac->l[21] = 0;
|
||||
scalefac->l[22] = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_get_scale_factors.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_MPEG2_GET_SCALE_FACTORS_H
|
||||
#define PVMP3_MPEG2_GET_SCALE_FACTORS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_mp3bits.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_mpeg2_get_scale_factors(mp3ScaleFactors *scalefac,
|
||||
mp3SideInfo *si,
|
||||
int32 gr,
|
||||
int32 ch,
|
||||
mp3Header *info,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
tmp3Bits *pMainData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,700 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_stereo_proc.cpp
|
||||
|
||||
Functions:
|
||||
|
||||
pvmp3_st_intensity_ver2
|
||||
pvmp3_mpeg2_stereo_proc
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pvmp3_st_intensity_ver2
|
||||
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
int32 xr[], input channel
|
||||
int32 xl[],
|
||||
int32 m, selecting index: io = 2(1/4) (m=0), io = 2(1/8) (m=1)
|
||||
int32 is_pos, index on table is_pos_pow_eitgh_root_of_2
|
||||
int32 Start, Location of first element where stereo intensity is applied
|
||||
int32 Number number of elements affected
|
||||
|
||||
Returns
|
||||
|
||||
int32 xl[], generated stereo channel
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pvmp3_mpeg2_stereo_proc
|
||||
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
int32 xr[], input channel
|
||||
int32 xl[],
|
||||
mp3ScaleFactors *scalefac, scale factors structure for Right channel
|
||||
granuleInfo *gr_info_l, granule structure for the left channel
|
||||
granuleInfo *gr_info_r, granule structure for the rigth channel
|
||||
uint32 *scalefac_IIP_buffer, auxiliary scale factor vector
|
||||
mp3Header *info mp3 header info
|
||||
Returns
|
||||
|
||||
int32 xl[], generated stereo channel
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
stereo processing for mpeg2 layer III LSF extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_mpeg2_stereo_proc.h"
|
||||
#include "pvmp3_stereo_proc.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_tables.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
const int32 is_pos_pow_eitgh_root_of_2[8] =
|
||||
{
|
||||
/* --- 2^(1/8) ----- */
|
||||
Q31_fmt(1.00000000000000), Q31_fmt(0.91700404320467), Q31_fmt(0.84089641525371),
|
||||
Q31_fmt(0.77110541270397), Q31_fmt(0.70710678118655), Q31_fmt(0.64841977732550),
|
||||
Q31_fmt(0.59460355750136), Q31_fmt(0.54525386633263)
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_st_intensity_ver2(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 m,
|
||||
int32 is_pos,
|
||||
int32 Start,
|
||||
int32 Number)
|
||||
{
|
||||
int32 k[2];
|
||||
|
||||
/* pow(io, ((is_pos + 1)>>1)); io = 2(1/4) (m=0), io = 2(1/8) (m=1) */
|
||||
k[0] = is_pos_pow_eitgh_root_of_2[((is_pos+1)&(3+(m<<2)))<<(1-m)] >> ((is_pos + 1) >> (2 + m));
|
||||
/* pow(io, (is_pos>>1)); io = 2(1/4) (m=0), io = 2(1/8) (m=1) */
|
||||
k[1] = is_pos_pow_eitgh_root_of_2[(is_pos&(3+(m<<2)))<<(1-m)] >> (is_pos >> (2 + m));
|
||||
|
||||
|
||||
int32 *pt_xr = &xr[Start];
|
||||
int32 *pt_xl = &xl[Start];
|
||||
|
||||
if (is_pos == 0) /* 0 < is_pos < 31 */
|
||||
{
|
||||
pv_memcpy(pt_xl, pt_xr, Number*sizeof(*pt_xr));
|
||||
}
|
||||
else if (is_pos & 1)
|
||||
{
|
||||
for (int32 i = Number >> 1; i != 0; i--)
|
||||
{
|
||||
*(pt_xl++) = (*pt_xr);
|
||||
*(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
|
||||
pt_xr++;
|
||||
*(pt_xl++) = (*pt_xr);
|
||||
*(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
|
||||
pt_xr++;
|
||||
}
|
||||
if (Number&1)
|
||||
{
|
||||
*(pt_xl) = (*pt_xr);
|
||||
*(pt_xr) = fxp_mul32_Q32((*pt_xr) << 1, k[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int32 i = Number >> 1; i != 0; i--)
|
||||
{
|
||||
*(pt_xl++) = fxp_mul32_Q32((*(pt_xr++)) << 1, k[1]);
|
||||
*(pt_xl++) = fxp_mul32_Q32((*(pt_xr++)) << 1, k[1]);
|
||||
}
|
||||
if (Number&1)
|
||||
{
|
||||
*(pt_xl) = fxp_mul32_Q32((*pt_xr) << 1, k[1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
void pvmp3_mpeg2_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac_R,
|
||||
granuleInfo *gr_info_l,
|
||||
granuleInfo *gr_info_r,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
int32 used_freq_lines,
|
||||
mp3Header *info)
|
||||
{
|
||||
|
||||
int32 sfreq;
|
||||
int32 sb;
|
||||
int32 ss;
|
||||
int32 sfbNo;
|
||||
int32 sfbStart;
|
||||
int32 sfb;
|
||||
int32 sfbTemp;
|
||||
int32 i;
|
||||
int32 j;
|
||||
int32 io;
|
||||
|
||||
|
||||
int32 i_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
|
||||
(info->mode_ext & 0x1);
|
||||
|
||||
int32 ms_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
|
||||
(info->mode_ext & 0x2);
|
||||
|
||||
|
||||
if (i_stereo)
|
||||
{
|
||||
if (gr_info_r->scalefac_compress & 1)
|
||||
{
|
||||
io = 0; /* 2^(-1/4) */
|
||||
}
|
||||
else
|
||||
{
|
||||
io = 1; /* 2^(-1/8) */
|
||||
}
|
||||
|
||||
sfreq = info->version_x + (info->version_x << 1);
|
||||
sfreq += info->sampling_frequency;
|
||||
|
||||
if (gr_info_l->window_switching_flag && (gr_info_l->block_type == 2))
|
||||
{
|
||||
if (gr_info_l->mixed_block_flag)
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing
|
||||
*/
|
||||
i = 31;
|
||||
ss = 17;
|
||||
sb = -1;
|
||||
|
||||
while (i >= 0)
|
||||
{
|
||||
if (xl[(i*FILTERBANK_BANDS) + ss])
|
||||
{
|
||||
sb = (i << 4) + (i << 1) + ss;
|
||||
i = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss--;
|
||||
if (ss < 0)
|
||||
{
|
||||
i--;
|
||||
ss = 17;
|
||||
}
|
||||
}
|
||||
} /* now sb is the number of highest line with value != 0 */
|
||||
/* can be between -1 (all lines zero) and 575 (no line zero) */
|
||||
|
||||
if (sb < 36) /* was (sb <= 36) */
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing: intensity bound inside long blocks
|
||||
*/
|
||||
/* 1. long blocks up to intensity border: Stereo or M/S */
|
||||
if (mp3_sfBandIndex[sfreq].l[4] <= sb)
|
||||
{
|
||||
i = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
while (mp3_sfBandIndex[sfreq].l[i] <= sb)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
sfbTemp = i; /* from that (long) sfb on we have intensity stereo */
|
||||
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp]; /* number of lines to process */
|
||||
|
||||
/* from sfbStart up sfbNo lines do ms_stereo or normal stereo */
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, sfbNo);
|
||||
}
|
||||
|
||||
/* 2. long blocks from intensity border up to sfb band 6: intensity */
|
||||
/* calc. MPEG_1_2_Factor[0], MPEG_1_2_Factor[1] */
|
||||
|
||||
for (sfb = sfbTemp; sfb < 6; sfb++)
|
||||
{
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfb]; /* = Start in 0 ... 575 */
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* No of lines to process */
|
||||
|
||||
if ((uint32)(scalefac_R->l[sfb]) != scalefac_IIP_buffer[sfb])
|
||||
{
|
||||
pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->l[sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
|
||||
/* 3. now process all sfb with short blocks (3...12), all in intensity mode */
|
||||
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
/* first calculate directional factors for intensity stereo,
|
||||
* for all sfb in intensity mode, but only
|
||||
* if they do not have "illegal" position:
|
||||
*/
|
||||
/* to do this for all sfb we have to get information for last scale factor band:
|
||||
* here we clearly have more than one sfb in intensity mode,
|
||||
* so copy factors and legal/illegal information from sfb11 to sfb12
|
||||
*/
|
||||
(scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
|
||||
scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
|
||||
|
||||
for (sfb = 3; sfb < 13; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
|
||||
|
||||
if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
|
||||
{
|
||||
pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
}
|
||||
else /* else then (sb >= 36) */
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing: intensity bound outside long blocks
|
||||
*/
|
||||
|
||||
/* 2. short blocks, do for all 3 */
|
||||
/* ------------------------------ */
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
int32 sfbcnt = -1;
|
||||
|
||||
for (sfb = 12; sfb >= 3; sfb--)
|
||||
{
|
||||
int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
|
||||
i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
|
||||
|
||||
while (lines > 0)
|
||||
{
|
||||
if (xl[i])
|
||||
{
|
||||
sfbcnt = sfb;
|
||||
sfb = -10;
|
||||
lines = -10;
|
||||
}
|
||||
lines--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
sfbcnt += 1;
|
||||
if (sfbcnt < 3)
|
||||
{
|
||||
sfbcnt = 3; /* should not be necessary */
|
||||
}
|
||||
|
||||
sfbTemp = sfbcnt; /* from this (short) sfb on we have intensity mode */
|
||||
/* can have values between 3 (all short sfb in intensity) */
|
||||
/* and 13 (no short sfb in intensity mode) */
|
||||
|
||||
/* 3. from sfbTemp to last sfb calculate is_ratio values: */
|
||||
/* first calculate directional factors for intensity stereo, */
|
||||
/* for all sfb in intensity mode, but only */
|
||||
/* if they do not have "illegal" position: */
|
||||
|
||||
/* to do this for all sfb we have to get information for last scale factor band: */
|
||||
/* get factors for last scale factor band: */
|
||||
/* more than one sfb in intensity mode,
|
||||
copy factors and legal/illegal information from sfb11 to sfb12 */
|
||||
if (sfbTemp < 12)
|
||||
{
|
||||
(scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
|
||||
scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
|
||||
}
|
||||
else if (sfbTemp == sfb)
|
||||
/* only sfb 12 in intensity mode, use factors corresponding to is_pos[12] == 0 */
|
||||
{
|
||||
(scalefac_R->s[j][12]) = 0;
|
||||
scalefac_IIP_buffer[36 + j] = 1; /* the scf value 0 in sfb12 is "legal" */
|
||||
}
|
||||
/* if sfbTemp > sfb (no sfb in intensity mode): do nothing */
|
||||
|
||||
|
||||
/* 4. do normal stereo or MS stereo from sfb 3 to < sfbTemp: */
|
||||
for (sfb = 3; sfb < sfbTemp; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
|
||||
/* 5. now intensity stereo processing of the remaining sfb's: */
|
||||
|
||||
for (sfb = sfbTemp; sfb < 13; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
|
||||
if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
|
||||
{
|
||||
pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
/* end of correction by efs 2003-07-04 */
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
|
||||
|
||||
/* long blocks 0 up to sfb band 6: no intensity */
|
||||
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[6]; /* number of lines to process */
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, sfbNo);
|
||||
}
|
||||
|
||||
} /* if intensity bound inside or outside long blocks */
|
||||
} /* if (gr_info->mixed_block_flag) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* short block processing
|
||||
*/
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
int32 sfbcnt = -1;
|
||||
|
||||
for (sfb = 12; sfb >= 0; sfb--)
|
||||
{
|
||||
int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
|
||||
|
||||
while (lines > 0)
|
||||
{
|
||||
if (xl[i])
|
||||
{
|
||||
sfbcnt = sfb;
|
||||
sfb = -10;
|
||||
lines = -10;
|
||||
}
|
||||
lines--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
sfbcnt += 1;
|
||||
|
||||
/* start of corrected version by efs 2003-07-04 */
|
||||
sfbTemp = sfbcnt; /* from this (short) sfb on we have intensity mode */
|
||||
/* can have values between 3 (all short sfb in intensity) */
|
||||
/* and 13 (no short sfb in intensity mode) */
|
||||
|
||||
/* first calculate directional factors for intensity stereo,
|
||||
for all sfb in intensity mode, but only
|
||||
if they do not have "illegal" position: */
|
||||
|
||||
/* to do this for all sfb we have to get information for last scale factor band: */
|
||||
/* get factors for last scale factor band: */
|
||||
/* more than one sfb in intensity mode,
|
||||
copy factors and legal/illegal information from sfb11 to sfb12 */
|
||||
if (sfbTemp < 12)
|
||||
{
|
||||
(scalefac_R->s[j][12]) = (scalefac_R->s[j][11]);
|
||||
scalefac_IIP_buffer[36 + j] = scalefac_IIP_buffer[33 + j]; /* legal/illegal in sfb 12 same as in sfb 11 */
|
||||
}
|
||||
else if (sfbTemp == 12)
|
||||
/* only sfb 12 in intensity mode, use factors corresponding to is_pos[12] == 0 */
|
||||
{
|
||||
(scalefac_R->s[j][12]) = 0;
|
||||
scalefac_IIP_buffer[36 + j] = 1; /* the scf value 0 in sfb12 is "legal" */
|
||||
}
|
||||
/* if sfbTemp > sfb (no sfb in intensity mode): do nothing */
|
||||
|
||||
|
||||
/* Now process audio samples */
|
||||
/* first process lower sfb's not in intensity mode */
|
||||
for (sfb = 0; sfb < sfbTemp; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
|
||||
/* now intensity stereo processing of the remaining sfb's: */
|
||||
for (sfb = sfbTemp; sfb < 13; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfb] + j * sfbNo;
|
||||
|
||||
if ((uint32)(scalefac_R->s[j][sfb]) != scalefac_IIP_buffer[3*sfb + j])
|
||||
{
|
||||
pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->s[j][sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
|
||||
} /* end of else ( gr_info->mixed_block_flag) */
|
||||
|
||||
} /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* long block processing
|
||||
*/
|
||||
i = 31;
|
||||
ss = 17;
|
||||
sb = 0;
|
||||
|
||||
while (i >= 0)
|
||||
{
|
||||
if (xl[(i*FILTERBANK_BANDS) + ss])
|
||||
{
|
||||
sb = (i << 4) + (i << 1) + ss;
|
||||
/* i = -1 patched RF 24-09-2002 */
|
||||
i = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss--;
|
||||
if (ss < 0)
|
||||
{
|
||||
i--;
|
||||
ss = 17;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* patched RF 24-09-2002 */
|
||||
if (sb)
|
||||
{
|
||||
if (mp3_sfBandIndex[sfreq].l[14] <= sb)
|
||||
{
|
||||
i = 14;
|
||||
}
|
||||
else if (mp3_sfBandIndex[sfreq].l[7] <= sb)
|
||||
{
|
||||
i = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
while (mp3_sfBandIndex[sfreq].l[i] <= sb)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (i == -1)
|
||||
{
|
||||
/* all xr[1][][] are 0: set IS bound sfb to 0 */
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* xr[1][0][0] is unequal 0 and all others are 0: set IS bound sfb to 1 */
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
/* corrected version by efs 2003-07-04 */
|
||||
sfbTemp = i; /* from this (long) sfb on we have intensity mode */
|
||||
/* can have values between 0 (all long sfb in intensity) */
|
||||
/* and 22 (no long sfb in intensity mode) */
|
||||
|
||||
/* first calculate directional factors for intensity stereo,
|
||||
for all sfb in intensity mode, but only if they
|
||||
do not have "illegal" position: */
|
||||
|
||||
/* to do this for all sfb we have to get information for last scale factor band: */
|
||||
if (sfbTemp < 21)
|
||||
/* more than one sfb in intensity mode, */
|
||||
/* copy factors and legal/illegal information from sfb20 to sfb21 */
|
||||
{
|
||||
(scalefac_R->l[21]) = (scalefac_R->l[20]);
|
||||
scalefac_IIP_buffer[21] = scalefac_IIP_buffer[20]; /* legal/illegal in sfb 21 same as in sfb 20 */
|
||||
}
|
||||
else if (sfbTemp == 21)
|
||||
/* only sfb 21 in intensity mode, is_pos[21] = 0 */
|
||||
{
|
||||
(scalefac_R->l[21]) = 0;
|
||||
scalefac_IIP_buffer[21] = 1; /* the scf value 0 in sfb21 is "legal" */
|
||||
}
|
||||
/* if sfbTemp > 21 (no sfb in intensity mode): do nothing */
|
||||
|
||||
|
||||
/* Now process audio samples */
|
||||
/* first process lower sfb's not in intensity mode */
|
||||
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp] - mp3_sfBandIndex[sfreq].l[0];
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[0];
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
/* now intensity stereo processing of the remaining sfb's: */
|
||||
for (sfb = sfbTemp; sfb < 22; sfb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* number of lines to process */
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfb]; /* start of sfb */
|
||||
|
||||
if ((uint32)(scalefac_R->l[sfb]) != scalefac_IIP_buffer[sfb]) /* "legal" position ? */
|
||||
{
|
||||
pvmp3_st_intensity_ver2(xr, xl, io, scalefac_R->l[sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (sfb = sfbTemp; sfb < 22; sfb++) */
|
||||
|
||||
} /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
|
||||
|
||||
} /* if (i_stereo) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* normal or ms stereo processing
|
||||
*/
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, used_freq_lines);
|
||||
}
|
||||
|
||||
} /* if (i_stereo) */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_mpeg2_stereo_proc.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_MPEG2_STEREO_PROC_H
|
||||
#define PVMP3_MPEG2_STEREO_PROC_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_mpeg2_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac,
|
||||
granuleInfo *gr_info_l,
|
||||
granuleInfo *gr_info_r,
|
||||
uint32 *scalefac_IIP_buffer,
|
||||
int32 used_freq_lines,
|
||||
mp3Header *info);
|
||||
|
||||
|
||||
void pvmp3_st_intensity_ver2(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 m,
|
||||
int32 is_pos,
|
||||
int32 Start,
|
||||
int32 Number);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_normalize.cpp
|
||||
|
||||
Date: 10/02/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
Int32 x 32-bit integer non-zero input
|
||||
Returns
|
||||
Int32 i number of leading zeros on x
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
Returns number of leading zeros on the non-zero input
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3_normalize.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
|
||||
#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
|
||||
|
||||
|
||||
/* function is inlined in header file */
|
||||
|
||||
|
||||
#else
|
||||
|
||||
int32 pvmp3_normalize(int32 x)
|
||||
{
|
||||
/*----------------------------------------------------------------------------
|
||||
; Define all local variables
|
||||
----------------------------------------------------------------------------*/
|
||||
int32 i;
|
||||
|
||||
|
||||
if (x > 0x0FFFFFFF)
|
||||
{
|
||||
i = 0; /* most likely case */
|
||||
}
|
||||
else if (x > 0x00FFFFFF)
|
||||
{
|
||||
i = 3; /* second most likely case */
|
||||
}
|
||||
else if (x > 0x0000FFFF)
|
||||
{
|
||||
i = x > 0x000FFFFF ? 7 : 11;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > 0x000000FF)
|
||||
{
|
||||
i = x > 0x00000FFF ? 15 : 19;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = x > 0x0000000F ? 23 : 27;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
x <<= i;
|
||||
|
||||
switch (x & 0x78000000)
|
||||
{
|
||||
case 0x08000000:
|
||||
i += 3;
|
||||
break;
|
||||
|
||||
case 0x18000000:
|
||||
case 0x10000000:
|
||||
i += 2;
|
||||
break;
|
||||
case 0x28000000:
|
||||
case 0x20000000:
|
||||
case 0x38000000:
|
||||
case 0x30000000:
|
||||
i++;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_normalize.h
|
||||
|
||||
Date: 10/02/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PVMP3_NORMALIZE_H
|
||||
#define PVMP3_NORMALIZE_H
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES AND SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
|
||||
|
||||
__inline int32 pvmp3_normalize(int32 x)
|
||||
{
|
||||
int32 y;
|
||||
__asm
|
||||
{
|
||||
clz y, x;
|
||||
sub y, y, #1
|
||||
}
|
||||
return (y);
|
||||
}
|
||||
|
||||
|
||||
#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
|
||||
|
||||
__inline int32 pvmp3_normalize(int32 x)
|
||||
{
|
||||
register int32 y;
|
||||
register int32 ra = x;
|
||||
|
||||
|
||||
asm volatile(
|
||||
"clz %0, %1\n\t"
|
||||
"sub %0, %0, #1"
|
||||
: "=&r*i"(y)
|
||||
: "r"(ra));
|
||||
return (y);
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int32 pvmp3_normalize(int32 x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* PV_NORMALIZE_H */
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_poly_phase_synthesis.cpp
|
||||
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
tmp3dec_chan *pChVars, decoder state structure per channel
|
||||
int32 numChannels, number of channels
|
||||
e_equalization equalizerType, equalization mode
|
||||
int16 *outPcm pointer to the PCM output data
|
||||
|
||||
Output
|
||||
int16 *outPcm pointer to the PCM output data
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
polyphase synthesis
|
||||
Each time the subband samples for all 32 polyphase subbands of one
|
||||
channel have been calculated, they can be applied to the synthesis
|
||||
subband filter and 32 consecutive audio samples can be calculated
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_poly_phase_synthesis.h"
|
||||
#include "pvmp3_polyphase_filter_window.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_dct_16.h"
|
||||
#include "pvmp3_equalizer.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_poly_phase_synthesis(tmp3dec_chan *pChVars,
|
||||
int32 numChannels,
|
||||
e_equalization equalizerType,
|
||||
int16 *outPcm)
|
||||
{
|
||||
/*
|
||||
* Equalizer
|
||||
*/
|
||||
pvmp3_equalizer(pChVars->circ_buffer,
|
||||
equalizerType,
|
||||
pChVars->work_buf_int32);
|
||||
|
||||
|
||||
int16 * ptr_out = outPcm;
|
||||
|
||||
|
||||
for (int32 band = 0; band < FILTERBANK_BANDS; band += 2)
|
||||
{
|
||||
int32 *inData = &pChVars->circ_buffer[544 - (band<<5)];
|
||||
|
||||
/*
|
||||
* DCT 32
|
||||
*/
|
||||
|
||||
pvmp3_split(&inData[16]);
|
||||
|
||||
pvmp3_dct_16(&inData[16], 0);
|
||||
pvmp3_dct_16(inData, 1); // Even terms
|
||||
|
||||
pvmp3_merge_in_place_N32(inData);
|
||||
|
||||
pvmp3_polyphase_filter_window(inData,
|
||||
ptr_out,
|
||||
numChannels);
|
||||
|
||||
inData -= SUBBANDS_NUMBER;
|
||||
|
||||
/*
|
||||
* DCT 32
|
||||
*/
|
||||
|
||||
pvmp3_split(&inData[16]);
|
||||
|
||||
pvmp3_dct_16(&inData[16], 0);
|
||||
pvmp3_dct_16(inData, 1); // Even terms
|
||||
|
||||
pvmp3_merge_in_place_N32(inData);
|
||||
|
||||
pvmp3_polyphase_filter_window(inData,
|
||||
ptr_out + (numChannels << 5),
|
||||
numChannels);
|
||||
|
||||
ptr_out += (numChannels << 6);
|
||||
|
||||
inData -= SUBBANDS_NUMBER;
|
||||
|
||||
}/* end band loop */
|
||||
|
||||
pv_memmove(&pChVars->circ_buffer[576],
|
||||
pChVars->circ_buffer,
|
||||
480*sizeof(*pChVars->circ_buffer));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_poly_phase_synthesis.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_POLY_PHASE_SYNTHESIS_H
|
||||
#define PVMP3_POLY_PHASE_SYNTHESIS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_tmp3dec_chan.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_poly_phase_synthesis(tmp3dec_chan *pChVars,
|
||||
int32 numChannels,
|
||||
e_equalization equalizerType,
|
||||
int16 *outPcm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_polyphase_filter_window.cpp
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
|
||||
Input
|
||||
int32 *synth_buffer, synthesis input buffer
|
||||
int16 *outPcm, generated output ( 32 values)
|
||||
int32 numChannels number of channels
|
||||
Returns
|
||||
|
||||
int16 *outPcm
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
apply polyphase filter window
|
||||
Input 32 subband samples
|
||||
Calculate 64 values
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_polyphase_filter_window.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_tables.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module1 specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module1
|
||||
----------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module_x
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module_x but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_polyphase_filter_window(int32 *synth_buffer,
|
||||
int16 *outPcm,
|
||||
int32 numChannels)
|
||||
{
|
||||
int32 sum1;
|
||||
int32 sum2;
|
||||
const int32 *winPtr = pqmfSynthWin;
|
||||
int32 i;
|
||||
|
||||
|
||||
for (int16 j = 1; j < SUBBANDS_NUMBER / 2; j++)
|
||||
{
|
||||
sum1 = 0x00000020;
|
||||
sum2 = 0x00000020;
|
||||
|
||||
|
||||
for (i = (SUBBANDS_NUMBER >> 1);
|
||||
i < HAN_SIZE + (SUBBANDS_NUMBER >> 1);
|
||||
i += SUBBANDS_NUMBER << 4)
|
||||
{
|
||||
int32 *pt_1 = &synth_buffer[ i+j];
|
||||
int32 *pt_2 = &synth_buffer[ i-j];
|
||||
int32 temp1 = pt_1[ 0];
|
||||
int32 temp3 = pt_2[ SUBBANDS_NUMBER*15 ];
|
||||
int32 temp2 = pt_2[ SUBBANDS_NUMBER* 1 ];
|
||||
int32 temp4 = pt_1[ SUBBANDS_NUMBER*14 ];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 0]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 0]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 1]);
|
||||
sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 1]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[ 2]);
|
||||
sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[ 2]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[ 3]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[ 3]);
|
||||
|
||||
temp1 = pt_1[ SUBBANDS_NUMBER* 2];
|
||||
temp3 = pt_2[ SUBBANDS_NUMBER*13];
|
||||
temp2 = pt_2[ SUBBANDS_NUMBER* 3];
|
||||
temp4 = pt_1[ SUBBANDS_NUMBER*12];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 4]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 4]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 5]);
|
||||
sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 5]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[ 6]);
|
||||
sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[ 6]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[ 7]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[ 7]);
|
||||
|
||||
temp1 = pt_1[ SUBBANDS_NUMBER* 4 ];
|
||||
temp3 = pt_2[ SUBBANDS_NUMBER*11 ];
|
||||
temp2 = pt_2[ SUBBANDS_NUMBER* 5 ];
|
||||
temp4 = pt_1[ SUBBANDS_NUMBER*10 ];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[ 8]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[ 8]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[ 9]);
|
||||
sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[ 9]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[10]);
|
||||
sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[10]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[11]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[11]);
|
||||
|
||||
temp1 = pt_1[ SUBBANDS_NUMBER*6 ];
|
||||
temp3 = pt_2[ SUBBANDS_NUMBER*9 ];
|
||||
temp2 = pt_2[ SUBBANDS_NUMBER*7 ];
|
||||
temp4 = pt_1[ SUBBANDS_NUMBER*8 ];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[12]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[12]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp1, winPtr[13]);
|
||||
sum1 = fxp_msb32_Q32(sum1, temp3, winPtr[13]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[14]);
|
||||
sum2 = fxp_msb32_Q32(sum2, temp4, winPtr[14]);
|
||||
sum2 = fxp_mac32_Q32(sum2, temp2, winPtr[15]);
|
||||
sum1 = fxp_mac32_Q32(sum1, temp4, winPtr[15]);
|
||||
|
||||
winPtr += 16;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32 k = j << (numChannels - 1);
|
||||
outPcm[k] = saturate16(sum1 >> 6);
|
||||
outPcm[(numChannels<<5) - k] = saturate16(sum2 >> 6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sum1 = 0x00000020;
|
||||
sum2 = 0x00000020;
|
||||
|
||||
|
||||
for (i = 16; i < HAN_SIZE + 16; i += (SUBBANDS_NUMBER << 2))
|
||||
{
|
||||
int32 *pt_synth = &synth_buffer[i];
|
||||
int32 temp1 = pt_synth[ 0 ];
|
||||
int32 temp2 = pt_synth[ SUBBANDS_NUMBER ];
|
||||
int32 temp3 = pt_synth[ SUBBANDS_NUMBER/2];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[0]) ;
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[1]) ;
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[2]) ;
|
||||
|
||||
temp1 = pt_synth[ SUBBANDS_NUMBER<<1 ];
|
||||
temp2 = pt_synth[ 3*SUBBANDS_NUMBER ];
|
||||
temp3 = pt_synth[ SUBBANDS_NUMBER*5/2];
|
||||
|
||||
sum1 = fxp_mac32_Q32(sum1, temp1, winPtr[3]) ;
|
||||
sum1 = fxp_mac32_Q32(sum1, temp2, winPtr[4]) ;
|
||||
sum2 = fxp_mac32_Q32(sum2, temp3, winPtr[5]) ;
|
||||
|
||||
winPtr += 6;
|
||||
}
|
||||
|
||||
|
||||
outPcm[0] = saturate16(sum1 >> 6);
|
||||
outPcm[(SUBBANDS_NUMBER/2)<<(numChannels-1)] = saturate16(sum2 >> 6);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // If not assembly
|
||||
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_decode_header.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_POLYPHASE_FILTER_WINDOW_H
|
||||
#define PVMP3_POLYPHASE_FILTER_WINDOW_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "s_tmp3dec_chan.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define MAX_16BITS_INT 0x7FFF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(PV_ARM_V5)||defined(PV_ARM_V4))
|
||||
|
||||
|
||||
__inline int16 saturate16(int32 sample)
|
||||
{
|
||||
int32 a;
|
||||
int32 b = 31;
|
||||
__asm
|
||||
{
|
||||
mov a, sample, asr#15
|
||||
teq a, sample, asr b
|
||||
eorne sample, MAX_16BITS_INT, sample, asr#31
|
||||
}
|
||||
return sample ;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline int16 saturate16(int32 sample)
|
||||
{
|
||||
|
||||
if ((sample >> 15) ^(sample >> 31))
|
||||
{
|
||||
sample = MAX_16BITS_INT ^(sample >> 31);
|
||||
}
|
||||
return sample;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void pvmp3_polyphase_filter_window(int32 *synth_buffer,
|
||||
int16 *outPcm,
|
||||
int32 numChannels);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_reorder.cpp
|
||||
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Inputs:
|
||||
|
||||
int32 xr[ ], rescaled data
|
||||
struct gr_info_s *gr_info, granule structure
|
||||
mp3Header *info, mp3 header info
|
||||
int32 Scratch_mem[198] for temporary usage
|
||||
|
||||
Outputs:
|
||||
|
||||
int32 xr[ ], reordered data
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
If short blocks are used (block_type[gr][ch]=='10'), the rescaled data
|
||||
xr[scf_band][window][freq_line] shall be reordered in polyphase subband
|
||||
order, xr[subband][window][freq_line], prior to the IMDCT operation.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_reorder.h"
|
||||
#include "pvmp3_tables.h"
|
||||
#include "mp3_mem_funcs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_reorder(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
granuleInfo *gr_info,
|
||||
int32 *used_freq_lines,
|
||||
mp3Header *info,
|
||||
int32 Scratch_mem[198])
|
||||
{
|
||||
int32 sfreq = info->version_x + (info->version_x << 1);
|
||||
sfreq += info->sampling_frequency;
|
||||
|
||||
if (gr_info->window_switching_flag && (gr_info->block_type == 2))
|
||||
{
|
||||
int32 sfb_lines;
|
||||
int32 freq;
|
||||
int32 src_line;
|
||||
int32 sfb;
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
/* REORDERING FOR REST SWITCHED SHORT */
|
||||
sfb = 3; /* no reorder for low 2 subbands */
|
||||
src_line = 36;
|
||||
}
|
||||
else
|
||||
{ /* pure short */
|
||||
sfb = 0;
|
||||
src_line = 0;
|
||||
}
|
||||
int16 ct = src_line;
|
||||
|
||||
for (; sfb < 13; sfb++)
|
||||
{
|
||||
if (*used_freq_lines > 3*mp3_sfBandIndex[sfreq].s[sfb+1])
|
||||
{
|
||||
sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
|
||||
for (freq = 0; freq < 3*sfb_lines; freq += 3)
|
||||
{
|
||||
int32 tmp1 = xr[src_line];
|
||||
int32 tmp2 = xr[src_line+(sfb_lines)];
|
||||
int32 tmp3 = xr[src_line+(sfb_lines<<1)];
|
||||
src_line++;
|
||||
Scratch_mem[freq ] = tmp1;
|
||||
Scratch_mem[freq+1] = tmp2;
|
||||
Scratch_mem[freq+2] = tmp3;
|
||||
}
|
||||
src_line += (sfb_lines << 1);
|
||||
|
||||
pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
|
||||
ct += sfb_lines + (sfb_lines << 1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
sfb_lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
|
||||
for (freq = 0; freq < 3*sfb_lines; freq += 3)
|
||||
{
|
||||
int32 tmp1 = xr[src_line];
|
||||
int32 tmp2 = xr[src_line+(sfb_lines)];
|
||||
int32 tmp3 = xr[src_line+(sfb_lines<<1)];
|
||||
src_line++;
|
||||
Scratch_mem[freq ] = tmp1;
|
||||
Scratch_mem[freq+1] = tmp2;
|
||||
Scratch_mem[freq+2] = tmp3;
|
||||
}
|
||||
|
||||
pv_memcpy(&xr[ct], Scratch_mem, sfb_lines*3*sizeof(int32));
|
||||
|
||||
*used_freq_lines = mp3_sfBandIndex[sfreq].s[sfb+1] * 3;
|
||||
|
||||
sfb = 13; /* force out of the for-loop */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_reorder.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_REORDER_H
|
||||
#define PVMP3_REORDER_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void pvmp3_reorder(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
granuleInfo *gr_info,
|
||||
int32 *used_freq_lines,
|
||||
mp3Header *info,
|
||||
int32 Scratch_mem[198]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,308 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_seek_synch.cpp
|
||||
|
||||
Functions:
|
||||
pvmp3_seek_synch
|
||||
pvmp3_header_sync
|
||||
|
||||
|
||||
Date: 9/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
pvmp3_frame_synch
|
||||
|
||||
Input
|
||||
pExt = pointer to the external interface structure. See the file
|
||||
pvmp3decoder_api.h for a description of each field.
|
||||
Data type of pointer to a tPVMP3DecoderExternal
|
||||
structure.
|
||||
|
||||
pMem = void pointer to hide the internal implementation of the library
|
||||
It is cast back to a tmp3dec_file structure. This structure
|
||||
contains information that needs to persist between calls to
|
||||
this function, or is too big to be placed on the stack, even
|
||||
though the data is only needed during execution of this function
|
||||
Data type void pointer, internally pointer to a tmp3dec_file
|
||||
structure.
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
search mp3 sync word, when found, it verifies, based on header parameters,
|
||||
the locations of the very next sync word,
|
||||
- if fails, then indicates a false sync,
|
||||
- otherwise, it confirm synchronization of at least 2 consecutives frames
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_seek_synch.h"
|
||||
#include "pvmp3_getbits.h"
|
||||
#include "s_tmp3dec_file.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_tables.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
ERROR_CODE pvmp3_frame_synch(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem) /* bit stream structure */
|
||||
{
|
||||
uint16 val;
|
||||
ERROR_CODE err;
|
||||
|
||||
tmp3dec_file *pVars;
|
||||
|
||||
pVars = (tmp3dec_file *)pMem;
|
||||
|
||||
pVars->inputStream.pBuffer = pExt->pInputBuffer;
|
||||
pVars->inputStream.usedBits = (pExt->inputBufferUsedLength << 3); // in bits
|
||||
|
||||
|
||||
pVars->inputStream.inputBufferCurrentLength = (pExt->inputBufferCurrentLength); // in bits
|
||||
|
||||
err = pvmp3_header_sync(&pVars->inputStream);
|
||||
|
||||
if (err == NO_DECODING_ERROR)
|
||||
{
|
||||
/* validate synchronization by checking two consecutive sync words */
|
||||
|
||||
// to avoid multiple bitstream accesses
|
||||
uint32 temp = getNbits(&pVars->inputStream, 21);
|
||||
// put back whole header
|
||||
pVars->inputStream.usedBits -= 21 + SYNC_WORD_LNGTH;
|
||||
|
||||
int32 version;
|
||||
|
||||
switch (temp >> 19) /* 2 */
|
||||
{
|
||||
case 0:
|
||||
version = MPEG_2_5;
|
||||
break;
|
||||
case 2:
|
||||
version = MPEG_2;
|
||||
break;
|
||||
case 3:
|
||||
version = MPEG_1;
|
||||
break;
|
||||
default:
|
||||
version = INVALID_VERSION;
|
||||
break;
|
||||
}
|
||||
|
||||
int32 freq_index = (temp << 20) >> 30;
|
||||
|
||||
if (version != INVALID_VERSION && (freq_index != 3))
|
||||
{
|
||||
int32 numBytes = fxp_mul32_Q28(mp3_bitrate[version][(temp<<16)>>28] << 20,
|
||||
inv_sfreq[freq_index]);
|
||||
|
||||
numBytes >>= (20 - version);
|
||||
|
||||
if (version != MPEG_1)
|
||||
{
|
||||
numBytes >>= 1;
|
||||
}
|
||||
if ((temp << 22) >> 31)
|
||||
{
|
||||
numBytes++;
|
||||
}
|
||||
|
||||
if (numBytes > (int32)pVars->inputStream.inputBufferCurrentLength)
|
||||
{
|
||||
/* frame should account for padding and 2 bytes to check sync */
|
||||
pExt->CurrentFrameLength = numBytes + 3;
|
||||
return (SYNCH_LOST_ERROR);
|
||||
}
|
||||
else if (numBytes == (int32)pVars->inputStream.inputBufferCurrentLength)
|
||||
{
|
||||
/* No enough data to validate, but current frame appears to be correct ( EOF case) */
|
||||
pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3;
|
||||
return (NO_DECODING_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int32 offset = pVars->inputStream.usedBits + ((numBytes) << 3);
|
||||
|
||||
offset >>= INBUF_ARRAY_INDEX_SHIFT;
|
||||
uint8 *pElem = pVars->inputStream.pBuffer + offset;
|
||||
uint16 tmp1 = *(pElem++);
|
||||
uint16 tmp2 = *(pElem);
|
||||
|
||||
val = (tmp1 << 3);
|
||||
val |= (tmp2 >> 5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val = 0; // force mismatch
|
||||
}
|
||||
|
||||
if (val == SYNC_WORD)
|
||||
{
|
||||
pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3; /// !!!!!
|
||||
err = NO_DECODING_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
pExt->inputBufferCurrentLength = 0;
|
||||
err = SYNCH_LOST_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pExt->inputBufferCurrentLength = 0;
|
||||
}
|
||||
|
||||
return(err);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
pvmp3_header_sync
|
||||
|
||||
Input
|
||||
tmp3Bits *inputStream, structure holding the input stream parameters
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
search mp3 sync word
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
ERROR_CODE pvmp3_header_sync(tmp3Bits *inputStream)
|
||||
{
|
||||
uint16 val;
|
||||
uint32 availableBits = (inputStream->inputBufferCurrentLength << 3); // in bits
|
||||
|
||||
// byte aligment
|
||||
inputStream->usedBits = (inputStream->usedBits + 7) & 8;
|
||||
|
||||
val = (uint16)getUpTo17bits(inputStream, SYNC_WORD_LNGTH);
|
||||
|
||||
while (((val&SYNC_WORD) != SYNC_WORD) && (inputStream->usedBits < availableBits))
|
||||
{
|
||||
val <<= 8;
|
||||
val |= getUpTo9bits(inputStream, 8);
|
||||
}
|
||||
|
||||
if ((val&SYNC_WORD) == SYNC_WORD && (inputStream->usedBits < availableBits))
|
||||
{
|
||||
return(NO_DECODING_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(SYNCH_LOST_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_seek_synch.h
|
||||
|
||||
Date: 09/21/2007
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
|
||||
Description:
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_SEEK_SYNCH_H
|
||||
#define PVMP3_SEEK_SYNCH_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3decoder_api.h"
|
||||
#include "s_tmp3dec_file.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
ERROR_CODE pvmp3_frame_synch(tPVMP3DecoderExternal *pExt,
|
||||
void *pMem);
|
||||
|
||||
ERROR_CODE pvmp3_header_sync(tmp3Bits *inputStream);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif /* DECODE_READ_INPUT_H */
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,676 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_stereo_proc.cpp
|
||||
|
||||
Functions:
|
||||
|
||||
pvmp3_st_mid_side
|
||||
pvmp3_st_intensity
|
||||
pvmp3_stereo_proc
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pvmp3_st_mid_side
|
||||
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
int32 xr[], input channel
|
||||
int32 xl[],
|
||||
int32 Start, Location of first element where stereo intensity is applied
|
||||
int32 Number number of elements affected
|
||||
|
||||
Returns
|
||||
|
||||
int32 xl[], generated stereo channel
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pvmp3_st_intensity
|
||||
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
int32 xr[], input channel
|
||||
int32 xl[],
|
||||
int32 is_pos, index to table is_ratio_factor[]
|
||||
int32 Start, Location of first element where stereo intensity is applied
|
||||
int32 Number number of elements affected
|
||||
|
||||
Returns
|
||||
|
||||
int32 xl[], generated stereo channel
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
pvmp3_stereo_proc
|
||||
|
||||
INPUT AND OUTPUT DEFINITIONS
|
||||
|
||||
Input
|
||||
|
||||
int32 xr[], input channel
|
||||
int32 xl[],
|
||||
mp3ScaleFactors *scalefac, scale factors structure
|
||||
struct gr_info_s *gr_info, granule structure
|
||||
mp3Header *info mp3 header info
|
||||
Returns
|
||||
|
||||
int32 xl[], generated stereo channel
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
FUNCTION DESCRIPTION
|
||||
|
||||
stereo processing for mpeg1 layer III
|
||||
After requantization, the reconstructed values are processed for ms_stereo
|
||||
or intensity_stereo modes or both, before passing them to the synthesis
|
||||
filterbank
|
||||
|
||||
In ms_stereo mode the values of the normalized middle/side channels
|
||||
M[l] and S[l] are transmitted instead of the left/right channel values
|
||||
L[l] and R[l]. From here, L[l] and R[l] are reconstructed
|
||||
|
||||
Intensity_stereo is done by specifying the magnitude (via the
|
||||
scalefactors of the left channel) and a stereo position is_pos[sfb],
|
||||
which is transmitted instead of scalefactors of the right channel.
|
||||
The stereo position is used to derive the left and right channel signals
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REQUIREMENTS
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
PSEUDO-CODE
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_stereo_proc.h"
|
||||
#include "pv_mp3dec_fxd_op.h"
|
||||
#include "pvmp3_tables.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here. Include conditional
|
||||
; compile variables also.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define N31 31
|
||||
|
||||
#define Q31_fmt(a) (int32(double(0x7FFFFFFF)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
|
||||
; Variable declaration - defined here and used outside this module
|
||||
----------------------------------------------------------------------------*/
|
||||
/*
|
||||
* TmpFac= tan(is_pos * (PI /12));
|
||||
*
|
||||
* TmpFac /= (1 + TmpFac);
|
||||
*
|
||||
*/
|
||||
|
||||
const int32 is_ratio_factor[8] = {0,
|
||||
Q31_fmt(0.21132486540519), Q31_fmt(0.36602540378444), Q31_fmt(0.50000000000000),
|
||||
Q31_fmt(0.63397459621556), Q31_fmt(0.78867513459481), Q31_fmt(1.00000000000000),
|
||||
0
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL FUNCTION REFERENCES
|
||||
; Declare functions defined elsewhere and referenced in this module
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_st_mid_side(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 Start,
|
||||
int32 Number)
|
||||
{
|
||||
|
||||
int32 *pt_xr = &xr[Start];
|
||||
int32 *pt_xl = &xl[Start];
|
||||
|
||||
for (int32 i = Number >> 1; i != 0; i--)
|
||||
{
|
||||
int32 xxr = *(pt_xr) << 1;
|
||||
int32 xxl = *(pt_xl) << 1;
|
||||
*(pt_xr++) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
|
||||
*(pt_xl++) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
|
||||
xxr = *(pt_xr) << 1;
|
||||
xxl = *(pt_xl) << 1;
|
||||
*(pt_xr++) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
|
||||
*(pt_xl++) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
|
||||
}
|
||||
|
||||
|
||||
if (Number&1)
|
||||
{
|
||||
int32 xxr = *(pt_xr) << 1;
|
||||
int32 xxl = *(pt_xl) << 1;
|
||||
*(pt_xr) = fxp_mul32_Q32((xxr + xxl), Q31_fmt(0.70710678118655)); /* Sum */
|
||||
*(pt_xl) = fxp_mul32_Q32((xxr - xxl), Q31_fmt(0.70710678118655)); /* Diff */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void pvmp3_st_intensity(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 is_pos,
|
||||
int32 Start,
|
||||
int32 Number)
|
||||
{
|
||||
|
||||
int32 TmpFac = is_ratio_factor[ is_pos & 7];
|
||||
|
||||
int32 *pt_xr = &xr[Start];
|
||||
int32 *pt_xl = &xl[Start];
|
||||
|
||||
for (int32 i = Number >> 1; i != 0; i--)
|
||||
{
|
||||
int32 tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
|
||||
*(pt_xl++) = (*pt_xr) - tmp;
|
||||
*(pt_xr++) = tmp;
|
||||
tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
|
||||
*(pt_xl++) = (*pt_xr) - tmp;
|
||||
*(pt_xr++) = tmp;
|
||||
}
|
||||
|
||||
if (Number&1)
|
||||
{
|
||||
int32 tmp = fxp_mul32_Q32((*pt_xr) << 1, TmpFac);
|
||||
*(pt_xl) = (*pt_xr) - tmp;
|
||||
*(pt_xr) = tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; FUNCTION CODE
|
||||
----------------------------------------------------------------------------*/
|
||||
void pvmp3_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac,
|
||||
granuleInfo *gr_info,
|
||||
int32 used_freq_lines,
|
||||
mp3Header *info)
|
||||
{
|
||||
|
||||
|
||||
int32 sb;
|
||||
int32 ss;
|
||||
int32 sfbNo;
|
||||
int32 sfbStart;
|
||||
|
||||
int32 sfb;
|
||||
int32 sfbTemp;
|
||||
int32 i;
|
||||
int32 j;
|
||||
|
||||
|
||||
int32 i_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
|
||||
(info->mode_ext & 0x1);
|
||||
|
||||
int32 ms_stereo = (info->mode == MPG_MD_JOINT_STEREO) &&
|
||||
(info->mode_ext & 0x2);
|
||||
|
||||
int32 sfreq = info->version_x + (info->version_x << 1);
|
||||
sfreq += info->sampling_frequency;
|
||||
|
||||
|
||||
|
||||
|
||||
if (i_stereo)
|
||||
{
|
||||
if (gr_info->window_switching_flag && (gr_info->block_type == 2))
|
||||
{
|
||||
if (gr_info->mixed_block_flag)
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing
|
||||
*/
|
||||
i = 31;
|
||||
ss = 17;
|
||||
sb = 0;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (xl[(i*FILTERBANK_BANDS) + ss])
|
||||
{
|
||||
sb = (i << 4) + (i << 1) + ss;
|
||||
i = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss--;
|
||||
if (ss < 0)
|
||||
{
|
||||
i--;
|
||||
ss = 17;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sb < 36)
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing: intensity bound inside long blocks
|
||||
*/
|
||||
/* 1. long blocks up to intensity border: not intensity */
|
||||
|
||||
if (mp3_sfBandIndex[sfreq].l[4] <= sb)
|
||||
{
|
||||
sfb = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
sfb = 0;
|
||||
}
|
||||
|
||||
while (mp3_sfBandIndex[sfreq].l[sfb] < sb)
|
||||
{
|
||||
sfb++;
|
||||
}
|
||||
|
||||
/* from that sfb on intensity stereo */
|
||||
sfbTemp = sfb; /* save for later use */
|
||||
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
|
||||
|
||||
/* from 0 up to sfbStart do ms_stereo or normal stereo */
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, sfbStart);
|
||||
}
|
||||
|
||||
/* 2. long blocks from intensity border up to sfb band 8: intensity */
|
||||
/* calc. is_ratio */
|
||||
|
||||
|
||||
/* Start of intensity stereo of remaining sfc bands: */
|
||||
for (; sfbTemp < 8; sfbTemp++)
|
||||
{
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfbTemp]; /* = Start in 0 ... 575 */
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfbTemp+1] - mp3_sfBandIndex[sfreq].l[sfbTemp]; /* No of lines to process */
|
||||
|
||||
if (scalefac->l[sfbTemp] != 7)
|
||||
{
|
||||
pvmp3_st_intensity(xr, xl, scalefac->l[sfbTemp], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (; sfbTemp < 8; sfbTemp++) */
|
||||
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
/* 3. short blocks from sfbcnt to last sfb do intensity stereo */
|
||||
for (sfbTemp = 3; sfbTemp < 13; sfbTemp++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
|
||||
|
||||
if (scalefac->s[j][sfbTemp] != 7)
|
||||
{
|
||||
pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (; sfbTemp < 22; sfbTemp++) */
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
}
|
||||
else /* else for (sb >= 36) */
|
||||
{
|
||||
/*
|
||||
* mixed blocks processing: intensity bound outside long blocks
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* 2. short blocks from sfb band 3 up to intensity border: normal stereo, ms stereo and intensity
|
||||
*/
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
int32 sfbcnt;
|
||||
sfbcnt = -1;
|
||||
|
||||
for (sfb = 12; sfb >= 3; sfb--)
|
||||
{
|
||||
int32 lines;
|
||||
lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
|
||||
|
||||
while (lines > 0)
|
||||
{
|
||||
if (xl[i])
|
||||
{
|
||||
sfbcnt = sfb;
|
||||
sfb = -10;
|
||||
lines = -10;
|
||||
}
|
||||
lines--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
sfbcnt += 1;
|
||||
if (sfbcnt < 3)
|
||||
{
|
||||
sfbcnt = 3;
|
||||
}
|
||||
|
||||
sfbTemp = sfbcnt; /* for later use */
|
||||
|
||||
|
||||
/*
|
||||
* do normal stereo or MS stereo from sfb 3 to < sfbcnt:
|
||||
*/
|
||||
for (sb = 3; sb < sfbcnt; sb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sb+1] - mp3_sfBandIndex[sfreq].s[sb];
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sb] + j * sfbNo;
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* from sfbcnt to last sfb do intensity stereo */
|
||||
for (; sfbTemp < 13; sfbTemp++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
|
||||
|
||||
if (scalefac->s[j][sfbTemp] != 7)
|
||||
{
|
||||
pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (; sfbTemp < 22; sfbTemp++) */
|
||||
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
|
||||
/* 1. long blocks up to sfb band 8: not intensity */
|
||||
/* from 0 to sfb 8 ms_stereo or normal stereo */
|
||||
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[8];
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, sfbStart);
|
||||
}
|
||||
|
||||
}
|
||||
} /* if (gr_info->mixed_block_flag) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* short block processing
|
||||
*/
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
int32 sfbcnt = -1;
|
||||
|
||||
for (sfb = 12; sfb >= 0; sfb--)
|
||||
{
|
||||
int32 lines = mp3_sfBandIndex[sfreq].s[sfb+1] - mp3_sfBandIndex[sfreq].s[sfb];
|
||||
i = 3 * mp3_sfBandIndex[sfreq].s[sfb] + (j + 1) * lines - 1;
|
||||
|
||||
while (lines > 0)
|
||||
{
|
||||
if (xl[i])
|
||||
{
|
||||
sfbcnt = sfb;
|
||||
sfb = -10;
|
||||
lines = -10;
|
||||
}
|
||||
lines--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
sfbcnt += 1;
|
||||
sfbTemp = sfbcnt; /* for later use */
|
||||
|
||||
/* do normal stereo or MS stereo from 0 to sfbcnt */
|
||||
for (sb = 0; sb < sfbcnt; sb++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sb+1] - mp3_sfBandIndex[sfreq].s[sb];
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sb] + j * sfbNo;
|
||||
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* from sfbcnt to last sfb do intensity stereo */
|
||||
for (; sfbTemp < 13; sfbTemp++)
|
||||
{
|
||||
sfbNo = mp3_sfBandIndex[sfreq].s[sfbTemp+1] - mp3_sfBandIndex[sfreq].s[sfbTemp]; /* No of lines to process */
|
||||
sfbStart = 3 * mp3_sfBandIndex[sfreq].s[sfbTemp] + j * sfbNo;
|
||||
|
||||
if (scalefac->s[j][sfbTemp] != 7)
|
||||
{
|
||||
pvmp3_st_intensity(xr, xl, scalefac->s[j][sfbTemp], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (; sfbTemp < 22; sfbTemp++) */
|
||||
|
||||
} /* for (j = 0; j < 3; j++) */
|
||||
|
||||
} /* if( gr_info->mixed_block_flag) */
|
||||
|
||||
|
||||
|
||||
} /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* long block processing
|
||||
*/
|
||||
i = 31;
|
||||
ss = 17;
|
||||
sb = 0;
|
||||
|
||||
while (i >= 0)
|
||||
{
|
||||
if (xl[(i*FILTERBANK_BANDS) + ss] != 0)
|
||||
{
|
||||
sb = (i << 4) + (i << 1) + ss;
|
||||
i = -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss--;
|
||||
if (ss < 0)
|
||||
{
|
||||
i--;
|
||||
ss = 17;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sb)
|
||||
{
|
||||
if (mp3_sfBandIndex[sfreq].l[14] <= sb)
|
||||
{
|
||||
sfb = 14;
|
||||
}
|
||||
else if (mp3_sfBandIndex[sfreq].l[7] <= sb)
|
||||
{
|
||||
sfb = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
sfb = 0;
|
||||
}
|
||||
|
||||
|
||||
while (mp3_sfBandIndex[sfreq].l[sfb] <= sb)
|
||||
{
|
||||
sfb++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i == -1)
|
||||
{
|
||||
/* all xr[1][][] are 0: set IS bound sfb to 0 */
|
||||
sfb = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* xr[1][0][0] is unequal 0 and all others are 0: set IS bound sfb to 1 */
|
||||
sfb = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sfbTemp = sfb; /* save for later use */
|
||||
|
||||
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
|
||||
|
||||
/* from 0 to sfbStart ms_stereo or normal stereo */
|
||||
if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, 0, sfbStart);
|
||||
}
|
||||
|
||||
/* now intensity stereo of the remaining sfb's: */
|
||||
for (; sfb < 21; sfb++)
|
||||
{
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[sfb];
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[sfb+1] - mp3_sfBandIndex[sfreq].l[sfb]; /* No of lines to process */
|
||||
|
||||
if (scalefac->l[sfb] != 7)
|
||||
{
|
||||
pvmp3_st_intensity(xr, xl, scalefac->l[sfb], sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* for (; sfbTemp < 22; sfbTemp++) */
|
||||
|
||||
|
||||
|
||||
sfbStart = mp3_sfBandIndex[sfreq].l[21];
|
||||
sfbNo = mp3_sfBandIndex[sfreq].l[22] - mp3_sfBandIndex[sfreq].l[21]; /* No of lines to process */
|
||||
|
||||
if (scalefac->l[21] != 7)
|
||||
{
|
||||
if (sfbTemp < 21)
|
||||
{
|
||||
sfbTemp = scalefac->l[20];
|
||||
}
|
||||
else
|
||||
{
|
||||
sfbTemp = 0; /* if scalefac[20] is not an intensity position, is_pos = 0 */
|
||||
}
|
||||
|
||||
pvmp3_st_intensity(xr, xl, sfbTemp, sfbStart, sfbNo);
|
||||
}
|
||||
else if (ms_stereo)
|
||||
{
|
||||
pvmp3_st_mid_side(xr, xl, sfbStart, sfbNo);
|
||||
}
|
||||
|
||||
} /* if (gr_info->window_switching_flag && (gr_info->block_type == 2)) */
|
||||
|
||||
|
||||
} /* if (i_stereo) */
|
||||
else
|
||||
{
|
||||
/*
|
||||
* normal or ms stereo processing
|
||||
*/
|
||||
if (ms_stereo)
|
||||
{
|
||||
|
||||
pvmp3_st_mid_side(xr, xl, 0, used_freq_lines);
|
||||
|
||||
}
|
||||
|
||||
} /* if (i_stereo) */
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: pvmp3_stereo_proc.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef PVMP3_STEREO_PROC_H
|
||||
#define PVMP3_STEREO_PROC_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
void pvmp3_stereo_proc(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
mp3ScaleFactors *scalefac,
|
||||
granuleInfo *gr_info,
|
||||
int32 used_freq_lines,
|
||||
mp3Header *info);
|
||||
|
||||
void pvmp3_st_intensity(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 is_pos,
|
||||
int32 Start,
|
||||
int32 Number);
|
||||
|
||||
void pvmp3_st_mid_side(int32 xr[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 xl[SUBBANDS_NUMBER*FILTERBANK_BANDS],
|
||||
int32 Start,
|
||||
int32 Number);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,124 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
Filename: pvmp3_tables.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PVMP3_TABLES_H
|
||||
#define PVMP3_TABLES_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "pvmp3_dec_defs.h"
|
||||
#include "pv_mp3_huffman.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES AND SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#define Qfmt_28(a) (int32(double(0x10000000)*a))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16 l[23];
|
||||
int16 s[14];
|
||||
} mp3_scaleFactorBandIndex;
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern const int32 mp3_s_freq[4][4];
|
||||
extern const int32 inv_sfreq[4];
|
||||
extern const int16 mp3_bitrate[3][15];
|
||||
extern const int32 power_one_third[513];
|
||||
|
||||
extern const mp3_scaleFactorBandIndex mp3_sfBandIndex[9];
|
||||
extern const int32 mp3_shortwindBandWidths[9][13];
|
||||
extern const int32 pqmfSynthWin[(HAN_SIZE/2) + 8];
|
||||
|
||||
|
||||
extern const uint16 huffTable_1[];
|
||||
extern const uint16 huffTable_2[];
|
||||
extern const uint16 huffTable_3[];
|
||||
extern const uint16 huffTable_5[];
|
||||
extern const uint16 huffTable_6[];
|
||||
extern const uint16 huffTable_7[];
|
||||
extern const uint16 huffTable_8[];
|
||||
extern const uint16 huffTable_9[];
|
||||
extern const uint16 huffTable_10[];
|
||||
extern const uint16 huffTable_11[];
|
||||
extern const uint16 huffTable_12[];
|
||||
extern const uint16 huffTable_13[];
|
||||
extern const uint16 huffTable_15[];
|
||||
extern const uint16 huffTable_16[];
|
||||
extern const uint16 huffTable_24[];
|
||||
extern const uint16 huffTable_32[];
|
||||
extern const uint16 huffTable_33[];
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: s_huffcodetab.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REFERENCES
|
||||
|
||||
[1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
|
||||
ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
|
||||
|
||||
----------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef S_HUFFCODETAB_H
|
||||
#define S_HUFFCODETAB_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
#define HUFF_TBL 34
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
struct huffcodetab
|
||||
{
|
||||
uint32 linbits; /*number of linbits */
|
||||
uint16(*pdec_huff_tab)(tmp3Bits *);
|
||||
};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: s_mp3bits.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines the structure, BITS
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef S_MP3BITS_H
|
||||
#define S_MP3BITS_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Name: BITS
|
||||
* Description: Holds information for processing the input data buffer
|
||||
* as a "stream". The data is in packed format.
|
||||
* Fields:
|
||||
* pBuffer - pointer to the beginning of the buffer. If the data type of
|
||||
* this changes, make sure to update the constants in ibstream.h
|
||||
* usedBits - number of bits read thus far from the buffer. Bit 0 is
|
||||
* the LSB of pBuffer[0].
|
||||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 *pBuffer;
|
||||
uint32 usedBits;
|
||||
uint32 inputBufferCurrentLength;
|
||||
uint32 offset;
|
||||
} tmp3Bits;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: s_tmp3dec_chan.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines the structure, tmp3dec_chan.
|
||||
This structure contains information per channel that needs to persist
|
||||
between calls
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef S_TMP3DEC_CHAN_H
|
||||
#define S_TMP3DEC_CHAN_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "pvmp3_audio_type_defs.h"
|
||||
#include "pvmp3_dec_defs.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32 used_freq_lines;
|
||||
int32 overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS];
|
||||
int32 work_buf_int32[SUBBANDS_NUMBER*FILTERBANK_BANDS]; /* working buffer */
|
||||
int32 circ_buffer[480 + 576];
|
||||
|
||||
} tmp3dec_chan;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
PacketVideo Corp.
|
||||
MP3 Decoder Library
|
||||
|
||||
Filename: s_tmp3dec_file.h
|
||||
|
||||
Date: 09/21/2007
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
REVISION HISTORY
|
||||
|
||||
Description:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
INCLUDE DESCRIPTION
|
||||
|
||||
This include file defines the structure, tmp3dec_file.
|
||||
This structure contains information that needs to persist between calls
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; CONTINUE ONLY IF NOT ALREADY DEFINED
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifndef S_TMP3DEC_FILE_H
|
||||
#define S_TMP3DEC_FILE_H
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; INCLUDES
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "s_tmp3dec_chan.h"
|
||||
#include "s_mp3bits.h"
|
||||
#include "s_huffcodetab.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; MACROS
|
||||
; Define module specific macros here
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; DEFINES
|
||||
; Include all pre-processor statements here.
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; EXTERNAL VARIABLES REFERENCES
|
||||
; Declare variables used in this module but defined elsewhere
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; SIMPLE TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; ENUMERATED TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; STRUCTURES TYPEDEF'S
|
||||
----------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32 num_channels;
|
||||
int32 predicted_frame_size;
|
||||
int32 frame_start;
|
||||
int32 Scratch_mem[198];
|
||||
tmp3dec_chan perChan[CHAN];
|
||||
mp3ScaleFactors scaleFactors[CHAN];
|
||||
mp3SideInfo sideInfo;
|
||||
tmp3Bits mainDataStream;
|
||||
uint8 mainDataBuffer[BUFSIZE];
|
||||
tmp3Bits inputStream;
|
||||
huffcodetab ht[HUFF_TBL];
|
||||
} tmp3dec_file;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; GLOBAL FUNCTION DEFINITIONS
|
||||
; Function Prototype declaration
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
; END
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES = \
|
||||
Tremolo/bitwise.c \
|
||||
Tremolo/codebook.c \
|
||||
Tremolo/dsp.c \
|
||||
Tremolo/floor0.c \
|
||||
Tremolo/floor1.c \
|
||||
Tremolo/floor_lookup.c \
|
||||
Tremolo/framing.c \
|
||||
Tremolo/mapping0.c \
|
||||
Tremolo/mdct.c \
|
||||
Tremolo/misc.c \
|
||||
Tremolo/res012.c \
|
||||
Tremolo/treminfo.c \
|
||||
Tremolo/vorbisfile.c
|
||||
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += \
|
||||
Tremolo/bitwiseARM.s \
|
||||
Tremolo/dpen.s \
|
||||
Tremolo/floor1ARM.s \
|
||||
Tremolo/mdctARM.s
|
||||
LOCAL_CFLAGS += \
|
||||
-D_ARM_ASSEM_
|
||||
# Assembly code in asm_arm.h does not compile with Clang.
|
||||
LOCAL_CLANG_ASFLAGS_arm += \
|
||||
-no-integrated-as
|
||||
else
|
||||
LOCAL_CFLAGS += \
|
||||
-DONLY_C
|
||||
endif
|
||||
LOCAL_CFLAGS+= -O2
|
||||
|
||||
LOCAL_C_INCLUDES:= \
|
||||
$(LOCAL_PATH)/Tremolo
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := liblog
|
||||
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
||||
LOCAL_MODULE := libvorbisidec
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (C) 2007 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# If you don't need to do a full clean build but would like to touch
|
||||
# a file or delete some intermediate files, add a clean step to the end
|
||||
# of the list. These steps will only be run once, if they haven't been
|
||||
# run before.
|
||||
#
|
||||
# E.g.:
|
||||
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
|
||||
# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
|
||||
#
|
||||
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
|
||||
# files that are missing or have been moved.
|
||||
#
|
||||
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
|
||||
# Use $(OUT_DIR) to refer to the "out" directory.
|
||||
#
|
||||
# If you need to re-do something that's already mentioned, just copy
|
||||
# the command and add it to the bottom of the list. E.g., if a change
|
||||
# that you made last week required touching a file and a change you
|
||||
# made today requires touching the same file, just copy the old
|
||||
# touch step and add it to the end of the list.
|
||||
#
|
||||
# ************************************************
|
||||
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
||||
# ************************************************
|
||||
|
||||
# For example:
|
||||
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
|
||||
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
|
||||
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
|
||||
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
|
||||
|
||||
# ************************************************
|
||||
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
||||
# ************************************************
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
Productions Ltd nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
This version of Tremolo is derived from Tremolo library version
|
||||
0.07. It has been patched against publicly known vulnerabilities
|
||||
with sample files available here:
|
||||
|
||||
http://static.dataspill.org/releases/ogg/examples/
|
||||
|
||||
When syncing with svn, please ensure that these defects are not
|
||||
reintroduced.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
URL: http://wss.co.uk/pinknoise/tremolo/Tremolo007.zip
|
||||
Version: 0.07
|
||||
BugComponent: 99142
|
||||
|
|
@ -0,0 +1,265 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: arm7 and later wide math functions
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifdef _ARM_ASSEM_
|
||||
|
||||
#if !defined(_V_WIDE_MATH) && !defined(_LOW_ACCURACY_)
|
||||
#define _V_WIDE_MATH
|
||||
|
||||
static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
|
||||
int lo,hi;
|
||||
asm volatile("smull\t%0, %1, %2, %3"
|
||||
: "=&r"(lo),"=&r"(hi)
|
||||
: "%r"(x),"r"(y)
|
||||
: "cc");
|
||||
return(hi);
|
||||
}
|
||||
|
||||
static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
|
||||
return MULT32(x,y)<<1;
|
||||
}
|
||||
|
||||
static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
|
||||
int lo,hi;
|
||||
asm volatile("smull %0, %1, %2, %3\n\t"
|
||||
"movs %0, %0, lsr #15\n\t"
|
||||
"adc %1, %0, %1, lsl #17\n\t"
|
||||
: "=&r"(lo),"=&r"(hi)
|
||||
: "%r"(x),"r"(y)
|
||||
: "cc");
|
||||
return(hi);
|
||||
}
|
||||
|
||||
#define MB() asm volatile ("" : : : "memory")
|
||||
|
||||
static inline void XPROD32(ogg_int32_t a, ogg_int32_t b,
|
||||
ogg_int32_t t, ogg_int32_t v,
|
||||
ogg_int32_t *x, ogg_int32_t *y)
|
||||
{
|
||||
int x1, y1, l;
|
||||
asm( "smull %0, %1, %4, %6\n\t"
|
||||
"smlal %0, %1, %5, %7\n\t"
|
||||
"rsb %3, %4, #0\n\t"
|
||||
"smull %0, %2, %5, %6\n\t"
|
||||
"smlal %0, %2, %3, %7"
|
||||
: "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
|
||||
: "3" (a), "r" (b), "r" (t), "r" (v)
|
||||
: "cc" );
|
||||
*x = x1;
|
||||
MB();
|
||||
*y = y1;
|
||||
}
|
||||
|
||||
/* x = (a*t + b*v)>>31, y = (b*t - a*v)>>31 */
|
||||
static inline void XPROD31(ogg_int32_t a, ogg_int32_t b,
|
||||
ogg_int32_t t, ogg_int32_t v,
|
||||
ogg_int32_t *x, ogg_int32_t *y)
|
||||
{
|
||||
int x1, y1, l;
|
||||
asm( "smull %0, %1, %4, %6\n\t"
|
||||
"smlal %0, %1, %5, %7\n\t"
|
||||
"rsb %3, %4, #0\n\t"
|
||||
"smull %0, %2, %5, %6\n\t"
|
||||
"smlal %0, %2, %3, %7"
|
||||
: "=&r" (l), "=&r" (x1), "=&r" (y1), "=r" (a)
|
||||
: "3" (a), "r" (b), "r" (t), "r" (v)
|
||||
: "cc" );
|
||||
*x = x1 << 1;
|
||||
MB();
|
||||
*y = y1 << 1;
|
||||
}
|
||||
|
||||
/* x = (a*t - b*v)>>31, y = (b*t + a*v)>>31 */
|
||||
static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b,
|
||||
ogg_int32_t t, ogg_int32_t v,
|
||||
ogg_int32_t *x, ogg_int32_t *y)
|
||||
{
|
||||
int x1, y1, l;
|
||||
asm( "rsb %2, %4, #0\n\t"
|
||||
"smull %0, %1, %3, %5\n\t"
|
||||
"smlal %0, %1, %2, %6\n\t"
|
||||
"smull %0, %2, %4, %5\n\t"
|
||||
"smlal %0, %2, %3, %6"
|
||||
: "=&r" (l), "=&r" (x1), "=&r" (y1)
|
||||
: "r" (a), "r" (b), "r" (t), "r" (v)
|
||||
: "cc" );
|
||||
*x = x1 << 1;
|
||||
MB();
|
||||
*y = y1 << 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _V_CLIP_MATH
|
||||
#define _V_CLIP_MATH
|
||||
|
||||
static inline ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
|
||||
int tmp;
|
||||
asm volatile("subs %1, %0, #32768\n\t"
|
||||
"movpl %0, #0x7f00\n\t"
|
||||
"orrpl %0, %0, #0xff\n"
|
||||
"adds %1, %0, #32768\n\t"
|
||||
"movmi %0, #0x8000"
|
||||
: "+r"(x),"=r"(tmp)
|
||||
:
|
||||
: "cc");
|
||||
return(x);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _V_LSP_MATH_ASM
|
||||
#define _V_LSP_MATH_ASM
|
||||
|
||||
static inline void lsp_loop_asm(ogg_uint32_t *qip,ogg_uint32_t *pip,
|
||||
ogg_int32_t *qexpp,
|
||||
ogg_int32_t *ilsp,ogg_int32_t wi,
|
||||
ogg_int32_t m){
|
||||
|
||||
ogg_uint32_t qi=*qip,pi=*pip;
|
||||
ogg_int32_t qexp=*qexpp;
|
||||
|
||||
asm("mov r0,%3;"
|
||||
"mov r1,%5,asr#1;"
|
||||
"add r0,r0,r1,lsl#3;"
|
||||
"1:"
|
||||
|
||||
"ldmdb r0!,{r1,r3};"
|
||||
"subs r1,r1,%4;" //ilsp[j]-wi
|
||||
"rsbmi r1,r1,#0;" //labs(ilsp[j]-wi)
|
||||
"umull %0,r2,r1,%0;" //qi*=labs(ilsp[j]-wi)
|
||||
|
||||
"subs r1,r3,%4;" //ilsp[j+1]-wi
|
||||
"rsbmi r1,r1,#0;" //labs(ilsp[j+1]-wi)
|
||||
"umull %1,r3,r1,%1;" //pi*=labs(ilsp[j+1]-wi)
|
||||
|
||||
"cmn r2,r3;" // shift down 16?
|
||||
"beq 0f;"
|
||||
"add %2,%2,#16;"
|
||||
"mov %0,%0,lsr #16;"
|
||||
"orr %0,%0,r2,lsl #16;"
|
||||
"mov %1,%1,lsr #16;"
|
||||
"orr %1,%1,r3,lsl #16;"
|
||||
"0:"
|
||||
"cmp r0,%3;\n"
|
||||
"bhi 1b;\n"
|
||||
|
||||
// odd filter assymetry
|
||||
"ands r0,%5,#1;\n"
|
||||
"beq 2f;\n"
|
||||
"add r0,%3,%5,lsl#2;\n"
|
||||
|
||||
"ldr r1,[r0,#-4];\n"
|
||||
"mov r0,#0x4000;\n"
|
||||
|
||||
"subs r1,r1,%4;\n" //ilsp[j]-wi
|
||||
"rsbmi r1,r1,#0;\n" //labs(ilsp[j]-wi)
|
||||
"umull %0,r2,r1,%0;\n" //qi*=labs(ilsp[j]-wi)
|
||||
"umull %1,r3,r0,%1;\n" //pi*=labs(ilsp[j+1]-wi)
|
||||
|
||||
"cmn r2,r3;\n" // shift down 16?
|
||||
"beq 2f;\n"
|
||||
"add %2,%2,#16;\n"
|
||||
"mov %0,%0,lsr #16;\n"
|
||||
"orr %0,%0,r2,lsl #16;\n"
|
||||
"mov %1,%1,lsr #16;\n"
|
||||
"orr %1,%1,r3,lsl #16;\n"
|
||||
|
||||
//qi=(pi>>shift)*labs(ilsp[j]-wi);
|
||||
//pi=(qi>>shift)*labs(ilsp[j+1]-wi);
|
||||
//qexp+=shift;
|
||||
|
||||
//}
|
||||
|
||||
/* normalize to max 16 sig figs */
|
||||
"2:"
|
||||
"mov r2,#0;"
|
||||
"orr r1,%0,%1;"
|
||||
"tst r1,#0xff000000;"
|
||||
"addne r2,r2,#8;"
|
||||
"movne r1,r1,lsr #8;"
|
||||
"tst r1,#0x00f00000;"
|
||||
"addne r2,r2,#4;"
|
||||
"movne r1,r1,lsr #4;"
|
||||
"tst r1,#0x000c0000;"
|
||||
"addne r2,r2,#2;"
|
||||
"movne r1,r1,lsr #2;"
|
||||
"tst r1,#0x00020000;"
|
||||
"addne r2,r2,#1;"
|
||||
"movne r1,r1,lsr #1;"
|
||||
"tst r1,#0x00010000;"
|
||||
"addne r2,r2,#1;"
|
||||
"mov %0,%0,lsr r2;"
|
||||
"mov %1,%1,lsr r2;"
|
||||
"add %2,%2,r2;"
|
||||
|
||||
: "+r"(qi),"+r"(pi),"+r"(qexp)
|
||||
: "r"(ilsp),"r"(wi),"r"(m)
|
||||
: "r0","r1","r2","r3","cc");
|
||||
|
||||
*qip=qi;
|
||||
*pip=pi;
|
||||
*qexpp=qexp;
|
||||
}
|
||||
|
||||
static inline void lsp_norm_asm(ogg_uint32_t *qip,ogg_int32_t *qexpp){
|
||||
|
||||
ogg_uint32_t qi=*qip;
|
||||
ogg_int32_t qexp=*qexpp;
|
||||
|
||||
asm("tst %0,#0x0000ff00;"
|
||||
"moveq %0,%0,lsl #8;"
|
||||
"subeq %1,%1,#8;"
|
||||
"tst %0,#0x0000f000;"
|
||||
"moveq %0,%0,lsl #4;"
|
||||
"subeq %1,%1,#4;"
|
||||
"tst %0,#0x0000c000;"
|
||||
"moveq %0,%0,lsl #2;"
|
||||
"subeq %1,%1,#2;"
|
||||
"tst %0,#0x00008000;"
|
||||
"moveq %0,%0,lsl #1;"
|
||||
"subeq %1,%1,#1;"
|
||||
: "+r"(qi),"+r"(qexp)
|
||||
:
|
||||
: "cc");
|
||||
*qip=qi;
|
||||
*qexpp=qexp;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,871 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: packing variable sized words into an octet stream
|
||||
|
||||
************************************************************************/
|
||||
|
||||
/* We're 'LSb' endian; if we write a word but read individual bits,
|
||||
then we'll read the lsb first */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "misc.h"
|
||||
#include "ogg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if !defined(ARM_LITTLE_ENDIAN) || defined(_V_BIT_TEST)
|
||||
static unsigned long mask[]=
|
||||
{0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
|
||||
0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
|
||||
0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
|
||||
0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
|
||||
0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
|
||||
0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
|
||||
0x3fffffff,0x7fffffff,0xffffffff };
|
||||
#endif
|
||||
|
||||
#ifdef ARM_LITTLE_ENDIAN
|
||||
|
||||
#ifdef DEBUGGING_BITWISE
|
||||
extern void oggpack_readinitARM(oggpack_buffer *b,ogg_reference *r);
|
||||
|
||||
void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){
|
||||
oggpack_readinitARM(b,r);
|
||||
//fprintf(stderr, "Init: buffer=(%d,%x,%d,%d) %08x%08x\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord, b->count,
|
||||
// b->ptr[1], b->ptr[0]);
|
||||
//fflush(stderr);
|
||||
}
|
||||
|
||||
extern long oggpack_lookARM(oggpack_buffer *b,int bits);
|
||||
|
||||
long oggpack_look(oggpack_buffer *b,int bits){
|
||||
long l;
|
||||
|
||||
//fprintf(stderr, "PreLook: buffer=(%x,%x,%x) %08x%08x (%d bits)\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord,
|
||||
// b->ptr[1], b->ptr[0], bits);
|
||||
//fflush(stderr);
|
||||
l = oggpack_lookARM(b,bits);
|
||||
//fprintf(stderr, "Look: buffer=(%d,%x,%d,%d) %08x%08x (%d bits) (result=%x)\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord, b->count,
|
||||
// b->ptr[1], b->ptr[0], bits, l);
|
||||
//fflush(stderr);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
extern void oggpack_advARM(oggpack_buffer *b,int bits);
|
||||
|
||||
void oggpack_adv(oggpack_buffer *b,int bits){
|
||||
//fprintf(stderr, "Adv before: buffer=(%x,%x,%x) %08x%08x (%d bits)\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord,
|
||||
// b->ptr[1], b->ptr[0],bits);
|
||||
//fflush(stderr);
|
||||
oggpack_advARM(b,bits);
|
||||
//fprintf(stderr, "Adv: buffer=(%d,%x,%d,%d) %08x%08x\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord, b->count,
|
||||
// b->ptr[1], b->ptr[0]);
|
||||
//fflush(stderr);
|
||||
}
|
||||
|
||||
extern long oggpack_readARM(oggpack_buffer *b,int bits);
|
||||
|
||||
/* bits <= 32 */
|
||||
long oggpack_read(oggpack_buffer *b,int bits){
|
||||
long l;
|
||||
|
||||
//fprintf(stderr, "PreRead: buffer=(%d,%x,%d,%d) %08x%08x (%d bits)\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord, b->count,
|
||||
// b->ptr[1], b->ptr[0], bits);
|
||||
//fflush(stderr);
|
||||
l = oggpack_readARM(b,bits);
|
||||
//fprintf(stderr, "Read: buffer=(%d,%x,%d,%d) %08x%08x (%d bits) (result=%x)\n",
|
||||
// b->bitsLeftInSegment, b->ptr, b->bitsLeftInWord, b->count,
|
||||
// b->ptr[1], b->ptr[0], bits, l);
|
||||
//fflush(stderr);
|
||||
|
||||
return l;
|
||||
}
|
||||
#endif
|
||||
|
||||
int oggpack_eop(oggpack_buffer *b){
|
||||
int ret;
|
||||
if(b->bitsLeftInSegment<0)ret= -1;
|
||||
else ret = 0;
|
||||
//fprintf(stderr, "EOP %d\n", ret);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long oggpack_bytes(oggpack_buffer *b){
|
||||
long ret;
|
||||
if(b->bitsLeftInSegment<0) ret = b->count+b->head->length;
|
||||
else ret = b->count + b->head->length - (b->bitsLeftInSegment)/8;
|
||||
//fprintf(stderr, "count=%d length=%d bitsLeftInSegment=%d\n",
|
||||
// b->count, b->head->length, b->bitsLeftInSegment);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long oggpack_bits(oggpack_buffer *b){
|
||||
long ret;
|
||||
if(b->bitsLeftInSegment<0) ret=(b->count+b->head->length)*8;
|
||||
else ret = b->count*8 + b->head->length*8 - b->bitsLeftInSegment;
|
||||
//fprintf(stderr, "count=%d length=%d bitsLeftInSegment=%d\n",
|
||||
// b->count, b->head->length, b->bitsLeftInSegment);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* spans forward, skipping as many bytes as headend is negative; if
|
||||
headend is zero, simply finds next byte. If we're up to the end
|
||||
of the buffer, leaves headend at zero. If we've read past the end,
|
||||
halt the decode process. */
|
||||
|
||||
static void _span(oggpack_buffer *b){
|
||||
while(b->headend-(b->headbit>>3)<1){
|
||||
b->headend-=b->headbit>>3;
|
||||
b->headbit&=0x7;
|
||||
|
||||
if(b->head && b->head->next){
|
||||
b->count+=b->head->length;
|
||||
b->head=b->head->next;
|
||||
|
||||
if(b->headend+b->head->length>0)
|
||||
b->headptr=b->head->buffer->data+b->head->begin-b->headend;
|
||||
|
||||
b->headend+=b->head->length;
|
||||
}else{
|
||||
/* we've either met the end of decode, or gone past it. halt
|
||||
only if we're past */
|
||||
if(b->headend*8<b->headbit)
|
||||
/* read has fallen off the end */
|
||||
b->headend=-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){
|
||||
memset(b,0,sizeof(*b));
|
||||
|
||||
b->tail=b->head=r;
|
||||
b->count=0;
|
||||
if (b->head && r->length) {
|
||||
b->headptr=b->head->buffer->data+b->head->begin;
|
||||
b->headend=b->head->length;
|
||||
} else {
|
||||
b->headptr=0;
|
||||
b->headend=0;
|
||||
}
|
||||
_span(b);
|
||||
|
||||
//fprintf(stderr,
|
||||
// "Init: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x\n",
|
||||
// b->headbit, b->headptr, b->headend, b->count,
|
||||
// b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
|
||||
// b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0]);
|
||||
//fflush(stderr);
|
||||
}
|
||||
|
||||
#define _lookspan() while(!end){\
|
||||
head=head->next;\
|
||||
if(!head) return -1;\
|
||||
ptr=head->buffer->data + head->begin;\
|
||||
end=head->length;\
|
||||
}
|
||||
|
||||
/* Read in bits without advancing the bitptr; bits <= 32 */
|
||||
long oggpack_look(oggpack_buffer *b,int bits){
|
||||
unsigned long m=mask[bits];
|
||||
unsigned long ret = 0;
|
||||
int BITS = bits;
|
||||
|
||||
if (!b->headptr) return 0;
|
||||
|
||||
bits+=b->headbit;
|
||||
|
||||
if(bits >= b->headend<<3){
|
||||
int end=b->headend;
|
||||
unsigned char *ptr=b->headptr;
|
||||
ogg_reference *head=b->head;
|
||||
|
||||
if(end<0)return 0;
|
||||
if (!head || !end)return 0;
|
||||
|
||||
if(bits){
|
||||
_lookspan();
|
||||
ret=*ptr++>>b->headbit;
|
||||
if(bits>8){
|
||||
--end;
|
||||
_lookspan();
|
||||
ret|=*ptr++<<(8-b->headbit);
|
||||
if(bits>16){
|
||||
--end;
|
||||
_lookspan();
|
||||
ret|=*ptr++<<(16-b->headbit);
|
||||
if(bits>24){
|
||||
--end;
|
||||
_lookspan();
|
||||
ret|=*ptr++<<(24-b->headbit);
|
||||
if(bits>32 && b->headbit){
|
||||
--end;
|
||||
_lookspan();
|
||||
ret|=*ptr<<(32-b->headbit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
/* make this a switch jump-table */
|
||||
ret=b->headptr[0]>>b->headbit;
|
||||
if(bits>8){
|
||||
ret|=b->headptr[1]<<(8-b->headbit);
|
||||
if(bits>16){
|
||||
ret|=b->headptr[2]<<(16-b->headbit);
|
||||
if(bits>24){
|
||||
ret|=b->headptr[3]<<(24-b->headbit);
|
||||
if(bits>32 && b->headbit)
|
||||
ret|=b->headptr[4]<<(32-b->headbit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret&=m;
|
||||
//fprintf(stderr,
|
||||
// "Look: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x (%d bits) return=%x\n",
|
||||
// b->headbit, b->headptr, b->headend, b->count,
|
||||
// b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
|
||||
// b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0],
|
||||
// BITS, ret);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* limited to 32 at a time */
|
||||
void oggpack_adv(oggpack_buffer *b,int bits){
|
||||
int BITS=bits;
|
||||
bits+=b->headbit;
|
||||
b->headbit=bits&7;
|
||||
b->headend-=(bits>>3);
|
||||
b->headptr+=(bits>>3);
|
||||
if(b->headend<1)_span(b);
|
||||
//fprintf(stderr, "Adv: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x (%d bits)\n",
|
||||
// b->headbit, b->headptr, b->headend,b->count,
|
||||
// b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
|
||||
// b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0],
|
||||
// BITS);
|
||||
//fflush(stderr);
|
||||
}
|
||||
|
||||
int oggpack_eop(oggpack_buffer *b){
|
||||
int ret;
|
||||
if(b->headend<0)ret= -1;
|
||||
else ret = 0;
|
||||
//fprintf(stderr, "EOP %d\n", ret);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long oggpack_bytes(oggpack_buffer *b){
|
||||
long ret;
|
||||
if(b->headend<0) ret = b->count+b->head->length;
|
||||
ret = b->count + b->head->length-b->headend + (b->headbit+7)/8;
|
||||
//fprintf(stderr, "Bytes: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x (%d bytes)\n",
|
||||
// b->headbit, b->headptr, b->headend, b->count,
|
||||
// b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
|
||||
// b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0],
|
||||
// ret);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long oggpack_bits(oggpack_buffer *b){
|
||||
long ret;
|
||||
if(b->headend<0) ret = (b->count+b->head->length)*8;
|
||||
else ret = (b->count + b->head->length-b->headend)*8 + b->headbit;
|
||||
//fprintf(stderr, "Bits: buffer=(%x,%x,%x) %02x%02x%02x%02x%02x%02x%02x%02x (%d bits)\n",
|
||||
// b->headbit, b->headptr, b->headend,
|
||||
// b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
|
||||
// b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0],
|
||||
// ret);
|
||||
//fflush(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* bits <= 32 */
|
||||
long oggpack_read(oggpack_buffer *b,int bits){
|
||||
long ret=oggpack_look(b,bits);
|
||||
oggpack_adv(b,bits);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Self test of the bitwise routines; everything else is based on
|
||||
them, so they damned well better be solid. */
|
||||
|
||||
#ifdef _V_BIT_TEST
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "framing.c"
|
||||
|
||||
static int ilog(unsigned long v){
|
||||
int ret=0;
|
||||
while(v){
|
||||
ret++;
|
||||
v>>=1;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
oggpack_buffer r;
|
||||
oggpack_buffer o;
|
||||
ogg_buffer_state *bs;
|
||||
ogg_reference *or;
|
||||
#define TESTWORDS 256
|
||||
|
||||
void report(char *in){
|
||||
fprintf(stderr,"%s",in);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int getbyte(ogg_reference *or,int position){
|
||||
while(or && position>=or->length){
|
||||
position-=or->length;
|
||||
or=or->next;
|
||||
if(or==NULL){
|
||||
fprintf(stderr,"\n\tERROR: getbyte ran off end of buffer.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if((position+or->begin)&1)
|
||||
return (or->buffer->data[(position+or->begin)>>1])&0xff;
|
||||
else
|
||||
return (or->buffer->data[(position+or->begin)>>1]>>8)&0xff;
|
||||
}
|
||||
|
||||
void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
|
||||
long i,bitcount=0;
|
||||
ogg_reference *or=ogg_buffer_alloc(bs,64);
|
||||
for(i=0;i<compsize;i++)
|
||||
or->buffer->data[i]= comp[i];
|
||||
or->length=i;
|
||||
|
||||
oggpack_readinit(&r,or);
|
||||
for(i=0;i<vals;i++){
|
||||
unsigned long test;
|
||||
int tbit=bits?bits:ilog(b[i]);
|
||||
if((test=oggpack_look(&r,tbit))==0xffffffff)
|
||||
report("out of data!\n");
|
||||
if(test!=(b[i]&mask[tbit])){
|
||||
fprintf(stderr,"%ld) %lx %lx\n",i,(b[i]&mask[tbit]),test);
|
||||
report("looked at incorrect value!\n");
|
||||
}
|
||||
if((test=oggpack_read(&r,tbit))==0xffffffff){
|
||||
report("premature end of data when reading!\n");
|
||||
}
|
||||
if(test!=(b[i]&mask[tbit])){
|
||||
fprintf(stderr,"%ld) %lx %lx\n",i,(b[i]&mask[tbit]),test);
|
||||
report("read incorrect value!\n");
|
||||
}
|
||||
bitcount+=tbit;
|
||||
|
||||
if(bitcount!=oggpack_bits(&r))
|
||||
report("wrong number of bits while reading!\n");
|
||||
if((bitcount+7)/8!=oggpack_bytes(&r))
|
||||
report("wrong number of bytes while reading!\n");
|
||||
|
||||
}
|
||||
if(oggpack_bytes(&r)!=(bitcount+7)/8){
|
||||
fprintf(stderr, "%d vs %d\n", oggpack_bytes(&r), (bitcount+7)/8);
|
||||
report("leftover bytes after read!\n");
|
||||
}
|
||||
ogg_buffer_release(or);
|
||||
}
|
||||
|
||||
void _end_verify(int count){
|
||||
int i;
|
||||
|
||||
/* are the proper number of bits left over? */
|
||||
int leftover=count*8-oggpack_bits(&o);
|
||||
if(leftover>7)
|
||||
report("\nERROR: too many bits reported left over.\n");
|
||||
|
||||
/* does reading to exactly byte alignment *not* trip EOF? */
|
||||
if(oggpack_read(&o,leftover)==-1)
|
||||
report("\nERROR: read to but not past exact end tripped EOF.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read to but not past exact end reported bad bitcount.\n");
|
||||
|
||||
/* does EOF trip properly after a single additional bit? */
|
||||
if(oggpack_read(&o,1)!=-1)
|
||||
report("\nERROR: read past exact end did not trip EOF.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read past exact end reported bad bitcount.\n");
|
||||
|
||||
/* does EOF stay set over additional bit reads? */
|
||||
for(i=0;i<=32;i++){
|
||||
if(oggpack_read(&o,i)!=-1)
|
||||
report("\nERROR: EOF did not stay set on stream.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read past exact end reported bad bitcount.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void _end_verify2(int count){
|
||||
int i;
|
||||
|
||||
/* are the proper number of bits left over? */
|
||||
int leftover=count*8-oggpack_bits(&o);
|
||||
if(leftover>7)
|
||||
report("\nERROR: too many bits reported left over.\n");
|
||||
|
||||
/* does reading to exactly byte alignment *not* trip EOF? */
|
||||
oggpack_adv(&o,leftover);
|
||||
#ifdef ARM_LITTLE_ENDIAN
|
||||
if(o.bitsLeftInSegment!=0)
|
||||
#else
|
||||
if(o.headend!=0)
|
||||
#endif
|
||||
report("\nERROR: read to but not past exact end tripped EOF.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read to but not past exact end reported bad bitcount.\n");
|
||||
|
||||
/* does EOF trip properly after a single additional bit? */
|
||||
oggpack_adv(&o,1);
|
||||
#ifdef ARM_LITTLE_ENDIAN
|
||||
if(o.bitsLeftInSegment>=0)
|
||||
#else
|
||||
if(o.headend>=0)
|
||||
#endif
|
||||
report("\nERROR: read past exact end did not trip EOF.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read past exact end reported bad bitcount.\n");
|
||||
|
||||
/* does EOF stay set over additional bit reads? */
|
||||
for(i=0;i<=32;i++){
|
||||
oggpack_adv(&o,i);
|
||||
#ifdef ARM_LITTLE_ENDIAN
|
||||
if(o.bitsLeftInSegment>=0)
|
||||
#else
|
||||
if(o.headend>=0)
|
||||
#endif
|
||||
report("\nERROR: EOF did not stay set on stream.\n");
|
||||
if(oggpack_bits(&o)!=count*8)
|
||||
report("\nERROR: read past exact end reported bad bitcount.\n");
|
||||
}
|
||||
}
|
||||
|
||||
long ogg_buffer_length(ogg_reference *or){
|
||||
int count=0;
|
||||
while(or){
|
||||
count+=or->length;
|
||||
or=or->next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
ogg_reference *ogg_buffer_extend(ogg_reference *or,long bytes){
|
||||
if(or){
|
||||
while(or->next){
|
||||
or=or->next;
|
||||
}
|
||||
or->next=ogg_buffer_alloc(or->buffer->ptr.owner,bytes);
|
||||
return(or->next);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ogg_buffer_posttruncate(ogg_reference *or,long pos){
|
||||
/* walk to the point where we want to begin truncate */
|
||||
while(or && pos>or->length){
|
||||
pos-=or->length;
|
||||
or=or->next;
|
||||
}
|
||||
if(or){
|
||||
ogg_buffer_release(or->next);
|
||||
or->next=0;
|
||||
or->length=pos;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
long i;
|
||||
static unsigned long testbuffer1[]=
|
||||
{18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
|
||||
567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
|
||||
int test1size=43;
|
||||
|
||||
static unsigned long testbuffer2[]=
|
||||
{216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
|
||||
1233432,534,5,346435231,14436467,7869299,76326614,167548585,
|
||||
85525151,0,12321,1,349528352};
|
||||
int test2size=21;
|
||||
|
||||
static unsigned long testbuffer3[]=
|
||||
{1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
|
||||
0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
|
||||
int test3size=56;
|
||||
|
||||
static unsigned long large[]=
|
||||
{2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
|
||||
1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
|
||||
85525151,0,12321,1,2146528352};
|
||||
|
||||
int onesize=33;
|
||||
static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
|
||||
34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
|
||||
223,4};
|
||||
|
||||
int twosize=6;
|
||||
static int two[6]={61,255,255,251,231,29};
|
||||
|
||||
int threesize=54;
|
||||
static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
|
||||
142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
|
||||
58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
|
||||
100,52,4,14,18,86,77,1};
|
||||
|
||||
int foursize=38;
|
||||
static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
|
||||
132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
|
||||
28,2,133,0,1};
|
||||
|
||||
int fivesize=45;
|
||||
static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
|
||||
241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
|
||||
84,75,159,2,1,0,132,192,8,0,0,18,22};
|
||||
|
||||
int sixsize=7;
|
||||
static int six[7]={17,177,170,242,169,19,148};
|
||||
|
||||
/* Test read/write together */
|
||||
/* Later we test against pregenerated bitstreams */
|
||||
bs=ogg_buffer_create();
|
||||
|
||||
fprintf(stderr,"\nSmall preclipped packing (LSb): ");
|
||||
cliptest(testbuffer1,test1size,0,one,onesize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nNull bit call (LSb): ");
|
||||
cliptest(testbuffer3,test3size,0,two,twosize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nLarge preclipped packing (LSb): ");
|
||||
cliptest(testbuffer2,test2size,0,three,threesize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
|
||||
|
||||
or=ogg_buffer_alloc(bs,128);
|
||||
for(i=0;i<test2size;i++){
|
||||
or->buffer->data[i*4] = large[i]&0xff;
|
||||
or->buffer->data[i*4+1] = (large[i]>>8)&0xff;
|
||||
or->buffer->data[i*4+2] = (large[i]>>16)&0xff;
|
||||
or->buffer->data[i*4+3] = (large[i]>>24)&0xff;
|
||||
}
|
||||
or->length=test2size*4;
|
||||
oggpack_readinit(&r,or);
|
||||
for(i=0;i<test2size;i++){
|
||||
unsigned long test;
|
||||
if((test=oggpack_look(&r,32))==0xffffffffUL)report("out of data. failed!");
|
||||
if(test!=large[i]){
|
||||
fprintf(stderr,"%ld != %ld (%lx!=%lx):",test,large[i],
|
||||
test,large[i]);
|
||||
report("read incorrect value!\n");
|
||||
}
|
||||
oggpack_adv(&r,32);
|
||||
}
|
||||
ogg_buffer_release(or);
|
||||
if(oggpack_bytes(&r)!=test2size*4){
|
||||
fprintf(stderr, "%d vs %d\n", oggpack_bytes(&r), test2size*4);
|
||||
report("leftover bytes after read!\n");
|
||||
}
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nSmall unclipped packing (LSb): ");
|
||||
cliptest(testbuffer1,test1size,7,four,foursize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nLarge unclipped packing (LSb): ");
|
||||
cliptest(testbuffer2,test2size,17,five,fivesize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
|
||||
cliptest(testbuffer3,test3size,1,six,sixsize);
|
||||
fprintf(stderr,"ok.");
|
||||
|
||||
fprintf(stderr,"\nTesting read past end (LSb): ");
|
||||
{
|
||||
unsigned char dda[]={0,0,0,0};
|
||||
ogg_buffer lob={dda,8,0,{0}};
|
||||
ogg_reference lor={&lob,0,8,0};
|
||||
|
||||
oggpack_readinit(&r,&lor);
|
||||
for(i=0;i<64;i++){
|
||||
if(oggpack_read(&r,1)<0){
|
||||
fprintf(stderr,"failed; got -1 prematurely.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if(oggpack_look(&r,1)!=-1 ||
|
||||
oggpack_read(&r,1)!=-1){
|
||||
fprintf(stderr,"failed; read past end without -1.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned char dda[]={0,0,0,0};
|
||||
ogg_buffer lob={dda,8,0,{0}};
|
||||
ogg_reference lor={&lob,0,8,0};
|
||||
unsigned long test;
|
||||
|
||||
oggpack_readinit(&r,&lor);
|
||||
if((test=oggpack_read(&r,30))==0xffffffffUL ||
|
||||
(test=oggpack_read(&r,16))==0xffffffffUL){
|
||||
fprintf(stderr,"failed 2; got -1 prematurely.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if((test=oggpack_look(&r,18))==0xffffffffUL){
|
||||
fprintf(stderr,"failed 3; got -1 prematurely.\n");
|
||||
exit(1);
|
||||
}
|
||||
if((test=oggpack_look(&r,19))!=0xffffffffUL){
|
||||
fprintf(stderr,"failed; read past end without -1.\n");
|
||||
exit(1);
|
||||
}
|
||||
if((test=oggpack_look(&r,32))!=0xffffffffUL){
|
||||
fprintf(stderr,"failed; read past end without -1.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"ok.\n");
|
||||
|
||||
/* now the scary shit: randomized testing */
|
||||
|
||||
for(i=0;i<10000;i++){
|
||||
long j,count=0,count2=0,bitcount=0;
|
||||
unsigned long values[TESTWORDS];
|
||||
int len[TESTWORDS];
|
||||
unsigned char flat[4*TESTWORDS]; /* max possible needed size */
|
||||
|
||||
memset(flat,0,sizeof(flat));
|
||||
fprintf(stderr,"\rRandomized testing (LSb)... (%ld) ",10000-i);
|
||||
|
||||
/* generate a list of words and lengths */
|
||||
/* write the required number of bits out to packbuffer */
|
||||
{
|
||||
long word=0;
|
||||
long bit=0;
|
||||
int k;
|
||||
|
||||
for(j=0;j<TESTWORDS;j++){
|
||||
values[j]=rand();
|
||||
len[j]=(rand()%33);
|
||||
|
||||
for(k=0;k<len[j];k++){
|
||||
flat[word] |= ((values[j]>>k)&0x1)<<bit;
|
||||
bit++;
|
||||
bitcount++;
|
||||
if(bit>7){
|
||||
bit=0;
|
||||
word++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
count2=(bitcount+7)>>3;
|
||||
|
||||
/* construct random-length buffer chain from flat vector; random
|
||||
byte starting offset within the length of the vector */
|
||||
{
|
||||
ogg_reference *or=NULL,*orl=NULL;
|
||||
long pos=0;
|
||||
|
||||
/* build buffer chain */
|
||||
while(count2){
|
||||
int ilen=(rand()%32),k;
|
||||
int ibegin=(rand()%32);
|
||||
|
||||
|
||||
if(ilen>count2)ilen=count2;
|
||||
|
||||
if(or)
|
||||
orl=ogg_buffer_extend(orl,64);
|
||||
else
|
||||
or=orl=ogg_buffer_alloc(bs,64);
|
||||
|
||||
orl->length=ilen;
|
||||
orl->begin=ibegin;
|
||||
|
||||
for(k=0;k<ilen;k++)
|
||||
orl->buffer->data[ibegin++]= flat[pos++];
|
||||
|
||||
count2-=ilen;
|
||||
}
|
||||
|
||||
if(ogg_buffer_length(or)!=(bitcount+7)/8){
|
||||
fprintf(stderr,"\nERROR: buffer length incorrect after build.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int begin=0; //=(rand()%TESTWORDS);
|
||||
int ilen=(rand()%(TESTWORDS-begin));
|
||||
int bitoffset,bitcount=0;
|
||||
unsigned long temp;
|
||||
|
||||
for(j=0;j<begin;j++)
|
||||
bitcount+=len[j];
|
||||
or=ogg_buffer_pretruncate(or,bitcount/8);
|
||||
bitoffset=bitcount%=8;
|
||||
for(;j<begin+ilen;j++)
|
||||
bitcount+=len[j];
|
||||
ogg_buffer_posttruncate(or,((bitcount+7)/8));
|
||||
|
||||
if((count=ogg_buffer_length(or))!=(bitcount+7)/8){
|
||||
fprintf(stderr,"\nERROR: buffer length incorrect after truncate.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
oggpack_readinit(&o,or);
|
||||
|
||||
/* verify bit count */
|
||||
if(oggpack_bits(&o)!=0){
|
||||
fprintf(stderr,"\nERROR: Read bitcounter not zero!\n");
|
||||
exit(1);
|
||||
}
|
||||
if(oggpack_bytes(&o)!=0){
|
||||
fprintf(stderr,"\nERROR: Read bytecounter not zero!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
bitcount=bitoffset;
|
||||
oggpack_read(&o,bitoffset);
|
||||
|
||||
/* read and compare to original list */
|
||||
for(j=begin;j<begin+ilen;j++){
|
||||
temp=oggpack_read(&o,len[j]);
|
||||
if(temp==0xffffffffUL){
|
||||
fprintf(stderr,"\nERROR: End of stream too soon! word: %ld,%d\n",
|
||||
j-begin,ilen);
|
||||
exit(1);
|
||||
}
|
||||
if(temp!=(values[j]&mask[len[j]])){
|
||||
fprintf(stderr,"\nERROR: Incorrect read %lx != %lx, word %ld, len %d\n"
|
||||
,
|
||||
values[j]&mask[len[j]],temp,j-begin,len[j]);
|
||||
exit(1);
|
||||
}
|
||||
bitcount+=len[j];
|
||||
if(oggpack_bits(&o)!=bitcount){
|
||||
fprintf(stderr,"\nERROR: Read bitcounter %d != %ld!\n",
|
||||
bitcount,oggpack_bits(&o));
|
||||
exit(1);
|
||||
}
|
||||
if(oggpack_bytes(&o)!=(bitcount+7)/8){
|
||||
fprintf(stderr,"\nERROR: Read bytecounter %d != %ld!\n",
|
||||
(bitcount+7)/8,oggpack_bytes(&o));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
_end_verify(count);
|
||||
|
||||
/* look/adv version */
|
||||
oggpack_readinit(&o,or);
|
||||
bitcount=bitoffset;
|
||||
oggpack_adv(&o,bitoffset);
|
||||
|
||||
/* read and compare to original list */
|
||||
for(j=begin;j<begin+ilen;j++){
|
||||
temp=oggpack_look(&o,len[j]);
|
||||
|
||||
if(temp==0xffffffffUL){
|
||||
fprintf(stderr,"\nERROR: End of stream too soon! word: %ld\n",
|
||||
j-begin);
|
||||
exit(1);
|
||||
}
|
||||
if(temp!=(values[j]&mask[len[j]])){
|
||||
fprintf(stderr,"\nERROR: Incorrect look %lx != %lx, word %ld, len %d\n"
|
||||
,
|
||||
values[j]&mask[len[j]],temp,j-begin,len[j]);
|
||||
exit(1);
|
||||
}
|
||||
oggpack_adv(&o,len[j]);
|
||||
bitcount+=len[j];
|
||||
if(oggpack_bits(&o)!=bitcount){
|
||||
fprintf(stderr,"\nERROR: Look/Adv bitcounter %d != %ld!\n",
|
||||
bitcount,oggpack_bits(&o));
|
||||
exit(1);
|
||||
}
|
||||
if(oggpack_bytes(&o)!=(bitcount+7)/8){
|
||||
fprintf(stderr,"\nERROR: Look/Adv bytecounter %d != %ld!\n",
|
||||
(bitcount+7)/8,oggpack_bytes(&o));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
_end_verify2(count);
|
||||
|
||||
}
|
||||
ogg_buffer_release(or);
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"\rRandomized testing (LSb)... ok. \n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
int WinMain(void){
|
||||
return main();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,399 @@
|
|||
@ Tremolo library
|
||||
@-----------------------------------------------------------------------
|
||||
@ Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
@ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
@ All rights reserved.
|
||||
|
||||
@ Redistribution and use in source and binary forms, with or without
|
||||
@ modification, are permitted provided that the following conditions
|
||||
@ are met:
|
||||
|
||||
@ * Redistributions of source code must retain the above copyright
|
||||
@ notice, this list of conditions and the following disclaimer.
|
||||
@ * Redistributions in binary form must reproduce the above
|
||||
@ copyright notice, this list of conditions and the following disclaimer
|
||||
@ in the documentation and/or other materials provided with the
|
||||
@ distribution.
|
||||
@ * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
@ Productions Ltd nor the names of its contributors may be used to
|
||||
@ endorse or promote products derived from this software without
|
||||
@ specific prior written permission.
|
||||
@
|
||||
@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
@ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
@ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@ ----------------------------------------------------------------------
|
||||
|
||||
.text
|
||||
|
||||
.global oggpack_look
|
||||
.global oggpack_adv
|
||||
.global oggpack_readinit
|
||||
.global oggpack_read
|
||||
|
||||
oggpack_look:
|
||||
@ r0 = oggpack_buffer *b
|
||||
@ r1 = int bits
|
||||
STMFD r13!,{r10,r11,r14}
|
||||
LDMIA r0,{r2,r3,r12}
|
||||
@ r2 = bitsLeftInSegment
|
||||
@ r3 = ptr
|
||||
@ r12= bitsLeftInWord
|
||||
SUBS r2,r2,r1 @ bitsLeftinSegment -= bits
|
||||
BLT look_slow @ Not enough bits in this segment for
|
||||
@ this request. Do it slowly.
|
||||
LDR r10,[r3] @ r10= ptr[0]
|
||||
RSB r14,r12,#32 @ r14= 32-bitsLeftInWord
|
||||
SUBS r12,r12,r1 @ r12= bitsLeftInWord -= bits
|
||||
LDRLT r11,[r3,#4]! @ r11= ptr[1]
|
||||
MOV r10,r10,LSR r14 @ r10= ptr[0]>>(32-bitsLeftInWord)
|
||||
ADDLE r12,r12,#32 @ r12= bitsLeftInWord += 32
|
||||
RSB r14,r14,#32 @ r14= 32-bitsLeftInWord
|
||||
ORRLT r10,r10,r11,LSL r14 @ r10= Next 32 bits.
|
||||
MOV r14,#1
|
||||
RSB r14,r14,r14,LSL r1
|
||||
AND r0,r10,r14
|
||||
LDMFD r13!,{r10,r11,PC}
|
||||
|
||||
look_slow:
|
||||
STMFD r13!,{r5,r6}
|
||||
ADDS r10,r2,r1 @ r10= bitsLeftInSegment + bits (i.e.
|
||||
@ the initial value of bitsLeftInSeg)
|
||||
@ r10 = bitsLeftInSegment (initial)
|
||||
@ r12 = bitsLeftInWord
|
||||
RSB r14,r12,#32 @ r14= 32-bitsLeftInWord
|
||||
MOV r5,r10 @ r5 = bitsLeftInSegment (initial)
|
||||
BLT look_overrun
|
||||
BEQ look_next_segment @ r10= r12 = 0, if we branch
|
||||
CMP r12,r10 @ If bitsLeftInWord < bitsLeftInSeg
|
||||
@ there must be more in the next word
|
||||
LDR r10,[r3],#4 @ r10= ptr[0]
|
||||
LDRLT r6,[r3] @ r6 = ptr[1]
|
||||
MOV r11,#1
|
||||
MOV r10,r10,LSR r14 @ r10= first bitsLeftInWord bits
|
||||
ORRLT r10,r10,r6,LSL r12 @ r10= first bitsLeftInSeg bits+crap
|
||||
RSB r11,r11,r11,LSL r5 @ r11= mask
|
||||
AND r10,r10,r11 @ r10= first r5 bits
|
||||
@ Load the next segments data
|
||||
look_next_segment:
|
||||
@ At this point, r10 contains the first r5 bits of the result
|
||||
LDR r11,[r0,#12] @ r11= head = b->head
|
||||
@ Stall
|
||||
@ Stall
|
||||
look_next_segment_2:
|
||||
LDR r11,[r11,#12] @ r11= head = head->next
|
||||
@ Stall
|
||||
@ Stall
|
||||
CMP r11,#0
|
||||
BEQ look_out_of_data
|
||||
LDMIA r11,{r6,r12,r14} @ r6 = buffer
|
||||
@ r12= begin
|
||||
@ r14= length
|
||||
LDR r6,[r6] @ r6 = buffer->data
|
||||
CMP r14,#0
|
||||
BEQ look_next_segment_2
|
||||
ADD r6,r6,r12 @ r6 = buffer->data+begin
|
||||
look_slow_loop:
|
||||
LDRB r12,[r6],#1 @ r12= *buffer
|
||||
SUBS r14,r14,#1 @ r14= length
|
||||
@ Stall
|
||||
ORR r10,r10,r12,LSL r5 @ r10= first r5+8 bits
|
||||
ADD r5,r5,#8
|
||||
BLE look_really_slow
|
||||
CMP r5,r1
|
||||
BLT look_slow_loop
|
||||
MOV r14,#1
|
||||
RSB r14,r14,r14,LSL r1
|
||||
AND r0,r10,r14
|
||||
LDMFD r13!,{r5,r6,r10,r11,PC}
|
||||
|
||||
|
||||
look_really_slow:
|
||||
CMP r5,r1
|
||||
BLT look_next_segment_2
|
||||
MOV r14,#1
|
||||
RSB r14,r14,r14,LSL r1
|
||||
AND r0,r10,r14
|
||||
LDMFD r13!,{r5,r6,r10,r11,PC}
|
||||
|
||||
look_out_of_data:
|
||||
@MVN r0,#0 ; return -1
|
||||
MOV r0,#0
|
||||
LDMFD r13!,{r5,r6,r10,r11,PC}
|
||||
|
||||
look_overrun:
|
||||
@ We had overrun when we started, so we need to skip -r10 bits.
|
||||
LDR r11,[r0,#12] @ r11 = head = b->head
|
||||
@ stall
|
||||
@ stall
|
||||
look_overrun_next_segment:
|
||||
LDR r11,[r11,#12] @ r11 = head->next
|
||||
@ stall
|
||||
@ stall
|
||||
CMP r11,#0
|
||||
BEQ look_out_of_data
|
||||
LDMIA r11,{r6,r7,r14} @ r6 = buffer
|
||||
@ r7 = begin
|
||||
@ r14= length
|
||||
LDR r6,[r6] @ r6 = buffer->data
|
||||
@ stall
|
||||
@ stall
|
||||
ADD r6,r6,r7 @ r6 = buffer->data+begin
|
||||
MOV r14,r14,LSL #3 @ r14= length in bits
|
||||
ADDS r14,r14,r10 @ r14= length in bits-bits to skip
|
||||
MOVLE r10,r14
|
||||
BLE look_overrun_next_segment
|
||||
RSB r10,r10,#0 @ r10= bits to skip
|
||||
ADD r6,r10,r10,LSR #3 @ r6 = pointer to data
|
||||
MOV r10,#0
|
||||
B look_slow_loop
|
||||
|
||||
oggpack_adv:
|
||||
@ r0 = oggpack_buffer *b
|
||||
@ r1 = bits
|
||||
LDMIA r0,{r2,r3,r12}
|
||||
@ r2 = bitsLeftInSegment
|
||||
@ r3 = ptr
|
||||
@ r12= bitsLeftInWord
|
||||
SUBS r2,r2,r1 @ Does this run us out of bits in the
|
||||
BLE adv_slow @ segment? If so, do it slowly
|
||||
SUBS r12,r12,r1
|
||||
ADDLE r12,r12,#32
|
||||
ADDLE r3,r3,#4
|
||||
STMIA r0,{r2,r3,r12}
|
||||
BX LR
|
||||
adv_slow:
|
||||
STMFD r13!,{r10,r14}
|
||||
|
||||
LDR r14,[r0,#12] @ r14= head
|
||||
@ stall
|
||||
adv_slow_loop:
|
||||
LDR r1,[r0,#20] @ r1 = count
|
||||
LDR r10,[r14,#8] @ r10= head->length
|
||||
LDR r14,[r14,#12] @ r14= head->next
|
||||
@ stall
|
||||
ADD r1,r1,r10 @ r1 = count += head->length
|
||||
CMP r14,#0
|
||||
BEQ adv_end
|
||||
STR r1,[r0,#20] @ b->count = count
|
||||
STR r14,[r0,#12] @ b->head = head
|
||||
LDMIA r14,{r3,r10,r12} @ r3 = buffer
|
||||
@ r10= begin
|
||||
@ r12= length
|
||||
LDR r3,[r3] @ r3 = buffer->data
|
||||
ADD r3,r3,r10 @ r3 = Pointer to start (byte)
|
||||
AND r10,r3,#3 @ r10= bytes to backtrk to word align
|
||||
MOV r10,r10,LSL #3 @ r10= bits to backtrk to word align
|
||||
RSB r10,r10,#32 @ r10= bits left in word
|
||||
ADDS r10,r10,r2 @ r10= bits left in word after skip
|
||||
ADDLE r10,r10,#32
|
||||
ADDLE r3,r3,#4
|
||||
BIC r3,r3,#3 @ r3 = Pointer to start (word)
|
||||
ADDS r2,r2,r12,LSL #3 @ r2 = length in bits after advance
|
||||
BLE adv_slow_loop
|
||||
STMIA r0,{r2,r3,r10}
|
||||
|
||||
LDMFD r13!,{r10,PC}
|
||||
adv_end:
|
||||
MOV r2, #0
|
||||
MOV r12,#0
|
||||
STMIA r0,{r2,r3,r12}
|
||||
|
||||
LDMFD r13!,{r10,PC}
|
||||
|
||||
oggpack_readinit:
|
||||
@ r0 = oggpack_buffer *b
|
||||
@ r1 = oggreference *r
|
||||
STR r1,[r0,#12] @ b->head = r1
|
||||
STR r1,[r0,#16] @ b->tail = r1
|
||||
LDMIA r1,{r2,r3,r12} @ r2 = b->head->buffer
|
||||
@ r3 = b->head->begin
|
||||
@ r12= b->head->length
|
||||
LDR r2,[r2] @ r2 = b->head->buffer->data
|
||||
MOV r1,r12,LSL #3 @ r1 = BitsInSegment
|
||||
MOV r12,#0
|
||||
ADD r3,r2,r3 @ r3 = r2+b->head->begin
|
||||
BIC r2,r3,#3 @ r2 = b->headptr (word)
|
||||
AND r3,r3,#3
|
||||
MOV r3,r3,LSL #3
|
||||
RSB r3,r3,#32 @ r3 = BitsInWord
|
||||
STMIA r0,{r1,r2,r3}
|
||||
STR r12,[r0,#20]
|
||||
BX LR
|
||||
|
||||
oggpack_read:
|
||||
@ r0 = oggpack_buffer *b
|
||||
@ r1 = int bits
|
||||
STMFD r13!,{r10,r11,r14}
|
||||
LDMIA r0,{r2,r3,r12}
|
||||
@ r2 = bitsLeftInSegment
|
||||
@ r3 = ptr
|
||||
@ r12= bitsLeftInWord
|
||||
SUBS r2,r2,r1 @ bitsLeftinSegment -= bits
|
||||
BLT read_slow @ Not enough bits in this segment for
|
||||
@ this request. Do it slowly.
|
||||
LDR r10,[r3] @ r10= ptr[0]
|
||||
RSB r14,r12,#32 @ r14= 32-bitsLeftInWord
|
||||
SUBS r12,r12,r1 @ r12= bitsLeftInWord -= bits
|
||||
ADDLE r3,r3,#4
|
||||
LDRLT r11,[r3] @ r11= ptr[1]
|
||||
MOV r10,r10,LSR r14 @ r10= ptr[0]>>(32-bitsLeftInWord)
|
||||
ADDLE r12,r12,#32 @ r12= bitsLeftInWord += 32
|
||||
RSB r14,r14,#32 @ r14= 32-bitsLeftInWord
|
||||
ORRLT r10,r10,r11,LSL r14 @ r10= Next 32 bits.
|
||||
STMIA r0,{r2,r3,r12}
|
||||
MOV r14,#1
|
||||
RSB r14,r14,r14,LSL r1
|
||||
AND r0,r10,r14
|
||||
LDMFD r13!,{r10,r11,PC}
|
||||
|
||||
read_slow:
|
||||
STMFD r13!,{r5,r6}
|
||||
ADDS r10,r2,r1 @ r10= bitsLeftInSegment + bits (i.e.
|
||||
@ the initial value of bitsLeftInSeg)
|
||||
@ r10 = bitsLeftInSegment (initial)
|
||||
@ r12 = bitsLeftInWord
|
||||
RSB r14,r12,#32 @ r14= 32-bitsLeftInWord
|
||||
MOV r5,r10 @ r5 = bitsLeftInSegment (initial)
|
||||
BLT read_overrun
|
||||
BEQ read_next_segment @ r10= r12 = 0, if we branch
|
||||
CMP r12,r10 @ If bitsLeftInWord < bitsLeftInSeg
|
||||
@ there must be more in the next word
|
||||
LDR r10,[r3],#4 @ r10= ptr[0]
|
||||
LDRLT r6,[r3] @ r6 = ptr[1]
|
||||
MOV r11,#1
|
||||
MOV r10,r10,LSR r14 @ r10= first bitsLeftInWord bits
|
||||
ORRLT r10,r10,r6,LSL r12 @ r10= first bitsLeftInSeg bits+crap
|
||||
RSB r11,r11,r11,LSL r5 @ r11= mask
|
||||
AND r10,r10,r11 @ r10= first r5 bits
|
||||
@ Load the next segments data
|
||||
read_next_segment:
|
||||
@ At this point, r10 contains the first r5 bits of the result
|
||||
LDR r11,[r0,#12] @ r11= head = b->head
|
||||
@ Stall
|
||||
read_next_segment_2:
|
||||
@ r11 = head
|
||||
LDR r6,[r0,#20] @ r6 = count
|
||||
LDR r12,[r11,#8] @ r12= length
|
||||
LDR r11,[r11,#12] @ r11= head = head->next
|
||||
@ Stall
|
||||
ADD r6,r6,r12 @ count += length
|
||||
CMP r11,#0
|
||||
BEQ read_out_of_data
|
||||
STR r11,[r0,#12]
|
||||
STR r6,[r0,#20] @ b->count = count
|
||||
LDMIA r11,{r6,r12,r14} @ r6 = buffer
|
||||
@ r12= begin
|
||||
@ r14= length
|
||||
LDR r6,[r6] @ r6 = buffer->data
|
||||
CMP r14,#0
|
||||
BEQ read_next_segment_2
|
||||
ADD r6,r6,r12 @ r6 = buffer->data+begin
|
||||
read_slow_loop:
|
||||
LDRB r12,[r6],#1 @ r12= *buffer
|
||||
SUBS r14,r14,#1 @ r14= length
|
||||
@ Stall
|
||||
ORR r10,r10,r12,LSL r5 @ r10= first r5+8 bits
|
||||
ADD r5,r5,#8
|
||||
BLE read_really_slow
|
||||
CMP r5,r1
|
||||
BLT read_slow_loop
|
||||
read_end:
|
||||
MOV r12,#1
|
||||
RSB r12,r12,r12,LSL r1
|
||||
|
||||
@ Store back the new position
|
||||
@ r2 = -number of bits to go from this segment
|
||||
@ r6 = ptr
|
||||
@ r14= bytesLeftInSegment
|
||||
@ r11= New head value
|
||||
LDMIA r11,{r3,r6,r14} @ r3 = buffer
|
||||
@ r6 = begin
|
||||
@ r14= length
|
||||
LDR r3,[r3] @ r3 = buffer->data
|
||||
ADD r1,r2,r14,LSL #3 @ r1 = bitsLeftInSegment
|
||||
@ stall
|
||||
ADD r6,r3,r6 @ r6 = pointer
|
||||
AND r3,r6,#3 @ r3 = bytes used in first word
|
||||
RSB r3,r2,r3,LSL #3 @ r3 = bits used in first word
|
||||
BIC r2,r6,#3 @ r2 = word ptr
|
||||
RSBS r3,r3,#32 @ r3 = bitsLeftInWord
|
||||
ADDLE r3,r3,#32
|
||||
ADDLE r2,r2,#4
|
||||
STMIA r0,{r1,r2,r3}
|
||||
|
||||
AND r0,r10,r12
|
||||
LDMFD r13!,{r5,r6,r10,r11,PC}
|
||||
|
||||
|
||||
read_really_slow:
|
||||
CMP r5,r1
|
||||
BGE read_end
|
||||
LDR r14,[r11,#8] @ r14= length of segment just done
|
||||
@ stall
|
||||
@ stall
|
||||
ADD r2,r2,r14,LSL #3 @ r2 = -bits to use from next seg
|
||||
B read_next_segment_2
|
||||
|
||||
read_out_of_data:
|
||||
@ Store back the new position
|
||||
@ r2 = -number of bits to go from this segment
|
||||
@ r6 = ptr
|
||||
@ r14= bytesLeftInSegment
|
||||
@ RJW: This may be overkill - we leave the buffer empty, with -1
|
||||
@ bits left in it. We might get away with just storing the
|
||||
@ bitsLeftInSegment as -1.
|
||||
LDR r11,[r0,#12] @ r11=head
|
||||
|
||||
LDMIA r11,{r3,r6,r14} @ r3 = buffer
|
||||
@ r6 = begin
|
||||
@ r14= length
|
||||
LDR r3,[r3] @ r3 = buffer->data
|
||||
ADD r6,r3,r6 @ r6 = pointer
|
||||
ADD r6,r6,r14
|
||||
AND r3,r6,#3 @ r3 = bytes used in first word
|
||||
MOV r3,r3,LSL #3 @ r3 = bits used in first word
|
||||
BIC r2,r6,#3 @ r2 = word ptr
|
||||
RSBS r3,r3,#32 @ r3 = bitsLeftInWord
|
||||
MVN r1,#0 @ r1 = -1 = bitsLeftInSegment
|
||||
STMIA r0,{r1,r2,r3}
|
||||
@MVN r0,#0 ; return -1
|
||||
MOV r0,#0
|
||||
LDMFD r13!,{r5,r6,r10,r11,PC}
|
||||
|
||||
read_overrun:
|
||||
@ We had overrun when we started, so we need to skip -r10 bits.
|
||||
LDR r11,[r0,#12] @ r11 = head = b->head
|
||||
@ stall
|
||||
@ stall
|
||||
read_overrun_next_segment:
|
||||
LDR r11,[r11,#12] @ r11 = head->next
|
||||
@ stall
|
||||
@ stall
|
||||
CMP r11,#0
|
||||
BEQ read_out_of_data
|
||||
LDMIA r11,{r6,r7,r14} @ r6 = buffer
|
||||
@ r7 = begin
|
||||
@ r14= length
|
||||
LDR r6,[r6] @ r6 = buffer->data
|
||||
@ stall
|
||||
@ stall
|
||||
ADD r6,r6,r7 @ r6 = buffer->data+begin
|
||||
MOV r14,r14,LSL #3 @ r14= length in bits
|
||||
ADDS r14,r14,r10 @ r14= length in bits-bits to skip
|
||||
MOVLE r10,r14
|
||||
BLE read_overrun_next_segment
|
||||
RSB r10,r10,#0 @ r10= bits to skip
|
||||
ADD r6,r10,r10,LSR #3 @ r6 = pointer to data
|
||||
MOV r10,#0
|
||||
B read_slow_loop
|
||||
|
||||
@ END
|
||||
|
|
@ -0,0 +1,920 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: basic codebook pack/unpack/code/decode operations
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
// #include <log/log.h>
|
||||
#include "ogg.h"
|
||||
#include "ivorbiscodec.h"
|
||||
#include "codebook.h"
|
||||
#include "misc.h"
|
||||
#include "os.h"
|
||||
|
||||
#define MARKER_SIZE 33
|
||||
|
||||
/**** pack/unpack helpers ******************************************/
|
||||
int _ilog(unsigned int v){
|
||||
int ret=0;
|
||||
while(v){
|
||||
ret++;
|
||||
v>>=1;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static ogg_uint32_t decpack(long entry,long used_entry,long quantvals,
|
||||
codebook *b,oggpack_buffer *opb,int maptype){
|
||||
ogg_uint32_t ret=0;
|
||||
int j;
|
||||
|
||||
switch(b->dec_type){
|
||||
|
||||
case 0:
|
||||
return (ogg_uint32_t)entry;
|
||||
|
||||
case 1:
|
||||
if(maptype==1){
|
||||
/* vals are already read into temporary column vector here */
|
||||
for(j=0;j<b->dim;j++){
|
||||
ogg_uint32_t off=entry%quantvals;
|
||||
entry/=quantvals;
|
||||
ret|=((ogg_uint16_t *)(b->q_val))[off]<<(b->q_bits*j);
|
||||
}
|
||||
}else{
|
||||
for(j=0;j<b->dim;j++)
|
||||
ret|=oggpack_read(opb,b->q_bits)<<(b->q_bits*j);
|
||||
}
|
||||
return ret;
|
||||
|
||||
case 2:
|
||||
for(j=0;j<b->dim;j++){
|
||||
ogg_uint32_t off=entry%quantvals;
|
||||
entry/=quantvals;
|
||||
ret|=off<<(b->q_pack*j);
|
||||
}
|
||||
return ret;
|
||||
|
||||
case 3:
|
||||
return (ogg_uint32_t)used_entry;
|
||||
|
||||
}
|
||||
return 0; /* silence compiler */
|
||||
}
|
||||
|
||||
/* 32 bit float (not IEEE; nonnormalized mantissa +
|
||||
biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm
|
||||
Why not IEEE? It's just not that important here. */
|
||||
|
||||
static ogg_int32_t _float32_unpack(long val,int *point){
|
||||
long mant=val&0x1fffff;
|
||||
int sign=val&0x80000000;
|
||||
|
||||
*point=((val&0x7fe00000L)>>21)-788;
|
||||
|
||||
if(mant){
|
||||
while(!(mant&0x40000000)){
|
||||
mant<<=1;
|
||||
*point-=1;
|
||||
}
|
||||
if(sign)mant= -mant;
|
||||
}else{
|
||||
*point=-9999;
|
||||
}
|
||||
return mant;
|
||||
}
|
||||
|
||||
/* choose the smallest supported node size that fits our decode table.
|
||||
Legal bytewidths are 1/1 1/2 2/2 2/4 4/4 */
|
||||
static int _determine_node_bytes(long used, int leafwidth){
|
||||
|
||||
/* special case small books to size 4 to avoid multiple special
|
||||
cases in repack */
|
||||
if(used<2)
|
||||
return 4;
|
||||
|
||||
if(leafwidth==3)leafwidth=4;
|
||||
if(_ilog(3*used-6)+1 <= leafwidth*4)
|
||||
return leafwidth/2?leafwidth/2:1;
|
||||
return leafwidth;
|
||||
}
|
||||
|
||||
/* convenience/clarity; leaves are specified as multiple of node word
|
||||
size (1 or 2) */
|
||||
static int _determine_leaf_words(int nodeb, int leafwidth){
|
||||
if(leafwidth>nodeb)return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* given a list of word lengths, number of used entries, and byte
|
||||
width of a leaf, generate the decode table */
|
||||
static int _make_words(char *l,long n,ogg_uint32_t *r,long quantvals,
|
||||
codebook *b, oggpack_buffer *opb,int maptype){
|
||||
long i,j,count=0;
|
||||
long top=0;
|
||||
ogg_uint32_t marker[MARKER_SIZE];
|
||||
|
||||
if (n<1)
|
||||
return 1;
|
||||
|
||||
if(n<2){
|
||||
r[0]=0x80000000;
|
||||
}else{
|
||||
memset(marker,0,sizeof(marker));
|
||||
|
||||
for(i=0;i<n;i++){
|
||||
long length=l[i];
|
||||
if(length){
|
||||
if (length < 0 || length >= MARKER_SIZE) {
|
||||
//cjh ALOGE("b/23881715");
|
||||
return 1;
|
||||
}
|
||||
ogg_uint32_t entry=marker[length];
|
||||
long chase=0;
|
||||
if(count && !entry)return -1; /* overpopulated tree! */
|
||||
|
||||
/* chase the tree as far as it's already populated, fill in past */
|
||||
for(j=0;j<length-1;j++){
|
||||
int bit=(entry>>(length-j-1))&1;
|
||||
if(chase>=top){
|
||||
if (chase < 0 || chase >= n) return 1;
|
||||
top++;
|
||||
r[chase*2]=top;
|
||||
r[chase*2+1]=0;
|
||||
}else
|
||||
if (chase < 0 || chase >= n || chase*2+bit > n*2+1) return 1;
|
||||
if(!r[chase*2+bit])
|
||||
r[chase*2+bit]=top;
|
||||
chase=r[chase*2+bit];
|
||||
if (chase < 0 || chase >= n) return 1;
|
||||
}
|
||||
{
|
||||
int bit=(entry>>(length-j-1))&1;
|
||||
if(chase>=top){
|
||||
top++;
|
||||
r[chase*2+1]=0;
|
||||
}
|
||||
r[chase*2+bit]= decpack(i,count++,quantvals,b,opb,maptype) |
|
||||
0x80000000;
|
||||
}
|
||||
|
||||
/* Look to see if the next shorter marker points to the node
|
||||
above. if so, update it and repeat. */
|
||||
for(j=length;j>0;j--){
|
||||
if(marker[j]&1){
|
||||
marker[j]=marker[j-1]<<1;
|
||||
break;
|
||||
}
|
||||
marker[j]++;
|
||||
}
|
||||
|
||||
/* prune the tree; the implicit invariant says all the longer
|
||||
markers were dangling from our just-taken node. Dangle them
|
||||
from our *new* node. */
|
||||
for(j=length+1;j<MARKER_SIZE;j++)
|
||||
if((marker[j]>>1) == entry){
|
||||
entry=marker[j];
|
||||
marker[j]=marker[j-1]<<1;
|
||||
}else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// following sanity check copied from libvorbis
|
||||
/* sanity check the huffman tree; an underpopulated tree must be
|
||||
rejected. The only exception is the one-node pseudo-nil tree,
|
||||
which appears to be underpopulated because the tree doesn't
|
||||
really exist; there's only one possible 'codeword' or zero bits,
|
||||
but the above tree-gen code doesn't mark that. */
|
||||
if(b->used_entries != 1){
|
||||
for(i=1;i<MARKER_SIZE;i++)
|
||||
if(marker[i] & (0xffffffffUL>>(32-i))){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _make_decode_table(codebook *s,char *lengthlist,long quantvals,
|
||||
oggpack_buffer *opb,int maptype){
|
||||
int i;
|
||||
ogg_uint32_t *work;
|
||||
|
||||
if (!lengthlist) return 1;
|
||||
if(s->dec_nodeb==4){
|
||||
/* Over-allocate by using s->entries instead of used_entries.
|
||||
* This means that we can use s->entries to enforce size in
|
||||
* _make_words without messing up length list looping.
|
||||
* This probably wastes a bit of space, but it shouldn't
|
||||
* impact behavior or size too much.
|
||||
*/
|
||||
s->dec_table=_ogg_malloc((s->entries*2+1)*sizeof(*work));
|
||||
if (!s->dec_table) return 1;
|
||||
/* +1 (rather than -2) is to accommodate 0 and 1 sized books,
|
||||
which are specialcased to nodeb==4 */
|
||||
if(_make_words(lengthlist,s->entries,
|
||||
s->dec_table,quantvals,s,opb,maptype))return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s->used_entries > INT_MAX/2 ||
|
||||
s->used_entries*2 > INT_MAX/((long) sizeof(*work)) - 1) return 1;
|
||||
/* Overallocate as above */
|
||||
work=calloc((s->entries*2+1),sizeof(*work));
|
||||
if (!work) return 1;
|
||||
if(_make_words(lengthlist,s->entries,work,quantvals,s,opb,maptype)) goto error_out;
|
||||
if (s->used_entries > INT_MAX/(s->dec_leafw+1)) goto error_out;
|
||||
if (s->dec_nodeb && s->used_entries * (s->dec_leafw+1) > INT_MAX/s->dec_nodeb) goto error_out;
|
||||
s->dec_table=_ogg_malloc((s->used_entries*(s->dec_leafw+1)-2)*
|
||||
s->dec_nodeb);
|
||||
if (!s->dec_table) goto error_out;
|
||||
|
||||
if(s->dec_leafw==1){
|
||||
switch(s->dec_nodeb){
|
||||
case 1:
|
||||
for(i=0;i<s->used_entries*2-2;i++)
|
||||
((unsigned char *)s->dec_table)[i]=(unsigned char)
|
||||
(((work[i] & 0x80000000UL) >> 24) | work[i]);
|
||||
break;
|
||||
case 2:
|
||||
for(i=0;i<s->used_entries*2-2;i++)
|
||||
((ogg_uint16_t *)s->dec_table)[i]=(ogg_uint16_t)
|
||||
(((work[i] & 0x80000000UL) >> 16) | work[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
}else{
|
||||
/* more complex; we have to do a two-pass repack that updates the
|
||||
node indexing. */
|
||||
long top=s->used_entries*3-2;
|
||||
if(s->dec_nodeb==1){
|
||||
unsigned char *out=(unsigned char *)s->dec_table;
|
||||
|
||||
for(i=s->used_entries*2-4;i>=0;i-=2){
|
||||
if(work[i]&0x80000000UL){
|
||||
if(work[i+1]&0x80000000UL){
|
||||
top-=4;
|
||||
out[top]=(work[i]>>8 & 0x7f)|0x80;
|
||||
out[top+1]=(work[i+1]>>8 & 0x7f)|0x80;
|
||||
out[top+2]=work[i] & 0xff;
|
||||
out[top+3]=work[i+1] & 0xff;
|
||||
}else{
|
||||
top-=3;
|
||||
out[top]=(work[i]>>8 & 0x7f)|0x80;
|
||||
out[top+1]=work[work[i+1]*2];
|
||||
out[top+2]=work[i] & 0xff;
|
||||
}
|
||||
}else{
|
||||
if(work[i+1]&0x80000000UL){
|
||||
top-=3;
|
||||
out[top]=work[work[i]*2];
|
||||
out[top+1]=(work[i+1]>>8 & 0x7f)|0x80;
|
||||
out[top+2]=work[i+1] & 0xff;
|
||||
}else{
|
||||
top-=2;
|
||||
out[top]=work[work[i]*2];
|
||||
out[top+1]=work[work[i+1]*2];
|
||||
}
|
||||
}
|
||||
work[i]=top;
|
||||
}
|
||||
}else{
|
||||
ogg_uint16_t *out=(ogg_uint16_t *)s->dec_table;
|
||||
for(i=s->used_entries*2-4;i>=0;i-=2){
|
||||
if(work[i]&0x80000000UL){
|
||||
if(work[i+1]&0x80000000UL){
|
||||
top-=4;
|
||||
out[top]=(work[i]>>16 & 0x7fff)|0x8000;
|
||||
out[top+1]=(work[i+1]>>16 & 0x7fff)|0x8000;
|
||||
out[top+2]=work[i] & 0xffff;
|
||||
out[top+3]=work[i+1] & 0xffff;
|
||||
}else{
|
||||
top-=3;
|
||||
out[top]=(work[i]>>16 & 0x7fff)|0x8000;
|
||||
out[top+1]=work[work[i+1]*2];
|
||||
out[top+2]=work[i] & 0xffff;
|
||||
}
|
||||
}else{
|
||||
if(work[i+1]&0x80000000UL){
|
||||
top-=3;
|
||||
out[top]=work[work[i]*2];
|
||||
out[top+1]=(work[i+1]>>16 & 0x7fff)|0x8000;
|
||||
out[top+2]=work[i+1] & 0xffff;
|
||||
}else{
|
||||
top-=2;
|
||||
out[top]=work[work[i]*2];
|
||||
out[top+1]=work[work[i+1]*2];
|
||||
}
|
||||
}
|
||||
work[i]=top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(work);
|
||||
return 0;
|
||||
error_out:
|
||||
free(work);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* most of the time, entries%dimensions == 0, but we need to be
|
||||
well defined. We define that the possible vales at each
|
||||
scalar is values == entries/dim. If entries%dim != 0, we'll
|
||||
have 'too few' values (values*dim<entries), which means that
|
||||
we'll have 'left over' entries; left over entries use zeroed
|
||||
values (and are wasted). So don't generate codebooks like
|
||||
that */
|
||||
/* there might be a straightforward one-line way to do the below
|
||||
that's portable and totally safe against roundoff, but I haven't
|
||||
thought of it. Therefore, we opt on the side of caution */
|
||||
long _book_maptype1_quantvals(codebook *b){
|
||||
/* get us a starting hint, we'll polish it below */
|
||||
int bits=_ilog(b->entries);
|
||||
int vals=b->entries>>((bits-1)*(b->dim-1)/b->dim);
|
||||
|
||||
while(1){
|
||||
long acc=1;
|
||||
long acc1=1;
|
||||
int i;
|
||||
for(i=0;i<b->dim;i++){
|
||||
acc*=vals;
|
||||
acc1*=vals+1;
|
||||
}
|
||||
if(acc<=b->entries && acc1>b->entries){
|
||||
return(vals);
|
||||
}else{
|
||||
if(acc>b->entries){
|
||||
vals--;
|
||||
}else{
|
||||
vals++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vorbis_book_clear(codebook *b){
|
||||
/* static book is not cleared; we're likely called on the lookup and
|
||||
the static codebook belongs to the info struct */
|
||||
if(b->q_val)_ogg_free(b->q_val);
|
||||
if(b->dec_table)_ogg_free(b->dec_table);
|
||||
if(b->dec_buf)_ogg_free(b->dec_buf);
|
||||
|
||||
memset(b,0,sizeof(*b));
|
||||
}
|
||||
|
||||
int vorbis_book_unpack(oggpack_buffer *opb,codebook *s){
|
||||
char *lengthlist=NULL;
|
||||
int quantvals=0;
|
||||
long i,j;
|
||||
int maptype;
|
||||
|
||||
memset(s,0,sizeof(*s));
|
||||
|
||||
/* make sure alignment is correct */
|
||||
if(oggpack_read(opb,24)!=0x564342)goto _eofout;
|
||||
|
||||
/* first the basic parameters */
|
||||
s->dim=oggpack_read(opb,16);
|
||||
s->dec_buf=_ogg_malloc(sizeof(ogg_int32_t)*s->dim);
|
||||
if (s->dec_buf == NULL)
|
||||
goto _errout;
|
||||
s->entries=oggpack_read(opb,24);
|
||||
if(s->entries<=0)goto _eofout;
|
||||
if(s->dim<=0)goto _eofout;
|
||||
if(_ilog(s->dim)+_ilog(s->entries)>24)goto _eofout;
|
||||
if (s->dim > INT_MAX/s->entries) goto _eofout;
|
||||
|
||||
/* codeword ordering.... length ordered or unordered? */
|
||||
switch((int)oggpack_read(opb,1)){
|
||||
case 0:
|
||||
/* unordered */
|
||||
lengthlist=(char *)calloc(s->entries, sizeof(*lengthlist));
|
||||
if(!lengthlist) goto _eofout;
|
||||
|
||||
/* allocated but unused entries? */
|
||||
if(oggpack_read(opb,1)){
|
||||
/* yes, unused entries */
|
||||
|
||||
for(i=0;i<s->entries;i++){
|
||||
if(oggpack_read(opb,1)){
|
||||
long num=oggpack_read(opb,5);
|
||||
if(num==-1)goto _eofout;
|
||||
lengthlist[i]=(char)(num+1);
|
||||
s->used_entries++;
|
||||
if(num+1>s->dec_maxlength)s->dec_maxlength=num+1;
|
||||
}else
|
||||
lengthlist[i]=0;
|
||||
}
|
||||
}else{
|
||||
/* all entries used; no tagging */
|
||||
s->used_entries=s->entries;
|
||||
for(i=0;i<s->entries;i++){
|
||||
long num=oggpack_read(opb,5);
|
||||
if(num==-1)goto _eofout;
|
||||
lengthlist[i]=(char)(num+1);
|
||||
if(num+1>s->dec_maxlength)s->dec_maxlength=num+1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
/* ordered */
|
||||
{
|
||||
long length=oggpack_read(opb,5)+1;
|
||||
|
||||
s->used_entries=s->entries;
|
||||
lengthlist=(char *)calloc(s->entries, sizeof(*lengthlist));
|
||||
if (!lengthlist) goto _eofout;
|
||||
|
||||
for(i=0;i<s->entries;){
|
||||
long num=oggpack_read(opb,_ilog(s->entries-i));
|
||||
if(num<0)goto _eofout;
|
||||
for(j=0;j<num && i<s->entries;j++,i++)
|
||||
lengthlist[i]=(char)length;
|
||||
s->dec_maxlength=length;
|
||||
length++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* EOF */
|
||||
goto _eofout;
|
||||
}
|
||||
|
||||
|
||||
/* Do we have a mapping to unpack? */
|
||||
|
||||
if((maptype=oggpack_read(opb,4))>0){
|
||||
s->q_min=_float32_unpack(oggpack_read(opb,32),&s->q_minp);
|
||||
s->q_del=_float32_unpack(oggpack_read(opb,32),&s->q_delp);
|
||||
s->q_bits=oggpack_read(opb,4)+1;
|
||||
s->q_seq=oggpack_read(opb,1);
|
||||
|
||||
s->q_del>>=s->q_bits;
|
||||
s->q_delp+=s->q_bits;
|
||||
}
|
||||
|
||||
switch(maptype){
|
||||
case 0:
|
||||
|
||||
/* no mapping; decode type 0 */
|
||||
|
||||
/* how many bytes for the indexing? */
|
||||
/* this is the correct boundary here; we lose one bit to
|
||||
node/leaf mark */
|
||||
s->dec_nodeb=_determine_node_bytes(s->used_entries,_ilog(s->entries)/8+1);
|
||||
s->dec_leafw=_determine_leaf_words(s->dec_nodeb,_ilog(s->entries)/8+1);
|
||||
s->dec_type=0;
|
||||
|
||||
if(_make_decode_table(s,lengthlist,quantvals,opb,maptype)) goto _errout;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
/* mapping type 1; implicit values by lattice position */
|
||||
quantvals=_book_maptype1_quantvals(s);
|
||||
|
||||
/* dec_type choices here are 1,2; 3 doesn't make sense */
|
||||
{
|
||||
/* packed values */
|
||||
long total1=(s->q_bits*s->dim+8)/8; /* remember flag bit */
|
||||
if (s->dim > (INT_MAX-8)/s->q_bits) goto _eofout;
|
||||
/* vector of column offsets; remember flag bit */
|
||||
long total2=(_ilog(quantvals-1)*s->dim+8)/8+(s->q_bits+7)/8;
|
||||
|
||||
|
||||
if(total1<=4 && total1<=total2){
|
||||
/* use dec_type 1: vector of packed values */
|
||||
|
||||
/* need quantized values before */
|
||||
s->q_val=calloc(sizeof(ogg_uint16_t), quantvals);
|
||||
if (!s->q_val) goto _eofout;
|
||||
for(i=0;i<quantvals;i++)
|
||||
((ogg_uint16_t *)s->q_val)[i]=(ogg_uint16_t)oggpack_read(opb,s->q_bits);
|
||||
|
||||
if(oggpack_eop(opb)){
|
||||
goto _eofout;
|
||||
}
|
||||
|
||||
s->dec_type=1;
|
||||
s->dec_nodeb=_determine_node_bytes(s->used_entries,
|
||||
(s->q_bits*s->dim+8)/8);
|
||||
s->dec_leafw=_determine_leaf_words(s->dec_nodeb,
|
||||
(s->q_bits*s->dim+8)/8);
|
||||
if(_make_decode_table(s,lengthlist,quantvals,opb,maptype)){
|
||||
goto _errout;
|
||||
}
|
||||
|
||||
free(s->q_val);
|
||||
s->q_val=0;
|
||||
|
||||
}else{
|
||||
/* use dec_type 2: packed vector of column offsets */
|
||||
|
||||
/* need quantized values before */
|
||||
if(s->q_bits<=8){
|
||||
s->q_val=_ogg_malloc(quantvals);
|
||||
if (!s->q_val) goto _eofout;
|
||||
for(i=0;i<quantvals;i++)
|
||||
((unsigned char *)s->q_val)[i]=(unsigned char)oggpack_read(opb,s->q_bits);
|
||||
}else{
|
||||
s->q_val=_ogg_malloc(quantvals*2);
|
||||
if (!s->q_val) goto _eofout;
|
||||
for(i=0;i<quantvals;i++)
|
||||
((ogg_uint16_t *)s->q_val)[i]=(ogg_uint16_t)oggpack_read(opb,s->q_bits);
|
||||
}
|
||||
|
||||
if(oggpack_eop(opb))goto _eofout;
|
||||
|
||||
s->q_pack=_ilog(quantvals-1);
|
||||
s->dec_type=2;
|
||||
s->dec_nodeb=_determine_node_bytes(s->used_entries,
|
||||
(_ilog(quantvals-1)*s->dim+8)/8);
|
||||
s->dec_leafw=_determine_leaf_words(s->dec_nodeb,
|
||||
(_ilog(quantvals-1)*s->dim+8)/8);
|
||||
if(_make_decode_table(s,lengthlist,quantvals,opb,maptype))goto _errout;
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
||||
/* mapping type 2; explicit array of values */
|
||||
quantvals=s->entries*s->dim;
|
||||
/* dec_type choices here are 1,3; 2 is not possible */
|
||||
|
||||
if( (s->q_bits*s->dim+8)/8 <=4){ /* remember flag bit */
|
||||
/* use dec_type 1: vector of packed values */
|
||||
|
||||
s->dec_type=1;
|
||||
s->dec_nodeb=_determine_node_bytes(s->used_entries,(s->q_bits*s->dim+8)/8);
|
||||
s->dec_leafw=_determine_leaf_words(s->dec_nodeb,(s->q_bits*s->dim+8)/8);
|
||||
if(_make_decode_table(s,lengthlist,quantvals,opb,maptype))goto _errout;
|
||||
|
||||
}else{
|
||||
/* use dec_type 3: scalar offset into packed value array */
|
||||
|
||||
s->dec_type=3;
|
||||
s->dec_nodeb=_determine_node_bytes(s->used_entries,_ilog(s->used_entries-1)/8+1);
|
||||
s->dec_leafw=_determine_leaf_words(s->dec_nodeb,_ilog(s->used_entries-1)/8+1);
|
||||
if(_make_decode_table(s,lengthlist,quantvals,opb,maptype))goto _errout;
|
||||
|
||||
/* get the vals & pack them */
|
||||
s->q_pack=(s->q_bits+7)/8*s->dim;
|
||||
s->q_val=_ogg_malloc(s->q_pack*s->used_entries);
|
||||
|
||||
if(s->q_bits<=8){
|
||||
for(i=0;i<s->used_entries*s->dim;i++)
|
||||
((unsigned char *)(s->q_val))[i]=(unsigned char)oggpack_read(opb,s->q_bits);
|
||||
}else{
|
||||
for(i=0;i<s->used_entries*s->dim;i++)
|
||||
((ogg_uint16_t *)(s->q_val))[i]=(ogg_uint16_t)oggpack_read(opb,s->q_bits);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto _errout;
|
||||
}
|
||||
|
||||
if (s->dec_nodeb==1)
|
||||
if (s->dec_leafw == 1)
|
||||
s->dec_method = 0;
|
||||
else
|
||||
s->dec_method = 1;
|
||||
else if (s->dec_nodeb==2)
|
||||
if (s->dec_leafw == 1)
|
||||
s->dec_method = 2;
|
||||
else
|
||||
s->dec_method = 3;
|
||||
else
|
||||
s->dec_method = 4;
|
||||
|
||||
if(oggpack_eop(opb))goto _eofout;
|
||||
|
||||
free(lengthlist);
|
||||
return 0;
|
||||
_errout:
|
||||
_eofout:
|
||||
vorbis_book_clear(s);
|
||||
free(lengthlist);
|
||||
free(s->q_val);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef ONLY_C
|
||||
ogg_uint32_t decode_packed_entry_number(codebook *book,
|
||||
oggpack_buffer *b);
|
||||
#else
|
||||
static inline ogg_uint32_t decode_packed_entry_number(codebook *book,
|
||||
oggpack_buffer *b){
|
||||
ogg_uint32_t chase=0;
|
||||
int read=book->dec_maxlength;
|
||||
long lok = oggpack_look(b,read),i;
|
||||
|
||||
while(lok<0 && read>1)
|
||||
lok = oggpack_look(b, --read);
|
||||
|
||||
if(lok<0){
|
||||
oggpack_adv(b,1); /* force eop */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* chase the tree with the bits we got */
|
||||
switch (book->dec_method)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/* book->dec_nodeb==1, book->dec_leafw==1 */
|
||||
/* 8/8 - Used */
|
||||
unsigned char *t=(unsigned char *)book->dec_table;
|
||||
|
||||
for(i=0;i<read;i++){
|
||||
chase=t[chase*2+((lok>>i)&1)];
|
||||
if(chase&0x80UL)break;
|
||||
}
|
||||
chase&=0x7fUL;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
/* book->dec_nodeb==1, book->dec_leafw!=1 */
|
||||
/* 8/16 - Used by infile2 */
|
||||
unsigned char *t=(unsigned char *)book->dec_table;
|
||||
for(i=0;i<read;i++){
|
||||
int bit=(lok>>i)&1;
|
||||
int next=t[chase+bit];
|
||||
if(next&0x80){
|
||||
chase= (next<<8) | t[chase+bit+1+(!bit || t[chase]&0x80)];
|
||||
break;
|
||||
}
|
||||
chase=next;
|
||||
}
|
||||
//chase&=0x7fffUL;
|
||||
chase&=~0x8000UL;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
/* book->dec_nodeb==2, book->dec_leafw==1 */
|
||||
/* 16/16 - Used */
|
||||
for(i=0;i<read;i++){
|
||||
chase=((ogg_uint16_t *)(book->dec_table))[chase*2+((lok>>i)&1)];
|
||||
if(chase&0x8000UL)break;
|
||||
}
|
||||
//chase&=0x7fffUL;
|
||||
chase&=~0x8000UL;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
/* book->dec_nodeb==2, book->dec_leafw!=1 */
|
||||
/* 16/32 - Used by infile2 */
|
||||
ogg_uint16_t *t=(ogg_uint16_t *)book->dec_table;
|
||||
for(i=0;i<read;i++){
|
||||
int bit=(lok>>i)&1;
|
||||
int next=t[chase+bit];
|
||||
if(next&0x8000){
|
||||
chase= (next<<16) | t[chase+bit+1+(!bit || t[chase]&0x8000)];
|
||||
break;
|
||||
}
|
||||
chase=next;
|
||||
}
|
||||
//chase&=0x7fffffffUL;
|
||||
chase&=~0x80000000UL;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
//Output("32/32");
|
||||
for(i=0;i<read;i++){
|
||||
chase=((ogg_uint32_t *)(book->dec_table))[chase*2+((lok>>i)&1)];
|
||||
if(chase&0x80000000UL)break;
|
||||
}
|
||||
//chase&=0x7fffffffUL;
|
||||
chase&=~0x80000000UL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i<read){
|
||||
oggpack_adv(b,i+1);
|
||||
return chase;
|
||||
}
|
||||
oggpack_adv(b,read+1);
|
||||
return(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* returns the [original, not compacted] entry number or -1 on eof *********/
|
||||
long vorbis_book_decode(codebook *book, oggpack_buffer *b){
|
||||
if(book->dec_type)return -1;
|
||||
return decode_packed_entry_number(book,b);
|
||||
}
|
||||
|
||||
#ifndef ONLY_C
|
||||
int decode_map(codebook *s, oggpack_buffer *b, ogg_int32_t *v, int point);
|
||||
#else
|
||||
static int decode_map(codebook *s, oggpack_buffer *b, ogg_int32_t *v, int point){
|
||||
ogg_uint32_t entry = decode_packed_entry_number(s,b);
|
||||
int i;
|
||||
if(oggpack_eop(b))return(-1);
|
||||
|
||||
/* 1 used by test file 0 */
|
||||
|
||||
/* according to decode type */
|
||||
switch(s->dec_type){
|
||||
case 1:{
|
||||
/* packed vector of values */
|
||||
int mask=(1<<s->q_bits)-1;
|
||||
for(i=0;i<s->dim;i++){
|
||||
v[i]=entry&mask;
|
||||
entry>>=s->q_bits;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
/* packed vector of column offsets */
|
||||
int mask=(1<<s->q_pack)-1;
|
||||
for(i=0;i<s->dim;i++){
|
||||
if(s->q_bits<=8)
|
||||
v[i]=((unsigned char *)(s->q_val))[entry&mask];
|
||||
else
|
||||
v[i]=((ogg_uint16_t *)(s->q_val))[entry&mask];
|
||||
entry>>=s->q_pack;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:{
|
||||
/* offset into array */
|
||||
void *ptr=((char *)s->q_val)+entry*s->q_pack;
|
||||
|
||||
if(s->q_bits<=8){
|
||||
for(i=0;i<s->dim;i++)
|
||||
v[i]=((unsigned char *)ptr)[i];
|
||||
}else{
|
||||
for(i=0;i<s->dim;i++)
|
||||
v[i]=((ogg_uint16_t *)ptr)[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* we have the unpacked multiplicands; compute final vals */
|
||||
{
|
||||
int shiftM = point-s->q_delp;
|
||||
ogg_int32_t add = point-s->q_minp;
|
||||
int mul = s->q_del;
|
||||
|
||||
if(add>0)
|
||||
add= s->q_min >> add;
|
||||
else
|
||||
add= s->q_min << -add;
|
||||
if (shiftM<0)
|
||||
{
|
||||
mul <<= -shiftM;
|
||||
shiftM = 0;
|
||||
}
|
||||
add <<= shiftM;
|
||||
|
||||
for(i=0;i<s->dim;i++)
|
||||
v[i]= ((add + v[i] * mul) >> shiftM);
|
||||
|
||||
if(s->q_seq)
|
||||
for(i=1;i<s->dim;i++)
|
||||
v[i]+=v[i-1];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* returns 0 on OK or -1 on eof *************************************/
|
||||
long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point){
|
||||
if(book->used_entries>0){
|
||||
int step=n/book->dim;
|
||||
ogg_int32_t *v = book->dec_buf;//(ogg_int32_t *)alloca(sizeof(*v)*book->dim);
|
||||
int i,j,o;
|
||||
if (!v) return -1;
|
||||
|
||||
for (j=0;j<step;j++){
|
||||
if(decode_map(book,b,v,point))return -1;
|
||||
for(i=0,o=j;i<book->dim;i++,o+=step)
|
||||
a[o]+=v[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point){
|
||||
if(book->used_entries>0){
|
||||
ogg_int32_t *v = book->dec_buf;//(ogg_int32_t *)alloca(sizeof(*v)*book->dim);
|
||||
int i,j;
|
||||
|
||||
if (!v) return -1;
|
||||
for(i=0;i<n;){
|
||||
if(decode_map(book,b,v,point))return -1;
|
||||
for (j=0;j<book->dim;j++)
|
||||
a[i++]+=v[j];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point){
|
||||
if(book->used_entries>0){
|
||||
ogg_int32_t *v = book->dec_buf;//(ogg_int32_t *)alloca(sizeof(*v)*book->dim);
|
||||
int i,j;
|
||||
|
||||
if (!v) return -1;
|
||||
for(i=0;i<n;){
|
||||
if(decode_map(book,b,v,point))return -1;
|
||||
for (j=0;j<book->dim;j++)
|
||||
a[i++]=v[j];
|
||||
}
|
||||
}else{
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<n;){
|
||||
for (j=0;j<book->dim;j++)
|
||||
a[i++]=0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef ONLY_C
|
||||
long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
|
||||
long offset,int ch,
|
||||
oggpack_buffer *b,int n,int point);
|
||||
#else
|
||||
long vorbis_book_decodevv_add(codebook *book,ogg_int32_t **a,
|
||||
long offset,int ch,
|
||||
oggpack_buffer *b,int n,int point){
|
||||
if(book->used_entries>0){
|
||||
|
||||
ogg_int32_t *v = book->dec_buf;//(ogg_int32_t *)alloca(sizeof(*v)*book->dim);
|
||||
long i,j;
|
||||
int chptr=0;
|
||||
|
||||
if (!v) return -1;
|
||||
for(i=offset;i<offset+n;){
|
||||
if(decode_map(book,b,v,point))return -1;
|
||||
for (j=0;j<book->dim;j++){
|
||||
a[chptr++][i]+=v[j];
|
||||
if(chptr==ch){
|
||||
chptr=0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: basic shared codebook operations
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _V_CODEBOOK_H_
|
||||
#define _V_CODEBOOK_H_
|
||||
|
||||
#include "ogg.h"
|
||||
|
||||
typedef struct codebook{
|
||||
/* Top 15 used in ARM code */
|
||||
int dec_maxlength;
|
||||
void *dec_table;
|
||||
int dec_method;
|
||||
int dec_type; /* 0 = entry number
|
||||
1 = packed vector of values
|
||||
2 = packed vector of column offsets, maptype 1
|
||||
3 = scalar offset into value array, maptype 2 */
|
||||
int q_bits;
|
||||
long dim; /* codebook dimensions (elements per vector) */
|
||||
int q_delp;
|
||||
int q_minp;
|
||||
ogg_int32_t q_del;
|
||||
ogg_int32_t q_min;
|
||||
int q_seq;
|
||||
int q_pack;
|
||||
void *q_val;
|
||||
long used_entries; /* populated codebook entries */
|
||||
ogg_int32_t *dec_buf;
|
||||
|
||||
/* C only */
|
||||
int dec_nodeb;
|
||||
int dec_leafw;
|
||||
|
||||
long entries; /* codebook entries */
|
||||
|
||||
} codebook;
|
||||
|
||||
extern void vorbis_book_clear(codebook *b);
|
||||
extern int vorbis_book_unpack(oggpack_buffer *b,codebook *c);
|
||||
|
||||
extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
|
||||
extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point);
|
||||
extern long vorbis_book_decodev_set(codebook *book, ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point);
|
||||
extern long vorbis_book_decodev_add(codebook *book, ogg_int32_t *a,
|
||||
oggpack_buffer *b,int n,int point);
|
||||
extern long vorbis_book_decodevv_add(codebook *book, ogg_int32_t **a,
|
||||
long off,int ch,
|
||||
oggpack_buffer *b,int n,int point);
|
||||
|
||||
extern int _ilog(unsigned int v);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,235 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: libvorbis codec headers
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _V_CODECI_H_
|
||||
#define _V_CODECI_H_
|
||||
|
||||
#define CHUNKSIZE 1024
|
||||
|
||||
#include "codebook.h"
|
||||
#include "ivorbiscodec.h"
|
||||
|
||||
#define VI_TRANSFORMB 1
|
||||
#define VI_WINDOWB 1
|
||||
#define VI_TIMEB 1
|
||||
#define VI_FLOORB 2
|
||||
#define VI_RESB 3
|
||||
#define VI_MAPB 1
|
||||
|
||||
typedef void vorbis_info_floor;
|
||||
|
||||
/* vorbis_dsp_state buffers the current vorbis audio
|
||||
analysis/synthesis state. The DSP state belongs to a specific
|
||||
logical bitstream ****************************************************/
|
||||
struct vorbis_dsp_state{
|
||||
vorbis_info *vi;
|
||||
oggpack_buffer opb;
|
||||
|
||||
ogg_int32_t **work;
|
||||
ogg_int32_t **mdctright;
|
||||
int out_begin;
|
||||
int out_end;
|
||||
|
||||
long lW;
|
||||
long W;
|
||||
|
||||
ogg_int64_t granulepos;
|
||||
ogg_int64_t sequence;
|
||||
ogg_int64_t sample_count;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* Floor backend generic *****************************************/
|
||||
|
||||
extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *);
|
||||
extern void floor0_free_info(vorbis_info_floor *);
|
||||
extern int floor0_memosize(vorbis_info_floor *);
|
||||
extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *,
|
||||
vorbis_info_floor *,ogg_int32_t *);
|
||||
extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
|
||||
ogg_int32_t *buffer,ogg_int32_t *);
|
||||
|
||||
extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *);
|
||||
extern void floor1_free_info(vorbis_info_floor *);
|
||||
extern int floor1_memosize(vorbis_info_floor *);
|
||||
extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *,
|
||||
vorbis_info_floor *,ogg_int32_t *);
|
||||
extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
|
||||
ogg_int32_t *buffer,ogg_int32_t *);
|
||||
|
||||
typedef struct{
|
||||
int order;
|
||||
long rate;
|
||||
long barkmap;
|
||||
|
||||
int ampbits;
|
||||
int ampdB;
|
||||
|
||||
int numbooks; /* <= 16 */
|
||||
char books[16];
|
||||
|
||||
} vorbis_info_floor0;
|
||||
|
||||
typedef struct{
|
||||
char class_dim; /* 1 to 8 */
|
||||
char class_subs; /* 0,1,2,3 (bits: 1<<n poss) */
|
||||
unsigned char class_book; /* subs ^ dim entries */
|
||||
unsigned char class_subbook[8]; /* [VIF_CLASS][subs] */
|
||||
} floor1class;
|
||||
|
||||
typedef struct{
|
||||
floor1class *klass; /* [VIF_CLASS] */
|
||||
ogg_uint8_t *partitionclass; /* [VIF_PARTS]; 0 to 15 */
|
||||
ogg_uint16_t *postlist; /* [VIF_POSIT+2]; first two implicit */
|
||||
ogg_uint8_t *forward_index; /* [VIF_POSIT+2]; */
|
||||
ogg_uint8_t *hineighbor; /* [VIF_POSIT]; */
|
||||
ogg_uint8_t *loneighbor; /* [VIF_POSIT]; */
|
||||
|
||||
int partitions; /* 0 to 31 */
|
||||
int posts;
|
||||
int mult; /* 1 2 3 or 4 */
|
||||
|
||||
} vorbis_info_floor1;
|
||||
|
||||
/* Residue backend generic *****************************************/
|
||||
|
||||
typedef struct vorbis_info_residue{
|
||||
int type;
|
||||
unsigned char *stagemasks;
|
||||
unsigned char *stagebooks;
|
||||
|
||||
/* block-partitioned VQ coded straight residue */
|
||||
long begin;
|
||||
long end;
|
||||
|
||||
/* first stage (lossless partitioning) */
|
||||
int grouping; /* group n vectors per partition */
|
||||
char partitions; /* possible codebooks for a partition */
|
||||
unsigned char groupbook; /* huffbook for partitioning */
|
||||
char stages;
|
||||
} vorbis_info_residue;
|
||||
|
||||
extern void res_clear_info(vorbis_info_residue *info);
|
||||
extern int res_unpack(vorbis_info_residue *info,
|
||||
vorbis_info *vi,oggpack_buffer *opb);
|
||||
extern int res_inverse(vorbis_dsp_state *,vorbis_info_residue *info,
|
||||
ogg_int32_t **in,int *nonzero,int ch);
|
||||
|
||||
/* mode ************************************************************/
|
||||
typedef struct {
|
||||
unsigned char blockflag;
|
||||
unsigned char mapping;
|
||||
} vorbis_info_mode;
|
||||
|
||||
/* Mapping backend generic *****************************************/
|
||||
typedef struct coupling_step{
|
||||
unsigned char mag;
|
||||
unsigned char ang;
|
||||
} coupling_step;
|
||||
|
||||
typedef struct submap{
|
||||
char floor;
|
||||
char residue;
|
||||
} submap;
|
||||
|
||||
typedef struct vorbis_info_mapping{
|
||||
int submaps;
|
||||
|
||||
unsigned char *chmuxlist;
|
||||
submap *submaplist;
|
||||
|
||||
int coupling_steps;
|
||||
coupling_step *coupling;
|
||||
} vorbis_info_mapping;
|
||||
|
||||
extern int mapping_info_unpack(vorbis_info_mapping *,vorbis_info *,
|
||||
oggpack_buffer *);
|
||||
extern void mapping_clear_info(vorbis_info_mapping *);
|
||||
extern int mapping_inverse(struct vorbis_dsp_state *,vorbis_info_mapping *);
|
||||
|
||||
/* codec_setup_info contains all the setup information specific to the
|
||||
specific compression/decompression mode in progress (eg,
|
||||
psychoacoustic settings, channel setup, options, codebook
|
||||
etc).
|
||||
*********************************************************************/
|
||||
|
||||
typedef struct codec_setup_info {
|
||||
|
||||
/* Vorbis supports only short and long blocks, but allows the
|
||||
encoder to choose the sizes */
|
||||
|
||||
long blocksizes[2];
|
||||
|
||||
/* modes are the primary means of supporting on-the-fly different
|
||||
blocksizes, different channel mappings (LR or M/A),
|
||||
different residue backends, etc. Each mode consists of a
|
||||
blocksize flag and a mapping (along with the mapping setup */
|
||||
|
||||
int modes;
|
||||
int maps;
|
||||
int floors;
|
||||
int residues;
|
||||
int books;
|
||||
|
||||
vorbis_info_mode *mode_param;
|
||||
vorbis_info_mapping *map_param;
|
||||
char *floor_type;
|
||||
vorbis_info_floor **floor_param;
|
||||
vorbis_info_residue *residue_param;
|
||||
codebook *book_param;
|
||||
|
||||
} codec_setup_info;
|
||||
|
||||
extern int vorbis_dsp_init(vorbis_dsp_state *v, vorbis_info *vi);
|
||||
extern void vorbis_dsp_clear(vorbis_dsp_state *v);
|
||||
extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi);
|
||||
extern void vorbis_dsp_destroy(vorbis_dsp_state *v);
|
||||
extern int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,
|
||||
ogg_packet *op);
|
||||
|
||||
extern int vorbis_dsp_restart(vorbis_dsp_state *v);
|
||||
extern int vorbis_dsp_synthesis(vorbis_dsp_state *vd,
|
||||
ogg_packet *op,int decodep);
|
||||
extern int vorbis_dsp_pcmout(vorbis_dsp_state *v,
|
||||
ogg_int16_t *pcm,int samples);
|
||||
extern int vorbis_dsp_read(vorbis_dsp_state *v,int samples);
|
||||
extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: #ifdef jail to whip a few platforms into the UNIX ideal.
|
||||
|
||||
************************************************************************/
|
||||
#ifndef _OS_CVTYPES_H
|
||||
#define _OS_CVTYPES_H
|
||||
|
||||
typedef long long ogg_int64_t;
|
||||
typedef int ogg_int32_t;
|
||||
typedef unsigned int ogg_uint32_t;
|
||||
typedef short ogg_int16_t;
|
||||
typedef unsigned short ogg_uint16_t;
|
||||
typedef unsigned char ogg_uint8_t;
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,496 @@
|
|||
@ Tremolo library
|
||||
@-----------------------------------------------------------------------
|
||||
@ Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
@ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
@ All rights reserved.
|
||||
|
||||
@ Redistribution and use in source and binary forms, with or without
|
||||
@ modification, are permitted provided that the following conditions
|
||||
@ are met:
|
||||
|
||||
@ * Redistributions of source code must retain the above copyright
|
||||
@ notice, this list of conditions and the following disclaimer.
|
||||
@ * Redistributions in binary form must reproduce the above
|
||||
@ copyright notice, this list of conditions and the following disclaimer
|
||||
@ in the documentation and/or other materials provided with the
|
||||
@ distribution.
|
||||
@ * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
@ Productions Ltd nor the names of its contributors may be used to
|
||||
@ endorse or promote products derived from this software without
|
||||
@ specific prior written permission.
|
||||
@
|
||||
@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
@ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
@ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@ ----------------------------------------------------------------------
|
||||
|
||||
.text
|
||||
|
||||
.global decode_packed_entry_number
|
||||
.global decode_packed_entry_number_REALSTART
|
||||
.global decode_map
|
||||
.global vorbis_book_decodevv_add
|
||||
.global _checksum
|
||||
|
||||
.extern oggpack_adv
|
||||
.extern oggpack_look
|
||||
.extern oggpack_eop
|
||||
.extern crc_lookup
|
||||
.hidden crc_lookup
|
||||
|
||||
decode_packed_entry_number_REALSTART:
|
||||
dpen_nobits:
|
||||
MOV r0,r5 @ r0 = b
|
||||
MOV r1,#1 @ r1 = 1
|
||||
BL oggpack_adv @ oggpack_adv(b,1) /* Force eop */
|
||||
duff:
|
||||
MVN r0,#0 @ return -1
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
dpen_readfailed:
|
||||
SUBS r4,r4,#1 @ r4 = --read
|
||||
BEQ dpen_nobits
|
||||
MOV r0,r5 @ r0 = b
|
||||
MOV r1,r4 @ r1 = read
|
||||
ADR r14,dpen_read_return
|
||||
B oggpack_look
|
||||
|
||||
decode_packed_entry_number:
|
||||
@ r0 = codebook *book
|
||||
@ r1 = oggpack_buffer *b
|
||||
STMFD r13!,{r4-r8,r10,r14}
|
||||
|
||||
LDMIA r0,{r4,r6,r7} @ r4 = read = book->max_length
|
||||
@ r6 = book->dec_table
|
||||
@ r7 = book->dec_method
|
||||
MOV r5,r1 @ r5 = b
|
||||
|
||||
MOV r0,r5 @ r0 = b
|
||||
MOV r1,r4 @ r1 = read
|
||||
BL oggpack_look
|
||||
dpen_read_return:
|
||||
CMP r0,#0
|
||||
BLT dpen_readfailed
|
||||
|
||||
@ r0 = lok
|
||||
@ r4 = read
|
||||
@ r5 = b
|
||||
@ r6 = dec_table
|
||||
@ r7 = dec_method
|
||||
|
||||
CMP r7, #3
|
||||
BGT meth4
|
||||
BEQ meth3
|
||||
CMP r7, #1
|
||||
BGT meth2
|
||||
BEQ meth1
|
||||
meth0:
|
||||
RSB r1, r4, #0 @ r1 = i-read = 0-read
|
||||
MOV r7, #0 @ r7 = chase
|
||||
m0_loop:
|
||||
MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit
|
||||
ADC r2, r6, r7, LSL #1 @ r8 = &t[chase*2+C]
|
||||
LDRB r7, [r2]
|
||||
ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i<read)
|
||||
@ stall Xscale
|
||||
CMPLT r7, #0x80
|
||||
BLT m0_loop
|
||||
AND r7, r7, #0x7F @ r7 = chase
|
||||
CMP r1, #0 @ if (i-read >= 0) === (i >= read)
|
||||
MVNGT r7, #0 @ if (i >= read) value to return = -1
|
||||
ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1
|
||||
MOV r0, r5 @ r0 = b
|
||||
BL oggpack_adv @ oggpack_adv(b, i+1);
|
||||
MOV r0, r7 @ return chase
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
meth1:
|
||||
@ r0 = lok
|
||||
@ r4 = read
|
||||
@ r5 = b
|
||||
@ r6 = dec_table
|
||||
RSB r1, r4, #0 @ r1 = i = -read
|
||||
MOV r10,#0 @ r10= next = 0
|
||||
m1_loop:
|
||||
MOV r7, r10 @ r7 = chase=next
|
||||
MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit
|
||||
ADC r8, r6, r7 @ r8 = t+chase+bit
|
||||
LDRB r10,[r8], -r6 @ r10= next=t[chase+bit] r8=chase+bit
|
||||
ADDS r1, r1, #1 @ r1 = i++
|
||||
@ stall Xscale
|
||||
CMPLT r10,#0x80 @ if (next & 0x80) == 0
|
||||
BLT m1_loop
|
||||
|
||||
ADD r1, r1, r4 @ r1 = i+read
|
||||
MOV r0, r5 @ r0 = b
|
||||
BL oggpack_adv @ oggpack_adv(b, i)
|
||||
|
||||
CMP r10,#0x80
|
||||
BLT duff
|
||||
|
||||
CMP r8, r7 @ if bit==0 (chase+bit==chase) (sets C)
|
||||
LDRNEB r14,[r6, r7] @ r14= t[chase]
|
||||
MOVEQ r14,#128
|
||||
ADC r12,r8, r6 @ r12= chase+bit+1+t
|
||||
LDRB r14,[r12,r14,LSR #7] @ r14= t[chase+bit+1+(!bit || t[chase]0x0x80)]
|
||||
BIC r10,r10,#0x80 @ r3 = next &= ~0x80
|
||||
@ stall Xscale
|
||||
ORR r0, r14,r10,LSL #8 @ r7 = chase = (next<<8) | r14
|
||||
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
|
||||
meth2:
|
||||
RSB r1, r4, #0 @ r1 = i-read = 0-read
|
||||
MOV r7, #0 @ r7 = chase
|
||||
MOV r6, r6, LSR #1
|
||||
m2_loop:
|
||||
MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit
|
||||
ADC r2, r6, r7, LSL #1 @ r8 = &t[chase*2+C]
|
||||
LDRH r7, [r2, r2]
|
||||
ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i<read)
|
||||
@ stall Xscale
|
||||
CMPLT r7, #0x8000
|
||||
BLT m2_loop
|
||||
BIC r7, r7, #0x8000 @ r7 = chase
|
||||
CMP r1, #0 @ if (i-read >= 0) === (i >= read)
|
||||
MVNGT r7, #0 @ if (i >= read) value to return = -1
|
||||
ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1
|
||||
MOV r0, r5 @ r0 = b
|
||||
BL oggpack_adv @ oggpack_adv(b, i+1);
|
||||
MOV r0, r7 @ return chase
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
meth3:
|
||||
@ r0 = lok
|
||||
@ r4 = read
|
||||
@ r5 = b
|
||||
@ r6 = dec_table
|
||||
RSB r1, r4, #0 @ r1 = i = -read
|
||||
MOV r10,#0 @ r10= next = 0
|
||||
m3_loop:
|
||||
MOV r7, r10 @ r7 = chase=next
|
||||
MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit
|
||||
ADC r8, r7, #0 @ r8 = chase+bit
|
||||
MOV r8, r8, LSL #1 @ r8 = (chase+bit)<<1
|
||||
LDRH r10,[r6, r8] @ r10= next=t[chase+bit]
|
||||
ADDS r1, r1, #1 @ r1 = i++
|
||||
@ stall Xscale
|
||||
CMPLT r10,#0x8000 @ if (next & 0x8000) == 0
|
||||
BLT m3_loop
|
||||
|
||||
ADD r1, r1, r4 @ r1 = i+read
|
||||
MOV r0, r5 @ r0 = b
|
||||
BL oggpack_adv @ oggpack_adv(b, i)
|
||||
|
||||
CMP r10,#0x8000
|
||||
BLT duff
|
||||
|
||||
MOV r7, r7, LSL #1
|
||||
CMP r8, r7 @ if bit==0 (chase+bit==chase) sets C
|
||||
LDRNEH r14,[r6, r7] @ r14= t[chase]
|
||||
MOVEQ r14,#0x8000
|
||||
ADC r12,r8, r14,LSR #15 @ r12= 1+((chase+bit)<<1)+(!bit || t[chase]0x0x8000)
|
||||
ADC r12,r12,r14,LSR #15 @ r12= t + (1+chase+bit+(!bit || t[chase]0x0x8000))<<1
|
||||
LDRH r14,[r6, r12] @ r14= t[chase+bit+1
|
||||
BIC r10,r10,#0x8000 @ r3 = next &= ~0x8000
|
||||
@ stall Xscale
|
||||
ORR r0, r14,r10,LSL #16 @ r7 = chase = (next<<16) | r14
|
||||
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
meth4:
|
||||
RSB r1, r4, #0 @ r1 = i-read = 0-read
|
||||
MOV r7, #0 @ r7 = chase
|
||||
m4_loop:
|
||||
MOVS r0, r0, LSR #1 @ r0 = lok>>1 C = bottom bit
|
||||
ADC r2, r7, r7 @ r8 = chase*2+C
|
||||
LDR r7, [r6, r2, LSL #2]
|
||||
ADDS r1, r1, #1 @ r1 = i-read++ (i-read<0 => i<read)
|
||||
@ stall Xscale
|
||||
CMPLT r7, #0x80000000
|
||||
BLT m4_loop
|
||||
BIC r7, r7, #0x80000000 @ r7 = chase
|
||||
CMP r1, #0 @ if (i-read >= 0) === (i >= read)
|
||||
MVNGT r7, #0 @ if (i >= read) value to return = -1
|
||||
ADD r1, r1, r4 @ r1 = i-read+read+1 = i +1
|
||||
MOV r0, r5 @ r0 = b
|
||||
BL oggpack_adv @ oggpack_adv(b, i+1);
|
||||
MOV r0, r7 @ return chase
|
||||
LDMFD r13!,{r4-r8,r10,PC}
|
||||
|
||||
decode_map:
|
||||
@ r0 = codebook *s
|
||||
@ r1 = oggpack_buffer *b
|
||||
@ r2 = int v
|
||||
@ r3 = int point
|
||||
STMFD r13!,{r4-r11,r14}
|
||||
|
||||
MOV r4, r0 @ r4 = s
|
||||
MOV r5, r1 @ r5 = b
|
||||
MOV r6, r2 @ r6 = v
|
||||
MOV r7, r3 @ r7 = point
|
||||
BL decode_packed_entry_number
|
||||
MOV r8, r0
|
||||
|
||||
MOV r0, r5
|
||||
BL oggpack_eop
|
||||
CMP r0, #0
|
||||
BNE dm_duff
|
||||
|
||||
@ r4 = s
|
||||
@ r5 = b
|
||||
@ r6 = v
|
||||
@ r7 = point
|
||||
@ r8 = entry
|
||||
|
||||
LDR r1, [r4,#12] @ r1 = s->dec_type
|
||||
LDR r2, [r4,#16] @ r2 = s->q_bits
|
||||
LDR r3, [r4,#20] @ r3 = s->dim
|
||||
LDR r5, [r4,#24] @ r5 = s->q_delp
|
||||
LDR r11,[r4,#28] @ r11= s->q_minp
|
||||
LDR r12,[r4,#32] @ r12= s->q_del = mul
|
||||
LDR r14,[r4,#36] @ r14= s->q_min
|
||||
SUBS r11,r7, r11 @ r11= add = point - s->q_minp
|
||||
|
||||
MOVGT r14,r14,ASR r11 @ r14= add = s->q_min >> add (if add >0)
|
||||
RSBLT r11,r11,#0
|
||||
MOVLT r14,r14,LSL r11 @ r14= add = s->q_min << -add (if add < 0)
|
||||
|
||||
SUBS r5, r7, r5 @ r5 = shiftM = point - s->q_delp
|
||||
LDR r7, [r4,#40] @ r7 = s->q_seq
|
||||
RSBLT r5, r5, #0 @ if (shiftM<0) r5 =-shiftM
|
||||
MOVLT r12,r12,LSL r5 @ r12=mul<<-shiftM
|
||||
MOVLT r5, #0 @ r5 =shiftM = 0
|
||||
MOVGT r14,r14,LSL r5 @ add <<= shiftM
|
||||
|
||||
CMP r7,#0 @ seqMask = (s->q_seq?-1:0)
|
||||
MVNNE r7,#0
|
||||
|
||||
CMP r1, #2
|
||||
BEQ dm2
|
||||
BGT dm3
|
||||
CMP r1,#0 @ probably never happens
|
||||
BLE dm_duff
|
||||
dm1:
|
||||
@ r1 = s->dec_type
|
||||
@ r2 = s->q_bits
|
||||
@ r3 = s->dim
|
||||
@ r5 = shiftM
|
||||
@ r6 = v
|
||||
@ r7 = seqMask
|
||||
@ r8 = entry
|
||||
@ r12= mul
|
||||
@ r14= add
|
||||
MOV r0, #1
|
||||
RSB r0, r0, r0, LSL r2 @ r0 = mask = (1<<s->q_bits)-1
|
||||
MOV r11,#0 @ r11= prev = 0
|
||||
dm1_loop:
|
||||
AND r1, r8, r0 @ r1 = v = entry & mask
|
||||
MLA r1, r12, r1, r14 @ r1 = (add + mul*v)
|
||||
MOV r8, r8, LSR r2 @ r8 = entry>>s->q_bits
|
||||
SUBS r3, r3, #1
|
||||
ADD r1, r11,r1, ASR r5 @ r1 = v = prev+((add+mul*v)>>shiftM)
|
||||
AND r11,r1, r7 @ r11= prev = seqMask & v
|
||||
STR r1, [r6], #4 @ *v++ = v
|
||||
BGT dm1_loop
|
||||
|
||||
MOV r0, #0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
dm2:
|
||||
@ r1 = s->dec_type
|
||||
@ r2 = s->q_bits
|
||||
@ r3 = s->dim
|
||||
@ r4 = s
|
||||
@ r5 = shiftM
|
||||
@ r6 = v
|
||||
@ r7 = seqMask
|
||||
@ r8 = entry
|
||||
@ r12= mul
|
||||
@ r14= add
|
||||
LDR r1, [r4,#44] @ r1 = s->q_pack
|
||||
LDR r4, [r4,#48] @ r4 = s->q_val
|
||||
MOV r11,#0 @ r11= prev
|
||||
MOV r0, #1
|
||||
RSB r0, r0, r0, LSL r1 @ r8 = mask = (1<<s->q_pack)-1
|
||||
CMP r2,#8
|
||||
BGT dm2_hword
|
||||
dm2_loop:
|
||||
AND r2, r8, r0 @ r2 = entry & mask
|
||||
LDRB r2, [r4, r2] @ r2 = v = q->val[entry & mask]
|
||||
MOV r8, r8, LSR r1 @ r8 = entry>>q_pack
|
||||
MLA r2, r12,r2, r14 @ r2 = (add+mul*v)
|
||||
SUBS r3, r3, #1
|
||||
ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM
|
||||
AND r11,r2, r7 @ r11= prev = seqMask & v
|
||||
STR r2, [r6], #4 @ *v++ = v
|
||||
BGT dm2_loop
|
||||
MOV r0, #0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
dm2_hword:
|
||||
AND r2, r8, r0 @ r2 = entry & mask
|
||||
MOV r2, r2, LSL #1 @ r2 = 2*r2
|
||||
LDRH r2, [r4, r2] @ r2 = v = q->val[entry & mask]
|
||||
MOV r8, r8, LSR r1 @ r8 = entry>>q_pack
|
||||
MLA r2, r12,r2, r14 @ r2 = (add+mul*v)
|
||||
SUBS r3, r3, #1
|
||||
ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM
|
||||
AND r11,r2, r7 @ r11= prev = seqMask & v
|
||||
STR r2, [r6], #4 @ *v++ = v
|
||||
BGT dm2_hword
|
||||
MOV r0, #0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
dm3:
|
||||
@ r1 = s->dec_type
|
||||
@ r2 = s->q_bits
|
||||
@ r3 = s->dim
|
||||
@ r4 = s
|
||||
@ r5 = shiftM
|
||||
@ r6 = v
|
||||
@ r7 = seqMask
|
||||
@ r8 = entry
|
||||
@ r12= mul
|
||||
@ r14= add
|
||||
LDR r1, [r4,#44] @ r1 = s->q_pack
|
||||
LDR r4, [r4,#52] @ r4 = s->q_val
|
||||
CMP r2,#8
|
||||
MOV r11,#0 @ r11= prev
|
||||
MLA r4,r1,r8,r4 @ r4 = ptr = s->q_val+entry*s->q_pack
|
||||
|
||||
BGT dm3_hword
|
||||
dm3_loop:
|
||||
LDRB r2, [r4], #1 @ r2 = v = *ptr++
|
||||
SUBS r3, r3, #1
|
||||
MLA r2, r12,r2, r14 @ r2 = (add+mul*v)
|
||||
ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM
|
||||
AND r11,r2, r7 @ r11= prev = seqMask & v
|
||||
STR r2, [r6], #4 @ *v++ = v
|
||||
BGT dm3_loop
|
||||
MOV r0, #0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
dm3_hword:
|
||||
LDRH r2, [r4], #2 @ r2 = *ptr++
|
||||
SUBS r3, r3, #1
|
||||
MLA r2, r12,r2, r14 @ r2 = (add+mul*v)
|
||||
ADD r2, r11,r2, ASR r5 @ r2 = v = prev+(add+mul*v)>>shiftM
|
||||
AND r11,r2, r7 @ r11= prev = seqMask & v
|
||||
STR r2, [r6], #4 @ *v++ = v
|
||||
BGT dm3_hword
|
||||
MOV r0, #0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
dm_duff:
|
||||
MVN r0,#0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
vorbis_book_decodevv_add:
|
||||
@ r0 = codebook *book
|
||||
@ r1 = ogg_int32_t **a
|
||||
@ r2 = long offset
|
||||
@ r3 = int ch
|
||||
@ <> = b
|
||||
@ <> = n
|
||||
@ <> = point
|
||||
STMFD r13!,{r4-r11,R14}
|
||||
LDR r7, [r0, #13*4] @ r7 = used_entries
|
||||
MOV r9, r0 @ r9 = book
|
||||
MOV r10,r1 @ r10= 0xa[chptr] chptr=0
|
||||
MOV r6, r3 @ r6 = ch
|
||||
ADD r8, r10,r3, LSL #2 @ r8 = 0xa[ch]
|
||||
MOV r11,r2 @ r11= offset
|
||||
CMP r7, #0 @ if (used_entries <= 0)
|
||||
BLE vbdvva_exit @ exit
|
||||
LDR r5, [r13,#10*4] @ r5 = n
|
||||
vbdvva_loop1:
|
||||
@ r5 = n
|
||||
@ r6 = ch
|
||||
@ r8 = 0xa[ch]
|
||||
@ r9 = book
|
||||
@ r10= 0xa[chptr]
|
||||
@ r11= offset
|
||||
MOV r0, r9 @ r0 = book
|
||||
LDR r1, [r13,# 9*4] @ r1 = b
|
||||
LDR r2, [r9, #14*4] @ r2 = v = dec_buf
|
||||
LDR r3, [r13,#11*4] @ r3 = point
|
||||
BL decode_map
|
||||
CMP r0, #0
|
||||
BNE vbdvva_fail
|
||||
|
||||
LDR r0, [r9, # 5*4] @ r0 = book->dim
|
||||
LDR r1, [r9, #14*4] @ r1 = v = dec_buf
|
||||
vbdvva_loop2:
|
||||
LDR r2, [r10],#4 @ r2 = a[chptr++]
|
||||
LDR r12,[r1], #4 @ r1 = v[j++]
|
||||
CMP r10,r8 @ if (chptr == ch)
|
||||
SUBEQ r10,r10,r6, LSL #2 @ chptr = 0
|
||||
LDR r14,[r2, r11,LSL #2]! @ r2 = 0xa[chptr++][i] r14=[r12]
|
||||
ADDEQ r11,r11,#1 @ i++
|
||||
SUBEQ r5, r5, #1 @ n--
|
||||
SUBS r0, r0, #1 @ r0--
|
||||
ADD r12,r12,r14 @ r12= a[chptr++][i]+ v[j]
|
||||
STR r12,[r2] @ r12= a[chptr++][i]+=v[j]
|
||||
BGT vbdvva_loop2
|
||||
CMP r5,#0
|
||||
BGT vbdvva_loop1
|
||||
vbdvva_exit:
|
||||
MOV r0, #0 @ return 0
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
vbdvva_fail:
|
||||
MVN r0, #0 @ return -1
|
||||
LDMFD r13!,{r4-r11,PC}
|
||||
|
||||
_checksum:
|
||||
@ r0 = ogg_reference *or
|
||||
@ r1 = bytes
|
||||
STMFD r13!,{r5-r6,r14}
|
||||
|
||||
ADR r6,.Lcrc_lookup
|
||||
LDR r5,[r6]
|
||||
ADD r5,r6
|
||||
MOV r14,#0 @ r14= crc_reg = 0
|
||||
MOVS r12,r0
|
||||
BEQ _cs_end
|
||||
_cs_loop1:
|
||||
LDMIA r12,{r0,r2,r3,r12} @ r0 = or->buffer
|
||||
@ r2 = or->begin
|
||||
@ r3 = or->length
|
||||
@ r12= or->next
|
||||
LDR r0,[r0] @ r0 = or->buffer->data
|
||||
CMP r1,r3 @ r3 = post = (bytes < or->length ?
|
||||
MOVLT r3,r1 @ bytes : or->length)
|
||||
MOVS r6,r3 @ r6 = j = post
|
||||
BEQ _cs_no_bytes
|
||||
ADD r0,r0,r2 @ r0 = or->buffer->data + or->begin
|
||||
_cs_loop2:
|
||||
LDRB r2, [r0],#1 @ r2 = data[j]
|
||||
@ stall
|
||||
@ stall Xscale
|
||||
EOR r2, r2, r14,LSR #24 @ r2 = (crc_reg>>24)^data[j]
|
||||
LDR r2, [r5, r2, LSL #2] @ r2 = crc_lkp[(crc_reg>>24)^data[j]]
|
||||
SUBS r6, r6, #1 @ j--
|
||||
@ stall Xscale
|
||||
EOR r14,r2, r14,LSL #8 @ r14= crc_reg = (crc_reg<<8)^r2
|
||||
BGT _cs_loop2
|
||||
_cs_no_bytes:
|
||||
SUBS r1, r1, r3
|
||||
CMPNE r12,#0
|
||||
BNE _cs_loop1
|
||||
_cs_end:
|
||||
MOV r0,r14
|
||||
LDMFD r13!,{r5-r6,PC}
|
||||
|
||||
.Lcrc_lookup:
|
||||
.WORD crc_lookup-.Lcrc_lookup
|
||||
|
||||
@ END
|
||||
|
|
@ -0,0 +1,326 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: PCM data vector blocking, windowing and dis/reassembly
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ogg.h"
|
||||
#include "mdct.h"
|
||||
#include "ivorbiscodec.h"
|
||||
#include "codec_internal.h"
|
||||
#include "misc.h"
|
||||
#include "window_lookup.h"
|
||||
|
||||
int vorbis_dsp_restart(vorbis_dsp_state *v){
|
||||
if(!v)return -1;
|
||||
{
|
||||
vorbis_info *vi=v->vi;
|
||||
codec_setup_info *ci;
|
||||
|
||||
if(!vi)return -1;
|
||||
ci=vi->codec_setup;
|
||||
if(!ci)return -1;
|
||||
|
||||
v->out_end=-1;
|
||||
v->out_begin=-1;
|
||||
|
||||
v->granulepos=-1;
|
||||
v->sequence=-1;
|
||||
v->sample_count=-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vorbis_dsp_init(vorbis_dsp_state *v,vorbis_info *vi){
|
||||
int i;
|
||||
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
|
||||
v->vi=vi;
|
||||
|
||||
v->work=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->work));
|
||||
v->mdctright=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->mdctright));
|
||||
for(i=0;i<vi->channels;i++){
|
||||
v->work[i]=(ogg_int32_t *)_ogg_calloc(1,(ci->blocksizes[1]>>1)*
|
||||
sizeof(*v->work[i]));
|
||||
v->mdctright[i]=(ogg_int32_t *)_ogg_calloc(1,(ci->blocksizes[1]>>2)*
|
||||
sizeof(*v->mdctright[i]));
|
||||
}
|
||||
|
||||
v->lW=0; /* previous window size */
|
||||
v->W=0; /* current window size */
|
||||
|
||||
vorbis_dsp_restart(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi){
|
||||
vorbis_dsp_state *v=_ogg_calloc(1,sizeof(*v));
|
||||
vorbis_dsp_init(v,vi);
|
||||
return v;
|
||||
}
|
||||
|
||||
void vorbis_dsp_clear(vorbis_dsp_state *v){
|
||||
int i;
|
||||
if(v){
|
||||
vorbis_info *vi=v->vi;
|
||||
|
||||
if(v->work){
|
||||
for(i=0;i<vi->channels;i++)
|
||||
if(v->work[i])_ogg_free(v->work[i]);
|
||||
_ogg_free(v->work);
|
||||
}
|
||||
if(v->mdctright){
|
||||
for(i=0;i<vi->channels;i++)
|
||||
if(v->mdctright[i])_ogg_free(v->mdctright[i]);
|
||||
_ogg_free(v->mdctright);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vorbis_dsp_destroy(vorbis_dsp_state *v){
|
||||
vorbis_dsp_clear(v);
|
||||
_ogg_free(v);
|
||||
}
|
||||
|
||||
static LOOKUP_T *_vorbis_window(int left){
|
||||
switch(left){
|
||||
case 32:
|
||||
return vwin64;
|
||||
case 64:
|
||||
return vwin128;
|
||||
case 128:
|
||||
return vwin256;
|
||||
case 256:
|
||||
return vwin512;
|
||||
case 512:
|
||||
return vwin1024;
|
||||
case 1024:
|
||||
return vwin2048;
|
||||
case 2048:
|
||||
return vwin4096;
|
||||
#ifndef LIMIT_TO_64kHz
|
||||
case 4096:
|
||||
return vwin8192;
|
||||
#endif
|
||||
default:
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* pcm==0 indicates we just want the pending samples, no more */
|
||||
int vorbis_dsp_pcmout(vorbis_dsp_state *v,ogg_int16_t *pcm,int samples){
|
||||
vorbis_info *vi=v->vi;
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
if(v->out_begin>-1 && v->out_begin<v->out_end){
|
||||
int n=v->out_end-v->out_begin;
|
||||
if(pcm){
|
||||
int i;
|
||||
if(n>samples)n=samples;
|
||||
for(i=0;i<vi->channels;i++)
|
||||
mdct_unroll_lap(ci->blocksizes[0],ci->blocksizes[1],
|
||||
v->lW,v->W,v->work[i],v->mdctright[i],
|
||||
_vorbis_window(ci->blocksizes[0]>>1),
|
||||
_vorbis_window(ci->blocksizes[1]>>1),
|
||||
pcm+i,vi->channels,
|
||||
v->out_begin,v->out_begin+n);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int vorbis_dsp_read(vorbis_dsp_state *v,int s){
|
||||
if(s && v->out_begin+s>v->out_end)return(OV_EINVAL);
|
||||
v->out_begin+=s;
|
||||
return(0);
|
||||
}
|
||||
|
||||
long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
oggpack_buffer opb;
|
||||
int mode;
|
||||
int modebits=0;
|
||||
int v=ci->modes;
|
||||
|
||||
oggpack_readinit(&opb,op->packet);
|
||||
|
||||
/* Check the packet type */
|
||||
if(oggpack_read(&opb,1)!=0){
|
||||
/* Oops. This is not an audio data packet */
|
||||
return(OV_ENOTAUDIO);
|
||||
}
|
||||
|
||||
while(v>1){
|
||||
modebits++;
|
||||
v>>=1;
|
||||
}
|
||||
|
||||
/* read our mode and pre/post windowsize */
|
||||
mode=oggpack_read(&opb,modebits);
|
||||
if(mode==-1)return(OV_EBADPACKET);
|
||||
return(ci->blocksizes[ci->mode_param[mode].blockflag]);
|
||||
}
|
||||
|
||||
|
||||
static int ilog(ogg_uint32_t v){
|
||||
int ret=0;
|
||||
if(v)--v;
|
||||
while(v){
|
||||
ret++;
|
||||
v>>=1;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int vorbis_dsp_synthesis(vorbis_dsp_state *vd,ogg_packet *op,int decodep){
|
||||
vorbis_info *vi=vd->vi;
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
int mode,i;
|
||||
|
||||
oggpack_readinit(&vd->opb,op->packet);
|
||||
|
||||
/* Check the packet type */
|
||||
if(oggpack_read(&vd->opb,1)!=0){
|
||||
/* Oops. This is not an audio data packet */
|
||||
return OV_ENOTAUDIO ;
|
||||
}
|
||||
|
||||
/* read our mode and pre/post windowsize */
|
||||
mode=oggpack_read(&vd->opb,ilog(ci->modes));
|
||||
if(mode==-1 || mode>=ci->modes) return OV_EBADPACKET;
|
||||
|
||||
/* shift information we still need from last window */
|
||||
vd->lW=vd->W;
|
||||
vd->W=ci->mode_param[mode].blockflag;
|
||||
for(i=0;i<vi->channels;i++)
|
||||
mdct_shift_right(ci->blocksizes[vd->lW],vd->work[i],vd->mdctright[i]);
|
||||
|
||||
if(vd->W){
|
||||
int temp;
|
||||
oggpack_read(&vd->opb,1);
|
||||
temp=oggpack_read(&vd->opb,1);
|
||||
if(temp==-1) return OV_EBADPACKET;
|
||||
}
|
||||
|
||||
/* packet decode and portions of synthesis that rely on only this block */
|
||||
if(decodep){
|
||||
mapping_inverse(vd,ci->map_param+ci->mode_param[mode].mapping);
|
||||
|
||||
if(vd->out_begin==-1){
|
||||
vd->out_begin=0;
|
||||
vd->out_end=0;
|
||||
}else{
|
||||
vd->out_begin=0;
|
||||
vd->out_end=ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4;
|
||||
}
|
||||
}
|
||||
|
||||
/* track the frame number... This is for convenience, but also
|
||||
making sure our last packet doesn't end with added padding.
|
||||
|
||||
This is not foolproof! It will be confused if we begin
|
||||
decoding at the last page after a seek or hole. In that case,
|
||||
we don't have a starting point to judge where the last frame
|
||||
is. For this reason, vorbisfile will always try to make sure
|
||||
it reads the last two marked pages in proper sequence */
|
||||
|
||||
/* if we're out of sequence, dump granpos tracking until we sync back up */
|
||||
if(vd->sequence==-1 || vd->sequence+1 != op->packetno-3){
|
||||
/* out of sequence; lose count */
|
||||
vd->granulepos=-1;
|
||||
vd->sample_count=-1;
|
||||
}
|
||||
|
||||
vd->sequence=op->packetno;
|
||||
vd->sequence=vd->sequence-3;
|
||||
|
||||
if(vd->sample_count==-1){
|
||||
vd->sample_count=0;
|
||||
}else{
|
||||
vd->sample_count+=
|
||||
ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4;
|
||||
}
|
||||
|
||||
if(vd->granulepos==-1){
|
||||
if(op->granulepos!=-1){ /* only set if we have a
|
||||
position to set to */
|
||||
|
||||
vd->granulepos=op->granulepos;
|
||||
|
||||
/* is this a short page? */
|
||||
if(vd->sample_count>vd->granulepos){
|
||||
/* corner case; if this is both the first and last audio page,
|
||||
then spec says the end is cut, not beginning */
|
||||
if(op->e_o_s){
|
||||
/* trim the end */
|
||||
/* no preceeding granulepos; assume we started at zero (we'd
|
||||
have to in a short single-page stream) */
|
||||
/* granulepos could be -1 due to a seek, but that would result
|
||||
in a long coun t, not short count */
|
||||
|
||||
vd->out_end-=(int)(vd->sample_count-vd->granulepos);
|
||||
}else{
|
||||
/* trim the beginning */
|
||||
vd->out_begin+=(int)(vd->sample_count-vd->granulepos);
|
||||
if(vd->out_begin>vd->out_end)
|
||||
vd->out_begin=vd->out_end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
vd->granulepos+=
|
||||
ci->blocksizes[vd->lW]/4+ci->blocksizes[vd->W]/4;
|
||||
if(op->granulepos!=-1 && vd->granulepos!=op->granulepos){
|
||||
|
||||
if(vd->granulepos>op->granulepos){
|
||||
long extra=(long)(vd->granulepos-op->granulepos);
|
||||
|
||||
if(extra)
|
||||
if(op->e_o_s){
|
||||
/* partial last frame. Strip the extra samples off */
|
||||
vd->out_end-=extra;
|
||||
} /* else {Shouldn't happen *unless* the bitstream is out of
|
||||
spec. Either way, believe the bitstream } */
|
||||
} /* else {Shouldn't happen *unless* the bitstream is out of
|
||||
spec. Either way, believe the bitstream } */
|
||||
vd->granulepos=op->granulepos;
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
|
@ -0,0 +1,448 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: floor backend 0 implementation
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "ogg.h"
|
||||
#include "ivorbiscodec.h"
|
||||
#include "codec_internal.h"
|
||||
#include "codebook.h"
|
||||
#include "misc.h"
|
||||
#include "os.h"
|
||||
|
||||
#define LSP_FRACBITS 14
|
||||
extern const ogg_int32_t FLOOR_fromdB_LOOKUP[];
|
||||
|
||||
/*************** LSP decode ********************/
|
||||
|
||||
#include "lsp_lookup.h"
|
||||
|
||||
/* interpolated 1./sqrt(p) where .5 <= a < 1. (.100000... to .111111...) in
|
||||
16.16 format
|
||||
returns in m.8 format */
|
||||
|
||||
static long ADJUST_SQRT2[2]={8192,5792};
|
||||
static inline ogg_int32_t vorbis_invsqlook_i(long a,long e){
|
||||
long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
|
||||
long d=a&INVSQ_LOOKUP_I_MASK; /* 0.10 */
|
||||
long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
|
||||
((INVSQ_LOOKUP_IDel[i]*d)>>INVSQ_LOOKUP_I_SHIFT); /* result 1.16 */
|
||||
val*=ADJUST_SQRT2[e&1];
|
||||
e=(e>>1)+21;
|
||||
return(val>>e);
|
||||
}
|
||||
|
||||
/* interpolated lookup based fromdB function, domain -140dB to 0dB only */
|
||||
/* a is in n.12 format */
|
||||
#ifdef _LOW_ACCURACY_
|
||||
static inline ogg_int32_t vorbis_fromdBlook_i(long a){
|
||||
if(a>0) return 0x7fffffff;
|
||||
if(a<(int)(((unsigned)-140)<<12)) return 0;
|
||||
return FLOOR_fromdB_LOOKUP[((a+140)*467)>>20]<<9;
|
||||
}
|
||||
#else
|
||||
static inline ogg_int32_t vorbis_fromdBlook_i(long a){
|
||||
if(a>0) return 0x7fffffff;
|
||||
if(a<(int)(((unsigned)-140)<<12)) return 0;
|
||||
return FLOOR_fromdB_LOOKUP[((a+(140<<12))*467)>>20];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* interpolated lookup based cos function, domain 0 to PI only */
|
||||
/* a is in 0.16 format, where 0==0, 2^^16-1==PI, return 0.14 */
|
||||
static inline ogg_int32_t vorbis_coslook_i(long a){
|
||||
int i=a>>COS_LOOKUP_I_SHIFT;
|
||||
int d=a&COS_LOOKUP_I_MASK;
|
||||
return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
|
||||
COS_LOOKUP_I_SHIFT);
|
||||
}
|
||||
|
||||
/* interpolated half-wave lookup based cos function */
|
||||
/* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */
|
||||
static inline ogg_int32_t vorbis_coslook2_i(long a){
|
||||
int i=a>>COS_LOOKUP_I_SHIFT;
|
||||
int d=a&COS_LOOKUP_I_MASK;
|
||||
return ((COS_LOOKUP_I[i]<<COS_LOOKUP_I_SHIFT)-
|
||||
d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
|
||||
(COS_LOOKUP_I_SHIFT-LSP_FRACBITS+14);
|
||||
}
|
||||
|
||||
static const ogg_uint16_t barklook[54]={
|
||||
0,51,102,154, 206,258,311,365,
|
||||
420,477,535,594, 656,719,785,854,
|
||||
926,1002,1082,1166, 1256,1352,1454,1564,
|
||||
1683,1812,1953,2107, 2276,2463,2670,2900,
|
||||
3155,3440,3756,4106, 4493,4919,5387,5901,
|
||||
6466,7094,7798,8599, 9528,10623,11935,13524,
|
||||
15453,17775,20517,23667, 27183,31004
|
||||
};
|
||||
|
||||
/* used in init only; interpolate the long way */
|
||||
static inline ogg_int32_t toBARK(int n){
|
||||
int i;
|
||||
for(i=0;i<54;i++)
|
||||
if(n>=barklook[i] && n<barklook[i+1])break;
|
||||
|
||||
if(i==54){
|
||||
return 54<<14;
|
||||
}else{
|
||||
return (i<<14)+(((n-barklook[i])*
|
||||
((1UL<<31)/(barklook[i+1]-barklook[i])))>>17);
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned char MLOOP_1[64]={
|
||||
0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
|
||||
14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
|
||||
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
|
||||
15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
|
||||
};
|
||||
|
||||
static const unsigned char MLOOP_2[64]={
|
||||
0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
|
||||
8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
|
||||
9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
|
||||
9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
|
||||
};
|
||||
|
||||
static const unsigned char MLOOP_3[8]={0,1,2,2,3,3,3,3};
|
||||
|
||||
void vorbis_lsp_to_curve(ogg_int32_t *curve,int n,int ln,
|
||||
ogg_int32_t *lsp,int m,
|
||||
ogg_int32_t amp,
|
||||
ogg_int32_t ampoffset,
|
||||
ogg_int32_t nyq){
|
||||
|
||||
/* 0 <= m < 256 */
|
||||
|
||||
/* set up for using all int later */
|
||||
int i;
|
||||
int ampoffseti=ampoffset*4096;
|
||||
int ampi=amp;
|
||||
ogg_int32_t *ilsp=(ogg_int32_t *)alloca(m*sizeof(*ilsp));
|
||||
|
||||
ogg_uint32_t inyq= (1UL<<31) / toBARK(nyq);
|
||||
ogg_uint32_t imap= (1UL<<31) / ln;
|
||||
ogg_uint32_t tBnyq1 = toBARK(nyq)<<1;
|
||||
|
||||
/* Besenham for frequency scale to avoid a division */
|
||||
int f=0;
|
||||
int fdx=n;
|
||||
int fbase=nyq/fdx;
|
||||
int ferr=0;
|
||||
int fdy=nyq-fbase*fdx;
|
||||
int map=0;
|
||||
|
||||
#ifdef _LOW_ACCURACY_
|
||||
ogg_uint32_t nextbark=((tBnyq1<<11)/ln)>>12;
|
||||
#else
|
||||
ogg_uint32_t nextbark=MULT31(imap>>1,tBnyq1);
|
||||
#endif
|
||||
int nextf=barklook[nextbark>>14]+(((nextbark&0x3fff)*
|
||||
(barklook[(nextbark>>14)+1]-barklook[nextbark>>14]))>>14);
|
||||
|
||||
/* lsp is in 8.24, range 0 to PI; coslook wants it in .16 0 to 1*/
|
||||
for(i=0;i<m;i++){
|
||||
#ifndef _LOW_ACCURACY_
|
||||
ogg_int32_t val=MULT32(lsp[i],0x517cc2);
|
||||
#else
|
||||
ogg_int32_t val=((lsp[i]>>10)*0x517d)>>14;
|
||||
#endif
|
||||
|
||||
/* safeguard against a malicious stream */
|
||||
if(val<0 || (val>>COS_LOOKUP_I_SHIFT)>=COS_LOOKUP_I_SZ){
|
||||
memset(curve,0,sizeof(*curve)*n);
|
||||
return;
|
||||
}
|
||||
|
||||
ilsp[i]=vorbis_coslook_i(val);
|
||||
}
|
||||
|
||||
i=0;
|
||||
while(i<n){
|
||||
int j;
|
||||
ogg_uint32_t pi=46341; /* 2**-.5 in 0.16 */
|
||||
ogg_uint32_t qi=46341;
|
||||
ogg_int32_t qexp=0,shift;
|
||||
ogg_int32_t wi;
|
||||
|
||||
wi=vorbis_coslook2_i((map*imap)>>15);
|
||||
|
||||
|
||||
#ifdef _V_LSP_MATH_ASM
|
||||
lsp_loop_asm(&qi,&pi,&qexp,ilsp,wi,m);
|
||||
|
||||
pi=((pi*pi)>>16);
|
||||
qi=((qi*qi)>>16);
|
||||
|
||||
if(m&1){
|
||||
qexp= qexp*2-28*((m+1)>>1)+m;
|
||||
pi*=(1<<14)-((wi*wi)>>14);
|
||||
qi+=pi>>14;
|
||||
}else{
|
||||
qexp= qexp*2-13*m;
|
||||
|
||||
pi*=(1<<14)-wi;
|
||||
qi*=(1<<14)+wi;
|
||||
|
||||
qi=(qi+pi)>>14;
|
||||
}
|
||||
|
||||
if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
|
||||
qi>>=1; qexp++;
|
||||
}else
|
||||
lsp_norm_asm(&qi,&qexp);
|
||||
|
||||
#else
|
||||
|
||||
qi*=labs(ilsp[0]-wi);
|
||||
pi*=labs(ilsp[1]-wi);
|
||||
|
||||
for(j=3;j<m;j+=2){
|
||||
if(!(shift=MLOOP_1[(pi|qi)>>25]))
|
||||
if(!(shift=MLOOP_2[(pi|qi)>>19]))
|
||||
shift=MLOOP_3[(pi|qi)>>16];
|
||||
|
||||
qi=(qi>>shift)*labs(ilsp[j-1]-wi);
|
||||
pi=(pi>>shift)*labs(ilsp[j]-wi);
|
||||
qexp+=shift;
|
||||
}
|
||||
if(!(shift=MLOOP_1[(pi|qi)>>25]))
|
||||
if(!(shift=MLOOP_2[(pi|qi)>>19]))
|
||||
shift=MLOOP_3[(pi|qi)>>16];
|
||||
|
||||
/* pi,qi normalized collectively, both tracked using qexp */
|
||||
|
||||
if(m&1){
|
||||
/* odd order filter; slightly assymetric */
|
||||
/* the last coefficient */
|
||||
qi=(qi>>shift)*labs(ilsp[j-1]-wi);
|
||||
pi=(pi>>shift)<<14;
|
||||
qexp+=shift;
|
||||
|
||||
if(!(shift=MLOOP_1[(pi|qi)>>25]))
|
||||
if(!(shift=MLOOP_2[(pi|qi)>>19]))
|
||||
shift=MLOOP_3[(pi|qi)>>16];
|
||||
|
||||
pi>>=shift;
|
||||
qi>>=shift;
|
||||
qexp+=shift-14*((m+1)>>1);
|
||||
|
||||
pi=((pi*pi)>>16);
|
||||
qi=((qi*qi)>>16);
|
||||
qexp=qexp*2+m;
|
||||
|
||||
pi*=(1<<14)-((wi*wi)>>14);
|
||||
qi+=pi>>14;
|
||||
|
||||
}else{
|
||||
/* even order filter; still symmetric */
|
||||
|
||||
/* p*=p(1-w), q*=q(1+w), let normalization drift because it isn't
|
||||
worth tracking step by step */
|
||||
|
||||
pi>>=shift;
|
||||
qi>>=shift;
|
||||
qexp+=shift-7*m;
|
||||
|
||||
pi=((pi*pi)>>16);
|
||||
qi=((qi*qi)>>16);
|
||||
qexp=qexp*2+m;
|
||||
|
||||
pi*=(1<<14)-wi;
|
||||
qi*=(1<<14)+wi;
|
||||
qi=(qi+pi)>>14;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* we've let the normalization drift because it wasn't important;
|
||||
however, for the lookup, things must be normalized again. We
|
||||
need at most one right shift or a number of left shifts */
|
||||
|
||||
if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
|
||||
qi>>=1; qexp++;
|
||||
}else
|
||||
while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
|
||||
qi<<=1; qexp--;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
amp=vorbis_fromdBlook_i(ampi* /* n.4 */
|
||||
vorbis_invsqlook_i(qi,qexp)-
|
||||
/* m.8, m+n<=8 */
|
||||
ampoffseti); /* 8.12[0] */
|
||||
|
||||
#ifdef _LOW_ACCURACY_
|
||||
amp>>=9;
|
||||
#endif
|
||||
curve[i]= MULT31_SHIFT15(curve[i],amp);
|
||||
|
||||
while(++i<n){
|
||||
|
||||
/* line plot to get new f */
|
||||
ferr+=fdy;
|
||||
if(ferr>=fdx){
|
||||
ferr-=fdx;
|
||||
f++;
|
||||
}
|
||||
f+=fbase;
|
||||
|
||||
if(f>=nextf)break;
|
||||
|
||||
curve[i]= MULT31_SHIFT15(curve[i],amp);
|
||||
}
|
||||
|
||||
while(1){
|
||||
map++;
|
||||
|
||||
if(map+1<ln){
|
||||
|
||||
#ifdef _LOW_ACCURACY_
|
||||
nextbark=((tBnyq1<<11)/ln*(map+1))>>12;
|
||||
#else
|
||||
nextbark=MULT31((map+1)*(imap>>1),tBnyq1);
|
||||
#endif
|
||||
nextf=barklook[nextbark>>14]+
|
||||
(((nextbark&0x3fff)*
|
||||
(barklook[(nextbark>>14)+1]-barklook[nextbark>>14]))>>14);
|
||||
if(f<=nextf)break;
|
||||
|
||||
}else{
|
||||
nextf=9999999;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(map>=ln){
|
||||
map=ln-1; /* guard against the approximation */
|
||||
nextf=9999999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************** vorbis decode glue ************/
|
||||
|
||||
void floor0_free_info(vorbis_info_floor *i){
|
||||
vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
|
||||
if(info)_ogg_free(info);
|
||||
}
|
||||
|
||||
vorbis_info_floor *floor0_info_unpack (vorbis_info *vi,oggpack_buffer *opb){
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
int j;
|
||||
|
||||
vorbis_info_floor0 *info=(vorbis_info_floor0 *)_ogg_malloc(sizeof(*info));
|
||||
info->order=oggpack_read(opb,8);
|
||||
info->rate=oggpack_read(opb,16);
|
||||
info->barkmap=oggpack_read(opb,16);
|
||||
info->ampbits=oggpack_read(opb,6);
|
||||
info->ampdB=oggpack_read(opb,8);
|
||||
info->numbooks=oggpack_read(opb,4)+1;
|
||||
|
||||
if(info->order<1)goto err_out;
|
||||
if(info->rate<1)goto err_out;
|
||||
if(info->barkmap<1)goto err_out;
|
||||
|
||||
for(j=0;j<info->numbooks;j++){
|
||||
info->books[j]=(char)oggpack_read(opb,8);
|
||||
if(info->books[j]>=ci->books)goto err_out;
|
||||
}
|
||||
|
||||
if(oggpack_eop(opb))goto err_out;
|
||||
return(info);
|
||||
|
||||
err_out:
|
||||
floor0_free_info(info);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
int floor0_memosize(vorbis_info_floor *i){
|
||||
vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
|
||||
return info->order+1;
|
||||
}
|
||||
|
||||
ogg_int32_t *floor0_inverse1(vorbis_dsp_state *vd,vorbis_info_floor *i,
|
||||
ogg_int32_t *lsp){
|
||||
vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
|
||||
int j,k;
|
||||
|
||||
int ampraw=oggpack_read(&vd->opb,info->ampbits);
|
||||
if(ampraw>0){ /* also handles the -1 out of data case */
|
||||
long maxval=(1<<info->ampbits)-1;
|
||||
int amp=((ampraw*info->ampdB)<<4)/maxval;
|
||||
int booknum=oggpack_read(&vd->opb,_ilog(info->numbooks));
|
||||
|
||||
if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
|
||||
codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
|
||||
codebook *b=ci->book_param+info->books[booknum];
|
||||
ogg_int32_t last=0;
|
||||
|
||||
for(j=0;j<info->order;j+=b->dim)
|
||||
if(vorbis_book_decodev_set(b,lsp+j,&vd->opb,b->dim,-24)==-1)goto eop;
|
||||
for(j=0;j<info->order;){
|
||||
for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
|
||||
last=lsp[j-1];
|
||||
}
|
||||
|
||||
lsp[info->order]=amp;
|
||||
return(lsp);
|
||||
}
|
||||
}
|
||||
eop:
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
int floor0_inverse2(vorbis_dsp_state *vd,vorbis_info_floor *i,
|
||||
ogg_int32_t *lsp,ogg_int32_t *out){
|
||||
vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
|
||||
codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
|
||||
|
||||
if(lsp){
|
||||
ogg_int32_t amp=lsp[info->order];
|
||||
|
||||
/* take the coefficients back to a spectral envelope curve */
|
||||
vorbis_lsp_to_curve(out,ci->blocksizes[vd->W]/2,info->barkmap,
|
||||
lsp,info->order,amp,info->ampdB,
|
||||
info->rate>>1);
|
||||
return(1);
|
||||
}
|
||||
memset(out,0,sizeof(*out)*ci->blocksizes[vd->W]/2);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,407 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: floor backend 1 implementation
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "ogg.h"
|
||||
#include "ivorbiscodec.h"
|
||||
#include "codec_internal.h"
|
||||
#include "codebook.h"
|
||||
#include "misc.h"
|
||||
|
||||
extern const ogg_int32_t FLOOR_fromdB_LOOKUP[];
|
||||
#define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
|
||||
#define VIF_POSIT 63
|
||||
|
||||
/***********************************************/
|
||||
|
||||
void floor1_free_info(vorbis_info_floor *i){
|
||||
vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
|
||||
if(info){
|
||||
if(info->klass)_ogg_free(info->klass);
|
||||
if(info->partitionclass)_ogg_free(info->partitionclass);
|
||||
if(info->postlist)_ogg_free(info->postlist);
|
||||
if(info->forward_index)_ogg_free(info->forward_index);
|
||||
if(info->hineighbor)_ogg_free(info->hineighbor);
|
||||
if(info->loneighbor)_ogg_free(info->loneighbor);
|
||||
memset(info,0,sizeof(*info));
|
||||
_ogg_free(info);
|
||||
}
|
||||
}
|
||||
|
||||
static int ilog(unsigned int v){
|
||||
int ret=0;
|
||||
while(v){
|
||||
ret++;
|
||||
v>>=1;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static void floor1_mergesort(ogg_uint8_t *index,ogg_uint16_t *vals,ogg_uint16_t n){
|
||||
ogg_uint16_t i,j;
|
||||
ogg_uint8_t *temp,*A=index,*B=_ogg_malloc(n*sizeof(*B));
|
||||
|
||||
for(i=1;i<n;i<<=1){
|
||||
for(j=0;j+i<n;){
|
||||
int k1=j;
|
||||
int mid=j+i;
|
||||
int k2=mid;
|
||||
int end=(j+i*2<n?j+i*2:n);
|
||||
while(k1<mid && k2<end){
|
||||
if(vals[A[k1]]<vals[A[k2]])
|
||||
B[j++]=A[k1++];
|
||||
else
|
||||
B[j++]=A[k2++];
|
||||
}
|
||||
while(k1<mid) B[j++]=A[k1++];
|
||||
while(k2<end) B[j++]=A[k2++];
|
||||
}
|
||||
for(;j<n;j++)B[j]=A[j];
|
||||
temp=A;A=B;B=temp;
|
||||
}
|
||||
|
||||
if(B==index){
|
||||
for(j=0;j<n;j++)B[j]=A[j];
|
||||
_ogg_free(A);
|
||||
}else
|
||||
_ogg_free(B);
|
||||
}
|
||||
|
||||
|
||||
vorbis_info_floor *floor1_info_unpack (vorbis_info *vi,oggpack_buffer *opb){
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
int j,k,count=0,maxclass=-1,rangebits;
|
||||
|
||||
vorbis_info_floor1 *info=(vorbis_info_floor1 *)_ogg_calloc(1,sizeof(*info));
|
||||
/* read partitions */
|
||||
info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
|
||||
info->partitionclass=
|
||||
(ogg_uint8_t *)_ogg_malloc(info->partitions*sizeof(*info->partitionclass));
|
||||
for(j=0;j<info->partitions;j++){
|
||||
info->partitionclass[j]=(char)oggpack_read(opb,4); /* only 0 to 15 legal */
|
||||
if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
|
||||
}
|
||||
|
||||
/* read partition classes */
|
||||
info->klass=
|
||||
(floor1class *)_ogg_malloc((maxclass+1)*sizeof(*info->klass));
|
||||
for(j=0;j<maxclass+1;j++){
|
||||
info->klass[j].class_dim=(char)oggpack_read(opb,3)+1; /* 1 to 8 */
|
||||
info->klass[j].class_subs=(char)oggpack_read(opb,2); /* 0,1,2,3 bits */
|
||||
if(oggpack_eop(opb)<0) goto err_out;
|
||||
if(info->klass[j].class_subs)
|
||||
info->klass[j].class_book=(unsigned char)oggpack_read(opb,8);
|
||||
else
|
||||
info->klass[j].class_book=0;
|
||||
if(info->klass[j].class_book>=ci->books)goto err_out;
|
||||
for(k=0;k<(1<<info->klass[j].class_subs);k++){
|
||||
info->klass[j].class_subbook[k]=(unsigned char)(oggpack_read(opb,8)-1);
|
||||
if(info->klass[j].class_subbook[k]>=ci->books &&
|
||||
info->klass[j].class_subbook[k]!=0xff)goto err_out;
|
||||
}
|
||||
}
|
||||
|
||||
/* read the post list */
|
||||
info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
|
||||
rangebits=oggpack_read(opb,4);
|
||||
|
||||
for(j=0,k=0;j<info->partitions;j++)
|
||||
count+=info->klass[info->partitionclass[j]].class_dim;
|
||||
info->postlist=
|
||||
(ogg_uint16_t *)_ogg_malloc((count+2)*sizeof(*info->postlist));
|
||||
info->forward_index=
|
||||
(ogg_uint8_t *)_ogg_malloc((count+2)*sizeof(*info->forward_index));
|
||||
info->loneighbor=
|
||||
(ogg_uint8_t *)_ogg_malloc(count*sizeof(*info->loneighbor));
|
||||
info->hineighbor=
|
||||
(ogg_uint8_t *)_ogg_malloc(count*sizeof(*info->hineighbor));
|
||||
|
||||
count=0;
|
||||
for(j=0,k=0;j<info->partitions;j++){
|
||||
count+=info->klass[info->partitionclass[j]].class_dim;
|
||||
for(;k<count;k++){
|
||||
int t=info->postlist[k+2]=(ogg_uint16_t)oggpack_read(opb,rangebits);
|
||||
if(t>=(1<<rangebits))goto err_out;
|
||||
}
|
||||
}
|
||||
if(oggpack_eop(opb))goto err_out;
|
||||
info->postlist[0]=0;
|
||||
info->postlist[1]=1<<rangebits;
|
||||
info->posts=count+2;
|
||||
|
||||
/* also store a sorted position index */
|
||||
for(j=0;j<info->posts;j++)info->forward_index[j]=j;
|
||||
floor1_mergesort(info->forward_index,info->postlist,info->posts);
|
||||
|
||||
/* discover our neighbors for decode where we don't use fit flags
|
||||
(that would push the neighbors outward) */
|
||||
for(j=0;j<info->posts-2;j++){
|
||||
int lo=0;
|
||||
int hi=1;
|
||||
int lx=0;
|
||||
int hx=info->postlist[1];
|
||||
int currentx=info->postlist[j+2];
|
||||
for(k=0;k<j+2;k++){
|
||||
int x=info->postlist[k];
|
||||
if(x>lx && x<currentx){
|
||||
lo=k;
|
||||
lx=x;
|
||||
}
|
||||
if(x<hx && x>currentx){
|
||||
hi=k;
|
||||
hx=x;
|
||||
}
|
||||
}
|
||||
info->loneighbor[j]=lo;
|
||||
info->hineighbor[j]=hi;
|
||||
}
|
||||
|
||||
return(info);
|
||||
|
||||
err_out:
|
||||
floor1_free_info(info);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifdef ONLY_C
|
||||
static
|
||||
#endif
|
||||
int render_point(int x0,int x1,int y0,int y1,int x){
|
||||
y0&=0x7fff; /* mask off flag */
|
||||
y1&=0x7fff;
|
||||
|
||||
{
|
||||
int dy=y1-y0;
|
||||
int adx=x1-x0;
|
||||
int ady=abs(dy);
|
||||
int err=ady*(x-x0);
|
||||
|
||||
int off=err/adx;
|
||||
if(dy<0)return(y0-off);
|
||||
return(y0+off);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef ONLY_C
|
||||
void render_lineARM(int n, ogg_int32_t *d,const ogg_int32_t *floor, int base, int err, int adx, int ady);
|
||||
#endif
|
||||
|
||||
static void render_line(int n,int x0,int x1,int y0,int y1,ogg_int32_t *d){
|
||||
int dy;
|
||||
int adx;
|
||||
int ady;
|
||||
int base;
|
||||
int err;
|
||||
const ogg_int32_t *floor;
|
||||
|
||||
if(n>x1)n=x1;
|
||||
n -= x0;
|
||||
if (n <= 0 || y0 < 0 || y0 > 255 || y1 < 0 || y1 > 255) {
|
||||
return;
|
||||
}
|
||||
dy=y1-y0;
|
||||
adx=x1-x0;
|
||||
ady=abs(dy);
|
||||
base=dy/adx;
|
||||
err=adx-1;
|
||||
floor=&FLOOR_fromdB_LOOKUP[y0];
|
||||
d += x0;
|
||||
ady-=abs(base*adx);
|
||||
|
||||
/* We should add base each time, and then:
|
||||
* if dy >=0 we occasionally add 1
|
||||
* else occasionally subtract 1.
|
||||
* As an optimisation we say that if dy <0 we make base 1 smaller.
|
||||
* Then we need to add 1 occassionally, rather than subtract 1 - but we
|
||||
* need to add 1 in all the cases when we wouldn't have done so before.
|
||||
* Previously we'd have added 1 (100*ady/adx)% of the time. Now we want
|
||||
* to do so (100*(adx-ady)/adx)% of the time.
|
||||
*/
|
||||
if (dy < 0){
|
||||
base--;
|
||||
ady = adx-ady;
|
||||
err = 0;
|
||||
}
|
||||
|
||||
//if(x<n)
|
||||
// d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]);
|
||||
|
||||
#if defined(ONLY_C)
|
||||
do{
|
||||
*d = MULT31_SHIFT15(*d,*floor);
|
||||
d++;
|
||||
floor+=base;
|
||||
err-=ady;
|
||||
if(err<0){
|
||||
err+=adx;
|
||||
floor+=1;
|
||||
}
|
||||
n--;
|
||||
} while(n>0);
|
||||
#else
|
||||
render_lineARM(n,d,floor,base,err,adx,ady);
|
||||
#endif
|
||||
}
|
||||
|
||||
int floor1_memosize(vorbis_info_floor *i){
|
||||
vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
|
||||
return info->posts;
|
||||
}
|
||||
|
||||
static int quant_look[4]={256,128,86,64};
|
||||
|
||||
ogg_int32_t *floor1_inverse1(vorbis_dsp_state *vd,vorbis_info_floor *in,
|
||||
ogg_int32_t *fit_value){
|
||||
vorbis_info_floor1 *info=(vorbis_info_floor1 *)in;
|
||||
codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
|
||||
|
||||
int i,j,k;
|
||||
codebook *books=ci->book_param;
|
||||
int quant_q=quant_look[info->mult-1];
|
||||
|
||||
/* unpack wrapped/predicted values from stream */
|
||||
if(oggpack_read(&vd->opb,1)==1){
|
||||
fit_value[0]=oggpack_read(&vd->opb,ilog(quant_q-1));
|
||||
fit_value[1]=oggpack_read(&vd->opb,ilog(quant_q-1));
|
||||
|
||||
/* partition by partition */
|
||||
/* partition by partition */
|
||||
for(i=0,j=2;i<info->partitions;i++){
|
||||
int classv=info->partitionclass[i];
|
||||
int cdim=info->klass[classv].class_dim;
|
||||
int csubbits=info->klass[classv].class_subs;
|
||||
int csub=1<<csubbits;
|
||||
int cval=0;
|
||||
|
||||
/* decode the partition's first stage cascade value */
|
||||
if(csubbits){
|
||||
cval=vorbis_book_decode(books+info->klass[classv].class_book,&vd->opb);
|
||||
|
||||
if(cval==-1)goto eop;
|
||||
}
|
||||
|
||||
for(k=0;k<cdim;k++){
|
||||
int book=info->klass[classv].class_subbook[cval&(csub-1)];
|
||||
cval>>=csubbits;
|
||||
if(book!=0xff){
|
||||
if((fit_value[j+k]=vorbis_book_decode(books+book,&vd->opb))==-1)
|
||||
goto eop;
|
||||
}else{
|
||||
fit_value[j+k]=0;
|
||||
}
|
||||
}
|
||||
j+=cdim;
|
||||
}
|
||||
|
||||
/* unwrap positive values and reconsitute via linear interpolation */
|
||||
for(i=2;i<info->posts;i++){
|
||||
int predicted=render_point(info->postlist[info->loneighbor[i-2]],
|
||||
info->postlist[info->hineighbor[i-2]],
|
||||
fit_value[info->loneighbor[i-2]],
|
||||
fit_value[info->hineighbor[i-2]],
|
||||
info->postlist[i]);
|
||||
int hiroom=quant_q-predicted;
|
||||
int loroom=predicted;
|
||||
int room=(hiroom<loroom?hiroom:loroom)<<1;
|
||||
int val=fit_value[i];
|
||||
|
||||
if(val){
|
||||
if(val>=room){
|
||||
if(hiroom>loroom){
|
||||
val = val-loroom;
|
||||
}else{
|
||||
val = -1-(val-hiroom);
|
||||
}
|
||||
}else{
|
||||
if(val&1){
|
||||
val= -((val+1)>>1);
|
||||
}else{
|
||||
val>>=1;
|
||||
}
|
||||
}
|
||||
|
||||
fit_value[i]=val+predicted;
|
||||
fit_value[info->loneighbor[i-2]]&=0x7fff;
|
||||
fit_value[info->hineighbor[i-2]]&=0x7fff;
|
||||
|
||||
}else{
|
||||
fit_value[i]=predicted|0x8000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return(fit_value);
|
||||
}
|
||||
eop:
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
int floor1_inverse2(vorbis_dsp_state *vd,vorbis_info_floor *in,
|
||||
ogg_int32_t *fit_value,ogg_int32_t *out){
|
||||
vorbis_info_floor1 *info=(vorbis_info_floor1 *)in;
|
||||
|
||||
codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
|
||||
int n=ci->blocksizes[vd->W]/2;
|
||||
int j;
|
||||
|
||||
if(fit_value){
|
||||
/* render the lines */
|
||||
int hx=0;
|
||||
int lx=0;
|
||||
int ly=fit_value[0]*info->mult;
|
||||
for(j=1;j<info->posts;j++){
|
||||
int current=info->forward_index[j];
|
||||
int hy=fit_value[current]&0x7fff;
|
||||
if(hy==fit_value[current]){
|
||||
|
||||
hy*=info->mult;
|
||||
hx=info->postlist[current];
|
||||
|
||||
render_line(n,lx,hx,ly,hy,out);
|
||||
|
||||
lx=hx;
|
||||
ly=hy;
|
||||
}
|
||||
}
|
||||
for(j=hx;j<n;j++)out[j]*=ly; /* be certain */
|
||||
return(1);
|
||||
}
|
||||
memset(out,0,sizeof(*out)*n);
|
||||
return(0);
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
@ Tremolo library
|
||||
@-----------------------------------------------------------------------
|
||||
@ Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
@ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
@ All rights reserved.
|
||||
|
||||
@ Redistribution and use in source and binary forms, with or without
|
||||
@ modification, are permitted provided that the following conditions
|
||||
@ are met:
|
||||
|
||||
@ * Redistributions of source code must retain the above copyright
|
||||
@ notice, this list of conditions and the following disclaimer.
|
||||
@ * Redistributions in binary form must reproduce the above
|
||||
@ copyright notice, this list of conditions and the following disclaimer
|
||||
@ in the documentation and/or other materials provided with the
|
||||
@ distribution.
|
||||
@ * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
@ Productions Ltd nor the names of its contributors may be used to
|
||||
@ endorse or promote products derived from this software without
|
||||
@ specific prior written permission.
|
||||
@
|
||||
@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
@ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
@ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@ ----------------------------------------------------------------------
|
||||
|
||||
.text
|
||||
|
||||
.global render_lineARM
|
||||
|
||||
render_lineARM:
|
||||
@ r0 = n
|
||||
@ r1 = d
|
||||
@ r2 = floor
|
||||
@ r3 = base
|
||||
@ <> = err
|
||||
@ <> = adx
|
||||
@ <> = ady
|
||||
MOV r12,r13
|
||||
STMFD r13!,{r4-r6,r11,r14}
|
||||
LDMFD r12,{r11,r12,r14} @ r11 = err
|
||||
@ r12 = adx
|
||||
@ r14 = ady
|
||||
rl_loop:
|
||||
LDR r4,[r1] @ r4 = *d
|
||||
LDR r5,[r2],r3,LSL #2 @ r5 = *floor r2 = floor+base
|
||||
SUBS r11,r11,r14 @ err -= ady
|
||||
ADDLT r11,r11,r12 @ if (err < 0) err+=adx
|
||||
SMULL r6, r5, r4, r5 @ (r6,r5) = *d * *floor
|
||||
ADDLT r2, r2, #4 @ floor+=1
|
||||
MOVS r6, r6, LSR #15
|
||||
ADC r5, r6, r5, LSL #17 @ r5 = MULT31_SHIFT15
|
||||
STR r5,[r1],#4
|
||||
SUBS r0, r0, #1
|
||||
BGT rl_loop
|
||||
|
||||
LDMFD r13!,{r4-r6,r11,PC}
|
||||
|
||||
@ END
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
@ Tremolo library
|
||||
@-----------------------------------------------------------------------
|
||||
@ Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
@ Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
@ All rights reserved.
|
||||
|
||||
@ Redistribution and use in source and binary forms, with or without
|
||||
@ modification, are permitted provided that the following conditions
|
||||
@ are met:
|
||||
|
||||
@ * Redistributions of source code must retain the above copyright
|
||||
@ notice, this list of conditions and the following disclaimer.
|
||||
@ * Redistributions in binary form must reproduce the above
|
||||
@ copyright notice, this list of conditions and the following disclaimer
|
||||
@ in the documentation and/or other materials provided with the
|
||||
@ distribution.
|
||||
@ * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
@ Productions Ltd nor the names of its contributors may be used to
|
||||
@ endorse or promote products derived from this software without
|
||||
@ specific prior written permission.
|
||||
@
|
||||
@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
@ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
@ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
@ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@ ----------------------------------------------------------------------
|
||||
|
||||
.text
|
||||
|
||||
.global render_lineARM
|
||||
|
||||
render_lineARM:
|
||||
@ r0 = n
|
||||
@ r1 = d
|
||||
@ r2 = floor
|
||||
@ r3 = base
|
||||
@ <> = err
|
||||
@ <> = adx
|
||||
@ <> = ady
|
||||
MOV r12,r13
|
||||
STMFD r13!,{r4-r6,r11,r14}
|
||||
LDMFD r12,{r11,r12,r14} @ r11 = err
|
||||
@ r12 = adx
|
||||
@ r14 = ady
|
||||
rl_loop:
|
||||
LDR r4, [r1] @ r4 = *d
|
||||
LDR r5, [r2], r3,LSL #2 @ r5 = *floor r2 = floor+base
|
||||
SUBS r11,r11,r14 @ err -= ady
|
||||
MOV r4, r4, ASR #6
|
||||
MUL r5, r4, r5 @ r5 = MULT31_SHIFT15
|
||||
ADDLT r11,r11,r12 @ if (err < 0) err+=adx
|
||||
ADDLT r2, r2, #4 @ floor+=1
|
||||
SUBS r0, r0, #1
|
||||
STR r5, [r1], #4
|
||||
BGT rl_loop
|
||||
|
||||
LDMFD r13!,{r4-r6,r11,PC}
|
||||
|
||||
@ END
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: floor dB lookup
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef _LOW_ACCURACY_
|
||||
# define XdB(n) ((((n)>>8)+1)>>1)
|
||||
#else
|
||||
# define XdB(n) (n)
|
||||
#endif
|
||||
|
||||
const ogg_int32_t FLOOR_fromdB_LOOKUP[256]={
|
||||
XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114),
|
||||
XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163),
|
||||
XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9),
|
||||
XdB(0x000001e7), XdB(0x00000206), XdB(0x00000228), XdB(0x0000024c),
|
||||
XdB(0x00000272), XdB(0x0000029b), XdB(0x000002c6), XdB(0x000002f4),
|
||||
XdB(0x00000326), XdB(0x0000035a), XdB(0x00000392), XdB(0x000003cd),
|
||||
XdB(0x0000040c), XdB(0x00000450), XdB(0x00000497), XdB(0x000004e4),
|
||||
XdB(0x00000535), XdB(0x0000058c), XdB(0x000005e8), XdB(0x0000064a),
|
||||
XdB(0x000006b3), XdB(0x00000722), XdB(0x00000799), XdB(0x00000818),
|
||||
XdB(0x0000089e), XdB(0x0000092e), XdB(0x000009c6), XdB(0x00000a69),
|
||||
XdB(0x00000b16), XdB(0x00000bcf), XdB(0x00000c93), XdB(0x00000d64),
|
||||
XdB(0x00000e43), XdB(0x00000f30), XdB(0x0000102d), XdB(0x0000113a),
|
||||
XdB(0x00001258), XdB(0x0000138a), XdB(0x000014cf), XdB(0x00001629),
|
||||
XdB(0x0000179a), XdB(0x00001922), XdB(0x00001ac4), XdB(0x00001c82),
|
||||
XdB(0x00001e5c), XdB(0x00002055), XdB(0x0000226f), XdB(0x000024ac),
|
||||
XdB(0x0000270e), XdB(0x00002997), XdB(0x00002c4b), XdB(0x00002f2c),
|
||||
XdB(0x0000323d), XdB(0x00003581), XdB(0x000038fb), XdB(0x00003caf),
|
||||
XdB(0x000040a0), XdB(0x000044d3), XdB(0x0000494c), XdB(0x00004e10),
|
||||
XdB(0x00005323), XdB(0x0000588a), XdB(0x00005e4b), XdB(0x0000646b),
|
||||
XdB(0x00006af2), XdB(0x000071e5), XdB(0x0000794c), XdB(0x0000812e),
|
||||
XdB(0x00008993), XdB(0x00009283), XdB(0x00009c09), XdB(0x0000a62d),
|
||||
XdB(0x0000b0f9), XdB(0x0000bc79), XdB(0x0000c8b9), XdB(0x0000d5c4),
|
||||
XdB(0x0000e3a9), XdB(0x0000f274), XdB(0x00010235), XdB(0x000112fd),
|
||||
XdB(0x000124dc), XdB(0x000137e4), XdB(0x00014c29), XdB(0x000161bf),
|
||||
XdB(0x000178bc), XdB(0x00019137), XdB(0x0001ab4a), XdB(0x0001c70e),
|
||||
XdB(0x0001e4a1), XdB(0x0002041f), XdB(0x000225aa), XdB(0x00024962),
|
||||
XdB(0x00026f6d), XdB(0x000297f0), XdB(0x0002c316), XdB(0x0002f109),
|
||||
XdB(0x000321f9), XdB(0x00035616), XdB(0x00038d97), XdB(0x0003c8b4),
|
||||
XdB(0x000407a7), XdB(0x00044ab2), XdB(0x00049218), XdB(0x0004de23),
|
||||
XdB(0x00052f1e), XdB(0x0005855c), XdB(0x0005e135), XdB(0x00064306),
|
||||
XdB(0x0006ab33), XdB(0x00071a24), XdB(0x0007904b), XdB(0x00080e20),
|
||||
XdB(0x00089422), XdB(0x000922da), XdB(0x0009bad8), XdB(0x000a5cb6),
|
||||
XdB(0x000b091a), XdB(0x000bc0b1), XdB(0x000c8436), XdB(0x000d5471),
|
||||
XdB(0x000e3233), XdB(0x000f1e5f), XdB(0x001019e4), XdB(0x001125c1),
|
||||
XdB(0x00124306), XdB(0x001372d5), XdB(0x0014b663), XdB(0x00160ef7),
|
||||
XdB(0x00177df0), XdB(0x001904c1), XdB(0x001aa4f9), XdB(0x001c603d),
|
||||
XdB(0x001e384f), XdB(0x00202f0f), XdB(0x0022467a), XdB(0x002480b1),
|
||||
XdB(0x0026dff7), XdB(0x002966b3), XdB(0x002c1776), XdB(0x002ef4fc),
|
||||
XdB(0x0032022d), XdB(0x00354222), XdB(0x0038b828), XdB(0x003c67c2),
|
||||
XdB(0x004054ae), XdB(0x004482e8), XdB(0x0048f6af), XdB(0x004db488),
|
||||
XdB(0x0052c142), XdB(0x005821ff), XdB(0x005ddc33), XdB(0x0063f5b0),
|
||||
XdB(0x006a74a7), XdB(0x00715faf), XdB(0x0078bdce), XdB(0x0080967f),
|
||||
XdB(0x0088f1ba), XdB(0x0091d7f9), XdB(0x009b5247), XdB(0x00a56a41),
|
||||
XdB(0x00b02a27), XdB(0x00bb9ce2), XdB(0x00c7ce12), XdB(0x00d4ca17),
|
||||
XdB(0x00e29e20), XdB(0x00f15835), XdB(0x0101074b), XdB(0x0111bb4e),
|
||||
XdB(0x01238531), XdB(0x01367704), XdB(0x014aa402), XdB(0x016020a7),
|
||||
XdB(0x017702c3), XdB(0x018f6190), XdB(0x01a955cb), XdB(0x01c4f9cf),
|
||||
XdB(0x01e269a8), XdB(0x0201c33b), XdB(0x0223265a), XdB(0x0246b4ea),
|
||||
XdB(0x026c9302), XdB(0x0294e716), XdB(0x02bfda13), XdB(0x02ed9793),
|
||||
XdB(0x031e4e09), XdB(0x03522ee4), XdB(0x03896ed0), XdB(0x03c445e2),
|
||||
XdB(0x0402efd6), XdB(0x0445ac4b), XdB(0x048cbefc), XdB(0x04d87013),
|
||||
XdB(0x05290c67), XdB(0x057ee5ca), XdB(0x05da5364), XdB(0x063bb204),
|
||||
XdB(0x06a36485), XdB(0x0711d42b), XdB(0x0787710e), XdB(0x0804b299),
|
||||
XdB(0x088a17ef), XdB(0x0918287e), XdB(0x09af747c), XdB(0x0a50957e),
|
||||
XdB(0x0afc2f19), XdB(0x0bb2ef7f), XdB(0x0c759034), XdB(0x0d44d6ca),
|
||||
XdB(0x0e2195bc), XdB(0x0f0cad0d), XdB(0x10070b62), XdB(0x1111aeea),
|
||||
XdB(0x122da66c), XdB(0x135c120f), XdB(0x149e24d9), XdB(0x15f525b1),
|
||||
XdB(0x176270e3), XdB(0x18e7794b), XdB(0x1a85c9ae), XdB(0x1c3f06d1),
|
||||
XdB(0x1e14f07d), XdB(0x200963d7), XdB(0x221e5ccd), XdB(0x2455f870),
|
||||
XdB(0x26b2770b), XdB(0x29363e2b), XdB(0x2be3db5c), XdB(0x2ebe06b6),
|
||||
XdB(0x31c7a55b), XdB(0x3503ccd4), XdB(0x3875c5aa), XdB(0x3c210f44),
|
||||
XdB(0x4009632b), XdB(0x4432b8cf), XdB(0x48a149bc), XdB(0x4d59959e),
|
||||
XdB(0x52606733), XdB(0x57bad899), XdB(0x5d6e593a), XdB(0x6380b298),
|
||||
XdB(0x69f80e9a), XdB(0x70dafda8), XdB(0x78307d76), XdB(0x7fffffff),
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,124 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: libvorbis codec headers
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _vorbis_codec_h_
|
||||
#define _vorbis_codec_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "ogg.h"
|
||||
|
||||
struct vorbis_dsp_state;
|
||||
typedef struct vorbis_dsp_state vorbis_dsp_state;
|
||||
|
||||
typedef struct vorbis_info{
|
||||
int version;
|
||||
int channels;
|
||||
long rate;
|
||||
|
||||
/* The below bitrate declarations are *hints*.
|
||||
Combinations of the three values carry the following implications:
|
||||
|
||||
all three set to the same value:
|
||||
implies a fixed rate bitstream
|
||||
only nominal set:
|
||||
implies a VBR stream that averages the nominal bitrate. No hard
|
||||
upper/lower limit
|
||||
upper and or lower set:
|
||||
implies a VBR bitstream that obeys the bitrate limits. nominal
|
||||
may also be set to give a nominal rate.
|
||||
none set:
|
||||
the coder does not care to speculate.
|
||||
*/
|
||||
|
||||
long bitrate_upper;
|
||||
long bitrate_nominal;
|
||||
long bitrate_lower;
|
||||
long bitrate_window;
|
||||
|
||||
void *codec_setup;
|
||||
} vorbis_info;
|
||||
|
||||
typedef struct vorbis_comment{
|
||||
char **user_comments;
|
||||
int *comment_lengths;
|
||||
int comments;
|
||||
char *vendor;
|
||||
|
||||
} vorbis_comment;
|
||||
|
||||
|
||||
/* Vorbis PRIMITIVES: general ***************************************/
|
||||
|
||||
extern void vorbis_info_init(vorbis_info *vi);
|
||||
extern void vorbis_info_clear(vorbis_info *vi);
|
||||
extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
|
||||
extern void vorbis_comment_init(vorbis_comment *vc);
|
||||
extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
|
||||
extern void vorbis_comment_add_tag(vorbis_comment *vc,
|
||||
char *tag, char *contents);
|
||||
extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
|
||||
extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
|
||||
extern void vorbis_comment_clear(vorbis_comment *vc);
|
||||
|
||||
/* Vorbis ERRORS and return codes ***********************************/
|
||||
|
||||
#define OV_FALSE -1
|
||||
#define OV_EOF -2
|
||||
#define OV_HOLE -3
|
||||
|
||||
#define OV_EREAD -128
|
||||
#define OV_EFAULT -129
|
||||
#define OV_EIMPL -130
|
||||
#define OV_EINVAL -131
|
||||
#define OV_ENOTVORBIS -132
|
||||
#define OV_EBADHEADER -133
|
||||
#define OV_EVERSION -134
|
||||
#define OV_ENOTAUDIO -135
|
||||
#define OV_EBADPACKET -136
|
||||
#define OV_EBADLINK -137
|
||||
#define OV_ENOSEEK -138
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: stdio-based convenience library for opening/seeking/decoding
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _OV_FILE_H_
|
||||
#define _OV_FILE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ivorbiscodec.h"
|
||||
|
||||
/* The function prototypes for the callbacks are basically the same as for
|
||||
* the stdio functions fread, fseek, fclose, ftell.
|
||||
* The one difference is that the FILE * arguments have been replaced with
|
||||
* a void * - this is to be used as a pointer to whatever internal data these
|
||||
* functions might need. In the stdio case, it's just a FILE * cast to a void *
|
||||
*
|
||||
* If you use other functions, check the docs for these functions and return
|
||||
* the right values. For seek_func(), you *MUST* return -1 if the stream is
|
||||
* unseekable
|
||||
*/
|
||||
typedef struct {
|
||||
size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
|
||||
int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
|
||||
int (*close_func) (void *datasource);
|
||||
long (*tell_func) (void *datasource);
|
||||
} ov_callbacks;
|
||||
|
||||
typedef struct OggVorbis_File {
|
||||
void *datasource; /* Pointer to a FILE *, etc. */
|
||||
int seekable;
|
||||
ogg_int64_t offset;
|
||||
ogg_int64_t end;
|
||||
ogg_sync_state *oy;
|
||||
|
||||
/* If the FILE handle isn't seekable (eg, a pipe), only the current
|
||||
stream appears */
|
||||
int links;
|
||||
ogg_int64_t *offsets;
|
||||
ogg_int64_t *dataoffsets;
|
||||
ogg_uint32_t *serialnos;
|
||||
ogg_int64_t *pcmlengths;
|
||||
vorbis_info vi;
|
||||
vorbis_comment vc;
|
||||
|
||||
/* Decoding working state local storage */
|
||||
ogg_int64_t pcm_offset;
|
||||
int ready_state;
|
||||
ogg_uint32_t current_serialno;
|
||||
int current_link;
|
||||
|
||||
ogg_int64_t bittrack;
|
||||
ogg_int64_t samptrack;
|
||||
|
||||
ogg_stream_state *os; /* take physical pages, weld into a logical
|
||||
stream of packets */
|
||||
vorbis_dsp_state *vd; /* central working state for the packet->PCM decoder */
|
||||
|
||||
ov_callbacks callbacks;
|
||||
|
||||
} OggVorbis_File;
|
||||
|
||||
extern int ov_clear(OggVorbis_File *vf);
|
||||
extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
|
||||
extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
|
||||
char *initial, long ibytes, ov_callbacks callbacks);
|
||||
|
||||
extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
|
||||
extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
|
||||
char *initial, long ibytes, ov_callbacks callbacks);
|
||||
extern int ov_test_open(OggVorbis_File *vf);
|
||||
|
||||
extern long ov_bitrate(OggVorbis_File *vf,int i);
|
||||
extern long ov_bitrate_instant(OggVorbis_File *vf);
|
||||
extern long ov_streams(OggVorbis_File *vf);
|
||||
extern long ov_seekable(OggVorbis_File *vf);
|
||||
extern long ov_serialnumber(OggVorbis_File *vf,int i);
|
||||
|
||||
extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
|
||||
extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
|
||||
extern ogg_int64_t ov_time_total(OggVorbis_File *vf,int i);
|
||||
|
||||
extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
|
||||
extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
|
||||
extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
|
||||
extern int ov_time_seek(OggVorbis_File *vf,ogg_int64_t pos);
|
||||
extern int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
|
||||
|
||||
extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
|
||||
extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
|
||||
extern ogg_int64_t ov_time_tell(OggVorbis_File *vf);
|
||||
|
||||
extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
|
||||
extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
|
||||
|
||||
extern long ov_read(OggVorbis_File *vf,void *buffer,int length,
|
||||
int *bitstream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: lookup data
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _V_LOOKUP_DATA_H_
|
||||
#define _V_LOOKUP_DATA_H_
|
||||
|
||||
#include "os_types.h"
|
||||
|
||||
#define INVSQ_LOOKUP_I_SHIFT 10
|
||||
#define INVSQ_LOOKUP_I_MASK 1023
|
||||
static const long INVSQ_LOOKUP_I[64+1]={
|
||||
92682, 91966, 91267, 90583,
|
||||
89915, 89261, 88621, 87995,
|
||||
87381, 86781, 86192, 85616,
|
||||
85051, 84497, 83953, 83420,
|
||||
82897, 82384, 81880, 81385,
|
||||
80899, 80422, 79953, 79492,
|
||||
79039, 78594, 78156, 77726,
|
||||
77302, 76885, 76475, 76072,
|
||||
75674, 75283, 74898, 74519,
|
||||
74146, 73778, 73415, 73058,
|
||||
72706, 72359, 72016, 71679,
|
||||
71347, 71019, 70695, 70376,
|
||||
70061, 69750, 69444, 69141,
|
||||
68842, 68548, 68256, 67969,
|
||||
67685, 67405, 67128, 66855,
|
||||
66585, 66318, 66054, 65794,
|
||||
65536,
|
||||
};
|
||||
|
||||
static const long INVSQ_LOOKUP_IDel[64]={
|
||||
716, 699, 684, 668,
|
||||
654, 640, 626, 614,
|
||||
600, 589, 576, 565,
|
||||
554, 544, 533, 523,
|
||||
513, 504, 495, 486,
|
||||
477, 469, 461, 453,
|
||||
445, 438, 430, 424,
|
||||
417, 410, 403, 398,
|
||||
391, 385, 379, 373,
|
||||
368, 363, 357, 352,
|
||||
347, 343, 337, 332,
|
||||
328, 324, 319, 315,
|
||||
311, 306, 303, 299,
|
||||
294, 292, 287, 284,
|
||||
280, 277, 273, 270,
|
||||
267, 264, 260, 258,
|
||||
};
|
||||
|
||||
#define COS_LOOKUP_I_SHIFT 9
|
||||
#define COS_LOOKUP_I_MASK 511
|
||||
#define COS_LOOKUP_I_SZ 128
|
||||
static const ogg_int32_t COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
|
||||
16384, 16379, 16364, 16340,
|
||||
16305, 16261, 16207, 16143,
|
||||
16069, 15986, 15893, 15791,
|
||||
15679, 15557, 15426, 15286,
|
||||
15137, 14978, 14811, 14635,
|
||||
14449, 14256, 14053, 13842,
|
||||
13623, 13395, 13160, 12916,
|
||||
12665, 12406, 12140, 11866,
|
||||
11585, 11297, 11003, 10702,
|
||||
10394, 10080, 9760, 9434,
|
||||
9102, 8765, 8423, 8076,
|
||||
7723, 7366, 7005, 6639,
|
||||
6270, 5897, 5520, 5139,
|
||||
4756, 4370, 3981, 3590,
|
||||
3196, 2801, 2404, 2006,
|
||||
1606, 1205, 804, 402,
|
||||
0, -401, -803, -1204,
|
||||
-1605, -2005, -2403, -2800,
|
||||
-3195, -3589, -3980, -4369,
|
||||
-4755, -5138, -5519, -5896,
|
||||
-6269, -6638, -7004, -7365,
|
||||
-7722, -8075, -8422, -8764,
|
||||
-9101, -9433, -9759, -10079,
|
||||
-10393, -10701, -11002, -11296,
|
||||
-11584, -11865, -12139, -12405,
|
||||
-12664, -12915, -13159, -13394,
|
||||
-13622, -13841, -14052, -14255,
|
||||
-14448, -14634, -14810, -14977,
|
||||
-15136, -15285, -15425, -15556,
|
||||
-15678, -15790, -15892, -15985,
|
||||
-16068, -16142, -16206, -16260,
|
||||
-16304, -16339, -16363, -16378,
|
||||
-16383,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: channel mapping 0 implementation
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "ogg.h"
|
||||
#include "os.h"
|
||||
#include "ivorbiscodec.h"
|
||||
#include "mdct.h"
|
||||
#include "codec_internal.h"
|
||||
#include "codebook.h"
|
||||
#include "misc.h"
|
||||
|
||||
void mapping_clear_info(vorbis_info_mapping *info){
|
||||
if(info){
|
||||
if(info->chmuxlist)_ogg_free(info->chmuxlist);
|
||||
if(info->submaplist)_ogg_free(info->submaplist);
|
||||
if(info->coupling)_ogg_free(info->coupling);
|
||||
memset(info,0,sizeof(*info));
|
||||
}
|
||||
}
|
||||
|
||||
static int ilog(unsigned int v){
|
||||
int ret=0;
|
||||
if(v)--v;
|
||||
while(v){
|
||||
ret++;
|
||||
v>>=1;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/* also responsible for range checking */
|
||||
int mapping_info_unpack(vorbis_info_mapping *info,vorbis_info *vi,
|
||||
oggpack_buffer *opb){
|
||||
int i;
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
memset(info,0,sizeof(*info));
|
||||
|
||||
if(oggpack_read(opb,1))
|
||||
info->submaps=oggpack_read(opb,4)+1;
|
||||
else
|
||||
info->submaps=1;
|
||||
|
||||
if(oggpack_read(opb,1)){
|
||||
info->coupling_steps=oggpack_read(opb,8)+1;
|
||||
info->coupling=
|
||||
_ogg_malloc(info->coupling_steps*sizeof(*info->coupling));
|
||||
|
||||
for(i=0;i<info->coupling_steps;i++){
|
||||
int testM=info->coupling[i].mag=(unsigned char)(oggpack_read(opb,ilog(vi->channels)));
|
||||
int testA=info->coupling[i].ang=(unsigned char)(oggpack_read(opb,ilog(vi->channels)));
|
||||
|
||||
if(testM<0 ||
|
||||
testA<0 ||
|
||||
testM==testA ||
|
||||
testM>=vi->channels ||
|
||||
testA>=vi->channels) goto err_out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
|
||||
|
||||
if(info->submaps>1){
|
||||
info->chmuxlist=_ogg_malloc(sizeof(*info->chmuxlist)*vi->channels);
|
||||
for(i=0;i<vi->channels;i++){
|
||||
info->chmuxlist[i]=(unsigned char)(oggpack_read(opb,4));
|
||||
if(info->chmuxlist[i]>=info->submaps)goto err_out;
|
||||
}
|
||||
}
|
||||
|
||||
info->submaplist=_ogg_malloc(sizeof(*info->submaplist)*info->submaps);
|
||||
for(i=0;i<info->submaps;i++){
|
||||
int temp=oggpack_read(opb,8);
|
||||
info->submaplist[i].floor=(char)oggpack_read(opb,8);
|
||||
if(info->submaplist[i].floor>=ci->floors)goto err_out;
|
||||
info->submaplist[i].residue=(char)oggpack_read(opb,8);
|
||||
if(info->submaplist[i].residue>=ci->residues)goto err_out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_out:
|
||||
mapping_clear_info(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mapping_inverse(vorbis_dsp_state *vd,vorbis_info_mapping *info){
|
||||
vorbis_info *vi=vd->vi;
|
||||
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
||||
|
||||
int i,j;
|
||||
long n=ci->blocksizes[vd->W];
|
||||
|
||||
ogg_int32_t **pcmbundle=
|
||||
alloca(sizeof(*pcmbundle)*vi->channels);
|
||||
int *zerobundle=
|
||||
alloca(sizeof(*zerobundle)*vi->channels);
|
||||
int *nonzero=
|
||||
alloca(sizeof(*nonzero)*vi->channels);
|
||||
ogg_int32_t **floormemo=
|
||||
alloca(sizeof(*floormemo)*vi->channels);
|
||||
|
||||
/* recover the spectral envelope; store it in the PCM vector for now */
|
||||
for(i=0;i<vi->channels;i++){
|
||||
int submap=0;
|
||||
int floorno;
|
||||
|
||||
if(info->submaps>1)
|
||||
submap=info->chmuxlist[i];
|
||||
floorno=info->submaplist[submap].floor;
|
||||
|
||||
if(ci->floor_type[floorno]){
|
||||
/* floor 1 */
|
||||
floormemo[i]=alloca(sizeof(*floormemo[i])*
|
||||
floor1_memosize(ci->floor_param[floorno]));
|
||||
floormemo[i]=floor1_inverse1(vd,ci->floor_param[floorno],floormemo[i]);
|
||||
}else{
|
||||
/* floor 0 */
|
||||
floormemo[i]=alloca(sizeof(*floormemo[i])*
|
||||
floor0_memosize(ci->floor_param[floorno]));
|
||||
floormemo[i]=floor0_inverse1(vd,ci->floor_param[floorno],floormemo[i]);
|
||||
}
|
||||
|
||||
if(floormemo[i])
|
||||
nonzero[i]=1;
|
||||
else
|
||||
nonzero[i]=0;
|
||||
memset(vd->work[i],0,sizeof(*vd->work[i])*n/2);
|
||||
}
|
||||
|
||||
/* channel coupling can 'dirty' the nonzero listing */
|
||||
for(i=0;i<info->coupling_steps;i++){
|
||||
if(nonzero[info->coupling[i].mag] ||
|
||||
nonzero[info->coupling[i].ang]){
|
||||
nonzero[info->coupling[i].mag]=1;
|
||||
nonzero[info->coupling[i].ang]=1;
|
||||
}
|
||||
}
|
||||
|
||||
/* recover the residue into our working vectors */
|
||||
for(i=0;i<info->submaps;i++){
|
||||
int ch_in_bundle=0;
|
||||
for(j=0;j<vi->channels;j++){
|
||||
if(!info->chmuxlist || info->chmuxlist[j]==i){
|
||||
if(nonzero[j])
|
||||
zerobundle[ch_in_bundle]=1;
|
||||
else
|
||||
zerobundle[ch_in_bundle]=0;
|
||||
pcmbundle[ch_in_bundle++]=vd->work[j];
|
||||
}
|
||||
}
|
||||
|
||||
res_inverse(vd,ci->residue_param+info->submaplist[i].residue,
|
||||
pcmbundle,zerobundle,ch_in_bundle);
|
||||
}
|
||||
|
||||
//for(j=0;j<vi->channels;j++)
|
||||
//_analysis_output("coupled",seq+j,vb->pcm[j],-8,n/2,0,0);
|
||||
|
||||
/* channel coupling */
|
||||
for(i=info->coupling_steps-1;i>=0;i--){
|
||||
ogg_int32_t *pcmM=vd->work[info->coupling[i].mag];
|
||||
ogg_int32_t *pcmA=vd->work[info->coupling[i].ang];
|
||||
|
||||
for(j=0;j<n/2;j++){
|
||||
ogg_int32_t mag=pcmM[j];
|
||||
ogg_int32_t ang=pcmA[j];
|
||||
|
||||
if(mag>0)
|
||||
if(ang>0){
|
||||
pcmM[j]=mag;
|
||||
pcmA[j]=mag-ang;
|
||||
}else{
|
||||
pcmA[j]=mag;
|
||||
pcmM[j]=mag+ang;
|
||||
}
|
||||
else
|
||||
if(ang>0){
|
||||
pcmM[j]=mag;
|
||||
pcmA[j]=mag+ang;
|
||||
}else{
|
||||
pcmA[j]=mag;
|
||||
pcmM[j]=mag-ang;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for(j=0;j<vi->channels;j++)
|
||||
//_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0);
|
||||
|
||||
/* compute and apply spectral envelope */
|
||||
for(i=0;i<vi->channels;i++){
|
||||
ogg_int32_t *pcm=vd->work[i];
|
||||
int submap=0;
|
||||
int floorno;
|
||||
|
||||
if(info->submaps>1)
|
||||
submap=info->chmuxlist[i];
|
||||
floorno=info->submaplist[submap].floor;
|
||||
|
||||
if(ci->floor_type[floorno]){
|
||||
/* floor 1 */
|
||||
floor1_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm);
|
||||
}else{
|
||||
/* floor 0 */
|
||||
floor0_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm);
|
||||
}
|
||||
}
|
||||
|
||||
//for(j=0;j<vi->channels;j++)
|
||||
//_analysis_output("mdct",seq+j,vb->pcm[j],-24,n/2,0,1);
|
||||
|
||||
/* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
|
||||
/* only MDCT right now.... */
|
||||
for(i=0;i<vi->channels;i++)
|
||||
mdct_backward(n,vd->work[i]);
|
||||
|
||||
//for(j=0;j<vi->channels;j++)
|
||||
//_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0);
|
||||
|
||||
/* all done! */
|
||||
return(0);
|
||||
}
|
||||
|
|
@ -0,0 +1,582 @@
|
|||
/************************************************************************
|
||||
* Copyright (C) 2002-2009, Xiph.org Foundation
|
||||
* Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the names of the Xiph.org Foundation nor Pinknoise
|
||||
* Productions Ltd nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************
|
||||
|
||||
function: normalized modified discrete cosine transform
|
||||
power of two length transform only [64 <= n ]
|
||||
last mod: $Id: mdct.c,v 1.9.6.5 2003/04/29 04:03:27 xiphmont Exp $
|
||||
|
||||
Original algorithm adapted long ago from _The use of multirate filter
|
||||
banks for coding of high quality digital audio_, by T. Sporer,
|
||||
K. Brandenburg and B. Edler, collection of the European Signal
|
||||
Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp
|
||||
211-214
|
||||
|
||||
The below code implements an algorithm that no longer looks much like
|
||||
that presented in the paper, but the basic structure remains if you
|
||||
dig deep enough to see it.
|
||||
|
||||
This module DOES NOT INCLUDE code to generate/apply the window
|
||||
function. Everybody has their own weird favorite including me... I
|
||||
happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
|
||||
vehemently disagree.
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include "ivorbiscodec.h"
|
||||
#include "os.h"
|
||||
#include "misc.h"
|
||||
#include "mdct.h"
|
||||
#include "mdct_lookup.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(ONLY_C)
|
||||
STIN void presymmetry(DATA_TYPE *in,int n2,int step){
|
||||
DATA_TYPE *aX;
|
||||
DATA_TYPE *bX;
|
||||
LOOKUP_T *T;
|
||||
int n4=n2>>1;
|
||||
|
||||
aX = in+n2-3;
|
||||
T = sincos_lookup0;
|
||||
|
||||
do{
|
||||
REG_TYPE s0= aX[0];
|
||||
REG_TYPE s2= aX[2];
|
||||
XPROD31( s0, s2, T[0], T[1], &aX[0], &aX[2] ); T+=step;
|
||||
aX-=4;
|
||||
}while(aX>=in+n4);
|
||||
do{
|
||||
REG_TYPE s0= aX[0];
|
||||
REG_TYPE s2= aX[2];
|
||||
XPROD31( s0, s2, T[1], T[0], &aX[0], &aX[2] ); T-=step;
|
||||
aX-=4;
|
||||
}while(aX>=in);
|
||||
|
||||
aX = in+n2-4;
|
||||
bX = in;
|
||||
T = sincos_lookup0;
|
||||
do{
|
||||
REG_TYPE ri0= aX[0];
|
||||
REG_TYPE ri2= aX[2];
|
||||
REG_TYPE ro0= bX[0];
|
||||
REG_TYPE ro2= bX[2];
|
||||
|
||||
XNPROD31( ro2, ro0, T[1], T[0], &aX[0], &aX[2] ); T+=step;
|
||||
XNPROD31( ri2, ri0, T[0], T[1], &bX[0], &bX[2] );
|
||||
|
||||
aX-=4;
|
||||
bX+=4;
|
||||
}while(aX>=bX);
|
||||
}
|
||||
|
||||
/* 8 point butterfly (in place) */
|
||||
STIN void mdct_butterfly_8(DATA_TYPE *x){
|
||||
|
||||
REG_TYPE s0 = x[0] + x[1];
|
||||
REG_TYPE s1 = x[0] - x[1];
|
||||
REG_TYPE s2 = x[2] + x[3];
|
||||
REG_TYPE s3 = x[2] - x[3];
|
||||
REG_TYPE s4 = x[4] + x[5];
|
||||
REG_TYPE s5 = x[4] - x[5];
|
||||
REG_TYPE s6 = x[6] + x[7];
|
||||
REG_TYPE s7 = x[6] - x[7];
|
||||
|
||||
x[0] = s5 + s3;
|
||||
x[1] = s7 - s1;
|
||||
x[2] = s5 - s3;
|
||||
x[3] = s7 + s1;
|
||||
x[4] = s4 - s0;
|
||||
x[5] = s6 - s2;
|
||||
x[6] = s4 + s0;
|
||||
x[7] = s6 + s2;
|
||||
MB();
|
||||
}
|
||||
|
||||
/* 16 point butterfly (in place, 4 register) */
|
||||
STIN void mdct_butterfly_16(DATA_TYPE *x){
|
||||
|
||||
REG_TYPE s0, s1, s2, s3;
|
||||
|
||||
s0 = x[ 8] - x[ 9]; x[ 8] += x[ 9];
|
||||
s1 = x[10] - x[11]; x[10] += x[11];
|
||||
s2 = x[ 1] - x[ 0]; x[ 9] = x[ 1] + x[0];
|
||||
s3 = x[ 3] - x[ 2]; x[11] = x[ 3] + x[2];
|
||||
x[ 0] = MULT31((s0 - s1) , cPI2_8);
|
||||
x[ 1] = MULT31((s2 + s3) , cPI2_8);
|
||||
x[ 2] = MULT31((s0 + s1) , cPI2_8);
|
||||
x[ 3] = MULT31((s3 - s2) , cPI2_8);
|
||||
MB();
|
||||
|
||||
s2 = x[12] - x[13]; x[12] += x[13];
|
||||
s3 = x[14] - x[15]; x[14] += x[15];
|
||||
s0 = x[ 4] - x[ 5]; x[13] = x[ 5] + x[ 4];
|
||||
s1 = x[ 7] - x[ 6]; x[15] = x[ 7] + x[ 6];
|
||||
x[ 4] = s2; x[ 5] = s1;
|
||||
x[ 6] = s3; x[ 7] = s0;
|
||||
MB();
|
||||
|
||||
mdct_butterfly_8(x);
|
||||
mdct_butterfly_8(x+8);
|
||||
}
|
||||
|
||||
/* 32 point butterfly (in place, 4 register) */
|
||||
STIN void mdct_butterfly_32(DATA_TYPE *x){
|
||||
|
||||
REG_TYPE s0, s1, s2, s3;
|
||||
|
||||
s0 = x[16] - x[17]; x[16] += x[17];
|
||||
s1 = x[18] - x[19]; x[18] += x[19];
|
||||
s2 = x[ 1] - x[ 0]; x[17] = x[ 1] + x[ 0];
|
||||
s3 = x[ 3] - x[ 2]; x[19] = x[ 3] + x[ 2];
|
||||
XNPROD31( s0, s1, cPI3_8, cPI1_8, &x[ 0], &x[ 2] );
|
||||
XPROD31 ( s2, s3, cPI1_8, cPI3_8, &x[ 1], &x[ 3] );
|
||||
MB();
|
||||
|
||||
s0 = x[20] - x[21]; x[20] += x[21];
|
||||
s1 = x[22] - x[23]; x[22] += x[23];
|
||||
s2 = x[ 5] - x[ 4]; x[21] = x[ 5] + x[ 4];
|
||||
s3 = x[ 7] - x[ 6]; x[23] = x[ 7] + x[ 6];
|
||||
x[ 4] = MULT31((s0 - s1) , cPI2_8);
|
||||
x[ 5] = MULT31((s3 + s2) , cPI2_8);
|
||||
x[ 6] = MULT31((s0 + s1) , cPI2_8);
|
||||
x[ 7] = MULT31((s3 - s2) , cPI2_8);
|
||||
MB();
|
||||
|
||||
s0 = x[24] - x[25]; x[24] += x[25];
|
||||
s1 = x[26] - x[27]; x[26] += x[27];
|
||||
s2 = x[ 9] - x[ 8]; x[25] = x[ 9] + x[ 8];
|
||||
s3 = x[11] - x[10]; x[27] = x[11] + x[10];
|
||||
XNPROD31( s0, s1, cPI1_8, cPI3_8, &x[ 8], &x[10] );
|
||||
XPROD31 ( s2, s3, cPI3_8, cPI1_8, &x[ 9], &x[11] );
|
||||
MB();
|
||||
|
||||
s0 = x[28] - x[29]; x[28] += x[29];
|
||||
s1 = x[30] - x[31]; x[30] += x[31];
|
||||
s2 = x[12] - x[13]; x[29] = x[13] + x[12];
|
||||
s3 = x[15] - x[14]; x[31] = x[15] + x[14];
|
||||
x[12] = s0; x[13] = s3;
|
||||
x[14] = s1; x[15] = s2;
|
||||
MB();
|
||||
|
||||
mdct_butterfly_16(x);
|
||||
mdct_butterfly_16(x+16);
|
||||
}
|
||||
|
||||
/* N/stage point generic N stage butterfly (in place, 2 register) */
|
||||
STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){
|
||||
LOOKUP_T *T = sincos_lookup0;
|
||||
DATA_TYPE *x1 = x + points - 4;
|
||||
DATA_TYPE *x2 = x + (points>>1) - 4;
|
||||
REG_TYPE s0, s1, s2, s3;
|
||||
|
||||
do{
|
||||
s0 = x1[0] - x1[1]; x1[0] += x1[1];
|
||||
s1 = x1[3] - x1[2]; x1[2] += x1[3];
|
||||
s2 = x2[1] - x2[0]; x1[1] = x2[1] + x2[0];
|
||||
s3 = x2[3] - x2[2]; x1[3] = x2[3] + x2[2];
|
||||
XPROD31( s1, s0, T[0], T[1], &x2[0], &x2[2] );
|
||||
XPROD31( s2, s3, T[0], T[1], &x2[1], &x2[3] ); T+=step;
|
||||
x1-=4;
|
||||
x2-=4;
|
||||
}while(T<sincos_lookup0+1024);
|
||||
x1 = x + (points>>1) + (points>>2) - 4;
|
||||
x2 = x + (points>>2) - 4;
|
||||
T = sincos_lookup0+1024;
|
||||
do{
|
||||
s0 = x1[0] - x1[1]; x1[0] += x1[1];
|
||||
s1 = x1[2] - x1[3]; x1[2] += x1[3];
|
||||
s2 = x2[0] - x2[1]; x1[1] = x2[1] + x2[0];
|
||||
s3 = x2[3] - x2[2]; x1[3] = x2[3] + x2[2];
|
||||
XNPROD31( s0, s1, T[0], T[1], &x2[0], &x2[2] );
|
||||
XNPROD31( s3, s2, T[0], T[1], &x2[1], &x2[3] ); T-=step;
|
||||
x1-=4;
|
||||
x2-=4;
|
||||
}while(T>sincos_lookup0);
|
||||
}
|
||||
|
||||
STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){
|
||||
|
||||
int stages=7-shift;
|
||||
int i,j;
|
||||
|
||||
for(i=0;--stages>=0;i++){
|
||||
for(j=0;j<(1<<i);j++)
|
||||
{
|
||||
mdct_butterfly_generic(x+(points>>i)*j,points>>i,4<<(i+shift));
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<points;j+=32)
|
||||
mdct_butterfly_32(x+j);
|
||||
}
|
||||
|
||||
static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
|
||||
|
||||
STIN int bitrev12(int x){
|
||||
return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8);
|
||||
}
|
||||
|
||||
STIN void mdct_bitreverse(DATA_TYPE *x,int n,int shift){
|
||||
int bit = 0;
|
||||
DATA_TYPE *w = x+(n>>1);
|
||||
|
||||
do{
|
||||
DATA_TYPE b = bitrev12(bit++);
|
||||
DATA_TYPE *xx = x + (b>>shift);
|
||||
REG_TYPE r;
|
||||
|
||||
w -= 2;
|
||||
|
||||
if(w>xx){
|
||||
|
||||
r = xx[0];
|
||||
xx[0] = w[0];
|
||||
w[0] = r;
|
||||
|
||||
r = xx[1];
|
||||
xx[1] = w[1];
|
||||
w[1] = r;
|
||||
}
|
||||
}while(w>x);
|
||||
}
|
||||
|
||||
STIN void mdct_step7(DATA_TYPE *x,int n,int step){
|
||||
DATA_TYPE *w0 = x;
|
||||
DATA_TYPE *w1 = x+(n>>1);
|
||||
LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
|
||||
LOOKUP_T *Ttop = T+1024;
|
||||
REG_TYPE s0, s1, s2, s3;
|
||||
|
||||
do{
|
||||
w1 -= 2;
|
||||
|
||||
s0 = w0[0] + w1[0];
|
||||
s1 = w1[1] - w0[1];
|
||||
s2 = MULT32(s0, T[1]) + MULT32(s1, T[0]);
|
||||
s3 = MULT32(s1, T[1]) - MULT32(s0, T[0]);
|
||||
T+=step;
|
||||
|
||||
s0 = (w0[1] + w1[1])>>1;
|
||||
s1 = (w0[0] - w1[0])>>1;
|
||||
w0[0] = s0 + s2;
|
||||
w0[1] = s1 + s3;
|
||||
w1[0] = s0 - s2;
|
||||
w1[1] = s3 - s1;
|
||||
|
||||
w0 += 2;
|
||||
}while(T<Ttop);
|
||||
do{
|
||||
w1 -= 2;
|
||||
|
||||
s0 = w0[0] + w1[0];
|
||||
s1 = w1[1] - w0[1];
|
||||
T-=step;
|
||||
s2 = MULT32(s0, T[0]) + MULT32(s1, T[1]);
|
||||
s3 = MULT32(s1, T[0]) - MULT32(s0, T[1]);
|
||||
|
||||
s0 = (w0[1] + w1[1])>>1;
|
||||
s1 = (w0[0] - w1[0])>>1;
|
||||
w0[0] = s0 + s2;
|
||||
w0[1] = s1 + s3;
|
||||
w1[0] = s0 - s2;
|
||||
w1[1] = s3 - s1;
|
||||
|
||||
w0 += 2;
|
||||
}while(w0<w1);
|
||||
}
|
||||
#endif
|
||||
|
||||
STIN void mdct_step8(DATA_TYPE *x, int n, int step){
|
||||
LOOKUP_T *T;
|
||||
LOOKUP_T *V;
|
||||
DATA_TYPE *iX =x+(n>>1);
|
||||
|
||||
switch(step) {
|
||||
#if defined(ONLY_C)
|
||||
default:
|
||||
T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
|
||||
do{
|
||||
REG_TYPE s0 = x[0];
|
||||
REG_TYPE s1 = -x[1];
|
||||
XPROD31( s0, s1, T[0], T[1], x, x+1); T+=step;
|
||||
x +=2;
|
||||
}while(x<iX);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 1:
|
||||
{
|
||||
/* linear interpolation between table values: offset=0.5, step=1 */
|
||||
REG_TYPE t0,t1,v0,v1,s0,s1;
|
||||
T = sincos_lookup0;
|
||||
V = sincos_lookup1;
|
||||
t0 = (*T++)>>1;
|
||||
t1 = (*T++)>>1;
|
||||
do{
|
||||
s0 = x[0];
|
||||
s1 = -x[1];
|
||||
t0 += (v0 = (*V++)>>1);
|
||||
t1 += (v1 = (*V++)>>1);
|
||||
XPROD31( s0, s1, t0, t1, x, x+1 );
|
||||
|
||||
s0 = x[2];
|
||||
s1 = -x[3];
|
||||
v0 += (t0 = (*T++)>>1);
|
||||
v1 += (t1 = (*T++)>>1);
|
||||
XPROD31( s0, s1, v0, v1, x+2, x+3 );
|
||||
|
||||
x += 4;
|
||||
}while(x<iX);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0:
|
||||
{
|
||||
/* linear interpolation between table values: offset=0.25, step=0.5 */
|
||||
REG_TYPE t0,t1,v0,v1,q0,q1,s0,s1;
|
||||
T = sincos_lookup0;
|
||||
V = sincos_lookup1;
|
||||
t0 = *T++;
|
||||
t1 = *T++;
|
||||
do{
|
||||
|
||||
|
||||
v0 = *V++;
|
||||
v1 = *V++;
|
||||
t0 += (q0 = (v0-t0)>>2);
|
||||
t1 += (q1 = (v1-t1)>>2);
|
||||
s0 = x[0];
|
||||
s1 = -x[1];
|
||||
XPROD31( s0, s1, t0, t1, x, x+1 );
|
||||
t0 = v0-q0;
|
||||
t1 = v1-q1;
|
||||
s0 = x[2];
|
||||
s1 = -x[3];
|
||||
XPROD31( s0, s1, t0, t1, x+2, x+3 );
|
||||
|
||||
t0 = *T++;
|
||||
t1 = *T++;
|
||||
v0 += (q0 = (t0-v0)>>2);
|
||||
v1 += (q1 = (t1-v1)>>2);
|
||||
s0 = x[4];
|
||||
s1 = -x[5];
|
||||
XPROD31( s0, s1, v0, v1, x+4, x+5 );
|
||||
v0 = t0-q0;
|
||||
v1 = t1-q1;
|
||||
s0 = x[6];
|
||||
s1 = -x[7];
|
||||
XPROD31( s0, s1, v0, v1, x+5, x+6 );
|
||||
|
||||
x+=8;
|
||||
}while(x<iX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int mdct_backwardARM(int n, DATA_TYPE *in);
|
||||
|
||||
/* partial; doesn't perform last-step deinterleave/unrolling. That
|
||||
can be done more efficiently during pcm output */
|
||||
void mdct_backward(int n, DATA_TYPE *in){
|
||||
int step;
|
||||
|
||||
#if defined(ONLY_C)
|
||||
int shift;
|
||||
|
||||
for (shift=4;!(n&(1<<shift));shift++);
|
||||
shift=13-shift;
|
||||
step=2<<shift;
|
||||
|
||||
presymmetry(in,n>>1,step);
|
||||
mdct_butterflies(in,n>>1,shift);
|
||||
mdct_bitreverse(in,n,shift);
|
||||
mdct_step7(in,n,step);
|
||||
mdct_step8(in,n,step>>2);
|
||||
#else
|
||||
step = mdct_backwardARM(n, in);
|
||||
if (step <= 1)
|
||||
mdct_step8(in,n,step);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(ONLY_C)
|
||||
void mdct_shift_right(int n, DATA_TYPE *in, DATA_TYPE *right){
|
||||
int i;
|
||||
n>>=2;
|
||||
in+=1;
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
right[i]=in[i<<1];
|
||||
}
|
||||
#endif
|
||||
|
||||
extern ogg_int16_t *mdct_unroll_prelap(ogg_int16_t *out,
|
||||
DATA_TYPE *post,
|
||||
DATA_TYPE *l,
|
||||
int step);
|
||||
extern ogg_int16_t *mdct_unroll_part2(ogg_int16_t *out,
|
||||
DATA_TYPE *post,
|
||||
DATA_TYPE *l,
|
||||
DATA_TYPE *r,
|
||||
int step,
|
||||
LOOKUP_T *wL,
|
||||
LOOKUP_T *wR);
|
||||
extern ogg_int16_t *mdct_unroll_part3(ogg_int16_t *out,
|
||||
DATA_TYPE *post,
|
||||
DATA_TYPE *l,
|
||||
DATA_TYPE *r,
|
||||
int step,
|
||||
LOOKUP_T *wL,
|
||||
LOOKUP_T *wR);
|
||||
extern ogg_int16_t *mdct_unroll_postlap(ogg_int16_t *out,
|
||||
DATA_TYPE *post,
|
||||
DATA_TYPE *l,
|
||||
int step);
|
||||
|
||||
void mdct_unroll_lap(int n0,int n1,
|
||||
int lW,int W,
|
||||
DATA_TYPE *in,
|
||||
DATA_TYPE *right,
|
||||
LOOKUP_T *w0,
|
||||
LOOKUP_T *w1,
|
||||
ogg_int16_t *out,
|
||||
int step,
|
||||
int start, /* samples, this frame */
|
||||
int end /* samples, this frame */){
|
||||
|
||||
DATA_TYPE *l=in+(W&&lW ? n1>>1 : n0>>1);
|
||||
DATA_TYPE *r=right+(lW ? n1>>2 : n0>>2);
|
||||
DATA_TYPE *post;
|
||||
LOOKUP_T *wR=(W && lW ? w1+(n1>>1) : w0+(n0>>1));
|
||||
LOOKUP_T *wL=(W && lW ? w1 : w0 );
|
||||
|
||||
int preLap=(lW && !W ? (n1>>2)-(n0>>2) : 0 );
|
||||
int halfLap=(lW && W ? (n1>>2) : (n0>>2) );
|
||||
int postLap=(!lW && W ? (n1>>2)-(n0>>2) : 0 );
|
||||
int n,off;
|
||||
|
||||
/* preceeding direct-copy lapping from previous frame, if any */
|
||||
if(preLap){
|
||||
n = (end<preLap?end:preLap);
|
||||
off = (start<preLap?start:preLap);
|
||||
post = r-n;
|
||||
r -= off;
|
||||
start -= off;
|
||||
end -= n;
|
||||
#if defined(ONLY_C)
|
||||
while(r>post){
|
||||
*out = CLIP_TO_15((*--r)>>9);
|
||||
out+=step;
|
||||
}
|
||||
#else
|
||||
out = mdct_unroll_prelap(out,post,r,step);
|
||||
n -= off;
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
r -= n;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* cross-lap; two halves due to wrap-around */
|
||||
n = (end<halfLap?end:halfLap);
|
||||
off = (start<halfLap?start:halfLap);
|
||||
post = r-n;
|
||||
r -= off;
|
||||
l -= off*2;
|
||||
start -= off;
|
||||
wR -= off;
|
||||
wL += off;
|
||||
end -= n;
|
||||
#if defined(ONLY_C)
|
||||
while(r>post){
|
||||
l-=2;
|
||||
*out = CLIP_TO_15((MULT31(*--r,*--wR) + MULT31(*l,*wL++))>>9);
|
||||
out+=step;
|
||||
}
|
||||
#else
|
||||
out = mdct_unroll_part2(out, post, l, r, step, wL, wR);
|
||||
n -= off;
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
l -= 2*n;
|
||||
r -= n;
|
||||
wR -= n;
|
||||
wL += n;
|
||||
#endif
|
||||
|
||||
n = (end<halfLap?end:halfLap);
|
||||
off = (start<halfLap?start:halfLap);
|
||||
post = r+n;
|
||||
r += off;
|
||||
l += off*2;
|
||||
start -= off;
|
||||
end -= n;
|
||||
wR -= off;
|
||||
wL += off;
|
||||
#if defined(ONLY_C)
|
||||
while(r<post){
|
||||
*out = CLIP_TO_15((MULT31(*r++,*--wR) - MULT31(*l,*wL++))>>9);
|
||||
out+=step;
|
||||
l+=2;
|
||||
}
|
||||
#else
|
||||
out = mdct_unroll_part3(out, post, l, r, step, wL, wR);
|
||||
n -= off;
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
l += 2*n;
|
||||
r += n;
|
||||
wR -= n;
|
||||
wL += n;
|
||||
#endif
|
||||
|
||||
/* preceeding direct-copy lapping from previous frame, if any */
|
||||
if(postLap){
|
||||
n = (end<postLap?end:postLap);
|
||||
off = (start<postLap?start:postLap);
|
||||
post = l+n*2;
|
||||
l += off*2;
|
||||
#if defined(ONLY_C)
|
||||
while(l<post){
|
||||
*out = CLIP_TO_15((-*l)>>9);
|
||||
out+=step;
|
||||
l+=2;
|
||||
}
|
||||
#else
|
||||
out = mdct_unroll_postlap(out,post,l,step);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue