Skip to content

Commit

Permalink
Fix array resize madness
Browse files Browse the repository at this point in the history
  • Loading branch information
wo80 committed Jan 16, 2016
1 parent 4e3e8b3 commit 43dad1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
7 changes: 2 additions & 5 deletions AcoustID/ChromaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

namespace AcoustID
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcoustID.Chromaprint;
using AcoustID.Util;
using System;

/// <summary>
/// The main Chromaprint API.
Expand All @@ -21,7 +18,7 @@ public class ChromaContext
/// <summary>
/// Return the version number of Chromaprint.
/// </summary>
public static readonly string Version = "1.1.0";
public static readonly string Version = "1.2.0";

Fingerprinter fingerprinter;
int algorithm;
Expand Down
23 changes: 18 additions & 5 deletions AcoustID/Chromaprint/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace AcoustID.Chromaprint
/// </summary>
public class Image
{
private const int BUFFER_BLOCK_SIZE = 2048;

private int m_rows;
private int m_columns;
private double[] m_data;

Expand All @@ -23,7 +26,7 @@ public int Columns

public int Rows
{
get { return m_data.Length / m_columns; }
get { return m_rows; }
}

public double this[int i, int j]
Expand All @@ -44,12 +47,14 @@ public Image(int columns)

public Image(int columns, int rows)
{
m_rows = rows;
m_columns = columns;
m_data = new double[columns * rows];
m_data = new double[Math.Max(columns * rows, BUFFER_BLOCK_SIZE)];
}

public Image(int columns, double[] data)
{
m_rows = data.Length / columns;
m_columns = columns;
m_data = data;
}
Expand All @@ -66,13 +71,21 @@ internal void Set(int i, int j, double value)

internal void AddRow(double[] row)
{
int n = m_data.Length;
Array.Resize(ref m_data, n + m_columns);
int n = m_rows * m_columns;

int size = m_data.Length;

if (n + m_columns > size)
{
Array.Resize(ref m_data, size + BUFFER_BLOCK_SIZE);
}

for (int i = 0; i < m_columns; i++)
{
m_data[n + i] = row[i];
}

m_rows++;
}

internal double[] Row(int i)
Expand Down
10 changes: 4 additions & 6 deletions AcoustID/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AcoustID
{
using System;

public class Configuration
{
/// <summary>
/// The API key for using the AcoustID webservice.
/// </summary>
/// <remarks>
/// Visit http://acoustid.org/ to get an API key for your application.
/// Visit https://acoustid.org/ to get an API key for your application.
/// </remarks>
public static string ApiKey = String.Empty;
}
Expand Down

0 comments on commit 43dad1b

Please sign in to comment.