예제 #1
0
        public void DisplayFor(AudioSourceMgr mgr)
        {
            if (!Enabled)
            {
                return;
            }

            lastPlayed     = mgr.audiosource;
            lastPlayedName = mgr.FileName;
            currentAudioTracker.Stop();

            string soundName = Path.GetFileNameWithoutExtension(mgr.FileName);

            subtitleText.text = AUDIOCLIP_PREFIX + soundName;

            if (subtitleText.text == soundName)
            {
                lastWasTranslated = false;
                if (!showUntranslatedText)
                {
                    subtitleText.text = string.Empty;
                }

                Logger.DumpVoice(soundName, mgr.audiosource.clip, CurrentLevel);
            }
            else
            {
                lastWasTranslated = true;
            }

            TrackAudio(mgr.audiosource);
        }
 [HarmonyPrefix]                                    // There are different patch types. Prefix code runs before original code
 public static bool LoadPlayPrefix(AudioSourceMgr __instance, ref string f_strFileName)
 {                                                  // public void LoadPlay(string f_strFileName, float f_fFadeTime, bool f_bStreaming, bool f_bLoop = false)
     Log("LoadPlayPrefix");
     Log("f_strFileName:" + f_strFileName);
     // - returns a boolean that controls if original is executed (true) or not (false)
     return(true);
 }
예제 #3
0
        /// <summary>
        /// 楽曲読込
        /// </summary>
        public static bool LoadAndPlayAudioClip(string fileAndPath, bool loop = false)
        {
            Stop();

            var ext = Path.GetExtension(fileAndPath);

            if (string.IsNullOrEmpty(fileAndPath) || !File.Exists(fileAndPath) ||
                (ext != ".ogg" && ext != ".wav"))
            {
                if (!string.IsNullOrEmpty(fileAndPath))
                {
                    Debug.Log(string.Format("{0}または{1}ファイルを指定してください。{2}", ".ogg", ".wav", fileAndPath));
                }
                return(false);
            }

            isLoaded = false;
            try
            {
                using (var www = new WWW(@"file:///" + fileAndPath))
                {
                    var timer = 0;
                    while (!www.isDone)
                    {
                        Thread.Sleep(100);
                        timer += 100;
                        Debug.Log("LoadAndPlayAudioClip " + timer);
                        if (10000 < timer)
                        {
                            Debug.LogWarning("音声読込タイムアウトのため処理を中止します。");
                            return(false);
                        }
                    }
                    var audioClip = www.GetAudioClip();
                    if (audioClip.loadState == AudioDataLoadState.Loaded)
                    {
                        if (audioMgr == null)
                        {
                            AudioSourceMgr[] componentsInChildren = GameMain.Instance.MainCamera.gameObject.GetComponentsInChildren <AudioSourceMgr>();
                            audioMgr = componentsInChildren.FirstOrDefault(a => a.SoundType == AudioSourceMgr.Type.Bgm);
                        }
                        if (audioMgr != null)
                        {
                            audioMgr.audiosource.clip = audioClip;
                            audioMgr.audiosource.loop = loop;
                            danceVolumeLegacy         = GameMain.Instance.SoundMgr.GetVolumeDance();
                            SetVolume(danceVolumeLegacy);
                            Debug.Log("GetLength " + audioMgr.audiosource.clip.length);
                            isLoaded = true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning(e.ToString());
            }
            return(isLoaded);
        }
        public static void OnPlaySound(AudioSourceMgr mgr)
        {
            var args = new SoundEventArgs {
                AudioSourceMgr = mgr
            };

            PlaySound?.Invoke(null, args);
        }
예제 #5
0
        /// <summary>
        /// AudioSourceMgr.Play および AudioSourceMgr.PlayOneShot の処理終了後に呼ばれるコールバック。
        /// ピッチ変更を行う
        /// </summary>
        static void SetAudioPitch(AudioSourceMgr audioSourceMgr)
        {
            Maid maid = PluginHelper.GetMaid(audioSourceMgr);

            if (maid == null || audioSourceMgr.audiosource == null || !audioSourceMgr.audiosource.isPlaying)
            {
                return;
            }
            float f = ExSaveData.GetFloat(maid, PluginName, "PITCH", 0f);

            audioSourceMgr.audiosource.pitch = 1f + f;
        }
        void AudioSourceMgr_LoadFromWf_Callback(AudioSourceMgr audioSourceMgr, string f_strFileName, bool stream)
        {
            // audioSourceMgr.aryAmpRateを無理やり書き換えて音量制御を行う
            if (audioSourceMgr.SoundType == AudioSourceMgr.Type.Voice)
            {
                float s = 2f;
#if DEBUG
                Console.WriteLine("AudioSourceMgr.LoadFromWf(f_strFileName={0}, stream={1})", f_strFileName, stream);
#endif
                float[] aryAmpRate = Helper.GetInstanceField(typeof(AudioSourceMgr), audioSourceMgr, "aryAmpRate") as float[];
				VoiceNormalizationTable.Value val;
                var dict = VoiceNormalizationTable.Dict;
                string fn = Path.GetFileNameWithoutExtension(f_strFileName);
                if (dict.TryGetValue(fn, out val))
                {
                    s *= 32768f / (float)val.peak;
                    // s *= 0.5f / val.rms;
                }
                aryAmpRate[(int)AudioSourceMgr.Type.Voice] = s;
            }
        }
예제 #7
0
        void AudioSourceMgr_LoadFromWf_Callback(AudioSourceMgr audioSourceMgr, string f_strFileName, bool stream)
        {
            // audioSourceMgr.aryAmpRateを無理やり書き換えて音量制御を行う
            if (audioSourceMgr.SoundType == AudioSourceMgr.Type.Voice)
            {
                float s = 2f;
#if DEBUG
                Console.WriteLine("AudioSourceMgr.LoadFromWf(f_strFileName={0}, stream={1})", f_strFileName, stream);
#endif
                float[] aryAmpRate = Helper.GetInstanceField(typeof(AudioSourceMgr), audioSourceMgr, "aryAmpRate") as float[];
                VoiceNormalizationTable.Value val;
                var    dict = VoiceNormalizationTable.Dict;
                string fn   = Path.GetFileNameWithoutExtension(f_strFileName);
                if (dict.TryGetValue(fn, out val))
                {
                    s *= 32768f / (float)val.peak;
                    // s *= 0.5f / val.rms;
                }
                aryAmpRate[(int)AudioSourceMgr.Type.Voice] = s;
            }
        }
예제 #8
0
    // AudioSourceMgrを手がかりに、Maidを得る
    public static Maid GetMaid(AudioSourceMgr audioSourceMgr)
    {
        if (audioSourceMgr == null)
        {
            return(null);
        }
        CharacterMgr cm = GameMain.Instance.CharacterMgr;

        for (int i = 0, n = cm.GetStockMaidCount(); i < n; i++)
        {
            Maid maid = cm.GetStockMaid(i);
            if (maid.AudioMan == null)
            {
                continue;
            }
            if (object.ReferenceEquals(maid.AudioMan, audioSourceMgr))
            {
                return(maid);
            }
        }
        return(null);
    }
 void AudioSourceMgr_LoadFromWf_Callback(AudioSourceMgr audioSourceMgr, string f_strFileName)
 {
     // audioSourceMgr.aryAmpRateを無理やり書き換えて音量制御を行う
     if (audioSourceMgr.SoundType == AudioSourceMgr.Type.Voice)
     {
         float s = 2f;
     #if DEBUG
         Console.WriteLine("AudioSourceMgr.LoadFromWf(f_strFileName={0})", f_strFileName);
     #endif
         float[] aryAmpRate = Helper.GetInstanceField(typeof(AudioSourceMgr), audioSourceMgr, "aryAmpRate") as float[];
         int v;
         var dict = VoiceNormalizationTable.Dict;
         string fn = Path.GetFileNameWithoutExtension(f_strFileName);
         if (dict.TryGetValue(fn, out v))
         {
             s *= 32768.0f / (float)v;
         }
     #if DEBUG
         Console.WriteLine(" --> s = {0}", s);
     #endif
         aryAmpRate[(int)AudioSourceMgr.Type.Voice] = s;
     }
 }
        void AudioSourceMgr_LoadFromWf_Callback(AudioSourceMgr audioSourceMgr, string f_strFileName)
        {
            // audioSourceMgr.aryAmpRateを無理やり書き換えて音量制御を行う
            if (audioSourceMgr.SoundType == AudioSourceMgr.Type.Voice)
            {
                float s = 2f;
#if DEBUG
                Console.WriteLine("AudioSourceMgr.LoadFromWf(f_strFileName={0})", f_strFileName);
#endif
                float[] aryAmpRate = Helper.GetInstanceField(typeof(AudioSourceMgr), audioSourceMgr, "aryAmpRate") as float[];
                int     v;
                var     dict = VoiceNormalizationTable.Dict;
                string  fn   = Path.GetFileNameWithoutExtension(f_strFileName);
                if (dict.TryGetValue(fn, out v))
                {
                    s *= 32768.0f / (float)v;
                }
#if DEBUG
                Console.WriteLine(" --> s = {0}", s);
#endif
                aryAmpRate[(int)AudioSourceMgr.Type.Voice] = s;
            }
        }
 /// <summary>
 /// AudioSourceMgr.Play および AudioSourceMgr.PlayOneShot の処理終了後に呼ばれるコールバック。
 /// ピッチ変更を行う
 /// </summary>
 static void SetAudioPitch(AudioSourceMgr audioSourceMgr)
 {
     Maid maid = PluginHelper.GetMaid(audioSourceMgr);
     if (maid == null || audioSourceMgr.audiosource == null || !audioSourceMgr.audiosource.isPlaying)
     {
         return;
     }
     float f = ExSaveData.GetFloat(maid, PluginName, "PITCH", 0f);
     audioSourceMgr.audiosource.pitch = 1f + f;
 }
 public static void LoadPlayPostfix2(AudioSourceMgr __instance, string f_strFileName)
 {
     MyLog.LogMessage("LoadPlayPostfix2:" + f_strFileName);
 }
예제 #13
0
 public static void AudioSourceMgr_Play(AudioSourceMgr manager)
 {
     PlaySound?.Invoke(manager, null);
 }
예제 #14
0
 // PreCall
 // 사운드 파일명 출력용
 public static void LoadPlayPreCall(AudioSourceMgr that, string f_strFileName, float f_fFadeTime, bool f_bStreaming, bool f_bLoop = false) // 후킹시 원본 클래스도 같이 받도록 돼있음
 //     public void LoadPlay(                     string f_strFileName, float f_fFadeTime, bool f_bStreaming, bool f_bLoop = false) // 원본
 {
     Lilly.Log(name + ".LoadPlay.LoadPlayPreCall:" + f_strFileName);
 }