Removed all warnings. FFT still needs work.

Added test application.

svn path=/trunk/csvorbis/; revision=4017
This commit is contained in:
Mark Crichton 2002-04-24 04:12:50 +00:00
Родитель 6530017e23
Коммит 7aed3ef62b
36 изменённых файлов: 6600 добавлений и 6074 удалений

Двоичные данные
OggDecoder/App.ico Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Просмотреть файл

@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

343
OggDecoder/OggDecoder.cs Normal file
Просмотреть файл

@ -0,0 +1,343 @@
using System;
using System.IO;
using csogg;
using csvorbis;
namespace OggDecoder
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Decoder
{
static int convsize=4096*2;
static byte[] convbuffer=new byte[convsize]; // take 8k out of the data segment, not the stack
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
TextWriter s_err = Console.Error;
FileStream input = null, output = null;
if(args.Length == 2)
{
try
{
input = new FileStream(args[0], FileMode.Open);
output = new FileStream(args[1], FileMode.OpenOrCreate);
}
catch(Exception e)
{
s_err.WriteLine(e);
}
}
else
{
return;
}
SyncState oy=new SyncState(); // sync and verify incoming physical bitstream
StreamState os=new StreamState(); // take physical pages, weld into a logical stream of packets
Page og=new Page(); // one Ogg bitstream page. Vorbis packets are inside
Packet op=new Packet(); // one raw packet of data for decode
Info vi=new Info(); // struct that stores all the static vorbis bitstream settings
Comment vc=new Comment(); // struct that stores all the bitstream user comments
DspState vd=new DspState(); // central working state for the packet->PCM decoder
Block vb=new Block(vd); // local working space for packet->PCM decode
byte[] buffer;
int bytes=0;
// Decode setup
oy.init(); // Now we can read pages
while(true)
{ // we repeat if the bitstream is chained
int eos=0;
// grab some data at the head of the stream. We want the first page
// (which is guaranteed to be small and only contain the Vorbis
// stream initial header) We need the first page to get the stream
// serialno.
// submit a 4k block to libvorbis' Ogg layer
int index=oy.buffer(4096);
buffer=oy.data;
try
{
s_err.WriteLine("Read a little bit...");
bytes = input.Read(buffer, index, 4096);
}
catch(Exception e)
{
s_err.WriteLine(e);
}
oy.wrote(bytes);
// Get the first page.
if(oy.pageout(og)!=1)
{
// have we simply run out of data? If so, we're done.
if(bytes<4096)break;
// error case. Must not be Vorbis data
s_err.WriteLine("Input does not appear to be an Ogg bitstream.");
}
// Get the serial number and set up the rest of decode.
// serialno first; use it to set up a logical stream
os.init(og.serialno());
// extract the initial header from the first page and verify that the
// Ogg bitstream is in fact Vorbis data
// I handle the initial header first instead of just having the code
// read all three Vorbis headers at once because reading the initial
// header is an easy way to identify a Vorbis bitstream and it's
// useful to see that functionality seperated out.
vi.init();
vc.init();
if(os.pagein(og)<0)
{
// error; stream version mismatch perhaps
s_err.WriteLine("Error reading first page of Ogg bitstream data.");
}
if(os.packetout(op)!=1)
{
// no page? must not be vorbis
s_err.WriteLine("Error reading initial header packet.");
}
if(vi.synthesis_headerin(vc,op)<0)
{
// error case; not a vorbis header
s_err.WriteLine("This Ogg bitstream does not contain Vorbis audio data.");
}
// At this point, we're sure we're Vorbis. We've set up the logical
// (Ogg) bitstream decoder. Get the comment and codebook headers and
// set up the Vorbis decoder
// The next two packets in order are the comment and codebook headers.
// They're likely large and may span multiple pages. Thus we reead
// and submit data until we get our two pacakets, watching that no
// pages are missing. If a page is missing, error out; losing a
// header page is the only place where missing data is fatal. */
int i=0;
s_err.WriteLine("Starting the fun...");
while(i<2)
{
while(i<2)
{
int result=oy.pageout(og);
if(result==0) break; // Need more data
// Don't complain about missing or corrupt data yet. We'll
// catch it at the packet output phase
if(result==1)
{
os.pagein(og); // we can ignore any errors here
// as they'll also become apparent
// at packetout
while(i<2)
{
result=os.packetout(op);
if(result==0)break;
if(result==-1)
{
// Uh oh; data at some point was corrupted or missing!
// We can't tolerate that in a header. Die.
s_err.WriteLine("Corrupt secondary header. Exiting.");
}
vi.synthesis_headerin(vc,op);
i++;
}
}
}
// no harm in not checking before adding more
index=oy.buffer(4096);
buffer=oy.data;
try
{
bytes=input.Read(buffer, index, 4096);
}
catch(Exception e)
{
s_err.WriteLine(e);
}
if(bytes==0 && i<2)
{
s_err.WriteLine("End of file before finding all Vorbis headers!");
}
oy.wrote(bytes);
}
// Throw the comments plus a few lines about the bitstream we're
// decoding
{
byte[][] ptr=vc.user_comments;
for(int j=0; j<ptr.Length;j++)
{
if(ptr[j]==null) break;
s_err.WriteLine(ptr[j].ToString());
}
s_err.WriteLine("\nBitstream is "+vi.channels+" channel, "+vi.rate+"Hz");
s_err.WriteLine("Encoded by: "+vc.vendor.ToString()+"\n");
}
convsize=4096/vi.channels;
// OK, got and parsed all three headers. Initialize the Vorbis
// packet->PCM decoder.
s_err.WriteLine("Entering Init Routines");
vd.synthesis_init(vi); // central decode state
s_err.WriteLine("synthesis_init DONE");
vb.init(vd); // local state for most of the decode
s_err.WriteLine("Init DONE!");
// so multiple block decodes can
// proceed in parallel. We could init
// multiple vorbis_block structures
// for vd here
float[][][] _pcm=new float[1][][];
int[] _index=new int[vi.channels];
// The rest is just a straight decode loop until end of stream
while(eos==0)
{
while(eos==0)
{
int result=oy.pageout(og);
if(result==0)break; // need more data
if(result==-1)
{ // missing or corrupt data at this page position
s_err.WriteLine("Corrupt or missing data in bitstream; continuing...");
}
else
{
os.pagein(og); // can safely ignore errors at
// this point
while(true)
{
result=os.packetout(op);
if(result==0)break; // need more data
if(result==-1)
{ // missing or corrupt data at this page position
// no reason to complain; already complained above
}
else
{
// we have a packet. Decode it
int samples;
if(vb.synthesis(op)==0)
{ // test for success!
s_err.WriteLine("Blockin' the synth");
vd.synthesis_blockin(vb);
s_err.WriteLine("Done.");
}
// **pcm is a multichannel float vector. In stereo, for
// example, pcm[0] is left, and pcm[1] is right. samples is
// the size of each channel. Convert the float values
// (-1.<=range<=1.) to whatever PCM format and write it out
while((samples=vd.synthesis_pcmout(_pcm, _index))>0)
{
float[][] pcm=_pcm[0];
bool clipflag=false;
int bout=(samples<convsize?samples:convsize);
// convert floats to 16 bit signed ints (host order) and
// interleave
for(i=0;i<vi.channels;i++)
{
int ptr=i*2;
//int ptr=i;
int mono=_index[i];
for(int j=0;j<bout;j++)
{
int val=(int)(pcm[i][mono+j]*32767.0);
// short val=(short)(pcm[i][mono+j]*32767.);
// int val=(int)Math.round(pcm[i][mono+j]*32767.);
// might as well guard against clipping
if(val>32767)
{
val=32767;
clipflag=true;
}
if(val<-32768)
{
val=-32768;
clipflag=true;
}
if(val<0) val=val|0x8000;
convbuffer[ptr]=(byte)(val);
convbuffer[ptr+1]=(byte)((uint)val>>8);
ptr+=2*(vi.channels);
}
}
if(clipflag)
s_err.WriteLine("Clipping in frame "+vd.sequence);
s_err.WriteLine("ScribbleScribble");
output.Write(convbuffer, 0, 2*vi.channels*bout);
vd.synthesis_read(bout); // tell libvorbis how
// many samples we
// actually consumed
}
}
}
if(og.eos()!=0)eos=1;
}
}
if(eos==0)
{
index=oy.buffer(4096);
buffer=oy.data;
try
{
bytes=input.Read(buffer,index,4096);
}
catch(Exception e)
{
s_err.WriteLine(e);
}
oy.wrote(bytes);
if(bytes==0)eos=1;
}
}
// clean up this logical bitstream; before exit we see if we're
// followed by another [chained]
os.clear();
// ogg_page and ogg_packet structs always point to storage in
// libvorbis. They're never freed or manipulated directly
vb.clear();
vd.clear();
vi.clear(); // must be called last
}
// OK, clean up the framer
oy.clear();
s_err.WriteLine("Done.");
}
}
}

Просмотреть файл

@ -0,0 +1,107 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.0.9466"
SchemaVersion = "1.0"
ProjectGuid = "{4CA9EB23-E111-4DAD-9932-F73E8E6C54C5}"
>
<Build>
<Settings
ApplicationIcon = "App.ico"
AssemblyKeyContainerName = ""
AssemblyName = "OggDecoder"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Exe"
RootNamespace = "OggDecoder"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "true"
Optimize = "false"
OutputPath = "bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
Optimize = "true"
OutputPath = "bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "..\..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "..\..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.XML"
HintPath = "..\..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
/>
<Reference
Name = "csogg"
Project = "{FA4ACE8B-CDEE-41A3-92D7-C73069B84B83}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "csvorbis"
Project = "{0087C0AF-E896-4C55-A999-5245560BCBE3}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "App.ico"
BuildAction = "Content"
/>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "OggDecoder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

Просмотреть файл

@ -0,0 +1,48 @@
<VisualStudioProject>
<CSHARP>
<Build>
<Settings ReferencePath = "" >
<Config
Name = "Debug"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "true"
/>
<Config
Name = "Release"
EnableASPDebugging = "false"
EnableASPXDebugging = "false"
EnableUnmanagedDebugging = "false"
EnableSQLServerDebugging = "false"
RemoteDebugEnabled = "false"
RemoteDebugMachine = ""
StartAction = "Project"
StartArguments = ""
StartPage = ""
StartProgram = ""
StartURL = ""
StartWorkingDirectory = ""
StartWithIE = "true"
/>
</Settings>
</Build>
<OtherProjectSettings
CopyProjectDestinationFolder = ""
CopyProjectUncPath = ""
CopyProjectOption = "0"
ProjectView = "ProjectFiles"
ProjectTrust = "0"
/>
</CSHARP>
</VisualStudioProject>

Просмотреть файл

@ -70,7 +70,7 @@ namespace csogg
storage = bytes;
}
public void write(uint value, int bits)
public void write(int vvalue, int bits)
{
if(endbyte + 4 >= storage)
{
@ -80,23 +80,23 @@ namespace csogg
storage += BUFFER_INCREMENT;
}
value &= mask[bits];
vvalue = (int)((uint)vvalue & mask[bits]);
bits += endbit;
buffer[ptr] |= (byte)(value << endbit);
buffer[ptr] |= (byte)(vvalue << endbit);
if(bits >= 8)
{
buffer[ptr+1] = (byte)(value >> (8-endbit));
buffer[ptr+1] = (byte)((uint)vvalue >> (8-endbit));
if(bits >= 16)
{
buffer[ptr+2] = (byte)(value >> (16-endbit));
buffer[ptr+2] = (byte)((uint)vvalue >> (16-endbit));
if (bits >= 24)
{
buffer[ptr+3] = (byte)(value >> (24-endbit));
buffer[ptr+3] = (byte)((uint)vvalue >> (24-endbit));
if(bits >= 32)
{
if(endbit > 0)
buffer[ptr+4] = (byte)(value >> (32-endbit));
buffer[ptr+4] = (byte)((uint)vvalue >> (32-endbit));
else
buffer[ptr+4]=0;
}
@ -265,6 +265,11 @@ namespace csogg
return(ret);
}
public byte[] buf()
{
return(buffer);
}
public csBuffer()
{
// Really a noop?

Просмотреть файл

@ -9,14 +9,14 @@
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "cogg"
AssemblyName = "csogg"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
RootNamespace = "cogg"
RootNamespace = "csogg"
StartupObject = ""
>
<Config

Просмотреть файл

@ -25,8 +25,11 @@
using System;
class AllocChain
namespace csvorbis
{
Object ptr;
AllocChain next;
};
class AllocChain
{
//Object ptr;
//AllocChain next;
};
}

Просмотреть файл

@ -26,100 +26,109 @@
using System;
using csogg;
public class Block{
namespace csvorbis
{
public class Block
{
///necessary stream state for linking to the framing abstraction
float[][] pcm=new float[0][]; // this is a pointer into local storage
Buffer opb=new Buffer();
internal float[][] pcm=new float[0][]; // this is a pointer into local storage
internal csBuffer opb=new csBuffer();
int lW;
int W;
int nW;
int pcmend;
int mode;
internal int lW;
internal int W;
internal int nW;
internal int pcmend;
internal int mode;
int eofflag;
long granulepos;
long sequence;
DspState vd; // For read-only access of configuration
internal int eofflag;
internal long granulepos;
internal long sequence;
internal DspState vd; // For read-only access of configuration
// local storage to avoid remallocing; it's up to the mapping to
// structure it
//byte[] localstore;
//int localtop;
//int localalloc;
//int totaluse;
//AllocChain reap;
//byte[] localstore;
//int localtop;
//int localalloc;
//int totaluse;
//AllocChain reap;
// bitmetrics for the frame
int glue_bits;
int time_bits;
int floor_bits;
int res_bits;
internal int glue_bits;
internal int time_bits;
internal int floor_bits;
internal int res_bits;
public Block(DspState vd){
public Block(DspState vd)
{
this.vd=vd;
// localalloc=0;
// localstore=null;
if(vd.analysisp!=0){
// localalloc=0;
// localstore=null;
if(vd.analysisp!=0)
{
opb.writeinit();
}
}
public void init(DspState vd){
public void init(DspState vd)
{
this.vd=vd;
}
// int alloc(int bytes){
// bytes=(bytes+(8-1))&(~(8-1));
// if(bytes+localtop>localalloc){
// if(localstore!=null){
// AllocChain link=new AllocChain();
// totaluse+=localtop;
// link.next=reap;
// link.ptr=localstore;
// reap=link;
// }
// // highly conservative
// localalloc=bytes;
// localstore=new byte[localalloc];
// localtop=0;
// }
// {
// int foo=localtop;
// //void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
// localtop+=bytes;
// return foo;
// }
// }
// int alloc(int bytes){
// bytes=(bytes+(8-1))&(~(8-1));
// if(bytes+localtop>localalloc){
// if(localstore!=null){
// AllocChain link=new AllocChain();
// totaluse+=localtop;
// link.next=reap;
// link.ptr=localstore;
// reap=link;
// }
// // highly conservative
// localalloc=bytes;
// localstore=new byte[localalloc];
// localtop=0;
// }
// {
// int foo=localtop;
// //void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
// localtop+=bytes;
// return foo;
// }
// }
// reap the chain, pull the ripcord
// void ripcord(){
// // reap the chain
// while(reap!=null){
// AllocChain next=reap.next;
// //free(reap->ptr);
// reap.ptr=null;
// //memset(reap,0,sizeof(struct alloc_chain));
// //free(reap);
// reap=next;
// }
// // consolidate storage
// if(totaluse!=0){
// //vb->localstore=realloc(vb->localstore,vb->totaluse+vb->localalloc);
// byte[] foo=new byte[totaluse+localalloc];
// System.arraycopy(localstore, 0, foo, 0, localstore.length);
// localstore=foo;
// localalloc+=totaluse;
// totaluse=0;
// }
// // pull the ripcord
// localtop=0;
// reap=null;
// }
// void ripcord(){
// // reap the chain
// while(reap!=null){
// AllocChain next=reap.next;
// //free(reap->ptr);
// reap.ptr=null;
// //memset(reap,0,sizeof(struct alloc_chain));
// //free(reap);
// reap=next;
// }
// // consolidate storage
// if(totaluse!=0){
// //vb->localstore=realloc(vb->localstore,vb->totaluse+vb->localalloc);
// byte[] foo=new byte[totaluse+localalloc];
// Array.Copy(localstore, 0, foo, 0, localstore.length);
// localstore=foo;
// localalloc+=totaluse;
// totaluse=0;
// }
// // pull the ripcord
// localtop=0;
// reap=null;
// }
public int clear(){
if(vd!=null){
if(vd.analysisp!=0){
public int clear()
{
if(vd!=null)
{
if(vd.analysisp!=0)
{
opb.writeclear();
}
}
@ -130,7 +139,8 @@ public class Block{
return(0);
}
public int synthesis(Packet op){
public int synthesis(Packet op)
{
Info vi=vd.vi;
// first things first. Make sure decode is ready
@ -138,7 +148,8 @@ public class Block{
opb.readinit(op.packet_base, op.packet, op.bytes);
// Check the packet type
if(opb.read(1)!=0){
if(opb.read(1)!=0)
{
// Oops. This is not an audio data packet
return(-1);
}
@ -149,12 +160,14 @@ public class Block{
mode=_mode;
W=vi.mode_param[mode].blockflag;
if(W!=0){
if(W!=0)
{
lW=opb.read(1);
nW=opb.read(1);
if(nW==-1) return(-1);
}
else{
else
{
lW=0;
nW=0;
}
@ -167,15 +180,19 @@ public class Block{
// alloc pcm passback storage
pcmend=vi.blocksizes[W];
//pcm=alloc(vi.channels);
if(pcm.length<vi.channels){
if(pcm.Length<vi.channels)
{
pcm=new float[vi.channels][];
}
for(int i=0;i<vi.channels;i++){
if(pcm[i]==null || pcm[i].length<pcmend){
for(int i=0;i<vi.channels;i++)
{
if(pcm[i]==null || pcm[i].Length<pcmend)
{
pcm[i]=new float[pcmend];
//pcm[i]=alloc(pcmend);
}
else{
else
{
for(int j=0;j<pcmend;j++){ pcm[i][j]=0; }
}
}
@ -184,4 +201,5 @@ public class Block{
int type=vi.map_type[vi.mode_param[mode].mapping];
return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode]));
}
}
}

Просмотреть файл

@ -27,18 +27,20 @@ using System;
using System.Runtime.CompilerServices;
using csogg;
class CodeBook
namespace csvorbis
{
int dim; // codebook dimensions (elements per vector)
int entries; // codebook entries
StaticCodeBook c=new StaticCodeBook();
class CodeBook
{
internal int dim; // codebook dimensions (elements per vector)
internal int entries; // codebook entries
internal StaticCodeBook c=new StaticCodeBook();
float[] valuelist; // list of dim*entries actual entry values
int[] codelist; // list of bitstream codewords for each entry
DecodeAux decode_tree;
internal float[] valuelist; // list of dim*entries actual entry values
internal int[] codelist; // list of bitstream codewords for each entry
internal DecodeAux decode_tree;
// returns the number of bits
int encode(int a, Buffer b)
internal int encode(int a, csBuffer b)
{
b.write(codelist[a], c.lengthlist[a]);
return(c.lengthlist[a]);
@ -59,18 +61,18 @@ class CodeBook
// floor0 LSP (single stage, non interleaved, nearest match)
// returns entry number and *modifies a* to the quantization value
int errorv(float[] a)
internal int errorv(float[] a)
{
int best=best(a,1);
int bestt=best(a,1);
for(int k=0;k<dim;k++)
{
a[k]=valuelist[best*dim+k];
a[k]=valuelist[bestt*dim+k];
}
return(best);
return(bestt);
}
// returns the number of bits and *modifies a* to the quantization value
int encodev(int best, float[] a, Buffer b)
internal int encodev(int best, float[] a, csBuffer b)
{
for(int k=0;k<dim;k++)
{
@ -81,22 +83,22 @@ class CodeBook
// res0 (multistage, interleave, lattice)
// returns the number of bits and *modifies a* to the remainder value
int encodevs(float[] a, Buffer b, int step,int addmul)
internal int encodevs(float[] a, csBuffer b, int step,int addmul)
{
int best=besterror(a,step,addmul);
return(encode(best,b));
}
private int[] t=new int[15]; // decodevs_add is synchronized for re-using t.
internal int[] t=new int[15]; // decodevs_add is synchronized for re-using t.
[MethodImpl(MethodImplOptions.Synchronized)]
int decodevs_add(float[]a, int offset, Buffer b, int n)
internal int decodevs_add(float[]a, int offset, csBuffer b, int n)
{
int step=n/dim;
int entry;
int i,j,o;
if(t.length<step)
if(t.Length<step)
{
t=new int[step];
}
@ -118,9 +120,9 @@ class CodeBook
return(0);
}
int decodev_add(float[]a, int offset, Buffer b,int n)
internal int decodev_add(float[]a, int offset, csBuffer b,int n)
{
int i,j,entry;
int i,j,k,entry;
int t;
if(dim>8)
@ -144,33 +146,16 @@ class CodeBook
if(entry==-1)return(-1);
t=entry*dim;
j=0;
switch(dim)
for(k=0; k < dim; k++)
{
case 8:
a[offset+(i++)]+=valuelist[t+(j++)];
case 7:
a[offset+(i++)]+=valuelist[t+(j++)];
case 6:
a[offset+(i++)]+=valuelist[t+(j++)];
case 5:
a[offset+(i++)]+=valuelist[t+(j++)];
case 4:
a[offset+(i++)]+=valuelist[t+(j++)];
case 3:
a[offset+(i++)]+=valuelist[t+(j++)];
case 2:
a[offset+(i++)]+=valuelist[t+(j++)];
case 1:
a[offset+(i++)]+=valuelist[t+(j++)];
case 0:
break;
}
}
}
return(0);
}
int decodev_set(float[] a,int offset, Buffer b, int n)
internal int decodev_set(float[] a,int offset, csBuffer b, int n)
{
int i,j,entry;
int t;
@ -188,9 +173,9 @@ class CodeBook
return(0);
}
int decodevv_add(float[][] a, int offset,int ch, Buffer b,int n)
internal int decodevv_add(float[][] a, int offset,int ch, csBuffer b,int n)
{
int i,j,k,entry;
int i,j,entry;
int chptr=0;
//System.out.println("decodevv_add: a="+a+",b="+b+",valuelist="+valuelist);
@ -229,7 +214,7 @@ class CodeBook
// stage==2 -> multiplicitive
// returns the entry number or -1 on eof
int decode(Buffer b)
internal int decode(csBuffer b)
{
int ptr=0;
DecodeAux t=decode_tree;
@ -265,7 +250,7 @@ class CodeBook
}
// returns the entry number or -1 on eof
int decodevs(float[] a, int index, Buffer b, int step,int addmul)
internal int decodevs(float[] a, int index, csBuffer b, int step,int addmul)
{
int entry=decode(b);
if(entry==-1)return(-1);
@ -284,12 +269,13 @@ class CodeBook
a[index+o]*=valuelist[entry*dim+i];
break;
default:
System.err.println("CodeBook.decodeves: addmul="+addmul);
//nothing
break;
}
return(entry);
}
int best(float[] a, int step)
internal int best(float[] a, int step)
{
EncodeAuxNearestMatch nt=c.nearest_tree;
EncodeAuxThreshMatch tt=c.thresh_tree;
@ -329,15 +315,15 @@ class CodeBook
// optimized using the decision tree
while(true)
{
float c=0.f;
double cc=0.0;
int p=nt.p[ptr];
int q=nt.q[ptr];
for(int k=0,o=0;k<dim;k++,o+=step)
{
c+=(valuelist[p+k]-valuelist[q+k])*
cc+=(valuelist[p+k]-valuelist[q+k])*
(a[o]-(valuelist[p+k]+valuelist[q+k])*.5);
}
if(c>0.0)
if(cc>0.0)
{ // in A
ptr= -nt.ptr0[ptr];
}
@ -353,7 +339,7 @@ class CodeBook
// brute force it!
{
int besti=-1;
float best=0.f;
float best=0.0f;
int e=0;
for(int i=0;i<entries;i++)
{
@ -373,19 +359,19 @@ class CodeBook
}
// returns the entry number and *modifies a* to the remainder value
int besterror(float[] a, int step, int addmul)
internal int besterror(float[] a, int step, int addmul)
{
int best=best(a,step);
int bestt=best(a,step);
switch(addmul)
{
case 0:
for(int i=0,o=0;i<dim;i++,o+=step)
a[o]-=valuelist[best*dim+i];
a[o]-=valuelist[bestt*dim+i];
break;
case 1:
for(int i=0,o=0;i<dim;i++,o+=step)
{
float val=valuelist[best*dim+i];
float val=valuelist[bestt*dim+i];
if(val==0)
{
a[o]=0;
@ -397,10 +383,10 @@ class CodeBook
}
break;
}
return(best);
return(bestt);
}
void clear()
internal void clear()
{
// static book is not cleared; we're likely called on the lookup and
// the static codebook belongs to the info struct
@ -415,7 +401,7 @@ class CodeBook
//memset(b,0,sizeof(codebook));
}
private static float dist(int el, float[] rref, int index, float[] b, int step)
internal static float dist(int el, float[] rref, int index, float[] b, int step)
{
float acc=(float)0.0;
for(int i=0; i<el; i++)
@ -438,7 +424,7 @@ class CodeBook
}
*/
int init_decode(StaticCodeBook s)
internal int init_decode(StaticCodeBook s)
{
//memset(c,0,sizeof(codebook));
c=s;
@ -462,7 +448,7 @@ class CodeBook
// 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)
static int[] make_words(int[] l, int n)
internal static int[] make_words(int[] l, int n)
{
int[] marker=new int[33];
int[] r=new int[n];
@ -532,7 +518,7 @@ class CodeBook
for(int j=0;j<l[i];j++)
{
temp<<=1;
temp|=((uint)r[i]>>j)&1;
temp = (int)((uint)temp | ((uint)r[i]>>j)&1);
}
r[i]=temp;
}
@ -541,7 +527,7 @@ class CodeBook
}
// build the decode helper tree from the codewords
DecodeAux make_decode_tree()
internal DecodeAux make_decode_tree()
{
int top=0;
DecodeAux t=new DecodeAux();
@ -560,7 +546,7 @@ class CodeBook
int j;
for(j=0;j<c.lengthlist[i]-1;j++)
{
int bit=((uint)codelist[i]>>j)&1;
int bit=(int)(((uint)codelist[i]>>j)&1);
if(bit==0)
{
if(ptr0[ptr]==0)
@ -614,215 +600,27 @@ class CodeBook
return(t);
}
private static int ilog(int v)
internal static int ilog(int v)
{
int ret=0;
while(v!=0)
{
ret++;
(uint)v>>=1;
v = (int)((uint)v >> 1);
}
return(ret);
}
/*
// TEST
// Simple enough; pack a few candidate codebooks, unpack them. Code a
// number of vectors through (keeping track of the quantized values),
// and decode using the unpacked book. quantized version of in should
// exactly equal out
//#include "vorbis/book/lsp20_0.vqh"
//#include "vorbis/book/lsp32_0.vqh"
//#include "vorbis/book/res0_1a.vqh"
static final int TESTSIZE=40;
static float[] test1={
0.105939,
0.215373,
0.429117,
0.587974,
0.181173,
0.296583,
0.515707,
0.715261,
0.162327,
0.263834,
0.342876,
0.406025,
0.103571,
0.223561,
0.368513,
0.540313,
0.136672,
0.395882,
0.587183,
0.652476,
0.114338,
0.417300,
0.525486,
0.698679,
0.147492,
0.324481,
0.643089,
0.757582,
0.139556,
0.215795,
0.324559,
0.399387,
0.120236,
0.267420,
0.446940,
0.608760,
0.115587,
0.287234,
0.571081,
0.708603,
};
static float[] test2={
0.088654,
0.165742,
0.279013,
0.395894,
0.110812,
0.218422,
0.283423,
0.371719,
0.136985,
0.186066,
0.309814,
0.381521,
0.123925,
0.211707,
0.314771,
0.433026,
0.088619,
0.192276,
0.277568,
0.343509,
0.068400,
0.132901,
0.223999,
0.302538,
0.202159,
0.306131,
0.360362,
0.416066,
0.072591,
0.178019,
0.304315,
0.376516,
0.094336,
0.188401,
0.325119,
0.390264,
0.091636,
0.223099,
0.282899,
0.375124,
};
static float[] test3={
0,1,-2,3,4,-5,6,7,8,9,
8,-2,7,-1,4,6,8,3,1,-9,
10,11,12,13,14,15,26,17,18,19,
30,-25,-30,-1,-5,-32,4,3,-2,0};
// static_codebook *testlist[]={&_vq_book_lsp20_0,
// &_vq_book_lsp32_0,
// &_vq_book_res0_1a,NULL};
static[][] float testvec={test1,test2,test3};
static void main(String[] arg){
Buffer write=new Buffer();
Buffer read=new Buffer();
int ptr=0;
write.writeinit();
System.err.println("Testing codebook abstraction...:");
while(testlist[ptr]!=null){
CodeBook c=new CodeBook();
StaticCodeBook s=new StaticCodeBook();;
float *qv=alloca(sizeof(float)*TESTSIZE);
float *iv=alloca(sizeof(float)*TESTSIZE);
memcpy(qv,testvec[ptr],sizeof(float)*TESTSIZE);
memset(iv,0,sizeof(float)*TESTSIZE);
System.err.print("\tpacking/coding "+ptr+"... ");
// pack the codebook, write the testvector
write.reset();
vorbis_book_init_encode(&c,testlist[ptr]); // get it into memory
// we can write
vorbis_staticbook_pack(testlist[ptr],&write);
System.err.print("Codebook size "+write.bytes()+" bytes... ");
for(int i=0;i<TESTSIZE;i+=c.dim){
vorbis_book_encodev(&c,qv+i,&write);
}
c.clear();
System.err.print("OK.\n");
System.err.print("\tunpacking/decoding "+ptr+"... ");
// transfer the write data to a read buffer and unpack/read
_oggpack_readinit(&read,_oggpack_buffer(&write),_oggpack_bytes(&write));
if(s.unpack(read)){
System.err.print("Error unpacking codebook.\n");
System.exit(1);
}
if(vorbis_book_init_decode(&c,&s)){
System.err.print("Error initializing codebook.\n");
System.exit(1);
}
for(int i=0;i<TESTSIZE;i+=c.dim){
if(vorbis_book_decodevs(&c,iv+i,&read,1,-1)==-1){
System.err.print("Error reading codebook test data (EOP).\n");
System.exit(1);
}
}
for(int i=0;i<TESTSIZE;i++){
if(fabs(qv[i]-iv[i])>.000001){
System.err.print("read ("+iv[i]+") != written ("+qv[i]+") at position ("+i+")\n");
System.exit(1);
}
}
System.err.print("OK\n");
ptr++;
class DecodeAux
{
internal int[] tab;
internal int[] tabl;
internal int tabn;
internal int[] ptr0;
internal int[] ptr1;
internal int aux; // number of tree entries
}
// The above is the trivial stuff;
// now try unquantizing a log scale codebook
}
*/
}
class DecodeAux
{
int[] tab;
int[] tabl;
int tabn;
int[] ptr0;
int[] ptr1;
int aux; // number of tree entries
}

Просмотреть файл

@ -24,15 +24,18 @@
*/
using System;
using System.Text;
using csogg;
// the comments are not part of vorbis_info so that vorbis_info can be
// static storage
public class Comment
namespace csvorbis
{
private static byte[] _vorbis="vorbis".getBytes();
// the comments are not part of vorbis_info so that vorbis_info can be
// static storage
public class Comment
{
private static String _vorbis="vorbis";
private static int OV_EFAULT=-129;
//private static int OV_EFAULT=-129;
private static int OV_EIMPL=-130;
// unlimited user comment fields. libvorbis writes 'libvorbis'
@ -51,7 +54,9 @@ public class Comment
public void add(String comment)
{
add(comment.getBytes());
ASCIIEncoding AE = new ASCIIEncoding();
byte[] comment_byt = AE.GetBytes(comment);
add(comment_byt);
}
private void add(byte[] comment)
@ -59,21 +64,21 @@ public class Comment
byte[][] foo=new byte[comments+2][];
if(user_comments!=null)
{
System.arraycopy(user_comments, 0, foo, 0, comments);
Array.Copy(user_comments, 0, foo, 0, comments);
}
user_comments=foo;
int[] goo=new int[comments+2];
if(comment_lengths!=null)
{
System.arraycopy(comment_lengths, 0, goo, 0, comments);
Array.Copy(comment_lengths, 0, goo, 0, comments);
}
comment_lengths=goo;
byte[] bar=new byte[comment.length+1];
System.arraycopy(comment, 0, bar, 0, comment.length);
byte[] bar=new byte[comment.Length+1];
Array.Copy(comment, 0, bar, 0, comment.Length);
user_comments[comments]=bar;
comment_lengths[comments]=comment.length;
comment_lengths[comments]=comment.Length;
comments++;
user_comments[comments]=null;
}
@ -97,7 +102,7 @@ public class Comment
// 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(byte[] s1, byte[] s2, int n)
static bool tagcompare(byte[] s1, byte[] s2, int n)
{
int c=0;
byte u1, u2;
@ -119,14 +124,19 @@ public class Comment
public String query(String tag, int count)
{
int foo=query(tag.getBytes(), count);
ASCIIEncoding AE = new ASCIIEncoding();
byte[] tag_byt = AE.GetBytes(tag);
int foo=query(tag_byt, count);
if(foo==-1)return null;
byte[] comment=user_comments[foo];
for(int i=0; i<comment_lengths[foo]; i++)
{
if(comment[i]=='=')
{
return new String(comment, i+1, comment_lengths[foo]-(i+1));
//TODO
//return new String(comment, i+1, comment_lengths[foo]-(i+1));
return "Meme";
}
}
return null;
@ -136,10 +146,10 @@ public class Comment
{
int i=0;
int found = 0;
int taglen = tag.length;
int taglen = tag.Length;
byte[] fulltag = new byte[taglen+2];
System.arraycopy(tag, 0, fulltag, 0, tag.length);
fulltag[tag.length]=(byte)'=';
Array.Copy(tag, 0, fulltag, 0, tag.Length);
fulltag[tag.Length]=(byte)'=';
for(i=0;i<comments;i++)
{
@ -157,7 +167,7 @@ public class Comment
return -1;
}
int unpack(Buffer opb)
internal int unpack(csBuffer opb)
{
int vendorlen=opb.read(32);
if(vendorlen<0)
@ -204,17 +214,21 @@ public class Comment
// return(-1);
}
int pack(Buffer opb)
int pack(csBuffer opb)
{
byte[] temp="Xiphophorus libVorbis I 20000508".getBytes();
String temp="Xiphophorus libVorbis I 20000508";
ASCIIEncoding AE = new ASCIIEncoding();
byte[] temp_byt = AE.GetBytes(temp);
byte[] _vorbis_byt = AE.GetBytes(_vorbis);
// preamble
opb.write(0x03,8);
opb.write(_vorbis);
opb.write(_vorbis_byt);
// vendor
opb.write(temp.length,32);
opb.write(temp);
opb.write(temp.Length,32);
opb.write(temp_byt);
// comments
@ -240,7 +254,7 @@ public class Comment
public int header_out(Packet op)
{
Buffer opb=new Buffer();
csBuffer opb=new csBuffer();
opb.writeinit();
if(pack(opb)!=0) return OV_EIMPL;
@ -248,7 +262,7 @@ public class Comment
op.packet_base = new byte[opb.bytes()];
op.packet=0;
op.bytes=opb.bytes();
System.arraycopy(opb.buffer(), 0, op.packet_base, 0, op.bytes);
Array.Copy(opb.buf(), 0, op.packet_base, 0, op.bytes);
op.b_o_s=0;
op.e_o_s=0;
op.granulepos=0;
@ -265,21 +279,29 @@ public class Comment
public String getVendor()
{
return new String(vendor, 0, vendor.length-1);
//TODO
//return new String(vendor.ToString(), 0, vendor.Length-1);
return "The Labs";
}
public String getComment(int i)
{
if(comments<=i)return null;
return new String(user_comments[i], 0, user_comments[i].length-1);
//TODO
//Encoding asc = Encoding.ASCII;
//return new String(user_comments[i], 0, user_comments[i].Length-1, asc);
return "There is no spoon.";
}
public String toString()
{
String foo="Vendor: "+new String(vendor, 0, vendor.length-1);
for(int i=0; i<comments; i++)
{
foo=foo+"\nComment: "+new String(user_comments[i], 0, user_comments[i].length-1);
//TODO
//String foo="Vendor: "+new String(vendor.ToString(), 0, vendor.Length-1);
//for(int i=0; i<comments; i++)
//{
// foo=foo+"\nComment: "+new String(user_comments[i].ToString(), 0, user_comments[i].Length-1);
//}
//foo=foo+"\n";
//return foo;
return "Blah\n";
}
foo=foo+"\n";
return foo;
}
}

Просмотреть файл

@ -25,20 +25,22 @@
using System;
class Drft
namespace csvorbis
{
class Drft
{
int n;
float[] trigcache;
int[] splitcache;
void backward(float[] data)
internal void backward(float[] data)
{
//System.err.println("Drft.backward");
if(n==1)return;
drftb1(n,data,trigcache,trigcache,n,splitcache);
}
void init(int n)
internal void init(int n)
{
//System.err.println("Drft.init");
this.n=n;
@ -47,7 +49,7 @@ class Drft
fdrffti(n, trigcache, splitcache);
}
void clear()
internal void clear()
{
//System.err.println("Drft.clear");
if(trigcache!=null)trigcache=null;
@ -84,6 +86,8 @@ class Drft
ntry=ntryh[j];
else
ntry+=2;
state = 104;
break;
case 104:
nq=nl/ntry;
nr=nl-ntry*nq;
@ -112,6 +116,9 @@ class Drft
ifac[ib+1]=ifac[ib];
}
ifac[2] = 2;
state = 107;
break;
case 107:
if(nl!=1)
{
@ -140,19 +147,19 @@ class Drft
ld+=l1;
i=iis;
argld=(float)ld*argh;
fi=0.f;
fi=0.0f;
for (ii=2;ii<ido;ii+=2)
{
fi+=1.f;
fi+=1.0f;
arg=fi*argld;
wa[index+i++]=(float)Math.cos(arg);
wa[index+i++]=(float)Math.sin(arg);
wa[index+i++]=(float)Math.Cos(arg);
wa[index+i++]=(float)Math.Sin(arg);
}
iis+=ido;
}
l1=l2;
}
break loop;
goto loop;
}
}
}
@ -340,8 +347,8 @@ class Drft
int idp2,ipp2;
arg=tpi/(float)ip;
dcp=(float)Math.cos(arg);
dsp=(float)Math.sin(arg);
dcp=(float)Math.Cos(arg);
dsp=(float)Math.Sin(arg);
ipph=(ip+1)>>1;
ipp2=ip;
idp2=ido;
@ -476,6 +483,9 @@ class Drft
}
}
}
state = 119;
break;
case 119:
for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
@ -496,8 +506,8 @@ class Drft
}
}
ar1=1.f;
ai1=0.f;
ar1=1.0f;
ai1=0.0f;
t1=0;
t2=ipp2*idl1;
t3=(ip-1)*idl1;
@ -585,6 +595,8 @@ class Drft
t2+=t10;
}
}
state = 132;
break;
case 135:
t1=0;
t2=ido<<1;
@ -678,7 +690,7 @@ class Drft
}
}
}
break loop;
goto loop;
}
}
}
@ -740,6 +752,8 @@ class Drft
break;
case 103:
dradf2(ido,l1,ch,c,wa, iw-1);
state = 104;
break;
case 104:
if(ido==1)na=1-na;
if(na!=0)
@ -754,9 +768,11 @@ class Drft
case 109:
dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa,iw-1);
na=0;
l2=l1;
break;
case 110:
l2=l1;
break loop;
goto loop;
}
}
}
@ -1002,11 +1018,11 @@ class Drft
t10=ip*ido;
t0=l1*ido;
arg=tpi/(float)ip;
dcp=(float)Math.cos(arg);
dsp=(float)Math.sin(arg);
nbd=(uint)(ido-1)>>1;
dcp=(float)Math.Cos(arg);
dsp=(float)Math.Sin(arg);
nbd=(int)((uint)(ido-1)>>1);
ipp2=ip;
ipph=(uint)(ip+1)>>1;
ipph=(int)((uint)(ip+1)>>1);
if(ido<l1)
{
state=103;
@ -1043,6 +1059,8 @@ class Drft
}
t1++;
}
state = 106;
break;
case 106:
t1=0;
t2=ipp2*t0;
@ -1147,9 +1165,11 @@ class Drft
}
}
}
state = 116;
break;
case 116:
ar1=1.f;
ai1=0.f;
ar1=1.0f;
ai1=0.0f;
t1=0;
t9=(t2=ipp2*idl1);
t3=(ip-1)*idl1;
@ -1286,6 +1306,9 @@ class Drft
}
}
}
state = 132;
break;
case 132:
if(ido==1)return;
@ -1353,7 +1376,8 @@ class Drft
t2+=ido;
}
}
break loop;
goto loop;
}
}
}
@ -1445,15 +1469,18 @@ class Drft
else
dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa,index+iw-1);
if(ido==1)na=1-na;
l1=l2;
iw+=(ip-1)*ido;
break;
case 115:
l1=l2;
iw+=(ip-1)*ido;
break loop;
goto loop;
}
}
}
if(na==0)return;
for(i=0;i<n;i++)c[i]=ch[i];
}
}
}

Просмотреть файл

@ -25,16 +25,19 @@
using System;
using csogg;
using csvorbis;
public class DspState
namespace csvorbis
{
public class DspState
{
static float M_PI=3.1415926539f;
static int VI_TRANSFORMB=1;
static int VI_WINDOWB=1;
int analysisp;
Info vi;
int modebits;
internal int analysisp;
internal Info vi;
internal int modebits;
float[][] pcm;
//float[][] pcmret;
@ -54,7 +57,7 @@ public class DspState
int centerW;
long granulepos;
long sequence;
public long sequence;
long glue_bits;
long time_bits;
@ -64,12 +67,12 @@ public class DspState
// local lookup storage
//!! Envelope ve=new Envelope(); // envelope
//float **window[2][2][2]; // block, leadin, leadout, type
float[][][][][] wnd; // block, leadin, leadout, type
internal float[][][][][] wnd; // block, leadin, leadout, type
//vorbis_look_transform **transform[2]; // block, type
Object[][] transform;
CodeBook[] fullbooks;
internal Object[][] transform;
internal CodeBook[] fullbooks;
// backend lookups are tied to the mode, not the backend or naked mapping
Object[] mode;
internal Object[] mode;
// local storage, only used on the encoding side. This way the
// application does not need to worry about freeing some packets'
@ -105,12 +108,12 @@ public class DspState
while(v>1)
{
ret++;
(uint)v >>= 1;
v = (int)((uint)v >> 1);
}
return(ret);
}
static float[] window(int type, int wnd, int left, int right)
internal static float[] window(int type, int wnd, int left, int right)
{
float[] ret=new float[wnd];
switch(type)
@ -124,25 +127,25 @@ public class DspState
for(int i=0;i<left;i++)
{
float x=(float)((i+.5)/left*M_PI/2.0);
x=(float)Math.sin(x);
x=(float)Math.Sin(x);
x*=x;
x*=M_PI/2.0;
x=(float)Math.sin(x);
x*=(float)(M_PI/2.0);
x=(float)Math.Sin(x);
ret[i+leftbegin]=x;
}
for(int i=leftbegin+left;i<rightbegin;i++)
{
ret[i]=1.f;
ret[i]=1.0f;
}
for(int i=0;i<right;i++)
{
float x=(float)((right-i-.5)/right*M_PI/2.0);
x=(float)Math.sin(x);
x=(float)Math.Sin(x);
x*=x;
x*=M_PI/2.0;
x=(float)Math.sin(x);
x*=(float)(M_PI/2.0);
x=(float)Math.Sin(x);
ret[i+rightbegin]=x;
}
}
@ -158,9 +161,9 @@ public class DspState
// here and not in analysis.c (which is for analysis transforms only).
// The init is here because some of it is shared
int init(Info vi, int encp)
int init(Info vi, bool encp)
{
//System.err.println("DspState.init: vi="+vi+", encp="+encp);
Console.Error.WriteLine("DspState.init: vi="+vi+", encp="+encp);
//memset(v,0,sizeof(vorbis_dsp_state));
this.vi=vi;
modebits=ilog2(vi.modes);
@ -187,15 +190,15 @@ public class DspState
for(int i=0;i<VI_WINDOWB;i++)
{
wnd[0][0][0][i]=
wnd(i,vi.blocksizes[0],vi.blocksizes[0]/2,vi.blocksizes[0]/2);
window(i,vi.blocksizes[0],vi.blocksizes[0]/2,vi.blocksizes[0]/2);
wnd[1][0][0][i]=
wnd(i,vi.blocksizes[1],vi.blocksizes[0]/2,vi.blocksizes[0]/2);
window(i,vi.blocksizes[1],vi.blocksizes[0]/2,vi.blocksizes[0]/2);
wnd[1][0][1][i]=
wnd(i,vi.blocksizes[1],vi.blocksizes[0]/2,vi.blocksizes[1]/2);
window(i,vi.blocksizes[1],vi.blocksizes[0]/2,vi.blocksizes[1]/2);
wnd[1][1][0][i]=
wnd(i,vi.blocksizes[1],vi.blocksizes[1]/2,vi.blocksizes[0]/2);
window(i,vi.blocksizes[1],vi.blocksizes[1]/2,vi.blocksizes[0]/2);
wnd[1][1][1][i]=
wnd(i,vi.blocksizes[1],vi.blocksizes[1]/2,vi.blocksizes[1]/2);
window(i,vi.blocksizes[1],vi.blocksizes[1]/2,vi.blocksizes[1]/2);
}
// if(encp){ // encode/decode differ here
@ -215,6 +218,7 @@ public class DspState
fullbooks[i]=new CodeBook();
fullbooks[i].init_decode(vi.book_param[i]);
}
Console.Error.WriteLine("fullbooks done");
// }
// initialize the storage vectors to a decent size greater than the
@ -244,12 +248,15 @@ public class DspState
// initialize all the mapping/backend lookups
mode=new Object[vi.modes];
Console.Error.WriteLine("vi.modes: "+vi.modes);
for(int i=0;i<vi.modes;i++)
{
int mapnum=vi.mode_param[i].mapping;
int maptype=vi.map_type[mapnum];
Console.Error.WriteLine("Entering mapping.");
mode[i]=FuncMapping.mapping_P[maptype].look(this,vi.mode_param[i],
vi.map_param[mapnum]);
Console.Error.WriteLine("Done Mapping");
}
return(0);
}
@ -298,7 +305,7 @@ public class DspState
{
for(int i=0;i<vi.channels;i++)
{
System.arraycopy(pcm[i], shiftPCM, pcm[i], 0, pcm_current);
Array.Copy(pcm[i], shiftPCM, pcm[i], 0, pcm_current);
}
}
}
@ -332,7 +339,7 @@ public class DspState
for(int i=0;i<vi.channels;i++)
{
float[] foo=new float[pcm_storage];
System.arraycopy(pcm[i], 0, foo, 0, pcm[i].length);
Array.Copy(pcm[i], 0, foo, 0, pcm[i].Length);
pcm[i]=foo;
}
}
@ -389,7 +396,7 @@ public class DspState
if(granulepos>vb.granulepos && vb.eofflag!=0)
{
// partial last frame. Strip the padding off
_centerW-=(granulepos-vb.granulepos);
_centerW = _centerW - (int)(granulepos-vb.granulepos);
}// else{ Shouldn't happen *unless* the bitstream is out of
// spec. Either way, believe the bitstream }
granulepos=vb.granulepos;
@ -434,62 +441,6 @@ public class DspState
public void clear()
{
/*
if(window[0][0][0]!=0){
for(i=0;i<VI_WINDOWB;i++)
if(v->window[0][0][0][i])free(v->window[0][0][0][i]);
free(v->window[0][0][0]);
for(j=0;j<2;j++)
for(k=0;k<2;k++){
for(i=0;i<VI_WINDOWB;i++)
if(v->window[1][j][k][i])free(v->window[1][j][k][i]);
free(v->window[1][j][k]);
}
}
if(v->pcm){
for(i=0;i<vi->channels;i++)
if(v->pcm[i])free(v->pcm[i]);
free(v->pcm);
if(v->pcmret)free(v->pcmret);
}
if(v->multipliers)free(v->multipliers);
_ve_envelope_clear(&v->ve);
if(v->transform[0]){
mdct_clear(v->transform[0][0]);
free(v->transform[0][0]);
free(v->transform[0]);
}
if(v->transform[1]){
mdct_clear(v->transform[1][0]);
free(v->transform[1][0]);
free(v->transform[1]);
}
// free mode lookups; these are actually vorbis_look_mapping structs
if(vi){
for(i=0;i<vi->modes;i++){
int mapnum=vi->mode_param[i]->mapping;
int maptype=vi->map_type[mapnum];
_mapping_P[maptype]->free_look(v->mode[i]);
}
// free codebooks
for(i=0;i<vi->books;i++)
vorbis_book_clear(v->fullbooks+i);
}
if(v->mode)free(v->mode);
if(v->fullbooks)free(v->fullbooks);
// free header, header1, header2
if(v->header)free(v->header);
if(v->header1)free(v->header1);
if(v->header2)free(v->header2);
memset(v,0,sizeof(vorbis_dsp_state));
}
*/
}
}

Просмотреть файл

@ -25,12 +25,16 @@
using System;
class EncodeAuxNearestMatch{
int[] ptr0;
int[] ptr1;
namespace csvorbis
{
class EncodeAuxNearestMatch
{
internal int[] ptr0;
internal int[] ptr1;
int[] p; // decision points (each is an entry)
int[] q; // decision points (each is an entry)
int aux; // number of tree entries
int alloc;
internal int[] p; // decision points (each is an entry)
internal int[] q; // decision points (each is an entry)
internal int aux; // number of tree entries
internal int alloc;
}
}

Просмотреть файл

@ -25,9 +25,13 @@
using System;
class EncodeAuxThreshMatch{
float[] quantthresh;
int[] quantmap;
int quantvals;
int threshvals;
namespace csvorbis
{
class EncodeAuxThreshMatch
{
internal float[] quantthresh;
internal int[] quantmap;
internal int quantvals;
internal int threshvals;
}
}

Просмотреть файл

@ -26,10 +26,12 @@
using System;
using csogg;
class Floor0 : FuncFloor
namespace csvorbis
{
class Floor0 : FuncFloor
{
void pack(Object i, Buffer opb)
override public void pack(Object i, csBuffer opb)
{
InfoFloor0 info=(InfoFloor0)i;
opb.write(info.order,8);
@ -42,7 +44,7 @@ class Floor0 : FuncFloor
opb.write(info.books[j],8);
}
Object unpack(Info vi , Buffer opb)
override public Object unpack(Info vi , csBuffer opb)
{
InfoFloor0 info=new InfoFloor0();
info.order=opb.read(8);
@ -75,8 +77,9 @@ class Floor0 : FuncFloor
// free_info(info);
// return(NULL);
}
Object look(DspState vd, InfoMode mi, Object i)
override public Object look(DspState vd, InfoMode mi, Object i)
{
Console.Error.WriteLine("Floor0::look");
float scale;
Info vi=vd.vi;
InfoFloor0 info=(InfoFloor0)i;
@ -101,7 +104,7 @@ class Floor0 : FuncFloor
look.linearmap=new int[look.n];
for(int j=0;j<look.n;j++)
{
int val=(int)Math.floor(toBARK((float)((info.rate/2.0)/look.n*j))
int val=(int)Math.Floor(toBARK((float)((info.rate/2.0)/look.n*j))
*scale); // bark numbers represent band edges
if(val>=look.ln)val=look.ln; // guard against the approximation
look.linearmap[j]=val;
@ -111,7 +114,7 @@ class Floor0 : FuncFloor
static float toBARK(float f)
{
return (float)(13.1*Math.atan(.00074*(f))+2.24*Math.atan((f)*(f)*1.85e-8)+1e-4*(f));
return (float)(13.1*Math.Atan(.00074*(f))+2.24*Math.Atan((f)*(f)*1.85e-8)+1e-4*(f));
}
Object state(Object i)
@ -148,17 +151,17 @@ class Floor0 : FuncFloor
lock(this)
{
if(lsp==null||lsp.length<look.m)
if(lsp==null||lsp.Length<look.m)
{
lsp=new float[look.m];
}
else
{
for(int j=0; j<look.m; j++)lsp[j]=0.f;
for(int j=0; j<look.m; j++)lsp[j]=0.0f;
}
CodeBook b=vb.vd.fullbooks[info.books[booknum]];
float last=0.f;
float last=0.0f;
//memset(out,0,sizeof(float)*look->m);
for(int j=0; j<look.m; j++)fout[j]=0.0f;
@ -198,7 +201,7 @@ class Floor0 : FuncFloor
return(0);
}
Object inverse1(Block vb, Object i, Object memo)
override public Object inverse1(Block vb, Object i, Object memo)
{
//System.err.println("Floor0.inverse "+i.getClass()+"]");
LookFloor0 look=(LookFloor0)i;
@ -219,15 +222,15 @@ class Floor0 : FuncFloor
if(booknum!=-1 && booknum<info.numbooks)
{
CodeBook b=vb.vd.fullbooks[info.books[booknum]];
float last=0.f;
float last=0.0f;
if(lsp==null||lsp.length<look.m+1)
if(lsp==null||lsp.Length<look.m+1)
{
lsp=new float[look.m+1];
}
else
{
for(int j=0; j<lsp.length; j++)lsp[j]=0.f;
for(int j=0; j<lsp.Length; j++)lsp[j]=0.0f;
}
for(int j=0;j<look.m;j+=b.dim)
@ -252,7 +255,7 @@ class Floor0 : FuncFloor
return(null);
}
int inverse2(Block vb, Object i, Object memo, float[] fout)
override public int inverse2(Block vb, Object i, Object memo, float[] fout)
{
//System.err.println("Floor0.inverse "+i.getClass()+"]");
LookFloor0 look=(LookFloor0)i;
@ -271,14 +274,14 @@ class Floor0 : FuncFloor
// memset(out,0,sizeof(float)*look->n);
for(int j=0; j<look.n; j++)
{
fout[j]=0.f;
fout[j]=0.0f;
}
return(0);
}
static float fromdB(float x)
{
return (float)(Math.exp((x)*.11512925));
return (float)(Math.Exp((x)*.11512925));
}
private static int ilog(int v)
{
@ -286,7 +289,7 @@ class Floor0 : FuncFloor
while(v!=0)
{
ret++;
(uint)v>>=1;
v = (int)((uint)v >> 1);
}
return(ret);
}
@ -307,25 +310,25 @@ class Floor0 : FuncFloor
// even/odd roots setup
for(i=0;i<m2;i++)
{
O[i]=(float)(-2.0*Math.cos(lsp[i*2]));
E[i]=(float)(-2.0*Math.cos(lsp[i*2+1]));
O[i]=(float)(-2.0*Math.Cos(lsp[i*2]));
E[i]=(float)(-2.0*Math.Cos(lsp[i*2+1]));
}
// set up impulse response
for(j=0;j<m2;j++)
{
Ae[j]=0.f;
Ao[j]=1.f;
Be[j]=0.f;
Bo[j]=1.f;
Ae[j]=0.0f;
Ao[j]=1.0f;
Be[j]=0.0f;
Bo[j]=1.0f;
}
Ao[j]=1.f;
Ae[j]=1.f;
Ao[j]=1.0f;
Ae[j]=1.0f;
// run impulse response
for(i=1;i<m+1;i++)
{
A=B=0.f;
A=B=0.0f;
for(j=0;j<m2;j++)
{
temp=O[j]*Ao[j]+Ae[j];
@ -348,7 +351,7 @@ class Floor0 : FuncFloor
LookFloor0 l, String name, int frameno)
{
// l->m+1 must be less than l->ln, but guard in case we get a bad stream
float[] lcurve=new float[Math.max(l.ln*2,l.m*2+2)];
float[] lcurve=new float[Math.Max(l.ln*2,l.m*2+2)];
if(amp==0)
{
@ -360,36 +363,37 @@ class Floor0 : FuncFloor
for(int i=0;i<l.n;i++)curve[i]=lcurve[l.linearmap[i]];
}
}
class InfoFloor0
{
int order;
int rate;
int barkmap;
int ampbits;
int ampdB;
int numbooks; // <= 16
int[] books=new int[16];
}
class LookFloor0
{
int n;
int ln;
int m;
int[] linearmap;
InfoFloor0 vi;
Lpc lpclook=new Lpc();
}
class EchstateFloor0
{
int[] codewords;
float[] curve;
long frameno;
long codes;
}
class InfoFloor0
{
internal int order;
internal int rate;
internal int barkmap;
internal int ampbits;
internal int ampdB;
internal int numbooks; // <= 16
internal int[] books=new int[16];
}
class LookFloor0
{
internal int n;
internal int ln;
internal int m;
internal int[] linearmap;
internal InfoFloor0 vi;
internal Lpc lpclook=new Lpc();
}
class EchstateFloor0
{
internal int[] codewords;
internal float[] curve;
internal long frameno;
//internal long codes;
}
}

Просмотреть файл

@ -26,12 +26,14 @@
using System;
using csogg;
class Floor1 : FuncFloor
namespace csvorbis
{
class Floor1 : FuncFloor
{
static int floor1_rangedb=140;
static int VIF_POSIT=63;
void pack(Object i, Buffer opb)
override public void pack(Object i, csBuffer opb)
{
InfoFloor1 info=(InfoFloor1)i;
@ -79,7 +81,7 @@ class Floor1 : FuncFloor
}
}
Object unpack(Info vi , Buffer opb)
override public Object unpack(Info vi , csBuffer opb)
{
int count=0,maxclass=-1,rangebits;
InfoFloor1 info=new InfoFloor1();
@ -153,7 +155,7 @@ class Floor1 : FuncFloor
// return(null);
}
Object look(DspState vd, InfoMode mi, Object i)
override public Object look(DspState vd, InfoMode mi, Object i)
{
int _n=0;
@ -235,6 +237,7 @@ class Floor1 : FuncFloor
break;
default:
look.quant_q=-1;
break;
}
/* discover our neighbors for decode where we don't use fit flags
@ -267,13 +270,13 @@ class Floor1 : FuncFloor
return look;
}
void free_info(Object i){}
void free_look(Object i){}
void free_state(Object vs){}
override public void free_info(Object i){}
override public void free_look(Object i){}
override public void free_state(Object vs){}
int forward(Block vb, Object i, float[] fin, float[] fout, Object vs){return 0;}
override public int forward(Block vb, Object i, float[] fin, float[] fout, Object vs){return 0;}
Object inverse1(Block vb, Object ii, Object memo)
override public Object inverse1(Block vb, Object ii, Object memo)
{
LookFloor1 look=(LookFloor1)ii;
InfoFloor1 info=look.vi;
@ -287,13 +290,13 @@ class Floor1 : FuncFloor
{
fit_value=(int[])memo;
}
if(fit_value==null || fit_value.length<look.posts)
if(fit_value==null || fit_value.Length<look.posts)
{
fit_value=new int[look.posts];
}
else
{
for(int i=0; i<fit_value.length; i++) fit_value[i]=0;
for(int i=0; i<fit_value.Length; i++) fit_value[i]=0;
}
fit_value[0]=vb.opb.read(ilog(look.quant_q-1));
@ -323,7 +326,7 @@ class Floor1 : FuncFloor
for(int k=0;k<cdim;k++)
{
int book=info.class_subbook[clss][cval&(csub-1)];
(uint)cval >>= csubbits;
cval = (int)((uint)cval >> csubbits);
if(book>=0)
{
if((fit_value[j+k]=books[book].decode(vb.opb))==-1)
@ -369,7 +372,7 @@ class Floor1 : FuncFloor
{
if((val&1)!=0)
{
val= -((uint)(val+1) >> 1);
val= (int)(-((uint)(val+1) >> 1));
}
else
{
@ -402,7 +405,7 @@ class Floor1 : FuncFloor
{
int dy=y1-y0;
int adx=x1-x0;
int ady=Math.abs(dy);
int ady=Math.Abs(dy);
int err=ady*(x-x0);
int off=(int)(err/adx);
@ -411,7 +414,7 @@ class Floor1 : FuncFloor
}
}
int inverse2(Block vb, Object i, Object memo, float[] fout)
override public int inverse2(Block vb, Object i, Object memo, float[] fout)
{
LookFloor1 look=(LookFloor1)i;
InfoFloor1 info=look.vi;
@ -447,7 +450,7 @@ class Floor1 : FuncFloor
}
for(int j=0; j<n; j++)
{
fout[j]=0.f;
fout[j]=0.0f;
}
return(0);
}
@ -517,21 +520,21 @@ class Floor1 : FuncFloor
0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
0.82788260F, 0.88168307F, 0.9389798F, 1.F
0.82788260F, 0.88168307F, 0.9389798F, 1.0F
};
private static void render_line(int x0, int x1,int y0,int y1,float[] d)
{
int dy=y1-y0;
int adx=x1-x0;
int ady=Math.abs(dy);
int ady=Math.Abs(dy);
int bbase=dy/adx;
int sy=( (dy < 0) ? bbase-1 : bbase+1);
int x=x0;
int y=y0;
int err=0;
ady-=Math.abs(base*adx);
ady-=Math.Abs(bbase*adx);
d[x]*=FLOOR_fromdB_LOOKUP[y];
while(++x<x1)
@ -544,7 +547,7 @@ class Floor1 : FuncFloor
}
else
{
y+=base;
y+=bbase;
}
d[x]*=FLOOR_fromdB_LOOKUP[y];
}
@ -556,7 +559,7 @@ class Floor1 : FuncFloor
while(v!=0)
{
ret++;
(uint)v>>=1;
v = (int)((uint)v >> 1);
}
return(ret);
}
@ -567,54 +570,54 @@ class Floor1 : FuncFloor
while(v>1)
{
ret++;
(uint)v>>=1;
v = (int)((uint)v >> 1);
}
return(ret);
}
}
}
class InfoFloor1
{
class InfoFloor1
{
const int VIF_POSIT=63;
const int VIF_CLASS=16;
const int VIF_PARTS=31;
int partitions; /* 0 to 31 */
int[] partitionclass=new int[VIF_PARTS]; /* 0 to 15 */
internal int partitions; /* 0 to 31 */
internal int[] partitionclass=new int[VIF_PARTS]; /* 0 to 15 */
int[] class_dim=new int[VIF_CLASS]; /* 1 to 8 */
int[] class_subs=new int[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
int[] class_book=new int[VIF_CLASS]; /* subs ^ dim entries */
int[][] class_subbook=new int[VIF_CLASS][]; /* [VIF_CLASS][subs] */
internal int[] class_dim=new int[VIF_CLASS]; /* 1 to 8 */
internal int[] class_subs=new int[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
internal int[] class_book=new int[VIF_CLASS]; /* subs ^ dim entries */
internal int[][] class_subbook=new int[VIF_CLASS][]; /* [VIF_CLASS][subs] */
int mult; /* 1 2 3 or 4 */
int[] postlist=new int[VIF_POSIT+2]; /* first two implicit */
internal int mult; /* 1 2 3 or 4 */
internal int[] postlist=new int[VIF_POSIT+2]; /* first two implicit */
/* encode side analysis parameters */
float maxover;
float maxunder;
float maxerr;
internal float maxover;
internal float maxunder;
internal float maxerr;
int twofitminsize;
int twofitminused;
int twofitweight;
float twofitatten;
int unusedminsize;
int unusedmin_n;
internal int twofitminsize;
internal int twofitminused;
internal int twofitweight;
internal float twofitatten;
internal int unusedminsize;
internal int unusedmin_n;
int n;
internal int n;
InfoFloor1()
internal InfoFloor1()
{
for(int i=0; i<class_subbook.length; i++)
for(int i=0; i<class_subbook.Length; i++)
{
class_subbook[i]=new int[8];
}
}
void free()
internal void free()
{
partitionclass=null;
class_dim=null;
@ -624,7 +627,7 @@ class InfoFloor1
postlist=null;
}
Object copy_info()
internal Object copy_info()
{
InfoFloor1 info=this;
InfoFloor1 ret=new InfoFloor1();
@ -660,26 +663,26 @@ class InfoFloor1
return(ret);
}
}
}
class LookFloor1
{
class LookFloor1
{
static int VIF_POSIT=63;
int[] sorted_index=new int[VIF_POSIT+2];
int[] forward_index=new int[VIF_POSIT+2];
int[] reverse_index=new int[VIF_POSIT+2];
int[] hineighbor=new int[VIF_POSIT];
int[] loneighbor=new int[VIF_POSIT];
int posts;
internal int[] sorted_index=new int[VIF_POSIT+2];
internal int[] forward_index=new int[VIF_POSIT+2];
internal int[] reverse_index=new int[VIF_POSIT+2];
internal int[] hineighbor=new int[VIF_POSIT];
internal int[] loneighbor=new int[VIF_POSIT];
internal int posts;
int n;
int quant_q;
InfoFloor1 vi;
internal int n;
internal int quant_q;
internal InfoFloor1 vi;
int phrasebits;
int postbits;
int frames;
//internal int phrasebits;
//internal int postbits;
//internal int frames;
void free()
{
@ -689,29 +692,30 @@ class LookFloor1
hineighbor=null;
loneighbor=null;
}
}
}
class Lsfit_acc
{
long x0;
long x1;
class Lsfit_acc
{
//long x0;
//long x1;
long xa;
long ya;
long x2a;
long y2a;
long xya;
long n;
long an;
long un;
long edgey0;
long edgey1;
}
//long xa;
//long ya;
//long x2a;
//long y2a;
//long xya;
//long n;
//long an;
//long un;
//long edgey0;
//long edgey1;
}
class EchstateFloor1
{
int[] codewords;
float[] curve;
long frameno;
long codes;
class EchstateFloor1
{
//int[] codewords;
//float[] curve;
//long frameno;
//long codes;
}
}

Просмотреть файл

@ -26,12 +26,14 @@
using System;
using csogg;
abstract class FuncFloor
namespace csvorbis
{
abstract class FuncFloor
{
public static FuncFloor[] floor_P={new Floor0(),new Floor1()};
public abstract void pack(Object i, Buffer opb);
public abstract Object unpack(Info vi, Buffer opb);
public abstract void pack(Object i, csBuffer opb);
public abstract Object unpack(Info vi, csBuffer opb);
public abstract Object look(DspState vd, InfoMode mi, Object i);
public abstract void free_info(Object i);
public abstract void free_look(Object i);
@ -39,4 +41,5 @@ abstract class FuncFloor
public abstract int forward(Block vb, Object i, float[] fin, float[] fout, Object vs);
public abstract Object inverse1(Block vb, Object i, Object memo);
public abstract int inverse2(Block vb, Object i, Object memo, float[] fout);
}
}

Просмотреть файл

@ -26,13 +26,17 @@
using System;
using csogg;
abstract class FuncMapping{
namespace csvorbis
{
abstract class FuncMapping
{
public static FuncMapping[] mapping_P={new Mapping0()};
public abstract void pack(Info info , Object imap, Buffer buffer);
public abstract Object unpack(Info info , Buffer buffer);
public abstract void pack(Info info , Object imap, csBuffer buffer);
public abstract Object unpack(Info info , csBuffer buffer);
public abstract Object look(DspState vd, InfoMode vm, Object m);
public abstract void free_info(Object imap);
public abstract void free_look(Object imap);
public abstract int inverse(Block vd, Object lm);
}
}

Просмотреть файл

@ -26,8 +26,10 @@
using System;
using csogg;
abstract class FuncResidue
namespace csvorbis
{
abstract class FuncResidue
{
public static FuncResidue[] residue_P={new Residue0(),
new Residue1(),
new Residue2()};
@ -39,4 +41,6 @@ abstract class FuncResidue
public abstract void free_look(Object i);
public abstract int forward(Block vb,Object vl, float[][] fin, int ch);
public abstract int inverse(Block vb, Object vl, float[][] fin, int[] nonzero,int ch);}
public abstract int inverse(Block vb, Object vl, float[][] fin, int[] nonzero,int ch);
}
}

Просмотреть файл

@ -26,7 +26,10 @@
using System;
using csogg;
abstract class FuncTime{
namespace csvorbis
{
abstract class FuncTime
{
public static FuncTime[] time_P={new Time0()};
public abstract void pack(Object i, csBuffer opb);
@ -36,4 +39,5 @@ abstract class FuncTime{
public abstract void free_look(Object i);
public abstract int forward(Block vb, Object i);
public abstract int inverse(Block vb, Object i, float[] fin, float[] fout);
}
}

Просмотреть файл

@ -23,12 +23,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
using System;
using System.Text;
using csogg;
public class Info{
namespace csvorbis
{
public class Info
{
private static int OV_EBADPACKET=-136;
private static int OV_ENOTAUDIO=-135;
private static byte[] _vorbis="vorbis".getBytes();
private static string _vorbis="vorbis";
private static int VI_TIMEB=1;
private static int VI_FLOORB=2;
private static int VI_RESB=3;
@ -53,77 +57,83 @@ public class Info{
// none set:
// the coder does not care to speculate.
int bitrate_upper;
int bitrate_nominal;
int bitrate_lower;
internal int bitrate_upper;
internal int bitrate_nominal;
internal int bitrate_lower;
// Vorbis supports only short and long blocks, but allows the
// encoder to choose the sizes
int[] blocksizes=new int[2];
internal int[] blocksizes=new int[2];
// modes are the primary means of supporting on-the-fly different
// blocksizes, different channel mappings (LR or mid-side),
// 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;
int psys; // encode only
internal int modes;
internal int maps;
internal int times;
internal int floors;
internal int residues;
internal int books;
internal int psys; // encode only
InfoMode[] mode_param=null;
internal InfoMode[] mode_param=null;
int[] map_type=null;
Object[] map_param=null;
internal int[] map_type=null;
internal Object[] map_param=null;
int[] time_type=null;
Object[] time_param=null;
internal int[] time_type=null;
internal Object[] time_param=null;
int[] floor_type=null;
Object[] floor_param=null;
internal int[] floor_type=null;
internal Object[] floor_param=null;
int[] residue_type=null;
Object[] residue_param=null;
internal int[] residue_type=null;
internal Object[] residue_param=null;
StaticCodeBook[] book_param=null;
internal StaticCodeBook[] book_param=null;
PsyInfo[] psy_param=new PsyInfo[64]; // encode only
internal PsyInfo[] psy_param=new PsyInfo[64]; // encode only
// for block long/sort tuning; encode only
int envelopesa;
float preecho_thresh;
float preecho_clamp;
//internal int envelopesa;
//internal float preecho_thresh;
//internal float preecho_clamp;
// used by synthesis, which has a full, alloced vi
public void init(){
public void init()
{
rate=0;
//memset(vi,0,sizeof(vorbis_info));
}
public void clear(){
public void clear()
{
for(int i=0;i<modes;i++){ mode_param[i]=null; }
mode_param=null;
for(int i=0;i<maps;i++){ // unpack does the range checking
for(int i=0;i<maps;i++)
{ // unpack does the range checking
FuncMapping.mapping_P[map_type[i]].free_info(map_param[i]);
}
map_param=null;
for(int i=0;i<times;i++){ // unpack does the range checking
for(int i=0;i<times;i++)
{ // unpack does the range checking
FuncTime.time_P[time_type[i]].free_info(time_param[i]);
}
time_param=null;
for(int i=0;i<floors;i++){ // unpack does the range checking
for(int i=0;i<floors;i++)
{ // unpack does the range checking
FuncFloor.floor_P[floor_type[i]].free_info(floor_param[i]);
}
floor_param=null;
for(int i=0;i<residues;i++){ // unpack does the range checking
for(int i=0;i<residues;i++)
{ // unpack does the range checking
FuncResidue.residue_P[residue_type[i]].free_info(residue_param[i]);
}
residue_param=null;
@ -132,9 +142,11 @@ public class Info{
// decode side does alloc a 'static' codebook. Calling clear on the
// full codebook does not clear the static codebook (that's our
// responsibility)
for(int i=0;i<books;i++){
for(int i=0;i<books;i++)
{
// just in case the decoder pre-cleared to save space
if(book_param[i]!=null){
if(book_param[i]!=null)
{
book_param[i].clear();
book_param[i]=null;
}
@ -142,7 +154,8 @@ public class Info{
//if(vi->book_param)free(vi->book_param);
book_param=null;
for(int i=0;i<psys;i++){
for(int i=0;i<psys;i++)
{
psy_param[i].free();
}
//if(vi->psy_param)free(vi->psy_param);
@ -150,7 +163,8 @@ public class Info{
}
// Header packing/unpacking
int unpack_info(csBuffer opb){
int unpack_info(csBuffer opb)
{
version=opb.read(32);
if(version!=0)return(-1);
@ -168,7 +182,8 @@ public class Info{
(channels<1)||
(blocksizes[0]<8)||
(blocksizes[1]<blocksizes[0]) ||
(opb.read(1)!=1)){
(opb.read(1)!=1))
{
//goto err_out; // EOP check
clear();
return(-1);
@ -181,16 +196,19 @@ public class Info{
// all of the real encoding details are here. The modes, books,
// everything
int unpack_books(csBuffer opb){
int unpack_books(csBuffer opb)
{
//d* codebooks
books=opb.read(8)+1;
if(book_param==null || book_param.length!=books)
if(book_param==null || book_param.Length!=books)
book_param=new StaticCodeBook[books];
for(int i=0;i<books;i++){
for(int i=0;i<books;i++)
{
book_param[i]=new StaticCodeBook();
if(book_param[i].unpack(opb)!=0){
if(book_param[i].unpack(opb)!=0)
{
//goto err_out;
clear();
return(-1);
@ -199,18 +217,21 @@ public class Info{
// time backend settings
times=opb.read(6)+1;
if(time_type==null || time_type.length!=times) time_type=new int[times];
if(time_param==null || time_param.length!=times)
if(time_type==null || time_type.Length!=times) time_type=new int[times];
if(time_param==null || time_param.Length!=times)
time_param=new Object[times];
for(int i=0;i<times;i++){
for(int i=0;i<times;i++)
{
time_type[i]=opb.read(16);
if(time_type[i]<0 || time_type[i]>=VI_TIMEB){
if(time_type[i]<0 || time_type[i]>=VI_TIMEB)
{
//goto err_out;
clear();
return(-1);
}
time_param[i]=FuncTime.time_P[time_type[i]].unpack(this, opb);
if(time_param[i]==null){
if(time_param[i]==null)
{
//goto err_out;
clear();
return(-1);
@ -219,21 +240,24 @@ public class Info{
// floor backend settings
floors=opb.read(6)+1;
if(floor_type==null || floor_type.length!=floors)
if(floor_type==null || floor_type.Length!=floors)
floor_type=new int[floors];
if(floor_param==null || floor_param.length!=floors)
if(floor_param==null || floor_param.Length!=floors)
floor_param=new Object[floors];
for(int i=0;i<floors;i++){
for(int i=0;i<floors;i++)
{
floor_type[i]=opb.read(16);
if(floor_type[i]<0 || floor_type[i]>=VI_FLOORB){
if(floor_type[i]<0 || floor_type[i]>=VI_FLOORB)
{
//goto err_out;
clear();
return(-1);
}
floor_param[i]=FuncFloor.floor_P[floor_type[i]].unpack(this,opb);
if(floor_param[i]==null){
if(floor_param[i]==null)
{
//goto err_out;
clear();
return(-1);
@ -243,22 +267,25 @@ public class Info{
// residue backend settings
residues=opb.read(6)+1;
if(residue_type==null || residue_type.length!=residues)
if(residue_type==null || residue_type.Length!=residues)
residue_type=new int[residues];
if(residue_param==null || residue_param.length!=residues)
if(residue_param==null || residue_param.Length!=residues)
residue_param=new Object[residues];
for(int i=0;i<residues;i++){
for(int i=0;i<residues;i++)
{
residue_type[i]=opb.read(16);
if(residue_type[i]<0 || residue_type[i]>=VI_RESB){
// goto err_out;
if(residue_type[i]<0 || residue_type[i]>=VI_RESB)
{
// goto err_out;
clear();
return(-1);
}
residue_param[i]=FuncResidue.residue_P[residue_type[i]].unpack(this,opb);
if(residue_param[i]==null){
// goto err_out;
if(residue_param[i]==null)
{
// goto err_out;
clear();
return(-1);
}
@ -266,18 +293,21 @@ public class Info{
// map backend settings
maps=opb.read(6)+1;
if(map_type==null || map_type.length!=maps) map_type=new int[maps];
if(map_param==null || map_param.length!=maps) map_param=new Object[maps];
for(int i=0;i<maps;i++){
if(map_type==null || map_type.Length!=maps) map_type=new int[maps];
if(map_param==null || map_param.Length!=maps) map_param=new Object[maps];
for(int i=0;i<maps;i++)
{
map_type[i]=opb.read(16);
if(map_type[i]<0 || map_type[i]>=VI_MAPB){
// goto err_out;
if(map_type[i]<0 || map_type[i]>=VI_MAPB)
{
// goto err_out;
clear();
return(-1);
}
map_param[i]=FuncMapping.mapping_P[map_type[i]].unpack(this,opb);
if(map_param[i]==null){
// goto err_out;
if(map_param[i]==null)
{
// goto err_out;
clear();
return(-1);
}
@ -285,9 +315,10 @@ public class Info{
// mode settings
modes=opb.read(6)+1;
if(mode_param==null || mode_param.length!=modes)
if(mode_param==null || mode_param.Length!=modes)
mode_param=new InfoMode[modes];
for(int i=0;i<modes;i++){
for(int i=0;i<modes;i++)
{
mode_param[i]=new InfoMode();
mode_param[i].blockflag=opb.read(1);
mode_param[i].windowtype=opb.read(16);
@ -296,23 +327,25 @@ public class Info{
if((mode_param[i].windowtype>=VI_WINDOWB)||
(mode_param[i].transformtype>=VI_WINDOWB)||
(mode_param[i].mapping>=maps)){
// goto err_out;
(mode_param[i].mapping>=maps))
{
// goto err_out;
clear();
return(-1);
}
}
if(opb.read(1)!=1){
if(opb.read(1)!=1)
{
//goto err_out; // top level EOP check
clear();
return(-1);
}
return(0);
// err_out:
// vorbis_info_clear(vi);
// return(-1);
// err_out:
// vorbis_info_clear(vi);
// return(-1);
}
// The Vorbis header is in three packets; the initial small packet in
@ -320,10 +353,12 @@ public class Info{
// with bitstream comments and a third packet that holds the
// codebook.
public int synthesis_headerin(Comment vc, Packet op){
Buffer opb=new Buffer();
public int synthesis_headerin(Comment vc, Packet op)
{
csBuffer opb=new csBuffer();
if(op!=null){
if(op!=null)
{
opb.readinit(op.packet_base, op.packet, op.bytes);
// Which of the three types of header is this?
@ -334,29 +369,35 @@ public class Info{
//memset(buffer,0,6);
opb.read(buffer,6);
if(buffer[0]!='v' || buffer[1]!='o' || buffer[2]!='r' ||
buffer[3]!='b' || buffer[4]!='i' || buffer[5]!='s'){
buffer[3]!='b' || buffer[4]!='i' || buffer[5]!='s')
{
// not a vorbis header
return(-1);
}
switch(packtype){
switch(packtype)
{
case 0x01: // least significant *bit* is read first
if(op.b_o_s==0){
if(op.b_o_s==0)
{
// Not the initial packet
return(-1);
}
if(rate!=0){
if(rate!=0)
{
// previously initialized info header
return(-1);
}
return(unpack_info(opb));
case 0x03: // least significant *bit* is read first
if(rate==0){
if(rate==0)
{
// um... we didn't get the initial header
return(-1);
}
return(vc.unpack(opb));
case 0x05: // least significant *bit* is read first
if(rate==0 || vc.vendor==null){
if(rate==0 || vc.vendor==null)
{
// um... we didn;t get the initial header or comments yet
return(-1);
}
@ -372,10 +413,14 @@ public class Info{
}
// pack side
int pack_info(csBuffer opb){
int pack_info(csBuffer opb)
{
ASCIIEncoding AE = new ASCIIEncoding();
byte[] _vorbis_byt = AE.GetBytes(_vorbis);
// preamble
opb.write(0x01,8);
opb.write(_vorbis);
opb.write(_vorbis_byt);
// basic information about the stream
opb.write(0x00,32);
@ -392,14 +437,20 @@ public class Info{
return(0);
}
int pack_books(csBuffer opb){
int pack_books(csBuffer opb)
{
ASCIIEncoding AE = new ASCIIEncoding();
byte[] _vorbis_byt = AE.GetBytes(_vorbis);
opb.write(0x05,8);
opb.write(_vorbis);
opb.write(_vorbis_byt);
// books
opb.write(books-1,8);
for(int i=0;i<books;i++){
if(book_param[i].pack(opb)!=0){
for(int i=0;i<books;i++)
{
if(book_param[i].pack(opb)!=0)
{
//goto err_out;
return(-1);
}
@ -407,35 +458,40 @@ public class Info{
// times
opb.write(times-1,6);
for(int i=0;i<times;i++){
for(int i=0;i<times;i++)
{
opb.write(time_type[i],16);
FuncTime.time_P[time_type[i]].pack(this.time_param[i],opb);
}
// floors
opb.write(floors-1,6);
for(int i=0;i<floors;i++){
for(int i=0;i<floors;i++)
{
opb.write(floor_type[i],16);
FuncFloor.floor_P[floor_type[i]].pack(floor_param[i],opb);
}
// residues
opb.write(residues-1,6);
for(int i=0;i<residues;i++){
for(int i=0;i<residues;i++)
{
opb.write(residue_type[i],16);
FuncResidue.residue_P[residue_type[i]].pack(residue_param[i],opb);
}
// maps
opb.write(maps-1,6);
for(int i=0;i<maps;i++){
for(int i=0;i<maps;i++)
{
opb.write(map_type[i],16);
FuncMapping.mapping_P[map_type[i]].pack(this,map_param[i],opb);
}
// modes
opb.write(modes-1,6);
for(int i=0;i<modes;i++){
for(int i=0;i<modes;i++)
{
opb.write(mode_param[i].blockflag,1);
opb.write(mode_param[i].windowtype,16);
opb.write(mode_param[i].transformtype,16);
@ -447,40 +503,43 @@ public class Info{
//return(-1);
}
// static void v_writestring(Buffer o, byte[] s){
// int i=0;
// while(s[i]!=0){
// o.write(s[i++],8);
// }
// }
// static void v_writestring(csBuffer o, byte[] s){
// int i=0;
// while(s[i]!=0){
// o.write(s[i++],8);
// }
// }
// static void v_readstring(Buffer o, byte[] buf, int bytes){
// int i=0
// while(bytes--!=0){
// buf[i++]=o.read(8);
// }
// }
// static void v_readstring(csBuffer o, byte[] buf, int bytes){
// int i=0
// while(bytes--!=0){
// buf[i++]=o.read(8);
// }
// }
// private Buffer opb_blocksize=new Buffer();
public int blocksize(Packet op){
// private csBuffer opb_blocksize=new csBuffer();
public int blocksize(Packet op)
{
//codec_setup_info *ci=vi->codec_setup;
Buffer opb=new Buffer();
// synchronized(opb_blocksize){
csBuffer opb=new csBuffer();
// synchronized(opb_blocksize){
int mode;
opb.readinit(op.packet_base, op.packet, op.bytes);
/* Check the packet type */
if(opb.read(1)!=0){
if(opb.read(1)!=0)
{
/* Oops. This is not an audio data packet */
return(OV_ENOTAUDIO);
}
{
int modebits=0;
int v=modes;
while(v>1){
while(v>1)
{
modebits++;
(uint)v>>=1;
v = (int)((uint)v >> 1);
}
/* read our mode and pre/post windowsize */
@ -488,24 +547,28 @@ public class Info{
}
if(mode==-1)return(OV_EBADPACKET);
return(blocksizes[mode_param[mode].blockflag]);
// }
// }
}
private static int ilog2(int v){
private static int ilog2(int v)
{
int ret=0;
while(v>1){
while(v>1)
{
ret++;
(uint)v >>=1 ;
v = (int)((uint)v >> 1);
}
return(ret);
}
public String toString(){
return "version:"+new Integer(version)+
", channels:"+new Integer(channels)+
", rate:"+new Integer(rate)+
", bitrate:"+new Integer(bitrate_upper)+","+
new Integer(bitrate_nominal)+","+
new Integer(bitrate_lower);
public String toString()
{
return "version:"+ version.ToString() +
", channels:"+ channels.ToString() +
", rate:"+ rate.ToString() +
", bitrate:"+ bitrate_upper.ToString() +","+
bitrate_nominal.ToString() +","+
bitrate_lower.ToString();
}
}
}

Просмотреть файл

@ -26,9 +26,13 @@
using System;
using csogg;
class InfoMode{
int blockflag;
int windowtype;
int transformtype;
int mapping;
namespace csvorbis
{
class InfoMode
{
internal int blockflag;
internal int windowtype;
internal int transformtype;
internal int mapping;
}
}

Просмотреть файл

@ -26,7 +26,10 @@
using System;
using csogg;
class Lookup{
namespace csvorbis
{
class Lookup
{
static int COS_LOOKUP_SZ=128;
static float[] COS_LOOKUP={
+1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
@ -64,7 +67,8 @@ class Lookup{
-1.0000000000000f,
};
/* interpolated lookup based cos function, domain 0 to PI only */
static float coslook(float a){
internal static float coslook(float a)
{
double d=a*(.31830989*(float)COS_LOOKUP_SZ);
int i=(int)d;
return COS_LOOKUP[i]+ ((float)(d-i))*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
@ -83,25 +87,26 @@ class Lookup{
1.000000000000f,
};
/* interpolated 1./sqrt(p) where .5 <= p < 1. */
static float invsqlook(float a){
// System.out.println(a);
double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
internal static float invsqlook(float a)
{
// System.out.println(a);
double d=a*(2.0f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
int i=(int)d;
return INVSQ_LOOKUP[i]+ ((float)(d-i))*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
}
static int INVSQ2EXP_LOOKUP_MIN=-32;
static int INVSQ2EXP_LOOKUP_MAX=32;
//static int INVSQ2EXP_LOOKUP_MAX=32;
static float[] INVSQ2EXP_LOOKUP={
65536.f, 46340.95001f, 32768.f, 23170.47501f,
16384.f, 11585.2375f, 8192.f, 5792.618751f,
4096.f, 2896.309376f, 2048.f, 1448.154688f,
1024.f, 724.0773439f, 512.f, 362.038672f,
256.f, 181.019336f, 128.f, 90.50966799f,
64.f, 45.254834f, 32.f, 22.627417f,
16.f, 11.3137085f, 8.f, 5.656854249f,
4.f, 2.828427125f, 2.f, 1.414213562f,
1.f, 0.7071067812f, 0.5f, 0.3535533906f,
65536.0f, 46340.95001f, 32768.0f, 23170.47501f,
16384.0f, 11585.2375f, 8192.0f, 5792.618751f,
4096.0f, 2896.309376f, 2048.0f, 1448.154688f,
1024.0f, 724.0773439f, 512.0f, 362.038672f,
256.0f, 181.019336f, 128.0f, 90.50966799f,
64.0f, 45.254834f, 32.0f, 22.627417f,
16.0f, 11.3137085f, 8.0f, 5.656854249f,
4.0f, 2.828427125f, 2.0f, 1.414213562f,
1.0f, 0.7071067812f, 0.5f, 0.3535533906f,
0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
@ -112,7 +117,8 @@ class Lookup{
1.525878906e-05f,
};
/* interpolated 1./sqrt(p) where .5 <= p < 1. */
static float invsq2explook(int a){
internal static float invsq2explook(int a)
{
return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
}
@ -143,13 +149,13 @@ class Lookup{
0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
};
/* interpolated lookup based fromdB function, domain -140dB to 0dB only */
static float fromdBlook(float a){
internal static float fromdBlook(float a)
{
int i=(int)(a*((float)(-(1<<FROMdB2_SHIFT))));
return (i<0)?1.f:
((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
return (i<0)?1.0f:
((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.0f:
FROMdB_LOOKUP[(uint)i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
}
}
}

Просмотреть файл

@ -26,7 +26,10 @@
using System;
using csogg;
class Lpc{
namespace csvorbis
{
class Lpc
{
Drft fft=new Drft();
int ln;
@ -38,7 +41,8 @@ class Lpc{
// Input : n elements of time doamin data
// Output: m lpc coefficients, excitation energy
static float lpc_from_data(float[] data, float[] lpc,int n,int m){
static float lpc_from_data(float[] data, float[] lpc,int n,int m)
{
float[] aut=new float[m+1];
float error;
int i,j;
@ -46,8 +50,9 @@ class Lpc{
// autocorrelation, p+1 lag coefficients
j=m+1;
while(j--!=0){
float d=0;
while(j--!=0)
{
float d=0.0F;
for(i=j;i<n;i++)d+=data[i]*data[i-j];
aut[j]=d;
}
@ -62,10 +67,12 @@ class Lpc{
}
*/
for(i=0;i<m;i++){
for(i=0;i<m;i++)
{
float r=-aut[i+1];
if(error==0){
if(error==0)
{
for(int k=0; k<m; k++) lpc[k]=0.0f;
return 0;
}
@ -81,14 +88,15 @@ class Lpc{
// Update LPC coefficients and total error
lpc[i]=r;
for(j=0;j<i/2;j++){
for(j=0;j<i/2;j++)
{
float tmp=lpc[j];
lpc[j]+=r*lpc[i-1-j];
lpc[i-1-j]+=r*tmp;
}
if(i%2!=0)lpc[j]+=lpc[j]*r;
error*=1.0-r*r;
error*=(float)(1.0-r*r);
}
// we need the error value to know how big an impulse to hit the
@ -100,7 +108,8 @@ class Lpc{
// Input : n element envelope spectral curve
// Output: m lpc coefficients, excitation energy
float lpc_from_curve(float[] curve, float[] lpc){
float lpc_from_curve(float[] curve, float[] lpc)
{
int n=ln;
float[] work=new float[n+n];
float fscale=(float)(.5/n);
@ -108,7 +117,8 @@ class Lpc{
// input is a real curve. make it complex-real
// This mixes phase, but the LPC generation doesn't care.
for(i=0;i<n;i++){
for(i=0;i<n;i++)
{
work[i*2]=curve[i]*fscale;
work[i*2+1]=0;
}
@ -120,7 +130,8 @@ class Lpc{
// The autocorrelation will not be circular. Shift, else we lose
// most of the power in the edges.
for(i=0,j=n/2;i<n/2;){
for(i=0,j=n/2;i<n/2;)
{
float temp=work[i];
work[i++]=work[j];
work[j++]=temp;
@ -129,22 +140,26 @@ class Lpc{
return(lpc_from_data(work,lpc,n,m));
}
void init(int mapped, int m){
internal void init(int mapped, int m)
{
//memset(l,0,sizeof(lpc_lookup));
Console.Error.WriteLine("lpc::init");
ln=mapped;
this.m=m;
// we cheat decoding the LPC spectrum via FFTs
Console.Error.WriteLine("Setting up FFT");
fft.init(mapped*2);
}
void clear(){
void clear()
{
fft.clear();
}
static float FAST_HYPOT(float a, float b){
return (float)Math.sqrt((a)*(a) + (b)*(b));
static float FAST_HYPOT(float a, float b)
{
return (float)Math.Sqrt((a)*(a) + (b)*(b));
}
// One can do this the long way by generating the transfer function in
@ -154,25 +169,27 @@ class Lpc{
// This version does a linear curve generation and then later
// interpolates the log curve from the linear curve.
void lpc_to_curve(float[] curve, float[] lpc, float amp){
internal void lpc_to_curve(float[] curve, float[] lpc, float amp)
{
//memset(curve,0,sizeof(float)*l->ln*2);
for(int i=0; i<ln*2; i++)curve[i]=0.0f;
if(amp==0)return;
for(int i=0;i<m;i++){
for(int i=0;i<m;i++)
{
curve[i*2+1]=lpc[i]/(4*amp);
curve[i*2+2]=-lpc[i]/(4*amp);
}
fft.backward(curve); // reappropriated ;-)
{
int l2=ln*2;
float unit=(float)(1.0/amp);
curve[0]=(float)(1.0/(curve[0]*2+unit));
for(int i=1;i<ln;i++){
for(int i=1;i<ln;i++)
{
float real=(curve[i]+curve[l2-i]);
float imag=(curve[i]-curve[l2-i]);
@ -181,74 +198,4 @@ class Lpc{
}
}
}
/*
// subtract or add an lpc filter to data. Vorbis doesn't actually use this.
static void lpc_residue(float[] coeff, float[] prime,int m,
float[] data, int n){
// in: coeff[0...m-1] LPC coefficients
// prime[0...m-1] initial values
// data[0...n-1] data samples
// out: data[0...n-1] residuals from LPC prediction
float[] work=new float[m+n];
float y;
if(prime==null){
for(int i=0;i<m;i++){
work[i]=0;
}
}
else{
for(int i=0;i<m;i++){
work[i]=prime[i];
}
}
for(int i=0;i<n;i++){
y=0;
for(int j=0;j<m;j++){
y-=work[i+j]*coeff[m-j-1];
}
work[i+m]=data[i];
data[i]-=y;
}
}
static void lpc_predict(float[] coeff, float[] prime,int m,
float[] data, int n){
// in: coeff[0...m-1] LPC coefficients
// prime[0...m-1] initial values (allocated size of n+m-1)
// data[0...n-1] residuals from LPC prediction
// out: data[0...n-1] data samples
int o,p;
float y;
float[] work=new float[m+n];
if(prime==null){
for(int i=0;i<m;i++){
work[i]=0.f;
}
}
else{
for(int i=0;i<m;i++){
work[i]=prime[i];
}
}
for(int i=0;i<n;i++){
y=data[i];
o=i;
p=m;
for(int j=0;j<m;j++){
y-=work[o++]*coeff[--p];
}
data[i]=work[o]=y;
}
}
*/
}

Просмотреть файл

@ -24,9 +24,12 @@
*/
using System;
using System.Runtime.InteropServices;
using csogg;
/*
namespace csvorbis
{
/*
function: LSP (also called LSF) conversion routines
The LSP generation code is taken (with minimal modification) from
@ -36,12 +39,18 @@ using csogg;
http://www2.xtdl.com/~rothwlr/lsfpaper/lsfpage.html
********************************************************************/
class Lsp
{
class Lsp
{
[StructLayout(LayoutKind.Explicit, Size=32, CharSet=CharSet.Ansi)]
class FloatHack
{
[FieldOffset(0)] public float fh_float;
[FieldOffset(0)] public int fh_int;
}
static float M_PI=(float)(3.1415926539);
static void lsp_to_curve(float[] curve,
internal static void lsp_to_curve(float[] curve,
int[] map, int n, int ln,
float[] lsp, int m,
float amp, float ampoffset)
@ -54,12 +63,13 @@ class Lsp
i=0;
while(i<n)
{
FloatHack fh = new FloatHack();
int k=map[i];
float p=.7071067812f;
float q=.7071067812f;
float w=Lookup.coslook(wdel*k);
int ftmp=0;
int c=(uint)m >> 1;
//int ftmp=0;
int c=(int)((uint)m >> 1);
for(int j=0;j<m2;j+=2)
{
@ -73,18 +83,19 @@ class Lsp
/* the last coefficient */
q*=lsp[m-1]-w;
q*=q;
p*=p*(1.f-w*w);
p*=p*(1.0f-w*w);
}
else
{
/* even order filter; still symmetric */
q*=q*(1.f+w);
p*=p*(1.f-w);
q*=q*(1.0f+w);
p*=p*(1.0f-w);
}
// q=frexp(p+q,&qexp);
q=p+q;
int hx=Float.floatToIntBits(q);
fh.fh_float = q;
int hx=fh.fh_int;
int ix=0x7fffffff&hx;
int qexp=0;
@ -96,14 +107,16 @@ class Lsp
{
if(ix<0x00800000)
{ // subnormal
q*=3.3554432000e+07; // 0x4c000000
hx=Float.floatToIntBits(q);
q*=3.3554432000e+07F; // 0x4c000000
fh.fh_float = q;
hx=fh.fh_int;
ix=0x7fffffff&hx;
qexp=-25;
}
qexp += (((uint)ix >> 23)-126);
hx=(hx&0x807fffff)|0x3f000000;
q=Float.intBitsToFloat(hx);
qexp += (int)(((uint)ix >> 23)-126);
hx=(int)((hx&0x807fffff)|0x3f000000);
fh.fh_int = hx;
q=fh.fh_float;
}
q=Lookup.fromdBlook(amp*
@ -116,6 +129,5 @@ class Lsp
}
}
}
}

Просмотреть файл

@ -26,41 +26,49 @@
using System;
using csogg;
class Mapping0 : FuncMapping
namespace csvorbis
{
static int seq=0;
void free_info(Object imap){}
void free_look(Object imap){}
Object look(DspState vd, InfoMode vm, Object m)
class Mapping0 : FuncMapping
{
//static int seq=0;
override public void free_info(Object imap){}
override public void free_look(Object imap){}
override public Object look(DspState vd, InfoMode vm, Object m)
{
Console.Error.WriteLine("Mapping0");
Info vi=vd.vi;
LookMapping0 look=new LookMapping0();
InfoMapping0 info=look.map=(InfoMapping0)m;
look.mode=vm;
LookMapping0 looks=new LookMapping0();
InfoMapping0 info=looks.map=(InfoMapping0)m;
looks.mode=vm;
look.time_look=new Object[info.submaps];
look.floor_look=new Object[info.submaps];
look.residue_look=new Object[info.submaps];
looks.time_look=new Object[info.submaps];
looks.floor_look=new Object[info.submaps];
looks.residue_look=new Object[info.submaps];
look.time_func=new FuncTime[info.submaps];
look.floor_func=new FuncFloor[info.submaps];
look.residue_func=new FuncResidue[info.submaps];
looks.time_func=new FuncTime[info.submaps];
looks.floor_func=new FuncFloor[info.submaps];
looks.residue_func=new FuncResidue[info.submaps];
Console.Error.WriteLine("info.submaps: "+info.submaps);
for(int i=0;i<info.submaps;i++)
{
int timenum=info.timesubmap[i];
int floornum=info.floorsubmap[i];
int resnum=info.residuesubmap[i];
look.time_func[i]=FuncTime.time_P[vi.time_type[timenum]];
look.time_look[i]=look.time_func[i].look(vd,vm,vi.time_param[timenum]);
look.floor_func[i]=FuncFloor.floor_P[vi.floor_type[floornum]];
look.floor_look[i]=look.floor_func[i].
looks.time_func[i]=FuncTime.time_P[vi.time_type[timenum]];
looks.time_look[i]=looks.time_func[i].look(vd,vm,vi.time_param[timenum]);
Console.Error.WriteLine("TIME");
looks.floor_func[i]=FuncFloor.floor_P[vi.floor_type[floornum]];
Console.Error.WriteLine("FLO: floornum:" + floornum);
looks.floor_look[i]=looks.floor_func[i].
look(vd,vm,vi.floor_param[floornum]);
look.residue_func[i]=FuncResidue.residue_P[vi.residue_type[resnum]];
look.residue_look[i]=look.residue_func[i].
Console.Error.WriteLine("FLOOR");
looks.residue_func[i]=FuncResidue.residue_P[vi.residue_type[resnum]];
looks.residue_look[i]=looks.residue_func[i].
look(vd,vm,vi.residue_param[resnum]);
Console.Error.WriteLine("RESIDUE");
}
@ -68,12 +76,12 @@ class Mapping0 : FuncMapping
{
}
look.ch=vi.channels;
looks.ch=vi.channels;
return(look);
return(looks);
}
void pack(Info vi, Object imap, csBuffer opb)
override public void pack(Info vi, Object imap, csBuffer opb)
{
InfoMapping0 info=(InfoMapping0)imap;
@ -125,9 +133,9 @@ class Mapping0 : FuncMapping
}
}
// also responsible for range checking
Object unpack(Info vi, csBuffer opb)
override public Object unpack(Info vi, csBuffer opb)
{
// also responsible for range checking
InfoMapping0 info=new InfoMapping0();
// !!!!
@ -219,7 +227,7 @@ class Mapping0 : FuncMapping
int[] nonzero=null;
Object[] floormemo=null;
int inverse(Block vb, Object l)
override public int inverse(Block vb, Object l)
{
lock(this)
{
@ -231,10 +239,10 @@ class Mapping0 : FuncMapping
InfoMode mode=look.mode;
int n=vb.pcmend=vi.blocksizes[vb.W];
float[] window=vd.window[vb.W][vb.lW][vb.nW][mode.windowtype];
float[] window=vd.wnd[vb.W][vb.lW][vb.nW][mode.windowtype];
// float[][] pcmbundle=new float[vi.channels][];
// int[] nonzero=new int[vi.channels];
if(pcmbundle==null || pcmbundle.length<vi.channels)
if(pcmbundle==null || pcmbundle.Length<vi.channels)
{
pcmbundle=new float[vi.channels][];
nonzero=new int[vi.channels];
@ -379,7 +387,7 @@ class Mapping0 : FuncMapping
{
for(int j=0;j<n;j++)
{
pcm[j]=0.f;
pcm[j]=0.0f;
}
}
//_analysis_output("final",seq++,pcm,n,0,0);
@ -399,27 +407,27 @@ class Mapping0 : FuncMapping
while(v>1)
{
ret++;
(uint)v >>= 1;
v = (int)((uint)v >> 1);
}
return(ret);
}
}
}
class InfoMapping0
{
int submaps; // <= 16
int[] chmuxlist=new int[256]; // up to 256 channels in a Vorbis stream
class InfoMapping0
{
internal int submaps; // <= 16
internal int[] chmuxlist=new int[256]; // up to 256 channels in a Vorbis stream
int[] timesubmap=new int[16]; // [mux]
int[] floorsubmap=new int[16]; // [mux] submap to floors
int[] residuesubmap=new int[16];// [mux] submap to residue
int[] psysubmap=new int[16]; // [mux]; encode only
internal int[] timesubmap=new int[16]; // [mux]
internal int[] floorsubmap=new int[16]; // [mux] submap to floors
internal int[] residuesubmap=new int[16];// [mux] submap to residue
internal int[] psysubmap=new int[16]; // [mux]; encode only
int coupling_steps;
int[] coupling_mag=new int[256];
int[] coupling_ang=new int[256];
internal int coupling_steps;
internal int[] coupling_mag=new int[256];
internal int[] coupling_ang=new int[256];
void free()
internal void free()
{
chmuxlist=null;
timesubmap=null;
@ -430,24 +438,25 @@ class InfoMapping0
coupling_mag=null;
coupling_ang=null;
}
}
}
class LookMapping0
{
InfoMode mode;
InfoMapping0 map;
Object[] time_look;
Object[] floor_look;
Object[] floor_state;
Object[] residue_look;
PsyLook[] psy_look;
class LookMapping0
{
internal InfoMode mode;
internal InfoMapping0 map;
internal Object[] time_look;
internal Object[] floor_look;
//Object[] floor_state;
internal Object[] residue_look;
//PsyLook[] psy_look;
FuncTime[] time_func;
FuncFloor[] floor_func;
FuncResidue[] residue_func;
internal FuncTime[] time_func;
internal FuncFloor[] floor_func;
internal FuncResidue[] residue_func;
int ch;
float[][] decay;
int lastframe; // if a different mode is called, we need to
internal int ch;
//float[][] decay;
//int lastframe; // if a different mode is called, we need to
// invalidate decay and floor state
}
}

Просмотреть файл

@ -26,12 +26,14 @@
using System;
using csogg;
class Mdct
namespace csvorbis
{
class Mdct
{
static private float cPI3_8=0.38268343236508977175f;
static private float cPI2_8=0.70710678118654752441f;
static private float cPI1_8=0.92387953251128675613f;
//static private float cPI3_8=0.38268343236508977175f;
//static private float cPI2_8=0.70710678118654752441f;
//static private float cPI1_8=0.92387953251128675613f;
int n;
int log2n;
@ -41,13 +43,13 @@ class Mdct
float scale;
void init(int n)
internal void init(int n)
{
bitrev=new int[n/4];
trig=new float[n+n/4];
int n2=(uint)n >> 1;
log2n=(int)Math.rint(Math.log(n)/Math.log(2));
int n2=(int)((uint)n >> 1);
log2n=(int)Math.Round(Math.Log(n)/Math.Log(2));
this.n=n;
@ -60,15 +62,15 @@ class Mdct
// trig lookups...
for(int i=0;i<n/4;i++)
{
trig[AE+i*2]=(float)Math.cos((Math.PI/n)*(4*i));
trig[AO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i));
trig[BE+i*2]=(float)Math.cos((Math.PI/(2*n))*(2*i+1));
trig[BO+i*2]=(float)Math.sin((Math.PI/(2*n))*(2*i+1));
trig[AE+i*2]=(float)Math.Cos((Math.PI/n)*(4*i));
trig[AO+i*2]=(float)-Math.Sin((Math.PI/n)*(4*i));
trig[BE+i*2]=(float)Math.Cos((Math.PI/(2*n))*(2*i+1));
trig[BO+i*2]=(float)Math.Sin((Math.PI/(2*n))*(2*i+1));
}
for(int i=0;i<n/8;i++)
{
trig[CE+i*2]=(float)Math.cos((Math.PI/n)*(4*i+2));
trig[CO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i+2));
trig[CE+i*2]=(float)Math.Cos((Math.PI/n)*(4*i+2));
trig[CO+i*2]=(float)-Math.Sin((Math.PI/n)*(4*i+2));
}
{
@ -85,31 +87,31 @@ class Mdct
bitrev[i*2+1]=acc;
}
}
scale=4.f/n;
scale=4.0f/n;
}
void clear()
internal void clear()
{
}
void forward(float[] fin, float[] fout)
internal void forward(float[] fin, float[] fout)
{
}
float[] _x=new float[1024];
float[] _w=new float[1024];
void backward(float[] fin, float[] fout)
internal void backward(float[] fin, float[] fout)
{
lock(this)
{
if(_x.length < n/2){_x=new float[n/2];}
if(_w.length < n/2){_w=new float[n/2];}
if(_x.Length < n/2){_x=new float[n/2];}
if(_w.Length < n/2){_w=new float[n/2];}
float[] x=_x;
float[] w=_w;
int n2=(uint)n >> 1;
int n4=(uint)n >> 2;
int n8=(uint)n >> 3;
int n2=(int)((uint)n >> 1);
int n4=(int)((uint)n >> 2);
int n8=(int)((uint)n >> 3);
// rotate + step 1
{
@ -167,7 +169,7 @@ class Mdct
}
}
}
private float[] mdct_kernel(float[] x, float[] w,
internal float[] mdct_kernel(float[] x, float[] w,
int n, int n2, int n4, int n8)
{
// step 2
@ -198,7 +200,7 @@ class Mdct
{
for(int i=0;i<log2n-3;i++)
{
int k0=(uint)n >> (i+2);
int k0=(int)((uint)n >> (i+2));
int k1=1 << (i+3);
int wbase=n2-2;
@ -268,4 +270,5 @@ class Mdct
}
return(x);
}
}
}

Просмотреть файл

@ -26,19 +26,21 @@
using System;
using csogg;
// psychoacoustic setup
class PsyInfo
namespace csvorbis
{
int athp;
int decayp;
int smoothp;
int noisefitp;
int noisefit_subblock;
float noisefit_threshdB;
// psychoacoustic setup
class PsyInfo
{
//int athp;
//int decayp;
//int smoothp;
//int noisefitp;
//int noisefit_subblock;
//float noisefit_threshdB;
float ath_att;
//float ath_att;
int tonemaskp;
//int tonemaskp;
float[] toneatt_125Hz=new float[5];
float[] toneatt_250Hz=new float[5];
float[] toneatt_500Hz=new float[5];
@ -47,7 +49,7 @@ class PsyInfo
float[] toneatt_4000Hz=new float[5];
float[] toneatt_8000Hz=new float[5];
int peakattp;
//int peakattp;
float[] peakatt_125Hz=new float[5];
float[] peakatt_250Hz=new float[5];
float[] peakatt_500Hz=new float[5];
@ -56,7 +58,7 @@ class PsyInfo
float[] peakatt_4000Hz=new float[5];
float[] peakatt_8000Hz=new float[5];
int noisemaskp;
//int noisemaskp;
float[] noiseatt_125Hz=new float[5];
float[] noiseatt_250Hz=new float[5];
float[] noiseatt_500Hz=new float[5];
@ -65,10 +67,11 @@ class PsyInfo
float[] noiseatt_4000Hz=new float[5];
float[] noiseatt_8000Hz=new float[5];
float max_curve_dB;
//float max_curve_dB;
float attack_coeff;
float decay_coeff;
//float attack_coeff;
//float decay_coeff;
void free(){}
internal void free(){}
}
}

Просмотреть файл

@ -26,19 +26,22 @@
using System;
using csogg;
class PsyLook
namespace csvorbis
{
int n;
PsyInfo vi;
class PsyLook
{
//int n;
//PsyInfo vi;
float[][][] tonecurves;
float[][] peakatt;
float[][][] noisecurves;
//float[][][] tonecurves;
//float[][] peakatt;
//float[][][] noisecurves;
float[] ath;
int[] octave;
//float[] ath;
//int[] octave;
void init(PsyInfo vi, int n, int rate)
{
}
}
}

Просмотреть файл

@ -24,10 +24,15 @@
*/
using System;
using System.Runtime.CompilerServices;
using csogg;
class Residue0 : FuncResidue{
void pack(Object vr, csBuffer opb){
namespace csvorbis
{
class Residue0 : FuncResidue
{
override public void pack(Object vr, csBuffer opb)
{
InfoResidue0 info=(InfoResidue0)vr;
int acc=0;
opb.write(info.begin,24);
@ -41,24 +46,29 @@ class Residue0 : FuncResidue{
/* secondstages is a bitmask; as encoding progresses pass by pass, a
bitmask of one indicates this partition class has bits to write
this pass */
for(int j=0;j<info.partitions;j++){
if(ilog(info.secondstages[j])>3){
for(int j=0;j<info.partitions;j++)
{
if(ilog(info.secondstages[j])>3)
{
/* yes, this is a minor hack due to not thinking ahead */
opb.write(info.secondstages[j],3);
opb.write(1,1);
opb.write(info.secondstages[j] >> 3,5);
}
else{
else
{
opb.write(info.secondstages[j],4); /* trailing zero */
}
acc+=icount(info.secondstages[j]);
}
for(int j=0;j<acc;j++){
for(int j=0;j<acc;j++)
{
opb.write(info.booklist[j],8);
}
}
Object unpack(Info vi, csBuffer opb){
override public Object unpack(Info vi, csBuffer opb)
{
int acc=0;
InfoResidue0 info=new InfoResidue0();
@ -68,38 +78,45 @@ class Residue0 : FuncResidue{
info.partitions=opb.read(6)+1;
info.groupbook=opb.read(8);
for(int j=0;j<info.partitions;j++){
for(int j=0;j<info.partitions;j++)
{
int cascade=opb.read(3);
if(opb.read(1)!=0){
if(opb.read(1)!=0)
{
cascade|=(opb.read(5)<<3);
}
info.secondstages[j]=cascade;
acc+=icount(cascade);
}
for(int j=0;j<acc;j++){
for(int j=0;j<acc;j++)
{
info.booklist[j]=opb.read(8);
// if(info.booklist[j]==255)info.booklist[j]=-1;
// if(info.booklist[j]==255)info.booklist[j]=-1;
}
if(info.groupbook>=vi.books){
if(info.groupbook>=vi.books)
{
free_info(info);
return(null);
}
for(int j=0;j<acc;j++){
if(info.booklist[j]>=vi.books){
for(int j=0;j<acc;j++)
{
if(info.booklist[j]>=vi.books)
{
free_info(info);
return(null);
}
}
return(info);
// errout:
// free_info(info);
// return(NULL);
// errout:
// free_info(info);
// return(NULL);
}
Object look(DspState vd, InfoMode vm, Object vr){
override public Object look(DspState vd, InfoMode vm, Object vr)
{
InfoResidue0 info=(InfoResidue0)vr;
LookResidue0 look=new LookResidue0();
int acc=0;
@ -116,28 +133,34 @@ class Residue0 : FuncResidue{
look.partbooks=new int[look.parts][];
for(int j=0;j<look.parts;j++){
for(int j=0;j<look.parts;j++)
{
int stages=ilog(info.secondstages[j]);
if(stages!=0){
if(stages!=0)
{
if(stages>maxstage)maxstage=stages;
look.partbooks[j]=new int[stages];
for(int k=0; k<stages; k++){
if((info.secondstages[j]&(1<<k))!=0){
for(int k=0; k<stages; k++)
{
if((info.secondstages[j]&(1<<k))!=0)
{
look.partbooks[j][k]=info.booklist[acc++];
}
}
}
}
look.partvals=(int)Math.rint(Math.pow(look.parts,dim));
look.partvals=(int)Math.Round(Math.Pow(look.parts,dim));
look.stages=maxstage;
look.decodemap=new int[look.partvals][];
for(int j=0;j<look.partvals;j++){
for(int j=0;j<look.partvals;j++)
{
int val=j;
int mult=look.partvals/look.parts;
look.decodemap[j]=new int[dim];
for(int k=0;k<dim;k++){
for(int k=0;k<dim;k++)
{
int deco=val/mult;
val-=deco*mult;
mult/=look.parts;
@ -147,18 +170,18 @@ class Residue0 : FuncResidue{
return(look);
}
void free_info(Object i){}
void free_look(Object i){}
int forward(Block vb,Object vl, float[][] fin, int ch){
System.err.println("Residue0.forward: not implemented");
override public void free_info(Object i){}
override public void free_look(Object i){}
override public int forward(Block vb,Object vl, float[][] fin, int ch)
{
return 0;
}
static int[][][] partword=new int[2][][]; // _01inverse is synchronized for
// re-using partword
static int _01inverse(Block vb, Object vl, float[][] fin, int ch, int decodepart)
[MethodImpl(MethodImplOptions.Synchronized)]
internal static int _01inverse(Block vb, Object vl, float[][] fin, int ch, int decodepart)
{
lock(this)
{
int i,j,k,l,s;
LookResidue0 look=(LookResidue0 )vl;
@ -172,7 +195,7 @@ class Residue0 : FuncResidue{
int partvals=n/samples_per_partition;
int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
if(partword.length<ch)
if(partword.Length<ch)
{
partword=new int[ch][][];
for(j=0;j<ch;j++)
@ -184,7 +207,7 @@ class Residue0 : FuncResidue{
{
for(j=0;j<ch;j++)
{
if(partword[j]==null || partword[j].length<partwords)
if(partword[j]==null || partword[j].Length<partwords)
partword[j]=new int[partwords][];
}
}
@ -251,8 +274,9 @@ class Residue0 : FuncResidue{
}
}
static int _2inverse(Block vb, Object vl, float[][] fin, int ch){
int i,j,k,l,s;
internal static int _2inverse(Block vb, Object vl, float[][] fin, int ch)
{
int i,k,l,s;
LookResidue0 look=(LookResidue0 )vl;
InfoResidue0 info=look.info;
@ -265,29 +289,38 @@ class Residue0 : FuncResidue{
int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
int[][] partword=new int[partwords][];
for(s=0;s<look.stages;s++){
for(i=0,l=0;i<partvals;l++){
if(s==0){
for(s=0;s<look.stages;s++)
{
for(i=0,l=0;i<partvals;l++)
{
if(s==0)
{
// fetch the partition word for each channel
int temp=look.phrasebook.decode(vb.opb);
if(temp==-1){
if(temp==-1)
{
// goto eopbreak;
return(0);
}
partword[l]=look.decodemap[temp];
if(partword[l]==null){
if(partword[l]==null)
{
// goto errout;
return(0);
}
}
// now we decode residual values for the partitions
for(k=0;k<partitions_per_word && i<partvals;k++,i++){
for(k=0;k<partitions_per_word && i<partvals;k++,i++)
{
int offset=info.begin+i*samples_per_partition;
if((info.secondstages[partword[l][k]]&(1<<s))!=0){
if((info.secondstages[partword[l][k]]&(1<<s))!=0)
{
CodeBook stagebook=look.fullbooks[look.partbooks[partword[l][k]][s]];
if(stagebook!=null){
if(stagebook.decodevv_add(fin, offset, ch, vb.opb,samples_per_partition)==-1){
if(stagebook!=null)
{
if(stagebook.decodevv_add(fin, offset, ch, vb.opb,samples_per_partition)==-1)
{
// goto errout;
return(0);
}
@ -296,16 +329,19 @@ class Residue0 : FuncResidue{
}
}
}
// errout:
// eopbreak:
// errout:
// eopbreak:
return(0);
}
int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch){
override public int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
{
//System.err.println("Residue0.inverse");
int used=0;
for(int i=0;i<ch;i++){
if(nonzero[i]!=0){
for(int i=0;i<ch;i++)
{
if(nonzero[i]!=0)
{
fin[used++]=fin[i];
}
}
@ -315,59 +351,66 @@ class Residue0 : FuncResidue{
return(0);
}
private static int ilog(int v){
internal static int ilog(int v)
{
int ret=0;
while(v!=0){
while(v!=0)
{
ret++;
(uint)v >>= 1;
v = (int)((uint)v >> 1);
}
return(ret);
}
private static int icount(int v){
internal static int icount(int v)
{
int ret=0;
while(v!=0){
while(v!=0)
{
ret+=(v&1);
(uint)v >>= 1;
v = (int)((uint)v >> 1);
}
return(ret);
}
}
}
class LookResidue0 {
InfoResidue0 info;
int map;
class LookResidue0
{
internal InfoResidue0 info;
internal int map;
int parts;
int stages;
CodeBook[] fullbooks;
CodeBook phrasebook;
int[][] partbooks;
// CodeBook[][] partbooks;
internal int parts;
internal int stages;
internal CodeBook[] fullbooks;
internal CodeBook phrasebook;
internal int[][] partbooks;
// CodeBook[][] partbooks;
int partvals;
int[][] decodemap;
internal int partvals;
internal int[][] decodemap;
int postbits;
int phrasebits;
// int[][] frames;
int frames;
}
//internal int postbits;
//internal int phrasebits;
// int[][] frames;
//internal int frames;
}
class InfoResidue0{
class InfoResidue0
{
// block-partitioned VQ coded straight residue
int begin;
int end;
internal int begin;
internal int end;
// first stage (lossless partitioning)
int grouping; // group n vectors per partition
int partitions; // possible codebooks for a partition
int groupbook; // huffbook for partitioning
int[] secondstages=new int[64]; // expanded out to pointers in lookup
int[] booklist=new int[256]; // list of second stage books
internal int grouping; // group n vectors per partition
internal int partitions; // possible codebooks for a partition
internal int groupbook; // huffbook for partitioning
internal int[] secondstages=new int[64]; // expanded out to pointers in lookup
internal int[] booklist=new int[256]; // list of second stage books
// encode-only heuristic settings
float[] entmax=new float[64]; // book entropy threshholds
float[] ampmax=new float[64]; // book amp threshholds
int[] subgrp=new int[64]; // book heuristic subgroup size
int[] blimit=new int[64]; // subgroup position limits
internal float[] entmax=new float[64]; // book entropy threshholds
internal float[] ampmax=new float[64]; // book amp threshholds
internal int[] subgrp=new int[64]; // book heuristic subgroup size
internal int[] blimit=new int[64]; // subgroup position limits
}
}

Просмотреть файл

@ -26,25 +26,34 @@
using System;
using csogg;
class Residue1 : Residue0{
int forward(Block vb,Object vl, float[][] fin, int ch){
System.err.println("Residue0.forward: not implemented");
namespace csvorbis
{
class Residue1 : Residue0
{
new int forward(Block vb,Object vl, float[][] fin, int ch)
{
return 0;
}
int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch){
//System.err.println("Residue0.inverse");
override public int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
{
//System.err.println("Residue0.inverse");
int used=0;
for(int i=0; i<ch; i++){
if(nonzero[i]!=0){
for(int i=0; i<ch; i++)
{
if(nonzero[i]!=0)
{
fin[used++]=fin[i];
}
}
if(used!=0){
if(used!=0)
{
return(_01inverse(vb, vl, fin, used, 1));
}
else{
else
{
return 0;
}
}
}
}

Просмотреть файл

@ -26,15 +26,16 @@
using System;
using csogg;
class Residue2 : Residue0
namespace csvorbis
{
int forward(Block vb,Object vl, float[][] fin, int ch)
class Residue2 : Residue0
{
override public int forward(Block vb,Object vl, float[][] fin, int ch)
{
System.err.println("Residue0.forward: not implemented");
return 0;
}
int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
override public int inverse(Block vb, Object vl, float[][] fin, int[] nonzero, int ch)
{
//System.err.println("Residue0.inverse");
int i=0;
@ -43,4 +44,5 @@ class Residue2 : Residue0
return(_2inverse(vb, vl, fin, ch));
}
}
}

Просмотреть файл

@ -26,22 +26,24 @@
using System;
using csogg;
class StaticCodeBook
namespace csvorbis
{
int dim; // codebook dimensions (elements per vector)
int entries; // codebook entries
int[] lengthlist; // codeword lengths in bits
class StaticCodeBook
{
internal int dim; // codebook dimensions (elements per vector)
internal int entries; // codebook entries
internal int[] lengthlist; // codeword lengths in bits
// mapping
int maptype; // 0=none
internal int maptype; // 0=none
// 1=implicitly populated values from map column
// 2=listed arbitrary values
// The below does a linear, single monotonic sequence mapping.
int q_min; // packed 32 bit float; quant value 0 maps to minval
int q_delta; // packed 32 bit float; val 1 - val 0 == delta
int q_quant; // bits: 0 < quant <= 16
int q_sequencep; // bitflag
internal int q_min; // packed 32 bit float; quant value 0 maps to minval
internal int q_delta; // packed 32 bit float; val 1 - val 0 == delta
internal int q_quant; // bits: 0 < quant <= 16
internal int q_sequencep; // bitflag
// additional information for log (dB) mapping; the linear mapping
// is assumed to actually be values in dB. encodebias is used to
@ -50,34 +52,33 @@ class StaticCodeBook
// indicates if we're to represent negative linear values in a
// mirror of the positive mapping.
int[] quantlist; // map == 1: (int)(entries/dim) element column map
internal int[] quantlist; // map == 1: (int)(entries/dim) element column map
// map == 2: list of dim*entries quantized entry vals
// encode helpers
EncodeAuxNearestMatch nearest_tree;
EncodeAuxThreshMatch thresh_tree;
internal EncodeAuxNearestMatch nearest_tree;
internal EncodeAuxThreshMatch thresh_tree;
StaticCodeBook(){}
StaticCodeBook(int dim, int entries, int[] lengthlist,
internal StaticCodeBook(){}
internal StaticCodeBook(int dim, int entries, int[] lengthlist,
int maptype, int q_min, int q_delta,
int q_quant, int q_sequencep, int[] quantlist,
//EncodeAuxNearestmatch nearest_tree,
Object nearest_tree,
// EncodeAuxThreshmatch thresh_tree,
Object thresh_tree
)
) : this()
{
this();
this.dim=dim; this.entries=entries; this.lengthlist=lengthlist;
this.maptype=maptype; this.q_min=q_min; this.q_delta=q_delta;
this.q_quant=q_quant; this.q_sequencep=q_sequencep;
this.quantlist=quantlist;
}
int pack(csBuffer opb)
internal int pack(csBuffer opb)
{
int i;
boolean ordered=false;
bool ordered=false;
opb.write(0x564342,24);
opb.write(dim, 16);
@ -199,7 +200,7 @@ class StaticCodeBook
// quantized values
for(i=0;i<quantvals;i++)
{
opb.write(Math.abs(quantlist[i]),q_quant);
opb.write(Math.Abs(quantlist[i]),q_quant);
}
}
break;
@ -214,7 +215,7 @@ class StaticCodeBook
// unpacks a codebook from the packet buffer into the codebook struct,
// readies the codebook auxiliary structures for decode
int unpack(csBuffer opb)
internal int unpack(csBuffer opb)
{
int i;
//memset(s,0,sizeof(static_codebook));
@ -369,9 +370,9 @@ class StaticCodeBook
// 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
private int maptype1_quantvals()
internal int maptype1_quantvals()
{
int vals=(int)(Math.floor(Math.pow(entries,1.0/dim)));
int vals=(int)(Math.Floor(Math.Pow(entries,1.0/dim)));
// the above *should* be reliable, but we'll not assume that FP is
// ever reliable when bitstream sync is at stake; verify via integer
@ -396,7 +397,7 @@ class StaticCodeBook
}
}
void clear()
internal void clear()
{
// if(quantlist!=null)free(b->quantlist);
// if(lengthlist!=null)free(b->lengthlist);
@ -422,7 +423,7 @@ class StaticCodeBook
// 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
float[] unquantize()
internal float[] unquantize()
{
if(maptype==1 || maptype==2)
@ -448,13 +449,13 @@ class StaticCodeBook
quantvals=maptype1_quantvals();
for(int j=0;j<entries;j++)
{
float last=0.f;
float last=0.0f;
int indexdiv=1;
for(int k=0;k<dim;k++)
{
int index=(j/indexdiv)%quantvals;
float val=quantlist[index];
val=Math.abs(val)*delta+mindel+last;
val=Math.Abs(val)*delta+mindel+last;
if(q_sequencep!=0)last=val;
r[j*dim+k]=val;
indexdiv*=quantvals;
@ -464,31 +465,34 @@ class StaticCodeBook
case 2:
for(int j=0;j<entries;j++)
{
float last=0.f;
float last=0.0f;
for(int k=0;k<dim;k++)
{
float val=quantlist[j*dim+k];
//if((j*dim+k)==0){System.err.println(" | 0 -> "+val+" | ");}
val=Math.abs(val)*delta+mindel+last;
val=Math.Abs(val)*delta+mindel+last;
if(q_sequencep!=0)last=val;
r[j*dim+k]=val;
//if((j*dim+k)==0){System.err.println(" $ r[0] -> "+r[0]+" | ");}
}
}
//System.err.println("\nr[0]="+r[0]);
break;
default:
break;
}
return(r);
}
return(null);
}
private static int ilog(int v)
internal static int ilog(int v)
{
int ret=0;
while(v!=0)
{
ret++;
(uint)v >>= 1;
v = (int)((uint)v >> 1);
}
return(ret);
}
@ -497,28 +501,28 @@ class StaticCodeBook
// biased exponent) : neeeeeee eeemmmmm mmmmmmmm mmmmmmmm
// Why not IEEE? It's just not that important here.
static int VQ_FEXP=10;
//static int VQ_FEXP=10;
static int VQ_FMAN=21;
static int VQ_FEXP_BIAS=768; // bias toward values smaller than 1.
// doesn't currently guard under/overflow
static long float32_pack(float val)
internal static long float32_pack(float val)
{
int sign=0;
uint sign=0;
int exp;
int mant;
if(val<0)
{
sign=0x80000000;
val= -val;
sign = 0x80000000;
val = -val;
}
exp=(int)Math.floor(Math.log(val)/Math.log(2));
mant=(int)Math.rint(Math.pow(val,(VQ_FMAN-1)-exp));
exp=(int)Math.Floor(Math.Log(val)/Math.Log(2));
mant=(int)Math.Round(Math.Pow(val,(VQ_FMAN-1)-exp));
exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
return(sign|exp|mant);
return((int)sign | exp | mant);
}
static float float32_unpack(int val)
internal static float float32_unpack(int val)
{
float mant=val&0x1fffff;
float sign=val&0x80000000;
@ -530,8 +534,9 @@ class StaticCodeBook
return(ldexp(mant,((int)exp)-(VQ_FMAN-1)-VQ_FEXP_BIAS));
}
static float ldexp(float foo, int e)
internal static float ldexp(float foo, int e)
{
return (float)(foo*Math.pow(2, e));
return (float)(foo*Math.Pow(2, e));
}
}
}

Просмотреть файл

@ -26,13 +26,16 @@
using System;
using csogg;
class Time0 : FuncTime
namespace csvorbis
{
void pack(Object i, csBuffer opb){}
Object unpack(Info vi , csBuffer opb){return "";}
Object look(DspState vd, InfoMode mi, Object i){return "";}
void free_info(Object i){}
void free_look(Object i){}
int forward(Block vb, Object i){return 0;}
int inverse(Block vb, Object i, float[] fin, float[] fout){return 0;}
class Time0 : FuncTime
{
override public void pack(Object i, csBuffer opb){}
override public Object unpack(Info vi , csBuffer opb){return "";}
override public Object look(DspState vd, InfoMode mi, Object i){return "";}
override public void free_info(Object i){}
override public void free_look(Object i){}
override public int forward(Block vb, Object i){return 0;}
override public int inverse(Block vb, Object i, float[] fin, float[] fout){return 0;}
}
}

Просмотреть файл

@ -25,10 +25,13 @@
using System;
public class csorbisException : Exception
namespace csvorbis
{
public class csorbisException : Exception
{
public csorbisException ()
:base(){}
public csorbisException (String s)
:base("csorbis: "+s){}
}
}