private void BtnOpen_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                RestoreDirectory = true,
                Multiselect      = false,
                Filter           = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*",
                Title            = "Open Song File"
            };
            bool?result = openFileDialog.ShowDialog(this);

            if (result == true)
            {
                string fileName = openFileDialog.FileName;
                LblFileName.Content = fileName;
                AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.Load(fileName, false, false);
                unsafe
                {
                    var testResult = _analyzer.TestData(audio.RawData, audio.DataSize);
                    LsbPercents.ItemsSource = testResult.Select((pair) => string.Format("{0} - {1}%", pair.Key, pair.Value * 100));
                }

                audio.Dispose();
            }
        }
        public Dictionary <string, double>[] TestFile(string fileLocation, string fileName, string extension = ".wav")
        {
            string file = Path.Combine(fileLocation, fileName + extension);

            AudioEngineCSharp.AudioEngine.Audio a = AudioEngineCSharp.AudioEngine.Load(file, false, false);
            var context = _contextAnalyzer.TestData(a.Data);

            // var theme = _themeAnalyzer.TestData(a.Data);
            a.Dispose();
            return(new[] { context });
        }
        static void Main(string[] args)
        {
            string file = @"C:\Users\wsheng\Documents\Neumont\Q9\capstone\repo\unity\project\Assets\Audio\VN1.7.wav";

            AudioEngineCSharp.AudioEngine.Initialize();

            AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.LoadPreset(file);

            // ulong time = AudioEngineCSharp.AudioEngine.SecondsToBytes(audio, 1);
            AudioEngineCSharp.AudioEngine.Play(audio, 0, 1000);

            string command;

            ulong lastPos = 0;

            do
            {
                command = Console.ReadLine();
                command = command.ToLower();

                switch (command)
                {
                case "stop":
                    lastPos = audio.Pos + 1000;
                    AudioEngineCSharp.AudioEngine.Stop(audio, 1000);
                    break;

                case "play":

                    AudioEngineCSharp.AudioEngine.Play(audio, lastPos, 1000);
                    break;
                }
            } while (!command.Equals("exit"));

            AudioEngineCSharp.AudioEngine.Stop(audio, 0);

            Console.ReadKey();


            audio.Dispose();
            // AudioEngineCSharp.AudioEngine.Unload(audio._audio);
            // AudioEngineCSharp.AudioEngine.Unload(audio);

            AudioEngineCSharp.AudioEngine.Shutdown();
        }
        public void PassFiles(int iterations = 1, string extension = ".wav")
        {
            for (int i = 0; i < iterations; i++)
            {
                foreach (SongData data in _data)
                {
                    string file = Path.Combine(_fileLocation, data.Source, data.Name + extension);
                    // Console.WriteLine("Trying to load file...{0}", file);
                    AudioEngineCSharp.AudioEngine.Audio a = AudioEngineCSharp.AudioEngine.Load(file, false, false);
                    // load up the file

                    // _contextAnalyzer.AddData(a.Data, data.Context);
                    // _themeAnalyzer.AddData(a.Data, data.Theme);
                    a.Dispose();
                }
            }

            // _contextAnalyzer.TrainData();
            // _themeAnalyzer.TrainData();
        }
示例#5
0
 public void Dispose()
 {
     _audio.Dispose();
 }
        private void Worker_Work(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            MusicArg args = (MusicArg)e.Argument;

            Random r = new Random();

            if (args.Epoch <= 0)
            {
                double error = double.PositiveInfinity;
                double previous;
                do
                {
                    Shuffle(args.SongData, r);
                    previous = error;
                    error    = 0;
                    for (int j = 0; j < args.SongData.Count; j++)
                    {
                        SongData song = args.SongData[j];

                        string songFile = System.IO.Path.Combine(args.FilePath, song.Source, song.Name + ".wav");
                        //// Console.WriteLine("Trying to load file...{0}", file);
                        AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.Load(songFile, false, false);
                        //// load up the file


                        unsafe
                        {
                            // error += args.Analyzer.AddData(audio.RawData, audio.DataSize, args.IsContext ? song.Context : song.Theme, true);
                        }
                        //// _themeAnalyzer.AddData(a.Data, data.Theme);
                        audio.Dispose();

                        // float percent = ((float)(i * args.SongData.Count + (j + 1))) / totalNum;
                        // int progress = (int)(Math.Round(percent * 100));
                        Debug.WriteLine(string.Format("Finished ({0}) {1}", song.Source, song.Name));
                        // bw.ReportProgress(progress);
                    }
                    Debug.WriteLine(string.Format("Error: {0}, Previous: {1}", error, previous));
                    // } while (Math.Abs(previous - error) >= 1e-10 * previous);
                } while (Math.Abs(previous - error) >= 1e-4);
            }
            else
            {
                int totalNum = args.SongData.Count * args.Epoch;

                // prepreprocess
                for (int i = 0; i < args.SongData.Count; i++)
                {
                    SongData song     = args.SongData[i];
                    string   songFile = System.IO.Path.Combine(args.FilePath, song.Source, song.Name + ".wav");
                    AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.Load(songFile, false, false);

                    unsafe
                    {
                        args.Analyzer.PreprocessAddData(audio.RawData, audio.DataSize);
                    }
                    audio.Dispose();
                }

                args.Analyzer.PreDeviation();

                for (int i = 0; i < args.SongData.Count; i++)
                {
                    SongData song     = args.SongData[i];
                    string   songFile = System.IO.Path.Combine(args.FilePath, song.Source, song.Name + ".wav");
                    AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.Load(songFile, false, false);

                    unsafe
                    {
                        args.Analyzer.ProcessDeviation(audio.RawData, audio.DataSize);
                    }
                    audio.Dispose();
                }

                args.Analyzer.PreProcessData();

                for (int i = 0; i < args.Epoch; i++)
                {
                    Shuffle(args.SongData, r);

                    for (int j = 0; j < args.SongData.Count; j++)
                    {
                        SongData song = args.SongData[j];

                        string songFile = System.IO.Path.Combine(args.FilePath, song.Source, song.Name + ".wav");
                        //// Console.WriteLine("Trying to load file...{0}", file);
                        AudioEngineCSharp.AudioEngine.Audio audio = AudioEngineCSharp.AudioEngine.Load(songFile, false, false);
                        //// load up the file


                        unsafe
                        {
                            args.Analyzer.ProcessData(audio.RawData, audio.DataSize, args.IsContext ? song.Context : song.Theme);
                        }
                        //// _themeAnalyzer.AddData(a.Data, data.Theme);
                        audio.Dispose();

                        float percent  = ((float)(i * args.SongData.Count + (j + 1))) / totalNum;
                        int   progress = (int)(Math.Round(percent * 100));
                        Debug.WriteLine(string.Format("Percent: {0}, Finished ({1}) {2}", percent, song.Source, song.Name));
                        bw.ReportProgress(progress);
                    }
                }
            }
        }