Beispiel #1
0
        List <AudioClip> LoadClipsFromDir(string soundsPath)
        {
            List <AudioClip> audioClips = new List <AudioClip>();

            string path = Directory.GetCurrentDirectory() + "\\" + soundsPath;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            List <string> list = Directory.GetFiles(path).ToList <string>();

            for (int i = list.Count - 1; i >= 0; i--)
            {
                if (list[i].Contains(".wav"))
                {
                    list[i] = Path.GetFileName(list[i]);
                }
                else
                {
                    list.RemoveAt(i);
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                string wavText = Path.GetFileNameWithoutExtension(list[j]);
                wavText = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(wavText);
                byte[] wav              = File.ReadAllBytes(soundsPath + list[j]);
                WAV    wav2             = new WAV(wav);
                bool   failedContructor = wav2.failedContructor;
                if (failedContructor)
                {
                    MelonLogger.LogError("Could not read " + list[j]);
                }
                else
                {
                    AudioClip audioClip = AudioClip.Create(wavText, wav2.SampleCount, 1, wav2.Frequency, false);
                    audioClip.SetData(wav2.LeftChannel, 0);
                    if (audioClip != null)
                    {
                        audioClips.Add(audioClip);
                        MelonLogger.Log("Added " + list[j]);
                    }
                    else
                    {
                        MelonLogger.LogError("Failed To Read " + list[j]);
                    }
                }
            }

            return(audioClips);
        }
Beispiel #2
0
 public WAV(byte[] wav)
 {
     try
     {
         this.ChannelCount = (int)wav[22];
         this.Frequency    = WAV.bytesToInt(wav, 24);
         int i = 12;
         while (wav[i] != 100 || wav[i + 1] != 97 || wav[i + 2] != 116 || wav[i + 3] != 97)
         {
             i += 4;
             int num = (int)wav[i] + (int)wav[i + 1] * 256 + (int)wav[i + 2] * 65536 + (int)wav[i + 3] * 16777216;
             i += 4 + num;
         }
         i += 8;
         this.SampleCount = (wav.Length - i) / 2;
         bool flag = this.ChannelCount == 2;
         if (flag)
         {
             this.SampleCount /= 2;
         }
         this.LeftChannel = new float[this.SampleCount];
         bool flag2 = this.ChannelCount == 2;
         if (flag2)
         {
             this.RightChannel = new float[this.SampleCount];
         }
         else
         {
             this.RightChannel = null;
         }
         int num2 = 0;
         while (i < wav.Length)
         {
             this.LeftChannel[num2] = WAV.bytesToFloat(wav[i], wav[i + 1]);
             i += 2;
             bool flag3 = this.ChannelCount == 2;
             if (flag3)
             {
                 this.RightChannel[num2] = WAV.bytesToFloat(wav[i], wav[i + 1]);
                 i += 2;
             }
             num2++;
         }
     }
     catch
     {
         this.failedContructor = true;
     }
 }
Beispiel #3
0
 public WAV(string filename) : this(WAV.GetBytes(filename))
 {
 }