Esempio n. 1
0
	static void Main(string[] args)
	{
		Console.WriteLine("ToyTools MP3 Decoder Demo");
		if(args.Length != 3)
		{
			Console.WriteLine("Usage: ToyMP3Demo.exe <MP3 Filename> <OUTPUT FILENAME> <ch>");
			return;
		}

		var mp3     = new ToyTools.ToyMP3(args[0]);
		var output  = args[1];
		var frame   = new ToyTools.ToyMP3Frame();
		var decoder = new ToyTools.ToyMP3Decoder();
		var wout = new ToyWaveOut();

		// main loop
		var sw = new Stopwatch();
		var debug_framenum = 0;
		var loop = 0;
		wout.PublishWaveFile(output, int.Parse(args[2]));

		sw.Start();
		try{
			while(mp3.SeekMP3Frame(frame))
			{
				decoder.DecodeFrame(frame);
				debug_framenum++;
				wout.AddData(decoder.Pcm);
				loop++;
			}
		}
		catch(Exception)
		{
			//Console.WriteLine(e);
		}
		sw.Stop();
		var ts = sw.Elapsed;
		wout.FinishWriting();
		Console.WriteLine(
			"spent time:{0} total frame:{1} clpped_samples:{2}",
			ts, debug_framenum, decoder.Clip);
	}
Esempio n. 2
0
    public async void loadHash(string path)
    {
      center.Visibility = System.Windows.Visibility.Collapsed;
      await Task.Delay(1);
      
		  var mp3 = new ToyMP3(path);
      
		  var frame   = new ToyTools.ToyMP3Frame();
		  var decoder = new ToyTools.ToyMP3Decoder();

      var list = new List<short>();

      loading.Content = "Parseing...";
      await Task.Delay(1);

		  try
      {
			  while (mp3.SeekMP3Frame(frame))
			  {
				  decoder.DecodeFrame(frame);
          list.AddRange(decoder.Pcm);
			  }
      }
      catch (Exception) { }

      wave = PickFloat(list.ToArray()).ToArray();
      var bmp = new Bitmap((int)Math.Ceiling((double)wave.Length / 100), 100);

      loading.Content = "Drawing...";
      await Task.Delay(1);

      AudioVisualizationService.DrawWave(wave, bmp);
      image.Source = bmp.ToBitmapSource();

      loading.Visibility = System.Windows.Visibility.Collapsed;
      center.Visibility = System.Windows.Visibility.Visible;

      return;
    }