/// <summary> /// Using the passed datareader pointer, fill the audio feature tracks array with content /// </summary> /// <param name="tracksIterator">datareader pointer</param> /// <param name="tracks">AudioFeature array</param> /// <param name="mapping">array of trackids</param> /// <param name="len">number of tracks to return</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <returns>number of tracks returned</returns> public int GetNextTracks(ref IDataReader tracksIterator, ref AudioFeature[] tracks, ref int[] mapping, int len, Analyzer.AnalysisMethod analysisMethod) { int i = 0; while ((i < len) && tracksIterator.Read()) { AudioFeature audioFeature = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: audioFeature = MandelEllis.FromBytes((byte[])tracksIterator.GetValue(0)); break; case Analyzer.AnalysisMethod.SCMS: audioFeature = Scms.FromBytes((byte[])tracksIterator.GetValue(0)); break; } mapping[i] = tracksIterator.GetInt32(1); audioFeature.Name = tracksIterator.GetString(2); audioFeature.Duration = tracksIterator.GetInt64(3); audioFeature.BitString = tracksIterator.GetString(4); tracks[i] = audioFeature; i++; } if (i == 0) { tracksIterator.Close(); tracksIterator = null; } return(i); }
/// <summary> /// Get a track from the database using its id /// </summary> /// <param name="trackid">id</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <returns>an AudioFeature object</returns> public AudioFeature GetTrack(int trackid, Analyzer.AnalysisMethod analysisMethod) { IDbCommand dbcmd; lock (dbcon) { dbcmd = dbcon.CreateCommand(); } dbcmd.CommandText = "SELECT audioFeature, name, duration, bitstring FROM mirage " + "WHERE trackid = " + trackid; IDataReader reader = dbcmd.ExecuteReader(); if (!reader.Read()) { return(null); } byte[] buf = (byte[])reader.GetValue(0); string name = reader.GetString(1); long duration = reader.GetInt64(2); string bitstring = reader.GetString(3); reader.Close(); AudioFeature audioFeature = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: audioFeature = MandelEllis.FromBytes(buf); break; case Analyzer.AnalysisMethod.SCMS: audioFeature = Scms.FromBytes(buf); break; } audioFeature.Name = name; audioFeature.Duration = duration; audioFeature.BitString = bitstring; return(audioFeature); }