コード例 #1
0
 /// <summary>
 ///   Read mono from file
 /// </summary>
 /// <param name = "filename">Name of the file</param>
 /// <param name = "samplerate">Sample rate</param>
 /// <param name = "milliseconds">milliseconds to read</param>
 /// <param name = "startmillisecond">Start millisecond</param>
 /// <returns>Array of samples</returns>
 public static float[] ReadMonoFromFile(string filename, int samplerate, int milliseconds, int startmillisecond)
 {
     BassProxy proxy = new BassProxy(); /*audio proxy used in reading the file*/
     return proxy.ReadMonoFromFile(filename, samplerate, milliseconds, startmillisecond);
 }
コード例 #2
0
 public RepositoryGateway()
 {
     _storage = new RamStorage(NUMBER_OF_HASH_TABLES); /*Number of LSH Tables, used for storage purposes*/
     _permutations = new LocalPermutations(PATH_TO_PERMUTATIONS, SEPARATOR); /*Permutations*/
     _repository = new Repository(_storage, _permutations);
     _proxy = new BassProxy(); /*audio proxy used in reading the file*/
     _createStride = new IncrementalStaticStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT);
     _queryStride = new IncrementalRandomStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT, SAMPLES_IN_FINGERPRINT);
 }
コード例 #3
0
        /// <summary>
        ///   Read mono from file
        /// </summary>
        /// <param name = "filename">Name of the file</param>
        /// <param name = "samplerate">Sample rate</param>
        /// <param name = "milliseconds">milliseconds to read</param>
        /// <param name = "startmillisecond">Start millisecond</param>
        /// <returns>Array of samples</returns>
        public static float[] ReadMonoFromFile(string filename, int samplerate, int milliseconds, int startmillisecond)
        {
            BassProxy proxy = new BassProxy();             /*audio proxy used in reading the file*/

            return(proxy.ReadMonoFromFile(filename, samplerate, milliseconds, startmillisecond));
        }
コード例 #4
0
        // ******************************************************************** //
        // Constructor.
        // ******************************************************************** //
        ///
        ///	 <summary> * Create a AudioAnalyser instance. </summary>
        ///
        public AudioAnalyser()
        {
            audioReader = new BassProxy();

            spectrumAnalyser = new FFTTransformer(inputBlockSize, windowFunction);

            // Allocate the spectrum data.
            spectrumData = new float[inputBlockSize / 2];
            spectrumHist = RectangularArrays.ReturnRectangularFloatArray(inputBlockSize / 2, historyLen);
            spectrumIndex = 0;

            biasRange = new float[2];
        }
コード例 #5
0
ファイル: Repository.cs プロジェクト: remy22/AudioVSTToolbox
 /// <summary>
 /// Get track from the filename
 /// </summary>
 /// <param name="mintracklen">Min track length</param>
 /// <param name="maxtracklen">Max track length</param>
 /// <param name="filename">Filename from which to extract the requested info</param>
 /// <param name="proxy">Audio proxy to read tags</param>
 /// <returns>Track to be analyzed further / null if the track is not eligible</returns>
 private static Track GetTrack(int mintracklen, int maxtracklen, string filename, BassProxy proxy)
 {
     TAG_INFO tags = proxy.GetTagInfoFromFile(filename); //get file tags
     string artist, title;
     double duration;
     if (tags == null)
     {
         /*The song does not contain any tags*/
         artist = "Unknown";
         title = "Unknown";
         duration = 60;
     }
     else
     {
         /*The song contains related tags*/
         artist = tags.artist;
         title = tags.title;
         duration = tags.duration;
     }
     if (String.IsNullOrEmpty(artist)) /*assign a name to music files that don't have tags*/
         artist = "Unknown";
     if (String.IsNullOrEmpty(title)) /*assign a title to music files that don't have tags*/
         title = "Unknown";
     if (duration < mintracklen || duration > maxtracklen) /*check the duration of a music file*/
     {
         System.Diagnostics.Debug.WriteLine(String.Format("File {0} failed the duration validation. Duration: {1} [Min: {2}, Max: {3}]", filename, duration, mintracklen, maxtracklen) );
         return null;
     }
     Track track = new Track {Artist = artist, Title = title,
         TrackLength = duration, Path = Path.GetFullPath(filename)};
     return track;
 }
コード例 #6
0
ファイル: Repository.cs プロジェクト: remy22/AudioVSTToolbox
        /// <summary>
        ///   Create fingerprints/min-hash signatures/LSH buckets and insert them in underlying storage
        /// </summary>
        /// <param name = "files">Files to be processed</param>
        /// <param name = "audioProxy">Audio proxy used in processing</param>
        /// <param name = "queryStride">Stride between 2 consecutive fingerprints on query</param>
        /// <param name = "creationalStride">Stride between 2 consecutive fingerprints on creation</param>
        /// <param name = "mintracklen">Minimum track length</param>
        /// <param name = "maxtracklen">Maximum track length</param>
        /// <param name = "milliSecondsToProcess">Number of milliseconds to process</param>
        /// <param name = "startMillisecond">Start processing at a specific millisecond</param>
        /// <param name = "hashTables">Number of hash-tables used in LSH decomposition</param>
        /// <param name = "hashKeys">Number of Min Hash keys per LSH table</param>
        /// <param name = "trackProcessed">Invoked once the track is processed</param>
        /// <returns>List of processed tracks</returns>
        public List<Track> ProcessTracks(List<string> files, BassProxy audioProxy, IStride queryStride, IStride creationalStride,
                                  int mintracklen, int maxtracklen,
                                  int milliSecondsToProcess, int startMillisecond, int hashTables, int hashKeys, Action<Track> trackProcessed)
        {
            List<Track> tracks = new List<Track>();
            _threadCounts++;

            foreach (string file in files) //filter files that can be processed
            {
                if (_aborted) break;

                Track track = GetTrack(mintracklen, maxtracklen, file, audioProxy);
                if (track == null)
                    continue; /*track is not eligible because of min/max parameters*/
                //create spectrogram of the file
                float[][] logSpectrum = null;
                try
                {
                    //try creating the spectrum from a file
                    logSpectrum = _manager.CreateLogSpectrogram(audioProxy, track.Path, milliSecondsToProcess, startMillisecond);
                }
                catch (Exception ex)
                {
                    if (ex is ThreadAbortException)
                        throw;
                    /*the file might be corrupted or missing*/
                    continue; /*Continue processing even if creation of the spectrogram failed*/
                }
                _storage.InsertTrack(track); /*Insert track into the storage*/
                /*Create fingerprints that will be used as initial fingerprints to be queried*/
                List<bool[]> dbFingers = _manager.CreateFingerprints(logSpectrum, creationalStride);
                /*Get fingerprint's hash signature, and associate it to a specific track*/
                List<HashSignature> creationalsignatures = GetSignatures(dbFingers, track, hashTables, hashKeys);
                foreach (HashSignature hash in creationalsignatures)
                {
                    _storage.InsertHash(hash, HashType.Creational);
                    /*Set this hashes as also the query hashes*/
                    _storage.InsertHash(hash, HashType.Query);
                }
                /*Create fingerprints for query*/
                List<bool[]> queryFingers = _manager.CreateFingerprints(logSpectrum, queryStride); /*Create fingerprints*/
                List<HashSignature> querysignatures = GetSignatures(queryFingers, track, hashTables, hashKeys);

                // ***** PIN TODO: CHANGE THIS
                object[][] arr = new object[querysignatures.Count][];
                int count = 0;
                foreach (HashSignature hash in querysignatures) {
                    _storage.InsertHash(hash, HashType.Query); /*Insert hash-buckets into hash-tables*/

                    String signatureText = "{";
                    for (int s = 0; s < hash.Signature.Length; s++) {
                        signatureText += hash.Signature[s];
                        signatureText += " ";
                    }
                    signatureText += "}";

                    arr[count++] = new object[5] {
                        hash.Id,
                        hash.Track.Title,
                        hash.Track.Artist,
                        hash.Track.TrackLength,
                        signatureText
                    };
                }
                String filenameToSave = String.Format("C:\\{0}-hash-buckets.txt", System.IO.Path.GetFileNameWithoutExtension(file));
                CSVWriter csv = new CSVWriter(filenameToSave);
                csv.Write(arr);
                // ***** end PIN

                if (trackProcessed != null)
                    trackProcessed.Invoke(track);
                tracks.Add(track);
            }
            _threadCounts--;
            return tracks;
        }