NodeList(NodeListUsed) = Node ' add the new node Node.RightNode = Nothing ' the default is nothing, but it is okay to assign a value Node.Probability = P(I) ' copy the probability Node.Symbol = I ' the symbol the node is representing ' next start creating the tree Dim NodeList( 0 To 255) As BinaryTreeNodeĭim NodeListUsed As Integer = 0 Dim Node As BinaryTreeNodeĭim I As Integer For I = 0 To 255 If P(I) > 0 Then ' create a node ![]() ' first get the probabilities Dim P() As Long = FindProbabilitiesForSymbols(Data) ![]() K2 = 0 End If End Sub ' compress the data Public Function CompressByteArray( ByVal Data() As Byte) As Byte() ' get two bits for the command Dim CMD As Integer Dim K1 As Integer Dim K2 As Integer If Node Is Nothing Then Exit Sub End If If Node.Symbol -1 ThenĮxit Sub End If If Not Node.LeftNode Is Nothing ThenĮnd If If Not Node.RightNode Is Nothing ThenĮnd If End Sub ' load tree from bits array Private Sub LoadTree( ByRef Node As BinaryTreeNode, ByVal BA As bitsarray) If N.LeftNode Is Nothing And N.RightNode Is Nothing Then Dim C As New CollectionĬ1 = GetSymbolCodes(N.LeftNode, Prefix & " 0")Įnd If If Not N.RightNode Is Nothing ThenĬ2 = GetSymbolCodes(N.RightNode, Prefix & " 1")Įnd If Dim I As Integer For I = 1 To C1.CountĮnd Function Private Sub StoreTree( ByVal Node As BinaryTreeNode, ByRef BA As bitsarray) Public Symbol As Integer End Class ' find the probabilities for a set of symbols Private Function FindProbabilitiesForSymbols( ByVal Data() As Byte) As Long()ĭim B( 0 To 255) As Long Dim I As Integer ' set probabilities to zero For I = 0 To 255ī(I) = 0 Next ' compute the probabilities For I = 0 To Data.Length - 1Įnd Function Private Function GetSymbolCodes( ByVal N As BinaryTreeNode, ByVal Prefix As String) As Collection Public Probability As Long Public RightNode As BinaryTreeNode Loop End Sub ' get the bits array Public Function GetBitsArray() As Byte()ĭim B() As Byte Dim I As Integer ReDim B( 0 To BytesUsed - 1)Įnd Function End Class ' next define the tree nodes data struction Private Class BinaryTreeNode Value = Value \ 2 Next End Sub ' save the rest of the byte Public Sub FlushBuffer() Public BytesUsed As Integer ' the number of bytes used from the array or the progress Public BytesArray() As Byte ' the bytes array Public ByteBuffer As Integer ' a single buffer used to store bits until they form a byte Public ByteBufferUsed As Integer ' a counter showing how many bits you are using from this array ' the constructer Public Sub New()īyteBufferUsed = 0 ReDim BytesArray( 0 To 1023)Įnd Sub ' SET BYTE ARRAY Public Sub SetArray( ByVal A() As Byte)Įnd Sub ' add single bit to the buffer Public Sub AddBit( ByVal BitValue As Integer)īitValue = BitValue Mod 2 ' extract the first bitīyteBuffer = ByteBuffer Or (BitValue * Math.Pow( 2, ByteBufferUsed - 1)) ' add the bit to the buffer If ByteBufferUsed = 8 ThenīyteBufferUsed = 0 If BytesUsed = BytesArray.Length Then ReDim Preserve BytesArray( 0 To BytesUsed + 1023)Įnd If End If End Sub ' read single bit from the buffer Public Function ReadBit() As Integer If ByteBufferUsed = -1 ThenīyteBufferUsed = 0 End If If ByteBufferUsed = 8 ThenīyteBufferUsed = 0 End If Dim Bit As IntegerīyteBufferUsed = ByteBufferUsed + 1 Return BitĮnd Function Public Function ReadBits( ByVal Bits As Integer) As Integer Dim V As Integer Dim K As IntegerĮnd Function ' add a number of bits to the array Public Sub AddBits( ByVal Value As Integer, ByVal Bits As Integer) ' first define the BitsArray, which is used to perform bitstoring and reading. So my final command is: ffmpeg.exe -y -i input.flac -codec:a libmp3lame -q:a 0 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 output.' this module is used to compress a byte array using the huffman coding technique. If you want ID3v1 metatags too, you should add the -write_id3v1 1 parameter. The option -qscale:a is mapped to the -V option in the standalone lame command-line interface tool. 0-3 will normally produce transparent results, 4 (default) should be close to perceptual transparency, and 6 produces an "acceptable" quality. Values are encoder specific, so for libmp3lame the range is 0-9 where a lower value is a higher quality. If you want use this option in ffmpeg, you should use the -q:a 0 alias.Ĭontrol quality with -qscale:a (or the alias -q:a). Audible differences between these presets may exist, but are rare. These VBR settings will normally produce transparent results. ![]() Very high quality: HiFi, home, or quiet listening, with best file size ![]() If you want to save a little space, try the recommendation of hydrogenaud.io:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |