コード例 #1
0
ファイル: MainForm.cs プロジェクト: LuckyLuik/AudioVSTToolbox
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			// set title
			this.Text = "Wav2Zebra2Osc Version " + VERSION;
			
			// Initialize Bass
			audioSystem = BassProxy.Instance;

			// Ensure the paint methods are called if resized
			ResizeRedraw = true;
			
			// Initialize the wave display cells
			waveDisplays = new WaveDisplayUserControl[16];
			int counter = 0;
			for( int row = 0; row != 4; ++row ) {
				for( int col = 0; col != 4; ++col ) {
					this.waveDisplays[counter] = new WaveDisplayUserControl(this);
					this.tableLayoutPanel.Controls.Add(waveDisplays[counter], col, row);
					this.waveDisplays[counter].ResumeLayout(false);
					this.waveDisplays[counter].PerformLayout();
					counter++;
				}
			}
			this.waveDisplays[0].Selected = true;

			// Initalize the jagged data arrays
			this.soundData = MathUtils.CreateJaggedArray<float[][]>(16, 128);
			this.morphedData = MathUtils.CreateJaggedArray<float[][]>(16, 128);
			
			// generate the sine data
			this.sineData = OscillatorGenerator.Sine();
			
			// set sine data to first and last element
			Array.Copy(this.sineData, 0, this.morphedData[0], 0, 128);
			Array.Copy(this.sineData, 0, this.morphedData[15], 0, 128);
			
			this.waveDisplays[0].Loaded = true;
			this.waveDisplays[15].Loaded = true;
			this.waveDisplays[0].MorphedData = this.morphedData[0];
			this.waveDisplays[15].MorphedData = this.morphedData[15];
			this.waveDisplays[0].Refresh();
			this.waveDisplays[15].Refresh();
			
			this.OutputText = "Export path: " + ReadExportPathName();
		}
コード例 #2
0
		/// <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;
		}
コード例 #3
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 = BassProxy.Instance; /*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);
		}
コード例 #4
0
		/// <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 = BassProxy.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;
		}