Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: boota
- * Date: 3/25/2017
- * Time: 11:46 AM
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Linq;
- using NotITGSpectrum;
- namespace NotITGSpectrum
- {
- public class Spectrum {
- // From:
- // https://github.com/CristianChPuma/SBWriter/blob/master/Sbter/Spectrum.cs
- // bcuz im nub and cant understand mlg 5/9 cod
- private int stream, start, end, bpm, bars;
- private string filename;
- public Spectrum(string filename, int bars, int startTime, int endTime, int bpm)
- {
- this.filename = filename;
- this.bars = bars;
- start = startTime;
- end = endTime;
- this.bpm = bpm;
- BeginStream();
- }
- List<SpectrumData> data = new List<SpectrumData>();
- List<string> values = new List<string>();
- StringBuilder _fft = new StringBuilder();
- List<double> fft_list = new List<double>();
- public List<SpectrumData> GenerateData()
- {
- for (int position = start; position < end; position += bpm / 4)
- {
- Bass.BASS_ChannelSetPosition(stream, Bass.BASS_ChannelSeconds2Bytes(stream, position * 0.001), BASSMode.BASS_POS_BYTES);
- float[] fft = new float[2048];
- Bass.BASS_ChannelGetData(stream, fft, (int)BASSData.BASS_DATA_FFT4096);
- double[] fft_values = new double[bars];
- for (int i = 0; i < bars; i++)
- {
- fft_values[i]= Math.Round(double.Parse((((fft[i] * 2000 / 40) + 0.1).ToString()).Split('E')[0]),2);
- }
- data.Add(new SpectrumData() {StartTime = position, EndTime = (position + (bpm / 4)), Frecuencies = fft_values });
- _fft.Clear();
- }
- return data;
- }
- private void BeginStream()
- {
- Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
- Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_3D, IntPtr.Zero);
- stream = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_STREAM_DECODE);
- }
- public class SpectrumData
- {
- public int StartTime { get; set; }
- public int EndTime { get; set; }
- public string FFT { get; set; }
- public double [] Frecuencies { get; set; }
- public int Line { get; set; }
- public int Bar { get; set; }
- }
- }
- class Program
- {
- public static void Main(string[] args)
- {
- if (!Directory.Exists(Directory.GetCurrentDirectory() + @"\spectrums\")) {
- Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\spectrums\");
- }
- int bars = 50;
- int st = 0;
- int end = 64529;
- Spectrum sp = new Spectrum(Directory.GetCurrentDirectory() + @"eggs.mp3", bars, st, end, 150);
- List<Spectrum.SpectrumData> fft = sp.GenerateData();
- Console.ReadKey();
- for (int i = 0; i < bars; i++)
- {
- List<object[]> asdf = new List<object[]>();
- // Going to edit this to ITG-friendly XML Cod
- for (int j = 0; j < fft.Count - 2; j++)
- {
- double value1 = fft[j].Frecuencies[i];
- double value2 = fft[j + 1].Frecuencies[i];
- /*values.Add(new Event {
- V = new ScaleVec { Start = fft[j].StartTime, End = fft[j].EndTime, Vxi = 0.5, Vyi = value1, Vxf = 0.5, Vyf = value2 }
- } );*/
- object[] thing = {fft[j].StartTime - fft[j].EndTime,value2};
- asdf.Add(thing);
- }
- CreateBar(asdf,i);
- asdf.Clear();
- Write("Wrote Bar " + i);
- }
- Write("");
- Write("[==]");
- Write("");
- Write("Completed! Press any key to exit.");
- Console.ReadKey();
- }
- public static void CreateBar(List<object[]> things, int num) {
- List<string> info = new List<string>() {"<ActorFrame><children>","<Layer","Type=\"Quad\"","InitCommand=\"hidden,1\"","OnCommand=\"%function(self)"};
- #region Cod
- // Bar[i]Info = {
- info.Add("Bar"+num+"Info = {");
- // Array Info
- foreach(object[] o in things) {
- int off = int.Parse(o[1].ToString());
- int val = int.Parse(o[2].ToString());
- info.Add("{"+off+","+val+"},");
- }
- // }
- info.Add("}");
- #endregion
- info.Add("/>");
- info.Add("</children></ActorFrame");
- if (!File.Exists(Directory.GetCurrentDirectory() + @"\spectrums\bar"+num+".xml")) {
- File.Create(Directory.GetCurrentDirectory() + @"\spectrums\bar"+num+".xml");
- }
- using(StreamWriter sw = new StreamWriter(Directory.GetCurrentDirectory() + @"\bar"+num+".xml")) {
- foreach(string s in info) {
- sw.WriteLine(s);
- }
- }
- }
- public static void Write(string msg) {
- Console.WriteLine(msg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement