# HG changeset patch # User Xeli # Date 1321114009 -3600 # Node ID d14adf1c772104bf0bf06b0f9d5dd9a0dd633045 # Parent 1998ff75321ae2fa265e56d79b9611c7d979127a# Parent 07d83af9d2a86985ff7b8a30412e888ae76a16f8 merge...i think diff -r 07d83af9d2a8 -r d14adf1c7721 .hgignore --- a/.hgignore Fri Nov 11 15:28:58 2011 -0500 +++ b/.hgignore Sat Nov 12 17:06:49 2011 +0100 @@ -36,3 +36,15 @@ glob:*.orig glob:*.bak glob:*.rej +glob:project_files/Android-build/SDL-android-project/jni/** +glob:project_files/Android-build/SDL-android-project/obj +glob:project_files/Android-build/SDL-android-project/libs +glob:project_files/Android-build/SDL-android-project/bin +glob:project_files/Android-build/SDL-android-project/gen +glob:project_files/Android-build/SDL-android-project/local.properties +glob:project_files/Android-build/SDL-android-project/default.properties +glob:project_files/Android-build/SDL-android-project/.* +glob:project_files/Android-build/complete_build.sh +glob:project_files/Android-build/pushToDevice.sh +glob:project_files/Android-build/Makefile.android +glob:project_files/Android-build/out diff -r 07d83af9d2a8 -r d14adf1c7721 CMakeLists.txt --- a/CMakeLists.txt Fri Nov 11 15:28:58 2011 -0500 +++ b/CMakeLists.txt Sat Nov 12 17:06:49 2011 +0100 @@ -192,6 +192,11 @@ add_subdirectory(misc/liblua) add_subdirectory(hedgewars) +#run cmake -DBUILD_ANDROID_PORT=1 to enable this +if(BUILD_ANDROID_PORT) + add_subdirectory(project_files/Android-build) +endif() + if(NOT BUILD_ENGINE_LIBRARY) add_subdirectory(bin) add_subdirectory(misc/quazip) @@ -264,7 +269,7 @@ "CMakeCache\\\\.txt$" # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" -# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" + "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/" "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]" diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/CMakeLists.txt Sat Nov 12 17:06:49 2011 +0100 @@ -184,8 +184,8 @@ add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}") IF(NOT APPLE) -add_custom_target(ENGINECLEAN COMMAND ${CMAKE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${hedgewars_SOURCE_DIR}/hedgewars") -add_dependencies(${engine_output_name} ENGINECLEAN) + add_custom_target(ENGINECLEAN COMMAND ${CMAKE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${hedgewars_SOURCE_DIR}/hedgewars") + add_dependencies(${engine_output_name} ENGINECLEAN) ENDIF() install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir}) diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/PascalExports.pas --- a/hedgewars/PascalExports.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/PascalExports.pas Sat Nov 12 17:06:49 2011 +0100 @@ -32,6 +32,10 @@ {$INCLUDE "config.inc"} procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export; +function HW_getNumberOfWeapons:LongInt; cdecl; export; +function HW_getMaxNumberOfTeams:LongInt; cdecl; export; +function HW_getMaxNumberOfHogs:LongInt; cdecl; export; +procedure HW_terminate(closeFrontend: Boolean); cdecl; export; implementation {$IFDEF HWLIBRARY} diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/SDLh.pas Sat Nov 12 17:06:49 2011 +0100 @@ -41,7 +41,9 @@ {$IFDEF HAIKU} {$linklib root} {$ELSE} - {$linklib pthread} + {$IFNDEF ANDROID} + {$linklib pthread} + {$ENDIF} {$ENDIF} {$ENDIF} @@ -562,7 +564,6 @@ windowID: LongWord; {$ELSE} which: Byte; -{$ENDIF} x, y: LongInt; end; @@ -610,6 +611,21 @@ {$ENDIF} end; + SDL_TouchID = LongInt; + SDL_FingerID = LongInt; + + TSDL_TouchFingerEvent = record + type_: LongWord; + windowId: LongWord; + touchId: SDL_TouchID; + fingerId: SDL_FingerID; + state, padding1, padding2, padding3: Byte; + x,y: Word; + dx,dy: ShortInt; + pressure: Word; + end; +//TODO: implement SDL_TouchButtonEvent, SDL_MultiGestureEvent, SDL_DollarGestureEvent + TSDL_QuitEvent = record type_: {$IFDEF SDL13}LongWord{$ELSE}Byte{$ENDIF}; end; @@ -644,6 +660,9 @@ SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent); SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent); + SDL_FINGERMOTION, + SDL_FINGERUP, + SDL_FINGERDOWN:(tfinger: TSDL_TouchFingerEvent); SDL_QUITEV: (quit: TSDL_QuitEvent); SDL_USEREVENT: (user: TSDL_UserEvent); SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent); diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/hwLibrary.pas --- a/hedgewars/hwLibrary.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/hwLibrary.pas Sat Nov 12 17:06:49 2011 +0100 @@ -17,15 +17,43 @@ *) Library hwLibrary; +{$INCLUDE "options.inc"} -// Add all your Pascal units to the "uses" clause below to add them to the program. +// Add all your Pascal units to the 'uses' clause below to add them to the program. // Mark all Pascal procedures/functions that you wish to call from C/C++/Objective-C code using -// "cdecl; export;" (see the fpclogo.pas unit for an example), and then add C-declarations for -// these procedures/functions to the PascalImports.h file (also in the "Pascal Sources" group) +// 'cdecl; export;' (see the fpclogo.pas unit for an example), and then add C-declarations for +// these procedures/functions to the PascalImports.h file (also in the 'Pascal Sources' group) // to make these functions available in the C/C++/Objective-C source files -// (add "#include PascalImports.h" near the top of these files if it's not there yet) -uses PascalExports, hwengine; +// (add '#include PascalImports.h' near the top of these files if it is not there yet) +uses PascalExports, hwengine{$IFDEF ANDROID}, jni{$ENDIF}; exports Game, HW_versionInfo; + +{$IFDEF ANDROID} +function JNI_HW_versionInfoNet(env: PJNIEnv; obj: JObject):JInt;cdecl; +begin + env:= env; // avoid hint + obj:= obj; // avoid hint + JNI_HW_versionInfoNet:= cNetProtoVersion; +end; + +function JNI_HW_versionInfoVersion(env: PJNIEnv; obj: JObject):JString; cdecl; +var envderef : JNIEnv; +begin + obj:= obj; // avoid hint + envderef:= @env; + JNI_HW_versionInfoVersion := envderef^.NewStringUTF(env, PChar(cVersionString)); +end; + +exports + JNI_HW_versionInfoNet name Java_Prefix+'HWversionInfoNetProto', + JNI_HW_versionInfoVersion name Java_Prefix+'HWversionInfoVersion', + GenLandPreview name Java_Prefix + 'GenLandPreview', + HW_getNumberOfweapons name Java_Prefix + 'HWgetNumberOfWeapons', + HW_getMaxNumberOfHogs name Java_Prefix + 'HWgetMaxNumberOfHogs', + HW_getMaxNumberOfTeams name Java_Prefix + 'HWgetMaxNumberOfTeams', + HW_terminate name Java_Prefix + 'HWterminate'; +{$ENDIF} + begin end. diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/hwengine.pas Sat Nov 12 17:06:49 2011 +0100 @@ -31,12 +31,13 @@ uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, - sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted; + sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted,uTouch {$IFDEF ANDROID}, GLUnit {$ENDIF}; {$IFDEF HWLIBRARY} procedure initEverything(complete:boolean); procedure freeEverything(complete:boolean); procedure Game(gameArgs: PPChar); cdecl; export; +procedure GenLandPreview(port: Longint); cdecl; export; implementation {$ELSE} @@ -187,6 +188,9 @@ cScreenResizeDelay:= RealTicks+500; *) end; + SDL_FINGERMOTION: onTouchMotion(event.tfinger.x, event.tfinger.y,event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId); + SDL_FINGERDOWN: onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); + SDL_FINGERUP: onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); {$ELSE} SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); @@ -268,7 +272,8 @@ isSoundEnabled:= gameArgs[6] = '1'; isMusicEnabled:= gameArgs[7] = '1'; cAltDamage:= gameArgs[8] = '1'; - val(gameArgs[9], rotationQt); + PathPrefix:= gameArgs[9]; + UserPathPrefix:= PathPrefix; recordFileName:= gameArgs[10]; cStereoMode:= smNone; {$ENDIF} @@ -278,7 +283,6 @@ cOrigScreenHeight:= cScreenHeight; initEverything(true); - WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); AddFileLog('Prefix: "' + PathPrefix +'"'); AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); @@ -384,7 +388,11 @@ if complete then begin - uAI.initModule; +{$IFDEF ANDROID} + GLUnit.init; +{$ENDIF} + uTouch.initModule; + uAI.initModule; //uAIActions does not need initialization //uAIAmmoTests does not need initialization uAIMisc.initModule; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/options.inc --- a/hedgewars/options.inc Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/options.inc Sat Nov 12 17:06:49 2011 +0100 @@ -27,16 +27,28 @@ {$DEFINE GLunit:=GL} +{$IFDEF ANDROID} + {$DEFINE SDL13} + {$DEFINE HWLIBRARY} + {$DEFINE S3D_DISABLED} + {$DEFINE GLunit:=gles11} + {$DEFINE MOBILE} + {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'} +{$ENDIF} + {$IFDEF IPHONEOS} {$DEFINE SDL13} {$DEFINE HWLIBRARY} {$DEFINE S3D_DISABLED} {$DEFINE GLunit:=gles11} -{$ELSE} + {$DEFINE MOBILE} +{$ENDIF} + +{$IFNDEF IPHONEOS} + // not needed on ios because it is switched from the compiler command line arguments {$DEFINE DEBUGFILE} //{$DEFINE TRACEAIACTIONS} //{$DEFINE COUNTTICKS} {$ENDIF} - //also available LUA_DISABLED diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uAI.pas Sat Nov 12 17:06:49 2011 +0100 @@ -30,13 +30,13 @@ implementation uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions, - uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes, + uAmmos, SysUtils{$IFDEF UNIX}{$IFNDEF ANDROID}, cthreads{$ENDIF}{$ENDIF}, uTypes, uVariables, uCommands, uUtils, uDebug; var BestActions: TActions; CanUseAmmo: array [TAmmoType] of boolean; StopThinking: boolean; - ThinkThread: TThreadID; + ThinkThread: PSDL_Thread = nil; hasThread: LongInt; procedure FreeActionsList; @@ -74,8 +74,7 @@ with CurrentHedgehog^ do a:= CurAmmoType; aa:= a; - - ThreadSwitch(); + SDL_delay(0); //ThreadSwitch was only a hint repeat if (CanUseAmmo[a]) and @@ -265,6 +264,7 @@ if (PGear(Me)^.State and gstAttacked) = 0 then if Targets.Count > 0 then begin + WalkMe:= BackMe; Walk(@WalkMe); if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000); @@ -316,7 +316,13 @@ for a:= Low(TAmmoType) to High(TAmmoType) do CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a); AddFileLog('Enter Think Thread'); -BeginThread(@Think, Me, ThinkThread) +{$IFDEF IPHONEOS} +//TODO: sdl_thread works on device but crashes in simulator, most likely because of outdated toolchain +BeginThread(@Think, Me, ThinkThread); +{$ELSE} +ThinkThread := SDL_CreateThread(@Think, Me); +{$ENDIF} +AddFileLog('Thread started'); end; procedure ProcessBot; @@ -347,6 +353,7 @@ procedure initModule; begin hasThread:= 0; + ThinkThread:= ThinkThread; end; procedure freeModule; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uCaptions.pas --- a/hedgewars/uCaptions.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uCaptions.pas Sat Nov 12 17:06:49 2011 +0100 @@ -59,7 +59,7 @@ grp: TCapGroup; offset: LongInt; begin -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} offset:= 48; {$ELSE} offset:= 8; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uCommandHandlers.pas diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uConsole.pas Sat Nov 12 17:06:49 2011 +0100 @@ -26,9 +26,10 @@ procedure WriteToConsole(s: shortstring); procedure WriteLnToConsole(s: shortstring); function GetLastConsoleLine: shortstring; +function ShortStringAsPChar(s: shortstring): PChar; implementation -uses Types, uVariables, uUtils; +uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF}; const cLineWidth: LongInt = 0; cLinesCount = 8; @@ -53,6 +54,9 @@ begin {$IFNDEF NOCONSOLE} AddFileLog('[Con] ' + s); +{$IFDEF ANDROID} + Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); +{$ELSE} Write(stderr, s); done:= false; @@ -70,20 +74,29 @@ done:= (Length(s) = 0); end; {$ENDIF} +{$ENDIF} end; procedure WriteLnToConsole(s: shortstring); begin {$IFNDEF NOCONSOLE} WriteToConsole(s); +{$IFNDEF ANDROID} WriteLn(stderr); inc(CurrLine); if CurrLine = cLinesCount then CurrLine:= 0; PByte(@ConsoleLines[CurrLine].s)^:= 0 {$ENDIF} +{$ENDIF} end; +function ShortStringAsPChar(s: ShortString) : PChar; +begin + if Length(s) = High(s) then Dec(s[0]); + s[Ord(Length(s))+1] := #0; + exit(@s[1]); +end; function GetLastConsoleLine: shortstring; var valueStr: shortstring; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uConsts.pas Sat Nov 12 17:06:49 2011 +0100 @@ -158,7 +158,7 @@ // do not change this value cDefaultZoomLevel = 2.0; -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} cMaxZoomLevel = 0.5; cMinZoomLevel = 3.5; cZoomDelta = 0.20; @@ -168,6 +168,8 @@ cZoomDelta = 0.25; {$ENDIF} + cMinMaxZoomLevelDelta = cMaxZoomLevel - cMinZoomLevel; + cSendEmptyPacketTime = 1000; trigTurns = $80000001; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uFloat.pas --- a/hedgewars/uFloat.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uFloat.pas Sat Nov 12 17:06:49 2011 +0100 @@ -62,6 +62,7 @@ // The implemented operators +operator = (const z1, z2: hwFloat) z:boolean; inline; operator + (const z1, z2: hwFloat) z : hwFloat; inline; operator - (const z1, z2: hwFloat) z : hwFloat; inline; operator - (const z1: hwFloat) z : hwFloat; inline; @@ -88,7 +89,7 @@ function AngleCos(const Angle: Longword): hwFloat; function SignAs(const num, signum: hwFloat): hwFloat; inline; // Returns an hwFloat with the value of parameter num and the sign of signum. function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r. - +function isZero(const z: hwFloat): boolean; inline; {$IFDEF FPC} {$J-} {$ENDIF} @@ -159,10 +160,13 @@ _40: hwFloat = (isNegative: false; QWordValue: 4294967296 * 40); _50: hwFloat = (isNegative: false; QWordValue: 4294967296 * 50); _70: hwFloat = (isNegative: false; QWordValue: 4294967296 * 70); + _90: hwFloat = (isNegative: false; QWordValue: 4294967296 * 90); _128: hwFloat = (isNegative: false; QWordValue: 4294967296 * 128); + _180: hwFloat = (isNegative: false; QWordValue: 4294967296 * 180); _250: hwFloat = (isNegative: false; QWordValue: 4294967296 * 250); _256: hwFloat = (isNegative: false; QWordValue: 4294967296 * 256); _300: hwFloat = (isNegative: false; QWordValue: 4294967296 * 300); + _360: hwFloat = (isNegative: false; QWordValue: 4294967296 * 360); _450: hwFloat = (isNegative: false; QWordValue: 4294967296 * 450); _1000: hwFloat = (isNegative: false; QWordValue: 4294967296 * 1000); _1024: hwFloat = (isNegative: false; QWordValue: 4294967296 * 1024); @@ -198,6 +202,12 @@ if i.isNegative then hwFloat2Float:= -hwFloat2Float; end; +operator = (const z1, z2: hwFloat) z:boolean; inline; +begin + z:= (z1.isNegative = z2.isNegative) and (z1.QWordValue = z2.QWordValue); +end; + + operator + (const z1, z2: hwFloat) z : hwFloat; begin if z1.isNegative = z2.isNegative then @@ -404,6 +414,10 @@ else AngleCos.QWordValue:= SinTable[Angle - 1024] end; +function isZero(const z: hwFloat): boolean; inline; +begin + isZero := z.QWordValue = 0; +end; {$ENDIF} end. diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uGame.pas --- a/hedgewars/uGame.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uGame.pas Sat Nov 12 17:06:49 2011 +0100 @@ -26,7 +26,7 @@ //////////////////// implementation //////////////////// -uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables; +uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables, uTouch; procedure DoGameTick(Lag: LongInt); var i: LongInt; @@ -52,7 +52,8 @@ if not CurrentTeam^.ExtDriven then begin if CurrentHedgehog^.BotLevel <> 0 then ProcessBot; - ProcessGears + ProcessGears; + ProcessTouch; end else begin NetGetNextCmd; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uGearsRender.pas Sat Nov 12 17:06:49 2011 +0100 @@ -188,7 +188,7 @@ procedure DrawHH(Gear: PGear; ox, oy: LongInt); var i, t: LongInt; amt: TAmmoType; - sign, hx, hy, cx, cy, tx, ty, sx, sy, m: LongInt; // hedgehog, crosshair, temp, sprite, direction + sign, hx, hy, tx, ty, sx, sy, m: LongInt; // hedgehog, crosshair, temp, sprite, direction dx, dy, ax, ay, aAngle, dAngle, hAngle, lx, ly: real; // laser, change defaultPos, HatVisible: boolean; HH: PHedgehog; @@ -319,10 +319,12 @@ end; end; // draw crosshair - cx:= Round(hwRound(Gear^.X) + dx * 80 + GetLaunchX(HH^.CurAmmoType, sign * m, Gear^.Angle)); - cy:= Round(hwRound(Gear^.Y) + dy * 80 + GetLaunchY(HH^.CurAmmoType, Gear^.Angle)); + CrosshairX := Round(hwRound(Gear^.X) + dx * 80 + GetLaunchX(HH^.CurAmmoType, sign * m, Gear^.Angle)); + CrosshairY := Round(hwRound(Gear^.Y) + dy * 80 + GetLaunchY(HH^.CurAmmoType, Gear^.Angle)); + + DrawRotatedTex(HH^.Team^.CrosshairTex, - 12, 12, cx + WorldDx, cy + WorldDy, 0, + 12, 12, CrosshairX + WorldDx, CrosshairY + WorldDy, 0, sign * (Gear^.Angle * 180.0) / cMaxAngle); end; hx:= ox + 8 * sign; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uLand.pas diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uScript.pas Sat Nov 12 17:06:49 2011 +0100 @@ -45,6 +45,9 @@ function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; function ScriptExists(fname : shortstring) : boolean; + +function ParseCommandOverride(key, value : shortstring) : shortstring; + procedure initModule; procedure freeModule; @@ -1724,6 +1727,25 @@ GetGlobals; end; +function ParseCommandOverride(key, value : shortstring) : shortstring; +begin +ParseCommandOverride:= value; +if not ScriptExists('ParseCommandOverride') then exit; +lua_getglobal(luaState, Str2PChar('ParseCommandOverride')); +lua_pushstring(luaState, Str2PChar(key)); +lua_pushstring(luaState, Str2PChar(value)); +if lua_pcall(luaState, 2, 1, 0) <> 0 then + begin + LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1)); + lua_pop(luaState, 1) + end +else + begin + ParseCommandOverride:= lua_tostring(luaState, -1); + lua_pop(luaState, 1) + end; +end; + function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; begin ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) @@ -2077,6 +2099,11 @@ ScriptExists:= false end; +function ParseCommandOverride(key, value : shortstring) : shortstring; +begin +ParseCommandOverride:= value +end; + procedure initModule; begin end; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uSound.pas --- a/hedgewars/uSound.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uSound.pas Sat Nov 12 17:06:49 2011 +0100 @@ -148,7 +148,7 @@ WriteToConsole('Init sound...'); isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0; -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} channels:= 1; {$ELSE} channels:= 2; diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uStore.pas Sat Nov 12 17:06:49 2011 +0100 @@ -290,7 +290,7 @@ ((vobCount > 0) or (ii <> sprFlake)) then begin if AltPath = ptNone then - if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk] then // FIXME: hack + if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack begin if not reload then begin @@ -999,7 +999,7 @@ y:= SDL_WINDOWPOS_CENTERED_MASK; flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN; -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} // make the sdl window appear on the second monitor when present x:= x or (SDL_GetNumVideoDisplays() - 1); y:= y or (SDL_GetNumVideoDisplays() - 1); diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uTouch.pas --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/uTouch.pas Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,513 @@ +(* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2011 Richard Deurwaarder + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + *) + +{$INCLUDE "options.inc"} + +unit uTouch; + +interface + +uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit; + +type + PTouch_Finger = ^Touch_Finger; + Touch_Finger = record + id : SDL_FingerId; + x,y : LongInt; + historicalX, historicalY : LongInt; + timeSinceDown : Longword; + end; + +procedure initModule; + +procedure ProcessTouch; +procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId); +procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: SDL_FingerId); +procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId); +function convertToCursor(scale: LongInt; xy: LongInt): LongInt; +function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; +procedure deleteFinger(id: SDL_FingerId); +procedure onTouchClick(finger: Touch_Finger); +procedure onTouchDoubleClick(finger: Touch_Finger); + +function findFinger(id: SDL_FingerId): PTouch_Finger; +procedure aim(finger: Touch_Finger); +function isOnCrosshair(finger: Touch_Finger): boolean; +function isOnCurrentHog(finger: Touch_Finger): boolean; +function isOnFireButton(finger: Touch_Finger): boolean; +procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger); +procedure convertToFingerCoord(var x,y: hwFloat; oldX, oldY: hwFloat); +function fingerHasMoved(finger: Touch_Finger): boolean; +function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; +function getSecondFinger(finger: Touch_Finger): PTouch_Finger; +procedure printFinger(finger: Touch_Finger); +implementation + +const + clicktime = 200; + nilFingerId = High(SDL_FingerId); + +var + fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt; + + + + leftButtonBoundary : LongInt; + rightButtonBoundary : LongInt; + topButtonBoundary : LongInt; + + pointerCount : Longword; + fingers: array of Touch_Finger; + moveCursor : boolean; + invertCursor : boolean; + + xTouchClick,yTouchClick : LongInt; + timeSinceClick : Longword; + + //Pinch to zoom + pinchSize : hwFloat; + baseZoomValue: GLFloat; + + + //aiming + aiming, movingCrosshair: boolean; + crosshairCommand: ShortString; + targetAngle: LongInt; + stopFiring: boolean; + + //moving + stopLeft, stopRight, walkingLeft, walkingRight : boolean; + + +procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId); +var + finger: PTouch_Finger; +begin + finger := addFinger(x,y,pointerId); + case pointerCount of + 1: + begin + moveCursor:= false; + if bShowAmmoMenu then + begin + moveCursor := true; + exit; + end; + + if isOnCrosshair(finger^) then + begin + aiming:= true; + exit; + end; + + if isOnFireButton(finger^) then + begin + stopFiring:= false; + ParseCommand('+attack', true); + exit; + end; + if (finger^.x < leftButtonBoundary) and (finger^.y < 390) then + begin + ParseCommand('+left', true); + walkingLeft := true; + exit; + end; + if finger^.x > rightButtonBoundary then + begin + ParseCommand('+right', true); + walkingRight:= true; + exit; + end; + if finger^.y < topButtonBoundary then + begin + ParseCommand('hjump', true); + exit; + end; + moveCursor:= true; + end; + 2: + begin + aiming:= false; + stopFiring:= true; + moveCursor:= false; + pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^); + baseZoomValue := ZoomValue + end; + end;//end case pointerCount of +end; + +procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId); +var + finger, secondFinger: PTouch_Finger; + currentPinchDelta, zoom : hwFloat; + tmpX, tmpY: LongInt; +begin + x := x; + y := y; + dx := dx; + dy := dy; + finger:= findFinger(pointerId); + tmpX := convertToCursor(cScreenWidth, x); + tmpY := convertToCursor(cScreenHeight, y); + + if moveCursor then + begin + if invertCursor then + begin + CursorPoint.X := CursorPoint.X + (finger^.x - tmpX); + CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY); + end + else + begin + CursorPoint.X := CursorPoint.X - (finger^.x - tmpX); + CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY); + end; + finger^.x := tmpX; + finger^.y := tmpY; + exit //todo change into switch rather than ugly ifs + end; + + finger^.x := tmpX; + finger^.y := tmpY; + + if aiming then + begin + aim(finger^); + exit + end; + if pointerCount = 2 then + begin + secondFinger := getSecondFinger(finger^); + currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize; + zoom := currentPinchDelta/cScreenWidth; + ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta)); + if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel; + if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel; + end; +end; + +procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId); +begin + x := x; + y := y; + aiming:= false; + stopFiring:= true; + deleteFinger(pointerId); + + if walkingLeft then + begin + ParseCommand('-left', true); + walkingLeft := false; + end; + + if walkingRight then + begin + ParseCommand('-right', true); + walkingRight := false; + end; +end; + +procedure onTouchDoubleClick(finger: Touch_Finger); +begin + finger := finger;//avoid compiler hint + ParseCommand('ljump', true); +end; + +procedure onTouchClick(finger: Touch_Finger); +begin + if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then + begin + onTouchDoubleClick(finger); + exit; + end + else + begin + xTouchClick := finger.x; + yTouchClick := finger.y; + timeSinceClick := SDL_GetTicks; + end; + + if bShowAmmoMenu then + begin + doPut(CursorPoint.X, CursorPoint.Y, false); + exit + end; + + if isOnCurrentHog(finger) then + begin + bShowAmmoMenu := true; + exit; + end; + + if finger.y < topButtonBoundary then + begin + ParseCommand('hjump', true); + exit; + end; +end; + +function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; +var + xCursor, yCursor, index : LongInt; +begin + //Check array sizes + if length(fingers) < Integer(pointerCount) then + begin + setLength(fingers, length(fingers)*2); + for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId; + end; + + + xCursor := convertToCursor(cScreenWidth, x); + yCursor := convertToCursor(cScreenHeight, y); + + //on removing fingers, all fingers are moved to the left + //with dynamic arrays being zero based, the new position of the finger is the old pointerCount + fingers[pointerCount].id := id; + fingers[pointerCount].historicalX := xCursor; + fingers[pointerCount].historicalY := yCursor; + fingers[pointerCount].x := xCursor; + fingers[pointerCount].y := yCursor; + fingers[pointerCount].timeSinceDown:= SDL_GetTicks; + + addFinger:= @fingers[pointerCount]; + inc(pointerCount); +end; + +procedure deleteFinger(id: SDL_FingerId); +var + index : Longword; +begin + + dec(pointerCount); + for index := 0 to pointerCount do + begin + if fingers[index].id = id then + begin + //Check for onTouchClick event + if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND + not(fingerHasMoved(fingers[index])) then onTouchClick(fingers[index]); + + //put the last finger into the spot of the finger to be removed, + //so that all fingers are packed to the far left + if pointerCount <> index then + begin + fingers[index].id := fingers[pointerCount].id; + fingers[index].x := fingers[pointerCount].x; + fingers[index].y := fingers[pointerCount].y; + fingers[index].historicalX := fingers[pointerCount].historicalX; + fingers[index].historicalY := fingers[pointerCount].historicalY; + fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown; + + fingers[pointerCount].id := nilFingerId; + end + else fingers[index].id := nilFingerId; + break; + end; + end; + +end; + +procedure ProcessTouch; +var + deltaAngle: LongInt; +begin + invertCursor := not(bShowAmmoMenu); + if aiming then + begin + if CurrentHedgehog^.Gear <> nil then + begin + deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; + if (deltaAngle <> 0) and not(movingCrosshair) then + begin + ParseCommand('+' + crosshairCommand, true); + movingCrosshair := true; + end + else + if movingCrosshair then + begin + ParseCommand('-' + crosshairCommand, true); + movingCrosshair:= false; + end; + end; + end + else if movingCrosshair then + begin + ParseCommand('-' + crosshairCommand, true); + movingCrosshair := false; + end; + + if stopFiring then + begin + ParseCommand('-attack', true); + stopFiring:= false; + end; + + if stopRight then + begin + stopRight := false; + ParseCommand('-right', true); + end; + + if stopLeft then + begin + stopLeft := false; + ParseCommand('-left', true); + end; + +end; + +function findFinger(id: SDL_FingerId): PTouch_Finger; +var + index: LongWord; +begin + for index := 0 to High(fingers) do + if fingers[index].id = id then + begin + findFinger := @fingers[index]; + break; + end; +end; + +procedure aim(finger: Touch_Finger); +var + hogX, hogY, touchX, touchY, deltaX, deltaY, tmpAngle: hwFloat; + tmp: ShortString; +begin + if CurrentHedgehog^.Gear <> nil then + begin + touchX := _0;//avoid compiler hint + touchY := _0; + hogX := CurrentHedgehog^.Gear^.X; + hogY := CurrentHedgehog^.Gear^.Y; + + convertToWorldCoord(touchX, touchY, finger); + deltaX := hwAbs(TouchX-HogX); + deltaY := (TouchY-HogY); + + tmpAngle:= DeltaY / Distance(deltaX, deltaY) *_2048; + targetAngle:= (hwRound(tmpAngle) + 2048) div 2; + + tmp := crosshairCommand; + if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then crosshairCommand := 'down' + else crosshairCommand:= 'up'; + if movingCrosshair and (tmp <> crosshairCommand) then + begin + ParseCommand('-' + tmp, true); + movingCrosshair := false; + end; + + end; //if CurrentHedgehog^.Gear <> nil +end; + +function convertToCursor(scale: LongInt; xy: LongInt): LongInt; +begin + convertToCursor := round(xy/32768*scale) +end; + +function isOnFireButton(finger: Touch_Finger): boolean; +begin + isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop); +end; + +function isOnCrosshair(finger: Touch_Finger): boolean; +var + x,y : hwFloat; +begin + x := _0;//avoid compiler hint + y := _0; + convertToFingerCoord(x, y, int2hwFloat(CrosshairX), int2hwFloat(CrosshairY)); + isOnCrosshair:= Distance(int2hwFloat(finger.x)-x, int2hwFloat(finger.y)-y) < _50; +end; + +function isOnCurrentHog(finger: Touch_Finger): boolean; +var + x,y : hwFloat; +begin + x := _0; + y := _0; + convertToFingerCoord(x, y, CurrentHedgehog^.Gear^.X, CurrentHedgehog^.Gear^.Y); + isOnCurrentHog := Distance(int2hwFloat(finger.X)-x, int2hwFloat(finger.Y)-y) < _50; +end; + +procedure convertToFingerCoord(var x,y : hwFloat; oldX, oldY: hwFloat); +begin + x := oldX + int2hwFloat(WorldDx + (cScreenWidth div 2)); + y := oldY + int2hwFloat(WorldDy); +end; + +procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger); +begin +//if x <> nil then + x := int2hwFloat((finger.x-WorldDx) - (cScreenWidth div 2)); +//if y <> nil then + y := int2hwFloat(finger.y-WorldDy); +end; + +//Method to calculate the distance this finger has moved since the downEvent +function fingerHasMoved(finger: Touch_Finger): boolean; +begin + fingerHasMoved := trunc(sqrt(Power(finger.X-finger.historicalX,2) + Power(finger.y-finger.historicalY, 2))) > 330; +end; + +function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; inline; +begin + calculateDelta := DistanceI(finger2.x-finger1.x, finger2.y-finger1.y); +end; + +// Under the premise that all pointer ids in pointerIds:SDL_FingerId are packed to the far left. +// If the pointer to be ignored is not pointerIds[0] the second must be there +function getSecondFinger(finger: Touch_Finger): PTouch_Finger; +begin + if fingers[0].id = finger.id then getSecondFinger := @fingers[1] + else getSecondFinger := @fingers[0]; +end; + +procedure printFinger(finger: Touch_Finger); +begin + WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown])); +end; + +procedure initModule; +var + index: Longword; + //uRenderCoordScaleX, uRenderCoordScaleY: Longword; +begin + movingCrosshair := false; + stopFiring:= false; + walkingLeft := false; + walkingRight := false; + + leftButtonBoundary := cScreenWidth div 4; + rightButtonBoundary := cScreenWidth div 4*3; + topButtonBoundary := cScreenHeight div 6; + + setLength(fingers, 4); + for index := 0 to High(fingers) do + fingers[index].id := nilFingerId; + + + //uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2); + fireButtonLeft := Round(cScreenWidth*0.01); + fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4)); + fireButtonBottom := Round(cScreenHeight*0.99); + fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4); +end; + +begin +end. diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uTypes.pas --- a/hedgewars/uTypes.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uTypes.pas Sat Nov 12 17:06:49 2011 +0100 @@ -44,7 +44,7 @@ // Different files are stored in different folders, this enumeration is used to tell which folder to use TPathType = (ptNone, ptData, ptGraphics, ptThemes, ptCurrTheme, ptTeams, ptMaps, ptMapCurrent, ptDemos, ptSounds, ptGraves, ptFonts, ptForts, - ptLocale, ptAmmoMenu, ptHedgehog, ptVoices, ptHats, ptFlags, ptMissionMaps, ptSuddenDeath); + ptLocale, ptAmmoMenu, ptHedgehog, ptVoices, ptHats, ptFlags, ptMissionMaps, ptSuddenDeath, ptButtons); // Available sprites for displaying stuff TSprite = (sprWater, sprCloud, sprBomb, sprBigDigit, sprFrame, @@ -82,7 +82,8 @@ sprSMineOff, sprSMineOn, sprHandSMine, sprHammer, sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb, sprBulletHit, sprSnowball, sprHandSnowball, sprSnow, - sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet, sprTardis + sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet, sprTardis, + sprFireButton ); // Gears that interact with other Gears and/or Land @@ -152,7 +153,7 @@ // Different kind of crates that e.g. hedgehogs can pick up TCrateType = (HealthCrate, AmmoCrate, UtilityCrate); - THWFont = (fnt16, fntBig, fntSmall {$IFNDEF IPHONEOS}, CJKfnt16, CJKfntBig, CJKfntSmall{$ENDIF}); + THWFont = (fnt16, fntBig, fntSmall {$IFNDEF MOBILE}, CJKfnt16, CJKfntBig, CJKfntSmall{$ENDIF}); TCapGroup = (capgrpGameState, capgrpAmmoinfo, capgrpVolume, capgrpMessage, capgrpMessage2, capgrpAmmostate); diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uUtils.pas --- a/hedgewars/uUtils.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uUtils.pas Sat Nov 12 17:06:49 2011 +0100 @@ -274,7 +274,7 @@ tmpstr: array[0..256] of WideChar; begin -{$IFNDEF IPHONEOS} +{$IFNDEF MOBILE} // remove chinese fonts for now if (font >= CJKfnt16) or (length(s) = 0) then {$ENDIF} @@ -333,12 +333,13 @@ end; procedure initModule; -{$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF} +{$IFDEF DEBUGFILE}{$IFNDEF MOBILE}var i: LongInt;{$ENDIF}{$ENDIF} begin {$IFDEF DEBUGFILE} {$I-} -{$IFDEF IPHONEOS} - Assign(f,'../Documents/hw-' + cLogfileBase + '.log'); +{$IFDEF MOBILE} + {$IFDEF IPHONEOS} Assign(f,'../Documents/hw-' + cLogfileBase + '.log'); {$ENDIF} + {$IFDEF ANDROID} Assign(f,pathPrefix + '/' + cLogfileBase + '.log'); {$ENDIF} Rewrite(f); {$ELSE} if (UserPathPrefix <> '') then diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uVariables.pas Sat Nov 12 17:06:49 2011 +0100 @@ -137,6 +137,8 @@ bWaterRising : boolean; //ShowCrosshair : boolean; This variable is inconvenient to set. Easier to decide when rendering + CrosshairX : LongInt; + CrosshairY : LongInt; CursorMovementX : LongInt; CursorMovementY : LongInt; cDrownSpeed : hwFloat; @@ -213,7 +215,8 @@ 'Graphics/Hats', // ptHats 'Graphics/Flags', // ptFlags 'Missions/Maps', // ptMissionMaps - 'Graphics/SuddenDeath' // ptSuddenDeath + 'Graphics/SuddenDeath', // ptSuddenDeath + 'Graphics/Buttons' // ptButton ); cTagsMasks : array[0..15] of byte = (7, 0, 0, 0, 15, 6, 4, 5, 0, 0, 0, 0, 0, 14, 12, 13); @@ -243,7 +246,7 @@ Height: 10; style: TTF_STYLE_NORMAL; Name: 'DejaVuSans-Bold.ttf') - {$IFNDEF IPHONEOS}, // remove chinese fonts for now + {$IFNDEF MOBILE}, // remove chinese fonts for now (Handle: nil; Height: 12; style: TTF_STYLE_NORMAL; @@ -620,8 +623,10 @@ Width: 80; Height: 50; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprSDSplash (FileName: 'SDDroplet'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil; Width: 16; Height: 16; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprSDDroplet - (FileName: 'TARDIS'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil; - Width: 48; Height: 79; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true)// sprTardis + (FileName: 'Egg'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;//TODO change back 'Egg' to 'Tardis' + Width: 0; Height: 0; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true),// sprTardis + (FileName: 'firebutton'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil; + Width: 450; Height: 150; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true) // sprFireButton ); @@ -759,7 +764,7 @@ (FileName: 'bump.ogg'; Path: ptSounds),// sndBump (FileName: 'hogchant3.ogg'; Path: ptSounds),// sndResurrector (FileName: 'plane.ogg'; Path: ptSounds), // sndPlane - (FileName: 'TARDIS.ogg'; Path: ptSounds) // sndTardis + (FileName: 'plane.ogg'; Path: ptSounds) // sndTardis TODO change when using a new data set ); Ammoz: array [TAmmoType] of record diff -r 07d83af9d2a8 -r d14adf1c7721 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Fri Nov 11 15:28:58 2011 -0500 +++ b/hedgewars/uWorld.pas Sat Nov 12 17:06:49 2011 +0100 @@ -306,11 +306,6 @@ inc(g) end; inc(t) - end; - for g:= g to cMaxSlotAmmoIndex do - DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1); - DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1); - inc(y, AMSlotSize); end; DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2); @@ -909,7 +904,7 @@ SetScale(cDefaultZoomLevel); // Turn time -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} offsetX:= cScreenHeight - 13; {$ELSE} offsetX:= 48; @@ -938,6 +933,10 @@ // Captions DrawCaptions; +{$IFDEF ANDROID} +// Draw buttons Related to the Touch interface +DrawTexture(Round(-cScreenWidth*0.5 + cScreenHeight*0.02),Round((cScreenHeight*0.98)-(spritesData[sprFireButton].Height*0.4) ),spritesData[sprFireButton].Texture, 0.4); +{$ENDIF} // Teams Healths if TeamsCount * 20 > Longword(cScreenHeight) div 7 then // take up less screen on small displays begin @@ -1011,7 +1010,7 @@ if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12); // Wind bar -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} offsetX:= cScreenHeight - 13; offsetY:= (cScreenWidth shr 1) + 74; {$ELSE} @@ -1063,7 +1062,7 @@ end; // fps -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} offsetX:= 8; {$ELSE} offsetX:= 10; @@ -1206,7 +1205,7 @@ var EdgesDist, wdy, shs,z: LongInt; PrevSentPointTime: LongWord = 0; begin -{$IFNDEF IPHONEOS} +{$IFNDEF MOBILE} if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus and (GameState <> gsConfirm) then uCursor.updatePosition(); {$ENDIF} @@ -1234,7 +1233,7 @@ if AMxShift < AMWidth then begin -{$IFDEF IPHONEOS} +{$IFDEF MOBILE} if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth; if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,6 @@ +MISC_DIR := $(call my-dir) +LOCAL_PATH := MISC_DIR + +include $(MISC_DIR)/libfreetype/Android.mk +include $(MISC_DIR)/liblua/Android.mk +include $(MISC_DIR)/libtremor/Android.mk diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libfreetype/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libfreetype/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,45 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# compile in ARM mode, since the glyph loader/renderer is a hotspot +# when loading complex pages in the browser +# +LOCAL_ARM_MODE := arm + +LOCAL_SRC_FILES:= \ + src/base/ftbbox.c \ + src/base/ftbitmap.c \ + src/base/ftglyph.c \ + src/base/ftstroke.c \ + src/base/ftxf86.c \ + src/base/ftbase.c \ + src/base/ftsystem.c \ + src/base/ftinit.c \ + src/base/ftgasp.c \ + src/raster/raster.c \ + src/sfnt/sfnt.c \ + src/smooth/smooth.c \ + src/autofit/autofit.c \ + src/truetype/truetype.c \ + src/cff/cff.c \ + src/psnames/psnames.c \ + src/pshinter/pshinter.c + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/builds \ + $(LOCAL_PATH)/include + +LOCAL_CFLAGS += -W -Wall +LOCAL_CFLAGS += -fPIC -DPIC +LOCAL_CFLAGS += "-DDARWIN_NO_CARBON" +LOCAL_CFLAGS += "-DFT2_BUILD_LIBRARY" + +# the following is for testing only, and should not be used in final builds +# of the product +#LOCAL_CFLAGS += "-DTT_CONFIG_OPTION_BYTECODE_INTERPRETER" + +LOCAL_CFLAGS += -O2 + +LOCAL_MODULE:= freetype + +include $(BUILD_STATIC_LIBRARY) diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libfreetype/include/freetype/config/ftconfig.h --- a/misc/libfreetype/include/freetype/config/ftconfig.h Fri Nov 11 15:28:58 2011 -0500 +++ b/misc/libfreetype/include/freetype/config/ftconfig.h Sat Nov 12 17:06:49 2011 +0100 @@ -340,6 +340,7 @@ #define FT_MULFIX_ASSEMBLER FT_MulFix_arm /* documentation is in freetype.h */ + // Xeli: Got this snippet from a 2.4.6 source static __inline__ FT_Int32 FT_MulFix_arm( FT_Int32 a, @@ -347,7 +348,6 @@ { register FT_Int32 t, t2; -<<<<<<< Updated upstream __asm__ __volatile__ ( "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */ @@ -357,17 +357,6 @@ "adc %2, %2, #0\n\t" /* %2 += carry */ "mov %0, %1, lsr #16\n\t" /* %0 = %1 >> 16 */ "orr %0, %0, %2, lsl #16\n\t" /* %0 |= %2 << 16 */ -======= -#warning Should this be __asm__ ? - asm __volatile__ ( - "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */ - "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */ - "add %0, %0, #0x8000\n\t" /* %0 += 0x8000 */ - "adds %1, %1, %0\n\t" /* %1 += %0 */ - "adc %2, %2, #0\n\t" /* %2 += carry */ - "mov %0, %1, lsr #16\n\t" /* %0 = %1 >> 16 */ - "orr %0, %2, lsl #16\n\t" /* %0 |= %2 << 16 */ ->>>>>>> Stashed changes : "=r"(a), "=&r"(t2), "=&r"(t) : "r"(a), "r"(b) ); return a; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/liblua/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/liblua/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := lua5.1 + +LOCAL_CFLAGS := -DANDROID + +LOCAL_SRC_FILES := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c lvm.c lzio.c + +include $(BUILD_SHARED_LIBRARY) + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/liblua/llex.c --- a/misc/liblua/llex.c Fri Nov 11 15:28:58 2011 -0500 +++ b/misc/liblua/llex.c Sat Nov 12 17:06:49 2011 +0100 @@ -176,9 +176,15 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* format error: try to update decimal point separator */ +#ifndef ANDROID struct lconv *cv = localeconv(); +#endif char old = ls->decpoint; +#ifdef ANDROID + ls->decpoint = '.'; +#else ls->decpoint = (cv ? cv->decimal_point[0] : '.'); +#endif buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { /* format error with correct decimal point: no more options */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,27 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := tremor + +LOCAL_CFLAGS := -I$(LOCAL_PATH) -DHAVE_ALLOCA_H + +LOCAL_SRC_FILES = \ + tremor/bitwise.c \ + tremor/block.c \ + tremor/codebook.c \ + tremor/floor0.c \ + tremor/floor1.c \ + tremor/framing.c \ + tremor/info.c \ + tremor/mapping0.c \ + tremor/mdct.c \ + tremor/registry.c \ + tremor/res012.c \ + tremor/sharedbook.c \ + tremor/synthesis.c \ + tremor/vorbisfile.c \ + tremor/window.c + +include $(BUILD_STATIC_LIBRARY) + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/CHANGELOG --- a/misc/libtremor/CHANGELOG Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -*** 20020517: 1.0.2 *** - - Playback bugfix to floor1; mode mistakenly used for sizing instead - of blockflag - -*** 20020515: 1.0.1 *** - - Added complete API documentation to source tarball. No code - changes. - -*** 20020412: 1.0.1 *** - - Fixed a clipping bug that affected ARM processors; negative - overflows were being properly clipped, but then clobbered to - positive by the positive overflow chec (asm_arm.h:CLIP_TO_15) - -*** 20020403: 1.0.0 *** - - Initial version \ No newline at end of file diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/COPYING --- a/misc/libtremor/COPYING Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -Copyright (c) 2002, Xiph.org Foundation - -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 name of the Xiph.org Foundation 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 FOUNDATION -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. diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Makefile.am --- a/misc/libtremor/Makefile.am Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -AUTOMAKE_OPTIONS = foreign - -INCLUDES = -I./ - -lib_LTLIBRARIES = libvorbisidec.la - -libvorbisidec_la_SOURCES = mdct.c block.c window.c \ - synthesis.c info.c \ - floor1.c floor0.c vorbisfile.c \ - res012.c mapping0.c registry.c codebook.c \ - sharedbook.c framing.c bitwise.c \ - codebook.h misc.h mdct_lookup.h\ - os.h mdct.h block.h ivorbisfile.h lsp_lookup.h\ - registry.h window.h window_lookup.h\ - codec_internal.h backends.h ogg.h \ - asm_arm.h ivorbiscodec.h -libvorbisidec_la_LDFLAGS = -version-info @V_LIB_CURRENT@:@V_LIB_REVISION@:@V_LIB_AGE@ - -EXTRA_PROGRAMS = ivorbisfile_example -CLEANFILES = $(EXTRA_PROGRAMS) $(lib_LTLIBRARIES) - -ivorbisfile_example_SOURCES = ivorbisfile_example.c -ivorbisfile_example_LDFLAGS = -static -ivorbisfile_example_LDADD = libvorbisidec.la - -includedir = $(prefix)/include/tremor - -include_HEADERS = ivorbiscodec.h ivorbisfile.h ogg.h os_types.h config_types.h - -example: - -ln -fs . vorbis - $(MAKE) ivorbisfile_example - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/README --- a/misc/libtremor/README Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -This README covers the Ogg Vorbis 'Tremor' integer playback codec -source as of date 2002 09 02, version 1.0.0. - - ****** - -The C source in this package will build on any ANSI C compiler and -function completely and properly on any platform. The included build -system assumes GNU build system and make tools (m4, automake, -autoconf, libtool and gmake). GCC is not required, although GCC is -the most tested compiler. To build using GNU tools, type in the -source directory: - -./autogen.sh -make - -Currently, the source implements playback in pure C on all platforms -except ARM, where a [currently] small amount of assembly (see -asm_arm.h) is used to implement 64 bit math operations and fast LSP -computation. If building on ARM without the benefit of GNU build -system tools, be sure that '_ARM_ASSEM_' is #defined by the build -system if this assembly is desired, else the resulting library will -use whatever 64 bit math builtins the compiler implements. - -No math library is required by this source. No floating point -operations are used at any point in either setup or decode. This -decoder library will properly decode any past, current or future -Vorbis I file or stream. - - ******** - -The build system produces a static and [when supported by the OS] -dynamic library named 'libvorbisidec'. This library exposes an API -nearly identical to the BSD reference library's 'libvorbisfile', -including all the features familiar to users of vorbisfile. This API -is similar enough that the proper header file to include is named -'ivorbisfile.h' [included in the source build directory]. Lower level -libvorbis-style headers and structures are in 'ivorbiscodec.h' -[included in the source build directory]. A simple example program, -ivorbisfile_example.c, can be built with 'make example'. - - ******** - -Detailed Tremor API Documentation begins at doc/index.html - -Monty -xiph.org diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Version_script.in --- a/misc/libtremor/Version_script.in Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -# -# Export file for libvorbisidec -# -# Only the symbols listed in the global section will be callable from -# applications linking to libvorbisidec. -# - -@PACKAGE@.so.1 -{ - global: - ov_clear; - ov_open; - ov_open_callbacks; - ov_test; - ov_test_callbacks; - ov_test_open; - ov_bitrate; - ov_bitrate_instant; - ov_streams; - ov_seekable; - ov_serialnumber; - ov_raw_total; - ov_pcm_total; - ov_time_total; - ov_raw_seek; - ov_pcm_seek; - ov_pcm_seek_page; - ov_time_seek; - ov_time_seek_page; - ov_raw_tell; - ov_pcm_tell; - ov_time_tell; - ov_info; - ov_comment; - ov_read; - - vorbis_info_init; - vorbis_info_clear; - vorbis_info_blocksize; - vorbis_comment_init; - vorbis_comment_add; - vorbis_comment_add_tag; - vorbis_comment_query; - vorbis_comment_query_count; - vorbis_comment_clear; - - local: - *; -}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Xcode/Tremor.xcodeproj/default.mode1v3 diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Xcode/Tremor.xcodeproj/default.pbxuser diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Xcode/Tremor.xcodeproj/project.pbxproj diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/Xcode/Tremor_Prefix.pch diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/asm_arm.h --- a/misc/libtremor/asm_arm.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,243 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - 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; -} - -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; -} - -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 - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/autogen.sh --- a/misc/libtremor/autogen.sh Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -#!/bin/sh -# Run this to set up the build system: configure, makefiles, etc. -# (based on the version in enlightenment's cvs) - -package="vorbisdec" - -olddir=`pwd` -srcdir=`dirname $0` -test -z "$srcdir" && srcdir=. - -cd "$srcdir" -DIE=0 - -echo "checking for autoconf... " -(autoconf --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have autoconf installed to compile $package." - echo "Download the appropriate package for your distribution," - echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" - DIE=1 -} - -VERSIONGREP="sed -e s/.*[^0-9\.]\([0-9]\.[0-9]\).*/\1/" -VERSIONMKINT="sed -e s/[^0-9]//" - -# do we need automake? -if test -r Makefile.am; then - AM_OPTIONS=`fgrep AUTOMAKE_OPTIONS Makefile.am` - AM_NEEDED=`echo $AM_OPTIONS | $VERSIONGREP` - if test x"$AM_NEEDED" = "x$AM_OPTIONS"; then - AM_NEEDED="" - fi - if test -z $AM_NEEDED; then - echo -n "checking for automake... " - AUTOMAKE=automake - ACLOCAL=aclocal - if ($AUTOMAKE --version < /dev/null > /dev/null 2>&1); then - echo "yes" - else - echo "no" - AUTOMAKE= - fi - else - echo -n "checking for automake $AM_NEEDED or later... " - for am in automake-$AM_NEEDED automake$AM_NEEDED automake; do - ($am --version < /dev/null > /dev/null 2>&1) || continue - ver=`$am --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT` - verneeded=`echo $AM_NEEDED | $VERSIONMKINT` - if test $ver -ge $verneeded; then - AUTOMAKE=$am - echo $AUTOMAKE - break - fi - done - test -z $AUTOMAKE && echo "no" - echo -n "checking for aclocal $AM_NEEDED or later... " - for ac in aclocal-$AM_NEEDED aclocal$AM_NEEDED aclocal; do - ($ac --version < /dev/null > /dev/null 2>&1) || continue - ver=`$ac --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT` - verneeded=`echo $AM_NEEDED | $VERSIONMKINT` - if test $ver -ge $verneeded; then - ACLOCAL=$ac - echo $ACLOCAL - break - fi - done - test -z $ACLOCAL && echo "no" - fi - test -z $AUTOMAKE || test -z $ACLOCAL && { - echo - echo "You must have automake installed to compile $package." - echo "Download the appropriate package for your distribution," - echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" - exit 1 - } -fi - -echo -n "checking for libtool... " -for LIBTOOLIZE in libtoolize glibtoolize nope; do - ($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 && break -done -if test x$LIBTOOLIZE = xnope; then - echo "nope." - LIBTOOLIZE=libtoolize -else - echo $LIBTOOLIZE -fi -($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have libtool installed to compile $package." - echo "Download the appropriate package for your system," - echo "or get the source from one of the GNU ftp sites" - echo "listed in http://www.gnu.org/order/ftp.html" - DIE=1 -} - -if test "$DIE" -eq 1; then - exit 1 -fi - -if test -z "$*"; then - echo "I am going to run ./configure with no arguments - if you wish " - echo "to pass any to it, please specify them on the $0 command line." -fi - -echo "Generating configuration files for $package, please wait...." - -echo " $ACLOCAL $ACLOCAL_FLAGS" -$ACLOCAL $ACLOCAL_FLAGS || exit 1 -echo " $LIBTOOLIZE --automake" -$LIBTOOLIZE --automake || exit 1 -echo " autoheader" -autoheader || exit 1 -echo " $AUTOMAKE --add-missing $AUTOMAKE_FLAGS" -$AUTOMAKE --add-missing $AUTOMAKE_FLAGS || exit 1 -echo " autoconf" -autoconf || exit 1 - -cd $olddir -$srcdir/configure --enable-maintainer-mode "$@" && echo diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/backends.h --- a/misc/libtremor/backends.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: backend and mapping structures - - ********************************************************************/ - -/* this is exposed up here because we need it for static modes. - Lookups for each backend aren't exposed because there's no reason - to do so */ - -#ifndef _vorbis_backend_h_ -#define _vorbis_backend_h_ - -#include "codec_internal.h" - -/* this would all be simpler/shorter with templates, but.... */ -/* Transform backend generic *************************************/ - -/* only mdct right now. Flesh it out more if we ever transcend mdct - in the transform domain */ - -/* Floor backend generic *****************************************/ -typedef struct{ - vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *); - vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_mode *, - vorbis_info_floor *); - void (*free_info) (vorbis_info_floor *); - void (*free_look) (vorbis_look_floor *); - void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *); - int (*inverse2) (struct vorbis_block *,vorbis_look_floor *, - void *buffer,ogg_int32_t *); -} vorbis_func_floor; - -typedef struct{ - int order; - long rate; - long barkmap; - - int ampbits; - int ampdB; - - int numbooks; /* <= 16 */ - int books[16]; - -} vorbis_info_floor0; - -#define VIF_POSIT 63 -#define VIF_CLASS 16 -#define VIF_PARTS 31 -typedef struct{ - int partitions; /* 0 to 31 */ - int partitionclass[VIF_PARTS]; /* 0 to 15 */ - - int class_dim[VIF_CLASS]; /* 1 to 8 */ - int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1< -#include -#include "ogg.h" - -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 }; - -/* mark read process as having run off the end */ -static void _adv_halt(oggpack_buffer *b){ - b->headptr=b->head->buffer->data+b->head->begin+b->head->length; - b->headend=-1; - b->headbit=0; -} - -/* 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<1){ - if(b->head->next){ - b->count+=b->head->length; - b->head=b->head->next; - 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<0 || b->headbit) - /* read has fallen off the end */ - _adv_halt(b); - - break; - } - } -} - -void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){ - memset(b,0,sizeof(*b)); - - b->tail=b->head=r; - b->count=0; - b->headptr=b->head->buffer->data+b->head->begin; - b->headend=b->head->length; - _span(b); -} - -#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=-1; - - 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 -1; - - 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; - return ret; -} - -/* limited to 32 at a time */ -void oggpack_adv(oggpack_buffer *b,int bits){ - bits+=b->headbit; - b->headbit=bits&7; - b->headptr+=bits/8; - if((b->headend-=bits/8)<1)_span(b); -} - -/* spans forward and finds next byte. Never halts */ -static void _span_one(oggpack_buffer *b){ - while(b->headend<1){ - if(b->head->next){ - b->count+=b->head->length; - b->head=b->head->next; - b->headptr=b->head->buffer->data+b->head->begin; - b->headend=b->head->length; - }else - break; - } -} - -static int _halt_one(oggpack_buffer *b){ - if(b->headend<1){ - _adv_halt(b); - return -1; - } - return 0; -} - -int oggpack_eop(oggpack_buffer *b){ - if(b->headend<0)return -1; - return 0; -} - -/* bits <= 32 */ -long oggpack_read(oggpack_buffer *b,int bits){ - unsigned long m=mask[bits]; - ogg_uint32_t ret=-1; - - bits+=b->headbit; - - if(bits >= b->headend<<3){ - - if(b->headend<0)return -1; - - if(bits){ - if (_halt_one(b)) return -1; - ret=*b->headptr>>b->headbit; - - if(bits>=8){ - ++b->headptr; - --b->headend; - _span_one(b); - if(bits>8){ - if (_halt_one(b)) return -1; - ret|=*b->headptr<<(8-b->headbit); - - if(bits>=16){ - ++b->headptr; - --b->headend; - _span_one(b); - if(bits>16){ - if (_halt_one(b)) return -1; - ret|=*b->headptr<<(16-b->headbit); - - if(bits>=24){ - ++b->headptr; - --b->headend; - _span_one(b); - if(bits>24){ - if (_halt_one(b)) return -1; - ret|=*b->headptr<<(24-b->headbit); - - if(bits>=32){ - ++b->headptr; - --b->headend; - _span_one(b); - if(bits>32){ - if (_halt_one(b)) return -1; - if(b->headbit)ret|=*b->headptr<<(32-b->headbit); - - } - } - } - } - } - } - } - } - } - }else{ - - 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); - } - } - } - } - - b->headptr+=bits/8; - b->headend-=bits/8; - } - - ret&=m; - b->headbit=bits&7; - return ret; -} - -long oggpack_bytes(oggpack_buffer *b){ - return(b->count+b->headptr-b->head->buffer->data-b->head->begin+ - (b->headbit+7)/8); -} - -long oggpack_bits(oggpack_buffer *b){ - return((b->count+b->headptr-b->head->buffer->data-b->head->begin)*8+ - b->headbit); -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/block.c --- a/misc/libtremor/block.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,453 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: PCM data vector blocking, windowing and dis/reassembly - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" - -#include "window.h" -#include "registry.h" -#include "misc.h" - -static int ilog(unsigned int v){ - int ret=0; - if(v)--v; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -/* pcm accumulator examples (not exhaustive): - - <-------------- lW ----------------> - <--------------- W ----------------> -: .....|..... _______________ | -: .''' | '''_--- | |\ | -:.....''' |_____--- '''......| | \_______| -:.................|__________________|_______|__|______| - |<------ Sl ------>| > Sr < |endW - |beginSl |endSl | |endSr - |beginW |endlW |beginSr - - - |< lW >| - <--------------- W ----------------> - | | .. ______________ | - | | ' `/ | ---_ | - |___.'___/`. | ---_____| - |_______|__|_______|_________________| - | >|Sl|< |<------ Sr ----->|endW - | | |endSl |beginSr |endSr - |beginW | |endlW - mult[0] |beginSl mult[n] - - <-------------- lW -----------------> - |<--W-->| -: .............. ___ | | -: .''' |`/ \ | | -:.....''' |/`....\|...| -:.........................|___|___|___| - |Sl |Sr |endW - | | |endSr - | |beginSr - | |endSl - |beginSl - |beginW -*/ - -/* block abstraction setup *********************************************/ - -#ifndef WORD_ALIGN -#define WORD_ALIGN 8 -#endif - -int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ - memset(vb,0,sizeof(*vb)); - vb->vd=v; - vb->localalloc=0; - vb->localstore=NULL; - - return(0); -} - -void *_vorbis_block_alloc(vorbis_block *vb,long bytes){ - bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1); - if(bytes+vb->localtop>vb->localalloc){ - /* can't just _ogg_realloc... there are outstanding pointers */ - if(vb->localstore){ - struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link)); - vb->totaluse+=vb->localtop; - link->next=vb->reap; - link->ptr=vb->localstore; - vb->reap=link; - } - /* highly conservative */ - vb->localalloc=bytes; - vb->localstore=_ogg_malloc(vb->localalloc); - vb->localtop=0; - } - { - void *ret=(void *)(((char *)vb->localstore)+vb->localtop); - vb->localtop+=bytes; - return ret; - } -} - -/* reap the chain, pull the ripcord */ -void _vorbis_block_ripcord(vorbis_block *vb){ - /* reap the chain */ - struct alloc_chain *reap=vb->reap; - while(reap){ - struct alloc_chain *next=reap->next; - _ogg_free(reap->ptr); - memset(reap,0,sizeof(*reap)); - _ogg_free(reap); - reap=next; - } - /* consolidate storage */ - if(vb->totaluse){ - vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc); - vb->localalloc+=vb->totaluse; - vb->totaluse=0; - } - - /* pull the ripcord */ - vb->localtop=0; - vb->reap=NULL; -} - -int vorbis_block_clear(vorbis_block *vb){ - _vorbis_block_ripcord(vb); - if(vb->localstore)_ogg_free(vb->localstore); - - memset(vb,0,sizeof(*vb)); - return(0); -} - -static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ - int i; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - private_state *b=NULL; - - memset(v,0,sizeof(*v)); - b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b))); - - v->vi=vi; - b->modebits=ilog(ci->modes); - - /* Vorbis I uses only window type 0 */ - b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2); - b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2); - - /* finish the codebooks */ - if(!ci->fullbooks){ - ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); - for(i=0;ibooks;i++){ - vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]); - /* decode codebooks are now standalone after init */ - vorbis_staticbook_destroy(ci->book_param[i]); - ci->book_param[i]=NULL; - } - } - - v->pcm_storage=ci->blocksizes[1]; - v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm)); - v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret)); - for(i=0;ichannels;i++) - v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i])); - - /* all 1 (large block) or 0 (small block) */ - /* explicitly set for the sake of clarity */ - v->lW=0; /* previous window size */ - v->W=0; /* current window size */ - - /* initialize all the mapping/backend lookups */ - b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode)); - for(i=0;imodes;i++){ - int mapnum=ci->mode_param[i]->mapping; - int maptype=ci->map_type[mapnum]; - b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i], - ci->map_param[mapnum]); - } - return(0); -} - -int vorbis_synthesis_restart(vorbis_dsp_state *v){ - vorbis_info *vi=v->vi; - codec_setup_info *ci; - - if(!v->backend_state)return -1; - if(!vi)return -1; - ci=vi->codec_setup; - if(!ci)return -1; - - v->centerW=ci->blocksizes[1]/2; - v->pcm_current=v->centerW; - - v->pcm_returned=-1; - v->granulepos=-1; - v->sequence=-1; - ((private_state *)(v->backend_state))->sample_count=-1; - - return(0); -} - -int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ - _vds_init(v,vi); - vorbis_synthesis_restart(v); - - return(0); -} - -void vorbis_dsp_clear(vorbis_dsp_state *v){ - int i; - if(v){ - vorbis_info *vi=v->vi; - codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); - private_state *b=(private_state *)v->backend_state; - - if(v->pcm){ - for(i=0;ichannels;i++) - if(v->pcm[i])_ogg_free(v->pcm[i]); - _ogg_free(v->pcm); - if(v->pcmret)_ogg_free(v->pcmret); - } - - /* free mode lookups; these are actually vorbis_look_mapping structs */ - if(ci){ - for(i=0;imodes;i++){ - int mapnum=ci->mode_param[i]->mapping; - int maptype=ci->map_type[mapnum]; - if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]); - } - } - - if(b){ - if(b->mode)_ogg_free(b->mode); - _ogg_free(b); - } - - memset(v,0,sizeof(*v)); - } -} - -/* Unlike in analysis, the window is only partially applied for each - block. The time domain envelope is not yet handled at the point of - calling (as it relies on the previous block). */ - -int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ - vorbis_info *vi=v->vi; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - private_state *b=v->backend_state; - int i,j; - - if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL); - - v->lW=v->W; - v->W=vb->W; - v->nW=-1; - - if((v->sequence==-1)|| - (v->sequence+1 != vb->sequence)){ - v->granulepos=-1; /* out of sequence; lose count */ - b->sample_count=-1; - } - - v->sequence=vb->sequence; - - if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly - was called on block */ - int n=ci->blocksizes[v->W]/2; - int n0=ci->blocksizes[0]/2; - int n1=ci->blocksizes[1]/2; - - int thisCenter; - int prevCenter; - - if(v->centerW){ - thisCenter=n1; - prevCenter=0; - }else{ - thisCenter=0; - prevCenter=n1; - } - - /* v->pcm is now used like a two-stage double buffer. We don't want - to have to constantly shift *or* adjust memory usage. Don't - accept a new block until the old is shifted out */ - - /* overlap/add PCM */ - - for(j=0;jchannels;j++){ - /* the overlap/add section */ - if(v->lW){ - if(v->W){ - /* large/large */ - ogg_int32_t *pcm=v->pcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]; - for(i=0;ipcm[j]+prevCenter+n1/2-n0/2; - ogg_int32_t *p=vb->pcm[j]; - for(i=0;iW){ - /* small/large */ - ogg_int32_t *pcm=v->pcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2; - for(i=0;ipcm[j]+prevCenter; - ogg_int32_t *p=vb->pcm[j]; - for(i=0;ipcm[j]+thisCenter; - ogg_int32_t *p=vb->pcm[j]+n; - for(i=0;icenterW) - v->centerW=0; - else - v->centerW=n1; - - /* deal with initial packet state; we do this using the explicit - pcm_returned==-1 flag otherwise we're sensitive to first block - being short or long */ - - if(v->pcm_returned==-1){ - v->pcm_returned=thisCenter; - v->pcm_current=thisCenter; - }else{ - v->pcm_returned=prevCenter; - v->pcm_current=prevCenter+ - ci->blocksizes[v->lW]/4+ - ci->blocksizes[v->W]/4; - } - - } - - /* track the frame number... This is for convenience, but also - making sure our last packet doesn't end with added padding. If - the last packet is partial, the number of samples we'll have to - return will be past the vb->granulepos. - - 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(b->sample_count==-1){ - b->sample_count=0; - }else{ - b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; - } - - if(v->granulepos==-1){ - if(vb->granulepos!=-1){ /* only set if we have a position to set to */ - - v->granulepos=vb->granulepos; - - /* is this a short page? */ - if(b->sample_count>v->granulepos){ - /* corner case; if this is both the first and last audio page, - then spec says the end is cut, not beginning */ - if(vb->eofflag){ - /* 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 */ - - v->pcm_current-=(b->sample_count-v->granulepos); - }else{ - /* trim the beginning */ - v->pcm_returned+=(b->sample_count-v->granulepos); - if(v->pcm_returned>v->pcm_current) - v->pcm_returned=v->pcm_current; - } - - } - - } - }else{ - v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; - if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){ - - if(v->granulepos>vb->granulepos){ - long extra=v->granulepos-vb->granulepos; - - if(extra) - if(vb->eofflag){ - /* partial last frame. Strip the extra samples off */ - v->pcm_current-=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 } */ - v->granulepos=vb->granulepos; - } - } - - /* Update, cleanup */ - - if(vb->eofflag)v->eofflag=1; - return(0); -} - -/* pcm==NULL indicates we just want the pending samples, no more */ -int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){ - vorbis_info *vi=v->vi; - if(v->pcm_returned>-1 && v->pcm_returnedpcm_current){ - if(pcm){ - int i; - for(i=0;ichannels;i++) - v->pcmret[i]=v->pcm[i]+v->pcm_returned; - *pcm=v->pcmret; - } - return(v->pcm_current-v->pcm_returned); - } - return(0); -} - -int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){ - if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL); - v->pcm_returned+=bytes; - return(0); -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/block.h --- a/misc/libtremor/block.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2008 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: shared block functions - - ********************************************************************/ - -#ifndef _V_BLOCK_ -#define _V_BLOCK_ - -#include "ivorbiscodec.h" - -extern void _vorbis_block_ripcord(vorbis_block *vb); -extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes); - -#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/codebook.c --- a/misc/libtremor/codebook.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,371 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: basic codebook pack/unpack/code/decode operations - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codebook.h" -#include "misc.h" - -/* unpacks a codebook from the packet buffer into the codebook struct, - readies the codebook auxiliary structures for decode *************/ -int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ - long i,j; - 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->entries=oggpack_read(opb,24); - if(s->entries==-1)goto _eofout; - - /* codeword ordering.... length ordered or unordered? */ - switch((int)oggpack_read(opb,1)){ - case 0: - /* unordered */ - s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); - - /* allocated but unused entries? */ - if(oggpack_read(opb,1)){ - /* yes, unused entries */ - - for(i=0;ientries;i++){ - if(oggpack_read(opb,1)){ - long num=oggpack_read(opb,5); - if(num==-1)goto _eofout; - s->lengthlist[i]=num+1; - }else - s->lengthlist[i]=0; - } - }else{ - /* all entries used; no tagging */ - for(i=0;ientries;i++){ - long num=oggpack_read(opb,5); - if(num==-1)goto _eofout; - s->lengthlist[i]=num+1; - } - } - - break; - case 1: - /* ordered */ - { - long length=oggpack_read(opb,5)+1; - s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); - - for(i=0;ientries;){ - long num=oggpack_read(opb,_ilog(s->entries-i)); - if(num==-1)goto _eofout; - for(j=0;jentries;j++,i++) - s->lengthlist[i]=length; - length++; - } - } - break; - default: - /* EOF */ - return(-1); - } - - /* Do we have a mapping to unpack? */ - switch((s->maptype=oggpack_read(opb,4))){ - case 0: - /* no mapping */ - break; - case 1: case 2: - /* implicitly populated value mapping */ - /* explicitly populated value mapping */ - - s->q_min=oggpack_read(opb,32); - s->q_delta=oggpack_read(opb,32); - s->q_quant=oggpack_read(opb,4)+1; - s->q_sequencep=oggpack_read(opb,1); - - { - int quantvals=0; - switch(s->maptype){ - case 1: - quantvals=_book_maptype1_quantvals(s); - break; - case 2: - quantvals=s->entries*s->dim; - break; - } - - /* quantized values */ - s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals); - for(i=0;iquantlist[i]=oggpack_read(opb,s->q_quant); - - if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout; - } - break; - default: - goto _errout; - } - - /* all set */ - return(0); - - _errout: - _eofout: - vorbis_staticbook_clear(s); - return(-1); -} - -/* the 'eliminate the decode tree' optimization actually requires the - codewords to be MSb first, not LSb. This is an annoying inelegancy - (and one of the first places where carefully thought out design - turned out to be wrong; Vorbis II and future Ogg codecs should go - to an MSb bitpacker), but not actually the huge hit it appears to - be. The first-stage decode table catches most words so that - bitreverse is not in the main execution path. */ - -static ogg_uint32_t bitreverse(ogg_uint32_t x){ - x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000); - x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00); - x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0); - x= ((x>> 2)&0x33333333) | ((x<< 2)&0xcccccccc); - return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa); -} - -STIN long decode_packed_entry_number(codebook *book, - oggpack_buffer *b){ - int read=book->dec_maxlength; - long lo,hi; - long lok = oggpack_look(b,book->dec_firsttablen); - - if (lok >= 0) { - long entry = book->dec_firsttable[lok]; - if(entry&0x80000000UL){ - lo=(entry>>15)&0x7fff; - hi=book->used_entries-(entry&0x7fff); - }else{ - oggpack_adv(b, book->dec_codelengths[entry-1]); - return(entry-1); - } - }else{ - lo=0; - hi=book->used_entries; - } - - lok = oggpack_look(b, read); - - while(lok<0 && read>1) - lok = oggpack_look(b, --read); - - if(lok<0){ - oggpack_adv(b,1); /* force eop */ - return -1; - } - - /* bisect search for the codeword in the ordered list */ - { - ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); - - while(hi-lo>1){ - long p=(hi-lo)>>1; - long test=book->codelist[lo+p]>testword; - lo+=p&(test-1); - hi-=p&(-test); - } - - if(book->dec_codelengths[lo]<=read){ - oggpack_adv(b, book->dec_codelengths[lo]); - return(lo); - } - } - - oggpack_adv(b, read+1); - return(-1); -} - -/* Decode side is specced and easier, because we don't need to find - matches using different criteria; we simply read and map. There are - two things we need to do 'depending': - - We may need to support interleave. We don't really, but it's - convenient to do it here rather than rebuild the vector later. - - Cascades may be additive or multiplicitive; this is not inherent in - the codebook, but set in the code using the codebook. Like - interleaving, it's easiest to do it here. - addmul==0 -> declarative (set the value) - addmul==1 -> additive - addmul==2 -> multiplicitive */ - -/* returns the [original, not compacted] entry number or -1 on eof *********/ -long vorbis_book_decode(codebook *book, oggpack_buffer *b){ - if(book->used_entries>0){ - long packed_entry=decode_packed_entry_number(book,b); - if(packed_entry>=0) - return(book->dec_index[packed_entry]); - } - - /* if there's no dec_index, the codebook unpacking isn't collapsed */ - return(-1); -} - -/* 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; - long *entry = (long *)alloca(sizeof(*entry)*step); - ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step); - int i,j,o; - int shift=point-book->binarypoint; - - if(shift>=0){ - for (i = 0; i < step; i++) { - entry[i]=decode_packed_entry_number(book,b); - if(entry[i]==-1)return(-1); - t[i] = book->valuelist+entry[i]*book->dim; - } - for(i=0,o=0;idim;i++,o+=step) - for (j=0;j>shift; - }else{ - for (i = 0; i < step; i++) { - entry[i]=decode_packed_entry_number(book,b); - if(entry[i]==-1)return(-1); - t[i] = book->valuelist+entry[i]*book->dim; - } - for(i=0,o=0;idim;i++,o+=step) - for (j=0;jused_entries>0){ - int i,j,entry; - ogg_int32_t *t; - int shift=point-book->binarypoint; - - if(shift>=0){ - for(i=0;ivaluelist+entry*book->dim; - for (j=0;jdim;) - a[i++]+=t[j++]>>shift; - } - }else{ - for(i=0;ivaluelist+entry*book->dim; - for (j=0;jdim;) - a[i++]+=t[j++]<<-shift; - } - } - } - 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){ - int i,j,entry; - ogg_int32_t *t; - int shift=point-book->binarypoint; - - if(shift>=0){ - - for(i=0;ivaluelist+entry*book->dim; - for (j=0;jdim;){ - a[i++]=t[j++]>>shift; - } - } - }else{ - - for(i=0;ivaluelist+entry*book->dim; - for (j=0;jdim;){ - a[i++]=t[j++]<<-shift; - } - } - } - }else{ - - int i,j; - for(i=0;idim;){ - a[i++]=0; - } - } - } - return(0); -} - -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){ - long i,j,entry; - int chptr=0; - int shift=point-book->binarypoint; - - if(shift>=0){ - - for(i=offset;ivaluelist+entry*book->dim; - for (j=0;jdim;j++){ - a[chptr++][i]+=t[j]>>shift; - if(chptr==ch){ - chptr=0; - i++; - } - } - } - } - }else{ - - for(i=offset;ivaluelist+entry*book->dim; - for (j=0;jdim;j++){ - a[chptr++][i]+=t[j]<<-shift; - if(chptr==ch){ - chptr=0; - i++; - } - } - } - } - } - } - return(0); -} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/codebook.h --- a/misc/libtremor/codebook.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: basic shared codebook operations - - ********************************************************************/ - -#ifndef _V_CODEBOOK_H_ -#define _V_CODEBOOK_H_ - -#include "ogg.h" - -/* This structure encapsulates huffman and VQ style encoding books; it - doesn't do anything specific to either. - - valuelist/quantlist are nonNULL (and q_* significant) only if - there's entry->value mapping to be done. - - If encode-side mapping must be done (and thus the entry needs to be - hunted), the auxiliary encode pointer will point to a decision - tree. This is true of both VQ and huffman, but is mostly useful - with VQ. - -*/ - -typedef struct static_codebook{ - long dim; /* codebook dimensions (elements per vector) */ - long entries; /* codebook entries */ - long *lengthlist; /* codeword lengths in bits */ - - /* mapping ***************************************************************/ - int maptype; /* 0=none - 1=implicitly populated values from map column - 2=listed arbitrary values */ - - /* The below does a linear, single monotonic sequence mapping. */ - long q_min; /* packed 32 bit float; quant value 0 maps to minval */ - long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ - int q_quant; /* bits: 0 < quant <= 16 */ - int q_sequencep; /* bitflag */ - - long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map - map == 2: list of dim*entries quantized entry vals - */ -} static_codebook; - -typedef struct codebook{ - long dim; /* codebook dimensions (elements per vector) */ - long entries; /* codebook entries */ - long used_entries; /* populated codebook entries */ - - /* the below are ordered by bitreversed codeword and only used - entries are populated */ - int binarypoint; - ogg_int32_t *valuelist; /* list of dim*entries actual entry values */ - ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */ - - int *dec_index; - char *dec_codelengths; - ogg_uint32_t *dec_firsttable; - int dec_firsttablen; - int dec_maxlength; - - long q_min; /* packed 32 bit float; quant value 0 maps to minval */ - long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ - -} codebook; - -extern void vorbis_staticbook_clear(static_codebook *b); -extern void vorbis_staticbook_destroy(static_codebook *b); -extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); - -extern void vorbis_book_clear(codebook *b); -extern long _book_maptype1_quantvals(const static_codebook *b); - -extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_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 diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/codec_internal.h --- a/misc/libtremor/codec_internal.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: libvorbis codec headers - - ********************************************************************/ - -#ifndef _V_CODECI_H_ -#define _V_CODECI_H_ - -#include "codebook.h" - -typedef void vorbis_look_mapping; -typedef void vorbis_look_floor; -typedef void vorbis_look_residue; -typedef void vorbis_look_transform; - -/* mode ************************************************************/ -typedef struct { - int blockflag; - int windowtype; - int transformtype; - int mapping; -} vorbis_info_mode; - -typedef void vorbis_info_floor; -typedef void vorbis_info_residue; -typedef void vorbis_info_mapping; - -typedef struct private_state { - /* local lookup storage */ - const void *window[2]; - - /* backend lookups are tied to the mode, not the backend or naked mapping */ - int modebits; - vorbis_look_mapping **mode; - - ogg_int64_t sample_count; - -} private_state; - -/* 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 times; - int floors; - int residues; - int books; - - vorbis_info_mode *mode_param[64]; - int map_type[64]; - vorbis_info_mapping *map_param[64]; - int time_type[64]; - int floor_type[64]; - vorbis_info_floor *floor_param[64]; - int residue_type[64]; - vorbis_info_residue *residue_param[64]; - static_codebook *book_param[256]; - codebook *fullbooks; - - int passlimit[32]; /* iteration limit per couple/quant pass */ - int coupling_passes; -} codec_setup_info; - -#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/config_types.h --- a/misc/libtremor/config_types.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - 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; - -#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/configure.in --- a/misc/libtremor/configure.in Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -dnl Process this file with autoconf to produce a configure script - -dnl ------------------------------------------------ -dnl Initialization and Versioning -dnl ------------------------------------------------ - -AC_INIT(mdct.c) - -AC_CANONICAL_HOST -AC_CANONICAL_TARGET - -AM_CONFIG_HEADER([config.h]) - -AM_INIT_AUTOMAKE(libvorbisidec,1.2.0) - -dnl Library versioning - -V_LIB_CURRENT=1 -V_LIB_REVISION=2 -V_LIB_AGE=0 -AC_SUBST(V_LIB_CURRENT) -AC_SUBST(V_LIB_REVISION) -AC_SUBST(V_LIB_AGE) - -dnl -------------------------------------------------- -dnl Check for programs -dnl -------------------------------------------------- - -dnl save $CFLAGS since AC_PROG_CC likes to insert "-g -O2" -dnl if $CFLAGS is blank -cflags_save="$CFLAGS" -AC_PROG_CC -AC_PROG_CPP -CFLAGS="$cflags_save" - -AM_PROG_LIBTOOL - -dnl -------------------------------------------------- -dnl Set build flags based on environment -dnl -------------------------------------------------- - -dnl Set some target options - -cflags_save="$CFLAGS" -ldflags_save="$LDFLAGS" -if test -z "$GCC"; then - case $host in - arm-*-*) - DEBUG="-g -D_ARM_ASSEM_" - CFLAGS="-O -D_ARM_ASSEM_" - PROFILE="-p -g -O -D_ARM_ASSEM_" ;; - *) - DEBUG="-g" - CFLAGS="-O" - PROFILE="-g -p" ;; - esac -else - - case $host in - arm-*-*) - DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char -D_ARM_ASSEM_" - CFLAGS="-O2 -D_ARM_ASSEM_ -fsigned-char" - PROFILE="-W -pg -g -O2 -D_ARM_ASSEM_ -fsigned-char -fno-inline-functions";; - - *) - DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char" - CFLAGS="-O2 -Wall -fsigned-char" - PROFILE="-Wall -pg -g -O2 -fsigned-char -fno-inline-functions";; - esac -fi -CFLAGS="$CFLAGS $cflags_save -D_REENTRANT" -LDFLAGS="$LDFLAGS $ldflags_save" - - -# Test whenever ld supports -version-script -AC_PROG_LD -AC_PROG_LD_GNU -if test "x$lt_cv_prog_gnu_ld" = "xyes"; then - SHLIB_VERSION_ARG="Wl,--version-script=Version_script" - - dnl Set extra linker options - case "$target_os" in - linux* | solaris* ) - SHLIB_VERSION_ARG="-Wl,--version-script=Version_script" - ;; - *) - ;; - esac - LDFLAGS="$LDFLAGS $SHLIB_VERSION_ARG" -fi - -dnl -------------------------------------------------- -dnl Options -dnl -------------------------------------------------- - -AC_ARG_ENABLE( - low-accuracy, - [ --enable-low-accuracy enable 32 bit only multiply operations], - CFLAGS="$CFLAGS -D_LOW_ACCURACY_" -) - -dnl -------------------------------------------------- -dnl Check for headers -dnl -------------------------------------------------- - -AC_CHECK_HEADER(memory.h,CFLAGS="$CFLAGS -DUSE_MEMORY_H",:) - -dnl -------------------------------------------------- -dnl Check for typedefs, structures, etc -dnl -------------------------------------------------- - -dnl none - -dnl -------------------------------------------------- -dnl Check for library functions -dnl -------------------------------------------------- - -AC_FUNC_ALLOCA -AC_FUNC_MEMCMP - -dnl -------------------------------------------------- -dnl Do substitutions -dnl -------------------------------------------------- - -LIBS="$LIBS" - -AC_SUBST(LIBS) -AC_SUBST(DEBUG) -AC_SUBST(PROFILE) - -AC_OUTPUT(Makefile Version_script) diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/floor0.c --- a/misc/libtremor/floor0.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,435 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: floor backend 0 implementation - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "registry.h" -#include "codebook.h" -#include "misc.h" -#include "block.h" - -#define LSP_FRACBITS 14 - -typedef struct { - long n; - int ln; - int m; - int *linearmap; - - vorbis_info_floor0 *vi; - ogg_int32_t *lsp_look; - -} vorbis_look_floor0; - -/*************** 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}; -STIN 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 */ -STIN ogg_int32_t vorbis_fromdBlook_i(long a){ - int i=(-a)>>(12-FROMdB2_SHIFT); - if(i<0) return 0x7fffffff; - if(i>=(FROMdB_LOOKUP_SZ<>FROMdB_SHIFT] * FROMdB2_LOOKUP[i&FROMdB2_MASK]; -} - -/* 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 */ -STIN 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 lookup based cos function */ -/* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */ -STIN ogg_int32_t vorbis_coslook2_i(long a){ - a=a&0x1ffff; - - if(a>0x10000)a=0x20000-a; - { - int i=a>>COS_LOOKUP_I_SHIFT; - int d=a&COS_LOOKUP_I_MASK; - a=((COS_LOOKUP_I[i]<> - (COS_LOOKUP_I_SHIFT-LSP_FRACBITS+14); - } - - return(a); -} - -static const int barklook[28]={ - 0,100,200,301, 405,516,635,766, - 912,1077,1263,1476, 1720,2003,2333,2721, - 3184,3742,4428,5285, 6376,7791,9662,12181, - 15624,20397,27087,36554 -}; - -/* used in init only; interpolate the long way */ -STIN ogg_int32_t toBARK(int n){ - int i; - for(i=0;i<27;i++) - if(n>=barklook[i] && n>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>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>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(map[++i]==k) curve[i]= MULT31_SHIFT15(curve[i],amp); - } -} - -/*************** vorbis decode glue ************/ - -static void floor0_free_info(vorbis_info_floor *i){ - vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; - if(info){ - memset(info,0,sizeof(*info)); - _ogg_free(info); - } -} - -static void floor0_free_look(vorbis_look_floor *i){ - vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; - if(look){ - - if(look->linearmap)_ogg_free(look->linearmap); - if(look->lsp_look)_ogg_free(look->lsp_look); - memset(look,0,sizeof(*look)); - _ogg_free(look); - } -} - -static vorbis_info_floor *floor0_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; - if(info->numbooks<1)goto err_out; - - for(j=0;jnumbooks;j++){ - info->books[j]=oggpack_read(opb,8); - if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out; - } - return(info); - - err_out: - floor0_free_info(info); - return(NULL); -} - -/* initialize Bark scale and normalization lookups. We could do this - with static tables, but Vorbis allows a number of possible - combinations, so it's best to do it computationally. - - The below is authoritative in terms of defining scale mapping. - Note that the scale depends on the sampling rate as well as the - linear block and mapping sizes */ - -static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi, - vorbis_info_floor *i){ - int j; - vorbis_info *vi=vd->vi; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; - vorbis_look_floor0 *look=(vorbis_look_floor0 *)_ogg_calloc(1,sizeof(*look)); - look->m=info->order; - look->n=ci->blocksizes[mi->blockflag]/2; - look->ln=info->barkmap; - look->vi=info; - - /* the mapping from a linear scale to a smaller bark scale is - straightforward. We do *not* make sure that the linear mapping - does not skip bark-scale bins; the decoder simply skips them and - the encoder may do what it wishes in filling them. They're - necessary in some mapping combinations to keep the scale spacing - accurate */ - look->linearmap=(int *)_ogg_malloc((look->n+1)*sizeof(*look->linearmap)); - for(j=0;jn;j++){ - - int val=(look->ln* - ((toBARK(info->rate/2*j/look->n)<<11)/toBARK(info->rate/2)))>>11; - - if(val>=look->ln)val=look->ln-1; /* guard against the approximation */ - look->linearmap[j]=val; - } - look->linearmap[j]=-1; - - look->lsp_look=(ogg_int32_t *)_ogg_malloc(look->ln*sizeof(*look->lsp_look)); - for(j=0;jln;j++) - look->lsp_look[j]=vorbis_coslook2_i(0x10000*j/look->ln); - - return look; -} - -static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ - vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; - vorbis_info_floor0 *info=look->vi; - int j,k; - - int ampraw=oggpack_read(&vb->opb,info->ampbits); - if(ampraw>0){ /* also handles the -1 out of data case */ - long maxval=(1<ampbits)-1; - int amp=((ampraw*info->ampdB)<<4)/maxval; - int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks)); - - if(booknum!=-1 && booknumnumbooks){ /* be paranoid */ - codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; - codebook *b=ci->fullbooks+info->books[booknum]; - ogg_int32_t last=0; - ogg_int32_t *lsp=(ogg_int32_t *)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+1)); - - for(j=0;jm;j+=b->dim) - if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim,-24)==-1)goto eop; - for(j=0;jm;){ - for(k=0;kdim;k++,j++)lsp[j]+=last; - last=lsp[j-1]; - } - - lsp[look->m]=amp; - return(lsp); - } - } - eop: - return(NULL); -} - -static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, - void *memo,ogg_int32_t *out){ - vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; - vorbis_info_floor0 *info=look->vi; - - if(memo){ - ogg_int32_t *lsp=(ogg_int32_t *)memo; - ogg_int32_t amp=lsp[look->m]; - - /* take the coefficients back to a spectral envelope curve */ - vorbis_lsp_to_curve(out,look->linearmap,look->n,look->ln, - lsp,look->m,amp,info->ampdB,look->lsp_look); - return(1); - } - memset(out,0,sizeof(*out)*look->n); - return(0); -} - -/* export hooks */ -vorbis_func_floor floor0_exportbundle={ - &floor0_unpack,&floor0_look,&floor0_free_info, - &floor0_free_look,&floor0_inverse1,&floor0_inverse2 -}; - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/floor1.c --- a/misc/libtremor/floor1.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,441 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: floor backend 1 implementation - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "registry.h" -#include "codebook.h" -#include "misc.h" -#include "block.h" - -#define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */ - -typedef struct { - int forward_index[VIF_POSIT+2]; - - int hineighbor[VIF_POSIT]; - int loneighbor[VIF_POSIT]; - int posts; - - int n; - int quant_q; - vorbis_info_floor1 *vi; - -} vorbis_look_floor1; - -/***********************************************/ - -static void floor1_free_info(vorbis_info_floor *i){ - vorbis_info_floor1 *info=(vorbis_info_floor1 *)i; - if(info){ - memset(info,0,sizeof(*info)); - _ogg_free(info); - } -} - -static void floor1_free_look(vorbis_look_floor *i){ - vorbis_look_floor1 *look=(vorbis_look_floor1 *)i; - if(look){ - memset(look,0,sizeof(*look)); - _ogg_free(look); - } -} - -static int ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -static vorbis_info_floor *floor1_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 */ - for(j=0;jpartitions;j++){ - info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */ - if(maxclasspartitionclass[j])maxclass=info->partitionclass[j]; - } - - /* read partition classes */ - for(j=0;jclass_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */ - info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */ - if(info->class_subs[j]<0) - goto err_out; - if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8); - if(info->class_book[j]<0 || info->class_book[j]>=ci->books) - goto err_out; - for(k=0;k<(1<class_subs[j]);k++){ - info->class_subbook[j][k]=oggpack_read(opb,8)-1; - if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books) - 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;jpartitions;j++){ - count+=info->class_dim[info->partitionclass[j]]; - for(;kpostlist[k+2]=oggpack_read(opb,rangebits); - if(t<0 || t>=(1<postlist[0]=0; - info->postlist[1]=1<vi=info; - look->n=info->postlist[1]; - - /* we drop each position value in-between already decoded values, - and use linear interpolation to predict each new value past the - edges. The positions are read in the order of the position - list... we precompute the bounding positions in the lookup. Of - course, the neighbors can change (if a position is declined), but - this is an initial mapping */ - - for(i=0;ipartitions;i++)n+=info->class_dim[info->partitionclass[i]]; - n+=2; - look->posts=n; - - /* also store a sorted position index */ - for(i=0;ipostlist+i; - qsort(sortpointer,n,sizeof(*sortpointer),icomp); - - /* points from sort order back to range number */ - for(i=0;iforward_index[i]=sortpointer[i]-info->postlist; - - /* quantize values to multiplier spec */ - switch(info->mult){ - case 1: /* 1024 -> 256 */ - look->quant_q=256; - break; - case 2: /* 1024 -> 128 */ - look->quant_q=128; - break; - case 3: /* 1024 -> 86 */ - look->quant_q=86; - break; - case 4: /* 1024 -> 64 */ - look->quant_q=64; - break; - } - - /* discover our neighbors for decode where we don't use fit flags - (that would push the neighbors outward) */ - for(i=0;in; - int currentx=info->postlist[i+2]; - for(j=0;jpostlist[j]; - if(x>lx && xcurrentx){ - hi=j; - hx=x; - } - } - look->loneighbor[i]=lo; - look->hineighbor[i]=hi; - } - - return(look); -} - -static 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); - } -} - -#ifdef _LOW_ACCURACY_ -# define XdB(n) ((((n)>>8)+1)>>1) -#else -# define XdB(n) (n) -#endif - -static 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), -}; - -static void render_line(int n, int x0,int x1,int y0,int y1,ogg_int32_t *d){ - int dy=y1-y0; - int adx=x1-x0; - int ady=abs(dy); - int base=dy/adx; - int sy=(dy<0?base-1:base+1); - int x=x0; - int y=y0; - int err=0; - - if(n>x1)n=x1; - ady-=abs(base*adx); - - if(x=adx){ - err-=adx; - y+=sy; - }else{ - y+=base; - } - d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]); - } -} - -static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ - vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; - vorbis_info_floor1 *info=look->vi; - codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; - - int i,j,k; - codebook *books=ci->fullbooks; - - /* unpack wrapped/predicted values from stream */ - if(oggpack_read(&vb->opb,1)==1){ - int *fit_value=(int *)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value)); - - fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1)); - fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1)); - - /* partition by partition */ - /* partition by partition */ - for(i=0,j=2;ipartitions;i++){ - int classv=info->partitionclass[i]; - int cdim=info->class_dim[classv]; - int csubbits=info->class_subs[classv]; - int csub=1<class_book[classv],&vb->opb); - - if(cval==-1)goto eop; - } - - for(k=0;kclass_subbook[classv][cval&(csub-1)]; - cval>>=csubbits; - if(book>=0){ - if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) - goto eop; - }else{ - fit_value[j+k]=0; - } - } - j+=cdim; - } - - /* unwrap positive values and reconsitute via linear interpolation */ - for(i=2;iposts;i++){ - int predicted=render_point(info->postlist[look->loneighbor[i-2]], - info->postlist[look->hineighbor[i-2]], - fit_value[look->loneighbor[i-2]], - fit_value[look->hineighbor[i-2]], - info->postlist[i]); - int hiroom=look->quant_q-predicted; - int loroom=predicted; - int room=(hiroom=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[look->loneighbor[i-2]]&=0x7fff; - fit_value[look->hineighbor[i-2]]&=0x7fff; - - }else{ - fit_value[i]=predicted|0x8000; - } - - } - - return(fit_value); - } - eop: - return(NULL); -} - -static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, - ogg_int32_t *out){ - vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; - vorbis_info_floor1 *info=look->vi; - - codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; - int n=ci->blocksizes[vb->W]/2; - int j; - - if(memo){ - /* render the lines */ - int *fit_value=(int *)memo; - int hx=0; - int lx=0; - int ly=fit_value[0]*info->mult; - for(j=1;jposts;j++){ - int current=look->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 -#include -#include "ogg.h" -#include "misc.h" - - -/* A complete description of Ogg framing exists in docs/framing.html */ - -/* basic, centralized Ogg memory management based on linked lists of - references to refcounted memory buffers. References and buffers - are both recycled. Buffers are passed around and consumed in - reference form. */ - -static ogg_buffer_state *ogg_buffer_create(void){ - ogg_buffer_state *bs=_ogg_calloc(1,sizeof(*bs)); - return bs; -} - -/* destruction is 'lazy'; there may be memory references outstanding, - and yanking the buffer state out from underneath would be - antisocial. Dealloc what is currently unused and have - _release_one watch for the stragglers to come in. When they do, - finish destruction. */ - -/* call the helper while holding lock */ -static void _ogg_buffer_destroy(ogg_buffer_state *bs){ - ogg_buffer *bt; - ogg_reference *rt; - - if(bs->shutdown){ - - bt=bs->unused_buffers; - rt=bs->unused_references; - - while(bt){ - ogg_buffer *b=bt; - bt=b->ptr.next; - if(b->data)_ogg_free(b->data); - _ogg_free(b); - } - bs->unused_buffers=0; - while(rt){ - ogg_reference *r=rt; - rt=r->next; - _ogg_free(r); - } - bs->unused_references=0; - - if(!bs->outstanding) - _ogg_free(bs); - - } -} - -static void ogg_buffer_destroy(ogg_buffer_state *bs){ - bs->shutdown=1; - _ogg_buffer_destroy(bs); -} - -static ogg_buffer *_fetch_buffer(ogg_buffer_state *bs,long bytes){ - ogg_buffer *ob; - bs->outstanding++; - - /* do we have an unused buffer sitting in the pool? */ - if(bs->unused_buffers){ - ob=bs->unused_buffers; - bs->unused_buffers=ob->ptr.next; - - /* if the unused buffer is too small, grow it */ - if(ob->sizedata=_ogg_realloc(ob->data,bytes); - ob->size=bytes; - } - }else{ - /* allocate a new buffer */ - ob=_ogg_malloc(sizeof(*ob)); - ob->data=_ogg_malloc(bytes<16?16:bytes); - ob->size=bytes; - } - - ob->refcount=1; - ob->ptr.owner=bs; - return ob; -} - -static ogg_reference *_fetch_ref(ogg_buffer_state *bs){ - ogg_reference *or; - bs->outstanding++; - - /* do we have an unused reference sitting in the pool? */ - if(bs->unused_references){ - or=bs->unused_references; - bs->unused_references=or->next; - }else{ - /* allocate a new reference */ - or=_ogg_malloc(sizeof(*or)); - } - - or->begin=0; - or->length=0; - or->next=0; - return or; -} - -/* fetch a reference pointing to a fresh, initially continguous buffer - of at least [bytes] length */ -static ogg_reference *ogg_buffer_alloc(ogg_buffer_state *bs,long bytes){ - ogg_buffer *ob=_fetch_buffer(bs,bytes); - ogg_reference *or=_fetch_ref(bs); - or->buffer=ob; - return or; -} - -/* enlarge the data buffer in the current link */ -static void ogg_buffer_realloc(ogg_reference *or,long bytes){ - ogg_buffer *ob=or->buffer; - - /* if the unused buffer is too small, grow it */ - if(ob->sizedata=_ogg_realloc(ob->data,bytes); - ob->size=bytes; - } -} - -static void _ogg_buffer_mark_one(ogg_reference *or){ - or->buffer->refcount++; -} - -/* increase the refcount of the buffers to which the reference points */ -static void ogg_buffer_mark(ogg_reference *or){ - while(or){ - _ogg_buffer_mark_one(or); - or=or->next; - } -} - -/* duplicate a reference (pointing to the same actual buffer memory) - and increment buffer refcount. If the desired segment begins out - of range, NULL is returned; if the desired segment is simply zero - length, a zero length ref is returned. Partial range overlap - returns the overlap of the ranges */ -static ogg_reference *ogg_buffer_sub(ogg_reference *or,long begin,long length){ - ogg_reference *ret=0,*head=0; - - /* walk past any preceeding fragments we don't want */ - while(or && begin>=or->length){ - begin-=or->length; - or=or->next; - } - - /* duplicate the reference chain; increment refcounts */ - while(or && length){ - ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); - if(head) - head->next=temp; - else - ret=temp; - head=temp; - head->buffer=or->buffer; - head->begin=or->begin+begin; - head->length=length; - if(head->length>or->length-begin) - head->length=or->length-begin; - - begin=0; - length-=head->length; - or=or->next; - } - - ogg_buffer_mark(ret); - return ret; -} - -ogg_reference *ogg_buffer_dup(ogg_reference *or){ - ogg_reference *ret=0,*head=0; - /* duplicate the reference chain; increment refcounts */ - while(or){ - ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); - if(head) - head->next=temp; - else - ret=temp; - head=temp; - head->buffer=or->buffer; - head->begin=or->begin; - head->length=or->length; - or=or->next; - } - - ogg_buffer_mark(ret); - return ret; -} - -/* split a reference into two references; 'return' is a reference to - the buffer preceeding pos and 'head'/'tail' are the buffer past the - split. If pos is at or past the end of the passed in segment, - 'head/tail' are NULL */ -static ogg_reference *ogg_buffer_split(ogg_reference **tail, - ogg_reference **head,long pos){ - - /* walk past any preceeding fragments to one of: - a) the exact boundary that seps two fragments - b) the fragment that needs split somewhere in the middle */ - ogg_reference *ret=*tail; - ogg_reference *or=*tail; - - while(or && pos>or->length){ - pos-=or->length; - or=or->next; - } - - if(!or || pos==0){ - - return 0; - - }else{ - - if(pos>=or->length){ - /* exact split, or off the end? */ - if(or->next){ - - /* a split */ - *tail=or->next; - or->next=0; - - }else{ - - /* off or at the end */ - *tail=*head=0; - - } - }else{ - - /* split within a fragment */ - long lengthA=pos; - long beginB=or->begin+pos; - long lengthB=or->length-pos; - - /* make a new reference to tail the second piece */ - *tail=_fetch_ref(or->buffer->ptr.owner); - - (*tail)->buffer=or->buffer; - (*tail)->begin=beginB; - (*tail)->length=lengthB; - (*tail)->next=or->next; - _ogg_buffer_mark_one(*tail); - if(head && or==*head)*head=*tail; - - /* update the first piece */ - or->next=0; - or->length=lengthA; - - } - } - return ret; -} - -static void ogg_buffer_release_one(ogg_reference *or){ - ogg_buffer *ob=or->buffer; - ogg_buffer_state *bs=ob->ptr.owner; - - ob->refcount--; - if(ob->refcount==0){ - bs->outstanding--; /* for the returned buffer */ - ob->ptr.next=bs->unused_buffers; - bs->unused_buffers=ob; - } - - bs->outstanding--; /* for the returned reference */ - or->next=bs->unused_references; - bs->unused_references=or; - - _ogg_buffer_destroy(bs); /* lazy cleanup (if needed) */ - -} - -/* release the references, decrease the refcounts of buffers to which - they point, release any buffers with a refcount that drops to zero */ -static void ogg_buffer_release(ogg_reference *or){ - while(or){ - ogg_reference *next=or->next; - ogg_buffer_release_one(or); - or=next; - } -} - -static ogg_reference *ogg_buffer_pretruncate(ogg_reference *or,long pos){ - /* release preceeding fragments we don't want */ - while(or && pos>=or->length){ - ogg_reference *next=or->next; - pos-=or->length; - ogg_buffer_release_one(or); - or=next; - } - if (or) { - or->begin+=pos; - or->length-=pos; - } - return or; -} - -static ogg_reference *ogg_buffer_walk(ogg_reference *or){ - if(!or)return NULL; - while(or->next){ - or=or->next; - } - return(or); -} - -/* *head is appended to the front end (head) of *tail; both continue to - be valid pointers, with *tail at the tail and *head at the head */ -static ogg_reference *ogg_buffer_cat(ogg_reference *tail, ogg_reference *head){ - if(!tail)return head; - - while(tail->next){ - tail=tail->next; - } - tail->next=head; - return ogg_buffer_walk(head); -} - -static void _positionB(oggbyte_buffer *b,int pos){ - if(pospos){ - /* start at beginning, scan forward */ - b->ref=b->baseref; - b->pos=0; - b->end=b->pos+b->ref->length; - b->ptr=b->ref->buffer->data+b->ref->begin; - } -} - -static void _positionF(oggbyte_buffer *b,int pos){ - /* scan forward for position */ - while(pos>=b->end){ - /* just seek forward */ - b->pos+=b->ref->length; - b->ref=b->ref->next; - b->end=b->ref->length+b->pos; - b->ptr=b->ref->buffer->data+b->ref->begin; - } -} - -static int oggbyte_init(oggbyte_buffer *b,ogg_reference *or){ - memset(b,0,sizeof(*b)); - if(or){ - b->ref=b->baseref=or; - b->pos=0; - b->end=b->ref->length; - b->ptr=b->ref->buffer->data+b->ref->begin; - return 0; - }else - return -1; -} - -static void oggbyte_set4(oggbyte_buffer *b,ogg_uint32_t val,int pos){ - int i; - _positionB(b,pos); - for(i=0;i<4;i++){ - _positionF(b,pos); - b->ptr[pos-b->pos]=val; - val>>=8; - ++pos; - } -} - -static unsigned char oggbyte_read1(oggbyte_buffer *b,int pos){ - _positionB(b,pos); - _positionF(b,pos); - return b->ptr[pos-b->pos]; -} - -static ogg_uint32_t oggbyte_read4(oggbyte_buffer *b,int pos){ - ogg_uint32_t ret; - _positionB(b,pos); - _positionF(b,pos); - ret=b->ptr[pos-b->pos]; - _positionF(b,++pos); - ret|=b->ptr[pos-b->pos]<<8; - _positionF(b,++pos); - ret|=b->ptr[pos-b->pos]<<16; - _positionF(b,++pos); - ret|=b->ptr[pos-b->pos]<<24; - return ret; -} - -static ogg_int64_t oggbyte_read8(oggbyte_buffer *b,int pos){ - ogg_int64_t ret; - unsigned char t[7]; - int i; - _positionB(b,pos); - for(i=0;i<7;i++){ - _positionF(b,pos); - t[i]=b->ptr[pos++ -b->pos]; - } - - _positionF(b,pos); - ret=b->ptr[pos-b->pos]; - - for(i=6;i>=0;--i) - ret= ret<<8 | t[i]; - - return ret; -} - -/* Now we get to the actual framing code */ - -int ogg_page_version(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read1(&ob,4); -} - -int ogg_page_continued(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read1(&ob,5)&0x01; -} - -int ogg_page_bos(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read1(&ob,5)&0x02; -} - -int ogg_page_eos(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read1(&ob,5)&0x04; -} - -ogg_int64_t ogg_page_granulepos(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read8(&ob,6); -} - -ogg_uint32_t ogg_page_serialno(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read4(&ob,14); -} - -ogg_uint32_t ogg_page_pageno(ogg_page *og){ - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - return oggbyte_read4(&ob,18); -} - -/* returns the number of packets that are completed on this page (if - the leading packet is begun on a previous page, but ends on this - page, it's counted */ - -/* NOTE: -If a page consists of a packet begun on a previous page, and a new -packet begun (but not completed) on this page, the return will be: - ogg_page_packets(page) ==1, - ogg_page_continued(page) !=0 - -If a page happens to be a single packet that was begun on a -previous page, and spans to the next page (in the case of a three or -more page packet), the return will be: - ogg_page_packets(page) ==0, - ogg_page_continued(page) !=0 -*/ - -int ogg_page_packets(ogg_page *og){ - int i; - int n; - int count=0; - oggbyte_buffer ob; - oggbyte_init(&ob,og->header); - - n=oggbyte_read1(&ob,26); - for(i=0;ibufferpool=ogg_buffer_create(); - return oy; -} - -int ogg_sync_destroy(ogg_sync_state *oy){ - if(oy){ - ogg_sync_reset(oy); - ogg_buffer_destroy(oy->bufferpool); - memset(oy,0,sizeof(*oy)); - _ogg_free(oy); - } - return OGG_SUCCESS; -} - -unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long bytes){ - - /* [allocate and] expose a buffer for data submission. - - If there is no head fragment - allocate one and expose it - else - if the current head fragment has sufficient unused space - expose it - else - if the current head fragment is unused - resize and expose it - else - allocate new fragment and expose it - */ - - /* base case; fifo uninitialized */ - if(!oy->fifo_head){ - oy->fifo_head=oy->fifo_tail=ogg_buffer_alloc(oy->bufferpool,bytes); - return oy->fifo_head->buffer->data; - } - - /* space left in current fragment case */ - if(oy->fifo_head->buffer->size- - oy->fifo_head->length- - oy->fifo_head->begin >= bytes) - return oy->fifo_head->buffer->data+ - oy->fifo_head->length+oy->fifo_head->begin; - - /* current fragment is unused, but too small */ - if(!oy->fifo_head->length){ - ogg_buffer_realloc(oy->fifo_head,bytes); - return oy->fifo_head->buffer->data+oy->fifo_head->begin; - } - - /* current fragment used/full; get new fragment */ - { - ogg_reference *new=ogg_buffer_alloc(oy->bufferpool,bytes); - oy->fifo_head->next=new; - oy->fifo_head=new; - } - return oy->fifo_head->buffer->data; -} - -int ogg_sync_wrote(ogg_sync_state *oy, long bytes){ - if(!oy->fifo_head)return OGG_EINVAL; - if(oy->fifo_head->buffer->size-oy->fifo_head->length-oy->fifo_head->begin < - bytes)return OGG_EINVAL; - oy->fifo_head->length+=bytes; - oy->fifo_fill+=bytes; - return OGG_SUCCESS; -} - -static ogg_uint32_t _checksum(ogg_reference *or, int bytes){ - ogg_uint32_t crc_reg=0; - int j,post; - - while(or){ - unsigned char *data=or->buffer->data+or->begin; - post=(byteslength?bytes:or->length); - for(j=0;j> 24)&0xff)^data[j]]; - bytes-=j; - or=or->next; - } - - return crc_reg; -} - - -/* sync the stream. This is meant to be useful for finding page - boundaries. - - return values for this: - -n) skipped n bytes - 0) page not ready; more data (no bytes skipped) - n) page synced at current location; page length n bytes - -*/ - -long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){ - oggbyte_buffer page; - long bytes,ret=0; - - ogg_page_release(og); - - bytes=oy->fifo_fill; - oggbyte_init(&page,oy->fifo_tail); - - if(oy->headerbytes==0){ - if(bytes<27)goto sync_out; /* not enough for even a minimal header */ - - /* verify capture pattern */ - if(oggbyte_read1(&page,0)!=(int)'O' || - oggbyte_read1(&page,1)!=(int)'g' || - oggbyte_read1(&page,2)!=(int)'g' || - oggbyte_read1(&page,3)!=(int)'S' ) goto sync_fail; - - oy->headerbytes=oggbyte_read1(&page,26)+27; - } - if(bytesheaderbytes)goto sync_out; /* not enough for header + - seg table */ - if(oy->bodybytes==0){ - int i; - /* count up body length in the segment table */ - for(i=0;iheaderbytes-27;i++) - oy->bodybytes+=oggbyte_read1(&page,27+i); - } - - if(oy->bodybytes+oy->headerbytes>bytes)goto sync_out; - - /* we have what appears to be a complete page; last test: verify - checksum */ - { - ogg_uint32_t chksum=oggbyte_read4(&page,22); - oggbyte_set4(&page,0,22); - - /* Compare checksums; memory continues to be common access */ - if(chksum!=_checksum(oy->fifo_tail,oy->bodybytes+oy->headerbytes)){ - - /* D'oh. Mismatch! Corrupt page (or miscapture and not a page - at all). replace the computed checksum with the one actually - read in; remember all the memory is common access */ - - oggbyte_set4(&page,chksum,22); - goto sync_fail; - } - oggbyte_set4(&page,chksum,22); - } - - /* We have a page. Set up page return. */ - if(og){ - /* set up page output */ - og->header=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->headerbytes); - og->header_len=oy->headerbytes; - og->body=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->bodybytes); - og->body_len=oy->bodybytes; - }else{ - /* simply advance */ - oy->fifo_tail= - ogg_buffer_pretruncate(oy->fifo_tail,oy->headerbytes+oy->bodybytes); - if(!oy->fifo_tail)oy->fifo_head=0; - } - - ret=oy->headerbytes+oy->bodybytes; - oy->unsynced=0; - oy->headerbytes=0; - oy->bodybytes=0; - oy->fifo_fill-=ret; - - return ret; - - sync_fail: - - oy->headerbytes=0; - oy->bodybytes=0; - oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,1); - ret--; - - /* search forward through fragments for possible capture */ - while(oy->fifo_tail){ - /* invariant: fifo_cursor points to a position in fifo_tail */ - unsigned char *now=oy->fifo_tail->buffer->data+oy->fifo_tail->begin; - unsigned char *next=memchr(now, 'O', oy->fifo_tail->length); - - if(next){ - /* possible capture in this segment */ - long bytes=next-now; - oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes); - ret-=bytes; - break; - }else{ - /* no capture. advance to next segment */ - long bytes=oy->fifo_tail->length; - ret-=bytes; - oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes); - } - } - if(!oy->fifo_tail)oy->fifo_head=0; - oy->fifo_fill+=ret; - - sync_out: - return ret; -} - -/* sync the stream and get a page. Keep trying until we find a page. - Supress 'sync errors' after reporting the first. - - return values: - OGG_HOLE) recapture (hole in data) - 0) need more data - 1) page returned - - Returns pointers into buffered data; invalidated by next call to - _stream, _clear, _init, or _buffer */ - -int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){ - - /* all we need to do is verify a page at the head of the stream - buffer. If it doesn't verify, we look for the next potential - frame */ - - while(1){ - long ret=ogg_sync_pageseek(oy,og); - if(ret>0){ - /* have a page */ - return 1; - } - if(ret==0){ - /* need more data */ - return 0; - } - - /* head did not start a synced page... skipped some bytes */ - if(!oy->unsynced){ - oy->unsynced=1; - return OGG_HOLE; - } - - /* loop. keep looking */ - - } -} - -/* clear things to an initial state. Good to call, eg, before seeking */ -int ogg_sync_reset(ogg_sync_state *oy){ - - ogg_buffer_release(oy->fifo_tail); - oy->fifo_tail=0; - oy->fifo_head=0; - oy->fifo_fill=0; - - oy->unsynced=0; - oy->headerbytes=0; - oy->bodybytes=0; - return OGG_SUCCESS; -} - -ogg_stream_state *ogg_stream_create(int serialno){ - ogg_stream_state *os=_ogg_calloc(1,sizeof(*os)); - os->serialno=serialno; - os->pageno=-1; - return os; -} - -int ogg_stream_destroy(ogg_stream_state *os){ - if(os){ - ogg_buffer_release(os->header_tail); - ogg_buffer_release(os->body_tail); - memset(os,0,sizeof(*os)); - _ogg_free(os); - } - return OGG_SUCCESS; -} - - -#define FINFLAG 0x80000000UL -#define FINMASK 0x7fffffffUL - -static void _next_lace(oggbyte_buffer *ob,ogg_stream_state *os){ - /* search ahead one lace */ - os->body_fill_next=0; - while(os->laceptrlacing_fill){ - int val=oggbyte_read1(ob,27+os->laceptr++); - os->body_fill_next+=val; - if(val<255){ - os->body_fill_next|=FINFLAG; - os->clearflag=1; - break; - } - } -} - -static void _span_queued_page(ogg_stream_state *os){ - while( !(os->body_fill&FINFLAG) ){ - - if(!os->header_tail)break; - - /* first flush out preceeding page header (if any). Body is - flushed as it's consumed, so that's not done here. */ - - if(os->lacing_fill>=0) - os->header_tail=ogg_buffer_pretruncate(os->header_tail, - os->lacing_fill+27); - os->lacing_fill=0; - os->laceptr=0; - os->clearflag=0; - - if(!os->header_tail){ - os->header_head=0; - break; - }else{ - - /* process/prepare next page, if any */ - - long pageno; - oggbyte_buffer ob; - ogg_page og; /* only for parsing header values */ - og.header=os->header_tail; /* only for parsing header values */ - pageno=ogg_page_pageno(&og); - - oggbyte_init(&ob,os->header_tail); - os->lacing_fill=oggbyte_read1(&ob,26); - - /* are we in sequence? */ - if(pageno!=os->pageno){ - if(os->pageno==-1) /* indicates seek or reset */ - os->holeflag=1; /* set for internal use */ - else - os->holeflag=2; /* set for external reporting */ - - os->body_tail=ogg_buffer_pretruncate(os->body_tail, - os->body_fill); - if(os->body_tail==0)os->body_head=0; - os->body_fill=0; - - } - - if(ogg_page_continued(&og)){ - if(os->body_fill==0){ - /* continued packet, but no preceeding data to continue */ - /* dump the first partial packet on the page */ - _next_lace(&ob,os); - os->body_tail= - ogg_buffer_pretruncate(os->body_tail,os->body_fill_next&FINMASK); - if(os->body_tail==0)os->body_head=0; - /* set span flag */ - if(!os->spanflag && !os->holeflag)os->spanflag=2; - } - }else{ - if(os->body_fill>0){ - /* preceeding data to continue, but not a continued page */ - /* dump body_fill */ - os->body_tail=ogg_buffer_pretruncate(os->body_tail, - os->body_fill); - if(os->body_tail==0)os->body_head=0; - os->body_fill=0; - - /* set espan flag */ - if(!os->spanflag && !os->holeflag)os->spanflag=2; - } - } - - if(os->laceptrlacing_fill){ - os->granulepos=ogg_page_granulepos(&og); - - /* get current packet size & flag */ - _next_lace(&ob,os); - os->body_fill+=os->body_fill_next; /* addition handles the flag fine; - unsigned on purpose */ - /* ...and next packet size & flag */ - _next_lace(&ob,os); - - } - - os->pageno=pageno+1; - os->e_o_s=ogg_page_eos(&og); - os->b_o_s=ogg_page_bos(&og); - - } - } -} - -/* add the incoming page to the stream state; we decompose the page - into packet segments here as well. */ - -int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){ - - int serialno=ogg_page_serialno(og); - int version=ogg_page_version(og); - - /* check the serial number */ - if(serialno!=os->serialno){ - ogg_page_release(og); - return OGG_ESERIAL; - } - if(version>0){ - ogg_page_release(og); - return OGG_EVERSION; - } - - /* add to fifos */ - if(!os->body_tail){ - os->body_tail=og->body; - os->body_head=ogg_buffer_walk(og->body); - }else{ - os->body_head=ogg_buffer_cat(os->body_head,og->body); - } - if(!os->header_tail){ - os->header_tail=og->header; - os->header_head=ogg_buffer_walk(og->header); - os->lacing_fill=-27; - }else{ - os->header_head=ogg_buffer_cat(os->header_head,og->header); - } - - memset(og,0,sizeof(*og)); - return OGG_SUCCESS; -} - -int ogg_stream_reset(ogg_stream_state *os){ - - ogg_buffer_release(os->header_tail); - ogg_buffer_release(os->body_tail); - os->header_tail=os->header_head=0; - os->body_tail=os->body_head=0; - - os->e_o_s=0; - os->b_o_s=0; - os->pageno=-1; - os->packetno=0; - os->granulepos=0; - - os->body_fill=0; - os->lacing_fill=0; - - os->holeflag=0; - os->spanflag=0; - os->clearflag=0; - os->laceptr=0; - os->body_fill_next=0; - - return OGG_SUCCESS; -} - -int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){ - ogg_stream_reset(os); - os->serialno=serialno; - return OGG_SUCCESS; -} - -static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){ - - ogg_packet_release(op); - _span_queued_page(os); - - if(os->holeflag){ - int temp=os->holeflag; - if(os->clearflag) - os->holeflag=0; - else - os->holeflag=1; - if(temp==2){ - os->packetno++; - return OGG_HOLE; - } - } - if(os->spanflag){ - int temp=os->spanflag; - if(os->clearflag) - os->spanflag=0; - else - os->spanflag=1; - if(temp==2){ - os->packetno++; - return OGG_SPAN; - } - } - - if(!(os->body_fill&FINFLAG)) return 0; - if(!op && !adv)return 1; /* just using peek as an inexpensive way - to ask if there's a whole packet - waiting */ - if(op){ - op->b_o_s=os->b_o_s; - if(os->e_o_s && os->body_fill_next==0) - op->e_o_s=os->e_o_s; - else - op->e_o_s=0; - if( (os->body_fill&FINFLAG) && !(os->body_fill_next&FINFLAG) ) - op->granulepos=os->granulepos; - else - op->granulepos=-1; - op->packetno=os->packetno; - } - - if(adv){ - oggbyte_buffer ob; - oggbyte_init(&ob,os->header_tail); - - /* split the body contents off */ - if(op){ - op->packet=ogg_buffer_split(&os->body_tail,&os->body_head, - os->body_fill&FINMASK); - op->bytes=os->body_fill&FINMASK; - }else{ - os->body_tail=ogg_buffer_pretruncate(os->body_tail, - os->body_fill&FINMASK); - if(os->body_tail==0)os->body_head=0; - } - - /* update lacing pointers */ - os->body_fill=os->body_fill_next; - _next_lace(&ob,os); - }else{ - if(op){ - op->packet=ogg_buffer_sub(os->body_tail,0,os->body_fill&FINMASK); - op->bytes=os->body_fill&FINMASK; - } - } - - if(adv){ - os->packetno++; - os->b_o_s=0; - } - - return 1; -} - -int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){ - return _packetout(os,op,1); -} - -int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){ - return _packetout(os,op,0); -} - -int ogg_packet_release(ogg_packet *op) { - if(op){ - ogg_buffer_release(op->packet); - memset(op, 0, sizeof(*op)); - } - return OGG_SUCCESS; -} - -int ogg_page_release(ogg_page *og) { - if(og){ - ogg_buffer_release(og->header); - ogg_buffer_release(og->body); - memset(og, 0, sizeof(*og)); - } - return OGG_SUCCESS; -} - -void ogg_page_dup(ogg_page *dup,ogg_page *orig){ - dup->header_len=orig->header_len; - dup->body_len=orig->body_len; - dup->header=ogg_buffer_dup(orig->header); - dup->body=ogg_buffer_dup(orig->body); -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/info.c --- a/misc/libtremor/info.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,356 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: maintain the info structure, info <-> header packets - - ********************************************************************/ - -/* general handling of the header and the vorbis_info structure (and - substructures) */ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "codebook.h" -#include "registry.h" -#include "window.h" -#include "misc.h" - -/* helpers */ -static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){ - while(bytes--){ - *buf++=oggpack_read(o,8); - } -} - -void vorbis_comment_init(vorbis_comment *vc){ - memset(vc,0,sizeof(*vc)); -} - -/* This is more or less the same as strncasecmp - but that doesn't exist - * everywhere, and this is a fairly trivial function, so we include it */ -static int tagcompare(const char *s1, const char *s2, int n){ - int c=0; - while(c < n){ - if(toupper(s1[c]) != toupper(s2[c])) - return !0; - c++; - } - return 0; -} - -char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ - long i; - int found = 0; - int taglen = strlen(tag)+1; /* +1 for the = we append */ - char *fulltag = (char *)alloca(taglen+ 1); - - strcpy(fulltag, tag); - strcat(fulltag, "="); - - for(i=0;icomments;i++){ - if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ - if(count == found) - /* We return a pointer to the data, not a copy */ - return vc->user_comments[i] + taglen; - else - found++; - } - } - return NULL; /* didn't find anything */ -} - -int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ - int i,count=0; - int taglen = strlen(tag)+1; /* +1 for the = we append */ - char *fulltag = (char *)alloca(taglen+1); - strcpy(fulltag,tag); - strcat(fulltag, "="); - - for(i=0;icomments;i++){ - if(!tagcompare(vc->user_comments[i], fulltag, taglen)) - count++; - } - - return count; -} - -void vorbis_comment_clear(vorbis_comment *vc){ - if(vc){ - long i; - for(i=0;icomments;i++) - if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); - if(vc->user_comments)_ogg_free(vc->user_comments); - if(vc->comment_lengths)_ogg_free(vc->comment_lengths); - if(vc->vendor)_ogg_free(vc->vendor); - memset(vc,0,sizeof(*vc)); - } -} - -/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long. - They may be equal, but short will never ge greater than long */ -int vorbis_info_blocksize(vorbis_info *vi,int zo){ - codec_setup_info *ci = (codec_setup_info *)vi->codec_setup; - return ci ? ci->blocksizes[zo] : -1; -} - -/* used by synthesis, which has a full, alloced vi */ -void vorbis_info_init(vorbis_info *vi){ - memset(vi,0,sizeof(*vi)); - vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); -} - -void vorbis_info_clear(vorbis_info *vi){ - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - int i; - - if(ci){ - - for(i=0;imodes;i++) - if(ci->mode_param[i])_ogg_free(ci->mode_param[i]); - - for(i=0;imaps;i++) /* unpack does the range checking */ - if(ci->map_param[i]) - _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); - - for(i=0;ifloors;i++) /* unpack does the range checking */ - if(ci->floor_param[i]) - _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); - - for(i=0;iresidues;i++) /* unpack does the range checking */ - if(ci->residue_param[i]) - _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); - - for(i=0;ibooks;i++){ - if(ci->book_param[i]){ - /* knows if the book was not alloced */ - vorbis_staticbook_destroy(ci->book_param[i]); - } - if(ci->fullbooks) - vorbis_book_clear(ci->fullbooks+i); - } - if(ci->fullbooks) - _ogg_free(ci->fullbooks); - - _ogg_free(ci); - } - - memset(vi,0,sizeof(*vi)); -} - -/* Header packing/unpacking ********************************************/ - -static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - if(!ci)return(OV_EFAULT); - - vi->version=oggpack_read(opb,32); - if(vi->version!=0)return(OV_EVERSION); - - vi->channels=oggpack_read(opb,8); - vi->rate=oggpack_read(opb,32); - - vi->bitrate_upper=oggpack_read(opb,32); - vi->bitrate_nominal=oggpack_read(opb,32); - vi->bitrate_lower=oggpack_read(opb,32); - - ci->blocksizes[0]=1<blocksizes[1]=1<rate<1)goto err_out; - if(vi->channels<1)goto err_out; - if(ci->blocksizes[0]<64)goto err_out; - if(ci->blocksizes[1]blocksizes[0])goto err_out; - if(ci->blocksizes[1]>8192)goto err_out; - - if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ - - return(0); - err_out: - vorbis_info_clear(vi); - return(OV_EBADHEADER); -} - -static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ - int i; - int vendorlen=oggpack_read(opb,32); - if(vendorlen<0)goto err_out; - vc->vendor=(char *)_ogg_calloc(vendorlen+1,1); - _v_readstring(opb,vc->vendor,vendorlen); - vc->comments=oggpack_read(opb,32); - if(vc->comments<0)goto err_out; - vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); - vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); - - for(i=0;icomments;i++){ - int len=oggpack_read(opb,32); - if(len<0)goto err_out; - vc->comment_lengths[i]=len; - vc->user_comments[i]=(char *)_ogg_calloc(len+1,1); - _v_readstring(opb,vc->user_comments[i],len); - } - if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ - - return(0); - err_out: - vorbis_comment_clear(vc); - return(OV_EBADHEADER); -} - -/* all of the real encoding details are here. The modes, books, - everything */ -static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - int i; - if(!ci)return(OV_EFAULT); - - /* codebooks */ - ci->books=oggpack_read(opb,8)+1; - /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/ - for(i=0;ibooks;i++){ - ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i])); - if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out; - } - - /* time backend settings */ - ci->times=oggpack_read(opb,6)+1; - /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/ - /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/ - for(i=0;itimes;i++){ - ci->time_type[i]=oggpack_read(opb,16); - if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out; - /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb); - Vorbis I has no time backend */ - /*if(!ci->time_param[i])goto err_out;*/ - } - - /* floor backend settings */ - ci->floors=oggpack_read(opb,6)+1; - /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/ - /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/ - for(i=0;ifloors;i++){ - ci->floor_type[i]=oggpack_read(opb,16); - if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out; - ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb); - if(!ci->floor_param[i])goto err_out; - } - - /* residue backend settings */ - ci->residues=oggpack_read(opb,6)+1; - /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/ - /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/ - for(i=0;iresidues;i++){ - ci->residue_type[i]=oggpack_read(opb,16); - if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out; - ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb); - if(!ci->residue_param[i])goto err_out; - } - - /* map backend settings */ - ci->maps=oggpack_read(opb,6)+1; - /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/ - /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/ - for(i=0;imaps;i++){ - ci->map_type[i]=oggpack_read(opb,16); - if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out; - ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb); - if(!ci->map_param[i])goto err_out; - } - - /* mode settings */ - ci->modes=oggpack_read(opb,6)+1; - /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/ - for(i=0;imodes;i++){ - ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i])); - ci->mode_param[i]->blockflag=oggpack_read(opb,1); - ci->mode_param[i]->windowtype=oggpack_read(opb,16); - ci->mode_param[i]->transformtype=oggpack_read(opb,16); - ci->mode_param[i]->mapping=oggpack_read(opb,8); - - if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out; - if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out; - if(ci->mode_param[i]->mapping>=ci->maps)goto err_out; - } - - if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */ - - return(0); - err_out: - vorbis_info_clear(vi); - return(OV_EBADHEADER); -} - -/* The Vorbis header is in three packets; the initial small packet in - the first page that identifies basic parameters, a second packet - with bitstream comments and a third packet that holds the - codebook. */ - -int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){ - oggpack_buffer opb; - - if(op){ - oggpack_readinit(&opb,op->packet); - - /* Which of the three types of header is this? */ - /* Also verify header-ness, vorbis */ - { - char buffer[6]; - int packtype=oggpack_read(&opb,8); - memset(buffer,0,6); - _v_readstring(&opb,buffer,6); - if(memcmp(buffer,"vorbis",6)){ - /* not a vorbis header */ - return(OV_ENOTVORBIS); - } - switch(packtype){ - case 0x01: /* least significant *bit* is read first */ - if(!op->b_o_s){ - /* Not the initial packet */ - return(OV_EBADHEADER); - } - if(vi->rate!=0){ - /* previously initialized info header */ - return(OV_EBADHEADER); - } - - return(_vorbis_unpack_info(vi,&opb)); - - case 0x03: /* least significant *bit* is read first */ - if(vi->rate==0){ - /* um... we didn't get the initial header */ - return(OV_EBADHEADER); - } - - return(_vorbis_unpack_comment(vc,&opb)); - - case 0x05: /* least significant *bit* is read first */ - if(vi->rate==0 || vc->vendor==NULL){ - /* um... we didn;t get the initial header or comments yet */ - return(OV_EBADHEADER); - } - - return(_vorbis_unpack_books(vi,&opb)); - - default: - /* Not a valid vorbis header type */ - return(OV_EBADHEADER); - break; - } - } - } - return(OV_EBADHEADER); -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/ivorbiscodec.h --- a/misc/libtremor/ivorbiscodec.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: libvorbis codec headers - - ********************************************************************/ - -#ifndef _vorbis_codec_h_ -#define _vorbis_codec_h_ - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#include "ogg.h" - -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; - -/* vorbis_dsp_state buffers the current vorbis audio - analysis/synthesis state. The DSP state belongs to a specific - logical bitstream ****************************************************/ -typedef struct vorbis_dsp_state{ - int analysisp; - vorbis_info *vi; - - ogg_int32_t **pcm; - ogg_int32_t **pcmret; - int pcm_storage; - int pcm_current; - int pcm_returned; - - int preextrapolate; - int eofflag; - - long lW; - long W; - long nW; - long centerW; - - ogg_int64_t granulepos; - ogg_int64_t sequence; - - void *backend_state; -} vorbis_dsp_state; - -typedef struct vorbis_block{ - /* necessary stream state for linking to the framing abstraction */ - ogg_int32_t **pcm; /* this is a pointer into local storage */ - oggpack_buffer opb; - - long lW; - long W; - long nW; - int pcmend; - int mode; - - int eofflag; - ogg_int64_t granulepos; - ogg_int64_t sequence; - vorbis_dsp_state *vd; /* For read-only access of configuration */ - - /* local storage to avoid remallocing; it's up to the mapping to - structure it */ - void *localstore; - long localtop; - long localalloc; - long totaluse; - struct alloc_chain *reap; - -} vorbis_block; - -/* vorbis_block is a single block of data to be processed as part of -the analysis/synthesis stream; it belongs to a specific logical -bitstream, but is independant from other vorbis_blocks belonging to -that logical bitstream. *************************************************/ - -struct alloc_chain{ - void *ptr; - struct alloc_chain *next; -}; - -/* vorbis_info contains all the setup information specific to the - specific compression/decompression mode in progress (eg, - psychoacoustic settings, channel setup, options, codebook - etc). vorbis_info and substructures are in backends.h. -*********************************************************************/ - -/* the comments are not part of vorbis_info so that vorbis_info can be - static storage */ -typedef struct vorbis_comment{ - /* unlimited user comment fields. libvorbis writes 'libvorbis' - whatever vendor is set to in encode */ - char **user_comments; - int *comment_lengths; - int comments; - char *vendor; - -} vorbis_comment; - - -/* libvorbis encodes in two abstraction layers; first we perform DSP - and produce a packet (see docs/analysis.txt). The packet is then - coded into a framed OggSquish bitstream by the second layer (see - docs/framing.txt). Decode is the reverse process; we sync/frame - the bitstream and extract individual packets, then decode the - packet back into PCM audio. - - The extra framing/packetizing is used in streaming formats, such as - files. Over the net (such as with UDP), the framing and - packetization aren't necessary as they're provided by the transport - and the streaming layer is not used */ - -/* 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); - -extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); -extern int vorbis_block_clear(vorbis_block *vb); -extern void vorbis_dsp_clear(vorbis_dsp_state *v); - -/* Vorbis PRIMITIVES: synthesis layer *******************************/ -extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, - ogg_packet *op); - -extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); -extern int vorbis_synthesis_restart(vorbis_dsp_state *v); -extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep); -extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); -extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm); -extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples); -extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); - -/* 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 - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/ivorbisfile.h --- a/misc/libtremor/ivorbisfile.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: stdio-based convenience library for opening/seeking/decoding - - ********************************************************************/ - -#ifndef _OV_FILE_H_ -#define _OV_FILE_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#include -#include "ivorbiscodec.h" - -#define CHUNKSIZE 1024 -/* 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; - -#define NOTOPEN 0 -#define PARTOPEN 1 -#define OPENED 2 -#define STREAMSET 3 -#define INITSET 4 - -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 */ - vorbis_block vb; /* local working space for packet->PCM decode */ - - 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,char *buffer,int length, - int *bitstream); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/ivorbisfile_example.c --- a/misc/libtremor/ivorbisfile_example.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: simple example decoder using vorbisidec - - ********************************************************************/ - -/* Takes a vorbis bitstream from stdin and writes raw stereo PCM to - stdout using vorbisfile. Using vorbisfile is much simpler than - dealing with libvorbis. */ - -#include -#include -#include -#include - -#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ -#include -#include -#endif - -char pcmout[4096]; /* take 4k out of the data segment, not the stack */ - -int main(){ - OggVorbis_File vf; - int eof=0; - int current_section; - -#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */ - /* Beware the evil ifdef. We avoid these where we can, but this one we - cannot. Don't add any more, you'll probably go to hell if you do. */ - _setmode( _fileno( stdin ), _O_BINARY ); - _setmode( _fileno( stdout ), _O_BINARY ); -#endif - - if(ov_open(stdin, &vf, NULL, 0) < 0) { - fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); - exit(1); - } - - /* Throw the comments plus a few lines about the bitstream we're - decoding */ - { - char **ptr=ov_comment(&vf,-1)->user_comments; - vorbis_info *vi=ov_info(&vf,-1); - while(*ptr){ - fprintf(stderr,"%s\n",*ptr); - ++ptr; - } - fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); - fprintf(stderr,"\nDecoded length: %ld samples\n", - (long)ov_pcm_total(&vf,-1)); - fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); - } - - while(!eof){ - long ret=ov_read(&vf,pcmout,sizeof(pcmout),¤t_section); - if (ret == 0) { - /* EOF */ - eof=1; - } else if (ret < 0) { - /* error in the stream. Not a problem, just reporting it in - case we (the app) cares. In this case, we don't. */ - } else { - /* we don't bother dealing with sample rate changes, etc, but - you'll have to*/ - fwrite(pcmout,1,ret,stdout); - } - } - - /* cleanup */ - ov_clear(&vf); - - fprintf(stderr,"Done.\n"); - return(0); -} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/lsp_lookup.h --- a/misc/libtremor/lsp_lookup.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: lookup data - - ********************************************************************/ - -#ifndef _V_LOOKUP_DATA_H_ -#define _V_LOOKUP_DATA_H_ - -#include "os_types.h" - -#define FROMdB_LOOKUP_SZ 35 -#define FROMdB2_LOOKUP_SZ 32 -#define FROMdB_SHIFT 5 -#define FROMdB2_SHIFT 3 -#define FROMdB2_MASK 31 - -static const ogg_int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ - 0x003fffff, 0x0028619b, 0x00197a96, 0x0010137a, - 0x000a24b0, 0x00066666, 0x000409c3, 0x00028c42, - 0x00019b8c, 0x000103ab, 0x0000a3d7, 0x00006760, - 0x0000413a, 0x00002928, 0x000019f8, 0x00001062, - 0x00000a56, 0x00000686, 0x0000041e, 0x00000299, - 0x000001a3, 0x00000109, 0x000000a7, 0x00000069, - 0x00000042, 0x0000002a, 0x0000001a, 0x00000011, - 0x0000000b, 0x00000007, 0x00000004, 0x00000003, - 0x00000002, 0x00000001, 0x00000001}; - -static const ogg_int32_t FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ - 0x000001fc, 0x000001f5, 0x000001ee, 0x000001e7, - 0x000001e0, 0x000001d9, 0x000001d2, 0x000001cc, - 0x000001c5, 0x000001bf, 0x000001b8, 0x000001b2, - 0x000001ac, 0x000001a6, 0x000001a0, 0x0000019a, - 0x00000194, 0x0000018e, 0x00000188, 0x00000183, - 0x0000017d, 0x00000178, 0x00000172, 0x0000016d, - 0x00000168, 0x00000163, 0x0000015e, 0x00000159, - 0x00000154, 0x0000014f, 0x0000014a, 0x00000145, -}; - -#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 - - - - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/mapping0.c --- a/misc/libtremor/mapping0.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,322 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: channel mapping 0 implementation - - ********************************************************************/ - -#include -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "mdct.h" -#include "codec_internal.h" -#include "codebook.h" -#include "window.h" -#include "registry.h" -#include "misc.h" - -/* simplistic, wasteful way of doing this (unique lookup for each - mode/submapping); there should be a central repository for - identical lookups. That will require minor work, so I'm putting it - off as low priority. - - Why a lookup for each backend in a given mode? Because the - blocksize is set by the mode, and low backend lookups may require - parameters from other areas of the mode/mapping */ - -typedef struct { - vorbis_info_mode *mode; - vorbis_info_mapping0 *map; - - vorbis_look_floor **floor_look; - - vorbis_look_residue **residue_look; - - vorbis_func_floor **floor_func; - vorbis_func_residue **residue_func; - - int ch; - long lastframe; /* if a different mode is called, we need to - invalidate decay */ -} vorbis_look_mapping0; - -static void mapping0_free_info(vorbis_info_mapping *i){ - vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i; - if(info){ - memset(info,0,sizeof(*info)); - _ogg_free(info); - } -} - -static void mapping0_free_look(vorbis_look_mapping *look){ - int i; - vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look; - if(l){ - - for(i=0;imap->submaps;i++){ - l->floor_func[i]->free_look(l->floor_look[i]); - l->residue_func[i]->free_look(l->residue_look[i]); - } - - _ogg_free(l->floor_func); - _ogg_free(l->residue_func); - _ogg_free(l->floor_look); - _ogg_free(l->residue_look); - memset(l,0,sizeof(*l)); - _ogg_free(l); - } -} - -static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, - vorbis_info_mapping *m){ - int i; - vorbis_info *vi=vd->vi; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look)); - vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m; - look->mode=vm; - - look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look)); - - look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look)); - - look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func)); - look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func)); - - for(i=0;isubmaps;i++){ - int floornum=info->floorsubmap[i]; - int resnum=info->residuesubmap[i]; - - look->floor_func[i]=_floor_P[ci->floor_type[floornum]]; - look->floor_look[i]=look->floor_func[i]-> - look(vd,vm,ci->floor_param[floornum]); - look->residue_func[i]=_residue_P[ci->residue_type[resnum]]; - look->residue_look[i]=look->residue_func[i]-> - look(vd,vm,ci->residue_param[resnum]); - - } - - look->ch=vi->channels; - - return(look); -} - -static int ilog(unsigned int v){ - int ret=0; - if(v)--v; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -/* also responsible for range checking */ -static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){ - int i; - vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info)); - 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; - - for(i=0;icoupling_steps;i++){ - int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels)); - int testA=info->coupling_ang[i]=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){ - for(i=0;ichannels;i++){ - info->chmuxlist[i]=oggpack_read(opb,4); - if(info->chmuxlist[i]>=info->submaps)goto err_out; - } - } - for(i=0;isubmaps;i++){ - int temp=oggpack_read(opb,8); - if(temp>=ci->times)goto err_out; - info->floorsubmap[i]=oggpack_read(opb,8); - if(info->floorsubmap[i]>=ci->floors)goto err_out; - info->residuesubmap[i]=oggpack_read(opb,8); - if(info->residuesubmap[i]>=ci->residues)goto err_out; - } - - return info; - - err_out: - mapping0_free_info(info); - return(NULL); -} - -static int seq=0; -static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ - vorbis_dsp_state *vd=vb->vd; - vorbis_info *vi=vd->vi; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - private_state *b=(private_state *)vd->backend_state; - vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l; - vorbis_info_mapping0 *info=look->map; - - int i,j; - long n=vb->pcmend=ci->blocksizes[vb->W]; - - ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); - int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels); - - int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels); - void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels); - - /* time domain information decode (note that applying the - information would have to happen later; we'll probably add a - function entry to the harness for that later */ - /* NOT IMPLEMENTED */ - - /* recover the spectral envelope; store it in the PCM vector for now */ - for(i=0;ichannels;i++){ - int submap=info->chmuxlist[i]; - floormemo[i]=look->floor_func[submap]-> - inverse1(vb,look->floor_look[submap]); - if(floormemo[i]) - nonzero[i]=1; - else - nonzero[i]=0; - memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2); - } - - /* channel coupling can 'dirty' the nonzero listing */ - for(i=0;icoupling_steps;i++){ - if(nonzero[info->coupling_mag[i]] || - nonzero[info->coupling_ang[i]]){ - nonzero[info->coupling_mag[i]]=1; - nonzero[info->coupling_ang[i]]=1; - } - } - - /* recover the residue into our working vectors */ - for(i=0;isubmaps;i++){ - int ch_in_bundle=0; - for(j=0;jchannels;j++){ - if(info->chmuxlist[j]==i){ - if(nonzero[j]) - zerobundle[ch_in_bundle]=1; - else - zerobundle[ch_in_bundle]=0; - pcmbundle[ch_in_bundle++]=vb->pcm[j]; - } - } - - look->residue_func[i]->inverse(vb,look->residue_look[i], - pcmbundle,zerobundle,ch_in_bundle); - } - - //for(j=0;jchannels;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=vb->pcm[info->coupling_mag[i]]; - ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]]; - - for(j=0;j0) - 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;jchannels;j++) - //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0); - - /* compute and apply spectral envelope */ - for(i=0;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; - int submap=info->chmuxlist[i]; - look->floor_func[submap]-> - inverse2(vb,look->floor_look[submap],floormemo[i],pcm); - } - - //for(j=0;jchannels;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;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; - mdct_backward(n,pcm,pcm); - } - - //for(j=0;jchannels;j++) - //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0); - - /* window the data */ - for(i=0;ichannels;i++){ - ogg_int32_t *pcm=vb->pcm[i]; - if(nonzero[i]) - _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); - else - for(j=0;jchannels;j++) - //_analysis_output("window",seq+j,vb->pcm[j],-24,n,0,0); - - seq+=vi->channels; - /* all done! */ - return(0); -} - -/* export hooks */ -vorbis_func_mapping mapping0_exportbundle={ - &mapping0_unpack, - &mapping0_look, - &mapping0_free_info, - &mapping0_free_look, - &mapping0_inverse -}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/mdct.c --- a/misc/libtremor/mdct.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,510 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: normalized modified discrete cosine transform - power of two length transform only [64 <= n ] - last mod: $Id: mdct.c,v 1.9 2002/10/16 09:17:39 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 "codebook.h" -#include "misc.h" -#include "mdct.h" -#include "mdct_lookup.h" - - -/* 8 point butterfly (in place) */ -STIN void mdct_butterfly_8(DATA_TYPE *x){ - - REG_TYPE r0 = x[4] + x[0]; - REG_TYPE r1 = x[4] - x[0]; - REG_TYPE r2 = x[5] + x[1]; - REG_TYPE r3 = x[5] - x[1]; - REG_TYPE r4 = x[6] + x[2]; - REG_TYPE r5 = x[6] - x[2]; - REG_TYPE r6 = x[7] + x[3]; - REG_TYPE r7 = x[7] - x[3]; - - x[0] = r5 + r3; - x[1] = r7 - r1; - x[2] = r5 - r3; - x[3] = r7 + r1; - x[4] = r4 - r0; - x[5] = r6 - r2; - x[6] = r4 + r0; - x[7] = r6 + r2; - MB(); -} - -/* 16 point butterfly (in place, 4 register) */ -STIN void mdct_butterfly_16(DATA_TYPE *x){ - - REG_TYPE r0, r1; - - r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; - r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; - x[ 0] = MULT31((r0 + r1) , cPI2_8); - x[ 1] = MULT31((r1 - r0) , cPI2_8); - MB(); - - r0 = x[10] - x[ 2]; x[10] += x[ 2]; - r1 = x[ 3] - x[11]; x[11] += x[ 3]; - x[ 2] = r1; x[ 3] = r0; - MB(); - - r0 = x[12] - x[ 4]; x[12] += x[ 4]; - r1 = x[13] - x[ 5]; x[13] += x[ 5]; - x[ 4] = MULT31((r0 - r1) , cPI2_8); - x[ 5] = MULT31((r0 + r1) , cPI2_8); - MB(); - - r0 = x[14] - x[ 6]; x[14] += x[ 6]; - r1 = x[15] - x[ 7]; x[15] += x[ 7]; - x[ 6] = r0; x[ 7] = r1; - 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 r0, r1; - - r0 = x[30] - x[14]; x[30] += x[14]; - r1 = x[31] - x[15]; x[31] += x[15]; - x[14] = r0; x[15] = r1; - MB(); - - r0 = x[28] - x[12]; x[28] += x[12]; - r1 = x[29] - x[13]; x[29] += x[13]; - XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); - MB(); - - r0 = x[26] - x[10]; x[26] += x[10]; - r1 = x[27] - x[11]; x[27] += x[11]; - x[10] = MULT31((r0 - r1) , cPI2_8); - x[11] = MULT31((r0 + r1) , cPI2_8); - MB(); - - r0 = x[24] - x[ 8]; x[24] += x[ 8]; - r1 = x[25] - x[ 9]; x[25] += x[ 9]; - XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); - MB(); - - r0 = x[22] - x[ 6]; x[22] += x[ 6]; - r1 = x[ 7] - x[23]; x[23] += x[ 7]; - x[ 6] = r1; x[ 7] = r0; - MB(); - - r0 = x[ 4] - x[20]; x[20] += x[ 4]; - r1 = x[ 5] - x[21]; x[21] += x[ 5]; - XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); - MB(); - - r0 = x[ 2] - x[18]; x[18] += x[ 2]; - r1 = x[ 3] - x[19]; x[19] += x[ 3]; - x[ 2] = MULT31((r1 + r0) , cPI2_8); - x[ 3] = MULT31((r1 - r0) , cPI2_8); - MB(); - - r0 = x[ 0] - x[16]; x[16] += x[ 0]; - r1 = x[ 1] - x[17]; x[17] += x[ 1]; - XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); - 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 - 8; - DATA_TYPE *x2 = x + (points>>1) - 8; - REG_TYPE r0; - REG_TYPE r1; - - do{ - r0 = x1[6] - x2[6]; x1[6] += x2[6]; - r1 = x2[7] - x1[7]; x1[7] += x2[7]; - XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step; - - r0 = x1[4] - x2[4]; x1[4] += x2[4]; - r1 = x2[5] - x1[5]; x1[5] += x2[5]; - XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step; - - r0 = x1[2] - x2[2]; x1[2] += x2[2]; - r1 = x2[3] - x1[3]; x1[3] += x2[3]; - XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step; - - r0 = x1[0] - x2[0]; x1[0] += x2[0]; - r1 = x2[1] - x1[1]; x1[1] += x2[1]; - XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step; - - x1-=8; x2-=8; - }while(Tsincos_lookup0); - do{ - r0 = x2[6] - x1[6]; x1[6] += x2[6]; - r1 = x2[7] - x1[7]; x1[7] += x2[7]; - XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step; - - r0 = x2[4] - x1[4]; x1[4] += x2[4]; - r1 = x2[5] - x1[5]; x1[5] += x2[5]; - XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step; - - r0 = x2[2] - x1[2]; x1[2] += x2[2]; - r1 = x2[3] - x1[3]; x1[3] += x2[3]; - XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step; - - r0 = x2[0] - x1[0]; x1[0] += x2[0]; - r1 = x2[1] - x1[1]; x1[1] += x2[1]; - XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step; - - x1-=8; x2-=8; - }while(Tsincos_lookup0); -} - -STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ - - int stages=8-shift; - int i,j; - - for(i=0;--stages>0;i++){ - for(j=0;j<(1<>i)*j,points>>i,4<<(i+shift)); - } - - for(j=0;j>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8); -} - -STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ - - int bit = 0; - DATA_TYPE *w0 = x; - DATA_TYPE *w1 = x = w0+(n>>1); - LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; - LOOKUP_T *Ttop = T+1024; - DATA_TYPE r2; - - do{ - DATA_TYPE r3 = bitrev12(bit++); - DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1; - DATA_TYPE *x1 = x + (r3>>shift); - - REG_TYPE r0 = x0[0] + x1[0]; - REG_TYPE r1 = x1[1] - x0[1]; - - XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; - - w1 -= 4; - - r0 = (x0[1] + x1[1])>>1; - r1 = (x0[0] - x1[0])>>1; - w0[0] = r0 + r2; - w0[1] = r1 + r3; - w1[2] = r0 - r2; - w1[3] = r3 - r1; - - r3 = bitrev12(bit++); - x0 = x + ((r3 ^ 0xfff)>>shift) -1; - x1 = x + (r3>>shift); - - r0 = x0[0] + x1[0]; - r1 = x1[1] - x0[1]; - - XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; - - r0 = (x0[1] + x1[1])>>1; - r1 = (x0[0] - x1[0])>>1; - w0[2] = r0 + r2; - w0[3] = r1 + r3; - w1[0] = r0 - r2; - w1[1] = r3 - r1; - - w0 += 4; - }while(T>shift) -1; - DATA_TYPE *x1 = x + (r3>>shift); - - REG_TYPE r0 = x0[0] + x1[0]; - REG_TYPE r1 = x1[1] - x0[1]; - - T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); - - w1 -= 4; - - r0 = (x0[1] + x1[1])>>1; - r1 = (x0[0] - x1[0])>>1; - w0[0] = r0 + r2; - w0[1] = r1 + r3; - w1[2] = r0 - r2; - w1[3] = r3 - r1; - - r3 = bitrev12(bit++); - x0 = x + ((r3 ^ 0xfff)>>shift) -1; - x1 = x + (r3>>shift); - - r0 = x0[0] + x1[0]; - r1 = x1[1] - x0[1]; - - T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); - - r0 = (x0[1] + x1[1])>>1; - r1 = (x0[0] - x1[0])>>1; - w0[2] = r0 + r2; - w0[3] = r1 + r3; - w1[0] = r0 - r2; - w1[1] = r3 - r1; - - w0 += 4; - }while(w0>1; - int n4=n>>2; - DATA_TYPE *iX; - DATA_TYPE *oX; - LOOKUP_T *T; - LOOKUP_T *V; - int shift; - int step; - - for (shift=6;!(n&(1<=in+n4); - do{ - oX-=4; - XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step; - XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step; - iX-=8; - }while(iX>=in); - - iX = in+n2-8; - oX = out+n2+n4; - T = sincos_lookup0; - - do{ - T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] ); - T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] ); - iX-=8; - oX+=4; - }while(iX>=in+n4); - do{ - T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] ); - T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] ); - iX-=8; - oX+=4; - }while(iX>=in); - - mdct_butterflies(out+n2,n2,shift); - mdct_bitreverse(out,n,step,shift); - - /* rotate + window */ - - step>>=2; - { - DATA_TYPE *oX1=out+n2+n4; - DATA_TYPE *oX2=out+n2+n4; - DATA_TYPE *iX =out; - - switch(step) { - default: { - T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; - do{ - oX1-=4; - XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step; - XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step; - XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step; - XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step; - oX2+=4; - iX+=8; - }while(iX>1; - t1 = (*T++)>>1; - do{ - oX1-=4; - - t0 += (v0 = (*V++)>>1); - t1 += (v1 = (*V++)>>1); - XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); - v0 += (t0 = (*T++)>>1); - v1 += (t1 = (*T++)>>1); - XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); - t0 += (v0 = (*V++)>>1); - t1 += (v1 = (*V++)>>1); - XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); - v0 += (t0 = (*T++)>>1); - v1 += (t1 = (*T++)>>1); - XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); - - oX2+=4; - iX+=8; - }while(iX>2); - t1 += (q1 = (v1-t1)>>2); - XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); - t0 = v0-q0; - t1 = v1-q1; - XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); - - t0 = *T++; - t1 = *T++; - v0 += (q0 = (t0-v0)>>2); - v1 += (q1 = (t1-v1)>>2); - XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); - v0 = t0-q0; - v1 = t1-q1; - XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); - - oX2+=4; - iX+=8; - }while(iXoX2); - } -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/mdct.h --- a/misc/libtremor/mdct.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: modified discrete cosine transform prototypes - - ********************************************************************/ - -#ifndef _OGG_mdct_H_ -#define _OGG_mdct_H_ - -#include "ivorbiscodec.h" -#include "misc.h" - -#define DATA_TYPE ogg_int32_t -#define REG_TYPE register ogg_int32_t - -#ifdef _LOW_ACCURACY_ -#define cPI3_8 (0x0062) -#define cPI2_8 (0x00b5) -#define cPI1_8 (0x00ed) -#else -#define cPI3_8 (0x30fbc54d) -#define cPI2_8 (0x5a82799a) -#define cPI1_8 (0x7641af3d) -#endif - -extern void mdct_forward(int n, DATA_TYPE *in, DATA_TYPE *out); -extern void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out); - -#endif - - - - - - - - - - - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/mdct_lookup.h --- a/misc/libtremor/mdct_lookup.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,540 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: sin,cos lookup tables - - ********************************************************************/ - -#include "os_types.h" - -/* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */ -static LOOKUP_T sincos_lookup0[1026] = { - X(0x00000000), X(0x7fffffff), X(0x003243f5), X(0x7ffff621), - X(0x006487e3), X(0x7fffd886), X(0x0096cbc1), X(0x7fffa72c), - X(0x00c90f88), X(0x7fff6216), X(0x00fb5330), X(0x7fff0943), - X(0x012d96b1), X(0x7ffe9cb2), X(0x015fda03), X(0x7ffe1c65), - X(0x01921d20), X(0x7ffd885a), X(0x01c45ffe), X(0x7ffce093), - X(0x01f6a297), X(0x7ffc250f), X(0x0228e4e2), X(0x7ffb55ce), - X(0x025b26d7), X(0x7ffa72d1), X(0x028d6870), X(0x7ff97c18), - X(0x02bfa9a4), X(0x7ff871a2), X(0x02f1ea6c), X(0x7ff75370), - X(0x03242abf), X(0x7ff62182), X(0x03566a96), X(0x7ff4dbd9), - X(0x0388a9ea), X(0x7ff38274), X(0x03bae8b2), X(0x7ff21553), - X(0x03ed26e6), X(0x7ff09478), X(0x041f6480), X(0x7feeffe1), - X(0x0451a177), X(0x7fed5791), X(0x0483ddc3), X(0x7feb9b85), - X(0x04b6195d), X(0x7fe9cbc0), X(0x04e8543e), X(0x7fe7e841), - X(0x051a8e5c), X(0x7fe5f108), X(0x054cc7b1), X(0x7fe3e616), - X(0x057f0035), X(0x7fe1c76b), X(0x05b137df), X(0x7fdf9508), - X(0x05e36ea9), X(0x7fdd4eec), X(0x0615a48b), X(0x7fdaf519), - X(0x0647d97c), X(0x7fd8878e), X(0x067a0d76), X(0x7fd6064c), - X(0x06ac406f), X(0x7fd37153), X(0x06de7262), X(0x7fd0c8a3), - X(0x0710a345), X(0x7fce0c3e), X(0x0742d311), X(0x7fcb3c23), - X(0x077501be), X(0x7fc85854), X(0x07a72f45), X(0x7fc560cf), - X(0x07d95b9e), X(0x7fc25596), X(0x080b86c2), X(0x7fbf36aa), - X(0x083db0a7), X(0x7fbc040a), X(0x086fd947), X(0x7fb8bdb8), - X(0x08a2009a), X(0x7fb563b3), X(0x08d42699), X(0x7fb1f5fc), - X(0x09064b3a), X(0x7fae7495), X(0x09386e78), X(0x7faadf7c), - X(0x096a9049), X(0x7fa736b4), X(0x099cb0a7), X(0x7fa37a3c), - X(0x09cecf89), X(0x7f9faa15), X(0x0a00ece8), X(0x7f9bc640), - X(0x0a3308bd), X(0x7f97cebd), X(0x0a6522fe), X(0x7f93c38c), - X(0x0a973ba5), X(0x7f8fa4b0), X(0x0ac952aa), X(0x7f8b7227), - X(0x0afb6805), X(0x7f872bf3), X(0x0b2d7baf), X(0x7f82d214), - X(0x0b5f8d9f), X(0x7f7e648c), X(0x0b919dcf), X(0x7f79e35a), - X(0x0bc3ac35), X(0x7f754e80), X(0x0bf5b8cb), X(0x7f70a5fe), - X(0x0c27c389), X(0x7f6be9d4), X(0x0c59cc68), X(0x7f671a05), - X(0x0c8bd35e), X(0x7f62368f), X(0x0cbdd865), X(0x7f5d3f75), - X(0x0cefdb76), X(0x7f5834b7), X(0x0d21dc87), X(0x7f531655), - X(0x0d53db92), X(0x7f4de451), X(0x0d85d88f), X(0x7f489eaa), - X(0x0db7d376), X(0x7f434563), X(0x0de9cc40), X(0x7f3dd87c), - X(0x0e1bc2e4), X(0x7f3857f6), X(0x0e4db75b), X(0x7f32c3d1), - X(0x0e7fa99e), X(0x7f2d1c0e), X(0x0eb199a4), X(0x7f2760af), - X(0x0ee38766), X(0x7f2191b4), X(0x0f1572dc), X(0x7f1baf1e), - X(0x0f475bff), X(0x7f15b8ee), X(0x0f7942c7), X(0x7f0faf25), - X(0x0fab272b), X(0x7f0991c4), X(0x0fdd0926), X(0x7f0360cb), - X(0x100ee8ad), X(0x7efd1c3c), X(0x1040c5bb), X(0x7ef6c418), - X(0x1072a048), X(0x7ef05860), X(0x10a4784b), X(0x7ee9d914), - X(0x10d64dbd), X(0x7ee34636), X(0x11082096), X(0x7edc9fc6), - X(0x1139f0cf), X(0x7ed5e5c6), X(0x116bbe60), X(0x7ecf1837), - X(0x119d8941), X(0x7ec8371a), X(0x11cf516a), X(0x7ec14270), - X(0x120116d5), X(0x7eba3a39), X(0x1232d979), X(0x7eb31e78), - X(0x1264994e), X(0x7eabef2c), X(0x1296564d), X(0x7ea4ac58), - X(0x12c8106f), X(0x7e9d55fc), X(0x12f9c7aa), X(0x7e95ec1a), - X(0x132b7bf9), X(0x7e8e6eb2), X(0x135d2d53), X(0x7e86ddc6), - X(0x138edbb1), X(0x7e7f3957), X(0x13c0870a), X(0x7e778166), - X(0x13f22f58), X(0x7e6fb5f4), X(0x1423d492), X(0x7e67d703), - X(0x145576b1), X(0x7e5fe493), X(0x148715ae), X(0x7e57dea7), - X(0x14b8b17f), X(0x7e4fc53e), X(0x14ea4a1f), X(0x7e47985b), - X(0x151bdf86), X(0x7e3f57ff), X(0x154d71aa), X(0x7e37042a), - X(0x157f0086), X(0x7e2e9cdf), X(0x15b08c12), X(0x7e26221f), - X(0x15e21445), X(0x7e1d93ea), X(0x16139918), X(0x7e14f242), - X(0x16451a83), X(0x7e0c3d29), X(0x1676987f), X(0x7e0374a0), - X(0x16a81305), X(0x7dfa98a8), X(0x16d98a0c), X(0x7df1a942), - X(0x170afd8d), X(0x7de8a670), X(0x173c6d80), X(0x7ddf9034), - X(0x176dd9de), X(0x7dd6668f), X(0x179f429f), X(0x7dcd2981), - X(0x17d0a7bc), X(0x7dc3d90d), X(0x1802092c), X(0x7dba7534), - X(0x183366e9), X(0x7db0fdf8), X(0x1864c0ea), X(0x7da77359), - X(0x18961728), X(0x7d9dd55a), X(0x18c7699b), X(0x7d9423fc), - X(0x18f8b83c), X(0x7d8a5f40), X(0x192a0304), X(0x7d808728), - X(0x195b49ea), X(0x7d769bb5), X(0x198c8ce7), X(0x7d6c9ce9), - X(0x19bdcbf3), X(0x7d628ac6), X(0x19ef0707), X(0x7d58654d), - X(0x1a203e1b), X(0x7d4e2c7f), X(0x1a517128), X(0x7d43e05e), - X(0x1a82a026), X(0x7d3980ec), X(0x1ab3cb0d), X(0x7d2f0e2b), - X(0x1ae4f1d6), X(0x7d24881b), X(0x1b161479), X(0x7d19eebf), - X(0x1b4732ef), X(0x7d0f4218), X(0x1b784d30), X(0x7d048228), - X(0x1ba96335), X(0x7cf9aef0), X(0x1bda74f6), X(0x7ceec873), - X(0x1c0b826a), X(0x7ce3ceb2), X(0x1c3c8b8c), X(0x7cd8c1ae), - X(0x1c6d9053), X(0x7ccda169), X(0x1c9e90b8), X(0x7cc26de5), - X(0x1ccf8cb3), X(0x7cb72724), X(0x1d00843d), X(0x7cabcd28), - X(0x1d31774d), X(0x7ca05ff1), X(0x1d6265dd), X(0x7c94df83), - X(0x1d934fe5), X(0x7c894bde), X(0x1dc4355e), X(0x7c7da505), - X(0x1df5163f), X(0x7c71eaf9), X(0x1e25f282), X(0x7c661dbc), - X(0x1e56ca1e), X(0x7c5a3d50), X(0x1e879d0d), X(0x7c4e49b7), - X(0x1eb86b46), X(0x7c4242f2), X(0x1ee934c3), X(0x7c362904), - X(0x1f19f97b), X(0x7c29fbee), X(0x1f4ab968), X(0x7c1dbbb3), - X(0x1f7b7481), X(0x7c116853), X(0x1fac2abf), X(0x7c0501d2), - X(0x1fdcdc1b), X(0x7bf88830), X(0x200d888d), X(0x7bebfb70), - X(0x203e300d), X(0x7bdf5b94), X(0x206ed295), X(0x7bd2a89e), - X(0x209f701c), X(0x7bc5e290), X(0x20d0089c), X(0x7bb9096b), - X(0x21009c0c), X(0x7bac1d31), X(0x21312a65), X(0x7b9f1de6), - X(0x2161b3a0), X(0x7b920b89), X(0x219237b5), X(0x7b84e61f), - X(0x21c2b69c), X(0x7b77ada8), X(0x21f3304f), X(0x7b6a6227), - X(0x2223a4c5), X(0x7b5d039e), X(0x225413f8), X(0x7b4f920e), - X(0x22847de0), X(0x7b420d7a), X(0x22b4e274), X(0x7b3475e5), - X(0x22e541af), X(0x7b26cb4f), X(0x23159b88), X(0x7b190dbc), - X(0x2345eff8), X(0x7b0b3d2c), X(0x23763ef7), X(0x7afd59a4), - X(0x23a6887f), X(0x7aef6323), X(0x23d6cc87), X(0x7ae159ae), - X(0x24070b08), X(0x7ad33d45), X(0x243743fa), X(0x7ac50dec), - X(0x24677758), X(0x7ab6cba4), X(0x2497a517), X(0x7aa8766f), - X(0x24c7cd33), X(0x7a9a0e50), X(0x24f7efa2), X(0x7a8b9348), - X(0x25280c5e), X(0x7a7d055b), X(0x2558235f), X(0x7a6e648a), - X(0x2588349d), X(0x7a5fb0d8), X(0x25b84012), X(0x7a50ea47), - X(0x25e845b6), X(0x7a4210d8), X(0x26184581), X(0x7a332490), - X(0x26483f6c), X(0x7a24256f), X(0x26783370), X(0x7a151378), - X(0x26a82186), X(0x7a05eead), X(0x26d809a5), X(0x79f6b711), - X(0x2707ebc7), X(0x79e76ca7), X(0x2737c7e3), X(0x79d80f6f), - X(0x27679df4), X(0x79c89f6e), X(0x27976df1), X(0x79b91ca4), - X(0x27c737d3), X(0x79a98715), X(0x27f6fb92), X(0x7999dec4), - X(0x2826b928), X(0x798a23b1), X(0x2856708d), X(0x797a55e0), - X(0x288621b9), X(0x796a7554), X(0x28b5cca5), X(0x795a820e), - X(0x28e5714b), X(0x794a7c12), X(0x29150fa1), X(0x793a6361), - X(0x2944a7a2), X(0x792a37fe), X(0x29743946), X(0x7919f9ec), - X(0x29a3c485), X(0x7909a92d), X(0x29d34958), X(0x78f945c3), - X(0x2a02c7b8), X(0x78e8cfb2), X(0x2a323f9e), X(0x78d846fb), - X(0x2a61b101), X(0x78c7aba2), X(0x2a911bdc), X(0x78b6fda8), - X(0x2ac08026), X(0x78a63d11), X(0x2aefddd8), X(0x789569df), - X(0x2b1f34eb), X(0x78848414), X(0x2b4e8558), X(0x78738bb3), - X(0x2b7dcf17), X(0x786280bf), X(0x2bad1221), X(0x7851633b), - X(0x2bdc4e6f), X(0x78403329), X(0x2c0b83fa), X(0x782ef08b), - X(0x2c3ab2b9), X(0x781d9b65), X(0x2c69daa6), X(0x780c33b8), - X(0x2c98fbba), X(0x77fab989), X(0x2cc815ee), X(0x77e92cd9), - X(0x2cf72939), X(0x77d78daa), X(0x2d263596), X(0x77c5dc01), - X(0x2d553afc), X(0x77b417df), X(0x2d843964), X(0x77a24148), - X(0x2db330c7), X(0x7790583e), X(0x2de2211e), X(0x777e5cc3), - X(0x2e110a62), X(0x776c4edb), X(0x2e3fec8b), X(0x775a2e89), - X(0x2e6ec792), X(0x7747fbce), X(0x2e9d9b70), X(0x7735b6af), - X(0x2ecc681e), X(0x77235f2d), X(0x2efb2d95), X(0x7710f54c), - X(0x2f29ebcc), X(0x76fe790e), X(0x2f58a2be), X(0x76ebea77), - X(0x2f875262), X(0x76d94989), X(0x2fb5fab2), X(0x76c69647), - X(0x2fe49ba7), X(0x76b3d0b4), X(0x30133539), X(0x76a0f8d2), - X(0x3041c761), X(0x768e0ea6), X(0x30705217), X(0x767b1231), - X(0x309ed556), X(0x76680376), X(0x30cd5115), X(0x7654e279), - X(0x30fbc54d), X(0x7641af3d), X(0x312a31f8), X(0x762e69c4), - X(0x3158970e), X(0x761b1211), X(0x3186f487), X(0x7607a828), - X(0x31b54a5e), X(0x75f42c0b), X(0x31e39889), X(0x75e09dbd), - X(0x3211df04), X(0x75ccfd42), X(0x32401dc6), X(0x75b94a9c), - X(0x326e54c7), X(0x75a585cf), X(0x329c8402), X(0x7591aedd), - X(0x32caab6f), X(0x757dc5ca), X(0x32f8cb07), X(0x7569ca99), - X(0x3326e2c3), X(0x7555bd4c), X(0x3354f29b), X(0x75419de7), - X(0x3382fa88), X(0x752d6c6c), X(0x33b0fa84), X(0x751928e0), - X(0x33def287), X(0x7504d345), X(0x340ce28b), X(0x74f06b9e), - X(0x343aca87), X(0x74dbf1ef), X(0x3468aa76), X(0x74c7663a), - X(0x34968250), X(0x74b2c884), X(0x34c4520d), X(0x749e18cd), - X(0x34f219a8), X(0x7489571c), X(0x351fd918), X(0x74748371), - X(0x354d9057), X(0x745f9dd1), X(0x357b3f5d), X(0x744aa63f), - X(0x35a8e625), X(0x74359cbd), X(0x35d684a6), X(0x74208150), - X(0x36041ad9), X(0x740b53fb), X(0x3631a8b8), X(0x73f614c0), - X(0x365f2e3b), X(0x73e0c3a3), X(0x368cab5c), X(0x73cb60a8), - X(0x36ba2014), X(0x73b5ebd1), X(0x36e78c5b), X(0x73a06522), - X(0x3714f02a), X(0x738acc9e), X(0x37424b7b), X(0x73752249), - X(0x376f9e46), X(0x735f6626), X(0x379ce885), X(0x73499838), - X(0x37ca2a30), X(0x7333b883), X(0x37f76341), X(0x731dc70a), - X(0x382493b0), X(0x7307c3d0), X(0x3851bb77), X(0x72f1aed9), - X(0x387eda8e), X(0x72db8828), X(0x38abf0ef), X(0x72c54fc1), - X(0x38d8fe93), X(0x72af05a7), X(0x39060373), X(0x7298a9dd), - X(0x3932ff87), X(0x72823c67), X(0x395ff2c9), X(0x726bbd48), - X(0x398cdd32), X(0x72552c85), X(0x39b9bebc), X(0x723e8a20), - X(0x39e6975e), X(0x7227d61c), X(0x3a136712), X(0x7211107e), - X(0x3a402dd2), X(0x71fa3949), X(0x3a6ceb96), X(0x71e35080), - X(0x3a99a057), X(0x71cc5626), X(0x3ac64c0f), X(0x71b54a41), - X(0x3af2eeb7), X(0x719e2cd2), X(0x3b1f8848), X(0x7186fdde), - X(0x3b4c18ba), X(0x716fbd68), X(0x3b78a007), X(0x71586b74), - X(0x3ba51e29), X(0x71410805), X(0x3bd19318), X(0x7129931f), - X(0x3bfdfecd), X(0x71120cc5), X(0x3c2a6142), X(0x70fa74fc), - X(0x3c56ba70), X(0x70e2cbc6), X(0x3c830a50), X(0x70cb1128), - X(0x3caf50da), X(0x70b34525), X(0x3cdb8e09), X(0x709b67c0), - X(0x3d07c1d6), X(0x708378ff), X(0x3d33ec39), X(0x706b78e3), - X(0x3d600d2c), X(0x70536771), X(0x3d8c24a8), X(0x703b44ad), - X(0x3db832a6), X(0x7023109a), X(0x3de4371f), X(0x700acb3c), - X(0x3e10320d), X(0x6ff27497), X(0x3e3c2369), X(0x6fda0cae), - X(0x3e680b2c), X(0x6fc19385), X(0x3e93e950), X(0x6fa90921), - X(0x3ebfbdcd), X(0x6f906d84), X(0x3eeb889c), X(0x6f77c0b3), - X(0x3f1749b8), X(0x6f5f02b2), X(0x3f430119), X(0x6f463383), - X(0x3f6eaeb8), X(0x6f2d532c), X(0x3f9a5290), X(0x6f1461b0), - X(0x3fc5ec98), X(0x6efb5f12), X(0x3ff17cca), X(0x6ee24b57), - X(0x401d0321), X(0x6ec92683), X(0x40487f94), X(0x6eaff099), - X(0x4073f21d), X(0x6e96a99d), X(0x409f5ab6), X(0x6e7d5193), - X(0x40cab958), X(0x6e63e87f), X(0x40f60dfb), X(0x6e4a6e66), - X(0x4121589b), X(0x6e30e34a), X(0x414c992f), X(0x6e174730), - X(0x4177cfb1), X(0x6dfd9a1c), X(0x41a2fc1a), X(0x6de3dc11), - X(0x41ce1e65), X(0x6dca0d14), X(0x41f93689), X(0x6db02d29), - X(0x42244481), X(0x6d963c54), X(0x424f4845), X(0x6d7c3a98), - X(0x427a41d0), X(0x6d6227fa), X(0x42a5311b), X(0x6d48047e), - X(0x42d0161e), X(0x6d2dd027), X(0x42faf0d4), X(0x6d138afb), - X(0x4325c135), X(0x6cf934fc), X(0x4350873c), X(0x6cdece2f), - X(0x437b42e1), X(0x6cc45698), X(0x43a5f41e), X(0x6ca9ce3b), - X(0x43d09aed), X(0x6c8f351c), X(0x43fb3746), X(0x6c748b3f), - X(0x4425c923), X(0x6c59d0a9), X(0x4450507e), X(0x6c3f055d), - X(0x447acd50), X(0x6c242960), X(0x44a53f93), X(0x6c093cb6), - X(0x44cfa740), X(0x6bee3f62), X(0x44fa0450), X(0x6bd3316a), - X(0x452456bd), X(0x6bb812d1), X(0x454e9e80), X(0x6b9ce39b), - X(0x4578db93), X(0x6b81a3cd), X(0x45a30df0), X(0x6b66536b), - X(0x45cd358f), X(0x6b4af279), X(0x45f7526b), X(0x6b2f80fb), - X(0x4621647d), X(0x6b13fef5), X(0x464b6bbe), X(0x6af86c6c), - X(0x46756828), X(0x6adcc964), X(0x469f59b4), X(0x6ac115e2), - X(0x46c9405c), X(0x6aa551e9), X(0x46f31c1a), X(0x6a897d7d), - X(0x471cece7), X(0x6a6d98a4), X(0x4746b2bc), X(0x6a51a361), - X(0x47706d93), X(0x6a359db9), X(0x479a1d67), X(0x6a1987b0), - X(0x47c3c22f), X(0x69fd614a), X(0x47ed5be6), X(0x69e12a8c), - X(0x4816ea86), X(0x69c4e37a), X(0x48406e08), X(0x69a88c19), - X(0x4869e665), X(0x698c246c), X(0x48935397), X(0x696fac78), - X(0x48bcb599), X(0x69532442), X(0x48e60c62), X(0x69368bce), - X(0x490f57ee), X(0x6919e320), X(0x49389836), X(0x68fd2a3d), - X(0x4961cd33), X(0x68e06129), X(0x498af6df), X(0x68c387e9), - X(0x49b41533), X(0x68a69e81), X(0x49dd282a), X(0x6889a4f6), - X(0x4a062fbd), X(0x686c9b4b), X(0x4a2f2be6), X(0x684f8186), - X(0x4a581c9e), X(0x683257ab), X(0x4a8101de), X(0x68151dbe), - X(0x4aa9dba2), X(0x67f7d3c5), X(0x4ad2a9e2), X(0x67da79c3), - X(0x4afb6c98), X(0x67bd0fbd), X(0x4b2423be), X(0x679f95b7), - X(0x4b4ccf4d), X(0x67820bb7), X(0x4b756f40), X(0x676471c0), - X(0x4b9e0390), X(0x6746c7d8), X(0x4bc68c36), X(0x67290e02), - X(0x4bef092d), X(0x670b4444), X(0x4c177a6e), X(0x66ed6aa1), - X(0x4c3fdff4), X(0x66cf8120), X(0x4c6839b7), X(0x66b187c3), - X(0x4c9087b1), X(0x66937e91), X(0x4cb8c9dd), X(0x6675658c), - X(0x4ce10034), X(0x66573cbb), X(0x4d092ab0), X(0x66390422), - X(0x4d31494b), X(0x661abbc5), X(0x4d595bfe), X(0x65fc63a9), - X(0x4d8162c4), X(0x65ddfbd3), X(0x4da95d96), X(0x65bf8447), - X(0x4dd14c6e), X(0x65a0fd0b), X(0x4df92f46), X(0x65826622), - X(0x4e210617), X(0x6563bf92), X(0x4e48d0dd), X(0x6545095f), - X(0x4e708f8f), X(0x6526438f), X(0x4e984229), X(0x65076e25), - X(0x4ebfe8a5), X(0x64e88926), X(0x4ee782fb), X(0x64c99498), - X(0x4f0f1126), X(0x64aa907f), X(0x4f369320), X(0x648b7ce0), - X(0x4f5e08e3), X(0x646c59bf), X(0x4f857269), X(0x644d2722), - X(0x4faccfab), X(0x642de50d), X(0x4fd420a4), X(0x640e9386), - X(0x4ffb654d), X(0x63ef3290), X(0x50229da1), X(0x63cfc231), - X(0x5049c999), X(0x63b0426d), X(0x5070e92f), X(0x6390b34a), - X(0x5097fc5e), X(0x637114cc), X(0x50bf031f), X(0x635166f9), - X(0x50e5fd6d), X(0x6331a9d4), X(0x510ceb40), X(0x6311dd64), - X(0x5133cc94), X(0x62f201ac), X(0x515aa162), X(0x62d216b3), - X(0x518169a5), X(0x62b21c7b), X(0x51a82555), X(0x6292130c), - X(0x51ced46e), X(0x6271fa69), X(0x51f576ea), X(0x6251d298), - X(0x521c0cc2), X(0x62319b9d), X(0x524295f0), X(0x6211557e), - X(0x5269126e), X(0x61f1003f), X(0x528f8238), X(0x61d09be5), - X(0x52b5e546), X(0x61b02876), X(0x52dc3b92), X(0x618fa5f7), - X(0x53028518), X(0x616f146c), X(0x5328c1d0), X(0x614e73da), - X(0x534ef1b5), X(0x612dc447), X(0x537514c2), X(0x610d05b7), - X(0x539b2af0), X(0x60ec3830), X(0x53c13439), X(0x60cb5bb7), - X(0x53e73097), X(0x60aa7050), X(0x540d2005), X(0x60897601), - X(0x5433027d), X(0x60686ccf), X(0x5458d7f9), X(0x604754bf), - X(0x547ea073), X(0x60262dd6), X(0x54a45be6), X(0x6004f819), - X(0x54ca0a4b), X(0x5fe3b38d), X(0x54efab9c), X(0x5fc26038), - X(0x55153fd4), X(0x5fa0fe1f), X(0x553ac6ee), X(0x5f7f8d46), - X(0x556040e2), X(0x5f5e0db3), X(0x5585adad), X(0x5f3c7f6b), - X(0x55ab0d46), X(0x5f1ae274), X(0x55d05faa), X(0x5ef936d1), - X(0x55f5a4d2), X(0x5ed77c8a), X(0x561adcb9), X(0x5eb5b3a2), - X(0x56400758), X(0x5e93dc1f), X(0x566524aa), X(0x5e71f606), - X(0x568a34a9), X(0x5e50015d), X(0x56af3750), X(0x5e2dfe29), - X(0x56d42c99), X(0x5e0bec6e), X(0x56f9147e), X(0x5de9cc33), - X(0x571deefa), X(0x5dc79d7c), X(0x5742bc06), X(0x5da5604f), - X(0x57677b9d), X(0x5d8314b1), X(0x578c2dba), X(0x5d60baa7), - X(0x57b0d256), X(0x5d3e5237), X(0x57d5696d), X(0x5d1bdb65), - X(0x57f9f2f8), X(0x5cf95638), X(0x581e6ef1), X(0x5cd6c2b5), - X(0x5842dd54), X(0x5cb420e0), X(0x58673e1b), X(0x5c9170bf), - X(0x588b9140), X(0x5c6eb258), X(0x58afd6bd), X(0x5c4be5b0), - X(0x58d40e8c), X(0x5c290acc), X(0x58f838a9), X(0x5c0621b2), - X(0x591c550e), X(0x5be32a67), X(0x594063b5), X(0x5bc024f0), - X(0x59646498), X(0x5b9d1154), X(0x598857b2), X(0x5b79ef96), - X(0x59ac3cfd), X(0x5b56bfbd), X(0x59d01475), X(0x5b3381ce), - X(0x59f3de12), X(0x5b1035cf), X(0x5a1799d1), X(0x5aecdbc5), - X(0x5a3b47ab), X(0x5ac973b5), X(0x5a5ee79a), X(0x5aa5fda5), - X(0x5a82799a), X(0x5a82799a) - }; - - /* {sin((2*i+1)*PI/4096), cos((2*i+1)*PI/4096)}, with i = 0 to 511 */ -static LOOKUP_T sincos_lookup1[1024] = { - X(0x001921fb), X(0x7ffffd88), X(0x004b65ee), X(0x7fffe9cb), - X(0x007da9d4), X(0x7fffc251), X(0x00afeda8), X(0x7fff8719), - X(0x00e23160), X(0x7fff3824), X(0x011474f6), X(0x7ffed572), - X(0x0146b860), X(0x7ffe5f03), X(0x0178fb99), X(0x7ffdd4d7), - X(0x01ab3e97), X(0x7ffd36ee), X(0x01dd8154), X(0x7ffc8549), - X(0x020fc3c6), X(0x7ffbbfe6), X(0x024205e8), X(0x7ffae6c7), - X(0x027447b0), X(0x7ff9f9ec), X(0x02a68917), X(0x7ff8f954), - X(0x02d8ca16), X(0x7ff7e500), X(0x030b0aa4), X(0x7ff6bcf0), - X(0x033d4abb), X(0x7ff58125), X(0x036f8a51), X(0x7ff4319d), - X(0x03a1c960), X(0x7ff2ce5b), X(0x03d407df), X(0x7ff1575d), - X(0x040645c7), X(0x7fefcca4), X(0x04388310), X(0x7fee2e30), - X(0x046abfb3), X(0x7fec7c02), X(0x049cfba7), X(0x7feab61a), - X(0x04cf36e5), X(0x7fe8dc78), X(0x05017165), X(0x7fe6ef1c), - X(0x0533ab20), X(0x7fe4ee06), X(0x0565e40d), X(0x7fe2d938), - X(0x05981c26), X(0x7fe0b0b1), X(0x05ca5361), X(0x7fde7471), - X(0x05fc89b8), X(0x7fdc247a), X(0x062ebf22), X(0x7fd9c0ca), - X(0x0660f398), X(0x7fd74964), X(0x06932713), X(0x7fd4be46), - X(0x06c5598a), X(0x7fd21f72), X(0x06f78af6), X(0x7fcf6ce8), - X(0x0729bb4e), X(0x7fcca6a7), X(0x075bea8c), X(0x7fc9ccb2), - X(0x078e18a7), X(0x7fc6df08), X(0x07c04598), X(0x7fc3dda9), - X(0x07f27157), X(0x7fc0c896), X(0x08249bdd), X(0x7fbd9fd0), - X(0x0856c520), X(0x7fba6357), X(0x0888ed1b), X(0x7fb7132b), - X(0x08bb13c5), X(0x7fb3af4e), X(0x08ed3916), X(0x7fb037bf), - X(0x091f5d06), X(0x7facac7f), X(0x09517f8f), X(0x7fa90d8e), - X(0x0983a0a7), X(0x7fa55aee), X(0x09b5c048), X(0x7fa1949e), - X(0x09e7de6a), X(0x7f9dbaa0), X(0x0a19fb04), X(0x7f99ccf4), - X(0x0a4c1610), X(0x7f95cb9a), X(0x0a7e2f85), X(0x7f91b694), - X(0x0ab0475c), X(0x7f8d8de1), X(0x0ae25d8d), X(0x7f895182), - X(0x0b147211), X(0x7f850179), X(0x0b4684df), X(0x7f809dc5), - X(0x0b7895f0), X(0x7f7c2668), X(0x0baaa53b), X(0x7f779b62), - X(0x0bdcb2bb), X(0x7f72fcb4), X(0x0c0ebe66), X(0x7f6e4a5e), - X(0x0c40c835), X(0x7f698461), X(0x0c72d020), X(0x7f64aabf), - X(0x0ca4d620), X(0x7f5fbd77), X(0x0cd6da2d), X(0x7f5abc8a), - X(0x0d08dc3f), X(0x7f55a7fa), X(0x0d3adc4e), X(0x7f507fc7), - X(0x0d6cda53), X(0x7f4b43f2), X(0x0d9ed646), X(0x7f45f47b), - X(0x0dd0d01f), X(0x7f409164), X(0x0e02c7d7), X(0x7f3b1aad), - X(0x0e34bd66), X(0x7f359057), X(0x0e66b0c3), X(0x7f2ff263), - X(0x0e98a1e9), X(0x7f2a40d2), X(0x0eca90ce), X(0x7f247ba5), - X(0x0efc7d6b), X(0x7f1ea2dc), X(0x0f2e67b8), X(0x7f18b679), - X(0x0f604faf), X(0x7f12b67c), X(0x0f923546), X(0x7f0ca2e7), - X(0x0fc41876), X(0x7f067bba), X(0x0ff5f938), X(0x7f0040f6), - X(0x1027d784), X(0x7ef9f29d), X(0x1059b352), X(0x7ef390ae), - X(0x108b8c9b), X(0x7eed1b2c), X(0x10bd6356), X(0x7ee69217), - X(0x10ef377d), X(0x7edff570), X(0x11210907), X(0x7ed94538), - X(0x1152d7ed), X(0x7ed28171), X(0x1184a427), X(0x7ecbaa1a), - X(0x11b66dad), X(0x7ec4bf36), X(0x11e83478), X(0x7ebdc0c6), - X(0x1219f880), X(0x7eb6aeca), X(0x124bb9be), X(0x7eaf8943), - X(0x127d7829), X(0x7ea85033), X(0x12af33ba), X(0x7ea1039b), - X(0x12e0ec6a), X(0x7e99a37c), X(0x1312a230), X(0x7e922fd6), - X(0x13445505), X(0x7e8aa8ac), X(0x137604e2), X(0x7e830dff), - X(0x13a7b1bf), X(0x7e7b5fce), X(0x13d95b93), X(0x7e739e1d), - X(0x140b0258), X(0x7e6bc8eb), X(0x143ca605), X(0x7e63e03b), - X(0x146e4694), X(0x7e5be40c), X(0x149fe3fc), X(0x7e53d462), - X(0x14d17e36), X(0x7e4bb13c), X(0x1503153a), X(0x7e437a9c), - X(0x1534a901), X(0x7e3b3083), X(0x15663982), X(0x7e32d2f4), - X(0x1597c6b7), X(0x7e2a61ed), X(0x15c95097), X(0x7e21dd73), - X(0x15fad71b), X(0x7e194584), X(0x162c5a3b), X(0x7e109a24), - X(0x165dd9f0), X(0x7e07db52), X(0x168f5632), X(0x7dff0911), - X(0x16c0cef9), X(0x7df62362), X(0x16f2443e), X(0x7ded2a47), - X(0x1723b5f9), X(0x7de41dc0), X(0x17552422), X(0x7ddafdce), - X(0x17868eb3), X(0x7dd1ca75), X(0x17b7f5a3), X(0x7dc883b4), - X(0x17e958ea), X(0x7dbf298d), X(0x181ab881), X(0x7db5bc02), - X(0x184c1461), X(0x7dac3b15), X(0x187d6c82), X(0x7da2a6c6), - X(0x18aec0db), X(0x7d98ff17), X(0x18e01167), X(0x7d8f4409), - X(0x19115e1c), X(0x7d85759f), X(0x1942a6f3), X(0x7d7b93da), - X(0x1973ebe6), X(0x7d719eba), X(0x19a52ceb), X(0x7d679642), - X(0x19d669fc), X(0x7d5d7a74), X(0x1a07a311), X(0x7d534b50), - X(0x1a38d823), X(0x7d4908d9), X(0x1a6a0929), X(0x7d3eb30f), - X(0x1a9b361d), X(0x7d3449f5), X(0x1acc5ef6), X(0x7d29cd8c), - X(0x1afd83ad), X(0x7d1f3dd6), X(0x1b2ea43a), X(0x7d149ad5), - X(0x1b5fc097), X(0x7d09e489), X(0x1b90d8bb), X(0x7cff1af5), - X(0x1bc1ec9e), X(0x7cf43e1a), X(0x1bf2fc3a), X(0x7ce94dfb), - X(0x1c240786), X(0x7cde4a98), X(0x1c550e7c), X(0x7cd333f3), - X(0x1c861113), X(0x7cc80a0f), X(0x1cb70f43), X(0x7cbcccec), - X(0x1ce80906), X(0x7cb17c8d), X(0x1d18fe54), X(0x7ca618f3), - X(0x1d49ef26), X(0x7c9aa221), X(0x1d7adb73), X(0x7c8f1817), - X(0x1dabc334), X(0x7c837ad8), X(0x1ddca662), X(0x7c77ca65), - X(0x1e0d84f5), X(0x7c6c06c0), X(0x1e3e5ee5), X(0x7c602fec), - X(0x1e6f342c), X(0x7c5445e9), X(0x1ea004c1), X(0x7c4848ba), - X(0x1ed0d09d), X(0x7c3c3860), X(0x1f0197b8), X(0x7c3014de), - X(0x1f325a0b), X(0x7c23de35), X(0x1f63178f), X(0x7c179467), - X(0x1f93d03c), X(0x7c0b3777), X(0x1fc4840a), X(0x7bfec765), - X(0x1ff532f2), X(0x7bf24434), X(0x2025dcec), X(0x7be5ade6), - X(0x205681f1), X(0x7bd9047c), X(0x208721f9), X(0x7bcc47fa), - X(0x20b7bcfe), X(0x7bbf7860), X(0x20e852f6), X(0x7bb295b0), - X(0x2118e3dc), X(0x7ba59fee), X(0x21496fa7), X(0x7b989719), - X(0x2179f64f), X(0x7b8b7b36), X(0x21aa77cf), X(0x7b7e4c45), - X(0x21daf41d), X(0x7b710a49), X(0x220b6b32), X(0x7b63b543), - X(0x223bdd08), X(0x7b564d36), X(0x226c4996), X(0x7b48d225), - X(0x229cb0d5), X(0x7b3b4410), X(0x22cd12bd), X(0x7b2da2fa), - X(0x22fd6f48), X(0x7b1feee5), X(0x232dc66d), X(0x7b1227d3), - X(0x235e1826), X(0x7b044dc7), X(0x238e646a), X(0x7af660c2), - X(0x23beab33), X(0x7ae860c7), X(0x23eeec78), X(0x7ada4dd8), - X(0x241f2833), X(0x7acc27f7), X(0x244f5e5c), X(0x7abdef25), - X(0x247f8eec), X(0x7aafa367), X(0x24afb9da), X(0x7aa144bc), - X(0x24dfdf20), X(0x7a92d329), X(0x250ffeb7), X(0x7a844eae), - X(0x25401896), X(0x7a75b74f), X(0x25702cb7), X(0x7a670d0d), - X(0x25a03b11), X(0x7a584feb), X(0x25d0439f), X(0x7a497feb), - X(0x26004657), X(0x7a3a9d0f), X(0x26304333), X(0x7a2ba75a), - X(0x26603a2c), X(0x7a1c9ece), X(0x26902b39), X(0x7a0d836d), - X(0x26c01655), X(0x79fe5539), X(0x26effb76), X(0x79ef1436), - X(0x271fda96), X(0x79dfc064), X(0x274fb3ae), X(0x79d059c8), - X(0x277f86b5), X(0x79c0e062), X(0x27af53a6), X(0x79b15435), - X(0x27df1a77), X(0x79a1b545), X(0x280edb23), X(0x79920392), - X(0x283e95a1), X(0x79823f20), X(0x286e49ea), X(0x797267f2), - X(0x289df7f8), X(0x79627e08), X(0x28cd9fc1), X(0x79528167), - X(0x28fd4140), X(0x79427210), X(0x292cdc6d), X(0x79325006), - X(0x295c7140), X(0x79221b4b), X(0x298bffb2), X(0x7911d3e2), - X(0x29bb87bc), X(0x790179cd), X(0x29eb0957), X(0x78f10d0f), - X(0x2a1a847b), X(0x78e08dab), X(0x2a49f920), X(0x78cffba3), - X(0x2a796740), X(0x78bf56f9), X(0x2aa8ced3), X(0x78ae9fb0), - X(0x2ad82fd2), X(0x789dd5cb), X(0x2b078a36), X(0x788cf94c), - X(0x2b36ddf7), X(0x787c0a36), X(0x2b662b0e), X(0x786b088c), - X(0x2b957173), X(0x7859f44f), X(0x2bc4b120), X(0x7848cd83), - X(0x2bf3ea0d), X(0x7837942b), X(0x2c231c33), X(0x78264849), - X(0x2c52478a), X(0x7814e9df), X(0x2c816c0c), X(0x780378f1), - X(0x2cb089b1), X(0x77f1f581), X(0x2cdfa071), X(0x77e05f91), - X(0x2d0eb046), X(0x77ceb725), X(0x2d3db928), X(0x77bcfc3f), - X(0x2d6cbb10), X(0x77ab2ee2), X(0x2d9bb5f6), X(0x77994f11), - X(0x2dcaa9d5), X(0x77875cce), X(0x2df996a3), X(0x7775581d), - X(0x2e287c5a), X(0x776340ff), X(0x2e575af3), X(0x77511778), - X(0x2e863267), X(0x773edb8b), X(0x2eb502ae), X(0x772c8d3a), - X(0x2ee3cbc1), X(0x771a2c88), X(0x2f128d99), X(0x7707b979), - X(0x2f41482e), X(0x76f5340e), X(0x2f6ffb7a), X(0x76e29c4b), - X(0x2f9ea775), X(0x76cff232), X(0x2fcd4c19), X(0x76bd35c7), - X(0x2ffbe95d), X(0x76aa670d), X(0x302a7f3a), X(0x76978605), - X(0x30590dab), X(0x768492b4), X(0x308794a6), X(0x76718d1c), - X(0x30b61426), X(0x765e7540), X(0x30e48c22), X(0x764b4b23), - X(0x3112fc95), X(0x76380ec8), X(0x31416576), X(0x7624c031), - X(0x316fc6be), X(0x76115f63), X(0x319e2067), X(0x75fdec60), - X(0x31cc7269), X(0x75ea672a), X(0x31fabcbd), X(0x75d6cfc5), - X(0x3228ff5c), X(0x75c32634), X(0x32573a3f), X(0x75af6a7b), - X(0x32856d5e), X(0x759b9c9b), X(0x32b398b3), X(0x7587bc98), - X(0x32e1bc36), X(0x7573ca75), X(0x330fd7e1), X(0x755fc635), - X(0x333debab), X(0x754bafdc), X(0x336bf78f), X(0x7537876c), - X(0x3399fb85), X(0x75234ce8), X(0x33c7f785), X(0x750f0054), - X(0x33f5eb89), X(0x74faa1b3), X(0x3423d78a), X(0x74e63108), - X(0x3451bb81), X(0x74d1ae55), X(0x347f9766), X(0x74bd199f), - X(0x34ad6b32), X(0x74a872e8), X(0x34db36df), X(0x7493ba34), - X(0x3508fa66), X(0x747eef85), X(0x3536b5be), X(0x746a12df), - X(0x356468e2), X(0x74552446), X(0x359213c9), X(0x744023bc), - X(0x35bfb66e), X(0x742b1144), X(0x35ed50c9), X(0x7415ece2), - X(0x361ae2d3), X(0x7400b69a), X(0x36486c86), X(0x73eb6e6e), - X(0x3675edd9), X(0x73d61461), X(0x36a366c6), X(0x73c0a878), - X(0x36d0d746), X(0x73ab2ab4), X(0x36fe3f52), X(0x73959b1b), - X(0x372b9ee3), X(0x737ff9ae), X(0x3758f5f2), X(0x736a4671), - X(0x37864477), X(0x73548168), X(0x37b38a6d), X(0x733eaa96), - X(0x37e0c7cc), X(0x7328c1ff), X(0x380dfc8d), X(0x7312c7a5), - X(0x383b28a9), X(0x72fcbb8c), X(0x38684c19), X(0x72e69db7), - X(0x389566d6), X(0x72d06e2b), X(0x38c278d9), X(0x72ba2cea), - X(0x38ef821c), X(0x72a3d9f7), X(0x391c8297), X(0x728d7557), - X(0x39497a43), X(0x7276ff0d), X(0x39766919), X(0x7260771b), - X(0x39a34f13), X(0x7249dd86), X(0x39d02c2a), X(0x72333251), - X(0x39fd0056), X(0x721c7580), X(0x3a29cb91), X(0x7205a716), - X(0x3a568dd4), X(0x71eec716), X(0x3a834717), X(0x71d7d585), - X(0x3aaff755), X(0x71c0d265), X(0x3adc9e86), X(0x71a9bdba), - X(0x3b093ca3), X(0x71929789), X(0x3b35d1a5), X(0x717b5fd3), - X(0x3b625d86), X(0x7164169d), X(0x3b8ee03e), X(0x714cbbeb), - X(0x3bbb59c7), X(0x71354fc0), X(0x3be7ca1a), X(0x711dd220), - X(0x3c143130), X(0x7106430e), X(0x3c408f03), X(0x70eea28e), - X(0x3c6ce38a), X(0x70d6f0a4), X(0x3c992ec0), X(0x70bf2d53), - X(0x3cc5709e), X(0x70a7589f), X(0x3cf1a91c), X(0x708f728b), - X(0x3d1dd835), X(0x70777b1c), X(0x3d49fde1), X(0x705f7255), - X(0x3d761a19), X(0x70475839), X(0x3da22cd7), X(0x702f2ccd), - X(0x3dce3614), X(0x7016f014), X(0x3dfa35c8), X(0x6ffea212), - X(0x3e262bee), X(0x6fe642ca), X(0x3e52187f), X(0x6fcdd241), - X(0x3e7dfb73), X(0x6fb5507a), X(0x3ea9d4c3), X(0x6f9cbd79), - X(0x3ed5a46b), X(0x6f841942), X(0x3f016a61), X(0x6f6b63d8), - X(0x3f2d26a0), X(0x6f529d40), X(0x3f58d921), X(0x6f39c57d), - X(0x3f8481dd), X(0x6f20dc92), X(0x3fb020ce), X(0x6f07e285), - X(0x3fdbb5ec), X(0x6eeed758), X(0x40074132), X(0x6ed5bb10), - X(0x4032c297), X(0x6ebc8db0), X(0x405e3a16), X(0x6ea34f3d), - X(0x4089a7a8), X(0x6e89ffb9), X(0x40b50b46), X(0x6e709f2a), - X(0x40e064ea), X(0x6e572d93), X(0x410bb48c), X(0x6e3daaf8), - X(0x4136fa27), X(0x6e24175c), X(0x416235b2), X(0x6e0a72c5), - X(0x418d6729), X(0x6df0bd35), X(0x41b88e84), X(0x6dd6f6b1), - X(0x41e3abbc), X(0x6dbd1f3c), X(0x420ebecb), X(0x6da336dc), - X(0x4239c7aa), X(0x6d893d93), X(0x4264c653), X(0x6d6f3365), - X(0x428fbabe), X(0x6d551858), X(0x42baa4e6), X(0x6d3aec6e), - X(0x42e584c3), X(0x6d20afac), X(0x43105a50), X(0x6d066215), - X(0x433b2585), X(0x6cec03af), X(0x4365e65b), X(0x6cd1947c), - X(0x43909ccd), X(0x6cb71482), X(0x43bb48d4), X(0x6c9c83c3), - X(0x43e5ea68), X(0x6c81e245), X(0x44108184), X(0x6c67300b), - X(0x443b0e21), X(0x6c4c6d1a), X(0x44659039), X(0x6c319975), - X(0x449007c4), X(0x6c16b521), X(0x44ba74bd), X(0x6bfbc021), - X(0x44e4d71c), X(0x6be0ba7b), X(0x450f2edb), X(0x6bc5a431), - X(0x45397bf4), X(0x6baa7d49), X(0x4563be60), X(0x6b8f45c7), - X(0x458df619), X(0x6b73fdae), X(0x45b82318), X(0x6b58a503), - X(0x45e24556), X(0x6b3d3bcb), X(0x460c5cce), X(0x6b21c208), - X(0x46366978), X(0x6b0637c1), X(0x46606b4e), X(0x6aea9cf8), - X(0x468a624a), X(0x6acef1b2), X(0x46b44e65), X(0x6ab335f4), - X(0x46de2f99), X(0x6a9769c1), X(0x470805df), X(0x6a7b8d1e), - X(0x4731d131), X(0x6a5fa010), X(0x475b9188), X(0x6a43a29a), - X(0x478546de), X(0x6a2794c1), X(0x47aef12c), X(0x6a0b7689), - X(0x47d8906d), X(0x69ef47f6), X(0x48022499), X(0x69d3090e), - X(0x482badab), X(0x69b6b9d3), X(0x48552b9b), X(0x699a5a4c), - X(0x487e9e64), X(0x697dea7b), X(0x48a805ff), X(0x69616a65), - X(0x48d16265), X(0x6944da10), X(0x48fab391), X(0x6928397e), - X(0x4923f97b), X(0x690b88b5), X(0x494d341e), X(0x68eec7b9), - X(0x49766373), X(0x68d1f68f), X(0x499f8774), X(0x68b5153a), - X(0x49c8a01b), X(0x689823bf), X(0x49f1ad61), X(0x687b2224), - X(0x4a1aaf3f), X(0x685e106c), X(0x4a43a5b0), X(0x6840ee9b), - X(0x4a6c90ad), X(0x6823bcb7), X(0x4a957030), X(0x68067ac3), - X(0x4abe4433), X(0x67e928c5), X(0x4ae70caf), X(0x67cbc6c0), - X(0x4b0fc99d), X(0x67ae54ba), X(0x4b387af9), X(0x6790d2b6), - X(0x4b6120bb), X(0x677340ba), X(0x4b89badd), X(0x67559eca), - X(0x4bb24958), X(0x6737ecea), X(0x4bdacc28), X(0x671a2b20), - X(0x4c034345), X(0x66fc596f), X(0x4c2baea9), X(0x66de77dc), - X(0x4c540e4e), X(0x66c0866d), X(0x4c7c622d), X(0x66a28524), - X(0x4ca4aa41), X(0x66847408), X(0x4ccce684), X(0x6666531d), - X(0x4cf516ee), X(0x66482267), X(0x4d1d3b7a), X(0x6629e1ec), - X(0x4d455422), X(0x660b91af), X(0x4d6d60df), X(0x65ed31b5), - X(0x4d9561ac), X(0x65cec204), X(0x4dbd5682), X(0x65b0429f), - X(0x4de53f5a), X(0x6591b38c), X(0x4e0d1c30), X(0x657314cf), - X(0x4e34ecfc), X(0x6554666d), X(0x4e5cb1b9), X(0x6535a86b), - X(0x4e846a60), X(0x6516dacd), X(0x4eac16eb), X(0x64f7fd98), - X(0x4ed3b755), X(0x64d910d1), X(0x4efb4b96), X(0x64ba147d), - X(0x4f22d3aa), X(0x649b08a0), X(0x4f4a4f89), X(0x647bed3f), - X(0x4f71bf2e), X(0x645cc260), X(0x4f992293), X(0x643d8806), - X(0x4fc079b1), X(0x641e3e38), X(0x4fe7c483), X(0x63fee4f8), - X(0x500f0302), X(0x63df7c4d), X(0x50363529), X(0x63c0043b), - X(0x505d5af1), X(0x63a07cc7), X(0x50847454), X(0x6380e5f6), - X(0x50ab814d), X(0x63613fcd), X(0x50d281d5), X(0x63418a50), - X(0x50f975e6), X(0x6321c585), X(0x51205d7b), X(0x6301f171), - X(0x5147388c), X(0x62e20e17), X(0x516e0715), X(0x62c21b7e), - X(0x5194c910), X(0x62a219aa), X(0x51bb7e75), X(0x628208a1), - X(0x51e22740), X(0x6261e866), X(0x5208c36a), X(0x6241b8ff), - X(0x522f52ee), X(0x62217a72), X(0x5255d5c5), X(0x62012cc2), - X(0x527c4bea), X(0x61e0cff5), X(0x52a2b556), X(0x61c06410), - X(0x52c91204), X(0x619fe918), X(0x52ef61ee), X(0x617f5f12), - X(0x5315a50e), X(0x615ec603), X(0x533bdb5d), X(0x613e1df0), - X(0x536204d7), X(0x611d66de), X(0x53882175), X(0x60fca0d2), - X(0x53ae3131), X(0x60dbcbd1), X(0x53d43406), X(0x60bae7e1), - X(0x53fa29ed), X(0x6099f505), X(0x542012e1), X(0x6078f344), - X(0x5445eedb), X(0x6057e2a2), X(0x546bbdd7), X(0x6036c325), - X(0x54917fce), X(0x601594d1), X(0x54b734ba), X(0x5ff457ad), - X(0x54dcdc96), X(0x5fd30bbc), X(0x5502775c), X(0x5fb1b104), - X(0x55280505), X(0x5f90478a), X(0x554d858d), X(0x5f6ecf53), - X(0x5572f8ed), X(0x5f4d4865), X(0x55985f20), X(0x5f2bb2c5), - X(0x55bdb81f), X(0x5f0a0e77), X(0x55e303e6), X(0x5ee85b82), - X(0x5608426e), X(0x5ec699e9), X(0x562d73b2), X(0x5ea4c9b3), - X(0x565297ab), X(0x5e82eae5), X(0x5677ae54), X(0x5e60fd84), - X(0x569cb7a8), X(0x5e3f0194), X(0x56c1b3a1), X(0x5e1cf71c), - X(0x56e6a239), X(0x5dfade20), X(0x570b8369), X(0x5dd8b6a7), - X(0x5730572e), X(0x5db680b4), X(0x57551d80), X(0x5d943c4e), - X(0x5779d65b), X(0x5d71e979), X(0x579e81b8), X(0x5d4f883b), - X(0x57c31f92), X(0x5d2d189a), X(0x57e7afe4), X(0x5d0a9a9a), - X(0x580c32a7), X(0x5ce80e41), X(0x5830a7d6), X(0x5cc57394), - X(0x58550f6c), X(0x5ca2ca99), X(0x58796962), X(0x5c801354), - X(0x589db5b3), X(0x5c5d4dcc), X(0x58c1f45b), X(0x5c3a7a05), - X(0x58e62552), X(0x5c179806), X(0x590a4893), X(0x5bf4a7d2), - X(0x592e5e19), X(0x5bd1a971), X(0x595265df), X(0x5bae9ce7), - X(0x59765fde), X(0x5b8b8239), X(0x599a4c12), X(0x5b68596d), - X(0x59be2a74), X(0x5b452288), X(0x59e1faff), X(0x5b21dd90), - X(0x5a05bdae), X(0x5afe8a8b), X(0x5a29727b), X(0x5adb297d), - X(0x5a4d1960), X(0x5ab7ba6c), X(0x5a70b258), X(0x5a943d5e), -}; - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/misc.h --- a/misc/libtremor/misc.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: miscellaneous math and prototypes - - ********************************************************************/ - -#ifndef _V_RANDOM_H_ -#define _V_RANDOM_H_ -#include "ivorbiscodec.h" -#include "os.h" - -#include "asm_arm.h" -#include /* for abs() */ - -#ifndef _V_WIDE_MATH -#define _V_WIDE_MATH - -#ifndef _LOW_ACCURACY_ -/* 64 bit multiply */ - -#if !(defined WIN32 && defined WINCE) -#include -#endif - -#if BYTE_ORDER==LITTLE_ENDIAN -union magic { - struct { - ogg_int32_t lo; - ogg_int32_t hi; - } halves; - ogg_int64_t whole; -}; -#endif - -#if BYTE_ORDER==BIG_ENDIAN -union magic { - struct { - ogg_int32_t hi; - ogg_int32_t lo; - } halves; - ogg_int64_t whole; -}; -#endif - -STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { - union magic magic; - magic.whole = (ogg_int64_t)x * y; - return magic.halves.hi; -} - -STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { - return MULT32(x,y)<<1; -} - -STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { - union magic magic; - magic.whole = (ogg_int64_t)x * y; - return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); -} - -#else -/* 32 bit multiply, more portable but less accurate */ - -/* - * Note: Precision is biased towards the first argument therefore ordering - * is important. Shift values were chosen for the best sound quality after - * many listening tests. - */ - -/* - * For MULT32 and MULT31: The second argument is always a lookup table - * value already preshifted from 31 to 8 bits. We therefore take the - * opportunity to save on text space and use unsigned char for those - * tables in this case. - */ - -STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { - return (x >> 9) * y; /* y preshifted >>23 */ -} - -STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { - return (x >> 8) * y; /* y preshifted >>23 */ -} - -STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { - return (x >> 6) * y; /* y preshifted >>9 */ -} - -#endif - -/* - * This should be used as a memory barrier, forcing all cached values in - * registers to wr writen back to memory. Might or might not be beneficial - * depending on the architecture and compiler. - */ -#define MB() - -/* - * The XPROD functions are meant to optimize the cross products found all - * over the place in mdct.c by forcing memory operation ordering to avoid - * unnecessary register reloads as soon as memory is being written to. - * However this is only beneficial on CPUs with a sane number of general - * purpose registers which exclude the Intel x86. On Intel, better let the - * compiler actually reload registers directly from original memory by using - * macros. - */ - -#ifdef __i386__ - -#define XPROD32(_a, _b, _t, _v, _x, _y) \ - { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \ - *(_y)=MULT32(_b,_t)-MULT32(_a,_v); } -#define XPROD31(_a, _b, _t, _v, _x, _y) \ - { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \ - *(_y)=MULT31(_b,_t)-MULT31(_a,_v); } -#define XNPROD31(_a, _b, _t, _v, _x, _y) \ - { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \ - *(_y)=MULT31(_b,_t)+MULT31(_a,_v); } - -#else - -STIN 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) -{ - *x = MULT32(a, t) + MULT32(b, v); - *y = MULT32(b, t) - MULT32(a, v); -} - -STIN 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) -{ - *x = MULT31(a, t) + MULT31(b, v); - *y = MULT31(b, t) - MULT31(a, v); -} - -STIN 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) -{ - *x = MULT31(a, t) - MULT31(b, v); - *y = MULT31(b, t) + MULT31(a, v); -} - -#endif - -#endif - -#ifndef _V_CLIP_MATH -#define _V_CLIP_MATH - -STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) { - int ret=x; - ret-= ((x<=32767)-1)&(x-32767); - ret-= ((x>=-32768)-1)&(x+32768); - return(ret); -} - -#endif - -STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t b,ogg_int32_t bp, - ogg_int32_t *p){ - if(a && b){ -#ifndef _LOW_ACCURACY_ - *p=ap+bp+32; - return MULT32(a,b); -#else - *p=ap+bp+31; - return (a>>15)*(b>>16); -#endif - }else - return 0; -} - -int _ilog(unsigned int); - -STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t i, - ogg_int32_t *p){ - - int ip=_ilog(abs(i))-31; - return VFLOAT_MULT(a,ap,i<<-ip,ip,p); -} - -STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, - ogg_int32_t b,ogg_int32_t bp, - ogg_int32_t *p){ - - if(!a){ - *p=bp; - return b; - }else if(!b){ - *p=ap; - return a; - } - - /* yes, this can leak a bit. */ - if(ap>bp){ - int shift=ap-bp+1; - *p=ap+1; - a>>=1; - if(shift<32){ - b=(b+(1<<(shift-1)))>>shift; - }else{ - b=0; - } - }else{ - int shift=bp-ap+1; - *p=bp+1; - b>>=1; - if(shift<32){ - a=(a+(1<<(shift-1)))>>shift; - }else{ - a=0; - } - } - - a+=b; - if((a&0xc0000000)==0xc0000000 || - (a&0xc0000000)==0){ - a<<=1; - (*p)--; - } - return(a); -} - -#endif - - - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/ogg.h --- a/misc/libtremor/ogg.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: subsumed libogg includes - - ********************************************************************/ -#ifndef _OGG_H -#define _OGG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "os_types.h" - -typedef struct ogg_buffer_state{ - struct ogg_buffer *unused_buffers; - struct ogg_reference *unused_references; - int outstanding; - int shutdown; -} ogg_buffer_state; - -typedef struct ogg_buffer { - unsigned char *data; - long size; - int refcount; - - union { - ogg_buffer_state *owner; - struct ogg_buffer *next; - } ptr; -} ogg_buffer; - -typedef struct ogg_reference { - ogg_buffer *buffer; - long begin; - long length; - - struct ogg_reference *next; -} ogg_reference; - -typedef struct oggpack_buffer { - int headbit; - unsigned char *headptr; - long headend; - - /* memory management */ - ogg_reference *head; - ogg_reference *tail; - - /* render the byte/bit counter API constant time */ - long count; /* doesn't count the tail */ -} oggpack_buffer; - -typedef struct oggbyte_buffer { - ogg_reference *baseref; - - ogg_reference *ref; - unsigned char *ptr; - long pos; - long end; -} oggbyte_buffer; - -typedef struct ogg_sync_state { - /* decode memory management pool */ - ogg_buffer_state *bufferpool; - - /* stream buffers */ - ogg_reference *fifo_head; - ogg_reference *fifo_tail; - long fifo_fill; - - /* stream sync management */ - int unsynced; - int headerbytes; - int bodybytes; - -} ogg_sync_state; - -typedef struct ogg_stream_state { - ogg_reference *header_head; - ogg_reference *header_tail; - ogg_reference *body_head; - ogg_reference *body_tail; - - int e_o_s; /* set when we have buffered the last - packet in the logical bitstream */ - int b_o_s; /* set after we've written the initial page - of a logical bitstream */ - long serialno; - long pageno; - ogg_int64_t packetno; /* sequence number for decode; the framing - knows where there's a hole in the data, - but we need coupling so that the codec - (which is in a seperate abstraction - layer) also knows about the gap */ - ogg_int64_t granulepos; - - int lacing_fill; - ogg_uint32_t body_fill; - - /* decode-side state data */ - int holeflag; - int spanflag; - int clearflag; - int laceptr; - ogg_uint32_t body_fill_next; - -} ogg_stream_state; - -typedef struct { - ogg_reference *packet; - long bytes; - long b_o_s; - long e_o_s; - ogg_int64_t granulepos; - ogg_int64_t packetno; /* sequence number for decode; the framing - knows where there's a hole in the data, - but we need coupling so that the codec - (which is in a seperate abstraction - layer) also knows about the gap */ -} ogg_packet; - -typedef struct { - ogg_reference *header; - int header_len; - ogg_reference *body; - long body_len; -} ogg_page; - -/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ - -extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); -extern long oggpack_look(oggpack_buffer *b,int bits); -extern void oggpack_adv(oggpack_buffer *b,int bits); -extern long oggpack_read(oggpack_buffer *b,int bits); -extern long oggpack_bytes(oggpack_buffer *b); -extern long oggpack_bits(oggpack_buffer *b); -extern int oggpack_eop(oggpack_buffer *b); - -/* Ogg BITSTREAM PRIMITIVES: decoding **************************/ - -extern ogg_sync_state *ogg_sync_create(void); -extern int ogg_sync_destroy(ogg_sync_state *oy); -extern int ogg_sync_reset(ogg_sync_state *oy); - -extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); -extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); -extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); -extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); -extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); -extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); -extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); - -/* Ogg BITSTREAM PRIMITIVES: general ***************************/ - -extern ogg_stream_state *ogg_stream_create(int serialno); -extern int ogg_stream_destroy(ogg_stream_state *os); -extern int ogg_stream_reset(ogg_stream_state *os); -extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); -extern int ogg_stream_eos(ogg_stream_state *os); - -extern int ogg_page_checksum_set(ogg_page *og); - -extern int ogg_page_version(ogg_page *og); -extern int ogg_page_continued(ogg_page *og); -extern int ogg_page_bos(ogg_page *og); -extern int ogg_page_eos(ogg_page *og); -extern ogg_int64_t ogg_page_granulepos(ogg_page *og); -extern ogg_uint32_t ogg_page_serialno(ogg_page *og); -extern ogg_uint32_t ogg_page_pageno(ogg_page *og); -extern int ogg_page_packets(ogg_page *og); -extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); - -extern int ogg_packet_release(ogg_packet *op); -extern int ogg_page_release(ogg_page *og); - -extern void ogg_page_dup(ogg_page *d, ogg_page *s); - -/* Ogg BITSTREAM PRIMITIVES: return codes ***************************/ - -#define OGG_SUCCESS 0 - -#define OGG_HOLE -10 -#define OGG_SPAN -11 -#define OGG_EVERSION -12 -#define OGG_ESERIAL -13 -#define OGG_EINVAL -14 -#define OGG_EEOS -15 - - -#ifdef __cplusplus -} -#endif - -#endif /* _OGG_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/os.h --- a/misc/libtremor/os.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -#ifndef _OS_H -#define _OS_H -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: #ifdef jail to whip a few platforms into the UNIX ideal. - - ********************************************************************/ - -#include -#include "os_types.h" - -#ifndef _V_IFDEFJAIL_H_ -# define _V_IFDEFJAIL_H_ - -# ifdef __GNUC__ -# define STIN static __inline__ -# elif _WIN32 -# define STIN static __inline -# endif -#else -# define STIN static -#endif - -#ifndef M_PI -# define M_PI (3.1415926536f) -#endif - -#ifdef _WIN32 -# include -# define rint(x) (floor((x)+0.5f)) -# define NO_FLOAT_MATH_LIB -# define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) -# define LITTLE_ENDIAN 1 -# define BYTE_ORDER LITTLE_ENDIAN -#endif - -#ifdef HAVE_ALLOCA_H -# include -#endif - -#ifdef USE_MEMORY_H -# include -#endif - -#ifndef min -# define min(x,y) ((x)>(y)?(y):(x)) -#endif - -#ifndef max -# define max(x,y) ((x)<(y)?(y):(x)) -#endif - -#endif /* _OS_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/os_types.h --- a/misc/libtremor/os_types.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: #ifdef jail to whip a few platforms into the UNIX ideal. - - ********************************************************************/ -#ifndef _OS_TYPES_H -#define _OS_TYPES_H - -#ifdef _LOW_ACCURACY_ -# define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9)) -# define LOOKUP_T const unsigned char -#else -# define X(n) (n) -# define LOOKUP_T const ogg_int32_t -#endif - -/* make it easy on the folks that want to compile the libs with a - different malloc than stdlib */ -#define _ogg_malloc malloc -#define _ogg_calloc calloc -#define _ogg_realloc realloc -#define _ogg_free free - -#ifdef _WIN32 - -# ifndef __GNUC__ - /* MSVC/Borland */ - typedef __int64 ogg_int64_t; - typedef __int32 ogg_int32_t; - typedef unsigned __int32 ogg_uint32_t; - typedef __int16 ogg_int16_t; -# else - /* Cygwin */ - #include <_G_config.h> - typedef _G_int64_t ogg_int64_t; - typedef _G_int32_t ogg_int32_t; - typedef _G_uint32_t ogg_uint32_t; - typedef _G_int16_t ogg_int16_t; -# endif - -#elif defined(__MACOS__) - -# include - typedef SInt16 ogg_int16_t; - typedef SInt32 ogg_int32_t; - typedef UInt32 ogg_uint32_t; - typedef SInt64 ogg_int64_t; - -#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ - -# include - typedef int16_t ogg_int16_t; - typedef int32_t ogg_int32_t; - typedef u_int32_t ogg_uint32_t; - typedef int64_t ogg_int64_t; - -#elif defined(__BEOS__) - - /* Be */ -# include - -#elif defined (__EMX__) - - /* OS/2 GCC */ - typedef short ogg_int16_t; - typedef int ogg_int32_t; - typedef unsigned int ogg_uint32_t; - typedef long long ogg_int64_t; - -#else - -# include -# include "config_types.h" - -#endif - -#endif /* _OS_TYPES_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/registry.c --- a/misc/libtremor/registry.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: registry for floor, res backends and channel mappings - - ********************************************************************/ - -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "registry.h" -#include "misc.h" - - -/* seems like major overkill now; the backend numbers will grow into - the infrastructure soon enough */ - -extern vorbis_func_floor floor0_exportbundle; -extern vorbis_func_floor floor1_exportbundle; -extern vorbis_func_residue residue0_exportbundle; -extern vorbis_func_residue residue1_exportbundle; -extern vorbis_func_residue residue2_exportbundle; -extern vorbis_func_mapping mapping0_exportbundle; - -vorbis_func_floor *_floor_P[]={ - &floor0_exportbundle, - &floor1_exportbundle, -}; - -vorbis_func_residue *_residue_P[]={ - &residue0_exportbundle, - &residue1_exportbundle, - &residue2_exportbundle, -}; - -vorbis_func_mapping *_mapping_P[]={ - &mapping0_exportbundle, -}; - - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/registry.h --- a/misc/libtremor/registry.h Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: registry for time, floor, res backends and channel mappings - - ********************************************************************/ - -#ifndef _V_REG_H_ -#define _V_REG_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 - -#include "backends.h" - -#if defined(_WIN32) && defined(VORBISDLL_IMPORT) -# define EXTERN __declspec(dllimport) extern -#else -# define EXTERN extern -#endif - -EXTERN vorbis_func_floor *_floor_P[]; -EXTERN vorbis_func_residue *_residue_P[]; -EXTERN vorbis_func_mapping *_mapping_P[]; - -#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/res012.c --- a/misc/libtremor/res012.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,342 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: residue backend 0, 1 and 2 implementation - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "registry.h" -#include "codebook.h" -#include "misc.h" -#include "os.h" -#include "block.h" - -typedef struct { - vorbis_info_residue0 *info; - int map; - - int parts; - int stages; - codebook *fullbooks; - codebook *phrasebook; - codebook ***partbooks; - - int partvals; - int **decodemap; - -} vorbis_look_residue0; - -void res0_free_info(vorbis_info_residue *i){ - vorbis_info_residue0 *info=(vorbis_info_residue0 *)i; - if(info){ - memset(info,0,sizeof(*info)); - _ogg_free(info); - } -} - -void res0_free_look(vorbis_look_residue *i){ - int j; - if(i){ - - vorbis_look_residue0 *look=(vorbis_look_residue0 *)i; - - for(j=0;jparts;j++) - if(look->partbooks[j])_ogg_free(look->partbooks[j]); - _ogg_free(look->partbooks); - for(j=0;jpartvals;j++) - _ogg_free(look->decodemap[j]); - _ogg_free(look->decodemap); - - memset(look,0,sizeof(*look)); - _ogg_free(look); - } -} - -static int ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -static int icount(unsigned int v){ - int ret=0; - while(v){ - ret+=v&1; - v>>=1; - } - return(ret); -} - -/* vorbis_info is for range checking */ -vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ - int j,acc=0; - vorbis_info_residue0 *info=(vorbis_info_residue0 *)_ogg_calloc(1,sizeof(*info)); - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - - info->begin=oggpack_read(opb,24); - info->end=oggpack_read(opb,24); - info->grouping=oggpack_read(opb,24)+1; - info->partitions=oggpack_read(opb,6)+1; - info->groupbook=oggpack_read(opb,8); - - for(j=0;jpartitions;j++){ - int cascade=oggpack_read(opb,3); - if(oggpack_read(opb,1)) - cascade|=(oggpack_read(opb,5)<<3); - info->secondstages[j]=cascade; - - acc+=icount(cascade); - } - for(j=0;jbooklist[j]=oggpack_read(opb,8); - - if(info->groupbook>=ci->books)goto errout; - for(j=0;jbooklist[j]>=ci->books)goto errout; - - return(info); - errout: - res0_free_info(info); - return(NULL); -} - -vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, - vorbis_info_residue *vr){ - vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; - vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look)); - codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; - - int j,k,acc=0; - int dim; - int maxstage=0; - look->info=info; - look->map=vm->mapping; - - look->parts=info->partitions; - look->fullbooks=ci->fullbooks; - look->phrasebook=ci->fullbooks+info->groupbook; - dim=look->phrasebook->dim; - - look->partbooks=(codebook ***)_ogg_calloc(look->parts,sizeof(*look->partbooks)); - - for(j=0;jparts;j++){ - int stages=ilog(info->secondstages[j]); - if(stages){ - if(stages>maxstage)maxstage=stages; - look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j])); - for(k=0;ksecondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; -#ifdef TRAIN_RES - look->training_data[k][j]=calloc(look->partbooks[j][k]->entries, - sizeof(***look->training_data)); -#endif - } - } - } - - look->partvals=look->parts; - for(j=1;jpartvals*=look->parts; - look->stages=maxstage; - look->decodemap=(int **)_ogg_malloc(look->partvals*sizeof(*look->decodemap)); - for(j=0;jpartvals;j++){ - long val=j; - long mult=look->partvals/look->parts; - look->decodemap[j]=(int *)_ogg_malloc(dim*sizeof(*look->decodemap[j])); - for(k=0;kparts; - look->decodemap[j][k]=deco; - } - } - - return(look); -} - - -/* a truncated packet here just means 'stop working'; it's not an error */ -static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, - ogg_int32_t **in,int ch, - long (*decodepart)(codebook *, ogg_int32_t *, - oggpack_buffer *,int,int)){ - - long i,j,k,l,s; - vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; - vorbis_info_residue0 *info=look->info; - - /* move all this setup out later */ - int samples_per_partition=info->grouping; - int partitions_per_word=look->phrasebook->dim; - int max=vb->pcmend>>1; - int end=(info->endend:max); - int n=end-info->begin; - - if(n>0){ - int partvals=n/samples_per_partition; - int partwords=(partvals+partitions_per_word-1)/partitions_per_word; - int ***partword=(int ***)alloca(ch*sizeof(*partword)); - - for(j=0;jstages;s++){ - - /* each loop decodes on partition codeword containing - partitions_pre_word partitions */ - for(i=0,l=0;iphrasebook,&vb->opb); - if(temp==-1)goto eopbreak; - partword[j][l]=look->decodemap[temp]; - if(partword[j][l]==NULL)goto errout; - } - } - - /* now we decode residual values for the partitions */ - for(k=0;kbegin+i*samples_per_partition; - if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; - if(stagebook){ - if(decodepart(stagebook,in[j]+offset,&vb->opb, - samples_per_partition,-8)==-1)goto eopbreak; - } - } - } - } - } - } - errout: - eopbreak: - return(0); -} - -int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl, - ogg_int32_t **in,int *nonzero,int ch){ - int i,used=0; - for(i=0;iinfo; - - /* move all this setup out later */ - int samples_per_partition=info->grouping; - int partitions_per_word=look->phrasebook->dim; - int max=(vb->pcmend*ch)>>1; - int end=(info->endend:max); - int n=end-info->begin; - - if(n>0){ - - int partvals=n/samples_per_partition; - int partwords=(partvals+partitions_per_word-1)/partitions_per_word; - int **partword=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword)); - int beginoff=info->begin/ch; - - for(i=0;istages;s++){ - for(i=0,l=0;iphrasebook,&vb->opb); - if(temp==-1)goto eopbreak; - partword[l]=look->decodemap[temp]; - if(partword[l]==NULL)goto errout; - } - - /* now we decode residual values for the partitions */ - for(k=0;ksecondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; - - if(stagebook){ - if(vorbis_book_decodevv_add(stagebook,in, - i*samples_per_partition+beginoff,ch, - &vb->opb, - samples_per_partition,-8)==-1) - goto eopbreak; - } - } - } - } - } - errout: - eopbreak: - return(0); -} - - -vorbis_func_residue residue0_exportbundle={ - &res0_unpack, - &res0_look, - &res0_free_info, - &res0_free_look, - &res0_inverse -}; - -vorbis_func_residue residue1_exportbundle={ - &res0_unpack, - &res0_look, - &res0_free_info, - &res0_free_look, - &res1_inverse -}; - -vorbis_func_residue residue2_exportbundle={ - &res0_unpack, - &res0_look, - &res0_free_info, - &res0_free_look, - &res2_inverse -}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/sharedbook.c --- a/misc/libtremor/sharedbook.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,439 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: basic shared codebook operations - - ********************************************************************/ - -#include -#include -#include -#include "ogg.h" -#include "misc.h" -#include "ivorbiscodec.h" -#include "codebook.h" - -/**** pack/unpack helpers ******************************************/ -int _ilog(unsigned int v){ - int ret=0; - while(v){ - ret++; - v>>=1; - } - return(ret); -} - -/* 32 bit float (not IEEE; nonnormalized mantissa + - biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm - Why not IEEE? It's just not that important here. */ - -#define VQ_FEXP 10 -#define VQ_FMAN 21 -#define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */ - -static ogg_int32_t _float32_unpack(long val,int *point){ - long mant=val&0x1fffff; - int sign=val&0x80000000; - long exp =(val&0x7fe00000L)>>VQ_FMAN; - - exp-=(VQ_FMAN-1)+VQ_FEXP_BIAS; - - if(mant){ - while(!(mant&0x40000000)){ - mant<<=1; - exp-=1; - } - - if(sign)mant= -mant; - }else{ - sign=0; - exp=-9999; - } - - *point=exp; - return mant; -} - -/* given a list of word lengths, generate a list of codewords. Works - for length ordered or unordered, always assigns the lowest valued - codewords first. Extended to handle unused entries (length 0) */ -ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ - long i,j,count=0; - ogg_uint32_t marker[33]; - ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); - memset(marker,0,sizeof(marker)); - - for(i=0;i0){ - ogg_uint32_t entry=marker[length]; - - /* when we claim a node for an entry, we also claim the nodes - below it (pruning off the imagined tree that may have dangled - from it) as well as blocking the use of any nodes directly - above for leaves */ - - /* update ourself */ - if(length<32 && (entry>>length)){ - /* error condition; the lengths must specify an overpopulated tree */ - _ogg_free(r); - return(NULL); - } - r[count++]=entry; - - /* 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){ - /* have to jump branches */ - if(j==1) - marker[1]++; - else - marker[j]=marker[j-1]<<1; - break; /* invariant says next upper marker would already - have been moved if it was on the same path */ - } - 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<33;j++) - if((marker[j]>>1) == entry){ - entry=marker[j]; - marker[j]=marker[j-1]<<1; - }else - break; - }else - if(sparsecount==0)count++; - } - - /* bitreverse the words because our bitwise packer/unpacker is LSb - endian */ - for(i=0,count=0;i>j)&1; - } - - if(sparsecount){ - if(l[i]) - r[count++]=temp; - }else - r[count++]=temp; - } - - return(r); -} - -/* 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(const static_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;idim;i++){ - acc*=vals; - acc1*=vals+1; - } - if(acc<=b->entries && acc1>b->entries){ - return(vals); - }else{ - if(acc>b->entries){ - vals--; - }else{ - vals++; - } - } - } -} - -/* different than what _book_unquantize does for mainline: - we repack the book in a fixed point format that shares the same - binary point. Upon first use, we can shift point if needed */ - -/* we need to deal with two map types: in map type 1, the values are - generated algorithmically (each column of the vector counts through - the values in the quant vector). in map type 2, all the values came - in in an explicit list. Both value lists must be unpacked */ - -ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, - int *maxpoint){ - long j,k,count=0; - if(b->maptype==1 || b->maptype==2){ - int quantvals; - int minpoint,delpoint; - ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); - ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); - ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); - int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); - - *maxpoint=minpoint; - - /* maptype 1 and 2 both use a quantized value vector, but - different sizes */ - switch(b->maptype){ - case 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*dimentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - ogg_int32_t last=0; - int lastpoint=0; - int indexdiv=1; - for(k=0;kdim;k++){ - int index= (j/indexdiv)%quantvals; - int point=0; - int val=VFLOAT_MULTI(delta,delpoint, - abs(b->quantlist[index]),&point); - - val=VFLOAT_ADD(mindel,minpoint,val,point,&point); - val=VFLOAT_ADD(last,lastpoint,val,point,&point); - - if(b->q_sequencep){ - last=val; - lastpoint=point; - } - - if(sparsemap){ - r[sparsemap[count]*b->dim+k]=val; - rp[sparsemap[count]*b->dim+k]=point; - }else{ - r[count*b->dim+k]=val; - rp[count*b->dim+k]=point; - } - if(*maxpointentries;j++){ - if((sparsemap && b->lengthlist[j]) || !sparsemap){ - ogg_int32_t last=0; - int lastpoint=0; - - for(k=0;kdim;k++){ - int point=0; - int val=VFLOAT_MULTI(delta,delpoint, - abs(b->quantlist[j*b->dim+k]),&point); - - val=VFLOAT_ADD(mindel,minpoint,val,point,&point); - val=VFLOAT_ADD(last,lastpoint,val,point,&point); - - if(b->q_sequencep){ - last=val; - lastpoint=point; - } - - if(sparsemap){ - r[sparsemap[count]*b->dim+k]=val; - rp[sparsemap[count]*b->dim+k]=point; - }else{ - r[count*b->dim+k]=val; - rp[count*b->dim+k]=point; - } - if(*maxpointdim;j++) - if(rp[j]<*maxpoint) - r[j]>>=*maxpoint-rp[j]; - - _ogg_free(rp); - return(r); - } - return(NULL); -} - -void vorbis_staticbook_clear(static_codebook *b){ - if(b->quantlist)_ogg_free(b->quantlist); - if(b->lengthlist)_ogg_free(b->lengthlist); - memset(b,0,sizeof(*b)); - -} - -void vorbis_staticbook_destroy(static_codebook *b){ - vorbis_staticbook_clear(b); - _ogg_free(b); -} - -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->valuelist)_ogg_free(b->valuelist); - if(b->codelist)_ogg_free(b->codelist); - - if(b->dec_index)_ogg_free(b->dec_index); - if(b->dec_codelengths)_ogg_free(b->dec_codelengths); - if(b->dec_firsttable)_ogg_free(b->dec_firsttable); - - memset(b,0,sizeof(*b)); -} - -static ogg_uint32_t bitreverse(ogg_uint32_t x){ - x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL); - x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL); - x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL); - x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL); - return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL); -} - -static int sort32a(const void *a,const void *b){ - return (**(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- - (**(ogg_uint32_t **)a<**(ogg_uint32_t **)b); -} - -/* decode codebook arrangement is more heavily optimized than encode */ -int vorbis_book_init_decode(codebook *c,const static_codebook *s){ - int i,j,n=0,tabn; - int *sortindex; - memset(c,0,sizeof(*c)); - - /* count actually used entries */ - for(i=0;ientries;i++) - if(s->lengthlist[i]>0) - n++; - - c->entries=s->entries; - c->used_entries=n; - c->dim=s->dim; - - if(n>0){ - /* two different remappings go on here. - - First, we collapse the likely sparse codebook down only to - actually represented values/words. This collapsing needs to be - indexed as map-valueless books are used to encode original entry - positions as integers. - - Second, we reorder all vectors, including the entry index above, - by sorted bitreversed codeword to allow treeless decode. */ - - /* perform sort */ - ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); - ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); - - if(codes==NULL)goto err_out; - - for(i=0;icodelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); - /* the index is a reverse index */ - for(i=0;icodelist[sortindex[i]]=codes[i]; - _ogg_free(codes); - - - - c->valuelist=_book_unquantize(s,n,sortindex,&c->binarypoint); - c->dec_index=(int *)_ogg_malloc(n*sizeof(*c->dec_index)); - - for(n=0,i=0;ientries;i++) - if(s->lengthlist[i]>0) - c->dec_index[sortindex[n++]]=i; - - c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths)); - for(n=0,i=0;ientries;i++) - if(s->lengthlist[i]>0) - c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; - - c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ - if(c->dec_firsttablen<5)c->dec_firsttablen=5; - if(c->dec_firsttablen>8)c->dec_firsttablen=8; - - tabn=1<dec_firsttablen; - c->dec_firsttable=(ogg_uint32_t *)_ogg_calloc(tabn,sizeof(*c->dec_firsttable)); - c->dec_maxlength=0; - - for(i=0;idec_maxlengthdec_codelengths[i]) - c->dec_maxlength=c->dec_codelengths[i]; - if(c->dec_codelengths[i]<=c->dec_firsttablen){ - ogg_uint32_t orig=bitreverse(c->codelist[i]); - for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) - c->dec_firsttable[orig|(j<dec_codelengths[i])]=i+1; - } - } - - /* now fill in 'unused' entries in the firsttable with hi/lo search - hints for the non-direct-hits */ - { - ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen); - long lo=0,hi=0; - - for(i=0;idec_firsttablen); - if(c->dec_firsttable[bitreverse(word)]==0){ - while((lo+1)codelist[lo+1]<=word)lo++; - while( hi=(c->codelist[hi]&mask))hi++; - - /* we only actually have 15 bits per hint to play with here. - In order to overflow gracefully (nothing breaks, efficiency - just drops), encode as the difference from the extremes. */ - { - unsigned long loval=lo; - unsigned long hival=n-hi; - - if(loval>0x7fff)loval=0x7fff; - if(hival>0x7fff)hival=0x7fff; - c->dec_firsttable[bitreverse(word)]= - 0x80000000UL | (loval<<15) | hival; - } - } - } - } - } - - return(0); - err_out: - vorbis_book_clear(c); - return(-1); -} - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/synthesis.c --- a/misc/libtremor/synthesis.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: single-block PCM synthesis - last mod: $Id: synthesis.c,v 1.4 2003/03/29 03:07:21 xiphmont Exp $ - - ********************************************************************/ - -#include -#include "ogg.h" -#include "ivorbiscodec.h" -#include "codec_internal.h" -#include "registry.h" -#include "misc.h" -#include "block.h" - -int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){ - vorbis_dsp_state *vd=vb->vd; - private_state *b=(private_state *)vd->backend_state; - vorbis_info *vi=vd->vi; - codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; - oggpack_buffer *opb=&vb->opb; - int type,mode,i; - - /* first things first. Make sure decode is ready */ - _vorbis_block_ripcord(vb); - 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); - } - - /* read our mode and pre/post windowsize */ - mode=oggpack_read(opb,b->modebits); - if(mode==-1)return(OV_EBADPACKET); - - vb->mode=mode; - vb->W=ci->mode_param[mode]->blockflag; - if(vb->W){ - vb->lW=oggpack_read(opb,1); - vb->nW=oggpack_read(opb,1); - if(vb->nW==-1) return(OV_EBADPACKET); - }else{ - vb->lW=0; - vb->nW=0; - } - - /* more setup */ - vb->granulepos=op->granulepos; - vb->sequence=op->packetno-3; /* first block is third packet */ - vb->eofflag=op->e_o_s; - - if(decodep){ - /* alloc pcm passback storage */ - vb->pcmend=ci->blocksizes[vb->W]; - vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); - for(i=0;ichannels;i++) - vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); - - /* unpack_header enforces range checking */ - type=ci->map_type[ci->mode_param[mode]->mapping]; - - return(_mapping_P[type]->inverse(vb,b->mode[mode])); - }else{ - /* no pcm */ - vb->pcmend=0; - vb->pcm=NULL; - - 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; - - 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); - } - - { - int modebits=0; - int v=ci->modes; - 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]); -} - - diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/CHANGELOG --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/CHANGELOG Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,19 @@ +*** 20020517: 1.0.2 *** + + Playback bugfix to floor1; mode mistakenly used for sizing instead + of blockflag + +*** 20020515: 1.0.1 *** + + Added complete API documentation to source tarball. No code + changes. + +*** 20020412: 1.0.1 *** + + Fixed a clipping bug that affected ARM processors; negative + overflows were being properly clipped, but then clobbered to + positive by the positive overflow chec (asm_arm.h:CLIP_TO_15) + +*** 20020403: 1.0.0 *** + + Initial version \ No newline at end of file diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/COPYING --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/COPYING Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,28 @@ +Copyright (c) 2002, Xiph.org Foundation + +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 name of the Xiph.org Foundation 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 FOUNDATION +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. diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/Makefile.am Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,38 @@ +AUTOMAKE_OPTIONS = foreign + +INCLUDES = -I./ + +lib_LTLIBRARIES = libvorbisidec.la + +libvorbisidec_la_SOURCES = mdct.c block.c window.c \ + synthesis.c info.c \ + floor1.c floor0.c vorbisfile.c \ + res012.c mapping0.c registry.c codebook.c \ + sharedbook.c framing.c bitwise.c \ + codebook.h misc.h mdct_lookup.h\ + os.h mdct.h block.h ivorbisfile.h lsp_lookup.h\ + registry.h window.h window_lookup.h\ + codec_internal.h backends.h ogg.h \ + asm_arm.h ivorbiscodec.h +libvorbisidec_la_LDFLAGS = -version-info @V_LIB_CURRENT@:@V_LIB_REVISION@:@V_LIB_AGE@ + +EXTRA_PROGRAMS = ivorbisfile_example +CLEANFILES = $(EXTRA_PROGRAMS) $(lib_LTLIBRARIES) + +ivorbisfile_example_SOURCES = ivorbisfile_example.c +ivorbisfile_example_LDFLAGS = -static +ivorbisfile_example_LDADD = libvorbisidec.la + +includedir = $(prefix)/include/tremor + +include_HEADERS = ivorbiscodec.h ivorbisfile.h ogg.h os_types.h config_types.h + +example: + -ln -fs . vorbis + $(MAKE) ivorbisfile_example + +debug: + $(MAKE) all CFLAGS="@DEBUG@" + +profile: + $(MAKE) all CFLAGS="@PROFILE@" diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/README Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,46 @@ +This README covers the Ogg Vorbis 'Tremor' integer playback codec +source as of date 2002 09 02, version 1.0.0. + + ****** + +The C source in this package will build on any ANSI C compiler and +function completely and properly on any platform. The included build +system assumes GNU build system and make tools (m4, automake, +autoconf, libtool and gmake). GCC is not required, although GCC is +the most tested compiler. To build using GNU tools, type in the +source directory: + +./autogen.sh +make + +Currently, the source implements playback in pure C on all platforms +except ARM, where a [currently] small amount of assembly (see +asm_arm.h) is used to implement 64 bit math operations and fast LSP +computation. If building on ARM without the benefit of GNU build +system tools, be sure that '_ARM_ASSEM_' is #defined by the build +system if this assembly is desired, else the resulting library will +use whatever 64 bit math builtins the compiler implements. + +No math library is required by this source. No floating point +operations are used at any point in either setup or decode. This +decoder library will properly decode any past, current or future +Vorbis I file or stream. + + ******** + +The build system produces a static and [when supported by the OS] +dynamic library named 'libvorbisidec'. This library exposes an API +nearly identical to the BSD reference library's 'libvorbisfile', +including all the features familiar to users of vorbisfile. This API +is similar enough that the proper header file to include is named +'ivorbisfile.h' [included in the source build directory]. Lower level +libvorbis-style headers and structures are in 'ivorbiscodec.h' +[included in the source build directory]. A simple example program, +ivorbisfile_example.c, can be built with 'make example'. + + ******** + +Detailed Tremor API Documentation begins at doc/index.html + +Monty +xiph.org diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/Version_script.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/Version_script.in Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,49 @@ +# +# Export file for libvorbisidec +# +# Only the symbols listed in the global section will be callable from +# applications linking to libvorbisidec. +# + +@PACKAGE@.so.1 +{ + global: + ov_clear; + ov_open; + ov_open_callbacks; + ov_test; + ov_test_callbacks; + ov_test_open; + ov_bitrate; + ov_bitrate_instant; + ov_streams; + ov_seekable; + ov_serialnumber; + ov_raw_total; + ov_pcm_total; + ov_time_total; + ov_raw_seek; + ov_pcm_seek; + ov_pcm_seek_page; + ov_time_seek; + ov_time_seek_page; + ov_raw_tell; + ov_pcm_tell; + ov_time_tell; + ov_info; + ov_comment; + ov_read; + + vorbis_info_init; + vorbis_info_clear; + vorbis_info_blocksize; + vorbis_comment_init; + vorbis_comment_add; + vorbis_comment_add_tag; + vorbis_comment_query; + vorbis_comment_query_count; + vorbis_comment_clear; + + local: + *; +}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/asm_arm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/asm_arm.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,243 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + 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; +} + +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; +} + +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 + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/autogen.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/autogen.sh Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,120 @@ +#!/bin/sh +# Run this to set up the build system: configure, makefiles, etc. +# (based on the version in enlightenment's cvs) + +package="vorbisdec" + +olddir=`pwd` +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +cd "$srcdir" +DIE=0 + +echo "checking for autoconf... " +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $package." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +VERSIONGREP="sed -e s/.*[^0-9\.]\([0-9]\.[0-9]\).*/\1/" +VERSIONMKINT="sed -e s/[^0-9]//" + +# do we need automake? +if test -r Makefile.am; then + AM_OPTIONS=`fgrep AUTOMAKE_OPTIONS Makefile.am` + AM_NEEDED=`echo $AM_OPTIONS | $VERSIONGREP` + if test x"$AM_NEEDED" = "x$AM_OPTIONS"; then + AM_NEEDED="" + fi + if test -z $AM_NEEDED; then + echo -n "checking for automake... " + AUTOMAKE=automake + ACLOCAL=aclocal + if ($AUTOMAKE --version < /dev/null > /dev/null 2>&1); then + echo "yes" + else + echo "no" + AUTOMAKE= + fi + else + echo -n "checking for automake $AM_NEEDED or later... " + for am in automake-$AM_NEEDED automake$AM_NEEDED automake; do + ($am --version < /dev/null > /dev/null 2>&1) || continue + ver=`$am --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT` + verneeded=`echo $AM_NEEDED | $VERSIONMKINT` + if test $ver -ge $verneeded; then + AUTOMAKE=$am + echo $AUTOMAKE + break + fi + done + test -z $AUTOMAKE && echo "no" + echo -n "checking for aclocal $AM_NEEDED or later... " + for ac in aclocal-$AM_NEEDED aclocal$AM_NEEDED aclocal; do + ($ac --version < /dev/null > /dev/null 2>&1) || continue + ver=`$ac --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT` + verneeded=`echo $AM_NEEDED | $VERSIONMKINT` + if test $ver -ge $verneeded; then + ACLOCAL=$ac + echo $ACLOCAL + break + fi + done + test -z $ACLOCAL && echo "no" + fi + test -z $AUTOMAKE || test -z $ACLOCAL && { + echo + echo "You must have automake installed to compile $package." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + exit 1 + } +fi + +echo -n "checking for libtool... " +for LIBTOOLIZE in libtoolize glibtoolize nope; do + ($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 && break +done +if test x$LIBTOOLIZE = xnope; then + echo "nope." + LIBTOOLIZE=libtoolize +else + echo $LIBTOOLIZE +fi +($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtool installed to compile $package." + echo "Download the appropriate package for your system," + echo "or get the source from one of the GNU ftp sites" + echo "listed in http://www.gnu.org/order/ftp.html" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +echo "Generating configuration files for $package, please wait...." + +echo " $ACLOCAL $ACLOCAL_FLAGS" +$ACLOCAL $ACLOCAL_FLAGS || exit 1 +echo " $LIBTOOLIZE --automake" +$LIBTOOLIZE --automake || exit 1 +echo " autoheader" +autoheader || exit 1 +echo " $AUTOMAKE --add-missing $AUTOMAKE_FLAGS" +$AUTOMAKE --add-missing $AUTOMAKE_FLAGS || exit 1 +echo " autoconf" +autoconf || exit 1 + +cd $olddir +$srcdir/configure --enable-maintainer-mode "$@" && echo diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/backends.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/backends.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,130 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: backend and mapping structures + + ********************************************************************/ + +/* this is exposed up here because we need it for static modes. + Lookups for each backend aren't exposed because there's no reason + to do so */ + +#ifndef _vorbis_backend_h_ +#define _vorbis_backend_h_ + +#include "codec_internal.h" + +/* this would all be simpler/shorter with templates, but.... */ +/* Transform backend generic *************************************/ + +/* only mdct right now. Flesh it out more if we ever transcend mdct + in the transform domain */ + +/* Floor backend generic *****************************************/ +typedef struct{ + vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *); + vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_mode *, + vorbis_info_floor *); + void (*free_info) (vorbis_info_floor *); + void (*free_look) (vorbis_look_floor *); + void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *); + int (*inverse2) (struct vorbis_block *,vorbis_look_floor *, + void *buffer,ogg_int32_t *); +} vorbis_func_floor; + +typedef struct{ + int order; + long rate; + long barkmap; + + int ampbits; + int ampdB; + + int numbooks; /* <= 16 */ + int books[16]; + +} vorbis_info_floor0; + +#define VIF_POSIT 63 +#define VIF_CLASS 16 +#define VIF_PARTS 31 +typedef struct{ + int partitions; /* 0 to 31 */ + int partitionclass[VIF_PARTS]; /* 0 to 15 */ + + int class_dim[VIF_CLASS]; /* 1 to 8 */ + int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1< +#include +#include "ogg.h" + +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 }; + +/* mark read process as having run off the end */ +static void _adv_halt(oggpack_buffer *b){ + b->headptr=b->head->buffer->data+b->head->begin+b->head->length; + b->headend=-1; + b->headbit=0; +} + +/* 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<1){ + if(b->head->next){ + b->count+=b->head->length; + b->head=b->head->next; + 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<0 || b->headbit) + /* read has fallen off the end */ + _adv_halt(b); + + break; + } + } +} + +void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){ + memset(b,0,sizeof(*b)); + + b->tail=b->head=r; + b->count=0; + b->headptr=b->head->buffer->data+b->head->begin; + b->headend=b->head->length; + _span(b); +} + +#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=-1; + + 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 -1; + + 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; + return ret; +} + +/* limited to 32 at a time */ +void oggpack_adv(oggpack_buffer *b,int bits){ + bits+=b->headbit; + b->headbit=bits&7; + b->headptr+=bits/8; + if((b->headend-=bits/8)<1)_span(b); +} + +/* spans forward and finds next byte. Never halts */ +static void _span_one(oggpack_buffer *b){ + while(b->headend<1){ + if(b->head->next){ + b->count+=b->head->length; + b->head=b->head->next; + b->headptr=b->head->buffer->data+b->head->begin; + b->headend=b->head->length; + }else + break; + } +} + +static int _halt_one(oggpack_buffer *b){ + if(b->headend<1){ + _adv_halt(b); + return -1; + } + return 0; +} + +int oggpack_eop(oggpack_buffer *b){ + if(b->headend<0)return -1; + return 0; +} + +/* bits <= 32 */ +long oggpack_read(oggpack_buffer *b,int bits){ + unsigned long m=mask[bits]; + ogg_uint32_t ret=-1; + + bits+=b->headbit; + + if(bits >= b->headend<<3){ + + if(b->headend<0)return -1; + + if(bits){ + if (_halt_one(b)) return -1; + ret=*b->headptr>>b->headbit; + + if(bits>=8){ + ++b->headptr; + --b->headend; + _span_one(b); + if(bits>8){ + if (_halt_one(b)) return -1; + ret|=*b->headptr<<(8-b->headbit); + + if(bits>=16){ + ++b->headptr; + --b->headend; + _span_one(b); + if(bits>16){ + if (_halt_one(b)) return -1; + ret|=*b->headptr<<(16-b->headbit); + + if(bits>=24){ + ++b->headptr; + --b->headend; + _span_one(b); + if(bits>24){ + if (_halt_one(b)) return -1; + ret|=*b->headptr<<(24-b->headbit); + + if(bits>=32){ + ++b->headptr; + --b->headend; + _span_one(b); + if(bits>32){ + if (_halt_one(b)) return -1; + if(b->headbit)ret|=*b->headptr<<(32-b->headbit); + + } + } + } + } + } + } + } + } + } + }else{ + + 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); + } + } + } + } + + b->headptr+=bits/8; + b->headend-=bits/8; + } + + ret&=m; + b->headbit=bits&7; + return ret; +} + +long oggpack_bytes(oggpack_buffer *b){ + return(b->count+b->headptr-b->head->buffer->data-b->head->begin+ + (b->headbit+7)/8); +} + +long oggpack_bits(oggpack_buffer *b){ + return((b->count+b->headptr-b->head->buffer->data-b->head->begin)*8+ + b->headbit); +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/block.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/block.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,453 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: PCM data vector blocking, windowing and dis/reassembly + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" + +#include "window.h" +#include "registry.h" +#include "misc.h" + +static int ilog(unsigned int v){ + int ret=0; + if(v)--v; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +/* pcm accumulator examples (not exhaustive): + + <-------------- lW ----------------> + <--------------- W ----------------> +: .....|..... _______________ | +: .''' | '''_--- | |\ | +:.....''' |_____--- '''......| | \_______| +:.................|__________________|_______|__|______| + |<------ Sl ------>| > Sr < |endW + |beginSl |endSl | |endSr + |beginW |endlW |beginSr + + + |< lW >| + <--------------- W ----------------> + | | .. ______________ | + | | ' `/ | ---_ | + |___.'___/`. | ---_____| + |_______|__|_______|_________________| + | >|Sl|< |<------ Sr ----->|endW + | | |endSl |beginSr |endSr + |beginW | |endlW + mult[0] |beginSl mult[n] + + <-------------- lW -----------------> + |<--W-->| +: .............. ___ | | +: .''' |`/ \ | | +:.....''' |/`....\|...| +:.........................|___|___|___| + |Sl |Sr |endW + | | |endSr + | |beginSr + | |endSl + |beginSl + |beginW +*/ + +/* block abstraction setup *********************************************/ + +#ifndef WORD_ALIGN +#define WORD_ALIGN 8 +#endif + +int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){ + memset(vb,0,sizeof(*vb)); + vb->vd=v; + vb->localalloc=0; + vb->localstore=NULL; + + return(0); +} + +void *_vorbis_block_alloc(vorbis_block *vb,long bytes){ + bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1); + if(bytes+vb->localtop>vb->localalloc){ + /* can't just _ogg_realloc... there are outstanding pointers */ + if(vb->localstore){ + struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link)); + vb->totaluse+=vb->localtop; + link->next=vb->reap; + link->ptr=vb->localstore; + vb->reap=link; + } + /* highly conservative */ + vb->localalloc=bytes; + vb->localstore=_ogg_malloc(vb->localalloc); + vb->localtop=0; + } + { + void *ret=(void *)(((char *)vb->localstore)+vb->localtop); + vb->localtop+=bytes; + return ret; + } +} + +/* reap the chain, pull the ripcord */ +void _vorbis_block_ripcord(vorbis_block *vb){ + /* reap the chain */ + struct alloc_chain *reap=vb->reap; + while(reap){ + struct alloc_chain *next=reap->next; + _ogg_free(reap->ptr); + memset(reap,0,sizeof(*reap)); + _ogg_free(reap); + reap=next; + } + /* consolidate storage */ + if(vb->totaluse){ + vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc); + vb->localalloc+=vb->totaluse; + vb->totaluse=0; + } + + /* pull the ripcord */ + vb->localtop=0; + vb->reap=NULL; +} + +int vorbis_block_clear(vorbis_block *vb){ + _vorbis_block_ripcord(vb); + if(vb->localstore)_ogg_free(vb->localstore); + + memset(vb,0,sizeof(*vb)); + return(0); +} + +static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ + int i; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + private_state *b=NULL; + + memset(v,0,sizeof(*v)); + b=(private_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b))); + + v->vi=vi; + b->modebits=ilog(ci->modes); + + /* Vorbis I uses only window type 0 */ + b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2); + b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2); + + /* finish the codebooks */ + if(!ci->fullbooks){ + ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); + for(i=0;ibooks;i++){ + vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]); + /* decode codebooks are now standalone after init */ + vorbis_staticbook_destroy(ci->book_param[i]); + ci->book_param[i]=NULL; + } + } + + v->pcm_storage=ci->blocksizes[1]; + v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm)); + v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret)); + for(i=0;ichannels;i++) + v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i])); + + /* all 1 (large block) or 0 (small block) */ + /* explicitly set for the sake of clarity */ + v->lW=0; /* previous window size */ + v->W=0; /* current window size */ + + /* initialize all the mapping/backend lookups */ + b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode)); + for(i=0;imodes;i++){ + int mapnum=ci->mode_param[i]->mapping; + int maptype=ci->map_type[mapnum]; + b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i], + ci->map_param[mapnum]); + } + return(0); +} + +int vorbis_synthesis_restart(vorbis_dsp_state *v){ + vorbis_info *vi=v->vi; + codec_setup_info *ci; + + if(!v->backend_state)return -1; + if(!vi)return -1; + ci=vi->codec_setup; + if(!ci)return -1; + + v->centerW=ci->blocksizes[1]/2; + v->pcm_current=v->centerW; + + v->pcm_returned=-1; + v->granulepos=-1; + v->sequence=-1; + ((private_state *)(v->backend_state))->sample_count=-1; + + return(0); +} + +int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){ + _vds_init(v,vi); + vorbis_synthesis_restart(v); + + return(0); +} + +void vorbis_dsp_clear(vorbis_dsp_state *v){ + int i; + if(v){ + vorbis_info *vi=v->vi; + codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); + private_state *b=(private_state *)v->backend_state; + + if(v->pcm){ + for(i=0;ichannels;i++) + if(v->pcm[i])_ogg_free(v->pcm[i]); + _ogg_free(v->pcm); + if(v->pcmret)_ogg_free(v->pcmret); + } + + /* free mode lookups; these are actually vorbis_look_mapping structs */ + if(ci){ + for(i=0;imodes;i++){ + int mapnum=ci->mode_param[i]->mapping; + int maptype=ci->map_type[mapnum]; + if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]); + } + } + + if(b){ + if(b->mode)_ogg_free(b->mode); + _ogg_free(b); + } + + memset(v,0,sizeof(*v)); + } +} + +/* Unlike in analysis, the window is only partially applied for each + block. The time domain envelope is not yet handled at the point of + calling (as it relies on the previous block). */ + +int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){ + vorbis_info *vi=v->vi; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + private_state *b=v->backend_state; + int i,j; + + if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL); + + v->lW=v->W; + v->W=vb->W; + v->nW=-1; + + if((v->sequence==-1)|| + (v->sequence+1 != vb->sequence)){ + v->granulepos=-1; /* out of sequence; lose count */ + b->sample_count=-1; + } + + v->sequence=vb->sequence; + + if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly + was called on block */ + int n=ci->blocksizes[v->W]/2; + int n0=ci->blocksizes[0]/2; + int n1=ci->blocksizes[1]/2; + + int thisCenter; + int prevCenter; + + if(v->centerW){ + thisCenter=n1; + prevCenter=0; + }else{ + thisCenter=0; + prevCenter=n1; + } + + /* v->pcm is now used like a two-stage double buffer. We don't want + to have to constantly shift *or* adjust memory usage. Don't + accept a new block until the old is shifted out */ + + /* overlap/add PCM */ + + for(j=0;jchannels;j++){ + /* the overlap/add section */ + if(v->lW){ + if(v->W){ + /* large/large */ + ogg_int32_t *pcm=v->pcm[j]+prevCenter; + ogg_int32_t *p=vb->pcm[j]; + for(i=0;ipcm[j]+prevCenter+n1/2-n0/2; + ogg_int32_t *p=vb->pcm[j]; + for(i=0;iW){ + /* small/large */ + ogg_int32_t *pcm=v->pcm[j]+prevCenter; + ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2; + for(i=0;ipcm[j]+prevCenter; + ogg_int32_t *p=vb->pcm[j]; + for(i=0;ipcm[j]+thisCenter; + ogg_int32_t *p=vb->pcm[j]+n; + for(i=0;icenterW) + v->centerW=0; + else + v->centerW=n1; + + /* deal with initial packet state; we do this using the explicit + pcm_returned==-1 flag otherwise we're sensitive to first block + being short or long */ + + if(v->pcm_returned==-1){ + v->pcm_returned=thisCenter; + v->pcm_current=thisCenter; + }else{ + v->pcm_returned=prevCenter; + v->pcm_current=prevCenter+ + ci->blocksizes[v->lW]/4+ + ci->blocksizes[v->W]/4; + } + + } + + /* track the frame number... This is for convenience, but also + making sure our last packet doesn't end with added padding. If + the last packet is partial, the number of samples we'll have to + return will be past the vb->granulepos. + + 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(b->sample_count==-1){ + b->sample_count=0; + }else{ + b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; + } + + if(v->granulepos==-1){ + if(vb->granulepos!=-1){ /* only set if we have a position to set to */ + + v->granulepos=vb->granulepos; + + /* is this a short page? */ + if(b->sample_count>v->granulepos){ + /* corner case; if this is both the first and last audio page, + then spec says the end is cut, not beginning */ + if(vb->eofflag){ + /* 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 */ + + v->pcm_current-=(b->sample_count-v->granulepos); + }else{ + /* trim the beginning */ + v->pcm_returned+=(b->sample_count-v->granulepos); + if(v->pcm_returned>v->pcm_current) + v->pcm_returned=v->pcm_current; + } + + } + + } + }else{ + v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4; + if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){ + + if(v->granulepos>vb->granulepos){ + long extra=v->granulepos-vb->granulepos; + + if(extra) + if(vb->eofflag){ + /* partial last frame. Strip the extra samples off */ + v->pcm_current-=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 } */ + v->granulepos=vb->granulepos; + } + } + + /* Update, cleanup */ + + if(vb->eofflag)v->eofflag=1; + return(0); +} + +/* pcm==NULL indicates we just want the pending samples, no more */ +int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){ + vorbis_info *vi=v->vi; + if(v->pcm_returned>-1 && v->pcm_returnedpcm_current){ + if(pcm){ + int i; + for(i=0;ichannels;i++) + v->pcmret[i]=v->pcm[i]+v->pcm_returned; + *pcm=v->pcmret; + } + return(v->pcm_current-v->pcm_returned); + } + return(0); +} + +int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){ + if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL); + v->pcm_returned+=bytes; + return(0); +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/block.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/block.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,26 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2008 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: shared block functions + + ********************************************************************/ + +#ifndef _V_BLOCK_ +#define _V_BLOCK_ + +#include "ivorbiscodec.h" + +extern void _vorbis_block_ripcord(vorbis_block *vb); +extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes); + +#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/codebook.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/codebook.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,371 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: basic codebook pack/unpack/code/decode operations + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codebook.h" +#include "misc.h" + +/* unpacks a codebook from the packet buffer into the codebook struct, + readies the codebook auxiliary structures for decode *************/ +int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ + long i,j; + 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->entries=oggpack_read(opb,24); + if(s->entries==-1)goto _eofout; + + /* codeword ordering.... length ordered or unordered? */ + switch((int)oggpack_read(opb,1)){ + case 0: + /* unordered */ + s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); + + /* allocated but unused entries? */ + if(oggpack_read(opb,1)){ + /* yes, unused entries */ + + for(i=0;ientries;i++){ + if(oggpack_read(opb,1)){ + long num=oggpack_read(opb,5); + if(num==-1)goto _eofout; + s->lengthlist[i]=num+1; + }else + s->lengthlist[i]=0; + } + }else{ + /* all entries used; no tagging */ + for(i=0;ientries;i++){ + long num=oggpack_read(opb,5); + if(num==-1)goto _eofout; + s->lengthlist[i]=num+1; + } + } + + break; + case 1: + /* ordered */ + { + long length=oggpack_read(opb,5)+1; + s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); + + for(i=0;ientries;){ + long num=oggpack_read(opb,_ilog(s->entries-i)); + if(num==-1)goto _eofout; + for(j=0;jentries;j++,i++) + s->lengthlist[i]=length; + length++; + } + } + break; + default: + /* EOF */ + return(-1); + } + + /* Do we have a mapping to unpack? */ + switch((s->maptype=oggpack_read(opb,4))){ + case 0: + /* no mapping */ + break; + case 1: case 2: + /* implicitly populated value mapping */ + /* explicitly populated value mapping */ + + s->q_min=oggpack_read(opb,32); + s->q_delta=oggpack_read(opb,32); + s->q_quant=oggpack_read(opb,4)+1; + s->q_sequencep=oggpack_read(opb,1); + + { + int quantvals=0; + switch(s->maptype){ + case 1: + quantvals=_book_maptype1_quantvals(s); + break; + case 2: + quantvals=s->entries*s->dim; + break; + } + + /* quantized values */ + s->quantlist=(long *)_ogg_malloc(sizeof(*s->quantlist)*quantvals); + for(i=0;iquantlist[i]=oggpack_read(opb,s->q_quant); + + if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout; + } + break; + default: + goto _errout; + } + + /* all set */ + return(0); + + _errout: + _eofout: + vorbis_staticbook_clear(s); + return(-1); +} + +/* the 'eliminate the decode tree' optimization actually requires the + codewords to be MSb first, not LSb. This is an annoying inelegancy + (and one of the first places where carefully thought out design + turned out to be wrong; Vorbis II and future Ogg codecs should go + to an MSb bitpacker), but not actually the huge hit it appears to + be. The first-stage decode table catches most words so that + bitreverse is not in the main execution path. */ + +static ogg_uint32_t bitreverse(ogg_uint32_t x){ + x= ((x>>16)&0x0000ffff) | ((x<<16)&0xffff0000); + x= ((x>> 8)&0x00ff00ff) | ((x<< 8)&0xff00ff00); + x= ((x>> 4)&0x0f0f0f0f) | ((x<< 4)&0xf0f0f0f0); + x= ((x>> 2)&0x33333333) | ((x<< 2)&0xcccccccc); + return((x>> 1)&0x55555555) | ((x<< 1)&0xaaaaaaaa); +} + +STIN long decode_packed_entry_number(codebook *book, + oggpack_buffer *b){ + int read=book->dec_maxlength; + long lo,hi; + long lok = oggpack_look(b,book->dec_firsttablen); + + if (lok >= 0) { + long entry = book->dec_firsttable[lok]; + if(entry&0x80000000UL){ + lo=(entry>>15)&0x7fff; + hi=book->used_entries-(entry&0x7fff); + }else{ + oggpack_adv(b, book->dec_codelengths[entry-1]); + return(entry-1); + } + }else{ + lo=0; + hi=book->used_entries; + } + + lok = oggpack_look(b, read); + + while(lok<0 && read>1) + lok = oggpack_look(b, --read); + + if(lok<0){ + oggpack_adv(b,1); /* force eop */ + return -1; + } + + /* bisect search for the codeword in the ordered list */ + { + ogg_uint32_t testword=bitreverse((ogg_uint32_t)lok); + + while(hi-lo>1){ + long p=(hi-lo)>>1; + long test=book->codelist[lo+p]>testword; + lo+=p&(test-1); + hi-=p&(-test); + } + + if(book->dec_codelengths[lo]<=read){ + oggpack_adv(b, book->dec_codelengths[lo]); + return(lo); + } + } + + oggpack_adv(b, read+1); + return(-1); +} + +/* Decode side is specced and easier, because we don't need to find + matches using different criteria; we simply read and map. There are + two things we need to do 'depending': + + We may need to support interleave. We don't really, but it's + convenient to do it here rather than rebuild the vector later. + + Cascades may be additive or multiplicitive; this is not inherent in + the codebook, but set in the code using the codebook. Like + interleaving, it's easiest to do it here. + addmul==0 -> declarative (set the value) + addmul==1 -> additive + addmul==2 -> multiplicitive */ + +/* returns the [original, not compacted] entry number or -1 on eof *********/ +long vorbis_book_decode(codebook *book, oggpack_buffer *b){ + if(book->used_entries>0){ + long packed_entry=decode_packed_entry_number(book,b); + if(packed_entry>=0) + return(book->dec_index[packed_entry]); + } + + /* if there's no dec_index, the codebook unpacking isn't collapsed */ + return(-1); +} + +/* 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; + long *entry = (long *)alloca(sizeof(*entry)*step); + ogg_int32_t **t = (ogg_int32_t **)alloca(sizeof(*t)*step); + int i,j,o; + int shift=point-book->binarypoint; + + if(shift>=0){ + for (i = 0; i < step; i++) { + entry[i]=decode_packed_entry_number(book,b); + if(entry[i]==-1)return(-1); + t[i] = book->valuelist+entry[i]*book->dim; + } + for(i=0,o=0;idim;i++,o+=step) + for (j=0;j>shift; + }else{ + for (i = 0; i < step; i++) { + entry[i]=decode_packed_entry_number(book,b); + if(entry[i]==-1)return(-1); + t[i] = book->valuelist+entry[i]*book->dim; + } + for(i=0,o=0;idim;i++,o+=step) + for (j=0;jused_entries>0){ + int i,j,entry; + ogg_int32_t *t; + int shift=point-book->binarypoint; + + if(shift>=0){ + for(i=0;ivaluelist+entry*book->dim; + for (j=0;jdim;) + a[i++]+=t[j++]>>shift; + } + }else{ + for(i=0;ivaluelist+entry*book->dim; + for (j=0;jdim;) + a[i++]+=t[j++]<<-shift; + } + } + } + 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){ + int i,j,entry; + ogg_int32_t *t; + int shift=point-book->binarypoint; + + if(shift>=0){ + + for(i=0;ivaluelist+entry*book->dim; + for (j=0;jdim;){ + a[i++]=t[j++]>>shift; + } + } + }else{ + + for(i=0;ivaluelist+entry*book->dim; + for (j=0;jdim;){ + a[i++]=t[j++]<<-shift; + } + } + } + }else{ + + int i,j; + for(i=0;idim;){ + a[i++]=0; + } + } + } + return(0); +} + +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){ + long i,j,entry; + int chptr=0; + int shift=point-book->binarypoint; + + if(shift>=0){ + + for(i=offset;ivaluelist+entry*book->dim; + for (j=0;jdim;j++){ + a[chptr++][i]+=t[j]>>shift; + if(chptr==ch){ + chptr=0; + i++; + } + } + } + } + }else{ + + for(i=offset;ivaluelist+entry*book->dim; + for (j=0;jdim;j++){ + a[chptr++][i]+=t[j]<<-shift; + if(chptr==ch){ + chptr=0; + i++; + } + } + } + } + } + } + return(0); +} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/codebook.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/codebook.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,102 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: basic shared codebook operations + + ********************************************************************/ + +#ifndef _V_CODEBOOK_H_ +#define _V_CODEBOOK_H_ + +#include "ogg.h" + +/* This structure encapsulates huffman and VQ style encoding books; it + doesn't do anything specific to either. + + valuelist/quantlist are nonNULL (and q_* significant) only if + there's entry->value mapping to be done. + + If encode-side mapping must be done (and thus the entry needs to be + hunted), the auxiliary encode pointer will point to a decision + tree. This is true of both VQ and huffman, but is mostly useful + with VQ. + +*/ + +typedef struct static_codebook{ + long dim; /* codebook dimensions (elements per vector) */ + long entries; /* codebook entries */ + long *lengthlist; /* codeword lengths in bits */ + + /* mapping ***************************************************************/ + int maptype; /* 0=none + 1=implicitly populated values from map column + 2=listed arbitrary values */ + + /* The below does a linear, single monotonic sequence mapping. */ + long q_min; /* packed 32 bit float; quant value 0 maps to minval */ + long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ + int q_quant; /* bits: 0 < quant <= 16 */ + int q_sequencep; /* bitflag */ + + long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map + map == 2: list of dim*entries quantized entry vals + */ +} static_codebook; + +typedef struct codebook{ + long dim; /* codebook dimensions (elements per vector) */ + long entries; /* codebook entries */ + long used_entries; /* populated codebook entries */ + + /* the below are ordered by bitreversed codeword and only used + entries are populated */ + int binarypoint; + ogg_int32_t *valuelist; /* list of dim*entries actual entry values */ + ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */ + + int *dec_index; + char *dec_codelengths; + ogg_uint32_t *dec_firsttable; + int dec_firsttablen; + int dec_maxlength; + + long q_min; /* packed 32 bit float; quant value 0 maps to minval */ + long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */ + +} codebook; + +extern void vorbis_staticbook_clear(static_codebook *b); +extern void vorbis_staticbook_destroy(static_codebook *b); +extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); + +extern void vorbis_book_clear(codebook *b); +extern long _book_maptype1_quantvals(const static_codebook *b); + +extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_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 diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/codec_internal.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/codec_internal.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,92 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: libvorbis codec headers + + ********************************************************************/ + +#ifndef _V_CODECI_H_ +#define _V_CODECI_H_ + +#include "codebook.h" + +typedef void vorbis_look_mapping; +typedef void vorbis_look_floor; +typedef void vorbis_look_residue; +typedef void vorbis_look_transform; + +/* mode ************************************************************/ +typedef struct { + int blockflag; + int windowtype; + int transformtype; + int mapping; +} vorbis_info_mode; + +typedef void vorbis_info_floor; +typedef void vorbis_info_residue; +typedef void vorbis_info_mapping; + +typedef struct private_state { + /* local lookup storage */ + const void *window[2]; + + /* backend lookups are tied to the mode, not the backend or naked mapping */ + int modebits; + vorbis_look_mapping **mode; + + ogg_int64_t sample_count; + +} private_state; + +/* 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 times; + int floors; + int residues; + int books; + + vorbis_info_mode *mode_param[64]; + int map_type[64]; + vorbis_info_mapping *map_param[64]; + int time_type[64]; + int floor_type[64]; + vorbis_info_floor *floor_param[64]; + int residue_type[64]; + vorbis_info_residue *residue_param[64]; + static_codebook *book_param[256]; + codebook *fullbooks; + + int passlimit[32]; /* iteration limit per couple/quant pass */ + int coupling_passes; +} codec_setup_info; + +#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/config_types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/config_types.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,25 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + 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; + +#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/configure.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/configure.in Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,131 @@ +dnl Process this file with autoconf to produce a configure script + +dnl ------------------------------------------------ +dnl Initialization and Versioning +dnl ------------------------------------------------ + +AC_INIT(mdct.c) + +AC_CANONICAL_HOST +AC_CANONICAL_TARGET + +AM_CONFIG_HEADER([config.h]) + +AM_INIT_AUTOMAKE(libvorbisidec,1.2.0) + +dnl Library versioning + +V_LIB_CURRENT=1 +V_LIB_REVISION=2 +V_LIB_AGE=0 +AC_SUBST(V_LIB_CURRENT) +AC_SUBST(V_LIB_REVISION) +AC_SUBST(V_LIB_AGE) + +dnl -------------------------------------------------- +dnl Check for programs +dnl -------------------------------------------------- + +dnl save $CFLAGS since AC_PROG_CC likes to insert "-g -O2" +dnl if $CFLAGS is blank +cflags_save="$CFLAGS" +AC_PROG_CC +AC_PROG_CPP +CFLAGS="$cflags_save" + +AM_PROG_LIBTOOL + +dnl -------------------------------------------------- +dnl Set build flags based on environment +dnl -------------------------------------------------- + +dnl Set some target options + +cflags_save="$CFLAGS" +ldflags_save="$LDFLAGS" +if test -z "$GCC"; then + case $host in + arm-*-*) + DEBUG="-g -D_ARM_ASSEM_" + CFLAGS="-O -D_ARM_ASSEM_" + PROFILE="-p -g -O -D_ARM_ASSEM_" ;; + *) + DEBUG="-g" + CFLAGS="-O" + PROFILE="-g -p" ;; + esac +else + + case $host in + arm-*-*) + DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char -D_ARM_ASSEM_" + CFLAGS="-O2 -D_ARM_ASSEM_ -fsigned-char" + PROFILE="-W -pg -g -O2 -D_ARM_ASSEM_ -fsigned-char -fno-inline-functions";; + + *) + DEBUG="-g -Wall -D__NO_MATH_INLINES -fsigned-char" + CFLAGS="-O2 -Wall -fsigned-char" + PROFILE="-Wall -pg -g -O2 -fsigned-char -fno-inline-functions";; + esac +fi +CFLAGS="$CFLAGS $cflags_save -D_REENTRANT" +LDFLAGS="$LDFLAGS $ldflags_save" + + +# Test whenever ld supports -version-script +AC_PROG_LD +AC_PROG_LD_GNU +if test "x$lt_cv_prog_gnu_ld" = "xyes"; then + SHLIB_VERSION_ARG="Wl,--version-script=Version_script" + + dnl Set extra linker options + case "$target_os" in + linux* | solaris* ) + SHLIB_VERSION_ARG="-Wl,--version-script=Version_script" + ;; + *) + ;; + esac + LDFLAGS="$LDFLAGS $SHLIB_VERSION_ARG" +fi + +dnl -------------------------------------------------- +dnl Options +dnl -------------------------------------------------- + +AC_ARG_ENABLE( + low-accuracy, + [ --enable-low-accuracy enable 32 bit only multiply operations], + CFLAGS="$CFLAGS -D_LOW_ACCURACY_" +) + +dnl -------------------------------------------------- +dnl Check for headers +dnl -------------------------------------------------- + +AC_CHECK_HEADER(memory.h,CFLAGS="$CFLAGS -DUSE_MEMORY_H",:) + +dnl -------------------------------------------------- +dnl Check for typedefs, structures, etc +dnl -------------------------------------------------- + +dnl none + +dnl -------------------------------------------------- +dnl Check for library functions +dnl -------------------------------------------------- + +AC_FUNC_ALLOCA +AC_FUNC_MEMCMP + +dnl -------------------------------------------------- +dnl Do substitutions +dnl -------------------------------------------------- + +LIBS="$LIBS" + +AC_SUBST(LIBS) +AC_SUBST(DEBUG) +AC_SUBST(PROFILE) + +AC_OUTPUT(Makefile Version_script) diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/floor0.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/floor0.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,435 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: floor backend 0 implementation + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "registry.h" +#include "codebook.h" +#include "misc.h" +#include "block.h" + +#define LSP_FRACBITS 14 + +typedef struct { + long n; + int ln; + int m; + int *linearmap; + + vorbis_info_floor0 *vi; + ogg_int32_t *lsp_look; + +} vorbis_look_floor0; + +/*************** 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}; +STIN 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 */ +STIN ogg_int32_t vorbis_fromdBlook_i(long a){ + int i=(-a)>>(12-FROMdB2_SHIFT); + if(i<0) return 0x7fffffff; + if(i>=(FROMdB_LOOKUP_SZ<>FROMdB_SHIFT] * FROMdB2_LOOKUP[i&FROMdB2_MASK]; +} + +/* 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 */ +STIN 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 lookup based cos function */ +/* a is in 0.16 format, where 0==0, 2^^16==PI, return .LSP_FRACBITS */ +STIN ogg_int32_t vorbis_coslook2_i(long a){ + a=a&0x1ffff; + + if(a>0x10000)a=0x20000-a; + { + int i=a>>COS_LOOKUP_I_SHIFT; + int d=a&COS_LOOKUP_I_MASK; + a=((COS_LOOKUP_I[i]<> + (COS_LOOKUP_I_SHIFT-LSP_FRACBITS+14); + } + + return(a); +} + +static const int barklook[28]={ + 0,100,200,301, 405,516,635,766, + 912,1077,1263,1476, 1720,2003,2333,2721, + 3184,3742,4428,5285, 6376,7791,9662,12181, + 15624,20397,27087,36554 +}; + +/* used in init only; interpolate the long way */ +STIN ogg_int32_t toBARK(int n){ + int i; + for(i=0;i<27;i++) + if(n>=barklook[i] && n>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>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>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(map[++i]==k) curve[i]= MULT31_SHIFT15(curve[i],amp); + } +} + +/*************** vorbis decode glue ************/ + +static void floor0_free_info(vorbis_info_floor *i){ + vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; + if(info){ + memset(info,0,sizeof(*info)); + _ogg_free(info); + } +} + +static void floor0_free_look(vorbis_look_floor *i){ + vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; + if(look){ + + if(look->linearmap)_ogg_free(look->linearmap); + if(look->lsp_look)_ogg_free(look->lsp_look); + memset(look,0,sizeof(*look)); + _ogg_free(look); + } +} + +static vorbis_info_floor *floor0_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; + if(info->numbooks<1)goto err_out; + + for(j=0;jnumbooks;j++){ + info->books[j]=oggpack_read(opb,8); + if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out; + } + return(info); + + err_out: + floor0_free_info(info); + return(NULL); +} + +/* initialize Bark scale and normalization lookups. We could do this + with static tables, but Vorbis allows a number of possible + combinations, so it's best to do it computationally. + + The below is authoritative in terms of defining scale mapping. + Note that the scale depends on the sampling rate as well as the + linear block and mapping sizes */ + +static vorbis_look_floor *floor0_look (vorbis_dsp_state *vd,vorbis_info_mode *mi, + vorbis_info_floor *i){ + int j; + vorbis_info *vi=vd->vi; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + vorbis_info_floor0 *info=(vorbis_info_floor0 *)i; + vorbis_look_floor0 *look=(vorbis_look_floor0 *)_ogg_calloc(1,sizeof(*look)); + look->m=info->order; + look->n=ci->blocksizes[mi->blockflag]/2; + look->ln=info->barkmap; + look->vi=info; + + /* the mapping from a linear scale to a smaller bark scale is + straightforward. We do *not* make sure that the linear mapping + does not skip bark-scale bins; the decoder simply skips them and + the encoder may do what it wishes in filling them. They're + necessary in some mapping combinations to keep the scale spacing + accurate */ + look->linearmap=(int *)_ogg_malloc((look->n+1)*sizeof(*look->linearmap)); + for(j=0;jn;j++){ + + int val=(look->ln* + ((toBARK(info->rate/2*j/look->n)<<11)/toBARK(info->rate/2)))>>11; + + if(val>=look->ln)val=look->ln-1; /* guard against the approximation */ + look->linearmap[j]=val; + } + look->linearmap[j]=-1; + + look->lsp_look=(ogg_int32_t *)_ogg_malloc(look->ln*sizeof(*look->lsp_look)); + for(j=0;jln;j++) + look->lsp_look[j]=vorbis_coslook2_i(0x10000*j/look->ln); + + return look; +} + +static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){ + vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; + vorbis_info_floor0 *info=look->vi; + int j,k; + + int ampraw=oggpack_read(&vb->opb,info->ampbits); + if(ampraw>0){ /* also handles the -1 out of data case */ + long maxval=(1<ampbits)-1; + int amp=((ampraw*info->ampdB)<<4)/maxval; + int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks)); + + if(booknum!=-1 && booknumnumbooks){ /* be paranoid */ + codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; + codebook *b=ci->fullbooks+info->books[booknum]; + ogg_int32_t last=0; + ogg_int32_t *lsp=(ogg_int32_t *)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+1)); + + for(j=0;jm;j+=b->dim) + if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim,-24)==-1)goto eop; + for(j=0;jm;){ + for(k=0;kdim;k++,j++)lsp[j]+=last; + last=lsp[j-1]; + } + + lsp[look->m]=amp; + return(lsp); + } + } + eop: + return(NULL); +} + +static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i, + void *memo,ogg_int32_t *out){ + vorbis_look_floor0 *look=(vorbis_look_floor0 *)i; + vorbis_info_floor0 *info=look->vi; + + if(memo){ + ogg_int32_t *lsp=(ogg_int32_t *)memo; + ogg_int32_t amp=lsp[look->m]; + + /* take the coefficients back to a spectral envelope curve */ + vorbis_lsp_to_curve(out,look->linearmap,look->n,look->ln, + lsp,look->m,amp,info->ampdB,look->lsp_look); + return(1); + } + memset(out,0,sizeof(*out)*look->n); + return(0); +} + +/* export hooks */ +vorbis_func_floor floor0_exportbundle={ + &floor0_unpack,&floor0_look,&floor0_free_info, + &floor0_free_look,&floor0_inverse1,&floor0_inverse2 +}; + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/floor1.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/floor1.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,441 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: floor backend 1 implementation + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "registry.h" +#include "codebook.h" +#include "misc.h" +#include "block.h" + +#define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */ + +typedef struct { + int forward_index[VIF_POSIT+2]; + + int hineighbor[VIF_POSIT]; + int loneighbor[VIF_POSIT]; + int posts; + + int n; + int quant_q; + vorbis_info_floor1 *vi; + +} vorbis_look_floor1; + +/***********************************************/ + +static void floor1_free_info(vorbis_info_floor *i){ + vorbis_info_floor1 *info=(vorbis_info_floor1 *)i; + if(info){ + memset(info,0,sizeof(*info)); + _ogg_free(info); + } +} + +static void floor1_free_look(vorbis_look_floor *i){ + vorbis_look_floor1 *look=(vorbis_look_floor1 *)i; + if(look){ + memset(look,0,sizeof(*look)); + _ogg_free(look); + } +} + +static int ilog(unsigned int v){ + int ret=0; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +static vorbis_info_floor *floor1_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 */ + for(j=0;jpartitions;j++){ + info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */ + if(maxclasspartitionclass[j])maxclass=info->partitionclass[j]; + } + + /* read partition classes */ + for(j=0;jclass_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */ + info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */ + if(info->class_subs[j]<0) + goto err_out; + if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8); + if(info->class_book[j]<0 || info->class_book[j]>=ci->books) + goto err_out; + for(k=0;k<(1<class_subs[j]);k++){ + info->class_subbook[j][k]=oggpack_read(opb,8)-1; + if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books) + 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;jpartitions;j++){ + count+=info->class_dim[info->partitionclass[j]]; + for(;kpostlist[k+2]=oggpack_read(opb,rangebits); + if(t<0 || t>=(1<postlist[0]=0; + info->postlist[1]=1<vi=info; + look->n=info->postlist[1]; + + /* we drop each position value in-between already decoded values, + and use linear interpolation to predict each new value past the + edges. The positions are read in the order of the position + list... we precompute the bounding positions in the lookup. Of + course, the neighbors can change (if a position is declined), but + this is an initial mapping */ + + for(i=0;ipartitions;i++)n+=info->class_dim[info->partitionclass[i]]; + n+=2; + look->posts=n; + + /* also store a sorted position index */ + for(i=0;ipostlist+i; + qsort(sortpointer,n,sizeof(*sortpointer),icomp); + + /* points from sort order back to range number */ + for(i=0;iforward_index[i]=sortpointer[i]-info->postlist; + + /* quantize values to multiplier spec */ + switch(info->mult){ + case 1: /* 1024 -> 256 */ + look->quant_q=256; + break; + case 2: /* 1024 -> 128 */ + look->quant_q=128; + break; + case 3: /* 1024 -> 86 */ + look->quant_q=86; + break; + case 4: /* 1024 -> 64 */ + look->quant_q=64; + break; + } + + /* discover our neighbors for decode where we don't use fit flags + (that would push the neighbors outward) */ + for(i=0;in; + int currentx=info->postlist[i+2]; + for(j=0;jpostlist[j]; + if(x>lx && xcurrentx){ + hi=j; + hx=x; + } + } + look->loneighbor[i]=lo; + look->hineighbor[i]=hi; + } + + return(look); +} + +static 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); + } +} + +#ifdef _LOW_ACCURACY_ +# define XdB(n) ((((n)>>8)+1)>>1) +#else +# define XdB(n) (n) +#endif + +static 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), +}; + +static void render_line(int n, int x0,int x1,int y0,int y1,ogg_int32_t *d){ + int dy=y1-y0; + int adx=x1-x0; + int ady=abs(dy); + int base=dy/adx; + int sy=(dy<0?base-1:base+1); + int x=x0; + int y=y0; + int err=0; + + if(n>x1)n=x1; + ady-=abs(base*adx); + + if(x=adx){ + err-=adx; + y+=sy; + }else{ + y+=base; + } + d[x]= MULT31_SHIFT15(d[x],FLOOR_fromdB_LOOKUP[y]); + } +} + +static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ + vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; + vorbis_info_floor1 *info=look->vi; + codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; + + int i,j,k; + codebook *books=ci->fullbooks; + + /* unpack wrapped/predicted values from stream */ + if(oggpack_read(&vb->opb,1)==1){ + int *fit_value=(int *)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value)); + + fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1)); + fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1)); + + /* partition by partition */ + /* partition by partition */ + for(i=0,j=2;ipartitions;i++){ + int classv=info->partitionclass[i]; + int cdim=info->class_dim[classv]; + int csubbits=info->class_subs[classv]; + int csub=1<class_book[classv],&vb->opb); + + if(cval==-1)goto eop; + } + + for(k=0;kclass_subbook[classv][cval&(csub-1)]; + cval>>=csubbits; + if(book>=0){ + if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) + goto eop; + }else{ + fit_value[j+k]=0; + } + } + j+=cdim; + } + + /* unwrap positive values and reconsitute via linear interpolation */ + for(i=2;iposts;i++){ + int predicted=render_point(info->postlist[look->loneighbor[i-2]], + info->postlist[look->hineighbor[i-2]], + fit_value[look->loneighbor[i-2]], + fit_value[look->hineighbor[i-2]], + info->postlist[i]); + int hiroom=look->quant_q-predicted; + int loroom=predicted; + int room=(hiroom=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[look->loneighbor[i-2]]&=0x7fff; + fit_value[look->hineighbor[i-2]]&=0x7fff; + + }else{ + fit_value[i]=predicted|0x8000; + } + + } + + return(fit_value); + } + eop: + return(NULL); +} + +static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, + ogg_int32_t *out){ + vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; + vorbis_info_floor1 *info=look->vi; + + codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup; + int n=ci->blocksizes[vb->W]/2; + int j; + + if(memo){ + /* render the lines */ + int *fit_value=(int *)memo; + int hx=0; + int lx=0; + int ly=fit_value[0]*info->mult; + for(j=1;jposts;j++){ + int current=look->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 +#include +#include "ogg.h" +#include "misc.h" + + +/* A complete description of Ogg framing exists in docs/framing.html */ + +/* basic, centralized Ogg memory management based on linked lists of + references to refcounted memory buffers. References and buffers + are both recycled. Buffers are passed around and consumed in + reference form. */ + +static ogg_buffer_state *ogg_buffer_create(void){ + ogg_buffer_state *bs=_ogg_calloc(1,sizeof(*bs)); + return bs; +} + +/* destruction is 'lazy'; there may be memory references outstanding, + and yanking the buffer state out from underneath would be + antisocial. Dealloc what is currently unused and have + _release_one watch for the stragglers to come in. When they do, + finish destruction. */ + +/* call the helper while holding lock */ +static void _ogg_buffer_destroy(ogg_buffer_state *bs){ + ogg_buffer *bt; + ogg_reference *rt; + + if(bs->shutdown){ + + bt=bs->unused_buffers; + rt=bs->unused_references; + + while(bt){ + ogg_buffer *b=bt; + bt=b->ptr.next; + if(b->data)_ogg_free(b->data); + _ogg_free(b); + } + bs->unused_buffers=0; + while(rt){ + ogg_reference *r=rt; + rt=r->next; + _ogg_free(r); + } + bs->unused_references=0; + + if(!bs->outstanding) + _ogg_free(bs); + + } +} + +static void ogg_buffer_destroy(ogg_buffer_state *bs){ + bs->shutdown=1; + _ogg_buffer_destroy(bs); +} + +static ogg_buffer *_fetch_buffer(ogg_buffer_state *bs,long bytes){ + ogg_buffer *ob; + bs->outstanding++; + + /* do we have an unused buffer sitting in the pool? */ + if(bs->unused_buffers){ + ob=bs->unused_buffers; + bs->unused_buffers=ob->ptr.next; + + /* if the unused buffer is too small, grow it */ + if(ob->sizedata=_ogg_realloc(ob->data,bytes); + ob->size=bytes; + } + }else{ + /* allocate a new buffer */ + ob=_ogg_malloc(sizeof(*ob)); + ob->data=_ogg_malloc(bytes<16?16:bytes); + ob->size=bytes; + } + + ob->refcount=1; + ob->ptr.owner=bs; + return ob; +} + +static ogg_reference *_fetch_ref(ogg_buffer_state *bs){ + ogg_reference *or; + bs->outstanding++; + + /* do we have an unused reference sitting in the pool? */ + if(bs->unused_references){ + or=bs->unused_references; + bs->unused_references=or->next; + }else{ + /* allocate a new reference */ + or=_ogg_malloc(sizeof(*or)); + } + + or->begin=0; + or->length=0; + or->next=0; + return or; +} + +/* fetch a reference pointing to a fresh, initially continguous buffer + of at least [bytes] length */ +static ogg_reference *ogg_buffer_alloc(ogg_buffer_state *bs,long bytes){ + ogg_buffer *ob=_fetch_buffer(bs,bytes); + ogg_reference *or=_fetch_ref(bs); + or->buffer=ob; + return or; +} + +/* enlarge the data buffer in the current link */ +static void ogg_buffer_realloc(ogg_reference *or,long bytes){ + ogg_buffer *ob=or->buffer; + + /* if the unused buffer is too small, grow it */ + if(ob->sizedata=_ogg_realloc(ob->data,bytes); + ob->size=bytes; + } +} + +static void _ogg_buffer_mark_one(ogg_reference *or){ + or->buffer->refcount++; +} + +/* increase the refcount of the buffers to which the reference points */ +static void ogg_buffer_mark(ogg_reference *or){ + while(or){ + _ogg_buffer_mark_one(or); + or=or->next; + } +} + +/* duplicate a reference (pointing to the same actual buffer memory) + and increment buffer refcount. If the desired segment begins out + of range, NULL is returned; if the desired segment is simply zero + length, a zero length ref is returned. Partial range overlap + returns the overlap of the ranges */ +static ogg_reference *ogg_buffer_sub(ogg_reference *or,long begin,long length){ + ogg_reference *ret=0,*head=0; + + /* walk past any preceeding fragments we don't want */ + while(or && begin>=or->length){ + begin-=or->length; + or=or->next; + } + + /* duplicate the reference chain; increment refcounts */ + while(or && length){ + ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); + if(head) + head->next=temp; + else + ret=temp; + head=temp; + head->buffer=or->buffer; + head->begin=or->begin+begin; + head->length=length; + if(head->length>or->length-begin) + head->length=or->length-begin; + + begin=0; + length-=head->length; + or=or->next; + } + + ogg_buffer_mark(ret); + return ret; +} + +ogg_reference *ogg_buffer_dup(ogg_reference *or){ + ogg_reference *ret=0,*head=0; + /* duplicate the reference chain; increment refcounts */ + while(or){ + ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); + if(head) + head->next=temp; + else + ret=temp; + head=temp; + head->buffer=or->buffer; + head->begin=or->begin; + head->length=or->length; + or=or->next; + } + + ogg_buffer_mark(ret); + return ret; +} + +/* split a reference into two references; 'return' is a reference to + the buffer preceeding pos and 'head'/'tail' are the buffer past the + split. If pos is at or past the end of the passed in segment, + 'head/tail' are NULL */ +static ogg_reference *ogg_buffer_split(ogg_reference **tail, + ogg_reference **head,long pos){ + + /* walk past any preceeding fragments to one of: + a) the exact boundary that seps two fragments + b) the fragment that needs split somewhere in the middle */ + ogg_reference *ret=*tail; + ogg_reference *or=*tail; + + while(or && pos>or->length){ + pos-=or->length; + or=or->next; + } + + if(!or || pos==0){ + + return 0; + + }else{ + + if(pos>=or->length){ + /* exact split, or off the end? */ + if(or->next){ + + /* a split */ + *tail=or->next; + or->next=0; + + }else{ + + /* off or at the end */ + *tail=*head=0; + + } + }else{ + + /* split within a fragment */ + long lengthA=pos; + long beginB=or->begin+pos; + long lengthB=or->length-pos; + + /* make a new reference to tail the second piece */ + *tail=_fetch_ref(or->buffer->ptr.owner); + + (*tail)->buffer=or->buffer; + (*tail)->begin=beginB; + (*tail)->length=lengthB; + (*tail)->next=or->next; + _ogg_buffer_mark_one(*tail); + if(head && or==*head)*head=*tail; + + /* update the first piece */ + or->next=0; + or->length=lengthA; + + } + } + return ret; +} + +static void ogg_buffer_release_one(ogg_reference *or){ + ogg_buffer *ob=or->buffer; + ogg_buffer_state *bs=ob->ptr.owner; + + ob->refcount--; + if(ob->refcount==0){ + bs->outstanding--; /* for the returned buffer */ + ob->ptr.next=bs->unused_buffers; + bs->unused_buffers=ob; + } + + bs->outstanding--; /* for the returned reference */ + or->next=bs->unused_references; + bs->unused_references=or; + + _ogg_buffer_destroy(bs); /* lazy cleanup (if needed) */ + +} + +/* release the references, decrease the refcounts of buffers to which + they point, release any buffers with a refcount that drops to zero */ +static void ogg_buffer_release(ogg_reference *or){ + while(or){ + ogg_reference *next=or->next; + ogg_buffer_release_one(or); + or=next; + } +} + +static ogg_reference *ogg_buffer_pretruncate(ogg_reference *or,long pos){ + /* release preceeding fragments we don't want */ + while(or && pos>=or->length){ + ogg_reference *next=or->next; + pos-=or->length; + ogg_buffer_release_one(or); + or=next; + } + if (or) { + or->begin+=pos; + or->length-=pos; + } + return or; +} + +static ogg_reference *ogg_buffer_walk(ogg_reference *or){ + if(!or)return NULL; + while(or->next){ + or=or->next; + } + return(or); +} + +/* *head is appended to the front end (head) of *tail; both continue to + be valid pointers, with *tail at the tail and *head at the head */ +static ogg_reference *ogg_buffer_cat(ogg_reference *tail, ogg_reference *head){ + if(!tail)return head; + + while(tail->next){ + tail=tail->next; + } + tail->next=head; + return ogg_buffer_walk(head); +} + +static void _positionB(oggbyte_buffer *b,int pos){ + if(pospos){ + /* start at beginning, scan forward */ + b->ref=b->baseref; + b->pos=0; + b->end=b->pos+b->ref->length; + b->ptr=b->ref->buffer->data+b->ref->begin; + } +} + +static void _positionF(oggbyte_buffer *b,int pos){ + /* scan forward for position */ + while(pos>=b->end){ + /* just seek forward */ + b->pos+=b->ref->length; + b->ref=b->ref->next; + b->end=b->ref->length+b->pos; + b->ptr=b->ref->buffer->data+b->ref->begin; + } +} + +static int oggbyte_init(oggbyte_buffer *b,ogg_reference *or){ + memset(b,0,sizeof(*b)); + if(or){ + b->ref=b->baseref=or; + b->pos=0; + b->end=b->ref->length; + b->ptr=b->ref->buffer->data+b->ref->begin; + return 0; + }else + return -1; +} + +static void oggbyte_set4(oggbyte_buffer *b,ogg_uint32_t val,int pos){ + int i; + _positionB(b,pos); + for(i=0;i<4;i++){ + _positionF(b,pos); + b->ptr[pos-b->pos]=val; + val>>=8; + ++pos; + } +} + +static unsigned char oggbyte_read1(oggbyte_buffer *b,int pos){ + _positionB(b,pos); + _positionF(b,pos); + return b->ptr[pos-b->pos]; +} + +static ogg_uint32_t oggbyte_read4(oggbyte_buffer *b,int pos){ + ogg_uint32_t ret; + _positionB(b,pos); + _positionF(b,pos); + ret=b->ptr[pos-b->pos]; + _positionF(b,++pos); + ret|=b->ptr[pos-b->pos]<<8; + _positionF(b,++pos); + ret|=b->ptr[pos-b->pos]<<16; + _positionF(b,++pos); + ret|=b->ptr[pos-b->pos]<<24; + return ret; +} + +static ogg_int64_t oggbyte_read8(oggbyte_buffer *b,int pos){ + ogg_int64_t ret; + unsigned char t[7]; + int i; + _positionB(b,pos); + for(i=0;i<7;i++){ + _positionF(b,pos); + t[i]=b->ptr[pos++ -b->pos]; + } + + _positionF(b,pos); + ret=b->ptr[pos-b->pos]; + + for(i=6;i>=0;--i) + ret= ret<<8 | t[i]; + + return ret; +} + +/* Now we get to the actual framing code */ + +int ogg_page_version(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read1(&ob,4); +} + +int ogg_page_continued(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read1(&ob,5)&0x01; +} + +int ogg_page_bos(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read1(&ob,5)&0x02; +} + +int ogg_page_eos(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read1(&ob,5)&0x04; +} + +ogg_int64_t ogg_page_granulepos(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read8(&ob,6); +} + +ogg_uint32_t ogg_page_serialno(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read4(&ob,14); +} + +ogg_uint32_t ogg_page_pageno(ogg_page *og){ + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + return oggbyte_read4(&ob,18); +} + +/* returns the number of packets that are completed on this page (if + the leading packet is begun on a previous page, but ends on this + page, it's counted */ + +/* NOTE: +If a page consists of a packet begun on a previous page, and a new +packet begun (but not completed) on this page, the return will be: + ogg_page_packets(page) ==1, + ogg_page_continued(page) !=0 + +If a page happens to be a single packet that was begun on a +previous page, and spans to the next page (in the case of a three or +more page packet), the return will be: + ogg_page_packets(page) ==0, + ogg_page_continued(page) !=0 +*/ + +int ogg_page_packets(ogg_page *og){ + int i; + int n; + int count=0; + oggbyte_buffer ob; + oggbyte_init(&ob,og->header); + + n=oggbyte_read1(&ob,26); + for(i=0;ibufferpool=ogg_buffer_create(); + return oy; +} + +int ogg_sync_destroy(ogg_sync_state *oy){ + if(oy){ + ogg_sync_reset(oy); + ogg_buffer_destroy(oy->bufferpool); + memset(oy,0,sizeof(*oy)); + _ogg_free(oy); + } + return OGG_SUCCESS; +} + +unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long bytes){ + + /* [allocate and] expose a buffer for data submission. + + If there is no head fragment + allocate one and expose it + else + if the current head fragment has sufficient unused space + expose it + else + if the current head fragment is unused + resize and expose it + else + allocate new fragment and expose it + */ + + /* base case; fifo uninitialized */ + if(!oy->fifo_head){ + oy->fifo_head=oy->fifo_tail=ogg_buffer_alloc(oy->bufferpool,bytes); + return oy->fifo_head->buffer->data; + } + + /* space left in current fragment case */ + if(oy->fifo_head->buffer->size- + oy->fifo_head->length- + oy->fifo_head->begin >= bytes) + return oy->fifo_head->buffer->data+ + oy->fifo_head->length+oy->fifo_head->begin; + + /* current fragment is unused, but too small */ + if(!oy->fifo_head->length){ + ogg_buffer_realloc(oy->fifo_head,bytes); + return oy->fifo_head->buffer->data+oy->fifo_head->begin; + } + + /* current fragment used/full; get new fragment */ + { + ogg_reference *new=ogg_buffer_alloc(oy->bufferpool,bytes); + oy->fifo_head->next=new; + oy->fifo_head=new; + } + return oy->fifo_head->buffer->data; +} + +int ogg_sync_wrote(ogg_sync_state *oy, long bytes){ + if(!oy->fifo_head)return OGG_EINVAL; + if(oy->fifo_head->buffer->size-oy->fifo_head->length-oy->fifo_head->begin < + bytes)return OGG_EINVAL; + oy->fifo_head->length+=bytes; + oy->fifo_fill+=bytes; + return OGG_SUCCESS; +} + +static ogg_uint32_t _checksum(ogg_reference *or, int bytes){ + ogg_uint32_t crc_reg=0; + int j,post; + + while(or){ + unsigned char *data=or->buffer->data+or->begin; + post=(byteslength?bytes:or->length); + for(j=0;j> 24)&0xff)^data[j]]; + bytes-=j; + or=or->next; + } + + return crc_reg; +} + + +/* sync the stream. This is meant to be useful for finding page + boundaries. + + return values for this: + -n) skipped n bytes + 0) page not ready; more data (no bytes skipped) + n) page synced at current location; page length n bytes + +*/ + +long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){ + oggbyte_buffer page; + long bytes,ret=0; + + ogg_page_release(og); + + bytes=oy->fifo_fill; + oggbyte_init(&page,oy->fifo_tail); + + if(oy->headerbytes==0){ + if(bytes<27)goto sync_out; /* not enough for even a minimal header */ + + /* verify capture pattern */ + if(oggbyte_read1(&page,0)!=(int)'O' || + oggbyte_read1(&page,1)!=(int)'g' || + oggbyte_read1(&page,2)!=(int)'g' || + oggbyte_read1(&page,3)!=(int)'S' ) goto sync_fail; + + oy->headerbytes=oggbyte_read1(&page,26)+27; + } + if(bytesheaderbytes)goto sync_out; /* not enough for header + + seg table */ + if(oy->bodybytes==0){ + int i; + /* count up body length in the segment table */ + for(i=0;iheaderbytes-27;i++) + oy->bodybytes+=oggbyte_read1(&page,27+i); + } + + if(oy->bodybytes+oy->headerbytes>bytes)goto sync_out; + + /* we have what appears to be a complete page; last test: verify + checksum */ + { + ogg_uint32_t chksum=oggbyte_read4(&page,22); + oggbyte_set4(&page,0,22); + + /* Compare checksums; memory continues to be common access */ + if(chksum!=_checksum(oy->fifo_tail,oy->bodybytes+oy->headerbytes)){ + + /* D'oh. Mismatch! Corrupt page (or miscapture and not a page + at all). replace the computed checksum with the one actually + read in; remember all the memory is common access */ + + oggbyte_set4(&page,chksum,22); + goto sync_fail; + } + oggbyte_set4(&page,chksum,22); + } + + /* We have a page. Set up page return. */ + if(og){ + /* set up page output */ + og->header=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->headerbytes); + og->header_len=oy->headerbytes; + og->body=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->bodybytes); + og->body_len=oy->bodybytes; + }else{ + /* simply advance */ + oy->fifo_tail= + ogg_buffer_pretruncate(oy->fifo_tail,oy->headerbytes+oy->bodybytes); + if(!oy->fifo_tail)oy->fifo_head=0; + } + + ret=oy->headerbytes+oy->bodybytes; + oy->unsynced=0; + oy->headerbytes=0; + oy->bodybytes=0; + oy->fifo_fill-=ret; + + return ret; + + sync_fail: + + oy->headerbytes=0; + oy->bodybytes=0; + oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,1); + ret--; + + /* search forward through fragments for possible capture */ + while(oy->fifo_tail){ + /* invariant: fifo_cursor points to a position in fifo_tail */ + unsigned char *now=oy->fifo_tail->buffer->data+oy->fifo_tail->begin; + unsigned char *next=memchr(now, 'O', oy->fifo_tail->length); + + if(next){ + /* possible capture in this segment */ + long bytes=next-now; + oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes); + ret-=bytes; + break; + }else{ + /* no capture. advance to next segment */ + long bytes=oy->fifo_tail->length; + ret-=bytes; + oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes); + } + } + if(!oy->fifo_tail)oy->fifo_head=0; + oy->fifo_fill+=ret; + + sync_out: + return ret; +} + +/* sync the stream and get a page. Keep trying until we find a page. + Supress 'sync errors' after reporting the first. + + return values: + OGG_HOLE) recapture (hole in data) + 0) need more data + 1) page returned + + Returns pointers into buffered data; invalidated by next call to + _stream, _clear, _init, or _buffer */ + +int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){ + + /* all we need to do is verify a page at the head of the stream + buffer. If it doesn't verify, we look for the next potential + frame */ + + while(1){ + long ret=ogg_sync_pageseek(oy,og); + if(ret>0){ + /* have a page */ + return 1; + } + if(ret==0){ + /* need more data */ + return 0; + } + + /* head did not start a synced page... skipped some bytes */ + if(!oy->unsynced){ + oy->unsynced=1; + return OGG_HOLE; + } + + /* loop. keep looking */ + + } +} + +/* clear things to an initial state. Good to call, eg, before seeking */ +int ogg_sync_reset(ogg_sync_state *oy){ + + ogg_buffer_release(oy->fifo_tail); + oy->fifo_tail=0; + oy->fifo_head=0; + oy->fifo_fill=0; + + oy->unsynced=0; + oy->headerbytes=0; + oy->bodybytes=0; + return OGG_SUCCESS; +} + +ogg_stream_state *ogg_stream_create(int serialno){ + ogg_stream_state *os=_ogg_calloc(1,sizeof(*os)); + os->serialno=serialno; + os->pageno=-1; + return os; +} + +int ogg_stream_destroy(ogg_stream_state *os){ + if(os){ + ogg_buffer_release(os->header_tail); + ogg_buffer_release(os->body_tail); + memset(os,0,sizeof(*os)); + _ogg_free(os); + } + return OGG_SUCCESS; +} + + +#define FINFLAG 0x80000000UL +#define FINMASK 0x7fffffffUL + +static void _next_lace(oggbyte_buffer *ob,ogg_stream_state *os){ + /* search ahead one lace */ + os->body_fill_next=0; + while(os->laceptrlacing_fill){ + int val=oggbyte_read1(ob,27+os->laceptr++); + os->body_fill_next+=val; + if(val<255){ + os->body_fill_next|=FINFLAG; + os->clearflag=1; + break; + } + } +} + +static void _span_queued_page(ogg_stream_state *os){ + while( !(os->body_fill&FINFLAG) ){ + + if(!os->header_tail)break; + + /* first flush out preceeding page header (if any). Body is + flushed as it's consumed, so that's not done here. */ + + if(os->lacing_fill>=0) + os->header_tail=ogg_buffer_pretruncate(os->header_tail, + os->lacing_fill+27); + os->lacing_fill=0; + os->laceptr=0; + os->clearflag=0; + + if(!os->header_tail){ + os->header_head=0; + break; + }else{ + + /* process/prepare next page, if any */ + + long pageno; + oggbyte_buffer ob; + ogg_page og; /* only for parsing header values */ + og.header=os->header_tail; /* only for parsing header values */ + pageno=ogg_page_pageno(&og); + + oggbyte_init(&ob,os->header_tail); + os->lacing_fill=oggbyte_read1(&ob,26); + + /* are we in sequence? */ + if(pageno!=os->pageno){ + if(os->pageno==-1) /* indicates seek or reset */ + os->holeflag=1; /* set for internal use */ + else + os->holeflag=2; /* set for external reporting */ + + os->body_tail=ogg_buffer_pretruncate(os->body_tail, + os->body_fill); + if(os->body_tail==0)os->body_head=0; + os->body_fill=0; + + } + + if(ogg_page_continued(&og)){ + if(os->body_fill==0){ + /* continued packet, but no preceeding data to continue */ + /* dump the first partial packet on the page */ + _next_lace(&ob,os); + os->body_tail= + ogg_buffer_pretruncate(os->body_tail,os->body_fill_next&FINMASK); + if(os->body_tail==0)os->body_head=0; + /* set span flag */ + if(!os->spanflag && !os->holeflag)os->spanflag=2; + } + }else{ + if(os->body_fill>0){ + /* preceeding data to continue, but not a continued page */ + /* dump body_fill */ + os->body_tail=ogg_buffer_pretruncate(os->body_tail, + os->body_fill); + if(os->body_tail==0)os->body_head=0; + os->body_fill=0; + + /* set espan flag */ + if(!os->spanflag && !os->holeflag)os->spanflag=2; + } + } + + if(os->laceptrlacing_fill){ + os->granulepos=ogg_page_granulepos(&og); + + /* get current packet size & flag */ + _next_lace(&ob,os); + os->body_fill+=os->body_fill_next; /* addition handles the flag fine; + unsigned on purpose */ + /* ...and next packet size & flag */ + _next_lace(&ob,os); + + } + + os->pageno=pageno+1; + os->e_o_s=ogg_page_eos(&og); + os->b_o_s=ogg_page_bos(&og); + + } + } +} + +/* add the incoming page to the stream state; we decompose the page + into packet segments here as well. */ + +int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){ + + int serialno=ogg_page_serialno(og); + int version=ogg_page_version(og); + + /* check the serial number */ + if(serialno!=os->serialno){ + ogg_page_release(og); + return OGG_ESERIAL; + } + if(version>0){ + ogg_page_release(og); + return OGG_EVERSION; + } + + /* add to fifos */ + if(!os->body_tail){ + os->body_tail=og->body; + os->body_head=ogg_buffer_walk(og->body); + }else{ + os->body_head=ogg_buffer_cat(os->body_head,og->body); + } + if(!os->header_tail){ + os->header_tail=og->header; + os->header_head=ogg_buffer_walk(og->header); + os->lacing_fill=-27; + }else{ + os->header_head=ogg_buffer_cat(os->header_head,og->header); + } + + memset(og,0,sizeof(*og)); + return OGG_SUCCESS; +} + +int ogg_stream_reset(ogg_stream_state *os){ + + ogg_buffer_release(os->header_tail); + ogg_buffer_release(os->body_tail); + os->header_tail=os->header_head=0; + os->body_tail=os->body_head=0; + + os->e_o_s=0; + os->b_o_s=0; + os->pageno=-1; + os->packetno=0; + os->granulepos=0; + + os->body_fill=0; + os->lacing_fill=0; + + os->holeflag=0; + os->spanflag=0; + os->clearflag=0; + os->laceptr=0; + os->body_fill_next=0; + + return OGG_SUCCESS; +} + +int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){ + ogg_stream_reset(os); + os->serialno=serialno; + return OGG_SUCCESS; +} + +static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){ + + ogg_packet_release(op); + _span_queued_page(os); + + if(os->holeflag){ + int temp=os->holeflag; + if(os->clearflag) + os->holeflag=0; + else + os->holeflag=1; + if(temp==2){ + os->packetno++; + return OGG_HOLE; + } + } + if(os->spanflag){ + int temp=os->spanflag; + if(os->clearflag) + os->spanflag=0; + else + os->spanflag=1; + if(temp==2){ + os->packetno++; + return OGG_SPAN; + } + } + + if(!(os->body_fill&FINFLAG)) return 0; + if(!op && !adv)return 1; /* just using peek as an inexpensive way + to ask if there's a whole packet + waiting */ + if(op){ + op->b_o_s=os->b_o_s; + if(os->e_o_s && os->body_fill_next==0) + op->e_o_s=os->e_o_s; + else + op->e_o_s=0; + if( (os->body_fill&FINFLAG) && !(os->body_fill_next&FINFLAG) ) + op->granulepos=os->granulepos; + else + op->granulepos=-1; + op->packetno=os->packetno; + } + + if(adv){ + oggbyte_buffer ob; + oggbyte_init(&ob,os->header_tail); + + /* split the body contents off */ + if(op){ + op->packet=ogg_buffer_split(&os->body_tail,&os->body_head, + os->body_fill&FINMASK); + op->bytes=os->body_fill&FINMASK; + }else{ + os->body_tail=ogg_buffer_pretruncate(os->body_tail, + os->body_fill&FINMASK); + if(os->body_tail==0)os->body_head=0; + } + + /* update lacing pointers */ + os->body_fill=os->body_fill_next; + _next_lace(&ob,os); + }else{ + if(op){ + op->packet=ogg_buffer_sub(os->body_tail,0,os->body_fill&FINMASK); + op->bytes=os->body_fill&FINMASK; + } + } + + if(adv){ + os->packetno++; + os->b_o_s=0; + } + + return 1; +} + +int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){ + return _packetout(os,op,1); +} + +int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){ + return _packetout(os,op,0); +} + +int ogg_packet_release(ogg_packet *op) { + if(op){ + ogg_buffer_release(op->packet); + memset(op, 0, sizeof(*op)); + } + return OGG_SUCCESS; +} + +int ogg_page_release(ogg_page *og) { + if(og){ + ogg_buffer_release(og->header); + ogg_buffer_release(og->body); + memset(og, 0, sizeof(*og)); + } + return OGG_SUCCESS; +} + +void ogg_page_dup(ogg_page *dup,ogg_page *orig){ + dup->header_len=orig->header_len; + dup->body_len=orig->body_len; + dup->header=ogg_buffer_dup(orig->header); + dup->body=ogg_buffer_dup(orig->body); +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/info.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/info.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,356 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: maintain the info structure, info <-> header packets + + ********************************************************************/ + +/* general handling of the header and the vorbis_info structure (and + substructures) */ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "codebook.h" +#include "registry.h" +#include "window.h" +#include "misc.h" + +/* helpers */ +static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){ + while(bytes--){ + *buf++=oggpack_read(o,8); + } +} + +void vorbis_comment_init(vorbis_comment *vc){ + memset(vc,0,sizeof(*vc)); +} + +/* This is more or less the same as strncasecmp - but that doesn't exist + * everywhere, and this is a fairly trivial function, so we include it */ +static int tagcompare(const char *s1, const char *s2, int n){ + int c=0; + while(c < n){ + if(toupper(s1[c]) != toupper(s2[c])) + return !0; + c++; + } + return 0; +} + +char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){ + long i; + int found = 0; + int taglen = strlen(tag)+1; /* +1 for the = we append */ + char *fulltag = (char *)alloca(taglen+ 1); + + strcpy(fulltag, tag); + strcat(fulltag, "="); + + for(i=0;icomments;i++){ + if(!tagcompare(vc->user_comments[i], fulltag, taglen)){ + if(count == found) + /* We return a pointer to the data, not a copy */ + return vc->user_comments[i] + taglen; + else + found++; + } + } + return NULL; /* didn't find anything */ +} + +int vorbis_comment_query_count(vorbis_comment *vc, char *tag){ + int i,count=0; + int taglen = strlen(tag)+1; /* +1 for the = we append */ + char *fulltag = (char *)alloca(taglen+1); + strcpy(fulltag,tag); + strcat(fulltag, "="); + + for(i=0;icomments;i++){ + if(!tagcompare(vc->user_comments[i], fulltag, taglen)) + count++; + } + + return count; +} + +void vorbis_comment_clear(vorbis_comment *vc){ + if(vc){ + long i; + for(i=0;icomments;i++) + if(vc->user_comments[i])_ogg_free(vc->user_comments[i]); + if(vc->user_comments)_ogg_free(vc->user_comments); + if(vc->comment_lengths)_ogg_free(vc->comment_lengths); + if(vc->vendor)_ogg_free(vc->vendor); + memset(vc,0,sizeof(*vc)); + } +} + +/* blocksize 0 is guaranteed to be short, 1 is guarantted to be long. + They may be equal, but short will never ge greater than long */ +int vorbis_info_blocksize(vorbis_info *vi,int zo){ + codec_setup_info *ci = (codec_setup_info *)vi->codec_setup; + return ci ? ci->blocksizes[zo] : -1; +} + +/* used by synthesis, which has a full, alloced vi */ +void vorbis_info_init(vorbis_info *vi){ + memset(vi,0,sizeof(*vi)); + vi->codec_setup=(codec_setup_info *)_ogg_calloc(1,sizeof(codec_setup_info)); +} + +void vorbis_info_clear(vorbis_info *vi){ + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + int i; + + if(ci){ + + for(i=0;imodes;i++) + if(ci->mode_param[i])_ogg_free(ci->mode_param[i]); + + for(i=0;imaps;i++) /* unpack does the range checking */ + if(ci->map_param[i]) + _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]); + + for(i=0;ifloors;i++) /* unpack does the range checking */ + if(ci->floor_param[i]) + _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]); + + for(i=0;iresidues;i++) /* unpack does the range checking */ + if(ci->residue_param[i]) + _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]); + + for(i=0;ibooks;i++){ + if(ci->book_param[i]){ + /* knows if the book was not alloced */ + vorbis_staticbook_destroy(ci->book_param[i]); + } + if(ci->fullbooks) + vorbis_book_clear(ci->fullbooks+i); + } + if(ci->fullbooks) + _ogg_free(ci->fullbooks); + + _ogg_free(ci); + } + + memset(vi,0,sizeof(*vi)); +} + +/* Header packing/unpacking ********************************************/ + +static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){ + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + if(!ci)return(OV_EFAULT); + + vi->version=oggpack_read(opb,32); + if(vi->version!=0)return(OV_EVERSION); + + vi->channels=oggpack_read(opb,8); + vi->rate=oggpack_read(opb,32); + + vi->bitrate_upper=oggpack_read(opb,32); + vi->bitrate_nominal=oggpack_read(opb,32); + vi->bitrate_lower=oggpack_read(opb,32); + + ci->blocksizes[0]=1<blocksizes[1]=1<rate<1)goto err_out; + if(vi->channels<1)goto err_out; + if(ci->blocksizes[0]<64)goto err_out; + if(ci->blocksizes[1]blocksizes[0])goto err_out; + if(ci->blocksizes[1]>8192)goto err_out; + + if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ + + return(0); + err_out: + vorbis_info_clear(vi); + return(OV_EBADHEADER); +} + +static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){ + int i; + int vendorlen=oggpack_read(opb,32); + if(vendorlen<0)goto err_out; + vc->vendor=(char *)_ogg_calloc(vendorlen+1,1); + _v_readstring(opb,vc->vendor,vendorlen); + vc->comments=oggpack_read(opb,32); + if(vc->comments<0)goto err_out; + vc->user_comments=(char **)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments)); + vc->comment_lengths=(int *)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths)); + + for(i=0;icomments;i++){ + int len=oggpack_read(opb,32); + if(len<0)goto err_out; + vc->comment_lengths[i]=len; + vc->user_comments[i]=(char *)_ogg_calloc(len+1,1); + _v_readstring(opb,vc->user_comments[i],len); + } + if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */ + + return(0); + err_out: + vorbis_comment_clear(vc); + return(OV_EBADHEADER); +} + +/* all of the real encoding details are here. The modes, books, + everything */ +static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + int i; + if(!ci)return(OV_EFAULT); + + /* codebooks */ + ci->books=oggpack_read(opb,8)+1; + /*ci->book_param=_ogg_calloc(ci->books,sizeof(*ci->book_param));*/ + for(i=0;ibooks;i++){ + ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i])); + if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out; + } + + /* time backend settings */ + ci->times=oggpack_read(opb,6)+1; + /*ci->time_type=_ogg_malloc(ci->times*sizeof(*ci->time_type));*/ + /*ci->time_param=_ogg_calloc(ci->times,sizeof(void *));*/ + for(i=0;itimes;i++){ + ci->time_type[i]=oggpack_read(opb,16); + if(ci->time_type[i]<0 || ci->time_type[i]>=VI_TIMEB)goto err_out; + /* ci->time_param[i]=_time_P[ci->time_type[i]]->unpack(vi,opb); + Vorbis I has no time backend */ + /*if(!ci->time_param[i])goto err_out;*/ + } + + /* floor backend settings */ + ci->floors=oggpack_read(opb,6)+1; + /*ci->floor_type=_ogg_malloc(ci->floors*sizeof(*ci->floor_type));*/ + /*ci->floor_param=_ogg_calloc(ci->floors,sizeof(void *));*/ + for(i=0;ifloors;i++){ + ci->floor_type[i]=oggpack_read(opb,16); + if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out; + ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb); + if(!ci->floor_param[i])goto err_out; + } + + /* residue backend settings */ + ci->residues=oggpack_read(opb,6)+1; + /*ci->residue_type=_ogg_malloc(ci->residues*sizeof(*ci->residue_type));*/ + /*ci->residue_param=_ogg_calloc(ci->residues,sizeof(void *));*/ + for(i=0;iresidues;i++){ + ci->residue_type[i]=oggpack_read(opb,16); + if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out; + ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb); + if(!ci->residue_param[i])goto err_out; + } + + /* map backend settings */ + ci->maps=oggpack_read(opb,6)+1; + /*ci->map_type=_ogg_malloc(ci->maps*sizeof(*ci->map_type));*/ + /*ci->map_param=_ogg_calloc(ci->maps,sizeof(void *));*/ + for(i=0;imaps;i++){ + ci->map_type[i]=oggpack_read(opb,16); + if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out; + ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb); + if(!ci->map_param[i])goto err_out; + } + + /* mode settings */ + ci->modes=oggpack_read(opb,6)+1; + /*vi->mode_param=_ogg_calloc(vi->modes,sizeof(void *));*/ + for(i=0;imodes;i++){ + ci->mode_param[i]=(vorbis_info_mode *)_ogg_calloc(1,sizeof(*ci->mode_param[i])); + ci->mode_param[i]->blockflag=oggpack_read(opb,1); + ci->mode_param[i]->windowtype=oggpack_read(opb,16); + ci->mode_param[i]->transformtype=oggpack_read(opb,16); + ci->mode_param[i]->mapping=oggpack_read(opb,8); + + if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out; + if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out; + if(ci->mode_param[i]->mapping>=ci->maps)goto err_out; + } + + if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */ + + return(0); + err_out: + vorbis_info_clear(vi); + return(OV_EBADHEADER); +} + +/* The Vorbis header is in three packets; the initial small packet in + the first page that identifies basic parameters, a second packet + with bitstream comments and a third packet that holds the + codebook. */ + +int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){ + oggpack_buffer opb; + + if(op){ + oggpack_readinit(&opb,op->packet); + + /* Which of the three types of header is this? */ + /* Also verify header-ness, vorbis */ + { + char buffer[6]; + int packtype=oggpack_read(&opb,8); + memset(buffer,0,6); + _v_readstring(&opb,buffer,6); + if(memcmp(buffer,"vorbis",6)){ + /* not a vorbis header */ + return(OV_ENOTVORBIS); + } + switch(packtype){ + case 0x01: /* least significant *bit* is read first */ + if(!op->b_o_s){ + /* Not the initial packet */ + return(OV_EBADHEADER); + } + if(vi->rate!=0){ + /* previously initialized info header */ + return(OV_EBADHEADER); + } + + return(_vorbis_unpack_info(vi,&opb)); + + case 0x03: /* least significant *bit* is read first */ + if(vi->rate==0){ + /* um... we didn't get the initial header */ + return(OV_EBADHEADER); + } + + return(_vorbis_unpack_comment(vc,&opb)); + + case 0x05: /* least significant *bit* is read first */ + if(vi->rate==0 || vc->vendor==NULL){ + /* um... we didn;t get the initial header or comments yet */ + return(OV_EBADHEADER); + } + + return(_vorbis_unpack_books(vi,&opb)); + + default: + /* Not a valid vorbis header type */ + return(OV_EBADHEADER); + break; + } + } + } + return(OV_EBADHEADER); +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/ivorbiscodec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/ivorbiscodec.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,202 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: libvorbis codec headers + + ********************************************************************/ + +#ifndef _vorbis_codec_h_ +#define _vorbis_codec_h_ + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +#include "ogg.h" + +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; + +/* vorbis_dsp_state buffers the current vorbis audio + analysis/synthesis state. The DSP state belongs to a specific + logical bitstream ****************************************************/ +typedef struct vorbis_dsp_state{ + int analysisp; + vorbis_info *vi; + + ogg_int32_t **pcm; + ogg_int32_t **pcmret; + int pcm_storage; + int pcm_current; + int pcm_returned; + + int preextrapolate; + int eofflag; + + long lW; + long W; + long nW; + long centerW; + + ogg_int64_t granulepos; + ogg_int64_t sequence; + + void *backend_state; +} vorbis_dsp_state; + +typedef struct vorbis_block{ + /* necessary stream state for linking to the framing abstraction */ + ogg_int32_t **pcm; /* this is a pointer into local storage */ + oggpack_buffer opb; + + long lW; + long W; + long nW; + int pcmend; + int mode; + + int eofflag; + ogg_int64_t granulepos; + ogg_int64_t sequence; + vorbis_dsp_state *vd; /* For read-only access of configuration */ + + /* local storage to avoid remallocing; it's up to the mapping to + structure it */ + void *localstore; + long localtop; + long localalloc; + long totaluse; + struct alloc_chain *reap; + +} vorbis_block; + +/* vorbis_block is a single block of data to be processed as part of +the analysis/synthesis stream; it belongs to a specific logical +bitstream, but is independant from other vorbis_blocks belonging to +that logical bitstream. *************************************************/ + +struct alloc_chain{ + void *ptr; + struct alloc_chain *next; +}; + +/* vorbis_info contains all the setup information specific to the + specific compression/decompression mode in progress (eg, + psychoacoustic settings, channel setup, options, codebook + etc). vorbis_info and substructures are in backends.h. +*********************************************************************/ + +/* the comments are not part of vorbis_info so that vorbis_info can be + static storage */ +typedef struct vorbis_comment{ + /* unlimited user comment fields. libvorbis writes 'libvorbis' + whatever vendor is set to in encode */ + char **user_comments; + int *comment_lengths; + int comments; + char *vendor; + +} vorbis_comment; + + +/* libvorbis encodes in two abstraction layers; first we perform DSP + and produce a packet (see docs/analysis.txt). The packet is then + coded into a framed OggSquish bitstream by the second layer (see + docs/framing.txt). Decode is the reverse process; we sync/frame + the bitstream and extract individual packets, then decode the + packet back into PCM audio. + + The extra framing/packetizing is used in streaming formats, such as + files. Over the net (such as with UDP), the framing and + packetization aren't necessary as they're provided by the transport + and the streaming layer is not used */ + +/* 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); + +extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); +extern int vorbis_block_clear(vorbis_block *vb); +extern void vorbis_dsp_clear(vorbis_dsp_state *v); + +/* Vorbis PRIMITIVES: synthesis layer *******************************/ +extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, + ogg_packet *op); + +extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); +extern int vorbis_synthesis_restart(vorbis_dsp_state *v); +extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep); +extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); +extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm); +extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples); +extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); + +/* 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 + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/ivorbisfile.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/ivorbisfile.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,130 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: stdio-based convenience library for opening/seeking/decoding + + ********************************************************************/ + +#ifndef _OV_FILE_H_ +#define _OV_FILE_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +#include +#include "ivorbiscodec.h" + +#define CHUNKSIZE 1024 +/* 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; + +#define NOTOPEN 0 +#define PARTOPEN 1 +#define OPENED 2 +#define STREAMSET 3 +#define INITSET 4 + +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 */ + vorbis_block vb; /* local working space for packet->PCM decode */ + + 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,char *buffer,int length, + int *bitstream); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/ivorbisfile_example.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/ivorbisfile_example.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,86 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: simple example decoder using vorbisidec + + ********************************************************************/ + +/* Takes a vorbis bitstream from stdin and writes raw stereo PCM to + stdout using vorbisfile. Using vorbisfile is much simpler than + dealing with libvorbis. */ + +#include +#include +#include +#include + +#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ +#include +#include +#endif + +char pcmout[4096]; /* take 4k out of the data segment, not the stack */ + +int main(){ + OggVorbis_File vf; + int eof=0; + int current_section; + +#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */ + /* Beware the evil ifdef. We avoid these where we can, but this one we + cannot. Don't add any more, you'll probably go to hell if you do. */ + _setmode( _fileno( stdin ), _O_BINARY ); + _setmode( _fileno( stdout ), _O_BINARY ); +#endif + + if(ov_open(stdin, &vf, NULL, 0) < 0) { + fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); + exit(1); + } + + /* Throw the comments plus a few lines about the bitstream we're + decoding */ + { + char **ptr=ov_comment(&vf,-1)->user_comments; + vorbis_info *vi=ov_info(&vf,-1); + while(*ptr){ + fprintf(stderr,"%s\n",*ptr); + ++ptr; + } + fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); + fprintf(stderr,"\nDecoded length: %ld samples\n", + (long)ov_pcm_total(&vf,-1)); + fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); + } + + while(!eof){ + long ret=ov_read(&vf,pcmout,sizeof(pcmout),¤t_section); + if (ret == 0) { + /* EOF */ + eof=1; + } else if (ret < 0) { + /* error in the stream. Not a problem, just reporting it in + case we (the app) cares. In this case, we don't. */ + } else { + /* we don't bother dealing with sample rate changes, etc, but + you'll have to*/ + fwrite(pcmout,1,ret,stdout); + } + } + + /* cleanup */ + ov_clear(&vf); + + fprintf(stderr,"Done.\n"); + return(0); +} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/lsp_lookup.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/lsp_lookup.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,136 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: lookup data + + ********************************************************************/ + +#ifndef _V_LOOKUP_DATA_H_ +#define _V_LOOKUP_DATA_H_ + +#include "os_types.h" + +#define FROMdB_LOOKUP_SZ 35 +#define FROMdB2_LOOKUP_SZ 32 +#define FROMdB_SHIFT 5 +#define FROMdB2_SHIFT 3 +#define FROMdB2_MASK 31 + +static const ogg_int32_t FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={ + 0x003fffff, 0x0028619b, 0x00197a96, 0x0010137a, + 0x000a24b0, 0x00066666, 0x000409c3, 0x00028c42, + 0x00019b8c, 0x000103ab, 0x0000a3d7, 0x00006760, + 0x0000413a, 0x00002928, 0x000019f8, 0x00001062, + 0x00000a56, 0x00000686, 0x0000041e, 0x00000299, + 0x000001a3, 0x00000109, 0x000000a7, 0x00000069, + 0x00000042, 0x0000002a, 0x0000001a, 0x00000011, + 0x0000000b, 0x00000007, 0x00000004, 0x00000003, + 0x00000002, 0x00000001, 0x00000001}; + +static const ogg_int32_t FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={ + 0x000001fc, 0x000001f5, 0x000001ee, 0x000001e7, + 0x000001e0, 0x000001d9, 0x000001d2, 0x000001cc, + 0x000001c5, 0x000001bf, 0x000001b8, 0x000001b2, + 0x000001ac, 0x000001a6, 0x000001a0, 0x0000019a, + 0x00000194, 0x0000018e, 0x00000188, 0x00000183, + 0x0000017d, 0x00000178, 0x00000172, 0x0000016d, + 0x00000168, 0x00000163, 0x0000015e, 0x00000159, + 0x00000154, 0x0000014f, 0x0000014a, 0x00000145, +}; + +#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 + + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/mapping0.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/mapping0.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,322 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: channel mapping 0 implementation + + ********************************************************************/ + +#include +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "mdct.h" +#include "codec_internal.h" +#include "codebook.h" +#include "window.h" +#include "registry.h" +#include "misc.h" + +/* simplistic, wasteful way of doing this (unique lookup for each + mode/submapping); there should be a central repository for + identical lookups. That will require minor work, so I'm putting it + off as low priority. + + Why a lookup for each backend in a given mode? Because the + blocksize is set by the mode, and low backend lookups may require + parameters from other areas of the mode/mapping */ + +typedef struct { + vorbis_info_mode *mode; + vorbis_info_mapping0 *map; + + vorbis_look_floor **floor_look; + + vorbis_look_residue **residue_look; + + vorbis_func_floor **floor_func; + vorbis_func_residue **residue_func; + + int ch; + long lastframe; /* if a different mode is called, we need to + invalidate decay */ +} vorbis_look_mapping0; + +static void mapping0_free_info(vorbis_info_mapping *i){ + vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i; + if(info){ + memset(info,0,sizeof(*info)); + _ogg_free(info); + } +} + +static void mapping0_free_look(vorbis_look_mapping *look){ + int i; + vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look; + if(l){ + + for(i=0;imap->submaps;i++){ + l->floor_func[i]->free_look(l->floor_look[i]); + l->residue_func[i]->free_look(l->residue_look[i]); + } + + _ogg_free(l->floor_func); + _ogg_free(l->residue_func); + _ogg_free(l->floor_look); + _ogg_free(l->residue_look); + memset(l,0,sizeof(*l)); + _ogg_free(l); + } +} + +static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, + vorbis_info_mapping *m){ + int i; + vorbis_info *vi=vd->vi; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look)); + vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m; + look->mode=vm; + + look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look)); + + look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look)); + + look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func)); + look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func)); + + for(i=0;isubmaps;i++){ + int floornum=info->floorsubmap[i]; + int resnum=info->residuesubmap[i]; + + look->floor_func[i]=_floor_P[ci->floor_type[floornum]]; + look->floor_look[i]=look->floor_func[i]-> + look(vd,vm,ci->floor_param[floornum]); + look->residue_func[i]=_residue_P[ci->residue_type[resnum]]; + look->residue_look[i]=look->residue_func[i]-> + look(vd,vm,ci->residue_param[resnum]); + + } + + look->ch=vi->channels; + + return(look); +} + +static int ilog(unsigned int v){ + int ret=0; + if(v)--v; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +/* also responsible for range checking */ +static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){ + int i; + vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info)); + 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; + + for(i=0;icoupling_steps;i++){ + int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels)); + int testA=info->coupling_ang[i]=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){ + for(i=0;ichannels;i++){ + info->chmuxlist[i]=oggpack_read(opb,4); + if(info->chmuxlist[i]>=info->submaps)goto err_out; + } + } + for(i=0;isubmaps;i++){ + int temp=oggpack_read(opb,8); + if(temp>=ci->times)goto err_out; + info->floorsubmap[i]=oggpack_read(opb,8); + if(info->floorsubmap[i]>=ci->floors)goto err_out; + info->residuesubmap[i]=oggpack_read(opb,8); + if(info->residuesubmap[i]>=ci->residues)goto err_out; + } + + return info; + + err_out: + mapping0_free_info(info); + return(NULL); +} + +static int seq=0; +static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ + vorbis_dsp_state *vd=vb->vd; + vorbis_info *vi=vd->vi; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + private_state *b=(private_state *)vd->backend_state; + vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l; + vorbis_info_mapping0 *info=look->map; + + int i,j; + long n=vb->pcmend=ci->blocksizes[vb->W]; + + ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); + int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels); + + int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels); + void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels); + + /* time domain information decode (note that applying the + information would have to happen later; we'll probably add a + function entry to the harness for that later */ + /* NOT IMPLEMENTED */ + + /* recover the spectral envelope; store it in the PCM vector for now */ + for(i=0;ichannels;i++){ + int submap=info->chmuxlist[i]; + floormemo[i]=look->floor_func[submap]-> + inverse1(vb,look->floor_look[submap]); + if(floormemo[i]) + nonzero[i]=1; + else + nonzero[i]=0; + memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2); + } + + /* channel coupling can 'dirty' the nonzero listing */ + for(i=0;icoupling_steps;i++){ + if(nonzero[info->coupling_mag[i]] || + nonzero[info->coupling_ang[i]]){ + nonzero[info->coupling_mag[i]]=1; + nonzero[info->coupling_ang[i]]=1; + } + } + + /* recover the residue into our working vectors */ + for(i=0;isubmaps;i++){ + int ch_in_bundle=0; + for(j=0;jchannels;j++){ + if(info->chmuxlist[j]==i){ + if(nonzero[j]) + zerobundle[ch_in_bundle]=1; + else + zerobundle[ch_in_bundle]=0; + pcmbundle[ch_in_bundle++]=vb->pcm[j]; + } + } + + look->residue_func[i]->inverse(vb,look->residue_look[i], + pcmbundle,zerobundle,ch_in_bundle); + } + + //for(j=0;jchannels;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=vb->pcm[info->coupling_mag[i]]; + ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]]; + + for(j=0;j0) + 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;jchannels;j++) + //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0); + + /* compute and apply spectral envelope */ + for(i=0;ichannels;i++){ + ogg_int32_t *pcm=vb->pcm[i]; + int submap=info->chmuxlist[i]; + look->floor_func[submap]-> + inverse2(vb,look->floor_look[submap],floormemo[i],pcm); + } + + //for(j=0;jchannels;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;ichannels;i++){ + ogg_int32_t *pcm=vb->pcm[i]; + mdct_backward(n,pcm,pcm); + } + + //for(j=0;jchannels;j++) + //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0); + + /* window the data */ + for(i=0;ichannels;i++){ + ogg_int32_t *pcm=vb->pcm[i]; + if(nonzero[i]) + _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); + else + for(j=0;jchannels;j++) + //_analysis_output("window",seq+j,vb->pcm[j],-24,n,0,0); + + seq+=vi->channels; + /* all done! */ + return(0); +} + +/* export hooks */ +vorbis_func_mapping mapping0_exportbundle={ + &mapping0_unpack, + &mapping0_look, + &mapping0_free_info, + &mapping0_free_look, + &mapping0_inverse +}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/mdct.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/mdct.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,510 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: normalized modified discrete cosine transform + power of two length transform only [64 <= n ] + last mod: $Id: mdct.c,v 1.9 2002/10/16 09:17:39 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 "codebook.h" +#include "misc.h" +#include "mdct.h" +#include "mdct_lookup.h" + + +/* 8 point butterfly (in place) */ +STIN void mdct_butterfly_8(DATA_TYPE *x){ + + REG_TYPE r0 = x[4] + x[0]; + REG_TYPE r1 = x[4] - x[0]; + REG_TYPE r2 = x[5] + x[1]; + REG_TYPE r3 = x[5] - x[1]; + REG_TYPE r4 = x[6] + x[2]; + REG_TYPE r5 = x[6] - x[2]; + REG_TYPE r6 = x[7] + x[3]; + REG_TYPE r7 = x[7] - x[3]; + + x[0] = r5 + r3; + x[1] = r7 - r1; + x[2] = r5 - r3; + x[3] = r7 + r1; + x[4] = r4 - r0; + x[5] = r6 - r2; + x[6] = r4 + r0; + x[7] = r6 + r2; + MB(); +} + +/* 16 point butterfly (in place, 4 register) */ +STIN void mdct_butterfly_16(DATA_TYPE *x){ + + REG_TYPE r0, r1; + + r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; + r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; + x[ 0] = MULT31((r0 + r1) , cPI2_8); + x[ 1] = MULT31((r1 - r0) , cPI2_8); + MB(); + + r0 = x[10] - x[ 2]; x[10] += x[ 2]; + r1 = x[ 3] - x[11]; x[11] += x[ 3]; + x[ 2] = r1; x[ 3] = r0; + MB(); + + r0 = x[12] - x[ 4]; x[12] += x[ 4]; + r1 = x[13] - x[ 5]; x[13] += x[ 5]; + x[ 4] = MULT31((r0 - r1) , cPI2_8); + x[ 5] = MULT31((r0 + r1) , cPI2_8); + MB(); + + r0 = x[14] - x[ 6]; x[14] += x[ 6]; + r1 = x[15] - x[ 7]; x[15] += x[ 7]; + x[ 6] = r0; x[ 7] = r1; + 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 r0, r1; + + r0 = x[30] - x[14]; x[30] += x[14]; + r1 = x[31] - x[15]; x[31] += x[15]; + x[14] = r0; x[15] = r1; + MB(); + + r0 = x[28] - x[12]; x[28] += x[12]; + r1 = x[29] - x[13]; x[29] += x[13]; + XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); + MB(); + + r0 = x[26] - x[10]; x[26] += x[10]; + r1 = x[27] - x[11]; x[27] += x[11]; + x[10] = MULT31((r0 - r1) , cPI2_8); + x[11] = MULT31((r0 + r1) , cPI2_8); + MB(); + + r0 = x[24] - x[ 8]; x[24] += x[ 8]; + r1 = x[25] - x[ 9]; x[25] += x[ 9]; + XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); + MB(); + + r0 = x[22] - x[ 6]; x[22] += x[ 6]; + r1 = x[ 7] - x[23]; x[23] += x[ 7]; + x[ 6] = r1; x[ 7] = r0; + MB(); + + r0 = x[ 4] - x[20]; x[20] += x[ 4]; + r1 = x[ 5] - x[21]; x[21] += x[ 5]; + XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); + MB(); + + r0 = x[ 2] - x[18]; x[18] += x[ 2]; + r1 = x[ 3] - x[19]; x[19] += x[ 3]; + x[ 2] = MULT31((r1 + r0) , cPI2_8); + x[ 3] = MULT31((r1 - r0) , cPI2_8); + MB(); + + r0 = x[ 0] - x[16]; x[16] += x[ 0]; + r1 = x[ 1] - x[17]; x[17] += x[ 1]; + XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); + 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 - 8; + DATA_TYPE *x2 = x + (points>>1) - 8; + REG_TYPE r0; + REG_TYPE r1; + + do{ + r0 = x1[6] - x2[6]; x1[6] += x2[6]; + r1 = x2[7] - x1[7]; x1[7] += x2[7]; + XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step; + + r0 = x1[4] - x2[4]; x1[4] += x2[4]; + r1 = x2[5] - x1[5]; x1[5] += x2[5]; + XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step; + + r0 = x1[2] - x2[2]; x1[2] += x2[2]; + r1 = x2[3] - x1[3]; x1[3] += x2[3]; + XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step; + + r0 = x1[0] - x2[0]; x1[0] += x2[0]; + r1 = x2[1] - x1[1]; x1[1] += x2[1]; + XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step; + + x1-=8; x2-=8; + }while(Tsincos_lookup0); + do{ + r0 = x2[6] - x1[6]; x1[6] += x2[6]; + r1 = x2[7] - x1[7]; x1[7] += x2[7]; + XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step; + + r0 = x2[4] - x1[4]; x1[4] += x2[4]; + r1 = x2[5] - x1[5]; x1[5] += x2[5]; + XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step; + + r0 = x2[2] - x1[2]; x1[2] += x2[2]; + r1 = x2[3] - x1[3]; x1[3] += x2[3]; + XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step; + + r0 = x2[0] - x1[0]; x1[0] += x2[0]; + r1 = x2[1] - x1[1]; x1[1] += x2[1]; + XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step; + + x1-=8; x2-=8; + }while(Tsincos_lookup0); +} + +STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ + + int stages=8-shift; + int i,j; + + for(i=0;--stages>0;i++){ + for(j=0;j<(1<>i)*j,points>>i,4<<(i+shift)); + } + + for(j=0;j>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8); +} + +STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ + + int bit = 0; + DATA_TYPE *w0 = x; + DATA_TYPE *w1 = x = w0+(n>>1); + LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; + LOOKUP_T *Ttop = T+1024; + DATA_TYPE r2; + + do{ + DATA_TYPE r3 = bitrev12(bit++); + DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1; + DATA_TYPE *x1 = x + (r3>>shift); + + REG_TYPE r0 = x0[0] + x1[0]; + REG_TYPE r1 = x1[1] - x0[1]; + + XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; + + w1 -= 4; + + r0 = (x0[1] + x1[1])>>1; + r1 = (x0[0] - x1[0])>>1; + w0[0] = r0 + r2; + w0[1] = r1 + r3; + w1[2] = r0 - r2; + w1[3] = r3 - r1; + + r3 = bitrev12(bit++); + x0 = x + ((r3 ^ 0xfff)>>shift) -1; + x1 = x + (r3>>shift); + + r0 = x0[0] + x1[0]; + r1 = x1[1] - x0[1]; + + XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; + + r0 = (x0[1] + x1[1])>>1; + r1 = (x0[0] - x1[0])>>1; + w0[2] = r0 + r2; + w0[3] = r1 + r3; + w1[0] = r0 - r2; + w1[1] = r3 - r1; + + w0 += 4; + }while(T>shift) -1; + DATA_TYPE *x1 = x + (r3>>shift); + + REG_TYPE r0 = x0[0] + x1[0]; + REG_TYPE r1 = x1[1] - x0[1]; + + T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); + + w1 -= 4; + + r0 = (x0[1] + x1[1])>>1; + r1 = (x0[0] - x1[0])>>1; + w0[0] = r0 + r2; + w0[1] = r1 + r3; + w1[2] = r0 - r2; + w1[3] = r3 - r1; + + r3 = bitrev12(bit++); + x0 = x + ((r3 ^ 0xfff)>>shift) -1; + x1 = x + (r3>>shift); + + r0 = x0[0] + x1[0]; + r1 = x1[1] - x0[1]; + + T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); + + r0 = (x0[1] + x1[1])>>1; + r1 = (x0[0] - x1[0])>>1; + w0[2] = r0 + r2; + w0[3] = r1 + r3; + w1[0] = r0 - r2; + w1[1] = r3 - r1; + + w0 += 4; + }while(w0>1; + int n4=n>>2; + DATA_TYPE *iX; + DATA_TYPE *oX; + LOOKUP_T *T; + LOOKUP_T *V; + int shift; + int step; + + for (shift=6;!(n&(1<=in+n4); + do{ + oX-=4; + XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step; + XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step; + iX-=8; + }while(iX>=in); + + iX = in+n2-8; + oX = out+n2+n4; + T = sincos_lookup0; + + do{ + T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] ); + T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] ); + iX-=8; + oX+=4; + }while(iX>=in+n4); + do{ + T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] ); + T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] ); + iX-=8; + oX+=4; + }while(iX>=in); + + mdct_butterflies(out+n2,n2,shift); + mdct_bitreverse(out,n,step,shift); + + /* rotate + window */ + + step>>=2; + { + DATA_TYPE *oX1=out+n2+n4; + DATA_TYPE *oX2=out+n2+n4; + DATA_TYPE *iX =out; + + switch(step) { + default: { + T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; + do{ + oX1-=4; + XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step; + XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step; + XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step; + XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step; + oX2+=4; + iX+=8; + }while(iX>1; + t1 = (*T++)>>1; + do{ + oX1-=4; + + t0 += (v0 = (*V++)>>1); + t1 += (v1 = (*V++)>>1); + XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); + v0 += (t0 = (*T++)>>1); + v1 += (t1 = (*T++)>>1); + XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); + t0 += (v0 = (*V++)>>1); + t1 += (v1 = (*V++)>>1); + XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); + v0 += (t0 = (*T++)>>1); + v1 += (t1 = (*T++)>>1); + XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); + + oX2+=4; + iX+=8; + }while(iX>2); + t1 += (q1 = (v1-t1)>>2); + XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); + t0 = v0-q0; + t1 = v1-q1; + XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); + + t0 = *T++; + t1 = *T++; + v0 += (q0 = (t0-v0)>>2); + v1 += (q1 = (t1-v1)>>2); + XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); + v0 = t0-q0; + v1 = t1-q1; + XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); + + oX2+=4; + iX+=8; + }while(iXoX2); + } +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/mdct.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/mdct.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,52 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: modified discrete cosine transform prototypes + + ********************************************************************/ + +#ifndef _OGG_mdct_H_ +#define _OGG_mdct_H_ + +#include "ivorbiscodec.h" +#include "misc.h" + +#define DATA_TYPE ogg_int32_t +#define REG_TYPE register ogg_int32_t + +#ifdef _LOW_ACCURACY_ +#define cPI3_8 (0x0062) +#define cPI2_8 (0x00b5) +#define cPI1_8 (0x00ed) +#else +#define cPI3_8 (0x30fbc54d) +#define cPI2_8 (0x5a82799a) +#define cPI1_8 (0x7641af3d) +#endif + +extern void mdct_forward(int n, DATA_TYPE *in, DATA_TYPE *out); +extern void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out); + +#endif + + + + + + + + + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/mdct_lookup.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/mdct_lookup.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,540 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: sin,cos lookup tables + + ********************************************************************/ + +#include "os_types.h" + +/* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */ +static LOOKUP_T sincos_lookup0[1026] = { + X(0x00000000), X(0x7fffffff), X(0x003243f5), X(0x7ffff621), + X(0x006487e3), X(0x7fffd886), X(0x0096cbc1), X(0x7fffa72c), + X(0x00c90f88), X(0x7fff6216), X(0x00fb5330), X(0x7fff0943), + X(0x012d96b1), X(0x7ffe9cb2), X(0x015fda03), X(0x7ffe1c65), + X(0x01921d20), X(0x7ffd885a), X(0x01c45ffe), X(0x7ffce093), + X(0x01f6a297), X(0x7ffc250f), X(0x0228e4e2), X(0x7ffb55ce), + X(0x025b26d7), X(0x7ffa72d1), X(0x028d6870), X(0x7ff97c18), + X(0x02bfa9a4), X(0x7ff871a2), X(0x02f1ea6c), X(0x7ff75370), + X(0x03242abf), X(0x7ff62182), X(0x03566a96), X(0x7ff4dbd9), + X(0x0388a9ea), X(0x7ff38274), X(0x03bae8b2), X(0x7ff21553), + X(0x03ed26e6), X(0x7ff09478), X(0x041f6480), X(0x7feeffe1), + X(0x0451a177), X(0x7fed5791), X(0x0483ddc3), X(0x7feb9b85), + X(0x04b6195d), X(0x7fe9cbc0), X(0x04e8543e), X(0x7fe7e841), + X(0x051a8e5c), X(0x7fe5f108), X(0x054cc7b1), X(0x7fe3e616), + X(0x057f0035), X(0x7fe1c76b), X(0x05b137df), X(0x7fdf9508), + X(0x05e36ea9), X(0x7fdd4eec), X(0x0615a48b), X(0x7fdaf519), + X(0x0647d97c), X(0x7fd8878e), X(0x067a0d76), X(0x7fd6064c), + X(0x06ac406f), X(0x7fd37153), X(0x06de7262), X(0x7fd0c8a3), + X(0x0710a345), X(0x7fce0c3e), X(0x0742d311), X(0x7fcb3c23), + X(0x077501be), X(0x7fc85854), X(0x07a72f45), X(0x7fc560cf), + X(0x07d95b9e), X(0x7fc25596), X(0x080b86c2), X(0x7fbf36aa), + X(0x083db0a7), X(0x7fbc040a), X(0x086fd947), X(0x7fb8bdb8), + X(0x08a2009a), X(0x7fb563b3), X(0x08d42699), X(0x7fb1f5fc), + X(0x09064b3a), X(0x7fae7495), X(0x09386e78), X(0x7faadf7c), + X(0x096a9049), X(0x7fa736b4), X(0x099cb0a7), X(0x7fa37a3c), + X(0x09cecf89), X(0x7f9faa15), X(0x0a00ece8), X(0x7f9bc640), + X(0x0a3308bd), X(0x7f97cebd), X(0x0a6522fe), X(0x7f93c38c), + X(0x0a973ba5), X(0x7f8fa4b0), X(0x0ac952aa), X(0x7f8b7227), + X(0x0afb6805), X(0x7f872bf3), X(0x0b2d7baf), X(0x7f82d214), + X(0x0b5f8d9f), X(0x7f7e648c), X(0x0b919dcf), X(0x7f79e35a), + X(0x0bc3ac35), X(0x7f754e80), X(0x0bf5b8cb), X(0x7f70a5fe), + X(0x0c27c389), X(0x7f6be9d4), X(0x0c59cc68), X(0x7f671a05), + X(0x0c8bd35e), X(0x7f62368f), X(0x0cbdd865), X(0x7f5d3f75), + X(0x0cefdb76), X(0x7f5834b7), X(0x0d21dc87), X(0x7f531655), + X(0x0d53db92), X(0x7f4de451), X(0x0d85d88f), X(0x7f489eaa), + X(0x0db7d376), X(0x7f434563), X(0x0de9cc40), X(0x7f3dd87c), + X(0x0e1bc2e4), X(0x7f3857f6), X(0x0e4db75b), X(0x7f32c3d1), + X(0x0e7fa99e), X(0x7f2d1c0e), X(0x0eb199a4), X(0x7f2760af), + X(0x0ee38766), X(0x7f2191b4), X(0x0f1572dc), X(0x7f1baf1e), + X(0x0f475bff), X(0x7f15b8ee), X(0x0f7942c7), X(0x7f0faf25), + X(0x0fab272b), X(0x7f0991c4), X(0x0fdd0926), X(0x7f0360cb), + X(0x100ee8ad), X(0x7efd1c3c), X(0x1040c5bb), X(0x7ef6c418), + X(0x1072a048), X(0x7ef05860), X(0x10a4784b), X(0x7ee9d914), + X(0x10d64dbd), X(0x7ee34636), X(0x11082096), X(0x7edc9fc6), + X(0x1139f0cf), X(0x7ed5e5c6), X(0x116bbe60), X(0x7ecf1837), + X(0x119d8941), X(0x7ec8371a), X(0x11cf516a), X(0x7ec14270), + X(0x120116d5), X(0x7eba3a39), X(0x1232d979), X(0x7eb31e78), + X(0x1264994e), X(0x7eabef2c), X(0x1296564d), X(0x7ea4ac58), + X(0x12c8106f), X(0x7e9d55fc), X(0x12f9c7aa), X(0x7e95ec1a), + X(0x132b7bf9), X(0x7e8e6eb2), X(0x135d2d53), X(0x7e86ddc6), + X(0x138edbb1), X(0x7e7f3957), X(0x13c0870a), X(0x7e778166), + X(0x13f22f58), X(0x7e6fb5f4), X(0x1423d492), X(0x7e67d703), + X(0x145576b1), X(0x7e5fe493), X(0x148715ae), X(0x7e57dea7), + X(0x14b8b17f), X(0x7e4fc53e), X(0x14ea4a1f), X(0x7e47985b), + X(0x151bdf86), X(0x7e3f57ff), X(0x154d71aa), X(0x7e37042a), + X(0x157f0086), X(0x7e2e9cdf), X(0x15b08c12), X(0x7e26221f), + X(0x15e21445), X(0x7e1d93ea), X(0x16139918), X(0x7e14f242), + X(0x16451a83), X(0x7e0c3d29), X(0x1676987f), X(0x7e0374a0), + X(0x16a81305), X(0x7dfa98a8), X(0x16d98a0c), X(0x7df1a942), + X(0x170afd8d), X(0x7de8a670), X(0x173c6d80), X(0x7ddf9034), + X(0x176dd9de), X(0x7dd6668f), X(0x179f429f), X(0x7dcd2981), + X(0x17d0a7bc), X(0x7dc3d90d), X(0x1802092c), X(0x7dba7534), + X(0x183366e9), X(0x7db0fdf8), X(0x1864c0ea), X(0x7da77359), + X(0x18961728), X(0x7d9dd55a), X(0x18c7699b), X(0x7d9423fc), + X(0x18f8b83c), X(0x7d8a5f40), X(0x192a0304), X(0x7d808728), + X(0x195b49ea), X(0x7d769bb5), X(0x198c8ce7), X(0x7d6c9ce9), + X(0x19bdcbf3), X(0x7d628ac6), X(0x19ef0707), X(0x7d58654d), + X(0x1a203e1b), X(0x7d4e2c7f), X(0x1a517128), X(0x7d43e05e), + X(0x1a82a026), X(0x7d3980ec), X(0x1ab3cb0d), X(0x7d2f0e2b), + X(0x1ae4f1d6), X(0x7d24881b), X(0x1b161479), X(0x7d19eebf), + X(0x1b4732ef), X(0x7d0f4218), X(0x1b784d30), X(0x7d048228), + X(0x1ba96335), X(0x7cf9aef0), X(0x1bda74f6), X(0x7ceec873), + X(0x1c0b826a), X(0x7ce3ceb2), X(0x1c3c8b8c), X(0x7cd8c1ae), + X(0x1c6d9053), X(0x7ccda169), X(0x1c9e90b8), X(0x7cc26de5), + X(0x1ccf8cb3), X(0x7cb72724), X(0x1d00843d), X(0x7cabcd28), + X(0x1d31774d), X(0x7ca05ff1), X(0x1d6265dd), X(0x7c94df83), + X(0x1d934fe5), X(0x7c894bde), X(0x1dc4355e), X(0x7c7da505), + X(0x1df5163f), X(0x7c71eaf9), X(0x1e25f282), X(0x7c661dbc), + X(0x1e56ca1e), X(0x7c5a3d50), X(0x1e879d0d), X(0x7c4e49b7), + X(0x1eb86b46), X(0x7c4242f2), X(0x1ee934c3), X(0x7c362904), + X(0x1f19f97b), X(0x7c29fbee), X(0x1f4ab968), X(0x7c1dbbb3), + X(0x1f7b7481), X(0x7c116853), X(0x1fac2abf), X(0x7c0501d2), + X(0x1fdcdc1b), X(0x7bf88830), X(0x200d888d), X(0x7bebfb70), + X(0x203e300d), X(0x7bdf5b94), X(0x206ed295), X(0x7bd2a89e), + X(0x209f701c), X(0x7bc5e290), X(0x20d0089c), X(0x7bb9096b), + X(0x21009c0c), X(0x7bac1d31), X(0x21312a65), X(0x7b9f1de6), + X(0x2161b3a0), X(0x7b920b89), X(0x219237b5), X(0x7b84e61f), + X(0x21c2b69c), X(0x7b77ada8), X(0x21f3304f), X(0x7b6a6227), + X(0x2223a4c5), X(0x7b5d039e), X(0x225413f8), X(0x7b4f920e), + X(0x22847de0), X(0x7b420d7a), X(0x22b4e274), X(0x7b3475e5), + X(0x22e541af), X(0x7b26cb4f), X(0x23159b88), X(0x7b190dbc), + X(0x2345eff8), X(0x7b0b3d2c), X(0x23763ef7), X(0x7afd59a4), + X(0x23a6887f), X(0x7aef6323), X(0x23d6cc87), X(0x7ae159ae), + X(0x24070b08), X(0x7ad33d45), X(0x243743fa), X(0x7ac50dec), + X(0x24677758), X(0x7ab6cba4), X(0x2497a517), X(0x7aa8766f), + X(0x24c7cd33), X(0x7a9a0e50), X(0x24f7efa2), X(0x7a8b9348), + X(0x25280c5e), X(0x7a7d055b), X(0x2558235f), X(0x7a6e648a), + X(0x2588349d), X(0x7a5fb0d8), X(0x25b84012), X(0x7a50ea47), + X(0x25e845b6), X(0x7a4210d8), X(0x26184581), X(0x7a332490), + X(0x26483f6c), X(0x7a24256f), X(0x26783370), X(0x7a151378), + X(0x26a82186), X(0x7a05eead), X(0x26d809a5), X(0x79f6b711), + X(0x2707ebc7), X(0x79e76ca7), X(0x2737c7e3), X(0x79d80f6f), + X(0x27679df4), X(0x79c89f6e), X(0x27976df1), X(0x79b91ca4), + X(0x27c737d3), X(0x79a98715), X(0x27f6fb92), X(0x7999dec4), + X(0x2826b928), X(0x798a23b1), X(0x2856708d), X(0x797a55e0), + X(0x288621b9), X(0x796a7554), X(0x28b5cca5), X(0x795a820e), + X(0x28e5714b), X(0x794a7c12), X(0x29150fa1), X(0x793a6361), + X(0x2944a7a2), X(0x792a37fe), X(0x29743946), X(0x7919f9ec), + X(0x29a3c485), X(0x7909a92d), X(0x29d34958), X(0x78f945c3), + X(0x2a02c7b8), X(0x78e8cfb2), X(0x2a323f9e), X(0x78d846fb), + X(0x2a61b101), X(0x78c7aba2), X(0x2a911bdc), X(0x78b6fda8), + X(0x2ac08026), X(0x78a63d11), X(0x2aefddd8), X(0x789569df), + X(0x2b1f34eb), X(0x78848414), X(0x2b4e8558), X(0x78738bb3), + X(0x2b7dcf17), X(0x786280bf), X(0x2bad1221), X(0x7851633b), + X(0x2bdc4e6f), X(0x78403329), X(0x2c0b83fa), X(0x782ef08b), + X(0x2c3ab2b9), X(0x781d9b65), X(0x2c69daa6), X(0x780c33b8), + X(0x2c98fbba), X(0x77fab989), X(0x2cc815ee), X(0x77e92cd9), + X(0x2cf72939), X(0x77d78daa), X(0x2d263596), X(0x77c5dc01), + X(0x2d553afc), X(0x77b417df), X(0x2d843964), X(0x77a24148), + X(0x2db330c7), X(0x7790583e), X(0x2de2211e), X(0x777e5cc3), + X(0x2e110a62), X(0x776c4edb), X(0x2e3fec8b), X(0x775a2e89), + X(0x2e6ec792), X(0x7747fbce), X(0x2e9d9b70), X(0x7735b6af), + X(0x2ecc681e), X(0x77235f2d), X(0x2efb2d95), X(0x7710f54c), + X(0x2f29ebcc), X(0x76fe790e), X(0x2f58a2be), X(0x76ebea77), + X(0x2f875262), X(0x76d94989), X(0x2fb5fab2), X(0x76c69647), + X(0x2fe49ba7), X(0x76b3d0b4), X(0x30133539), X(0x76a0f8d2), + X(0x3041c761), X(0x768e0ea6), X(0x30705217), X(0x767b1231), + X(0x309ed556), X(0x76680376), X(0x30cd5115), X(0x7654e279), + X(0x30fbc54d), X(0x7641af3d), X(0x312a31f8), X(0x762e69c4), + X(0x3158970e), X(0x761b1211), X(0x3186f487), X(0x7607a828), + X(0x31b54a5e), X(0x75f42c0b), X(0x31e39889), X(0x75e09dbd), + X(0x3211df04), X(0x75ccfd42), X(0x32401dc6), X(0x75b94a9c), + X(0x326e54c7), X(0x75a585cf), X(0x329c8402), X(0x7591aedd), + X(0x32caab6f), X(0x757dc5ca), X(0x32f8cb07), X(0x7569ca99), + X(0x3326e2c3), X(0x7555bd4c), X(0x3354f29b), X(0x75419de7), + X(0x3382fa88), X(0x752d6c6c), X(0x33b0fa84), X(0x751928e0), + X(0x33def287), X(0x7504d345), X(0x340ce28b), X(0x74f06b9e), + X(0x343aca87), X(0x74dbf1ef), X(0x3468aa76), X(0x74c7663a), + X(0x34968250), X(0x74b2c884), X(0x34c4520d), X(0x749e18cd), + X(0x34f219a8), X(0x7489571c), X(0x351fd918), X(0x74748371), + X(0x354d9057), X(0x745f9dd1), X(0x357b3f5d), X(0x744aa63f), + X(0x35a8e625), X(0x74359cbd), X(0x35d684a6), X(0x74208150), + X(0x36041ad9), X(0x740b53fb), X(0x3631a8b8), X(0x73f614c0), + X(0x365f2e3b), X(0x73e0c3a3), X(0x368cab5c), X(0x73cb60a8), + X(0x36ba2014), X(0x73b5ebd1), X(0x36e78c5b), X(0x73a06522), + X(0x3714f02a), X(0x738acc9e), X(0x37424b7b), X(0x73752249), + X(0x376f9e46), X(0x735f6626), X(0x379ce885), X(0x73499838), + X(0x37ca2a30), X(0x7333b883), X(0x37f76341), X(0x731dc70a), + X(0x382493b0), X(0x7307c3d0), X(0x3851bb77), X(0x72f1aed9), + X(0x387eda8e), X(0x72db8828), X(0x38abf0ef), X(0x72c54fc1), + X(0x38d8fe93), X(0x72af05a7), X(0x39060373), X(0x7298a9dd), + X(0x3932ff87), X(0x72823c67), X(0x395ff2c9), X(0x726bbd48), + X(0x398cdd32), X(0x72552c85), X(0x39b9bebc), X(0x723e8a20), + X(0x39e6975e), X(0x7227d61c), X(0x3a136712), X(0x7211107e), + X(0x3a402dd2), X(0x71fa3949), X(0x3a6ceb96), X(0x71e35080), + X(0x3a99a057), X(0x71cc5626), X(0x3ac64c0f), X(0x71b54a41), + X(0x3af2eeb7), X(0x719e2cd2), X(0x3b1f8848), X(0x7186fdde), + X(0x3b4c18ba), X(0x716fbd68), X(0x3b78a007), X(0x71586b74), + X(0x3ba51e29), X(0x71410805), X(0x3bd19318), X(0x7129931f), + X(0x3bfdfecd), X(0x71120cc5), X(0x3c2a6142), X(0x70fa74fc), + X(0x3c56ba70), X(0x70e2cbc6), X(0x3c830a50), X(0x70cb1128), + X(0x3caf50da), X(0x70b34525), X(0x3cdb8e09), X(0x709b67c0), + X(0x3d07c1d6), X(0x708378ff), X(0x3d33ec39), X(0x706b78e3), + X(0x3d600d2c), X(0x70536771), X(0x3d8c24a8), X(0x703b44ad), + X(0x3db832a6), X(0x7023109a), X(0x3de4371f), X(0x700acb3c), + X(0x3e10320d), X(0x6ff27497), X(0x3e3c2369), X(0x6fda0cae), + X(0x3e680b2c), X(0x6fc19385), X(0x3e93e950), X(0x6fa90921), + X(0x3ebfbdcd), X(0x6f906d84), X(0x3eeb889c), X(0x6f77c0b3), + X(0x3f1749b8), X(0x6f5f02b2), X(0x3f430119), X(0x6f463383), + X(0x3f6eaeb8), X(0x6f2d532c), X(0x3f9a5290), X(0x6f1461b0), + X(0x3fc5ec98), X(0x6efb5f12), X(0x3ff17cca), X(0x6ee24b57), + X(0x401d0321), X(0x6ec92683), X(0x40487f94), X(0x6eaff099), + X(0x4073f21d), X(0x6e96a99d), X(0x409f5ab6), X(0x6e7d5193), + X(0x40cab958), X(0x6e63e87f), X(0x40f60dfb), X(0x6e4a6e66), + X(0x4121589b), X(0x6e30e34a), X(0x414c992f), X(0x6e174730), + X(0x4177cfb1), X(0x6dfd9a1c), X(0x41a2fc1a), X(0x6de3dc11), + X(0x41ce1e65), X(0x6dca0d14), X(0x41f93689), X(0x6db02d29), + X(0x42244481), X(0x6d963c54), X(0x424f4845), X(0x6d7c3a98), + X(0x427a41d0), X(0x6d6227fa), X(0x42a5311b), X(0x6d48047e), + X(0x42d0161e), X(0x6d2dd027), X(0x42faf0d4), X(0x6d138afb), + X(0x4325c135), X(0x6cf934fc), X(0x4350873c), X(0x6cdece2f), + X(0x437b42e1), X(0x6cc45698), X(0x43a5f41e), X(0x6ca9ce3b), + X(0x43d09aed), X(0x6c8f351c), X(0x43fb3746), X(0x6c748b3f), + X(0x4425c923), X(0x6c59d0a9), X(0x4450507e), X(0x6c3f055d), + X(0x447acd50), X(0x6c242960), X(0x44a53f93), X(0x6c093cb6), + X(0x44cfa740), X(0x6bee3f62), X(0x44fa0450), X(0x6bd3316a), + X(0x452456bd), X(0x6bb812d1), X(0x454e9e80), X(0x6b9ce39b), + X(0x4578db93), X(0x6b81a3cd), X(0x45a30df0), X(0x6b66536b), + X(0x45cd358f), X(0x6b4af279), X(0x45f7526b), X(0x6b2f80fb), + X(0x4621647d), X(0x6b13fef5), X(0x464b6bbe), X(0x6af86c6c), + X(0x46756828), X(0x6adcc964), X(0x469f59b4), X(0x6ac115e2), + X(0x46c9405c), X(0x6aa551e9), X(0x46f31c1a), X(0x6a897d7d), + X(0x471cece7), X(0x6a6d98a4), X(0x4746b2bc), X(0x6a51a361), + X(0x47706d93), X(0x6a359db9), X(0x479a1d67), X(0x6a1987b0), + X(0x47c3c22f), X(0x69fd614a), X(0x47ed5be6), X(0x69e12a8c), + X(0x4816ea86), X(0x69c4e37a), X(0x48406e08), X(0x69a88c19), + X(0x4869e665), X(0x698c246c), X(0x48935397), X(0x696fac78), + X(0x48bcb599), X(0x69532442), X(0x48e60c62), X(0x69368bce), + X(0x490f57ee), X(0x6919e320), X(0x49389836), X(0x68fd2a3d), + X(0x4961cd33), X(0x68e06129), X(0x498af6df), X(0x68c387e9), + X(0x49b41533), X(0x68a69e81), X(0x49dd282a), X(0x6889a4f6), + X(0x4a062fbd), X(0x686c9b4b), X(0x4a2f2be6), X(0x684f8186), + X(0x4a581c9e), X(0x683257ab), X(0x4a8101de), X(0x68151dbe), + X(0x4aa9dba2), X(0x67f7d3c5), X(0x4ad2a9e2), X(0x67da79c3), + X(0x4afb6c98), X(0x67bd0fbd), X(0x4b2423be), X(0x679f95b7), + X(0x4b4ccf4d), X(0x67820bb7), X(0x4b756f40), X(0x676471c0), + X(0x4b9e0390), X(0x6746c7d8), X(0x4bc68c36), X(0x67290e02), + X(0x4bef092d), X(0x670b4444), X(0x4c177a6e), X(0x66ed6aa1), + X(0x4c3fdff4), X(0x66cf8120), X(0x4c6839b7), X(0x66b187c3), + X(0x4c9087b1), X(0x66937e91), X(0x4cb8c9dd), X(0x6675658c), + X(0x4ce10034), X(0x66573cbb), X(0x4d092ab0), X(0x66390422), + X(0x4d31494b), X(0x661abbc5), X(0x4d595bfe), X(0x65fc63a9), + X(0x4d8162c4), X(0x65ddfbd3), X(0x4da95d96), X(0x65bf8447), + X(0x4dd14c6e), X(0x65a0fd0b), X(0x4df92f46), X(0x65826622), + X(0x4e210617), X(0x6563bf92), X(0x4e48d0dd), X(0x6545095f), + X(0x4e708f8f), X(0x6526438f), X(0x4e984229), X(0x65076e25), + X(0x4ebfe8a5), X(0x64e88926), X(0x4ee782fb), X(0x64c99498), + X(0x4f0f1126), X(0x64aa907f), X(0x4f369320), X(0x648b7ce0), + X(0x4f5e08e3), X(0x646c59bf), X(0x4f857269), X(0x644d2722), + X(0x4faccfab), X(0x642de50d), X(0x4fd420a4), X(0x640e9386), + X(0x4ffb654d), X(0x63ef3290), X(0x50229da1), X(0x63cfc231), + X(0x5049c999), X(0x63b0426d), X(0x5070e92f), X(0x6390b34a), + X(0x5097fc5e), X(0x637114cc), X(0x50bf031f), X(0x635166f9), + X(0x50e5fd6d), X(0x6331a9d4), X(0x510ceb40), X(0x6311dd64), + X(0x5133cc94), X(0x62f201ac), X(0x515aa162), X(0x62d216b3), + X(0x518169a5), X(0x62b21c7b), X(0x51a82555), X(0x6292130c), + X(0x51ced46e), X(0x6271fa69), X(0x51f576ea), X(0x6251d298), + X(0x521c0cc2), X(0x62319b9d), X(0x524295f0), X(0x6211557e), + X(0x5269126e), X(0x61f1003f), X(0x528f8238), X(0x61d09be5), + X(0x52b5e546), X(0x61b02876), X(0x52dc3b92), X(0x618fa5f7), + X(0x53028518), X(0x616f146c), X(0x5328c1d0), X(0x614e73da), + X(0x534ef1b5), X(0x612dc447), X(0x537514c2), X(0x610d05b7), + X(0x539b2af0), X(0x60ec3830), X(0x53c13439), X(0x60cb5bb7), + X(0x53e73097), X(0x60aa7050), X(0x540d2005), X(0x60897601), + X(0x5433027d), X(0x60686ccf), X(0x5458d7f9), X(0x604754bf), + X(0x547ea073), X(0x60262dd6), X(0x54a45be6), X(0x6004f819), + X(0x54ca0a4b), X(0x5fe3b38d), X(0x54efab9c), X(0x5fc26038), + X(0x55153fd4), X(0x5fa0fe1f), X(0x553ac6ee), X(0x5f7f8d46), + X(0x556040e2), X(0x5f5e0db3), X(0x5585adad), X(0x5f3c7f6b), + X(0x55ab0d46), X(0x5f1ae274), X(0x55d05faa), X(0x5ef936d1), + X(0x55f5a4d2), X(0x5ed77c8a), X(0x561adcb9), X(0x5eb5b3a2), + X(0x56400758), X(0x5e93dc1f), X(0x566524aa), X(0x5e71f606), + X(0x568a34a9), X(0x5e50015d), X(0x56af3750), X(0x5e2dfe29), + X(0x56d42c99), X(0x5e0bec6e), X(0x56f9147e), X(0x5de9cc33), + X(0x571deefa), X(0x5dc79d7c), X(0x5742bc06), X(0x5da5604f), + X(0x57677b9d), X(0x5d8314b1), X(0x578c2dba), X(0x5d60baa7), + X(0x57b0d256), X(0x5d3e5237), X(0x57d5696d), X(0x5d1bdb65), + X(0x57f9f2f8), X(0x5cf95638), X(0x581e6ef1), X(0x5cd6c2b5), + X(0x5842dd54), X(0x5cb420e0), X(0x58673e1b), X(0x5c9170bf), + X(0x588b9140), X(0x5c6eb258), X(0x58afd6bd), X(0x5c4be5b0), + X(0x58d40e8c), X(0x5c290acc), X(0x58f838a9), X(0x5c0621b2), + X(0x591c550e), X(0x5be32a67), X(0x594063b5), X(0x5bc024f0), + X(0x59646498), X(0x5b9d1154), X(0x598857b2), X(0x5b79ef96), + X(0x59ac3cfd), X(0x5b56bfbd), X(0x59d01475), X(0x5b3381ce), + X(0x59f3de12), X(0x5b1035cf), X(0x5a1799d1), X(0x5aecdbc5), + X(0x5a3b47ab), X(0x5ac973b5), X(0x5a5ee79a), X(0x5aa5fda5), + X(0x5a82799a), X(0x5a82799a) + }; + + /* {sin((2*i+1)*PI/4096), cos((2*i+1)*PI/4096)}, with i = 0 to 511 */ +static LOOKUP_T sincos_lookup1[1024] = { + X(0x001921fb), X(0x7ffffd88), X(0x004b65ee), X(0x7fffe9cb), + X(0x007da9d4), X(0x7fffc251), X(0x00afeda8), X(0x7fff8719), + X(0x00e23160), X(0x7fff3824), X(0x011474f6), X(0x7ffed572), + X(0x0146b860), X(0x7ffe5f03), X(0x0178fb99), X(0x7ffdd4d7), + X(0x01ab3e97), X(0x7ffd36ee), X(0x01dd8154), X(0x7ffc8549), + X(0x020fc3c6), X(0x7ffbbfe6), X(0x024205e8), X(0x7ffae6c7), + X(0x027447b0), X(0x7ff9f9ec), X(0x02a68917), X(0x7ff8f954), + X(0x02d8ca16), X(0x7ff7e500), X(0x030b0aa4), X(0x7ff6bcf0), + X(0x033d4abb), X(0x7ff58125), X(0x036f8a51), X(0x7ff4319d), + X(0x03a1c960), X(0x7ff2ce5b), X(0x03d407df), X(0x7ff1575d), + X(0x040645c7), X(0x7fefcca4), X(0x04388310), X(0x7fee2e30), + X(0x046abfb3), X(0x7fec7c02), X(0x049cfba7), X(0x7feab61a), + X(0x04cf36e5), X(0x7fe8dc78), X(0x05017165), X(0x7fe6ef1c), + X(0x0533ab20), X(0x7fe4ee06), X(0x0565e40d), X(0x7fe2d938), + X(0x05981c26), X(0x7fe0b0b1), X(0x05ca5361), X(0x7fde7471), + X(0x05fc89b8), X(0x7fdc247a), X(0x062ebf22), X(0x7fd9c0ca), + X(0x0660f398), X(0x7fd74964), X(0x06932713), X(0x7fd4be46), + X(0x06c5598a), X(0x7fd21f72), X(0x06f78af6), X(0x7fcf6ce8), + X(0x0729bb4e), X(0x7fcca6a7), X(0x075bea8c), X(0x7fc9ccb2), + X(0x078e18a7), X(0x7fc6df08), X(0x07c04598), X(0x7fc3dda9), + X(0x07f27157), X(0x7fc0c896), X(0x08249bdd), X(0x7fbd9fd0), + X(0x0856c520), X(0x7fba6357), X(0x0888ed1b), X(0x7fb7132b), + X(0x08bb13c5), X(0x7fb3af4e), X(0x08ed3916), X(0x7fb037bf), + X(0x091f5d06), X(0x7facac7f), X(0x09517f8f), X(0x7fa90d8e), + X(0x0983a0a7), X(0x7fa55aee), X(0x09b5c048), X(0x7fa1949e), + X(0x09e7de6a), X(0x7f9dbaa0), X(0x0a19fb04), X(0x7f99ccf4), + X(0x0a4c1610), X(0x7f95cb9a), X(0x0a7e2f85), X(0x7f91b694), + X(0x0ab0475c), X(0x7f8d8de1), X(0x0ae25d8d), X(0x7f895182), + X(0x0b147211), X(0x7f850179), X(0x0b4684df), X(0x7f809dc5), + X(0x0b7895f0), X(0x7f7c2668), X(0x0baaa53b), X(0x7f779b62), + X(0x0bdcb2bb), X(0x7f72fcb4), X(0x0c0ebe66), X(0x7f6e4a5e), + X(0x0c40c835), X(0x7f698461), X(0x0c72d020), X(0x7f64aabf), + X(0x0ca4d620), X(0x7f5fbd77), X(0x0cd6da2d), X(0x7f5abc8a), + X(0x0d08dc3f), X(0x7f55a7fa), X(0x0d3adc4e), X(0x7f507fc7), + X(0x0d6cda53), X(0x7f4b43f2), X(0x0d9ed646), X(0x7f45f47b), + X(0x0dd0d01f), X(0x7f409164), X(0x0e02c7d7), X(0x7f3b1aad), + X(0x0e34bd66), X(0x7f359057), X(0x0e66b0c3), X(0x7f2ff263), + X(0x0e98a1e9), X(0x7f2a40d2), X(0x0eca90ce), X(0x7f247ba5), + X(0x0efc7d6b), X(0x7f1ea2dc), X(0x0f2e67b8), X(0x7f18b679), + X(0x0f604faf), X(0x7f12b67c), X(0x0f923546), X(0x7f0ca2e7), + X(0x0fc41876), X(0x7f067bba), X(0x0ff5f938), X(0x7f0040f6), + X(0x1027d784), X(0x7ef9f29d), X(0x1059b352), X(0x7ef390ae), + X(0x108b8c9b), X(0x7eed1b2c), X(0x10bd6356), X(0x7ee69217), + X(0x10ef377d), X(0x7edff570), X(0x11210907), X(0x7ed94538), + X(0x1152d7ed), X(0x7ed28171), X(0x1184a427), X(0x7ecbaa1a), + X(0x11b66dad), X(0x7ec4bf36), X(0x11e83478), X(0x7ebdc0c6), + X(0x1219f880), X(0x7eb6aeca), X(0x124bb9be), X(0x7eaf8943), + X(0x127d7829), X(0x7ea85033), X(0x12af33ba), X(0x7ea1039b), + X(0x12e0ec6a), X(0x7e99a37c), X(0x1312a230), X(0x7e922fd6), + X(0x13445505), X(0x7e8aa8ac), X(0x137604e2), X(0x7e830dff), + X(0x13a7b1bf), X(0x7e7b5fce), X(0x13d95b93), X(0x7e739e1d), + X(0x140b0258), X(0x7e6bc8eb), X(0x143ca605), X(0x7e63e03b), + X(0x146e4694), X(0x7e5be40c), X(0x149fe3fc), X(0x7e53d462), + X(0x14d17e36), X(0x7e4bb13c), X(0x1503153a), X(0x7e437a9c), + X(0x1534a901), X(0x7e3b3083), X(0x15663982), X(0x7e32d2f4), + X(0x1597c6b7), X(0x7e2a61ed), X(0x15c95097), X(0x7e21dd73), + X(0x15fad71b), X(0x7e194584), X(0x162c5a3b), X(0x7e109a24), + X(0x165dd9f0), X(0x7e07db52), X(0x168f5632), X(0x7dff0911), + X(0x16c0cef9), X(0x7df62362), X(0x16f2443e), X(0x7ded2a47), + X(0x1723b5f9), X(0x7de41dc0), X(0x17552422), X(0x7ddafdce), + X(0x17868eb3), X(0x7dd1ca75), X(0x17b7f5a3), X(0x7dc883b4), + X(0x17e958ea), X(0x7dbf298d), X(0x181ab881), X(0x7db5bc02), + X(0x184c1461), X(0x7dac3b15), X(0x187d6c82), X(0x7da2a6c6), + X(0x18aec0db), X(0x7d98ff17), X(0x18e01167), X(0x7d8f4409), + X(0x19115e1c), X(0x7d85759f), X(0x1942a6f3), X(0x7d7b93da), + X(0x1973ebe6), X(0x7d719eba), X(0x19a52ceb), X(0x7d679642), + X(0x19d669fc), X(0x7d5d7a74), X(0x1a07a311), X(0x7d534b50), + X(0x1a38d823), X(0x7d4908d9), X(0x1a6a0929), X(0x7d3eb30f), + X(0x1a9b361d), X(0x7d3449f5), X(0x1acc5ef6), X(0x7d29cd8c), + X(0x1afd83ad), X(0x7d1f3dd6), X(0x1b2ea43a), X(0x7d149ad5), + X(0x1b5fc097), X(0x7d09e489), X(0x1b90d8bb), X(0x7cff1af5), + X(0x1bc1ec9e), X(0x7cf43e1a), X(0x1bf2fc3a), X(0x7ce94dfb), + X(0x1c240786), X(0x7cde4a98), X(0x1c550e7c), X(0x7cd333f3), + X(0x1c861113), X(0x7cc80a0f), X(0x1cb70f43), X(0x7cbcccec), + X(0x1ce80906), X(0x7cb17c8d), X(0x1d18fe54), X(0x7ca618f3), + X(0x1d49ef26), X(0x7c9aa221), X(0x1d7adb73), X(0x7c8f1817), + X(0x1dabc334), X(0x7c837ad8), X(0x1ddca662), X(0x7c77ca65), + X(0x1e0d84f5), X(0x7c6c06c0), X(0x1e3e5ee5), X(0x7c602fec), + X(0x1e6f342c), X(0x7c5445e9), X(0x1ea004c1), X(0x7c4848ba), + X(0x1ed0d09d), X(0x7c3c3860), X(0x1f0197b8), X(0x7c3014de), + X(0x1f325a0b), X(0x7c23de35), X(0x1f63178f), X(0x7c179467), + X(0x1f93d03c), X(0x7c0b3777), X(0x1fc4840a), X(0x7bfec765), + X(0x1ff532f2), X(0x7bf24434), X(0x2025dcec), X(0x7be5ade6), + X(0x205681f1), X(0x7bd9047c), X(0x208721f9), X(0x7bcc47fa), + X(0x20b7bcfe), X(0x7bbf7860), X(0x20e852f6), X(0x7bb295b0), + X(0x2118e3dc), X(0x7ba59fee), X(0x21496fa7), X(0x7b989719), + X(0x2179f64f), X(0x7b8b7b36), X(0x21aa77cf), X(0x7b7e4c45), + X(0x21daf41d), X(0x7b710a49), X(0x220b6b32), X(0x7b63b543), + X(0x223bdd08), X(0x7b564d36), X(0x226c4996), X(0x7b48d225), + X(0x229cb0d5), X(0x7b3b4410), X(0x22cd12bd), X(0x7b2da2fa), + X(0x22fd6f48), X(0x7b1feee5), X(0x232dc66d), X(0x7b1227d3), + X(0x235e1826), X(0x7b044dc7), X(0x238e646a), X(0x7af660c2), + X(0x23beab33), X(0x7ae860c7), X(0x23eeec78), X(0x7ada4dd8), + X(0x241f2833), X(0x7acc27f7), X(0x244f5e5c), X(0x7abdef25), + X(0x247f8eec), X(0x7aafa367), X(0x24afb9da), X(0x7aa144bc), + X(0x24dfdf20), X(0x7a92d329), X(0x250ffeb7), X(0x7a844eae), + X(0x25401896), X(0x7a75b74f), X(0x25702cb7), X(0x7a670d0d), + X(0x25a03b11), X(0x7a584feb), X(0x25d0439f), X(0x7a497feb), + X(0x26004657), X(0x7a3a9d0f), X(0x26304333), X(0x7a2ba75a), + X(0x26603a2c), X(0x7a1c9ece), X(0x26902b39), X(0x7a0d836d), + X(0x26c01655), X(0x79fe5539), X(0x26effb76), X(0x79ef1436), + X(0x271fda96), X(0x79dfc064), X(0x274fb3ae), X(0x79d059c8), + X(0x277f86b5), X(0x79c0e062), X(0x27af53a6), X(0x79b15435), + X(0x27df1a77), X(0x79a1b545), X(0x280edb23), X(0x79920392), + X(0x283e95a1), X(0x79823f20), X(0x286e49ea), X(0x797267f2), + X(0x289df7f8), X(0x79627e08), X(0x28cd9fc1), X(0x79528167), + X(0x28fd4140), X(0x79427210), X(0x292cdc6d), X(0x79325006), + X(0x295c7140), X(0x79221b4b), X(0x298bffb2), X(0x7911d3e2), + X(0x29bb87bc), X(0x790179cd), X(0x29eb0957), X(0x78f10d0f), + X(0x2a1a847b), X(0x78e08dab), X(0x2a49f920), X(0x78cffba3), + X(0x2a796740), X(0x78bf56f9), X(0x2aa8ced3), X(0x78ae9fb0), + X(0x2ad82fd2), X(0x789dd5cb), X(0x2b078a36), X(0x788cf94c), + X(0x2b36ddf7), X(0x787c0a36), X(0x2b662b0e), X(0x786b088c), + X(0x2b957173), X(0x7859f44f), X(0x2bc4b120), X(0x7848cd83), + X(0x2bf3ea0d), X(0x7837942b), X(0x2c231c33), X(0x78264849), + X(0x2c52478a), X(0x7814e9df), X(0x2c816c0c), X(0x780378f1), + X(0x2cb089b1), X(0x77f1f581), X(0x2cdfa071), X(0x77e05f91), + X(0x2d0eb046), X(0x77ceb725), X(0x2d3db928), X(0x77bcfc3f), + X(0x2d6cbb10), X(0x77ab2ee2), X(0x2d9bb5f6), X(0x77994f11), + X(0x2dcaa9d5), X(0x77875cce), X(0x2df996a3), X(0x7775581d), + X(0x2e287c5a), X(0x776340ff), X(0x2e575af3), X(0x77511778), + X(0x2e863267), X(0x773edb8b), X(0x2eb502ae), X(0x772c8d3a), + X(0x2ee3cbc1), X(0x771a2c88), X(0x2f128d99), X(0x7707b979), + X(0x2f41482e), X(0x76f5340e), X(0x2f6ffb7a), X(0x76e29c4b), + X(0x2f9ea775), X(0x76cff232), X(0x2fcd4c19), X(0x76bd35c7), + X(0x2ffbe95d), X(0x76aa670d), X(0x302a7f3a), X(0x76978605), + X(0x30590dab), X(0x768492b4), X(0x308794a6), X(0x76718d1c), + X(0x30b61426), X(0x765e7540), X(0x30e48c22), X(0x764b4b23), + X(0x3112fc95), X(0x76380ec8), X(0x31416576), X(0x7624c031), + X(0x316fc6be), X(0x76115f63), X(0x319e2067), X(0x75fdec60), + X(0x31cc7269), X(0x75ea672a), X(0x31fabcbd), X(0x75d6cfc5), + X(0x3228ff5c), X(0x75c32634), X(0x32573a3f), X(0x75af6a7b), + X(0x32856d5e), X(0x759b9c9b), X(0x32b398b3), X(0x7587bc98), + X(0x32e1bc36), X(0x7573ca75), X(0x330fd7e1), X(0x755fc635), + X(0x333debab), X(0x754bafdc), X(0x336bf78f), X(0x7537876c), + X(0x3399fb85), X(0x75234ce8), X(0x33c7f785), X(0x750f0054), + X(0x33f5eb89), X(0x74faa1b3), X(0x3423d78a), X(0x74e63108), + X(0x3451bb81), X(0x74d1ae55), X(0x347f9766), X(0x74bd199f), + X(0x34ad6b32), X(0x74a872e8), X(0x34db36df), X(0x7493ba34), + X(0x3508fa66), X(0x747eef85), X(0x3536b5be), X(0x746a12df), + X(0x356468e2), X(0x74552446), X(0x359213c9), X(0x744023bc), + X(0x35bfb66e), X(0x742b1144), X(0x35ed50c9), X(0x7415ece2), + X(0x361ae2d3), X(0x7400b69a), X(0x36486c86), X(0x73eb6e6e), + X(0x3675edd9), X(0x73d61461), X(0x36a366c6), X(0x73c0a878), + X(0x36d0d746), X(0x73ab2ab4), X(0x36fe3f52), X(0x73959b1b), + X(0x372b9ee3), X(0x737ff9ae), X(0x3758f5f2), X(0x736a4671), + X(0x37864477), X(0x73548168), X(0x37b38a6d), X(0x733eaa96), + X(0x37e0c7cc), X(0x7328c1ff), X(0x380dfc8d), X(0x7312c7a5), + X(0x383b28a9), X(0x72fcbb8c), X(0x38684c19), X(0x72e69db7), + X(0x389566d6), X(0x72d06e2b), X(0x38c278d9), X(0x72ba2cea), + X(0x38ef821c), X(0x72a3d9f7), X(0x391c8297), X(0x728d7557), + X(0x39497a43), X(0x7276ff0d), X(0x39766919), X(0x7260771b), + X(0x39a34f13), X(0x7249dd86), X(0x39d02c2a), X(0x72333251), + X(0x39fd0056), X(0x721c7580), X(0x3a29cb91), X(0x7205a716), + X(0x3a568dd4), X(0x71eec716), X(0x3a834717), X(0x71d7d585), + X(0x3aaff755), X(0x71c0d265), X(0x3adc9e86), X(0x71a9bdba), + X(0x3b093ca3), X(0x71929789), X(0x3b35d1a5), X(0x717b5fd3), + X(0x3b625d86), X(0x7164169d), X(0x3b8ee03e), X(0x714cbbeb), + X(0x3bbb59c7), X(0x71354fc0), X(0x3be7ca1a), X(0x711dd220), + X(0x3c143130), X(0x7106430e), X(0x3c408f03), X(0x70eea28e), + X(0x3c6ce38a), X(0x70d6f0a4), X(0x3c992ec0), X(0x70bf2d53), + X(0x3cc5709e), X(0x70a7589f), X(0x3cf1a91c), X(0x708f728b), + X(0x3d1dd835), X(0x70777b1c), X(0x3d49fde1), X(0x705f7255), + X(0x3d761a19), X(0x70475839), X(0x3da22cd7), X(0x702f2ccd), + X(0x3dce3614), X(0x7016f014), X(0x3dfa35c8), X(0x6ffea212), + X(0x3e262bee), X(0x6fe642ca), X(0x3e52187f), X(0x6fcdd241), + X(0x3e7dfb73), X(0x6fb5507a), X(0x3ea9d4c3), X(0x6f9cbd79), + X(0x3ed5a46b), X(0x6f841942), X(0x3f016a61), X(0x6f6b63d8), + X(0x3f2d26a0), X(0x6f529d40), X(0x3f58d921), X(0x6f39c57d), + X(0x3f8481dd), X(0x6f20dc92), X(0x3fb020ce), X(0x6f07e285), + X(0x3fdbb5ec), X(0x6eeed758), X(0x40074132), X(0x6ed5bb10), + X(0x4032c297), X(0x6ebc8db0), X(0x405e3a16), X(0x6ea34f3d), + X(0x4089a7a8), X(0x6e89ffb9), X(0x40b50b46), X(0x6e709f2a), + X(0x40e064ea), X(0x6e572d93), X(0x410bb48c), X(0x6e3daaf8), + X(0x4136fa27), X(0x6e24175c), X(0x416235b2), X(0x6e0a72c5), + X(0x418d6729), X(0x6df0bd35), X(0x41b88e84), X(0x6dd6f6b1), + X(0x41e3abbc), X(0x6dbd1f3c), X(0x420ebecb), X(0x6da336dc), + X(0x4239c7aa), X(0x6d893d93), X(0x4264c653), X(0x6d6f3365), + X(0x428fbabe), X(0x6d551858), X(0x42baa4e6), X(0x6d3aec6e), + X(0x42e584c3), X(0x6d20afac), X(0x43105a50), X(0x6d066215), + X(0x433b2585), X(0x6cec03af), X(0x4365e65b), X(0x6cd1947c), + X(0x43909ccd), X(0x6cb71482), X(0x43bb48d4), X(0x6c9c83c3), + X(0x43e5ea68), X(0x6c81e245), X(0x44108184), X(0x6c67300b), + X(0x443b0e21), X(0x6c4c6d1a), X(0x44659039), X(0x6c319975), + X(0x449007c4), X(0x6c16b521), X(0x44ba74bd), X(0x6bfbc021), + X(0x44e4d71c), X(0x6be0ba7b), X(0x450f2edb), X(0x6bc5a431), + X(0x45397bf4), X(0x6baa7d49), X(0x4563be60), X(0x6b8f45c7), + X(0x458df619), X(0x6b73fdae), X(0x45b82318), X(0x6b58a503), + X(0x45e24556), X(0x6b3d3bcb), X(0x460c5cce), X(0x6b21c208), + X(0x46366978), X(0x6b0637c1), X(0x46606b4e), X(0x6aea9cf8), + X(0x468a624a), X(0x6acef1b2), X(0x46b44e65), X(0x6ab335f4), + X(0x46de2f99), X(0x6a9769c1), X(0x470805df), X(0x6a7b8d1e), + X(0x4731d131), X(0x6a5fa010), X(0x475b9188), X(0x6a43a29a), + X(0x478546de), X(0x6a2794c1), X(0x47aef12c), X(0x6a0b7689), + X(0x47d8906d), X(0x69ef47f6), X(0x48022499), X(0x69d3090e), + X(0x482badab), X(0x69b6b9d3), X(0x48552b9b), X(0x699a5a4c), + X(0x487e9e64), X(0x697dea7b), X(0x48a805ff), X(0x69616a65), + X(0x48d16265), X(0x6944da10), X(0x48fab391), X(0x6928397e), + X(0x4923f97b), X(0x690b88b5), X(0x494d341e), X(0x68eec7b9), + X(0x49766373), X(0x68d1f68f), X(0x499f8774), X(0x68b5153a), + X(0x49c8a01b), X(0x689823bf), X(0x49f1ad61), X(0x687b2224), + X(0x4a1aaf3f), X(0x685e106c), X(0x4a43a5b0), X(0x6840ee9b), + X(0x4a6c90ad), X(0x6823bcb7), X(0x4a957030), X(0x68067ac3), + X(0x4abe4433), X(0x67e928c5), X(0x4ae70caf), X(0x67cbc6c0), + X(0x4b0fc99d), X(0x67ae54ba), X(0x4b387af9), X(0x6790d2b6), + X(0x4b6120bb), X(0x677340ba), X(0x4b89badd), X(0x67559eca), + X(0x4bb24958), X(0x6737ecea), X(0x4bdacc28), X(0x671a2b20), + X(0x4c034345), X(0x66fc596f), X(0x4c2baea9), X(0x66de77dc), + X(0x4c540e4e), X(0x66c0866d), X(0x4c7c622d), X(0x66a28524), + X(0x4ca4aa41), X(0x66847408), X(0x4ccce684), X(0x6666531d), + X(0x4cf516ee), X(0x66482267), X(0x4d1d3b7a), X(0x6629e1ec), + X(0x4d455422), X(0x660b91af), X(0x4d6d60df), X(0x65ed31b5), + X(0x4d9561ac), X(0x65cec204), X(0x4dbd5682), X(0x65b0429f), + X(0x4de53f5a), X(0x6591b38c), X(0x4e0d1c30), X(0x657314cf), + X(0x4e34ecfc), X(0x6554666d), X(0x4e5cb1b9), X(0x6535a86b), + X(0x4e846a60), X(0x6516dacd), X(0x4eac16eb), X(0x64f7fd98), + X(0x4ed3b755), X(0x64d910d1), X(0x4efb4b96), X(0x64ba147d), + X(0x4f22d3aa), X(0x649b08a0), X(0x4f4a4f89), X(0x647bed3f), + X(0x4f71bf2e), X(0x645cc260), X(0x4f992293), X(0x643d8806), + X(0x4fc079b1), X(0x641e3e38), X(0x4fe7c483), X(0x63fee4f8), + X(0x500f0302), X(0x63df7c4d), X(0x50363529), X(0x63c0043b), + X(0x505d5af1), X(0x63a07cc7), X(0x50847454), X(0x6380e5f6), + X(0x50ab814d), X(0x63613fcd), X(0x50d281d5), X(0x63418a50), + X(0x50f975e6), X(0x6321c585), X(0x51205d7b), X(0x6301f171), + X(0x5147388c), X(0x62e20e17), X(0x516e0715), X(0x62c21b7e), + X(0x5194c910), X(0x62a219aa), X(0x51bb7e75), X(0x628208a1), + X(0x51e22740), X(0x6261e866), X(0x5208c36a), X(0x6241b8ff), + X(0x522f52ee), X(0x62217a72), X(0x5255d5c5), X(0x62012cc2), + X(0x527c4bea), X(0x61e0cff5), X(0x52a2b556), X(0x61c06410), + X(0x52c91204), X(0x619fe918), X(0x52ef61ee), X(0x617f5f12), + X(0x5315a50e), X(0x615ec603), X(0x533bdb5d), X(0x613e1df0), + X(0x536204d7), X(0x611d66de), X(0x53882175), X(0x60fca0d2), + X(0x53ae3131), X(0x60dbcbd1), X(0x53d43406), X(0x60bae7e1), + X(0x53fa29ed), X(0x6099f505), X(0x542012e1), X(0x6078f344), + X(0x5445eedb), X(0x6057e2a2), X(0x546bbdd7), X(0x6036c325), + X(0x54917fce), X(0x601594d1), X(0x54b734ba), X(0x5ff457ad), + X(0x54dcdc96), X(0x5fd30bbc), X(0x5502775c), X(0x5fb1b104), + X(0x55280505), X(0x5f90478a), X(0x554d858d), X(0x5f6ecf53), + X(0x5572f8ed), X(0x5f4d4865), X(0x55985f20), X(0x5f2bb2c5), + X(0x55bdb81f), X(0x5f0a0e77), X(0x55e303e6), X(0x5ee85b82), + X(0x5608426e), X(0x5ec699e9), X(0x562d73b2), X(0x5ea4c9b3), + X(0x565297ab), X(0x5e82eae5), X(0x5677ae54), X(0x5e60fd84), + X(0x569cb7a8), X(0x5e3f0194), X(0x56c1b3a1), X(0x5e1cf71c), + X(0x56e6a239), X(0x5dfade20), X(0x570b8369), X(0x5dd8b6a7), + X(0x5730572e), X(0x5db680b4), X(0x57551d80), X(0x5d943c4e), + X(0x5779d65b), X(0x5d71e979), X(0x579e81b8), X(0x5d4f883b), + X(0x57c31f92), X(0x5d2d189a), X(0x57e7afe4), X(0x5d0a9a9a), + X(0x580c32a7), X(0x5ce80e41), X(0x5830a7d6), X(0x5cc57394), + X(0x58550f6c), X(0x5ca2ca99), X(0x58796962), X(0x5c801354), + X(0x589db5b3), X(0x5c5d4dcc), X(0x58c1f45b), X(0x5c3a7a05), + X(0x58e62552), X(0x5c179806), X(0x590a4893), X(0x5bf4a7d2), + X(0x592e5e19), X(0x5bd1a971), X(0x595265df), X(0x5bae9ce7), + X(0x59765fde), X(0x5b8b8239), X(0x599a4c12), X(0x5b68596d), + X(0x59be2a74), X(0x5b452288), X(0x59e1faff), X(0x5b21dd90), + X(0x5a05bdae), X(0x5afe8a8b), X(0x5a29727b), X(0x5adb297d), + X(0x5a4d1960), X(0x5ab7ba6c), X(0x5a70b258), X(0x5a943d5e), +}; + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/misc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/misc.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,244 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: miscellaneous math and prototypes + + ********************************************************************/ + +#ifndef _V_RANDOM_H_ +#define _V_RANDOM_H_ +#include "ivorbiscodec.h" +#include "os.h" + +#include "asm_arm.h" +#include /* for abs() */ + +#ifndef _V_WIDE_MATH +#define _V_WIDE_MATH + +#ifndef _LOW_ACCURACY_ +/* 64 bit multiply */ + +#if !(defined WIN32 && defined WINCE) +#include +#endif + +#if BYTE_ORDER==LITTLE_ENDIAN +union magic { + struct { + ogg_int32_t lo; + ogg_int32_t hi; + } halves; + ogg_int64_t whole; +}; +#endif + +#if BYTE_ORDER==BIG_ENDIAN +/*union magic { + struct { + ogg_int32_t hi; + ogg_int32_t lo; + } halves; + ogg_int64_t whole; +};*/ +#endif + +STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { + union magic magic; + magic.whole = (ogg_int64_t)x * y; + return magic.halves.hi; +} + +STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { + return MULT32(x,y)<<1; +} + +STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { + union magic magic; + magic.whole = (ogg_int64_t)x * y; + return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17); +} + +#else +/* 32 bit multiply, more portable but less accurate */ + +/* + * Note: Precision is biased towards the first argument therefore ordering + * is important. Shift values were chosen for the best sound quality after + * many listening tests. + */ + +/* + * For MULT32 and MULT31: The second argument is always a lookup table + * value already preshifted from 31 to 8 bits. We therefore take the + * opportunity to save on text space and use unsigned char for those + * tables in this case. + */ + +STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { + return (x >> 9) * y; /* y preshifted >>23 */ +} + +STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { + return (x >> 8) * y; /* y preshifted >>23 */ +} + +STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { + return (x >> 6) * y; /* y preshifted >>9 */ +} + +#endif + +/* + * This should be used as a memory barrier, forcing all cached values in + * registers to wr writen back to memory. Might or might not be beneficial + * depending on the architecture and compiler. + */ +#define MB() + +/* + * The XPROD functions are meant to optimize the cross products found all + * over the place in mdct.c by forcing memory operation ordering to avoid + * unnecessary register reloads as soon as memory is being written to. + * However this is only beneficial on CPUs with a sane number of general + * purpose registers which exclude the Intel x86. On Intel, better let the + * compiler actually reload registers directly from original memory by using + * macros. + */ + +#ifdef __i386__ + +#define XPROD32(_a, _b, _t, _v, _x, _y) \ + { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \ + *(_y)=MULT32(_b,_t)-MULT32(_a,_v); } +#define XPROD31(_a, _b, _t, _v, _x, _y) \ + { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \ + *(_y)=MULT31(_b,_t)-MULT31(_a,_v); } +#define XNPROD31(_a, _b, _t, _v, _x, _y) \ + { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \ + *(_y)=MULT31(_b,_t)+MULT31(_a,_v); } + +#else + +STIN 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) +{ + *x = MULT32(a, t) + MULT32(b, v); + *y = MULT32(b, t) - MULT32(a, v); +} + +STIN 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) +{ + *x = MULT31(a, t) + MULT31(b, v); + *y = MULT31(b, t) - MULT31(a, v); +} + +STIN 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) +{ + *x = MULT31(a, t) - MULT31(b, v); + *y = MULT31(b, t) + MULT31(a, v); +} + +#endif + +#endif + +#ifndef _V_CLIP_MATH +#define _V_CLIP_MATH + +STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) { + int ret=x; + ret-= ((x<=32767)-1)&(x-32767); + ret-= ((x>=-32768)-1)&(x+32768); + return(ret); +} + +#endif + +STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, + ogg_int32_t b,ogg_int32_t bp, + ogg_int32_t *p){ + if(a && b){ +#ifndef _LOW_ACCURACY_ + *p=ap+bp+32; + return MULT32(a,b); +#else + *p=ap+bp+31; + return (a>>15)*(b>>16); +#endif + }else + return 0; +} + +int _ilog(unsigned int); + +STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap, + ogg_int32_t i, + ogg_int32_t *p){ + + int ip=_ilog(abs(i))-31; + return VFLOAT_MULT(a,ap,i<<-ip,ip,p); +} + +STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, + ogg_int32_t b,ogg_int32_t bp, + ogg_int32_t *p){ + + if(!a){ + *p=bp; + return b; + }else if(!b){ + *p=ap; + return a; + } + + /* yes, this can leak a bit. */ + if(ap>bp){ + int shift=ap-bp+1; + *p=ap+1; + a>>=1; + if(shift<32){ + b=(b+(1<<(shift-1)))>>shift; + }else{ + b=0; + } + }else{ + int shift=bp-ap+1; + *p=bp+1; + b>>=1; + if(shift<32){ + a=(a+(1<<(shift-1)))>>shift; + }else{ + a=0; + } + } + + a+=b; + if((a&0xc0000000)==0xc0000000 || + (a&0xc0000000)==0){ + a<<=1; + (*p)--; + } + return(a); +} + +#endif + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/ogg.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/ogg.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,206 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: subsumed libogg includes + + ********************************************************************/ +#ifndef _OGG_H +#define _OGG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "os_types.h" + +typedef struct ogg_buffer_state{ + struct ogg_buffer *unused_buffers; + struct ogg_reference *unused_references; + int outstanding; + int shutdown; +} ogg_buffer_state; + +typedef struct ogg_buffer { + unsigned char *data; + long size; + int refcount; + + union { + ogg_buffer_state *owner; + struct ogg_buffer *next; + } ptr; +} ogg_buffer; + +typedef struct ogg_reference { + ogg_buffer *buffer; + long begin; + long length; + + struct ogg_reference *next; +} ogg_reference; + +typedef struct oggpack_buffer { + int headbit; + unsigned char *headptr; + long headend; + + /* memory management */ + ogg_reference *head; + ogg_reference *tail; + + /* render the byte/bit counter API constant time */ + long count; /* doesn't count the tail */ +} oggpack_buffer; + +typedef struct oggbyte_buffer { + ogg_reference *baseref; + + ogg_reference *ref; + unsigned char *ptr; + long pos; + long end; +} oggbyte_buffer; + +typedef struct ogg_sync_state { + /* decode memory management pool */ + ogg_buffer_state *bufferpool; + + /* stream buffers */ + ogg_reference *fifo_head; + ogg_reference *fifo_tail; + long fifo_fill; + + /* stream sync management */ + int unsynced; + int headerbytes; + int bodybytes; + +} ogg_sync_state; + +typedef struct ogg_stream_state { + ogg_reference *header_head; + ogg_reference *header_tail; + ogg_reference *body_head; + ogg_reference *body_tail; + + int e_o_s; /* set when we have buffered the last + packet in the logical bitstream */ + int b_o_s; /* set after we've written the initial page + of a logical bitstream */ + long serialno; + long pageno; + ogg_int64_t packetno; /* sequence number for decode; the framing + knows where there's a hole in the data, + but we need coupling so that the codec + (which is in a seperate abstraction + layer) also knows about the gap */ + ogg_int64_t granulepos; + + int lacing_fill; + ogg_uint32_t body_fill; + + /* decode-side state data */ + int holeflag; + int spanflag; + int clearflag; + int laceptr; + ogg_uint32_t body_fill_next; + +} ogg_stream_state; + +typedef struct { + ogg_reference *packet; + long bytes; + long b_o_s; + long e_o_s; + ogg_int64_t granulepos; + ogg_int64_t packetno; /* sequence number for decode; the framing + knows where there's a hole in the data, + but we need coupling so that the codec + (which is in a seperate abstraction + layer) also knows about the gap */ +} ogg_packet; + +typedef struct { + ogg_reference *header; + int header_len; + ogg_reference *body; + long body_len; +} ogg_page; + +/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ + +extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); +extern long oggpack_look(oggpack_buffer *b,int bits); +extern void oggpack_adv(oggpack_buffer *b,int bits); +extern long oggpack_read(oggpack_buffer *b,int bits); +extern long oggpack_bytes(oggpack_buffer *b); +extern long oggpack_bits(oggpack_buffer *b); +extern int oggpack_eop(oggpack_buffer *b); + +/* Ogg BITSTREAM PRIMITIVES: decoding **************************/ + +extern ogg_sync_state *ogg_sync_create(void); +extern int ogg_sync_destroy(ogg_sync_state *oy); +extern int ogg_sync_reset(ogg_sync_state *oy); + +extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); +extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); +extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); +extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); +extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); +extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); +extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); + +/* Ogg BITSTREAM PRIMITIVES: general ***************************/ + +extern ogg_stream_state *ogg_stream_create(int serialno); +extern int ogg_stream_destroy(ogg_stream_state *os); +extern int ogg_stream_reset(ogg_stream_state *os); +extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); +extern int ogg_stream_eos(ogg_stream_state *os); + +extern int ogg_page_checksum_set(ogg_page *og); + +extern int ogg_page_version(ogg_page *og); +extern int ogg_page_continued(ogg_page *og); +extern int ogg_page_bos(ogg_page *og); +extern int ogg_page_eos(ogg_page *og); +extern ogg_int64_t ogg_page_granulepos(ogg_page *og); +extern ogg_uint32_t ogg_page_serialno(ogg_page *og); +extern ogg_uint32_t ogg_page_pageno(ogg_page *og); +extern int ogg_page_packets(ogg_page *og); +extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); + +extern int ogg_packet_release(ogg_packet *op); +extern int ogg_page_release(ogg_page *og); + +extern void ogg_page_dup(ogg_page *d, ogg_page *s); + +/* Ogg BITSTREAM PRIMITIVES: return codes ***************************/ + +#define OGG_SUCCESS 0 + +#define OGG_HOLE -10 +#define OGG_SPAN -11 +#define OGG_EVERSION -12 +#define OGG_ESERIAL -13 +#define OGG_EINVAL -14 +#define OGG_EEOS -15 + + +#ifdef __cplusplus +} +#endif + +#endif /* _OGG_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/os.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/os.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,64 @@ +#ifndef _OS_H +#define _OS_H +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: #ifdef jail to whip a few platforms into the UNIX ideal. + + ********************************************************************/ + +#include +#include "os_types.h" + +#ifndef _V_IFDEFJAIL_H_ +# define _V_IFDEFJAIL_H_ + +# ifdef __GNUC__ +# define STIN static __inline__ +# elif _WIN32 +# define STIN static __inline +# endif +#else +# define STIN static +#endif + +#ifndef M_PI +# define M_PI (3.1415926536f) +#endif + +#ifdef _WIN32 +# include +# define rint(x) (floor((x)+0.5f)) +# define NO_FLOAT_MATH_LIB +# define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) +# define LITTLE_ENDIAN 1 +# define BYTE_ORDER LITTLE_ENDIAN +#endif + +#ifdef HAVE_ALLOCA_H +# include +#endif + +#ifdef USE_MEMORY_H +# include +#endif + +#ifndef min +# define min(x,y) ((x)>(y)?(y):(x)) +#endif + +#ifndef max +# define max(x,y) ((x)<(y)?(y):(x)) +#endif + +#endif /* _OS_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/os_types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/os_types.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,88 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: #ifdef jail to whip a few platforms into the UNIX ideal. + + ********************************************************************/ +#ifndef _OS_TYPES_H +#define _OS_TYPES_H + +#ifdef _LOW_ACCURACY_ +# define X(n) (((((n)>>22)+1)>>1) - ((((n)>>22)+1)>>9)) +# define LOOKUP_T const unsigned char +#else +# define X(n) (n) +# define LOOKUP_T const ogg_int32_t +#endif + +/* make it easy on the folks that want to compile the libs with a + different malloc than stdlib */ +#define _ogg_malloc malloc +#define _ogg_calloc calloc +#define _ogg_realloc realloc +#define _ogg_free free + +#ifdef _WIN32 + +# ifndef __GNUC__ + /* MSVC/Borland */ + typedef __int64 ogg_int64_t; + typedef __int32 ogg_int32_t; + typedef unsigned __int32 ogg_uint32_t; + typedef __int16 ogg_int16_t; +# else + /* Cygwin */ + #include <_G_config.h> + typedef _G_int64_t ogg_int64_t; + typedef _G_int32_t ogg_int32_t; + typedef _G_uint32_t ogg_uint32_t; + typedef _G_int16_t ogg_int16_t; +# endif + +#elif defined(__MACOS__) + +# include + typedef SInt16 ogg_int16_t; + typedef SInt32 ogg_int32_t; + typedef UInt32 ogg_uint32_t; + typedef SInt64 ogg_int64_t; + +#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ + +# include + typedef int16_t ogg_int16_t; + typedef int32_t ogg_int32_t; + typedef u_int32_t ogg_uint32_t; + typedef int64_t ogg_int64_t; + +#elif defined(__BEOS__) + + /* Be */ +# include + +#elif defined (__EMX__) + + /* OS/2 GCC */ + typedef short ogg_int16_t; + typedef int ogg_int32_t; + typedef unsigned int ogg_uint32_t; + typedef long long ogg_int64_t; + +#else + +# include +# include "config_types.h" + +#endif + +#endif /* _OS_TYPES_H */ diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/registry.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/registry.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,50 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: registry for floor, res backends and channel mappings + + ********************************************************************/ + +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "registry.h" +#include "misc.h" + + +/* seems like major overkill now; the backend numbers will grow into + the infrastructure soon enough */ + +extern vorbis_func_floor floor0_exportbundle; +extern vorbis_func_floor floor1_exportbundle; +extern vorbis_func_residue residue0_exportbundle; +extern vorbis_func_residue residue1_exportbundle; +extern vorbis_func_residue residue2_exportbundle; +extern vorbis_func_mapping mapping0_exportbundle; + +vorbis_func_floor *_floor_P[]={ + &floor0_exportbundle, + &floor1_exportbundle, +}; + +vorbis_func_residue *_residue_P[]={ + &residue0_exportbundle, + &residue1_exportbundle, + &residue2_exportbundle, +}; + +vorbis_func_mapping *_mapping_P[]={ + &mapping0_exportbundle, +}; + + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/registry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/registry.h Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,40 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: registry for time, floor, res backends and channel mappings + + ********************************************************************/ + +#ifndef _V_REG_H_ +#define _V_REG_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 + +#include "backends.h" + +#if defined(_WIN32) && defined(VORBISDLL_IMPORT) +# define EXTERN __declspec(dllimport) extern +#else +# define EXTERN extern +#endif + +EXTERN vorbis_func_floor *_floor_P[]; +EXTERN vorbis_func_residue *_residue_P[]; +EXTERN vorbis_func_mapping *_mapping_P[]; + +#endif diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/res012.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/res012.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,342 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: residue backend 0, 1 and 2 implementation + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "registry.h" +#include "codebook.h" +#include "misc.h" +#include "os.h" +#include "block.h" + +typedef struct { + vorbis_info_residue0 *info; + int map; + + int parts; + int stages; + codebook *fullbooks; + codebook *phrasebook; + codebook ***partbooks; + + int partvals; + int **decodemap; + +} vorbis_look_residue0; + +void res0_free_info(vorbis_info_residue *i){ + vorbis_info_residue0 *info=(vorbis_info_residue0 *)i; + if(info){ + memset(info,0,sizeof(*info)); + _ogg_free(info); + } +} + +void res0_free_look(vorbis_look_residue *i){ + int j; + if(i){ + + vorbis_look_residue0 *look=(vorbis_look_residue0 *)i; + + for(j=0;jparts;j++) + if(look->partbooks[j])_ogg_free(look->partbooks[j]); + _ogg_free(look->partbooks); + for(j=0;jpartvals;j++) + _ogg_free(look->decodemap[j]); + _ogg_free(look->decodemap); + + memset(look,0,sizeof(*look)); + _ogg_free(look); + } +} + +static int ilog(unsigned int v){ + int ret=0; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +static int icount(unsigned int v){ + int ret=0; + while(v){ + ret+=v&1; + v>>=1; + } + return(ret); +} + +/* vorbis_info is for range checking */ +vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){ + int j,acc=0; + vorbis_info_residue0 *info=(vorbis_info_residue0 *)_ogg_calloc(1,sizeof(*info)); + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + + info->begin=oggpack_read(opb,24); + info->end=oggpack_read(opb,24); + info->grouping=oggpack_read(opb,24)+1; + info->partitions=oggpack_read(opb,6)+1; + info->groupbook=oggpack_read(opb,8); + + for(j=0;jpartitions;j++){ + int cascade=oggpack_read(opb,3); + if(oggpack_read(opb,1)) + cascade|=(oggpack_read(opb,5)<<3); + info->secondstages[j]=cascade; + + acc+=icount(cascade); + } + for(j=0;jbooklist[j]=oggpack_read(opb,8); + + if(info->groupbook>=ci->books)goto errout; + for(j=0;jbooklist[j]>=ci->books)goto errout; + + return(info); + errout: + res0_free_info(info); + return(NULL); +} + +vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, + vorbis_info_residue *vr){ + vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; + vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look)); + codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; + + int j,k,acc=0; + int dim; + int maxstage=0; + look->info=info; + look->map=vm->mapping; + + look->parts=info->partitions; + look->fullbooks=ci->fullbooks; + look->phrasebook=ci->fullbooks+info->groupbook; + dim=look->phrasebook->dim; + + look->partbooks=(codebook ***)_ogg_calloc(look->parts,sizeof(*look->partbooks)); + + for(j=0;jparts;j++){ + int stages=ilog(info->secondstages[j]); + if(stages){ + if(stages>maxstage)maxstage=stages; + look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j])); + for(k=0;ksecondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; +#ifdef TRAIN_RES + look->training_data[k][j]=calloc(look->partbooks[j][k]->entries, + sizeof(***look->training_data)); +#endif + } + } + } + + look->partvals=look->parts; + for(j=1;jpartvals*=look->parts; + look->stages=maxstage; + look->decodemap=(int **)_ogg_malloc(look->partvals*sizeof(*look->decodemap)); + for(j=0;jpartvals;j++){ + long val=j; + long mult=look->partvals/look->parts; + look->decodemap[j]=(int *)_ogg_malloc(dim*sizeof(*look->decodemap[j])); + for(k=0;kparts; + look->decodemap[j][k]=deco; + } + } + + return(look); +} + + +/* a truncated packet here just means 'stop working'; it's not an error */ +static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, + ogg_int32_t **in,int ch, + long (*decodepart)(codebook *, ogg_int32_t *, + oggpack_buffer *,int,int)){ + + long i,j,k,l,s; + vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; + vorbis_info_residue0 *info=look->info; + + /* move all this setup out later */ + int samples_per_partition=info->grouping; + int partitions_per_word=look->phrasebook->dim; + int max=vb->pcmend>>1; + int end=(info->endend:max); + int n=end-info->begin; + + if(n>0){ + int partvals=n/samples_per_partition; + int partwords=(partvals+partitions_per_word-1)/partitions_per_word; + int ***partword=(int ***)alloca(ch*sizeof(*partword)); + + for(j=0;jstages;s++){ + + /* each loop decodes on partition codeword containing + partitions_pre_word partitions */ + for(i=0,l=0;iphrasebook,&vb->opb); + if(temp==-1)goto eopbreak; + partword[j][l]=look->decodemap[temp]; + if(partword[j][l]==NULL)goto errout; + } + } + + /* now we decode residual values for the partitions */ + for(k=0;kbegin+i*samples_per_partition; + if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; + if(stagebook){ + if(decodepart(stagebook,in[j]+offset,&vb->opb, + samples_per_partition,-8)==-1)goto eopbreak; + } + } + } + } + } + } + errout: + eopbreak: + return(0); +} + +int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl, + ogg_int32_t **in,int *nonzero,int ch){ + int i,used=0; + for(i=0;iinfo; + + /* move all this setup out later */ + int samples_per_partition=info->grouping; + int partitions_per_word=look->phrasebook->dim; + int max=(vb->pcmend*ch)>>1; + int end=(info->endend:max); + int n=end-info->begin; + + if(n>0){ + + int partvals=n/samples_per_partition; + int partwords=(partvals+partitions_per_word-1)/partitions_per_word; + int **partword=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword)); + int beginoff=info->begin/ch; + + for(i=0;istages;s++){ + for(i=0,l=0;iphrasebook,&vb->opb); + if(temp==-1)goto eopbreak; + partword[l]=look->decodemap[temp]; + if(partword[l]==NULL)goto errout; + } + + /* now we decode residual values for the partitions */ + for(k=0;ksecondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; + + if(stagebook){ + if(vorbis_book_decodevv_add(stagebook,in, + i*samples_per_partition+beginoff,ch, + &vb->opb, + samples_per_partition,-8)==-1) + goto eopbreak; + } + } + } + } + } + errout: + eopbreak: + return(0); +} + + +vorbis_func_residue residue0_exportbundle={ + &res0_unpack, + &res0_look, + &res0_free_info, + &res0_free_look, + &res0_inverse +}; + +vorbis_func_residue residue1_exportbundle={ + &res0_unpack, + &res0_look, + &res0_free_info, + &res0_free_look, + &res1_inverse +}; + +vorbis_func_residue residue2_exportbundle={ + &res0_unpack, + &res0_look, + &res0_free_info, + &res0_free_look, + &res2_inverse +}; diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/sharedbook.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/sharedbook.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,439 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: basic shared codebook operations + + ********************************************************************/ + +#include +#include +#include +#include "ogg.h" +#include "misc.h" +#include "ivorbiscodec.h" +#include "codebook.h" + +/**** pack/unpack helpers ******************************************/ +int _ilog(unsigned int v){ + int ret=0; + while(v){ + ret++; + v>>=1; + } + return(ret); +} + +/* 32 bit float (not IEEE; nonnormalized mantissa + + biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm + Why not IEEE? It's just not that important here. */ + +#define VQ_FEXP 10 +#define VQ_FMAN 21 +#define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */ + +static ogg_int32_t _float32_unpack(long val,int *point){ + long mant=val&0x1fffff; + int sign=val&0x80000000; + long exp =(val&0x7fe00000L)>>VQ_FMAN; + + exp-=(VQ_FMAN-1)+VQ_FEXP_BIAS; + + if(mant){ + while(!(mant&0x40000000)){ + mant<<=1; + exp-=1; + } + + if(sign)mant= -mant; + }else{ + sign=0; + exp=-9999; + } + + *point=exp; + return mant; +} + +/* given a list of word lengths, generate a list of codewords. Works + for length ordered or unordered, always assigns the lowest valued + codewords first. Extended to handle unused entries (length 0) */ +ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ + long i,j,count=0; + ogg_uint32_t marker[33]; + ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); + memset(marker,0,sizeof(marker)); + + for(i=0;i0){ + ogg_uint32_t entry=marker[length]; + + /* when we claim a node for an entry, we also claim the nodes + below it (pruning off the imagined tree that may have dangled + from it) as well as blocking the use of any nodes directly + above for leaves */ + + /* update ourself */ + if(length<32 && (entry>>length)){ + /* error condition; the lengths must specify an overpopulated tree */ + _ogg_free(r); + return(NULL); + } + r[count++]=entry; + + /* 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){ + /* have to jump branches */ + if(j==1) + marker[1]++; + else + marker[j]=marker[j-1]<<1; + break; /* invariant says next upper marker would already + have been moved if it was on the same path */ + } + 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<33;j++) + if((marker[j]>>1) == entry){ + entry=marker[j]; + marker[j]=marker[j-1]<<1; + }else + break; + }else + if(sparsecount==0)count++; + } + + /* bitreverse the words because our bitwise packer/unpacker is LSb + endian */ + for(i=0,count=0;i>j)&1; + } + + if(sparsecount){ + if(l[i]) + r[count++]=temp; + }else + r[count++]=temp; + } + + return(r); +} + +/* 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(const static_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;idim;i++){ + acc*=vals; + acc1*=vals+1; + } + if(acc<=b->entries && acc1>b->entries){ + return(vals); + }else{ + if(acc>b->entries){ + vals--; + }else{ + vals++; + } + } + } +} + +/* different than what _book_unquantize does for mainline: + we repack the book in a fixed point format that shares the same + binary point. Upon first use, we can shift point if needed */ + +/* we need to deal with two map types: in map type 1, the values are + generated algorithmically (each column of the vector counts through + the values in the quant vector). in map type 2, all the values came + in in an explicit list. Both value lists must be unpacked */ + +ogg_int32_t *_book_unquantize(const static_codebook *b,int n,int *sparsemap, + int *maxpoint){ + long j,k,count=0; + if(b->maptype==1 || b->maptype==2){ + int quantvals; + int minpoint,delpoint; + ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); + ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); + ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); + int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); + + *maxpoint=minpoint; + + /* maptype 1 and 2 both use a quantized value vector, but + different sizes */ + switch(b->maptype){ + case 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*dimentries;j++){ + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + ogg_int32_t last=0; + int lastpoint=0; + int indexdiv=1; + for(k=0;kdim;k++){ + int index= (j/indexdiv)%quantvals; + int point=0; + int val=VFLOAT_MULTI(delta,delpoint, + abs(b->quantlist[index]),&point); + + val=VFLOAT_ADD(mindel,minpoint,val,point,&point); + val=VFLOAT_ADD(last,lastpoint,val,point,&point); + + if(b->q_sequencep){ + last=val; + lastpoint=point; + } + + if(sparsemap){ + r[sparsemap[count]*b->dim+k]=val; + rp[sparsemap[count]*b->dim+k]=point; + }else{ + r[count*b->dim+k]=val; + rp[count*b->dim+k]=point; + } + if(*maxpointentries;j++){ + if((sparsemap && b->lengthlist[j]) || !sparsemap){ + ogg_int32_t last=0; + int lastpoint=0; + + for(k=0;kdim;k++){ + int point=0; + int val=VFLOAT_MULTI(delta,delpoint, + abs(b->quantlist[j*b->dim+k]),&point); + + val=VFLOAT_ADD(mindel,minpoint,val,point,&point); + val=VFLOAT_ADD(last,lastpoint,val,point,&point); + + if(b->q_sequencep){ + last=val; + lastpoint=point; + } + + if(sparsemap){ + r[sparsemap[count]*b->dim+k]=val; + rp[sparsemap[count]*b->dim+k]=point; + }else{ + r[count*b->dim+k]=val; + rp[count*b->dim+k]=point; + } + if(*maxpointdim;j++) + if(rp[j]<*maxpoint) + r[j]>>=*maxpoint-rp[j]; + + _ogg_free(rp); + return(r); + } + return(NULL); +} + +void vorbis_staticbook_clear(static_codebook *b){ + if(b->quantlist)_ogg_free(b->quantlist); + if(b->lengthlist)_ogg_free(b->lengthlist); + memset(b,0,sizeof(*b)); + +} + +void vorbis_staticbook_destroy(static_codebook *b){ + vorbis_staticbook_clear(b); + _ogg_free(b); +} + +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->valuelist)_ogg_free(b->valuelist); + if(b->codelist)_ogg_free(b->codelist); + + if(b->dec_index)_ogg_free(b->dec_index); + if(b->dec_codelengths)_ogg_free(b->dec_codelengths); + if(b->dec_firsttable)_ogg_free(b->dec_firsttable); + + memset(b,0,sizeof(*b)); +} + +static ogg_uint32_t bitreverse(ogg_uint32_t x){ + x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL); + x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL); + x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL); + x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL); + return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL); +} + +static int sort32a(const void *a,const void *b){ + return (**(ogg_uint32_t **)a>**(ogg_uint32_t **)b)- + (**(ogg_uint32_t **)a<**(ogg_uint32_t **)b); +} + +/* decode codebook arrangement is more heavily optimized than encode */ +int vorbis_book_init_decode(codebook *c,const static_codebook *s){ + int i,j,n=0,tabn; + int *sortindex; + memset(c,0,sizeof(*c)); + + /* count actually used entries */ + for(i=0;ientries;i++) + if(s->lengthlist[i]>0) + n++; + + c->entries=s->entries; + c->used_entries=n; + c->dim=s->dim; + + if(n>0){ + /* two different remappings go on here. + + First, we collapse the likely sparse codebook down only to + actually represented values/words. This collapsing needs to be + indexed as map-valueless books are used to encode original entry + positions as integers. + + Second, we reorder all vectors, including the entry index above, + by sorted bitreversed codeword to allow treeless decode. */ + + /* perform sort */ + ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); + ogg_uint32_t **codep=(ogg_uint32_t **)alloca(sizeof(*codep)*n); + + if(codes==NULL)goto err_out; + + for(i=0;icodelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); + /* the index is a reverse index */ + for(i=0;icodelist[sortindex[i]]=codes[i]; + _ogg_free(codes); + + + + c->valuelist=_book_unquantize(s,n,sortindex,&c->binarypoint); + c->dec_index=(int *)_ogg_malloc(n*sizeof(*c->dec_index)); + + for(n=0,i=0;ientries;i++) + if(s->lengthlist[i]>0) + c->dec_index[sortindex[n++]]=i; + + c->dec_codelengths=(char *)_ogg_malloc(n*sizeof(*c->dec_codelengths)); + for(n=0,i=0;ientries;i++) + if(s->lengthlist[i]>0) + c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; + + c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ + if(c->dec_firsttablen<5)c->dec_firsttablen=5; + if(c->dec_firsttablen>8)c->dec_firsttablen=8; + + tabn=1<dec_firsttablen; + c->dec_firsttable=(ogg_uint32_t *)_ogg_calloc(tabn,sizeof(*c->dec_firsttable)); + c->dec_maxlength=0; + + for(i=0;idec_maxlengthdec_codelengths[i]) + c->dec_maxlength=c->dec_codelengths[i]; + if(c->dec_codelengths[i]<=c->dec_firsttablen){ + ogg_uint32_t orig=bitreverse(c->codelist[i]); + for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++) + c->dec_firsttable[orig|(j<dec_codelengths[i])]=i+1; + } + } + + /* now fill in 'unused' entries in the firsttable with hi/lo search + hints for the non-direct-hits */ + { + ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen); + long lo=0,hi=0; + + for(i=0;idec_firsttablen); + if(c->dec_firsttable[bitreverse(word)]==0){ + while((lo+1)codelist[lo+1]<=word)lo++; + while( hi=(c->codelist[hi]&mask))hi++; + + /* we only actually have 15 bits per hint to play with here. + In order to overflow gracefully (nothing breaks, efficiency + just drops), encode as the difference from the extremes. */ + { + unsigned long loval=lo; + unsigned long hival=n-hi; + + if(loval>0x7fff)loval=0x7fff; + if(hival>0x7fff)hival=0x7fff; + c->dec_firsttable[bitreverse(word)]= + 0x80000000UL | (loval<<15) | hival; + } + } + } + } + } + + return(0); + err_out: + vorbis_book_clear(c); + return(-1); +} + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/synthesis.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/synthesis.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,113 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: single-block PCM synthesis + last mod: $Id: synthesis.c,v 1.4 2003/03/29 03:07:21 xiphmont Exp $ + + ********************************************************************/ + +#include +#include "ogg.h" +#include "ivorbiscodec.h" +#include "codec_internal.h" +#include "registry.h" +#include "misc.h" +#include "block.h" + +int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){ + vorbis_dsp_state *vd=vb->vd; + private_state *b=(private_state *)vd->backend_state; + vorbis_info *vi=vd->vi; + codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; + oggpack_buffer *opb=&vb->opb; + int type,mode,i; + + /* first things first. Make sure decode is ready */ + _vorbis_block_ripcord(vb); + 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); + } + + /* read our mode and pre/post windowsize */ + mode=oggpack_read(opb,b->modebits); + if(mode==-1)return(OV_EBADPACKET); + + vb->mode=mode; + vb->W=ci->mode_param[mode]->blockflag; + if(vb->W){ + vb->lW=oggpack_read(opb,1); + vb->nW=oggpack_read(opb,1); + if(vb->nW==-1) return(OV_EBADPACKET); + }else{ + vb->lW=0; + vb->nW=0; + } + + /* more setup */ + vb->granulepos=op->granulepos; + vb->sequence=op->packetno-3; /* first block is third packet */ + vb->eofflag=op->e_o_s; + + if(decodep){ + /* alloc pcm passback storage */ + vb->pcmend=ci->blocksizes[vb->W]; + vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); + for(i=0;ichannels;i++) + vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); + + /* unpack_header enforces range checking */ + type=ci->map_type[ci->mode_param[mode]->mapping]; + + return(_mapping_P[type]->inverse(vb,b->mode[mode])); + }else{ + /* no pcm */ + vb->pcmend=0; + vb->pcm=NULL; + + 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; + + 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); + } + + { + int modebits=0; + int v=ci->modes; + 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]); +} + + diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/vorbisfile.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/vorbisfile.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,1586 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: stdio-based convenience library for opening/seeking/decoding + last mod: $Id: vorbisfile.c,v 1.6 2003/03/30 23:40:56 xiphmont Exp $ + + ********************************************************************/ + +#include +#include +#include +#include +#include + +#include "ivorbiscodec.h" +#include "ivorbisfile.h" + +#include "misc.h" + +/* A 'chained bitstream' is a Vorbis bitstream that contains more than + one logical bitstream arranged end to end (the only form of Ogg + multiplexing allowed in a Vorbis bitstream; grouping [parallel + multiplexing] is not allowed in Vorbis) */ + +/* A Vorbis file can be played beginning to end (streamed) without + worrying ahead of time about chaining (see decoder_example.c). If + we have the whole file, however, and want random access + (seeking/scrubbing) or desire to know the total length/time of a + file, we need to account for the possibility of chaining. */ + +/* We can handle things a number of ways; we can determine the entire + bitstream structure right off the bat, or find pieces on demand. + This example determines and caches structure for the entire + bitstream, but builds a virtual decoder on the fly when moving + between links in the chain. */ + +/* There are also different ways to implement seeking. Enough + information exists in an Ogg bitstream to seek to + sample-granularity positions in the output. Or, one can seek by + picking some portion of the stream roughly in the desired area if + we only want coarse navigation through the stream. */ + +/************************************************************************* + * Many, many internal helpers. The intention is not to be confusing; + * rampant duplication and monolithic function implementation would be + * harder to understand anyway. The high level functions are last. Begin + * grokking near the end of the file */ + + +/* read a little more data from the file/pipe into the ogg_sync framer */ +static long _get_data(OggVorbis_File *vf){ + errno=0; + if(vf->datasource){ + unsigned char *buffer=ogg_sync_bufferin(vf->oy,CHUNKSIZE); + long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource); + if(bytes>0)ogg_sync_wrote(vf->oy,bytes); + if(bytes==0 && errno)return(-1); + return(bytes); + }else + return(0); +} + +/* save a tiny smidge of verbosity to make the code more readable */ +static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){ + if(vf->datasource){ + (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET); + vf->offset=offset; + ogg_sync_reset(vf->oy); + }else{ + /* shouldn't happen unless someone writes a broken callback */ + return; + } +} + +/* The read/seek functions track absolute position within the stream */ + +/* from the head of the stream, get the next page. boundary specifies + if the function is allowed to fetch more data from the stream (and + how much) or only use internally buffered data. + + boundary: -1) unbounded search + 0) read no additional data; use cached only + n) search for a new page beginning for n bytes + + return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD) + n) found a page at absolute offset n + + produces a refcounted page */ + +static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, + ogg_int64_t boundary){ + if(boundary>0)boundary+=vf->offset; + while(1){ + long more; + + if(boundary>0 && vf->offset>=boundary)return(OV_FALSE); + more=ogg_sync_pageseek(vf->oy,og); + + if(more<0){ + /* skipped n bytes */ + vf->offset-=more; + }else{ + if(more==0){ + /* send more paramedics */ + if(!boundary)return(OV_FALSE); + { + long ret=_get_data(vf); + if(ret==0)return(OV_EOF); + if(ret<0)return(OV_EREAD); + } + }else{ + /* got a page. Return the offset at the page beginning, + advance the internal offset past the page end */ + ogg_int64_t ret=vf->offset; + vf->offset+=more; + return(ret); + + } + } + } +} + +/* find the latest page beginning before the current stream cursor + position. Much dirtier than the above as Ogg doesn't have any + backward search linkage. no 'readp' as it will certainly have to + read. */ +/* returns offset or OV_EREAD, OV_FAULT and produces a refcounted page */ + +static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){ + ogg_int64_t begin=vf->offset; + ogg_int64_t end=begin; + ogg_int64_t ret; + ogg_int64_t offset=-1; + + while(offset==-1){ + begin-=CHUNKSIZE; + if(begin<0) + begin=0; + _seek_helper(vf,begin); + while(vf->offsetoffset); + if(ret==OV_EREAD)return(OV_EREAD); + if(ret<0){ + break; + }else{ + offset=ret; + } + } + } + + /* we have the offset. Actually snork and hold the page now */ + _seek_helper(vf,offset); + ret=_get_next_page(vf,og,CHUNKSIZE); + if(ret<0) + /* this shouldn't be possible */ + return(OV_EFAULT); + + return(offset); +} + +/* finds each bitstream link one at a time using a bisection search + (has to begin by knowing the offset of the lb's initial page). + Recurses for each link so it can alloc the link storage after + finding them all, then unroll and fill the cache at the same time */ +static int _bisect_forward_serialno(OggVorbis_File *vf, + ogg_int64_t begin, + ogg_int64_t searched, + ogg_int64_t end, + ogg_uint32_t currentno, + long m){ + ogg_int64_t endsearched=end; + ogg_int64_t next=end; + ogg_page og={0,0,0,0}; + ogg_int64_t ret; + + /* the below guards against garbage seperating the last and + first pages of two links. */ + while(searched=0)next=ret; + }else{ + searched=ret+og.header_len+og.body_len; + } + ogg_page_release(&og); + } + + _seek_helper(vf,next); + ret=_get_next_page(vf,&og,-1); + if(ret==OV_EREAD)return(OV_EREAD); + + if(searched>=end || ret<0){ + ogg_page_release(&og); + vf->links=m+1; + vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets)); + vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos)); + vf->offsets[m+1]=searched; + }else{ + ret=_bisect_forward_serialno(vf,next,vf->offset, + end,ogg_page_serialno(&og),m+1); + ogg_page_release(&og); + if(ret==OV_EREAD)return(OV_EREAD); + } + + vf->offsets[m]=begin; + vf->serialnos[m]=currentno; + return(0); +} + +/* uses the local ogg_stream storage in vf; this is important for + non-streaming input sources */ +/* consumes the page that's passed in (if any) */ + +static int _fetch_headers(OggVorbis_File *vf, + vorbis_info *vi, + vorbis_comment *vc, + ogg_uint32_t *serialno, + ogg_page *og_ptr){ + ogg_page og={0,0,0,0}; + ogg_packet op={0,0,0,0,0,0}; + int i,ret; + + if(!og_ptr){ + ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE); + if(llret==OV_EREAD)return(OV_EREAD); + if(llret<0)return OV_ENOTVORBIS; + og_ptr=&og; + } + + ogg_stream_reset_serialno(vf->os,ogg_page_serialno(og_ptr)); + if(serialno)*serialno=vf->os->serialno; + vf->ready_state=STREAMSET; + + /* extract the initial header from the first page and verify that the + Ogg bitstream is in fact Vorbis data */ + + vorbis_info_init(vi); + vorbis_comment_init(vc); + + i=0; + while(i<3){ + ogg_stream_pagein(vf->os,og_ptr); + while(i<3){ + int result=ogg_stream_packetout(vf->os,&op); + if(result==0)break; + if(result==-1){ + ret=OV_EBADHEADER; + goto bail_header; + } + if((ret=vorbis_synthesis_headerin(vi,vc,&op))){ + goto bail_header; + } + i++; + } + if(i<3) + if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){ + ret=OV_EBADHEADER; + goto bail_header; + } + } + + ogg_packet_release(&op); + ogg_page_release(&og); + return 0; + + bail_header: + ogg_packet_release(&op); + ogg_page_release(&og); + vorbis_info_clear(vi); + vorbis_comment_clear(vc); + vf->ready_state=OPENED; + + return ret; +} + +/* last step of the OggVorbis_File initialization; get all the + vorbis_info structs and PCM positions. Only called by the seekable + initialization (local stream storage is hacked slightly; pay + attention to how that's done) */ + +/* this is void and does not propogate errors up because we want to be + able to open and use damaged bitstreams as well as we can. Just + watch out for missing information for links in the OggVorbis_File + struct */ +static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){ + ogg_page og={0,0,0,0}; + int i; + ogg_int64_t ret; + + vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi)); + vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc)); + vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets)); + vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths)); + + for(i=0;ilinks;i++){ + if(i==0){ + /* we already grabbed the initial header earlier. Just set the offset */ + vf->dataoffsets[i]=dataoffset; + _seek_helper(vf,dataoffset); + + }else{ + + /* seek to the location of the initial header */ + + _seek_helper(vf,vf->offsets[i]); + if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){ + vf->dataoffsets[i]=-1; + }else{ + vf->dataoffsets[i]=vf->offset; + } + } + + /* fetch beginning PCM offset */ + + if(vf->dataoffsets[i]!=-1){ + ogg_int64_t accumulated=0,pos; + long lastblock=-1; + int result; + + ogg_stream_reset_serialno(vf->os,vf->serialnos[i]); + + while(1){ + ogg_packet op={0,0,0,0,0,0}; + + ret=_get_next_page(vf,&og,-1); + if(ret<0) + /* this should not be possible unless the file is + truncated/mangled */ + break; + + if(ogg_page_serialno(&og)!=vf->serialnos[i]) + break; + + pos=ogg_page_granulepos(&og); + + /* count blocksizes of all frames in the page */ + ogg_stream_pagein(vf->os,&og); + while((result=ogg_stream_packetout(vf->os,&op))){ + if(result>0){ /* ignore holes */ + long thisblock=vorbis_packet_blocksize(vf->vi+i,&op); + if(lastblock!=-1) + accumulated+=(lastblock+thisblock)>>2; + lastblock=thisblock; + } + } + ogg_packet_release(&op); + + if(pos!=-1){ + /* pcm offset of last packet on the first audio page */ + accumulated= pos-accumulated; + break; + } + } + + /* less than zero? This is a stream with samples trimmed off + the beginning, a normal occurrence; set the offset to zero */ + if(accumulated<0)accumulated=0; + + vf->pcmlengths[i*2]=accumulated; + } + + /* get the PCM length of this link. To do this, + get the last page of the stream */ + { + ogg_int64_t end=vf->offsets[i+1]; + _seek_helper(vf,end); + + while(1){ + ret=_get_prev_page(vf,&og); + if(ret<0){ + /* this should not be possible */ + vorbis_info_clear(vf->vi+i); + vorbis_comment_clear(vf->vc+i); + break; + } + if(ogg_page_granulepos(&og)!=-1){ + vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2]; + break; + } + vf->offset=ret; + } + } + } + ogg_page_release(&og); +} + +static void _make_decode_ready(OggVorbis_File *vf){ + if(vf->ready_state!=STREAMSET)return; + if(vf->seekable){ + vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link); + }else{ + vorbis_synthesis_init(&vf->vd,vf->vi); + } + vorbis_block_init(&vf->vd,&vf->vb); + vf->ready_state=INITSET; + vf->bittrack=0; + vf->samptrack=0; + return; +} + +static int _open_seekable2(OggVorbis_File *vf){ + ogg_uint32_t serialno=vf->current_serialno; + ogg_uint32_t tempserialno; + ogg_int64_t dataoffset=vf->offset, end; + ogg_page og={0,0,0,0}; + + /* we're partially open and have a first link header state in + storage in vf */ + /* we can seek, so set out learning all about this file */ + (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END); + vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource); + + /* We get the offset for the last page of the physical bitstream. + Most OggVorbis files will contain a single logical bitstream */ + end=_get_prev_page(vf,&og); + if(end<0)return(end); + + /* more than one logical bitstream? */ + tempserialno=ogg_page_serialno(&og); + ogg_page_release(&og); + + if(tempserialno!=serialno){ + + /* Chained bitstream. Bisect-search each logical bitstream + section. Do so based on serial number only */ + if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD); + + }else{ + + /* Only one logical bitstream */ + if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD); + + } + + /* the initial header memory is referenced by vf after; don't free it */ + _prefetch_all_headers(vf,dataoffset); + return(ov_raw_seek(vf,0)); +} + +/* clear out the current logical bitstream decoder */ +static void _decode_clear(OggVorbis_File *vf){ + vorbis_dsp_clear(&vf->vd); + vorbis_block_clear(&vf->vb); + vf->ready_state=OPENED; +} + +/* fetch and process a packet. Handles the case where we're at a + bitstream boundary and dumps the decoding machine. If the decoding + machine is unloaded, it loads it. It also keeps pcm_offset up to + date (seek and read both use this. seek uses a special hack with + readp). + + return: <0) error, OV_HOLE (lost packet) or OV_EOF + 0) need more data (only if readp==0) + 1) got a packet +*/ + +static int _fetch_and_process_packet(OggVorbis_File *vf, + int readp, + int spanp){ + ogg_page og={0,0,0,0}; + ogg_packet op={0,0,0,0,0,0}; + int ret=0; + + /* handle one packet. Try to fetch it from current stream state */ + /* extract packets from page */ + while(1){ + + /* process a packet if we can. If the machine isn't loaded, + neither is a page */ + if(vf->ready_state==INITSET){ + while(1) { + int result=ogg_stream_packetout(vf->os,&op); + ogg_int64_t granulepos; + + if(result<0){ + ret=OV_HOLE; /* hole in the data. */ + goto cleanup; + } + if(result>0){ + /* got a packet. process it */ + granulepos=op.granulepos; + if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy + header handling. The + header packets aren't + audio, so if/when we + submit them, + vorbis_synthesis will + reject them */ + + /* suck in the synthesis data and track bitrate */ + { + int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); + /* for proper use of libvorbis within libvorbisfile, + oldsamples will always be zero. */ + if(oldsamples){ + ret=OV_EFAULT; + goto cleanup; + } + + vorbis_synthesis_blockin(&vf->vd,&vf->vb); + vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; + vf->bittrack+=op.bytes*8; + } + + /* update the pcm offset. */ + if(granulepos!=-1 && !op.e_o_s){ + int link=(vf->seekable?vf->current_link:0); + int i,samples; + + /* this packet has a pcm_offset on it (the last packet + completed on a page carries the offset) After processing + (above), we know the pcm position of the *last* sample + ready to be returned. Find the offset of the *first* + + As an aside, this trick is inaccurate if we begin + reading anew right at the last page; the end-of-stream + granulepos declares the last frame in the stream, and the + last packet of the last page may be a partial frame. + So, we need a previous granulepos from an in-sequence page + to have a reference point. Thus the !op.e_o_s clause + above */ + + if(vf->seekable && link>0) + granulepos-=vf->pcmlengths[link*2]; + if(granulepos<0)granulepos=0; /* actually, this + shouldn't be possible + here unless the stream + is very broken */ + + samples=vorbis_synthesis_pcmout(&vf->vd,NULL); + + granulepos-=samples; + for(i=0;ipcmlengths[i*2+1]; + vf->pcm_offset=granulepos; + } + ret=1; + goto cleanup; + } + } + else + break; + } + } + + if(vf->ready_state>=OPENED){ + int ret; + if(!readp){ + ret=0; + goto cleanup; + } + if((ret=_get_next_page(vf,&og,-1))<0){ + ret=OV_EOF; /* eof. leave unitialized */ + goto cleanup; + } + + /* bitrate tracking; add the header's bytes here, the body bytes + are done by packet above */ + vf->bittrack+=og.header_len*8; + + /* has our decoding just traversed a bitstream boundary? */ + if(vf->ready_state==INITSET){ + if(vf->current_serialno!=ogg_page_serialno(&og)){ + if(!spanp){ + ret=OV_EOF; + goto cleanup; + } + + _decode_clear(vf); + + if(!vf->seekable){ + vorbis_info_clear(vf->vi); + vorbis_comment_clear(vf->vc); + } + } + } + } + + /* Do we need to load a new machine before submitting the page? */ + /* This is different in the seekable and non-seekable cases. + + In the seekable case, we already have all the header + information loaded and cached; we just initialize the machine + with it and continue on our merry way. + + In the non-seekable (streaming) case, we'll only be at a + boundary if we just left the previous logical bitstream and + we're now nominally at the header of the next bitstream + */ + + if(vf->ready_state!=INITSET){ + int link; + + if(vf->ready_stateseekable){ + vf->current_serialno=ogg_page_serialno(&og); + + /* match the serialno to bitstream section. We use this rather than + offset positions to avoid problems near logical bitstream + boundaries */ + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links){ + ret=OV_EBADLINK; /* sign of a bogus stream. error out, + leave machine uninitialized */ + goto cleanup; + } + + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + vf->ready_state=STREAMSET; + + }else{ + /* we're streaming */ + /* fetch the three header packets, build the info struct */ + + int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og); + if(ret) goto cleanup; + vf->current_link++; + link=0; + } + } + + _make_decode_ready(vf); + } + ogg_stream_pagein(vf->os,&og); + } + cleanup: + ogg_packet_release(&op); + ogg_page_release(&og); + return ret; +} + +/* if, eg, 64 bit stdio is configured by default, this will build with + fseek64 */ +static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){ + if(f==NULL)return(-1); + return fseek(f,off,whence); +} + +static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, + long ibytes, ov_callbacks callbacks){ + int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); + int ret; + + memset(vf,0,sizeof(*vf)); + vf->datasource=f; + vf->callbacks = callbacks; + + /* init the framing state */ + vf->oy=ogg_sync_create(); + + /* perhaps some data was previously read into a buffer for testing + against other stream types. Allow initialization from this + previously read data (as we may be reading from a non-seekable + stream) */ + if(initial){ + unsigned char *buffer=ogg_sync_bufferin(vf->oy,ibytes); + memcpy(buffer,initial,ibytes); + ogg_sync_wrote(vf->oy,ibytes); + } + + /* can we seek? Stevens suggests the seek test was portable */ + if(offsettest!=-1)vf->seekable=1; + + /* No seeking yet; Set up a 'single' (current) logical bitstream + entry for partial open */ + vf->links=1; + vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi)); + vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc)); + vf->os=ogg_stream_create(-1); /* fill in the serialno later */ + + /* Try to fetch the headers, maintaining all the storage */ + if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){ + vf->datasource=NULL; + ov_clear(vf); + }else if(vf->ready_state < PARTOPEN) + vf->ready_state=PARTOPEN; + return(ret); +} + +static int _ov_open2(OggVorbis_File *vf){ + if(vf->ready_state < OPENED) + vf->ready_state=OPENED; + if(vf->seekable){ + int ret=_open_seekable2(vf); + if(ret){ + vf->datasource=NULL; + ov_clear(vf); + } + return(ret); + } + return 0; +} + + +/* clear out the OggVorbis_File struct */ +int ov_clear(OggVorbis_File *vf){ + if(vf){ + vorbis_block_clear(&vf->vb); + vorbis_dsp_clear(&vf->vd); + ogg_stream_destroy(vf->os); + + if(vf->vi && vf->links){ + int i; + for(i=0;ilinks;i++){ + vorbis_info_clear(vf->vi+i); + vorbis_comment_clear(vf->vc+i); + } + _ogg_free(vf->vi); + _ogg_free(vf->vc); + } + if(vf->dataoffsets)_ogg_free(vf->dataoffsets); + if(vf->pcmlengths)_ogg_free(vf->pcmlengths); + if(vf->serialnos)_ogg_free(vf->serialnos); + if(vf->offsets)_ogg_free(vf->offsets); + ogg_sync_destroy(vf->oy); + + if(vf->datasource)(vf->callbacks.close_func)(vf->datasource); + memset(vf,0,sizeof(*vf)); + } +#ifdef DEBUG_LEAKS + _VDBG_dump(); +#endif + return(0); +} + +/* inspects the OggVorbis file and finds/documents all the logical + bitstreams contained in it. Tries to be tolerant of logical + bitstream sections that are truncated/woogie. + + return: -1) error + 0) OK +*/ + +int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, + ov_callbacks callbacks){ + int ret=_ov_open1(f,vf,initial,ibytes,callbacks); + if(ret)return ret; + return _ov_open2(vf); +} + +int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ + ov_callbacks callbacks = { + (size_t (*)(void *, size_t, size_t, void *)) fread, + (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, + (int (*)(void *)) fclose, + (long (*)(void *)) ftell + }; + + return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks); +} + +/* Only partially open the vorbis file; test for Vorbisness, and load + the headers for the first chain. Do not seek (although test for + seekability). Use ov_test_open to finish opening the file, else + ov_clear to close/free it. Same return codes as open. */ + +int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, + ov_callbacks callbacks) +{ + return _ov_open1(f,vf,initial,ibytes,callbacks); +} + +int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ + ov_callbacks callbacks = { + (size_t (*)(void *, size_t, size_t, void *)) fread, + (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, + (int (*)(void *)) fclose, + (long (*)(void *)) ftell + }; + + return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks); +} + +int ov_test_open(OggVorbis_File *vf){ + if(vf->ready_state!=PARTOPEN)return(OV_EINVAL); + return _ov_open2(vf); +} + +/* How many logical bitstreams in this physical bitstream? */ +long ov_streams(OggVorbis_File *vf){ + return vf->links; +} + +/* Is the FILE * associated with vf seekable? */ +long ov_seekable(OggVorbis_File *vf){ + return vf->seekable; +} + +/* returns the bitrate for a given logical bitstream or the entire + physical bitstream. If the file is open for random access, it will + find the *actual* average bitrate. If the file is streaming, it + returns the nominal bitrate (if set) else the average of the + upper/lower bounds (if set) else -1 (unset). + + If you want the actual bitrate field settings, get them from the + vorbis_info structs */ + +long ov_bitrate(OggVorbis_File *vf,int i){ + if(vf->ready_state=vf->links)return(OV_EINVAL); + if(!vf->seekable && i!=0)return(ov_bitrate(vf,0)); + if(i<0){ + ogg_int64_t bits=0; + int i; + for(i=0;ilinks;i++) + bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8; + /* This once read: return(rint(bits/ov_time_total(vf,-1))); + * gcc 3.x on x86 miscompiled this at optimisation level 2 and above, + * so this is slightly transformed to make it work. + */ + return(bits*1000/ov_time_total(vf,-1)); + }else{ + if(vf->seekable){ + /* return the actual bitrate */ + return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i)); + }else{ + /* return nominal if set */ + if(vf->vi[i].bitrate_nominal>0){ + return vf->vi[i].bitrate_nominal; + }else{ + if(vf->vi[i].bitrate_upper>0){ + if(vf->vi[i].bitrate_lower>0){ + return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; + }else{ + return vf->vi[i].bitrate_upper; + } + } + return(OV_FALSE); + } + } + } +} + +/* returns the actual bitrate since last call. returns -1 if no + additional data to offer since last call (or at beginning of stream), + EINVAL if stream is only partially open +*/ +long ov_bitrate_instant(OggVorbis_File *vf){ + int link=(vf->seekable?vf->current_link:0); + long ret; + if(vf->ready_statesamptrack==0)return(OV_FALSE); + ret=vf->bittrack/vf->samptrack*vf->vi[link].rate; + vf->bittrack=0; + vf->samptrack=0; + return(ret); +} + +/* Guess */ +long ov_serialnumber(OggVorbis_File *vf,int i){ + if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1)); + if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1)); + if(i<0){ + return(vf->current_serialno); + }else{ + return(vf->serialnos[i]); + } +} + +/* returns: total raw (compressed) length of content if i==-1 + raw (compressed) length of that logical bitstream for i==0 to n + OV_EINVAL if the stream is not seekable (we can't know the length) + or if stream is only partially open +*/ +ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ + if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); + if(i<0){ + ogg_int64_t acc=0; + int i; + for(i=0;ilinks;i++) + acc+=ov_raw_total(vf,i); + return(acc); + }else{ + return(vf->offsets[i+1]-vf->offsets[i]); + } +} + +/* returns: total PCM length (samples) of content if i==-1 PCM length + (samples) of that logical bitstream for i==0 to n + OV_EINVAL if the stream is not seekable (we can't know the + length) or only partially open +*/ +ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){ + if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); + if(i<0){ + ogg_int64_t acc=0; + int i; + for(i=0;ilinks;i++) + acc+=ov_pcm_total(vf,i); + return(acc); + }else{ + return(vf->pcmlengths[i*2+1]); + } +} + +/* returns: total milliseconds of content if i==-1 + milliseconds in that logical bitstream for i==0 to n + OV_EINVAL if the stream is not seekable (we can't know the + length) or only partially open +*/ +ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){ + if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); + if(i<0){ + ogg_int64_t acc=0; + int i; + for(i=0;ilinks;i++) + acc+=ov_time_total(vf,i); + return(acc); + }else{ + return(((ogg_int64_t)vf->pcmlengths[i*2+1])*1000/vf->vi[i].rate); + } +} + +/* seek to an offset relative to the *compressed* data. This also + scans packets to update the PCM cursor. It will cross a logical + bitstream boundary, but only if it can't get any packets out of the + tail of the bitstream we seek to (so no surprises). + + returns zero on success, nonzero on failure */ + +int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ + ogg_stream_state *work_os=NULL; + ogg_page og={0,0,0,0}; + ogg_packet op={0,0,0,0,0,0}; + + if(vf->ready_stateseekable) + return(OV_ENOSEEK); /* don't dump machine if we can't seek */ + + if(pos<0 || pos>vf->end)return(OV_EINVAL); + + /* don't yet clear out decoding machine (if it's initialized), in + the case we're in the same link. Restart the decode lapping, and + let _fetch_and_process_packet deal with a potential bitstream + boundary */ + vf->pcm_offset=-1; + ogg_stream_reset_serialno(vf->os, + vf->current_serialno); /* must set serialno */ + vorbis_synthesis_restart(&vf->vd); + + _seek_helper(vf,pos); + + /* we need to make sure the pcm_offset is set, but we don't want to + advance the raw cursor past good packets just to get to the first + with a granulepos. That's not equivalent behavior to beginning + decoding as immediately after the seek position as possible. + + So, a hack. We use two stream states; a local scratch state and + the shared vf->os stream state. We use the local state to + scan, and the shared state as a buffer for later decode. + + Unfortuantely, on the last page we still advance to last packet + because the granulepos on the last page is not necessarily on a + packet boundary, and we need to make sure the granpos is + correct. + */ + + { + int lastblock=0; + int accblock=0; + int thisblock; + int eosflag=0; + + work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */ + while(1){ + if(vf->ready_state>=STREAMSET){ + /* snarf/scan a packet if we can */ + int result=ogg_stream_packetout(work_os,&op); + + if(result>0){ + + if(vf->vi[vf->current_link].codec_setup){ + thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); + if(thisblock<0){ + ogg_stream_packetout(vf->os,NULL); + thisblock=0; + }else{ + + if(eosflag) + ogg_stream_packetout(vf->os,NULL); + else + if(lastblock)accblock+=(lastblock+thisblock)>>2; + } + + if(op.granulepos!=-1){ + int i,link=vf->current_link; + ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; + if(granulepos<0)granulepos=0; + + for(i=0;ipcmlengths[i*2+1]; + vf->pcm_offset=granulepos-accblock; + break; + } + lastblock=thisblock; + continue; + }else + ogg_stream_packetout(vf->os,NULL); + } + } + + if(!lastblock){ + if(_get_next_page(vf,&og,-1)<0){ + vf->pcm_offset=ov_pcm_total(vf,-1); + break; + } + }else{ + /* huh? Bogus stream with packets but no granulepos */ + vf->pcm_offset=-1; + break; + } + + /* has our decoding just traversed a bitstream boundary? */ + if(vf->ready_state>=STREAMSET) + if(vf->current_serialno!=ogg_page_serialno(&og)){ + _decode_clear(vf); /* clear out stream state */ + ogg_stream_destroy(work_os); + } + + if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links) + goto seek_error; /* sign of a bogus stream. error out, + leave machine uninitialized */ + + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + ogg_stream_reset_serialno(work_os,vf->current_serialno); + vf->ready_state=STREAMSET; + + } + + { + ogg_page dup; + ogg_page_dup(&dup,&og); + eosflag=ogg_page_eos(&og); + ogg_stream_pagein(vf->os,&og); + ogg_stream_pagein(work_os,&dup); + } + } + } + + ogg_packet_release(&op); + ogg_page_release(&og); + ogg_stream_destroy(work_os); + vf->bittrack=0; + vf->samptrack=0; + return(0); + + seek_error: + ogg_packet_release(&op); + ogg_page_release(&og); + + /* dump the machine so we're in a known state */ + vf->pcm_offset=-1; + ogg_stream_destroy(work_os); + _decode_clear(vf); + return OV_EBADLINK; +} + +/* Page granularity seek (faster than sample granularity because we + don't do the last bit of decode to find a specific sample). + + Seek to the last [granule marked] page preceeding the specified pos + location, such that decoding past the returned point will quickly + arrive at the requested position. */ +int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ + int link=-1; + ogg_int64_t result=0; + ogg_int64_t total=ov_pcm_total(vf,-1); + ogg_page og={0,0,0,0}; + ogg_packet op={0,0,0,0,0,0}; + + if(vf->ready_stateseekable)return(OV_ENOSEEK); + if(pos<0 || pos>total)return(OV_EINVAL); + + /* which bitstream section does this pcm offset occur in? */ + for(link=vf->links-1;link>=0;link--){ + total-=vf->pcmlengths[link*2+1]; + if(pos>=total)break; + } + + /* search within the logical bitstream for the page with the highest + pcm_pos preceeding (or equal to) pos. There is a danger here; + missing pages or incorrect frame number information in the + bitstream could make our task impossible. Account for that (it + would be an error condition) */ + + /* new search algorithm by HB (Nicholas Vinen) */ + { + ogg_int64_t end=vf->offsets[link+1]; + ogg_int64_t begin=vf->offsets[link]; + ogg_int64_t begintime = vf->pcmlengths[link*2]; + ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime; + ogg_int64_t target=pos-total+begintime; + ogg_int64_t best=begin; + + while(beginoffset); + if(result==OV_EREAD) goto seek_error; + if(result<0){ + if(bisect<=begin+1) + end=begin; /* found it */ + else{ + if(bisect==0) goto seek_error; + bisect-=CHUNKSIZE; + if(bisect<=begin)bisect=begin+1; + _seek_helper(vf,bisect); + } + }else{ + ogg_int64_t granulepos=ogg_page_granulepos(&og); + if(granulepos==-1)continue; + if(granuleposoffset; /* raw offset of next page */ + begintime=granulepos; + + if(target-begintime>44100)break; + bisect=begin; /* *not* begin + 1 */ + }else{ + if(bisect<=begin+1) + end=begin; /* found it */ + else{ + if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ + end=result; + bisect-=CHUNKSIZE; /* an endless loop otherwise. */ + if(bisect<=begin)bisect=begin+1; + _seek_helper(vf,bisect); + }else{ + end=result; + endtime=granulepos; + break; + } + } + } + } + } + } + + /* found our page. seek to it, update pcm offset. Easier case than + raw_seek, don't keep packets preceeding granulepos. */ + { + + /* seek */ + _seek_helper(vf,best); + vf->pcm_offset=-1; + + if(_get_next_page(vf,&og,-1)<0){ + ogg_page_release(&og); + return(OV_EOF); /* shouldn't happen */ + } + + if(link!=vf->current_link){ + /* Different link; dump entire decode machine */ + _decode_clear(vf); + + vf->current_link=link; + vf->current_serialno=ogg_page_serialno(&og); + vf->ready_state=STREAMSET; + + }else{ + vorbis_synthesis_restart(&vf->vd); + } + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + ogg_stream_pagein(vf->os,&og); + + /* pull out all but last packet; the one with granulepos */ + while(1){ + result=ogg_stream_packetpeek(vf->os,&op); + if(result==0){ + /* !!! the packet finishing this page originated on a + preceeding page. Keep fetching previous pages until we + get one with a granulepos or without the 'continued' flag + set. Then just use raw_seek for simplicity. */ + + _seek_helper(vf,best); + + while(1){ + result=_get_prev_page(vf,&og); + if(result<0) goto seek_error; + if(ogg_page_granulepos(&og)>-1 || + !ogg_page_continued(&og)){ + return ov_raw_seek(vf,result); + } + vf->offset=result; + } + } + if(result<0){ + result = OV_EBADPACKET; + goto seek_error; + } + if(op.granulepos!=-1){ + vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; + if(vf->pcm_offset<0)vf->pcm_offset=0; + vf->pcm_offset+=total; + break; + }else + result=ogg_stream_packetout(vf->os,NULL); + } + } + } + + /* verify result */ + if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){ + result=OV_EFAULT; + goto seek_error; + } + vf->bittrack=0; + vf->samptrack=0; + + ogg_page_release(&og); + ogg_packet_release(&op); + return(0); + + seek_error: + + ogg_page_release(&og); + ogg_packet_release(&op); + + /* dump machine so we're in a known state */ + vf->pcm_offset=-1; + _decode_clear(vf); + return (int)result; +} + +/* seek to a sample offset relative to the decompressed pcm stream + returns zero on success, nonzero on failure */ + +int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ + ogg_packet op={0,0,0,0,0,0}; + ogg_page og={0,0,0,0}; + int thisblock,lastblock=0; + int ret=ov_pcm_seek_page(vf,pos); + if(ret<0)return(ret); + _make_decode_ready(vf); + + /* discard leading packets we don't need for the lapping of the + position we want; don't decode them */ + + while(1){ + + int ret=ogg_stream_packetpeek(vf->os,&op); + if(ret>0){ + thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); + if(thisblock<0){ + ogg_stream_packetout(vf->os,NULL); + continue; /* non audio packet */ + } + if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2; + + if(vf->pcm_offset+((thisblock+ + vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break; + + /* remove the packet from packet queue and track its granulepos */ + ogg_stream_packetout(vf->os,NULL); + vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with + only tracking, no + pcm_decode */ + vorbis_synthesis_blockin(&vf->vd,&vf->vb); + + /* end of logical stream case is hard, especially with exact + length positioning. */ + + if(op.granulepos>-1){ + int i; + /* always believe the stream markers */ + vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; + if(vf->pcm_offset<0)vf->pcm_offset=0; + for(i=0;icurrent_link;i++) + vf->pcm_offset+=vf->pcmlengths[i*2+1]; + } + + lastblock=thisblock; + + }else{ + if(ret<0 && ret!=OV_HOLE)break; + + /* suck in a new page */ + if(_get_next_page(vf,&og,-1)<0)break; + if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf); + + if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links){ + ogg_page_release(&og); + ogg_packet_release(&op); + return(OV_EBADLINK); + } + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + vf->ready_state=STREAMSET; + _make_decode_ready(vf); + lastblock=0; + } + + ogg_stream_pagein(vf->os,&og); + } + } + + vf->bittrack=0; + vf->samptrack=0; + /* discard samples until we reach the desired position. Crossing a + logical bitstream boundary with abandon is OK. */ + while(vf->pcm_offsetpcm_offset; + long samples=vorbis_synthesis_pcmout(&vf->vd,NULL); + + if(samples>target)samples=target; + vorbis_synthesis_read(&vf->vd,samples); + vf->pcm_offset+=samples; + + if(samplespcm_offset=ov_pcm_total(vf,-1); /* eof */ + } + + ogg_page_release(&og); + ogg_packet_release(&op); + return 0; +} + +/* seek to a playback time relative to the decompressed pcm stream + returns zero on success, nonzero on failure */ +int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ + /* translate time to PCM position and call ov_pcm_seek */ + + int link=-1; + ogg_int64_t pcm_total=ov_pcm_total(vf,-1); + ogg_int64_t time_total=ov_time_total(vf,-1); + + if(vf->ready_stateseekable)return(OV_ENOSEEK); + if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL); + + /* which bitstream section does this time offset occur in? */ + for(link=vf->links-1;link>=0;link--){ + pcm_total-=vf->pcmlengths[link*2+1]; + time_total-=ov_time_total(vf,link); + if(milliseconds>=time_total)break; + } + + /* enough information to convert time offset to pcm offset */ + { + ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; + return(ov_pcm_seek(vf,target)); + } +} + +/* page-granularity version of ov_time_seek + returns zero on success, nonzero on failure */ +int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ + /* translate time to PCM position and call ov_pcm_seek */ + + int link=-1; + ogg_int64_t pcm_total=ov_pcm_total(vf,-1); + ogg_int64_t time_total=ov_time_total(vf,-1); + + if(vf->ready_stateseekable)return(OV_ENOSEEK); + if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL); + + /* which bitstream section does this time offset occur in? */ + for(link=vf->links-1;link>=0;link--){ + pcm_total-=vf->pcmlengths[link*2+1]; + time_total-=ov_time_total(vf,link); + if(milliseconds>=time_total)break; + } + + /* enough information to convert time offset to pcm offset */ + { + ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; + return(ov_pcm_seek_page(vf,target)); + } +} + +/* tell the current stream offset cursor. Note that seek followed by + tell will likely not give the set offset due to caching */ +ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ + if(vf->ready_stateoffset); +} + +/* return PCM offset (sample) of next PCM sample to be read */ +ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){ + if(vf->ready_statepcm_offset); +} + +/* return time offset (milliseconds) of next PCM sample to be read */ +ogg_int64_t ov_time_tell(OggVorbis_File *vf){ + int link=0; + ogg_int64_t pcm_total=0; + ogg_int64_t time_total=0; + + if(vf->ready_stateseekable){ + pcm_total=ov_pcm_total(vf,-1); + time_total=ov_time_total(vf,-1); + + /* which bitstream section does this time offset occur in? */ + for(link=vf->links-1;link>=0;link--){ + pcm_total-=vf->pcmlengths[link*2+1]; + time_total-=ov_time_total(vf,link); + if(vf->pcm_offset>=pcm_total)break; + } + } + + return(time_total+(1000*vf->pcm_offset-pcm_total)/vf->vi[link].rate); +} + +/* link: -1) return the vorbis_info struct for the bitstream section + currently being decoded + 0-n) to request information for a specific bitstream section + + In the case of a non-seekable bitstream, any call returns the + current bitstream. NULL in the case that the machine is not + initialized */ + +vorbis_info *ov_info(OggVorbis_File *vf,int link){ + if(vf->seekable){ + if(link<0) + if(vf->ready_state>=STREAMSET) + return vf->vi+vf->current_link; + else + return vf->vi; + else + if(link>=vf->links) + return NULL; + else + return vf->vi+link; + }else{ + return vf->vi; + } +} + +/* grr, strong typing, grr, no templates/inheritence, grr */ +vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ + if(vf->seekable){ + if(link<0) + if(vf->ready_state>=STREAMSET) + return vf->vc+vf->current_link; + else + return vf->vc; + else + if(link>=vf->links) + return NULL; + else + return vf->vc+link; + }else{ + return vf->vc; + } +} + +/* up to this point, everything could more or less hide the multiple + logical bitstream nature of chaining from the toplevel application + if the toplevel application didn't particularly care. However, at + the point that we actually read audio back, the multiple-section + nature must surface: Multiple bitstream sections do not necessarily + have to have the same number of channels or sampling rate. + + ov_read returns the sequential logical bitstream number currently + being decoded along with the PCM data in order that the toplevel + application can take action on channel/sample rate changes. This + number will be incremented even for streamed (non-seekable) streams + (for seekable streams, it represents the actual logical bitstream + index within the physical bitstream. Note that the accessor + functions above are aware of this dichotomy). + + input values: buffer) a buffer to hold packed PCM data for return + length) the byte length requested to be placed into buffer + + return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL) + 0) EOF + n) number of bytes of PCM actually returned. The + below works on a packet-by-packet basis, so the + return length is not related to the 'length' passed + in, just guaranteed to fit. + + *section) set to the logical bitstream number */ + +long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ + int i,j; + + ogg_int32_t **pcm; + long samples; + + if(vf->ready_stateready_state==INITSET){ + samples=vorbis_synthesis_pcmout(&vf->vd,&pcm); + if(samples)break; + } + + /* suck in another packet */ + { + int ret=_fetch_and_process_packet(vf,1,1); + if(ret==OV_EOF) + return(0); + if(ret<=0) + return(ret); + } + + } + + if(samples>0){ + + /* yay! proceed to pack data into the byte buffer */ + + long channels=ov_info(vf,-1)->channels; + + if(samples>(bytes_req/(2*channels))) + samples=bytes_req/(2*channels); + + for(i=0;i>9); + dest+=channels; + } + } + + vorbis_synthesis_read(&vf->vd,samples); + vf->pcm_offset+=samples; + if(bitstream)*bitstream=vf->current_link; + return(samples*2*channels); + }else{ + return(samples); + } +} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/tremor/window.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/libtremor/tremor/window.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,83 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * + * * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * + * * + ******************************************************************** + + function: window functions + + ********************************************************************/ + +#include +#include +#include "misc.h" +#include "window.h" +#include "window_lookup.h" + +const void *_vorbis_window(int type, int left){ + + switch(type){ + case 0: + + 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; + case 4096: + return vwin8192; + default: + return(0); + } + break; + default: + return(0); + } +} + +void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], + long *blocksizes, + int lW,int W,int nW){ + + LOOKUP_T *window[2]={window_p[0],window_p[1]}; + long n=blocksizes[W]; + long ln=blocksizes[lW]; + long rn=blocksizes[nW]; + + long leftbegin=n/4-ln/4; + long leftend=leftbegin+ln/2; + + long rightbegin=n/2+n/4-rn/4; + long rightend=rightbegin+rn/2; + + int i,p; + + for(i=0;i -#include -#include -#include -#include - -#include "ivorbiscodec.h" -#include "ivorbisfile.h" - -#include "misc.h" - -/* A 'chained bitstream' is a Vorbis bitstream that contains more than - one logical bitstream arranged end to end (the only form of Ogg - multiplexing allowed in a Vorbis bitstream; grouping [parallel - multiplexing] is not allowed in Vorbis) */ - -/* A Vorbis file can be played beginning to end (streamed) without - worrying ahead of time about chaining (see decoder_example.c). If - we have the whole file, however, and want random access - (seeking/scrubbing) or desire to know the total length/time of a - file, we need to account for the possibility of chaining. */ - -/* We can handle things a number of ways; we can determine the entire - bitstream structure right off the bat, or find pieces on demand. - This example determines and caches structure for the entire - bitstream, but builds a virtual decoder on the fly when moving - between links in the chain. */ - -/* There are also different ways to implement seeking. Enough - information exists in an Ogg bitstream to seek to - sample-granularity positions in the output. Or, one can seek by - picking some portion of the stream roughly in the desired area if - we only want coarse navigation through the stream. */ - -/************************************************************************* - * Many, many internal helpers. The intention is not to be confusing; - * rampant duplication and monolithic function implementation would be - * harder to understand anyway. The high level functions are last. Begin - * grokking near the end of the file */ - - -/* read a little more data from the file/pipe into the ogg_sync framer */ -static long _get_data(OggVorbis_File *vf){ - errno=0; - if(vf->datasource){ - unsigned char *buffer=ogg_sync_bufferin(vf->oy,CHUNKSIZE); - long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource); - if(bytes>0)ogg_sync_wrote(vf->oy,bytes); - if(bytes==0 && errno)return(-1); - return(bytes); - }else - return(0); -} - -/* save a tiny smidge of verbosity to make the code more readable */ -static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){ - if(vf->datasource){ - (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET); - vf->offset=offset; - ogg_sync_reset(vf->oy); - }else{ - /* shouldn't happen unless someone writes a broken callback */ - return; - } -} - -/* The read/seek functions track absolute position within the stream */ - -/* from the head of the stream, get the next page. boundary specifies - if the function is allowed to fetch more data from the stream (and - how much) or only use internally buffered data. - - boundary: -1) unbounded search - 0) read no additional data; use cached only - n) search for a new page beginning for n bytes - - return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD) - n) found a page at absolute offset n - - produces a refcounted page */ - -static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, - ogg_int64_t boundary){ - if(boundary>0)boundary+=vf->offset; - while(1){ - long more; - - if(boundary>0 && vf->offset>=boundary)return(OV_FALSE); - more=ogg_sync_pageseek(vf->oy,og); - - if(more<0){ - /* skipped n bytes */ - vf->offset-=more; - }else{ - if(more==0){ - /* send more paramedics */ - if(!boundary)return(OV_FALSE); - { - long ret=_get_data(vf); - if(ret==0)return(OV_EOF); - if(ret<0)return(OV_EREAD); - } - }else{ - /* got a page. Return the offset at the page beginning, - advance the internal offset past the page end */ - ogg_int64_t ret=vf->offset; - vf->offset+=more; - return(ret); - - } - } - } -} - -/* find the latest page beginning before the current stream cursor - position. Much dirtier than the above as Ogg doesn't have any - backward search linkage. no 'readp' as it will certainly have to - read. */ -/* returns offset or OV_EREAD, OV_FAULT and produces a refcounted page */ - -static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){ - ogg_int64_t begin=vf->offset; - ogg_int64_t end=begin; - ogg_int64_t ret; - ogg_int64_t offset=-1; - - while(offset==-1){ - begin-=CHUNKSIZE; - if(begin<0) - begin=0; - _seek_helper(vf,begin); - while(vf->offsetoffset); - if(ret==OV_EREAD)return(OV_EREAD); - if(ret<0){ - break; - }else{ - offset=ret; - } - } - } - - /* we have the offset. Actually snork and hold the page now */ - _seek_helper(vf,offset); - ret=_get_next_page(vf,og,CHUNKSIZE); - if(ret<0) - /* this shouldn't be possible */ - return(OV_EFAULT); - - return(offset); -} - -/* finds each bitstream link one at a time using a bisection search - (has to begin by knowing the offset of the lb's initial page). - Recurses for each link so it can alloc the link storage after - finding them all, then unroll and fill the cache at the same time */ -static int _bisect_forward_serialno(OggVorbis_File *vf, - ogg_int64_t begin, - ogg_int64_t searched, - ogg_int64_t end, - ogg_uint32_t currentno, - long m){ - ogg_int64_t endsearched=end; - ogg_int64_t next=end; - ogg_page og={0,0,0,0}; - ogg_int64_t ret; - - /* the below guards against garbage seperating the last and - first pages of two links. */ - while(searched=0)next=ret; - }else{ - searched=ret+og.header_len+og.body_len; - } - ogg_page_release(&og); - } - - _seek_helper(vf,next); - ret=_get_next_page(vf,&og,-1); - if(ret==OV_EREAD)return(OV_EREAD); - - if(searched>=end || ret<0){ - ogg_page_release(&og); - vf->links=m+1; - vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets)); - vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos)); - vf->offsets[m+1]=searched; - }else{ - ret=_bisect_forward_serialno(vf,next,vf->offset, - end,ogg_page_serialno(&og),m+1); - ogg_page_release(&og); - if(ret==OV_EREAD)return(OV_EREAD); - } - - vf->offsets[m]=begin; - vf->serialnos[m]=currentno; - return(0); -} - -/* uses the local ogg_stream storage in vf; this is important for - non-streaming input sources */ -/* consumes the page that's passed in (if any) */ - -static int _fetch_headers(OggVorbis_File *vf, - vorbis_info *vi, - vorbis_comment *vc, - ogg_uint32_t *serialno, - ogg_page *og_ptr){ - ogg_page og={0,0,0,0}; - ogg_packet op={0,0,0,0,0,0}; - int i,ret; - - if(!og_ptr){ - ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE); - if(llret==OV_EREAD)return(OV_EREAD); - if(llret<0)return OV_ENOTVORBIS; - og_ptr=&og; - } - - ogg_stream_reset_serialno(vf->os,ogg_page_serialno(og_ptr)); - if(serialno)*serialno=vf->os->serialno; - vf->ready_state=STREAMSET; - - /* extract the initial header from the first page and verify that the - Ogg bitstream is in fact Vorbis data */ - - vorbis_info_init(vi); - vorbis_comment_init(vc); - - i=0; - while(i<3){ - ogg_stream_pagein(vf->os,og_ptr); - while(i<3){ - int result=ogg_stream_packetout(vf->os,&op); - if(result==0)break; - if(result==-1){ - ret=OV_EBADHEADER; - goto bail_header; - } - if((ret=vorbis_synthesis_headerin(vi,vc,&op))){ - goto bail_header; - } - i++; - } - if(i<3) - if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){ - ret=OV_EBADHEADER; - goto bail_header; - } - } - - ogg_packet_release(&op); - ogg_page_release(&og); - return 0; - - bail_header: - ogg_packet_release(&op); - ogg_page_release(&og); - vorbis_info_clear(vi); - vorbis_comment_clear(vc); - vf->ready_state=OPENED; - - return ret; -} - -/* last step of the OggVorbis_File initialization; get all the - vorbis_info structs and PCM positions. Only called by the seekable - initialization (local stream storage is hacked slightly; pay - attention to how that's done) */ - -/* this is void and does not propogate errors up because we want to be - able to open and use damaged bitstreams as well as we can. Just - watch out for missing information for links in the OggVorbis_File - struct */ -static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){ - ogg_page og={0,0,0,0}; - int i; - ogg_int64_t ret; - - vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi)); - vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc)); - vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets)); - vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths)); - - for(i=0;ilinks;i++){ - if(i==0){ - /* we already grabbed the initial header earlier. Just set the offset */ - vf->dataoffsets[i]=dataoffset; - _seek_helper(vf,dataoffset); - - }else{ - - /* seek to the location of the initial header */ - - _seek_helper(vf,vf->offsets[i]); - if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){ - vf->dataoffsets[i]=-1; - }else{ - vf->dataoffsets[i]=vf->offset; - } - } - - /* fetch beginning PCM offset */ - - if(vf->dataoffsets[i]!=-1){ - ogg_int64_t accumulated=0,pos; - long lastblock=-1; - int result; - - ogg_stream_reset_serialno(vf->os,vf->serialnos[i]); - - while(1){ - ogg_packet op={0,0,0,0,0,0}; - - ret=_get_next_page(vf,&og,-1); - if(ret<0) - /* this should not be possible unless the file is - truncated/mangled */ - break; - - if(ogg_page_serialno(&og)!=vf->serialnos[i]) - break; - - pos=ogg_page_granulepos(&og); - - /* count blocksizes of all frames in the page */ - ogg_stream_pagein(vf->os,&og); - while((result=ogg_stream_packetout(vf->os,&op))){ - if(result>0){ /* ignore holes */ - long thisblock=vorbis_packet_blocksize(vf->vi+i,&op); - if(lastblock!=-1) - accumulated+=(lastblock+thisblock)>>2; - lastblock=thisblock; - } - } - ogg_packet_release(&op); - - if(pos!=-1){ - /* pcm offset of last packet on the first audio page */ - accumulated= pos-accumulated; - break; - } - } - - /* less than zero? This is a stream with samples trimmed off - the beginning, a normal occurrence; set the offset to zero */ - if(accumulated<0)accumulated=0; - - vf->pcmlengths[i*2]=accumulated; - } - - /* get the PCM length of this link. To do this, - get the last page of the stream */ - { - ogg_int64_t end=vf->offsets[i+1]; - _seek_helper(vf,end); - - while(1){ - ret=_get_prev_page(vf,&og); - if(ret<0){ - /* this should not be possible */ - vorbis_info_clear(vf->vi+i); - vorbis_comment_clear(vf->vc+i); - break; - } - if(ogg_page_granulepos(&og)!=-1){ - vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2]; - break; - } - vf->offset=ret; - } - } - } - ogg_page_release(&og); -} - -static void _make_decode_ready(OggVorbis_File *vf){ - if(vf->ready_state!=STREAMSET)return; - if(vf->seekable){ - vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link); - }else{ - vorbis_synthesis_init(&vf->vd,vf->vi); - } - vorbis_block_init(&vf->vd,&vf->vb); - vf->ready_state=INITSET; - vf->bittrack=0; - vf->samptrack=0; - return; -} - -static int _open_seekable2(OggVorbis_File *vf){ - ogg_uint32_t serialno=vf->current_serialno; - ogg_uint32_t tempserialno; - ogg_int64_t dataoffset=vf->offset, end; - ogg_page og={0,0,0,0}; - - /* we're partially open and have a first link header state in - storage in vf */ - /* we can seek, so set out learning all about this file */ - (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END); - vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource); - - /* We get the offset for the last page of the physical bitstream. - Most OggVorbis files will contain a single logical bitstream */ - end=_get_prev_page(vf,&og); - if(end<0)return(end); - - /* more than one logical bitstream? */ - tempserialno=ogg_page_serialno(&og); - ogg_page_release(&og); - - if(tempserialno!=serialno){ - - /* Chained bitstream. Bisect-search each logical bitstream - section. Do so based on serial number only */ - if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD); - - }else{ - - /* Only one logical bitstream */ - if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD); - - } - - /* the initial header memory is referenced by vf after; don't free it */ - _prefetch_all_headers(vf,dataoffset); - return(ov_raw_seek(vf,0)); -} - -/* clear out the current logical bitstream decoder */ -static void _decode_clear(OggVorbis_File *vf){ - vorbis_dsp_clear(&vf->vd); - vorbis_block_clear(&vf->vb); - vf->ready_state=OPENED; -} - -/* fetch and process a packet. Handles the case where we're at a - bitstream boundary and dumps the decoding machine. If the decoding - machine is unloaded, it loads it. It also keeps pcm_offset up to - date (seek and read both use this. seek uses a special hack with - readp). - - return: <0) error, OV_HOLE (lost packet) or OV_EOF - 0) need more data (only if readp==0) - 1) got a packet -*/ - -static int _fetch_and_process_packet(OggVorbis_File *vf, - int readp, - int spanp){ - ogg_page og={0,0,0,0}; - ogg_packet op={0,0,0,0,0,0}; - int ret=0; - - /* handle one packet. Try to fetch it from current stream state */ - /* extract packets from page */ - while(1){ - - /* process a packet if we can. If the machine isn't loaded, - neither is a page */ - if(vf->ready_state==INITSET){ - while(1) { - int result=ogg_stream_packetout(vf->os,&op); - ogg_int64_t granulepos; - - if(result<0){ - ret=OV_HOLE; /* hole in the data. */ - goto cleanup; - } - if(result>0){ - /* got a packet. process it */ - granulepos=op.granulepos; - if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy - header handling. The - header packets aren't - audio, so if/when we - submit them, - vorbis_synthesis will - reject them */ - - /* suck in the synthesis data and track bitrate */ - { - int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); - /* for proper use of libvorbis within libvorbisfile, - oldsamples will always be zero. */ - if(oldsamples){ - ret=OV_EFAULT; - goto cleanup; - } - - vorbis_synthesis_blockin(&vf->vd,&vf->vb); - vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; - vf->bittrack+=op.bytes*8; - } - - /* update the pcm offset. */ - if(granulepos!=-1 && !op.e_o_s){ - int link=(vf->seekable?vf->current_link:0); - int i,samples; - - /* this packet has a pcm_offset on it (the last packet - completed on a page carries the offset) After processing - (above), we know the pcm position of the *last* sample - ready to be returned. Find the offset of the *first* - - As an aside, this trick is inaccurate if we begin - reading anew right at the last page; the end-of-stream - granulepos declares the last frame in the stream, and the - last packet of the last page may be a partial frame. - So, we need a previous granulepos from an in-sequence page - to have a reference point. Thus the !op.e_o_s clause - above */ - - if(vf->seekable && link>0) - granulepos-=vf->pcmlengths[link*2]; - if(granulepos<0)granulepos=0; /* actually, this - shouldn't be possible - here unless the stream - is very broken */ - - samples=vorbis_synthesis_pcmout(&vf->vd,NULL); - - granulepos-=samples; - for(i=0;ipcmlengths[i*2+1]; - vf->pcm_offset=granulepos; - } - ret=1; - goto cleanup; - } - } - else - break; - } - } - - if(vf->ready_state>=OPENED){ - int ret; - if(!readp){ - ret=0; - goto cleanup; - } - if((ret=_get_next_page(vf,&og,-1))<0){ - ret=OV_EOF; /* eof. leave unitialized */ - goto cleanup; - } - - /* bitrate tracking; add the header's bytes here, the body bytes - are done by packet above */ - vf->bittrack+=og.header_len*8; - - /* has our decoding just traversed a bitstream boundary? */ - if(vf->ready_state==INITSET){ - if(vf->current_serialno!=ogg_page_serialno(&og)){ - if(!spanp){ - ret=OV_EOF; - goto cleanup; - } - - _decode_clear(vf); - - if(!vf->seekable){ - vorbis_info_clear(vf->vi); - vorbis_comment_clear(vf->vc); - } - } - } - } - - /* Do we need to load a new machine before submitting the page? */ - /* This is different in the seekable and non-seekable cases. - - In the seekable case, we already have all the header - information loaded and cached; we just initialize the machine - with it and continue on our merry way. - - In the non-seekable (streaming) case, we'll only be at a - boundary if we just left the previous logical bitstream and - we're now nominally at the header of the next bitstream - */ - - if(vf->ready_state!=INITSET){ - int link; - - if(vf->ready_stateseekable){ - vf->current_serialno=ogg_page_serialno(&og); - - /* match the serialno to bitstream section. We use this rather than - offset positions to avoid problems near logical bitstream - boundaries */ - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links){ - ret=OV_EBADLINK; /* sign of a bogus stream. error out, - leave machine uninitialized */ - goto cleanup; - } - - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - vf->ready_state=STREAMSET; - - }else{ - /* we're streaming */ - /* fetch the three header packets, build the info struct */ - - int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og); - if(ret) goto cleanup; - vf->current_link++; - link=0; - } - } - - _make_decode_ready(vf); - } - ogg_stream_pagein(vf->os,&og); - } - cleanup: - ogg_packet_release(&op); - ogg_page_release(&og); - return ret; -} - -/* if, eg, 64 bit stdio is configured by default, this will build with - fseek64 */ -static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){ - if(f==NULL)return(-1); - return fseek(f,off,whence); -} - -static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, - long ibytes, ov_callbacks callbacks){ - int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); - int ret; - - memset(vf,0,sizeof(*vf)); - vf->datasource=f; - vf->callbacks = callbacks; - - /* init the framing state */ - vf->oy=ogg_sync_create(); - - /* perhaps some data was previously read into a buffer for testing - against other stream types. Allow initialization from this - previously read data (as we may be reading from a non-seekable - stream) */ - if(initial){ - unsigned char *buffer=ogg_sync_bufferin(vf->oy,ibytes); - memcpy(buffer,initial,ibytes); - ogg_sync_wrote(vf->oy,ibytes); - } - - /* can we seek? Stevens suggests the seek test was portable */ - if(offsettest!=-1)vf->seekable=1; - - /* No seeking yet; Set up a 'single' (current) logical bitstream - entry for partial open */ - vf->links=1; - vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi)); - vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc)); - vf->os=ogg_stream_create(-1); /* fill in the serialno later */ - - /* Try to fetch the headers, maintaining all the storage */ - if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){ - vf->datasource=NULL; - ov_clear(vf); - }else if(vf->ready_state < PARTOPEN) - vf->ready_state=PARTOPEN; - return(ret); -} - -static int _ov_open2(OggVorbis_File *vf){ - if(vf->ready_state < OPENED) - vf->ready_state=OPENED; - if(vf->seekable){ - int ret=_open_seekable2(vf); - if(ret){ - vf->datasource=NULL; - ov_clear(vf); - } - return(ret); - } - return 0; -} - - -/* clear out the OggVorbis_File struct */ -int ov_clear(OggVorbis_File *vf){ - if(vf){ - vorbis_block_clear(&vf->vb); - vorbis_dsp_clear(&vf->vd); - ogg_stream_destroy(vf->os); - - if(vf->vi && vf->links){ - int i; - for(i=0;ilinks;i++){ - vorbis_info_clear(vf->vi+i); - vorbis_comment_clear(vf->vc+i); - } - _ogg_free(vf->vi); - _ogg_free(vf->vc); - } - if(vf->dataoffsets)_ogg_free(vf->dataoffsets); - if(vf->pcmlengths)_ogg_free(vf->pcmlengths); - if(vf->serialnos)_ogg_free(vf->serialnos); - if(vf->offsets)_ogg_free(vf->offsets); - ogg_sync_destroy(vf->oy); - - if(vf->datasource)(vf->callbacks.close_func)(vf->datasource); - memset(vf,0,sizeof(*vf)); - } -#ifdef DEBUG_LEAKS - _VDBG_dump(); -#endif - return(0); -} - -/* inspects the OggVorbis file and finds/documents all the logical - bitstreams contained in it. Tries to be tolerant of logical - bitstream sections that are truncated/woogie. - - return: -1) error - 0) OK -*/ - -int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, - ov_callbacks callbacks){ - int ret=_ov_open1(f,vf,initial,ibytes,callbacks); - if(ret)return ret; - return _ov_open2(vf); -} - -int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ - ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) fread, - (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, - (int (*)(void *)) fclose, - (long (*)(void *)) ftell - }; - - return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks); -} - -/* Only partially open the vorbis file; test for Vorbisness, and load - the headers for the first chain. Do not seek (although test for - seekability). Use ov_test_open to finish opening the file, else - ov_clear to close/free it. Same return codes as open. */ - -int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes, - ov_callbacks callbacks) -{ - return _ov_open1(f,vf,initial,ibytes,callbacks); -} - -int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){ - ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) fread, - (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap, - (int (*)(void *)) fclose, - (long (*)(void *)) ftell - }; - - return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks); -} - -int ov_test_open(OggVorbis_File *vf){ - if(vf->ready_state!=PARTOPEN)return(OV_EINVAL); - return _ov_open2(vf); -} - -/* How many logical bitstreams in this physical bitstream? */ -long ov_streams(OggVorbis_File *vf){ - return vf->links; -} - -/* Is the FILE * associated with vf seekable? */ -long ov_seekable(OggVorbis_File *vf){ - return vf->seekable; -} - -/* returns the bitrate for a given logical bitstream or the entire - physical bitstream. If the file is open for random access, it will - find the *actual* average bitrate. If the file is streaming, it - returns the nominal bitrate (if set) else the average of the - upper/lower bounds (if set) else -1 (unset). - - If you want the actual bitrate field settings, get them from the - vorbis_info structs */ - -long ov_bitrate(OggVorbis_File *vf,int i){ - if(vf->ready_state=vf->links)return(OV_EINVAL); - if(!vf->seekable && i!=0)return(ov_bitrate(vf,0)); - if(i<0){ - ogg_int64_t bits=0; - int i; - for(i=0;ilinks;i++) - bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8; - /* This once read: return(rint(bits/ov_time_total(vf,-1))); - * gcc 3.x on x86 miscompiled this at optimisation level 2 and above, - * so this is slightly transformed to make it work. - */ - return(bits*1000/ov_time_total(vf,-1)); - }else{ - if(vf->seekable){ - /* return the actual bitrate */ - return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i)); - }else{ - /* return nominal if set */ - if(vf->vi[i].bitrate_nominal>0){ - return vf->vi[i].bitrate_nominal; - }else{ - if(vf->vi[i].bitrate_upper>0){ - if(vf->vi[i].bitrate_lower>0){ - return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; - }else{ - return vf->vi[i].bitrate_upper; - } - } - return(OV_FALSE); - } - } - } -} - -/* returns the actual bitrate since last call. returns -1 if no - additional data to offer since last call (or at beginning of stream), - EINVAL if stream is only partially open -*/ -long ov_bitrate_instant(OggVorbis_File *vf){ - int link=(vf->seekable?vf->current_link:0); - long ret; - if(vf->ready_statesamptrack==0)return(OV_FALSE); - ret=vf->bittrack/vf->samptrack*vf->vi[link].rate; - vf->bittrack=0; - vf->samptrack=0; - return(ret); -} - -/* Guess */ -long ov_serialnumber(OggVorbis_File *vf,int i){ - if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1)); - if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1)); - if(i<0){ - return(vf->current_serialno); - }else{ - return(vf->serialnos[i]); - } -} - -/* returns: total raw (compressed) length of content if i==-1 - raw (compressed) length of that logical bitstream for i==0 to n - OV_EINVAL if the stream is not seekable (we can't know the length) - or if stream is only partially open -*/ -ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ - if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); - if(i<0){ - ogg_int64_t acc=0; - int i; - for(i=0;ilinks;i++) - acc+=ov_raw_total(vf,i); - return(acc); - }else{ - return(vf->offsets[i+1]-vf->offsets[i]); - } -} - -/* returns: total PCM length (samples) of content if i==-1 PCM length - (samples) of that logical bitstream for i==0 to n - OV_EINVAL if the stream is not seekable (we can't know the - length) or only partially open -*/ -ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){ - if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); - if(i<0){ - ogg_int64_t acc=0; - int i; - for(i=0;ilinks;i++) - acc+=ov_pcm_total(vf,i); - return(acc); - }else{ - return(vf->pcmlengths[i*2+1]); - } -} - -/* returns: total milliseconds of content if i==-1 - milliseconds in that logical bitstream for i==0 to n - OV_EINVAL if the stream is not seekable (we can't know the - length) or only partially open -*/ -ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){ - if(vf->ready_stateseekable || i>=vf->links)return(OV_EINVAL); - if(i<0){ - ogg_int64_t acc=0; - int i; - for(i=0;ilinks;i++) - acc+=ov_time_total(vf,i); - return(acc); - }else{ - return(((ogg_int64_t)vf->pcmlengths[i*2+1])*1000/vf->vi[i].rate); - } -} - -/* seek to an offset relative to the *compressed* data. This also - scans packets to update the PCM cursor. It will cross a logical - bitstream boundary, but only if it can't get any packets out of the - tail of the bitstream we seek to (so no surprises). - - returns zero on success, nonzero on failure */ - -int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ - ogg_stream_state *work_os=NULL; - ogg_page og={0,0,0,0}; - ogg_packet op={0,0,0,0,0,0}; - - if(vf->ready_stateseekable) - return(OV_ENOSEEK); /* don't dump machine if we can't seek */ - - if(pos<0 || pos>vf->end)return(OV_EINVAL); - - /* don't yet clear out decoding machine (if it's initialized), in - the case we're in the same link. Restart the decode lapping, and - let _fetch_and_process_packet deal with a potential bitstream - boundary */ - vf->pcm_offset=-1; - ogg_stream_reset_serialno(vf->os, - vf->current_serialno); /* must set serialno */ - vorbis_synthesis_restart(&vf->vd); - - _seek_helper(vf,pos); - - /* we need to make sure the pcm_offset is set, but we don't want to - advance the raw cursor past good packets just to get to the first - with a granulepos. That's not equivalent behavior to beginning - decoding as immediately after the seek position as possible. - - So, a hack. We use two stream states; a local scratch state and - the shared vf->os stream state. We use the local state to - scan, and the shared state as a buffer for later decode. - - Unfortuantely, on the last page we still advance to last packet - because the granulepos on the last page is not necessarily on a - packet boundary, and we need to make sure the granpos is - correct. - */ - - { - int lastblock=0; - int accblock=0; - int thisblock; - int eosflag=0; - - work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */ - while(1){ - if(vf->ready_state>=STREAMSET){ - /* snarf/scan a packet if we can */ - int result=ogg_stream_packetout(work_os,&op); - - if(result>0){ - - if(vf->vi[vf->current_link].codec_setup){ - thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); - if(thisblock<0){ - ogg_stream_packetout(vf->os,NULL); - thisblock=0; - }else{ - - if(eosflag) - ogg_stream_packetout(vf->os,NULL); - else - if(lastblock)accblock+=(lastblock+thisblock)>>2; - } - - if(op.granulepos!=-1){ - int i,link=vf->current_link; - ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; - if(granulepos<0)granulepos=0; - - for(i=0;ipcmlengths[i*2+1]; - vf->pcm_offset=granulepos-accblock; - break; - } - lastblock=thisblock; - continue; - }else - ogg_stream_packetout(vf->os,NULL); - } - } - - if(!lastblock){ - if(_get_next_page(vf,&og,-1)<0){ - vf->pcm_offset=ov_pcm_total(vf,-1); - break; - } - }else{ - /* huh? Bogus stream with packets but no granulepos */ - vf->pcm_offset=-1; - break; - } - - /* has our decoding just traversed a bitstream boundary? */ - if(vf->ready_state>=STREAMSET) - if(vf->current_serialno!=ogg_page_serialno(&og)){ - _decode_clear(vf); /* clear out stream state */ - ogg_stream_destroy(work_os); - } - - if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links) - goto seek_error; /* sign of a bogus stream. error out, - leave machine uninitialized */ - - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - ogg_stream_reset_serialno(work_os,vf->current_serialno); - vf->ready_state=STREAMSET; - - } - - { - ogg_page dup; - ogg_page_dup(&dup,&og); - eosflag=ogg_page_eos(&og); - ogg_stream_pagein(vf->os,&og); - ogg_stream_pagein(work_os,&dup); - } - } - } - - ogg_packet_release(&op); - ogg_page_release(&og); - ogg_stream_destroy(work_os); - vf->bittrack=0; - vf->samptrack=0; - return(0); - - seek_error: - ogg_packet_release(&op); - ogg_page_release(&og); - - /* dump the machine so we're in a known state */ - vf->pcm_offset=-1; - ogg_stream_destroy(work_os); - _decode_clear(vf); - return OV_EBADLINK; -} - -/* Page granularity seek (faster than sample granularity because we - don't do the last bit of decode to find a specific sample). - - Seek to the last [granule marked] page preceeding the specified pos - location, such that decoding past the returned point will quickly - arrive at the requested position. */ -int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ - int link=-1; - ogg_int64_t result=0; - ogg_int64_t total=ov_pcm_total(vf,-1); - ogg_page og={0,0,0,0}; - ogg_packet op={0,0,0,0,0,0}; - - if(vf->ready_stateseekable)return(OV_ENOSEEK); - if(pos<0 || pos>total)return(OV_EINVAL); - - /* which bitstream section does this pcm offset occur in? */ - for(link=vf->links-1;link>=0;link--){ - total-=vf->pcmlengths[link*2+1]; - if(pos>=total)break; - } - - /* search within the logical bitstream for the page with the highest - pcm_pos preceeding (or equal to) pos. There is a danger here; - missing pages or incorrect frame number information in the - bitstream could make our task impossible. Account for that (it - would be an error condition) */ - - /* new search algorithm by HB (Nicholas Vinen) */ - { - ogg_int64_t end=vf->offsets[link+1]; - ogg_int64_t begin=vf->offsets[link]; - ogg_int64_t begintime = vf->pcmlengths[link*2]; - ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime; - ogg_int64_t target=pos-total+begintime; - ogg_int64_t best=begin; - - while(beginoffset); - if(result==OV_EREAD) goto seek_error; - if(result<0){ - if(bisect<=begin+1) - end=begin; /* found it */ - else{ - if(bisect==0) goto seek_error; - bisect-=CHUNKSIZE; - if(bisect<=begin)bisect=begin+1; - _seek_helper(vf,bisect); - } - }else{ - ogg_int64_t granulepos=ogg_page_granulepos(&og); - if(granulepos==-1)continue; - if(granuleposoffset; /* raw offset of next page */ - begintime=granulepos; - - if(target-begintime>44100)break; - bisect=begin; /* *not* begin + 1 */ - }else{ - if(bisect<=begin+1) - end=begin; /* found it */ - else{ - if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ - end=result; - bisect-=CHUNKSIZE; /* an endless loop otherwise. */ - if(bisect<=begin)bisect=begin+1; - _seek_helper(vf,bisect); - }else{ - end=result; - endtime=granulepos; - break; - } - } - } - } - } - } - - /* found our page. seek to it, update pcm offset. Easier case than - raw_seek, don't keep packets preceeding granulepos. */ - { - - /* seek */ - _seek_helper(vf,best); - vf->pcm_offset=-1; - - if(_get_next_page(vf,&og,-1)<0){ - ogg_page_release(&og); - return(OV_EOF); /* shouldn't happen */ - } - - if(link!=vf->current_link){ - /* Different link; dump entire decode machine */ - _decode_clear(vf); - - vf->current_link=link; - vf->current_serialno=ogg_page_serialno(&og); - vf->ready_state=STREAMSET; - - }else{ - vorbis_synthesis_restart(&vf->vd); - } - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - ogg_stream_pagein(vf->os,&og); - - /* pull out all but last packet; the one with granulepos */ - while(1){ - result=ogg_stream_packetpeek(vf->os,&op); - if(result==0){ - /* !!! the packet finishing this page originated on a - preceeding page. Keep fetching previous pages until we - get one with a granulepos or without the 'continued' flag - set. Then just use raw_seek for simplicity. */ - - _seek_helper(vf,best); - - while(1){ - result=_get_prev_page(vf,&og); - if(result<0) goto seek_error; - if(ogg_page_granulepos(&og)>-1 || - !ogg_page_continued(&og)){ - return ov_raw_seek(vf,result); - } - vf->offset=result; - } - } - if(result<0){ - result = OV_EBADPACKET; - goto seek_error; - } - if(op.granulepos!=-1){ - vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; - if(vf->pcm_offset<0)vf->pcm_offset=0; - vf->pcm_offset+=total; - break; - }else - result=ogg_stream_packetout(vf->os,NULL); - } - } - } - - /* verify result */ - if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){ - result=OV_EFAULT; - goto seek_error; - } - vf->bittrack=0; - vf->samptrack=0; - - ogg_page_release(&og); - ogg_packet_release(&op); - return(0); - - seek_error: - - ogg_page_release(&og); - ogg_packet_release(&op); - - /* dump machine so we're in a known state */ - vf->pcm_offset=-1; - _decode_clear(vf); - return (int)result; -} - -/* seek to a sample offset relative to the decompressed pcm stream - returns zero on success, nonzero on failure */ - -int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ - ogg_packet op={0,0,0,0,0,0}; - ogg_page og={0,0,0,0}; - int thisblock,lastblock=0; - int ret=ov_pcm_seek_page(vf,pos); - if(ret<0)return(ret); - _make_decode_ready(vf); - - /* discard leading packets we don't need for the lapping of the - position we want; don't decode them */ - - while(1){ - - int ret=ogg_stream_packetpeek(vf->os,&op); - if(ret>0){ - thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); - if(thisblock<0){ - ogg_stream_packetout(vf->os,NULL); - continue; /* non audio packet */ - } - if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2; - - if(vf->pcm_offset+((thisblock+ - vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break; - - /* remove the packet from packet queue and track its granulepos */ - ogg_stream_packetout(vf->os,NULL); - vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with - only tracking, no - pcm_decode */ - vorbis_synthesis_blockin(&vf->vd,&vf->vb); - - /* end of logical stream case is hard, especially with exact - length positioning. */ - - if(op.granulepos>-1){ - int i; - /* always believe the stream markers */ - vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; - if(vf->pcm_offset<0)vf->pcm_offset=0; - for(i=0;icurrent_link;i++) - vf->pcm_offset+=vf->pcmlengths[i*2+1]; - } - - lastblock=thisblock; - - }else{ - if(ret<0 && ret!=OV_HOLE)break; - - /* suck in a new page */ - if(_get_next_page(vf,&og,-1)<0)break; - if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf); - - if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links){ - ogg_page_release(&og); - ogg_packet_release(&op); - return(OV_EBADLINK); - } - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - vf->ready_state=STREAMSET; - _make_decode_ready(vf); - lastblock=0; - } - - ogg_stream_pagein(vf->os,&og); - } - } - - vf->bittrack=0; - vf->samptrack=0; - /* discard samples until we reach the desired position. Crossing a - logical bitstream boundary with abandon is OK. */ - while(vf->pcm_offsetpcm_offset; - long samples=vorbis_synthesis_pcmout(&vf->vd,NULL); - - if(samples>target)samples=target; - vorbis_synthesis_read(&vf->vd,samples); - vf->pcm_offset+=samples; - - if(samplespcm_offset=ov_pcm_total(vf,-1); /* eof */ - } - - ogg_page_release(&og); - ogg_packet_release(&op); - return 0; -} - -/* seek to a playback time relative to the decompressed pcm stream - returns zero on success, nonzero on failure */ -int ov_time_seek(OggVorbis_File *vf,ogg_int64_t milliseconds){ - /* translate time to PCM position and call ov_pcm_seek */ - - int link=-1; - ogg_int64_t pcm_total=ov_pcm_total(vf,-1); - ogg_int64_t time_total=ov_time_total(vf,-1); - - if(vf->ready_stateseekable)return(OV_ENOSEEK); - if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL); - - /* which bitstream section does this time offset occur in? */ - for(link=vf->links-1;link>=0;link--){ - pcm_total-=vf->pcmlengths[link*2+1]; - time_total-=ov_time_total(vf,link); - if(milliseconds>=time_total)break; - } - - /* enough information to convert time offset to pcm offset */ - { - ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; - return(ov_pcm_seek(vf,target)); - } -} - -/* page-granularity version of ov_time_seek - returns zero on success, nonzero on failure */ -int ov_time_seek_page(OggVorbis_File *vf,ogg_int64_t milliseconds){ - /* translate time to PCM position and call ov_pcm_seek */ - - int link=-1; - ogg_int64_t pcm_total=ov_pcm_total(vf,-1); - ogg_int64_t time_total=ov_time_total(vf,-1); - - if(vf->ready_stateseekable)return(OV_ENOSEEK); - if(milliseconds<0 || milliseconds>time_total)return(OV_EINVAL); - - /* which bitstream section does this time offset occur in? */ - for(link=vf->links-1;link>=0;link--){ - pcm_total-=vf->pcmlengths[link*2+1]; - time_total-=ov_time_total(vf,link); - if(milliseconds>=time_total)break; - } - - /* enough information to convert time offset to pcm offset */ - { - ogg_int64_t target=pcm_total+(milliseconds-time_total)*vf->vi[link].rate/1000; - return(ov_pcm_seek_page(vf,target)); - } -} - -/* tell the current stream offset cursor. Note that seek followed by - tell will likely not give the set offset due to caching */ -ogg_int64_t ov_raw_tell(OggVorbis_File *vf){ - if(vf->ready_stateoffset); -} - -/* return PCM offset (sample) of next PCM sample to be read */ -ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){ - if(vf->ready_statepcm_offset); -} - -/* return time offset (milliseconds) of next PCM sample to be read */ -ogg_int64_t ov_time_tell(OggVorbis_File *vf){ - int link=0; - ogg_int64_t pcm_total=0; - ogg_int64_t time_total=0; - - if(vf->ready_stateseekable){ - pcm_total=ov_pcm_total(vf,-1); - time_total=ov_time_total(vf,-1); - - /* which bitstream section does this time offset occur in? */ - for(link=vf->links-1;link>=0;link--){ - pcm_total-=vf->pcmlengths[link*2+1]; - time_total-=ov_time_total(vf,link); - if(vf->pcm_offset>=pcm_total)break; - } - } - - return(time_total+(1000*vf->pcm_offset-pcm_total)/vf->vi[link].rate); -} - -/* link: -1) return the vorbis_info struct for the bitstream section - currently being decoded - 0-n) to request information for a specific bitstream section - - In the case of a non-seekable bitstream, any call returns the - current bitstream. NULL in the case that the machine is not - initialized */ - -vorbis_info *ov_info(OggVorbis_File *vf,int link){ - if(vf->seekable){ - if(link<0) - if(vf->ready_state>=STREAMSET) - return vf->vi+vf->current_link; - else - return vf->vi; - else - if(link>=vf->links) - return NULL; - else - return vf->vi+link; - }else{ - return vf->vi; - } -} - -/* grr, strong typing, grr, no templates/inheritence, grr */ -vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ - if(vf->seekable){ - if(link<0) - if(vf->ready_state>=STREAMSET) - return vf->vc+vf->current_link; - else - return vf->vc; - else - if(link>=vf->links) - return NULL; - else - return vf->vc+link; - }else{ - return vf->vc; - } -} - -/* up to this point, everything could more or less hide the multiple - logical bitstream nature of chaining from the toplevel application - if the toplevel application didn't particularly care. However, at - the point that we actually read audio back, the multiple-section - nature must surface: Multiple bitstream sections do not necessarily - have to have the same number of channels or sampling rate. - - ov_read returns the sequential logical bitstream number currently - being decoded along with the PCM data in order that the toplevel - application can take action on channel/sample rate changes. This - number will be incremented even for streamed (non-seekable) streams - (for seekable streams, it represents the actual logical bitstream - index within the physical bitstream. Note that the accessor - functions above are aware of this dichotomy). - - input values: buffer) a buffer to hold packed PCM data for return - length) the byte length requested to be placed into buffer - - return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL) - 0) EOF - n) number of bytes of PCM actually returned. The - below works on a packet-by-packet basis, so the - return length is not related to the 'length' passed - in, just guaranteed to fit. - - *section) set to the logical bitstream number */ - -long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ - int i,j; - - ogg_int32_t **pcm; - long samples; - - if(vf->ready_stateready_state==INITSET){ - samples=vorbis_synthesis_pcmout(&vf->vd,&pcm); - if(samples)break; - } - - /* suck in another packet */ - { - int ret=_fetch_and_process_packet(vf,1,1); - if(ret==OV_EOF) - return(0); - if(ret<=0) - return(ret); - } - - } - - if(samples>0){ - - /* yay! proceed to pack data into the byte buffer */ - - long channels=ov_info(vf,-1)->channels; - - if(samples>(bytes_req/(2*channels))) - samples=bytes_req/(2*channels); - - for(i=0;i>9); - dest+=channels; - } - } - - vorbis_synthesis_read(&vf->vd,samples); - vf->pcm_offset+=samples; - if(bitstream)*bitstream=vf->current_link; - return(samples*2*channels); - }else{ - return(samples); - } -} diff -r 07d83af9d2a8 -r d14adf1c7721 misc/libtremor/window.c --- a/misc/libtremor/window.c Fri Nov 11 15:28:58 2011 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/******************************************************************** - * * - * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * - * * - * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * - * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * - * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * - * * - * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * - * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * - * * - ******************************************************************** - - function: window functions - - ********************************************************************/ - -#include -#include -#include "misc.h" -#include "window.h" -#include "window_lookup.h" - -const void *_vorbis_window(int type, int left){ - - switch(type){ - case 0: - - 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; - case 4096: - return vwin8192; - default: - return(0); - } - break; - default: - return(0); - } -} - -void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], - long *blocksizes, - int lW,int W,int nW){ - - LOOKUP_T *window[2]={window_p[0],window_p[1]}; - long n=blocksizes[W]; - long ln=blocksizes[lW]; - long rn=blocksizes[nW]; - - long leftbegin=n/4-ln/4; - long leftend=leftbegin+ln/2; - - long rightbegin=n/2+n/4-rn/4; - long rightend=rightbegin+rn/2; - - int i,p; - - for(i=0;i +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA +################################################################################### + +find_program(ANT ant) + +if(NOT ANDROID_NDK) + find_path(ANDROID_NDK ndk-build) +endif() + +if(IS_DIRECTORY ${ANDROID_NDK}) + MESSAGE(STATUS "Detected the android NDK directory at: " ${ANDROID_NDK}) +else () + MESSAGE(FATAL_ERROR "Couldn't detect the Android NDK directory") +endif() + +if(NOT ANDROID_SDK)#Check if its defined at the cmdline + find_path(ANDROID_SDK adb ) #assume they've added platform-tools to their path + get_filename_component(ANDROID_SDK ${ANDROID_SDK} PATH) + set(ANDROID_SDK ${ANDROID_SDK} CACHE PATH "Path to the android sdk" FORCE) +endif() + +if( IS_DIRECTORY ${ANDROID_SDK}) + MESSAGE(STATUS "Detected the android SDK directory at: " ${ANDROID_SDK}) +else () + MESSAGE(FATAL_ERROR "Couldn't detect the Android SDK directory") +endif() + +if( NOT FPC_DIR) + find_path(FPC_DIR ppcrossarm) + get_filename_component(FPC_DIR ${FPC_DIR} PATH) + set(FPC_DIR ${FPC_DIR} CACHE PATH "Path to fpc dir used in the android port" FORCE) +endif() + +if( IS_DIRECTORY ${FPC_DIR}) + MESSAGE(STATUS "Detected the FreePascal directory at: " ${FPC_DIR}) +else () + MESSAGE(FATAL_ERROR "Couldn't detect the FreePascal directory") +endif() + +set(SDL_DIR /home/richard/Downloads/android-project) + + +set(ANDROID_SDK_API_LVL 8) +set(ANDROID_NDK_API_LVL 5) + +MESSAGE(STATUS "Creating android scripts and configuration files") + +configure_file(Templates/complete_build.sh .) +configure_file(Templates/default.properties SDL-android-project/) +configure_file(Templates/local.properties SDL-android-project/) +configure_file(Templates/Makefile.android .) +configure_file(Templates/pushToDevice.sh .) + +if(SDL_DIR_TEMP_DISABLE) + MESSAGE("Moving Android port of SDL to the proper directories") + set(DirsToCopy + SDL + SDL_image + SDL_mixer + SDL_ttf + jpeg + png + mikmod + ) + foreach(DIR ${DirsToCopy}) + exec_program( + ${CMAKE_COMMAND} + ARGS -E copy_directory + ${SDL_DIR}/jni/${DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/${DIR} + ) + MESSAGE(STATUS "Moved ${DIR}") + endforeach(DIR) + exec_program(${HGCOMMAND} + ARGS revert ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp + ) + exec_program(${HGCOMMAND} + ARGS revert ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp + ) + exec_program(${HGCOMMAND} + ARGS revert ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/SDL/src/video/android/SDL_androidtouch.c + ) + + exec_program(${HGCOMMAND} + ARGS revert ${CMAKE_CURRENT_SOURCE_DIR}/SDL-android-project/jni/SDL/src/video/android/SDL_androidtouch.h + ) +endif(SDL_DIR_TEMP_DISABLE) diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/AndroidManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/AndroidManifest.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/build.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/build.properties Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/build.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,10 @@ +#Set the current path must be set like this because call all-subdir-makefiles changes LOCAL_PATH +JNI_DIR := $(call my-dir) +LOCAL_PATH := $(JNI_DIR) + +include $(call all-subdir-makefiles) + +include $(CLEAR_VARS) +include $(JNI_DIR)/../../../../misc/Android.mk + + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,267 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2011 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#define org_hedgewars_hedgeroid org_hedgewars_hedgeroid + +#include "SDL_config.h" +#include "SDL_stdinc.h" + +#include "SDL_android.h" + +extern "C" { +#include "../../events/SDL_events_c.h" +#include "../../video/android/SDL_androidkeyboard.h" +#include "../../video/android/SDL_androidtouch.h" +#include "../../video/android/SDL_androidvideo.h" + +/* Impelemented in audio/android/SDL_androidaudio.c */ +extern void Android_RunAudioThread(); +} // C + +/******************************************************************************* + This file links the Java side of Android with libsdl +*******************************************************************************/ +#include +#include + + +/******************************************************************************* + Globals +*******************************************************************************/ +static JNIEnv* mEnv = NULL; +static JNIEnv* mAudioEnv = NULL; + +// Main activity +static jclass mActivityClass; + +// method signatures +static jmethodID midCreateGLContext; +static jmethodID midFlipBuffers; +static jmethodID midAudioInit; +static jmethodID midAudioWriteShortBuffer; +static jmethodID midAudioWriteByteBuffer; +static jmethodID midAudioQuit; + +// Accelerometer data storage +static float fLastAccelerometer[3]; + + +/******************************************************************************* + Functions called by JNI +*******************************************************************************/ + +// Library init +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + return JNI_VERSION_1_4; +} + +// Called before SDL_main() to initialize JNI bindings +extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls) +{ + __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()"); + + mEnv = env; + mActivityClass = cls; + + midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass, + "createGLContext","(II)Z"); + midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass, + "flipBuffers","()V"); + midAudioInit = mEnv->GetStaticMethodID(mActivityClass, + "audioInit", "(IZZI)Ljava/lang/Object;"); + midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass, + "audioWriteShortBuffer", "([S)V"); + midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass, + "audioWriteByteBuffer", "([B)V"); + midAudioQuit = mEnv->GetStaticMethodID(mActivityClass, + "audioQuit", "()V"); + + if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || + !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly"); + } +} + +// Resize +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeResize( + JNIEnv* env, jclass jcls, + jint width, jint height, jint format) +{ + Android_SetScreenResolution(width, height, format); +} + +// Keydown +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeKeyDown( + JNIEnv* env, jclass jcls, jint keycode) +{ + Android_OnKeyDown(keycode); +} + +// Keyup +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeKeyUp( + JNIEnv* env, jclass jcls, jint keycode) +{ + Android_OnKeyUp(keycode); +} + +// Touch +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeTouch( + JNIEnv* env, jclass jcls, + jint touch_device_id_in, jint pointer_finger_id_in, + jint action, jfloat x, jfloat y, jfloat p) +{ + Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p); +} + +// Accelerometer +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeAccel( + JNIEnv* env, jclass jcls, + jfloat x, jfloat y, jfloat z) +{ + fLastAccelerometer[0] = x; + fLastAccelerometer[1] = y; + fLastAccelerometer[2] = z; +} + +// Quit +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeQuit( + JNIEnv* env, jclass cls) +{ + // Inject a SDL_QUIT event + SDL_SendQuit(); +} + +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeRunAudioThread( + JNIEnv* env, jclass cls) +{ + /* This is the audio thread, with a different environment */ + mAudioEnv = env; + + Android_RunAudioThread(); +} + + +/******************************************************************************* + Functions called by SDL into Java +*******************************************************************************/ +extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion) +{ + if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) { + return SDL_TRUE; + } else { + return SDL_FALSE; + } +} + +extern "C" void Android_JNI_SwapWindow() +{ + mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); +} + +extern "C" void Android_JNI_SetActivityTitle(const char *title) +{ + jmethodID mid; + + mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V"); + if (mid) { + mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title)); + } +} + +extern "C" void Android_JNI_GetAccelerometerValues(float values[3]) +{ + int i; + for (i = 0; i < 3; ++i) { + values[i] = fLastAccelerometer[i]; + } +} + +// +// Audio support +// +static jboolean audioBuffer16Bit = JNI_FALSE; +static jboolean audioBufferStereo = JNI_FALSE; +static jobject audioBuffer = NULL; +static void* audioBufferPinned = NULL; + +extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames) +{ + int audioBufferFrames; + + __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device"); + audioBuffer16Bit = is16Bit; + audioBufferStereo = channelCount > 1; + + audioBuffer = mEnv->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames); + + if (audioBuffer == NULL) { + __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!"); + return 0; + } + audioBuffer = mEnv->NewGlobalRef(audioBuffer); + + jboolean isCopy = JNI_FALSE; + if (audioBuffer16Bit) { + audioBufferPinned = mEnv->GetShortArrayElements((jshortArray)audioBuffer, &isCopy); + audioBufferFrames = mEnv->GetArrayLength((jshortArray)audioBuffer); + } else { + audioBufferPinned = mEnv->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy); + audioBufferFrames = mEnv->GetArrayLength((jbyteArray)audioBuffer); + } + if (audioBufferStereo) { + audioBufferFrames /= 2; + } + + return audioBufferFrames; +} + +extern "C" void * Android_JNI_GetAudioBuffer() +{ + return audioBufferPinned; +} + +extern "C" void Android_JNI_WriteAudioBuffer() +{ + if (audioBuffer16Bit) { + mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT); + mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer); + } else { + mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT); + mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer); + } + + /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */ +} + +extern "C" void Android_JNI_CloseAudioDevice() +{ + mEnv->CallStaticVoidMethod(mActivityClass, midAudioQuit); + + if (audioBuffer) { + mEnv->DeleteGlobalRef(audioBuffer); + audioBuffer = NULL; + audioBufferPinned = NULL; + } +} + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,49 @@ + +/* Include the SDL main definition header */ +#include "SDL_main.h" + +/******************************************************************************* + Functions called by JNI +*******************************************************************************/ +#include + +// Called before SDL_main() to initialize JNI bindings in SDL library +extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls); + +// Library init +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + return JNI_VERSION_1_4; +} + +// Start up the SDL app +extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobjectArray strArray) +{ + /* This interface could expand with ABI negotiation, calbacks, etc. */ + SDL_Android_Init(env, cls); + + //Get the String array from java + int argc = env->GetArrayLength(strArray); + char *argv[argc]; + jstring jstringArgv[argc]; + for(int i = 0; i < argc; i++){ + jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i); //get the element + argv[i] = (char*)malloc(sizeof(char) * env->GetStringLength(jstringArgv[i])); + strcpy(argv[i], env->GetStringUTFChars(jstringArgv[i], JNI_FALSE)); //copy it to a mutable location + //Don't release memory the JAVA GC will take care of it + //env->ReleaseStringChars(jstringArgv[i], (jchar*)argv[i]); + } + + /* Run the application code! */ + int status; + status = SDL_main(argc, argv); + + //Clean up argv + for(int i = 0; i < argc; i++){ + } + + /* We exit here for consistency with other platforms. */ + //exit(status); Xeli: Or lets not crash the entire app..... +} + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/SDL_mixer/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/SDL_mixer/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,20 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := SDL_mixer + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../../../../../misc/libtremor \ + $(LOCAL_PATH)/.. \ + $(LOCAL_PATH)/../SDL/include \ + $(LOCAL_PATH)/../mikmod/include \ + +LOCAL_CFLAGS := -DWAV_MUSIC -DOGG_MUSIC -DOGG_USE_TREMOR -DMOD_MUSIC + +LOCAL_SRC_FILES := $(notdir $(filter-out %/playmus.c %/playwave.c %/fluidsynth.c, $(wildcard $(LOCAL_PATH)/*.c))) + +LOCAL_SHARED_LIBRARIES := SDL mikmod +LOCAL_STATIC_LIBRARIES := tremor + +include $(BUILD_SHARED_LIBRARY) diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/src/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/src/Android.mk Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,17 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := main + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../SDL/include + +# Add your application source files here... +LOCAL_SRC_FILES := ../SDL/src/main/android/SDL_android_main.cpp hedgewars_main.c + +LOCAL_SHARED_LIBRARIES := SDL + +LOCAL_LDLIBS := -llog -lGLESv1_CM + +include $(BUILD_SHARED_LIBRARY) + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,40 @@ + +#include "android/log.h" +#include "SDL.h" +#include "dlfcn.h" +#include "GLES/gl.h" + +#define TAG "HWEngine Loader" + +typedef (*HWEngine_Game)(char**); + +main(int argc, char *argv[]){ + void *handle; + char *error; + HWEngine_Game Game; + + + __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine being loaded"); + handle = dlopen("libhwengine.so", RTLD_NOW|RTLD_GLOBAL); + if(!handle){ + __android_log_print(ANDROID_LOG_INFO, TAG, dlerror()); + __android_log_print(ANDROID_LOG_INFO, TAG, "error dlopen"); + exit(EXIT_FAILURE); + } + dlerror(); + + __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine successfully loaded.."); + + + Game = (HWEngine_Game) dlsym(handle,"Game"); + if((error = dlerror()) != NULL){ + __android_log_print(ANDROID_LOG_INFO, TAG, error); + __android_log_print(ANDROID_LOG_INFO, TAG, "error dlsym"); + exit(EXIT_FAILURE); + } + __android_log_print(ANDROID_LOG_INFO, TAG, "dlsym succeeded"); + Game(argv); + __android_log_print(ANDROID_LOG_INFO, TAG, "Game() ended"); + + dlclose(handle); +} diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/background.png Binary file project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/background.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/icon.png Binary file project_files/Android-build/SDL-android-project/res/drawable-large-mdpi/icon.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/backbutton.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/backbutton.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/background.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/background.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot1.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot1.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot2.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot2.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot3.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot3.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot4.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot4.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot5.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/bot5.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/box.9.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/box.9.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/dice.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/dice.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/dropdown.9.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/dropdown.9.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/edit.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/edit.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/fort.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/fort.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/human.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/human.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/icon.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/icon.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/playsound.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/playsound.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/savebutton.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/savebutton.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/settings.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/settings.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/startgamebutton.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/startgamebutton.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/statusbar.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/statusbar.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount0.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount0.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount1.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount1.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount2.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount2.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount3.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount3.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount4.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount4.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount5.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount5.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount6.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount6.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount7.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount7.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount8.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount8.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount9.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teamcount9.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number0.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number0.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number1.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number1.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number2.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number2.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number3.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number3.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number4.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number4.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number5.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number5.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number6.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number6.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number7.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number7.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number8.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number8.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number9.png Binary file project_files/Android-build/SDL-android-project/res/drawable-mdpi/teams_number9.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/background.png Binary file project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/background.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/fort.png Binary file project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/fort.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/icon.png Binary file project_files/Android-build/SDL-android-project/res/drawable-normal-hdpi/icon.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-normal-ldpi/icon.png Binary file project_files/Android-build/SDL-android-project/res/drawable-normal-ldpi/icon.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/drawable-xlarge-mdpi/background.png Binary file project_files/Android-build/SDL-android-project/res/drawable-xlarge-mdpi/background.png has changed diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/layout/backbutton.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/res/layout/backbutton.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/layout/background.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/res/layout/background.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/layout/config.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/res/layout/config.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,12 @@ + + + + + + + diff -r 07d83af9d2a8 -r d14adf1c7721 project_files/Android-build/SDL-android-project/res/layout/download.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/Android-build/SDL-android-project/res/layout/download.xml Sat Nov 12 17:06:49 2011 +0100 @@ -0,0 +1,40 @@ + + + + +