Exemple #1
0
        public static void LoadWave(HiSample smpl)
        {
            //Debug.Log("-------------------- " + smpl.Name);
            string    path = WavePath + "/" + Path.GetFileNameWithoutExtension(smpl.Name);// + ".wav";
            AudioClip ac   = Resources.Load <AudioClip>(path);

            if (ac != null)
            {
                float[] data = new float[ac.samples * ac.channels];
                if (ac.GetData(data, 0))
                {
                    //Debug.Log(smpl.Name + " " + factor);
                    smpl.Data = data;
                    DicAudioWave.Add(smpl);
                    //MPTK_CountWaveLoaded++;
                }
            }
            //else Debug.LogWarning("Sample " + smpl.WaveFile + " not found");
        }
        private static void LoadWave()
        {
            try
            {
                float start = Time.realtimeSinceStartup;
                //Debug.Log(">>> Load Sample");
                //int count = 0;
                if (ImSFCurrent != null)
                {
                    foreach (HiSample smpl in ImSFCurrent.HiSf.Samples)
                    {
                        if (smpl.Name != null)
                        {
                            if (!DicAudioWave.Exist(smpl.Name))
                            {
                                //Debug.Log("-------------------- " + smpl.Name);
                                string    path = WavePath + "/" + Path.GetFileNameWithoutExtension(smpl.Name);// + ".wav";
                                AudioClip ac   = Resources.Load <AudioClip>(path);
                                if (ac != null)
                                {
                                    //Debug.Log("Wave load " + path);
                                    //count++;
                                    //if (count % 50 == 0)
                                    //{
                                    //    System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
                                    //    long total = GC.GetTotalMemory(true);
                                    //    GC.Collect();
                                    //    total = GC.GetTotalMemory(true);
                                    //}
                                    //GC.Collect();

                                    //if (count > 1000) break;
                                    //// For test ...
                                    //float[] data = new float[ac.samples * ac.channels];
                                    //if (!ac.GetData(data, 0))
                                    //    Debug.LogWarningFormat("LoadAudioClip - Clip {0} data not loaded", smpl.Name);
                                    //else
                                    //    Debug.LogFormat("{0} {1} {2}", smpl.Name, ac.samples, ac.channels);
                                    //// end for test
                                    //HiSample newSample = new HiSample();
                                    //newSample.Name = smpl.Name;
                                    //newSample.SampleRate = (uint)ac.frequency;// smpl.SampleRate;
                                    //newSample.OrigPitch = smpl.OrigPitch;
                                    //newSample.PitchAdj = smpl.PitchAdj;
                                    //newSample.SampleType = smpl.SampleType;
                                    //newSample.Start = 0;
                                    //newSample.End = smpl.End;

                                    //if (smpl.Name.Contains("Fd4"))
                                    //    Debug.Log("");
                                    float[] data = new float[ac.samples * ac.channels];
                                    if (ac.GetData(data, 0))
                                    {
                                        //Debug.Log(smpl.Name + " " + factor);

                                        smpl.Data = data;

                                        //newSample.LoopStart = (uint)(smpl.LoopStart * factor);
                                        //newSample.LoopEnd = (uint)(smpl.LoopEnd * factor);
                                        //if (newSample.LoopEnd >= newSample.Data.Length)
                                        //    newSample.LoopEnd = (uint)newSample.Data.Length - 1;

                                        //Debug.Log(" OrigPitch:" + newSample.OrigPitch);
                                        //Debug.Log(" SampleRate:" + newSample.SampleRate);
                                        //Debug.Log(" Length:" + newSample.Data.Length);
                                        //Debug.Log(" LoopStart:" + newSample.LoopStart);
                                        //Debug.Log(" LoopEnd:" + newSample.LoopEnd);

                                        DicAudioWave.Add(smpl);
                                        //MPTK_CountWaveLoaded++;
                                    }
                                }
                                //else Debug.LogWarning("Wave " + smpl.WaveFile + " not found");
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log("SoundFont not loaded ");
                }
            }
            catch (System.Exception ex)
            {
                MidiPlayerGlobal.ErrorDetail(ex);
            }
        }