public override string GetInfoString()
        {
            AudioClip target       = this.target as AudioClip;
            int       channelCount = AudioUtil.GetChannelCount(target);
            string    str1;

            switch (channelCount)
            {
            case 1:
                str1 = "Mono";
                break;

            case 2:
                str1 = "Stereo";
                break;

            default:
                str1 = (channelCount - 1).ToString() + ".1";
                break;
            }
            string str2 = str1;
            AudioCompressionFormat compressionFormat1 = AudioUtil.GetTargetPlatformSoundCompressionFormat(target);
            AudioCompressionFormat compressionFormat2 = AudioUtil.GetSoundCompressionFormat(target);
            string str3 = compressionFormat1.ToString();

            if (compressionFormat1 != compressionFormat2)
            {
                str3 = str3 + " (" + compressionFormat2.ToString() + " in editor)";
            }
            string   str4     = str3 + ", " + (object)AudioUtil.GetFrequency(target) + " Hz, " + str2 + ", ";
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)AudioUtil.GetDuration(target));

            return((int)(uint)AudioUtil.GetDuration(target) != -1 ? str4 + string.Format("{0:00}:{1:00}.{2:000}", (object)timeSpan.Minutes, (object)timeSpan.Seconds, (object)timeSpan.Milliseconds) : str4 + "Unlimited");
        }
Exemplo n.º 2
0
 private void CopyCompFormatToSelected(AudioCompressionFormat _bulkCompressionFormat)
 {
     foreach (var aClip in SelectedClips)
     {
         aClip.CompressionFormat = _bulkCompressionFormat;
     }
 }
Exemplo n.º 3
0
        public override string GetInfoString()
        {
            AudioClip target       = this.target as AudioClip;
            int       channelCount = AudioUtil.GetChannelCount(target);
            string    str          = (channelCount != 1) ? ((channelCount != 2) ? (((channelCount - 1)).ToString() + ".1") : "Stereo") : "Mono";
            AudioCompressionFormat targetPlatformSoundCompressionFormat = AudioUtil.GetTargetPlatformSoundCompressionFormat(target);
            AudioCompressionFormat soundCompressionFormat = AudioUtil.GetSoundCompressionFormat(target);
            string str2 = targetPlatformSoundCompressionFormat.ToString();

            if (targetPlatformSoundCompressionFormat != soundCompressionFormat)
            {
                str2 = str2 + " (" + soundCompressionFormat.ToString() + " in editor)";
            }
            string str3 = str2;

            object[] objArray1 = new object[] { str3, ", ", AudioUtil.GetFrequency(target), " Hz, ", str, ", " };
            str2 = string.Concat(objArray1);
            TimeSpan span = new TimeSpan(0, 0, 0, 0, (int)AudioUtil.GetDuration(target));

            if (((uint)AudioUtil.GetDuration(target)) == uint.MaxValue)
            {
                return(str2 + "Unlimited");
            }
            return(str2 + string.Format("{0:00}:{1:00}.{2:000}", span.Minutes, span.Seconds, span.Milliseconds));
        }
Exemplo n.º 4
0
        public AudioInformation(string fullPath, string name, bool forceMono, bool loadInBG, bool preload, AudioClipLoadType loadType, AudioCompressionFormat compressionFormat, float quality, AudioSampleRateSetting sampleRateSetting, int sampleRateOverride)
        {
            OrigForceMono = forceMono;
            ForceMono     = forceMono;

            OrigLoadBG = loadInBG;
            LoadBG     = loadInBG;

            OrigPreload = preload;
            Preload     = preload;

            OrigLoadType = loadType;
            LoadType     = loadType;

            OrigCompressionFormat = compressionFormat;
            CompressionFormat     = compressionFormat;

            OrigSampleRateSetting = sampleRateSetting;
            SampleRateSetting     = sampleRateSetting;

            OrigQuality = quality;
            Quality     = quality;

            OrigSampleRateOverride = sampleRateOverride;
            SampleRateOverride     = sampleRateOverride;

            FullPath    = fullPath;
            Name        = name;
            IsSelected  = false;
            HasChanged  = false;
            LastUpdated = DateTime.MinValue.Ticks;
        }
Exemplo n.º 5
0
        public bool CurrentPlatformHasAutoTranslatedCompression()
        {
            BuildTargetGroup            buildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
            IEnumerator <AudioImporter> enumerator       = this.GetAllAudioImporterTargets().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    AudioImporter          current           = enumerator.Current;
                    AudioCompressionFormat compressionFormat = current.defaultSampleSettings.compressionFormat;
                    if (!current.Internal_ContainsSampleSettingsOverride(buildTargetGroup))
                    {
                        AudioCompressionFormat format2 = current.Internal_GetOverrideSampleSettings(buildTargetGroup).compressionFormat;
                        if (compressionFormat != format2)
                        {
                            return(true);
                        }
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            return(false);
        }
Exemplo n.º 6
0
        public AudioClip(ObjectReader reader) : base(reader)
        {
            if (version[0] < 5)
            {
                m_Format      = reader.ReadInt32();
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream(4);

                if (version[0] >= 4 || (version[0] == 3 && version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    if (reader.byteSize + reader.byteStart - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadInt32();
                        m_Source = assetsFile.fullName + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32();
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream(4);
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream(4);
                m_3D = m_Legacy3D;

                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            ResourceReader resourceReader;

            if (!string.IsNullOrEmpty(m_Source))
            {
                resourceReader = new ResourceReader(m_Source, assetsFile, m_Offset, (int)m_Size);
            }
            else
            {
                resourceReader = new ResourceReader(reader, reader.BaseStream.Position, (int)m_Size);
            }
            m_AudioData = new Lazy <byte[]>(resourceReader.GetData);
        }
Exemplo n.º 7
0
        public override string GetInfoString()
        {
            AudioClip clip = target as AudioClip;
            int       c    = AudioUtil.GetChannelCount(clip);
            string    ch   = c == 1 ? "Mono" : c == 2 ? "Stereo" : (c - 1).ToString() + ".1";
            AudioCompressionFormat platformFormat = AudioUtil.GetTargetPlatformSoundCompressionFormat(clip);
            AudioCompressionFormat editorFormat   = AudioUtil.GetSoundCompressionFormat(clip);
            string s = platformFormat.ToString();

            if (platformFormat != editorFormat)
            {
                s += " (" + editorFormat.ToString() + " in editor" + ")";
            }
            s += ", " + AudioUtil.GetFrequency(clip) + " Hz, " + ch + ", ";

            System.TimeSpan ts = new System.TimeSpan(0, 0, 0, 0, (int)AudioUtil.GetDuration(clip));

            if ((uint)AudioUtil.GetDuration(clip) == 0xffffffff)
            {
                s += "Unlimited";
            }
            else
            {
                s += string.Format("{0:00}:{1:00}.{2:000}", ts.Minutes, ts.Seconds, ts.Milliseconds);
            }

            return(s);
        }
Exemplo n.º 8
0
        public override void ApplyDefaults()
        {
            base.ApplyDefaults();

            this.Suffix = ".ogg";

            this.LoadType          = AudioClipLoadType.Streaming;
            this.CompressionFormat = AudioCompressionFormat.Vorbis;
            this.SampleRate        = AudioSampleRateSetting.PreserveSampleRate;
        }
Exemplo n.º 9
0
 private bool CompressionFormatHasQuality(AudioCompressionFormat format)
 {
     switch (format)
     {
     case AudioCompressionFormat.Vorbis:
     case AudioCompressionFormat.MP3:
     case AudioCompressionFormat.XMA:
     case AudioCompressionFormat.AAC:
         return(true);
     }
     return(false);
 }
        public bool IsHardwareSound(AudioCompressionFormat format)
        {
            switch (format)
            {
            case AudioCompressionFormat.HEVAG:
            case AudioCompressionFormat.VAG:
            case AudioCompressionFormat.XMA:
            case AudioCompressionFormat.GCADPCM:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 11
0
        public override void ApplyDefaults()
        {
            base.ApplyDefaults();

            this.SuffixFilter = ".ogg";

            this.forceToMono       = false;
            this.normalize         = true;
            this.loadInBackground  = true;
            this.ambisonic         = false;
            this.loadType          = AudioClipLoadType.Streaming;
            this.preloadAudioData  = true;
            this.compressionFormat = AudioCompressionFormat.Vorbis;
            this.quality           = 100;
            this.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate;
        }
Exemplo n.º 12
0
        public ItemAudioClip(string path, UnityEngine.Object obj) : base(path, obj)
        {
            AudioClip audioClip = (AudioClip)obj;

            Frequency = audioClip.frequency;
            Channels  = audioClip.channels;
            Length    = audioClip.length;
            Samples   = audioClip.samples;

            AudioImporter importer = (AudioImporter)AssetImporter.GetAtPath(path);
            string        platform = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget).ToString();
            AudioImporterSampleSettings settings = importer.GetOverrideSampleSettings(platform);

            CompressionFormat  = settings.compressionFormat;
            CompressionQuality = settings.quality;
        }
Exemplo n.º 13
0
 public AudioViewerData(string mode, AudioInfo audioInfo)
 {
     _mode                            = (AudioViewerMode)Enum.Parse(typeof(AudioViewerMode), mode);
     ForceToMono                      = audioInfo.ForceToMono;
     LoadInBackground                 = audioInfo.LoadInBackground;
     Ambisonic                        = audioInfo.Ambisonic;
     StandAloneAudioClipLoadType      = audioInfo.StandAloneAudioClipLoadType;
     AndroidAudioClipLoadType         = audioInfo.AndroidAudioClipLoadType;
     iOSAudioClipLoadType             = audioInfo.iOSAudioClipLoadType;
     StandAloneAudioCompressionFormat = audioInfo.StandAloneAudioCompressionFormat;
     AndroidAudioCompressionFormat    = audioInfo.AndroidAudioCompressionFormat;
     iOSAudioCompressionFormat        = audioInfo.iOSAudioCompressionFormat;
     OriginSize                       = audioInfo.OriginSize;
     CompressedSize                   = audioInfo.CompressedSize;
     All = "All";
 }
Exemplo n.º 14
0
        public override void DrawRuleGUI()
        {
            base.DrawRuleGUI();
            GUILayout.Space(10);
            EditorGUILayout.LabelField("Audio Import Settings", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            forceToMono = EditorGUILayout.Toggle(AssetImportStyles.Audio.ForceToMono, forceToMono);
            EditorGUI.indentLevel++;
            EditorGUI.BeginDisabledGroup(forceToMono);
            normalize = EditorGUILayout.Toggle(AssetImportStyles.Audio.Normalize, normalize);
            EditorGUI.EndDisabledGroup();
            EditorGUI.indentLevel--;
            loadInBackground = EditorGUILayout.Toggle(AssetImportStyles.Audio.LoadBackground, loadInBackground);
            ambisonic        = EditorGUILayout.Toggle(AssetImportStyles.Audio.Ambisonic, ambisonic);

            GUILayout.Space(6);
            EditorGUILayout.LabelField("Default Import Settings", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            loadType = (AudioClipLoadType)EditorGUILayout.EnumPopup(AssetImportStyles.Audio.LoadType, loadType);

            EditorGUI.BeginDisabledGroup(loadType == AudioClipLoadType.Streaming ? true : false);
            preloadAudioData = EditorGUILayout.Toggle(AssetImportStyles.Audio.PreloadAudioData, preloadAudioData);
            EditorGUI.EndDisabledGroup();

            if (loadType == AudioClipLoadType.Streaming)
            {
                preloadAudioData = false;
            }

            int compressionFormatIndex = Math.Max(Array.FindIndex(AssetImportStyles.Audio.CompressionEnumOpts, opt => opt.Equals(compressionFormat)), 0);

            compressionFormatIndex = EditorGUILayout.Popup(AssetImportStyles.Audio.CompressionFormat, compressionFormatIndex, AssetImportStyles.Audio.CompressionFormatOpts);
            compressionFormat      = AssetImportStyles.Audio.CompressionEnumOpts[compressionFormatIndex];
            EditorGUI.BeginDisabledGroup(compressionFormat != AudioCompressionFormat.Vorbis ? true : false);
            quality = EditorGUILayout.IntSlider(AssetImportStyles.Audio.Quality, quality, 1, 100);
            EditorGUI.EndDisabledGroup();

            sampleRateSetting = (AudioSampleRateSetting)EditorGUILayout.EnumPopup(AssetImportStyles.Audio.SampleRateSetting, sampleRateSetting);
            if (sampleRateSetting == AudioSampleRateSetting.OverrideSampleRate)
            {
                sampleRate = (SampleRates)EditorGUILayout.EnumPopup(AssetImportStyles.Audio.SampleRate, sampleRate);
            }
        }
 // Apply settings Method which searches and adds all audio clips in an array, and for each clip, adds the settings, overrides it for the selected platform
 // and imports the newly applied asset again, therefore applying all the settings properly.
 static void ApplySettings(uint sampleRate, AudioCompressionFormat format, AudioClipLoadType loadType, string platform)
 {
     Object[] audioclips = GetSelectedAudioclips();
     Selection.objects = new Object[0];
     foreach (AudioClip audioclip in audioclips)
     {
         string        path                   = AssetDatabase.GetAssetPath(audioclip);
         AudioImporter audioImporter          = AssetImporter.GetAtPath(path) as AudioImporter;
         AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings;
         settings.compressionFormat  = format;
         settings.sampleRateSetting  = AudioSampleRateSetting.OverrideSampleRate;
         settings.sampleRateOverride = sampleRate;
         settings.loadType           = loadType;
         audioImporter.SetOverrideSampleSettings(platform, settings);
         AssetDatabase.ImportAsset(path);
     }
 }
Exemplo n.º 16
0
        public bool CurrentPlatformHasAutoTranslatedCompression()
        {
            BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);

            foreach (AudioImporter importer in this.GetAllAudioImporterTargets())
            {
                AudioCompressionFormat compressionFormat = importer.defaultSampleSettings.compressionFormat;
                if (!importer.Internal_ContainsSampleSettingsOverride(buildTargetGroup))
                {
                    AudioCompressionFormat format2 = importer.Internal_GetOverrideSampleSettings(buildTargetGroup).compressionFormat;
                    if (compressionFormat != format2)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 17
0
        public override void DrawInnerGUI()
        {
            DrawFilterGUI();

            GUILayout.Space(6);
            EditorGUILayout.LabelField("Audio", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            m_forceToMono      = EditorGUILayout.Toggle("Force To Mono", m_forceToMono);
            m_loadInBackground = EditorGUILayout.Toggle("Load In Background", m_loadInBackground);

            GUILayout.Space(6);
            EditorGUILayout.LabelField("Default Import Settings", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            m_AudioClipLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("Load Type", m_AudioClipLoadType);

            EditorGUI.BeginDisabledGroup(m_AudioClipLoadType == AudioClipLoadType.Streaming ? true : false);
            m_preloadAudioData = EditorGUILayout.Toggle("Preload Audio Data", m_preloadAudioData);
            EditorGUI.EndDisabledGroup();

            if (m_AudioClipLoadType == AudioClipLoadType.Streaming)
            {
                m_preloadAudioData = false;
            }

            m_audioCompressionFormat = (AudioCompressionFormat)EditorGUILayout.EnumPopup("Compression Format", m_audioCompressionFormat);
            m_audioQuality           = EditorGUILayout.IntSlider("Quality", m_audioQuality, 1, 100);
            m_sampleRateSetting      = (AudioSampleRateSetting)EditorGUILayout.EnumPopup("Sample Rate Setting", m_sampleRateSetting);

            if (m_sampleRateSetting == AudioSampleRateSetting.OverrideSampleRate)
            {
                m_sampleRateOverride = (SampleOverrideValues)EditorGUILayout.EnumPopup("Sample Rate Setting", m_sampleRateOverride);
            }
        }
        public bool CurrentPlatformHasAutoTranslatedCompression()
        {
            BuildTargetGroup targetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);

            foreach (AudioImporter importer in GetAllAudioImporterTargets())
            {
                AudioCompressionFormat defaultCompressionFormat = importer.defaultSampleSettings.compressionFormat;
                // Because we only want to query if the importer does not have an override.
                if (!importer.Internal_ContainsSampleSettingsOverride(targetGroup))
                {
                    AudioImporterSampleSettings overrideSettings          = importer.Internal_GetOverrideSampleSettings(targetGroup);
                    AudioCompressionFormat      overrideCompressionFormat = overrideSettings.compressionFormat;

                    // If we dont have an override, but the translated compression format is different,
                    // this means we have audio translate happening.
                    if (defaultCompressionFormat != overrideCompressionFormat)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 19
0
        public override string GetInfoString()
        {
            AudioClip clip         = base.target as AudioClip;
            int       channelCount = AudioUtil.GetChannelCount(clip);
            string    text         = (channelCount != 1) ? ((channelCount != 2) ? ((channelCount - 1).ToString() + ".1") : "Stereo") : "Mono";
            AudioCompressionFormat targetPlatformSoundCompressionFormat = AudioUtil.GetTargetPlatformSoundCompressionFormat(clip);
            AudioCompressionFormat soundCompressionFormat = AudioUtil.GetSoundCompressionFormat(clip);
            string text2 = targetPlatformSoundCompressionFormat.ToString();

            if (targetPlatformSoundCompressionFormat != soundCompressionFormat)
            {
                text2 = text2 + " (" + soundCompressionFormat.ToString() + " in editor)";
            }
            string text3 = text2;

            text2 = string.Concat(new object[]
            {
                text3,
                ", ",
                AudioUtil.GetFrequency(clip),
                " Hz, ",
                text,
                ", "
            });
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)AudioUtil.GetDuration(clip));

            if ((uint)AudioUtil.GetDuration(clip) == 4294967295u)
            {
                text2 += "Unlimited";
            }
            else
            {
                text2 += string.Format("{0:00}:{1:00}.{2:000}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);
            }
            return(text2);
        }
Exemplo n.º 20
0
        private void OnGUI()
        {
            style.normal.textColor = Color.red;
            GUILayout.Label("建议 小于200k : " + AudioClipLoadType.DecompressOnLoad + " 大于200k小于1M : " + AudioClipLoadType.CompressedInMemory + " 大于1M : " + AudioClipLoadType.Streaming, style);
            style.normal.textColor = Color.black;
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Path:");
                currenAudioClipImportData.AssetPath = EditorGUILayout.TextField(currenAudioClipImportData.AssetPath);
                EditorGUILayout.LabelField("NameFilter:", GUILayout.MinWidth(200));
                currenAudioClipImportData.FileFilter = EditorGUILayout.TextField(currenAudioClipImportData.FileFilter);
                if (GUILayout.Button("Save", GUILayout.MinWidth(100)))
                {
                    SetSelectIndexDataInfo();
                }
                if (GUILayout.Button("Delete", GUILayout.MinWidth(100)))
                {
                    AudioClipImportManager.ImportRule.Delete(currentSelectIndex);
                }
                if (GUILayout.Button("New Data", GUILayout.MinWidth(100)))
                {
                    if (string.IsNullOrEmpty(currenAudioClipImportData.AssetPath) ||
                        string.IsNullOrEmpty(currenAudioClipImportData.FileFilter))
                    {
                        return;
                    }
                    AudioClipImportManager.AudioClipImportRule.AudioClipImportData data = GetNextAudioClipImportData();
                    data.AssetPath  = currenAudioClipImportData.AssetPath;
                    data.FileFilter = currenAudioClipImportData.FileFilter;
                    AudioClipImportManager.ImportRule.Add(data);
                    currenAudioClipImportData = data;
                    currentSelectIndex        = data.Index;
                    GetSelectIndexDataInfo(data);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                androidClipType =
                    (AudioCompressionFormat)EditorGUILayout.EnumPopup("Android Compression类型", androidClipType);
                androidLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("Android Load类型", androidLoadType);
                SetAndroidFormatInfo();
                iPhoneClipType =
                    (AudioCompressionFormat)EditorGUILayout.EnumPopup("iPhone Compression类型", iPhoneClipType);
                iPhoneLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("iPhone Load类型", iPhoneLoadType);
                SetiPhoneFormatInfo();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                currenAudioClipImportData.IsForceToMono =
                    EditorGUILayout.ToggleLeft("是否开启ForceToMono", currenAudioClipImportData.IsForceToMono);
                currenAudioClipImportData.IsLoadInBackground =
                    EditorGUILayout.ToggleLeft("是否开启LoadInBackground", currenAudioClipImportData.IsLoadInBackground);
                currenAudioClipImportData.IsAmbisonic =
                    EditorGUILayout.ToggleLeft("是否开启Ambisonic", currenAudioClipImportData.IsAmbisonic);
                currenAudioClipImportData.IsPreloadAudioClip =
                    EditorGUILayout.ToggleLeft("是否开启PreloadAudioClip", currenAudioClipImportData.IsPreloadAudioClip);
                currenAudioClipImportData.Index =
                    EditorGUILayout.IntField("Rule Index", currenAudioClipImportData.Index);
                currenAudioClipImportData.Quality =
                    EditorGUILayout.IntField("Quality", currenAudioClipImportData.Quality);
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(25);
            int height = (AudioClipImportManager.ImportRule.AudioClipImportDatas.Count + 1) * 20;

            AudioClipImportManager.AudioClipImportRule.AudioClipImportData rule =
                AudioClipImportManager.ImportRule.GetRule(currentSelectIndex);
            string[] guids = null;
            if (null != rule)
            {
                guids   = AssetDatabase.FindAssets("t:AudioClip", new string[] { rule.AssetPath });
                height += (guids.Length + 1) * 20;
            }

            scrollPosition = GUI.BeginScrollView(new Rect(0, 30, position.width, position.height - 30), scrollPosition,
                                                 new Rect(0, 0, 1250, height));
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label("AssetPath", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("FileFilter", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("Index", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("ForceToMono", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("LoadInBackground", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("Ambisonic", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("PreloadAudioClip", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("Quality", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("AndroidFormat", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("AndroidLoadType", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("iPhoneFormat", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("iPhoneLoadType", EditorStyles.label, GUILayout.MinWidth(100));
                GUILayout.Label("Apply", EditorStyles.label, GUILayout.MinWidth(100));
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            style = GUI.skin.textField;
            for (int i = 0; i < AudioClipImportManager.ImportRule.AudioClipImportDatas.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                AudioClipImportManager.AudioClipImportRule.AudioClipImportData data =
                    AudioClipImportManager.ImportRule.AudioClipImportDatas[i];

                GUI.color = data.Index == currentSelectIndex ? Color.green : new Color(0.8f, 0.8f, 0.8f, 1);

                if (GUILayout.Button(data.AssetPath, style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.FileFilter, style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.Index.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.IsForceToMono.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.IsLoadInBackground.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.IsAmbisonic.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.IsPreloadAudioClip.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.Quality.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.AndroidCompressionFormat.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.AndroidAudioClipLoadType.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.iPhoneCompressionFormat.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button(data.iPhoneClipLoadType.ToString(), style, GUILayout.MinWidth(100)))
                {
                    currentSelectIndex = data.Index;
                    GetSelectIndexDataInfo(data);
                }
                if (GUILayout.Button("Apply", GUILayout.MinWidth(100)))
                {
                    AudioClipImportManager.ReImportAudioClips(data);
                }
                EditorGUILayout.EndHorizontal();
            }
            if (null != guids)
            {
                int count = 0;
                for (int i = 0; i < guids.Length; i++)
                {
                    string path = AssetDatabase.GUIDToAssetPath(guids[i]);
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }
                    string dir = path.Remove(path.LastIndexOf('/'));
                    if (!dir.Equals(currenAudioClipImportData.AssetPath))
                    {
                        continue;
                    }
                    string fileName = path.Substring(path.LastIndexOf('/') + 1);
                    if (!currenAudioClipImportData.IsMatch(fileName))
                    {
                        continue;
                    }
                    AudioImporter ai = AssetImporter.GetAtPath(path) as AudioImporter;
                    if (null != ai)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            GUILayout.Label(fileName, EditorStyles.label, GUILayout.MinWidth(120));
                            GUILayout.Label("", EditorStyles.label, GUILayout.MinWidth(100));
                            GUILayout.Label((++count).ToString(), EditorStyles.label, GUILayout.MinWidth(100));
                            GUILayout.Label(ai.forceToMono.ToString(), EditorStyles.label, GUILayout.MinWidth(120));
                            GUILayout.Label(ai.loadInBackground.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(120));
                            GUILayout.Label(ai.ambisonic.ToString(), EditorStyles.label, GUILayout.MinWidth(100));
                            GUILayout.Label(ai.preloadAudioData.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            AudioImporterSampleSettings settingAndroid = ai.GetOverrideSampleSettings("Android");
                            AudioImporterSampleSettings settingiPhone  = ai.GetOverrideSampleSettings("iOS");
                            GUILayout.Label(settingAndroid.quality.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            GUILayout.Label(settingAndroid.compressionFormat.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            GUILayout.Label(settingAndroid.loadType.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            GUILayout.Label(settingiPhone.compressionFormat.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            GUILayout.Label(settingiPhone.loadType.ToString(), EditorStyles.label,
                                            GUILayout.MinWidth(100));
                            GUILayout.Label("", EditorStyles.label, GUILayout.MinWidth(100));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            GUI.EndScrollView();
            if (EditorUtility.IsDirty(AudioClipImportManager.ImportRule))
            {
                EditorUtility.SetDirty(AudioClipImportManager.ImportRule);
                AssetDatabase.Refresh();
            }
        }
        private void OnSampleSettingGUI(BuildTargetGroup platform, AudioImporterInspector.MultiValueStatus status, bool selectionContainsTrackerFile, ref AudioImporterInspector.SampleSettingProperties properties, bool disablePreloadAudioDataOption)
        {
            EditorGUI.showMixedValue = status.multiLoadType && !properties.loadTypeChanged;
            EditorGUI.BeginChangeCheck();
            AudioClipLoadType audioClipLoadType = (AudioClipLoadType)EditorGUILayout.EnumPopup("Load Type", (Enum)properties.settings.loadType, new GUILayoutOption[0]);

            if (EditorGUI.EndChangeCheck())
            {
                properties.settings.loadType = audioClipLoadType;
                properties.loadTypeChanged   = true;
            }
            EditorGUI.BeginDisabledGroup(disablePreloadAudioDataOption);
            if (disablePreloadAudioDataOption)
            {
                EditorGUILayout.Toggle("Preload Audio Data", false, new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.m_PreloadAudioData);
            }
            EditorGUI.EndDisabledGroup();
            if (selectionContainsTrackerFile)
            {
                return;
            }
            AudioCompressionFormat[] formatsForPlatform = this.GetFormatsForPlatform(platform);
            EditorGUI.showMixedValue = status.multiCompressionFormat && !properties.compressionFormatChanged;
            EditorGUI.BeginChangeCheck();
            AudioCompressionFormat compressionFormat = (AudioCompressionFormat)EditorGUILayout.IntPopup("Compression Format", (int)properties.settings.compressionFormat, Array.ConvertAll <AudioCompressionFormat, string>(formatsForPlatform, (Converter <AudioCompressionFormat, string>)(value => value.ToString())), Array.ConvertAll <AudioCompressionFormat, int>(formatsForPlatform, (Converter <AudioCompressionFormat, int>)(value => (int)value)), new GUILayoutOption[0]);

            if (EditorGUI.EndChangeCheck())
            {
                properties.settings.compressionFormat = compressionFormat;
                properties.compressionFormatChanged   = true;
            }
            if (this.CompressionFormatHasQuality(properties.settings.compressionFormat))
            {
                EditorGUI.showMixedValue = status.multiQuality && !properties.qualityChanged;
                EditorGUI.BeginChangeCheck();
                int num = EditorGUILayout.IntSlider("Quality", (int)Mathf.Clamp(properties.settings.quality * 100f, 1f, 100f), 1, 100, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    properties.settings.quality = 0.01f * (float)num;
                    properties.qualityChanged   = true;
                }
            }
            EditorGUI.showMixedValue = status.multiSampleRateSetting && !properties.sampleRateSettingChanged;
            EditorGUI.BeginChangeCheck();
            AudioSampleRateSetting sampleRateSetting = (AudioSampleRateSetting)EditorGUILayout.EnumPopup("Sample Rate Setting", (Enum)properties.settings.sampleRateSetting, new GUILayoutOption[0]);

            if (EditorGUI.EndChangeCheck())
            {
                properties.settings.sampleRateSetting = sampleRateSetting;
                properties.sampleRateSettingChanged   = true;
            }
            if (properties.settings.sampleRateSetting == AudioSampleRateSetting.OverrideSampleRate)
            {
                EditorGUI.showMixedValue = status.multiSampleRateOverride && !properties.sampleRateOverrideChanged;
                EditorGUI.BeginChangeCheck();
                int num = EditorGUILayout.IntPopup("Sample Rate", (int)properties.settings.sampleRateOverride, AudioImporterInspector.Styles.kSampleRateStrings, AudioImporterInspector.Styles.kSampleRateValues, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    properties.settings.sampleRateOverride = (uint)num;
                    properties.sampleRateOverrideChanged   = true;
                }
            }
            EditorGUI.showMixedValue = false;
        }
Exemplo n.º 22
0
        public AudioClip(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name   = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            version5 = sourceFile.version[0] >= 5;
            if (sourceFile.version[0] < 5)
            {
                m_Format           = a_Stream.ReadInt32(); //channels?
                m_Type             = (AudioType)a_Stream.ReadInt32();
                m_3D               = a_Stream.ReadBoolean();
                m_UseHardware      = a_Stream.ReadBoolean();
                a_Stream.Position += 2;                                                                       //4 byte alignment

                if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = a_Stream.ReadInt32();
                    m_Size = a_Stream.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    //TODO: Need more test
                    if (preloadData.Size + preloadData.Offset - a_Stream.Position != tsize)
                    {
                        m_Offset = a_Stream.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = a_Stream.ReadInt32();
                }
            }
            else
            {
                m_LoadType         = a_Stream.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
                m_Channels         = a_Stream.ReadInt32();
                m_Frequency        = a_Stream.ReadInt32();
                m_BitsPerSample    = a_Stream.ReadInt32();
                m_Length           = a_Stream.ReadSingle();
                m_IsTrackerFormat  = a_Stream.ReadBoolean();
                a_Stream.Position += 3;
                m_SubsoundIndex    = a_Stream.ReadInt32();
                m_PreloadAudioData = a_Stream.ReadBoolean();
                m_LoadInBackground = a_Stream.ReadBoolean();
                m_Legacy3D         = a_Stream.ReadBoolean();
                a_Stream.Position += 1;
                m_3D = m_Legacy3D;

                m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                if (m_Source != "")
                {
                    m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", ""));
                }
                m_Offset            = a_Stream.ReadInt64();
                m_Size              = a_Stream.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
            }

            if (readSwitch)
            {
                if (string.IsNullOrEmpty(m_Source))
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = a_Stream.ReadBytes((int)m_Size);
                    }
                }
                else if (File.Exists(m_Source) ||
                         File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
                {
                    BinaryReader reader = new BinaryReader(File.OpenRead(m_Source));
                    reader.BaseStream.Position = m_Offset;
                    m_AudioData = reader.ReadBytes((int)m_Size);
                    reader.Close();
                }
                else
                {
                    if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out var estream))
                    {
                        estream.Position = m_Offset;
                        m_AudioData      = estream.ReadBytes((int)m_Size);
                    }
                    else
                    {
                        MessageBox.Show($"can't find the resource file {Path.GetFileName(m_Source)}");
                    }
                }
            }
            else
            {
                preloadData.InfoText = "Compression format: ";

                if (sourceFile.version[0] < 5)
                {
                    switch (m_Type)
                    {
                    case AudioType.ACC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioType.AIFF:
                        preloadData.extension = ".aif";
                        preloadData.InfoText += "AIFF";
                        break;

                    case AudioType.IT:
                        preloadData.extension = ".it";
                        preloadData.InfoText += "Impulse tracker";
                        break;

                    case AudioType.MOD:
                        preloadData.extension = ".mod";
                        preloadData.InfoText += "Protracker / Fasttracker MOD";
                        break;

                    case AudioType.MPEG:
                        preloadData.extension = ".mp3";
                        preloadData.InfoText += "MP2/MP3 MPEG";
                        break;

                    case AudioType.OGGVORBIS:
                        preloadData.extension = ".ogg";
                        preloadData.InfoText += "Ogg vorbis";
                        break;

                    case AudioType.S3M:
                        preloadData.extension = ".s3m";
                        preloadData.InfoText += "ScreamTracker 3";
                        break;

                    case AudioType.WAV:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Microsoft WAV";
                        break;

                    case AudioType.XM:
                        preloadData.extension = ".xm";
                        preloadData.InfoText += "FastTracker 2 XM";
                        break;

                    case AudioType.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioType.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioType.AUDIOQUEUE:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "iPhone";
                        break;
                    }
                }
                else
                {
                    switch (m_CompressionFormat)
                    {
                    case AudioCompressionFormat.PCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "PCM";
                        break;

                    case AudioCompressionFormat.Vorbis:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Vorbis";
                        break;

                    case AudioCompressionFormat.ADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "ADPCM";
                        break;

                    case AudioCompressionFormat.MP3:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "MP3";
                        break;

                    case AudioCompressionFormat.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioCompressionFormat.HEVAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PSVita ADPCM";
                        break;

                    case AudioCompressionFormat.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioCompressionFormat.AAC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioCompressionFormat.GCADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Nintendo 3DS/Wii DSP";
                        break;

                    case AudioCompressionFormat.ATRAC9:
                        preloadData.extension = ".at9";
                        preloadData.InfoText += "PSVita ATRAC9";
                        break;
                    }
                }

                if (preloadData.extension == null)
                {
                    preloadData.extension = ".AudioClip";
                    preloadData.InfoText += "Unknown";
                }

                preloadData.InfoText += "\n3D: " + m_3D;

                preloadData.Text = m_Name;
                if (m_Source != null)
                {
                    preloadData.fullSize = preloadData.Size + (int)m_Size;
                }
            }
        }
Exemplo n.º 23
0
        public AudioClip(AssetPreloadData preloadData, bool readData) : base(preloadData)
        {
            if (version[0] < 5)
            {
                m_Format      = reader.ReadInt32();
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream(4);

                if (version[0] >= 4 || (version[0] == 3 && version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    if (preloadData.Size + preloadData.Offset - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32();
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream(4);
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream(4);
                m_3D = m_Legacy3D;

                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            if (readData)
            {
                if (!string.IsNullOrEmpty(m_Source))
                {
                    m_AudioData = ResourcesHelper.GetData(m_Source, sourceFile.filePath, m_Offset, (int)m_Size);
                }
                else
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = reader.ReadBytes((int)m_Size);
                    }
                }
            }
        }
        public static AudioType GetPlatformConversionType(AudioType inType, BuildTargetGroup targetGroup, AudioCompressionFormat format)
        {
            Assembly   unityEditorAssembly = typeof(AudioImporter).Assembly;
            Type       audioUtilClass      = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
            MethodInfo method = audioUtilClass.GetMethod(
                "GetPlatformConversionType",
                BindingFlags.Static | BindingFlags.Public
                );

            AudioType type = (AudioType)method.Invoke(
                null,
                new object[] {
                inType,
                targetGroup,
                format
            }
                );

            return(type);
        }
 private bool CompressionFormatHasQuality(AudioCompressionFormat format)
 {
   switch (format)
   {
     case AudioCompressionFormat.Vorbis:
     case AudioCompressionFormat.MP3:
     case AudioCompressionFormat.XMA:
     case AudioCompressionFormat.AAC:
       return true;
     default:
       return false;
   }
 }
 public bool IsHardwareSound(AudioCompressionFormat format)
 {
   switch (format)
   {
     case AudioCompressionFormat.VAG:
     case AudioCompressionFormat.HEVAG:
     case AudioCompressionFormat.XMA:
     case AudioCompressionFormat.GCADPCM:
       return true;
     default:
       return false;
   }
 }
Exemplo n.º 27
0
        public AudioClip(AssetPreloadData preloadData, bool readSwitch, Dictionary <string, EndianBinaryReader> resourceFileReaders)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();

            m_Name   = reader.ReadAlignedString();
            version5 = sourceFile.version[0] >= 5;
            if (sourceFile.version[0] < 5)
            {
                m_Format      = reader.ReadInt32(); //channels?
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream(4);

                if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    //TODO: Need more test
                    if (preloadData.Size + preloadData.Offset - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream(4);
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream(4);
                m_3D = m_Legacy3D;

                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            if (readSwitch)
            {
                if (!string.IsNullOrEmpty(m_Source))
                {
                    m_AudioData = ResourcesHelper.GetData(m_Source, sourceFile.filePath, m_Offset, (int)m_Size, resourceFileReaders);
                }
                else
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = reader.ReadBytes((int)m_Size);
                    }
                }
            }
            else
            {
                preloadData.InfoText = "Compression format: ";

                if (sourceFile.version[0] < 5)
                {
                    switch (m_Type)
                    {
                    case AudioType.ACC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioType.AIFF:
                        preloadData.extension = ".aif";
                        preloadData.InfoText += "AIFF";
                        break;

                    case AudioType.IT:
                        preloadData.extension = ".it";
                        preloadData.InfoText += "Impulse tracker";
                        break;

                    case AudioType.MOD:
                        preloadData.extension = ".mod";
                        preloadData.InfoText += "Protracker / Fasttracker MOD";
                        break;

                    case AudioType.MPEG:
                        preloadData.extension = ".mp3";
                        preloadData.InfoText += "MP2/MP3 MPEG";
                        break;

                    case AudioType.OGGVORBIS:
                        preloadData.extension = ".ogg";
                        preloadData.InfoText += "Ogg vorbis";
                        break;

                    case AudioType.S3M:
                        preloadData.extension = ".s3m";
                        preloadData.InfoText += "ScreamTracker 3";
                        break;

                    case AudioType.WAV:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Microsoft WAV";
                        break;

                    case AudioType.XM:
                        preloadData.extension = ".xm";
                        preloadData.InfoText += "FastTracker 2 XM";
                        break;

                    case AudioType.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioType.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioType.AUDIOQUEUE:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "iPhone";
                        break;
                    }
                }
                else
                {
                    switch (m_CompressionFormat)
                    {
                    case AudioCompressionFormat.PCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "PCM";
                        break;

                    case AudioCompressionFormat.Vorbis:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Vorbis";
                        break;

                    case AudioCompressionFormat.ADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "ADPCM";
                        break;

                    case AudioCompressionFormat.MP3:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "MP3";
                        break;

                    case AudioCompressionFormat.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioCompressionFormat.HEVAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PSVita ADPCM";
                        break;

                    case AudioCompressionFormat.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioCompressionFormat.AAC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "AAC";
                        break;

                    case AudioCompressionFormat.GCADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Nintendo 3DS/Wii DSP";
                        break;

                    case AudioCompressionFormat.ATRAC9:
                        preloadData.extension = ".at9";
                        preloadData.InfoText += "PSVita ATRAC9";
                        break;
                    }
                }

                if (preloadData.extension == null)
                {
                    preloadData.extension = ".AudioClip";
                    preloadData.InfoText += "Unknown";
                }

                preloadData.InfoText += "\n3D: " + m_3D;

                preloadData.FullName = m_Name;
                if (m_Source != null)
                {
                    preloadData.fullSize = preloadData.Size + (int)m_Size;
                }
            }
        }
Exemplo n.º 28
0
    /// <summary>
    /// 更改音效设置
    /// </summary>
    /// <param name="importer"></param>
    /// <param name="platform"></param>
    /// <param name="loadType"></param>
    public static void SetAudioSettingExt(this AudioImporter importer, string platform, AudioClipLoadType loadType, AudioCompressionFormat format, float quality = 1)
    {
        AudioImporterSampleSettings settings = importer.GetOverrideSampleSettings(platform);

        settings.loadType          = loadType;
        settings.compressionFormat = format;
        settings.quality           = quality;
        importer.SetOverrideSampleSettings(platform, settings);
    }
Exemplo n.º 29
0
    public static void DealAudioImporter(AudioClip clip, AudioImporter importer, bool forceMono, bool bSensitive = false, bool compressSampleRate = true)
    {
        bool bChange = false;

        if (clip == null)
        {
            return;
        }

        AudioImporterSampleSettings androidSetting = importer.GetOverrideSampleSettings("Android");
        AudioImporterSampleSettings iosSetting     = importer.GetOverrideSampleSettings("iPhone");

        if (clip.length >= 10)
        {
            if (androidSetting.loadType != AudioClipLoadType.Streaming)
            {
                androidSetting.loadType = AudioClipLoadType.Streaming;
                iosSetting.loadType     = AudioClipLoadType.Streaming;
                bChange = true;
            }

            AudioCompressionFormat newFmt = AudioCompressionFormat.Vorbis;
            if (newFmt != androidSetting.compressionFormat)
            {
                androidSetting.compressionFormat = newFmt;
                iosSetting.compressionFormat     = newFmt;
                androidSetting.quality           = 0.01f;
                iosSetting.quality = 0.01f;
                bChange            = true;
            }
        }
        else if (clip.length < 10 && clip.length >= 1)
        {
            AudioClipLoadType newLoadType = AudioClipLoadType.CompressedInMemory;
            if (newLoadType != androidSetting.loadType)
            {
                androidSetting.loadType = newLoadType;
                iosSetting.loadType     = newLoadType;
                bChange = true;
            }
            AudioCompressionFormat newFmt = bSensitive ? AudioCompressionFormat.ADPCM : AudioCompressionFormat.Vorbis;
            if (newFmt != androidSetting.compressionFormat)
            {
                androidSetting.compressionFormat = newFmt;
                iosSetting.compressionFormat     = newFmt;
                bChange = true;
                if (newFmt == AudioCompressionFormat.Vorbis)
                {
                    androidSetting.quality = 0.01f;
                    iosSetting.quality     = 0.01f;
                }
            }
        }
        else if (clip.length < 1)
        {
            AudioClipLoadType newLoadType = bSensitive ? AudioClipLoadType.DecompressOnLoad : AudioClipLoadType.CompressedInMemory;
            if (androidSetting.loadType != newLoadType)
            {
                androidSetting.loadType = newLoadType;
                iosSetting.loadType     = newLoadType;
                bChange = true;
            }
            AudioCompressionFormat newFmt = AudioCompressionFormat.ADPCM;
            if (newFmt != androidSetting.compressionFormat)
            {
                androidSetting.compressionFormat = newFmt;
                iosSetting.compressionFormat     = newFmt;
                bChange = true;
            }
        }

        var sampleRate = (uint)(compressSampleRate ? 22050 : 44100);

        if (androidSetting.sampleRateSetting != AudioSampleRateSetting.OverrideSampleRate || androidSetting.sampleRateOverride != sampleRate)
        {
            androidSetting.sampleRateSetting  = AudioSampleRateSetting.OverrideSampleRate;
            iosSetting.sampleRateSetting      = AudioSampleRateSetting.OverrideSampleRate;
            androidSetting.sampleRateOverride = sampleRate;
            iosSetting.sampleRateOverride     = sampleRate;
            bChange = true;
        }

        if (importer.forceToMono != forceMono)
        {
            importer.forceToMono = forceMono;
            bChange = true;
        }
        if (importer.loadInBackground && androidSetting.loadType != AudioClipLoadType.Streaming)
        {
            importer.loadInBackground = false;
            bChange = true;
        }
        if (importer.preloadAudioData)
        {
            importer.preloadAudioData = false;
            bChange = true;
        }

        if (bChange)
        {
            importer.SetOverrideSampleSettings("Android", androidSetting);
            importer.SetOverrideSampleSettings("iPhone", iosSetting);
            importer.SaveAndReimport();
        }
    }
Exemplo n.º 30
0
        public AudioPlatformNorm GetPlatformSetting(AudioImporterSampleSettings platformSetting, string platform,
                                                    AudioClipLoadType audioClipLoadType_Short, AudioCompressionFormat compressionFormat_Short,
                                                    AudioClipLoadType audioClipLoadType_Long, AudioCompressionFormat compressionFormat_Long)
        {
            AudioPlatformNorm apn = new AudioPlatformNorm()
            {
                platform = platform,
                setting  = platformSetting,
            };

            if (autioType == "Long")
            {
                apn.recommendloadType          = audioClipLoadType_Long;
                apn.recommendCompressionFormat = compressionFormat_Long;
                if (clip.loadType != audioClipLoadType_Long)
                {
                    apn.loadTypeLevel = 2;
                    errorNum++;
                }
                else
                {
                    apn.loadTypeLevel = 0;
                }
                if (audioImporter.defaultSampleSettings.compressionFormat != compressionFormat_Long)
                {
                    apn.compressionFormatLevel = 2;
                    errorNum++;
                }
                else
                {
                    apn.compressionFormatLevel = 0;
                }
            }
            else
            {
                apn.recommendloadType          = audioClipLoadType_Short;
                apn.recommendCompressionFormat = compressionFormat_Short;
                if (clip.loadType != audioClipLoadType_Short)
                {
                    apn.loadTypeLevel = 2;
                    errorNum++;
                }
                else
                {
                    apn.loadTypeLevel = 0;
                }
                if (audioImporter.defaultSampleSettings.compressionFormat != compressionFormat_Short)
                {
                    apn.compressionFormatLevel = 2;
                    errorNum++;
                }
                else
                {
                    apn.compressionFormatLevel = 0;
                }
            }

            return(apn);
        }
Exemplo n.º 31
0
        //オーディオファイルの設定を変更する
        private static void ChangeSetting(string audioPath, bool forceToMono, bool normalize, bool ambisonic, bool loadInBackground, AudioClipLoadType loadType, float quality, AudioCompressionFormat compressionFormat, AudioSampleRateSetting sampleRateSetting)
        {
            if (AssetDatabase.LoadAssetAtPath <AudioClip>(audioPath) == null)
            {
                return;
            }
            var importer = AssetImporter.GetAtPath(audioPath) as AudioImporter;

            importer.forceToMono = forceToMono;

            var serializedObject  = new SerializedObject(importer);
            var normalizeProperty = serializedObject.FindProperty("m_Normalize");

            normalizeProperty.boolValue = normalize;
            serializedObject.ApplyModifiedProperties();

            importer.ambisonic        = ambisonic;
            importer.loadInBackground = loadInBackground;

            var settings = importer.defaultSampleSettings;

            settings.loadType          = loadType;
            settings.quality           = quality;
            settings.compressionFormat = compressionFormat;
            settings.sampleRateSetting = sampleRateSetting;

            importer.defaultSampleSettings = settings;

            Debug.Log(audioPath + "の設定を変更しました");
        }
		private bool CompressionFormatHasQuality(AudioCompressionFormat format)
		{
			switch (format)
			{
			case AudioCompressionFormat.Vorbis:
			case AudioCompressionFormat.MP3:
				return true;
			}
			return false;
		}
Exemplo n.º 33
0
        public AudioClip(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();

            m_Name   = reader.ReadAlignedString();
            version5 = sourceFile.version[0] >= 5;
            if (sourceFile.version[0] < 5)
            {
                m_Format      = reader.ReadInt32(); //channels?
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream(4);

                if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    //TODO: Need more test
                    if (preloadData.Size + preloadData.Offset - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream(4);
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream(4);
                m_3D = m_Legacy3D;

                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            if (readSwitch)
            {
                if (!string.IsNullOrEmpty(m_Source))
                {
                    var resourceFileName = Path.GetFileName(m_Source);
                    var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
                    if (!File.Exists(resourceFilePath))
                    {
                        var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
                        if (findFiles.Length > 0)
                        {
                            resourceFilePath = findFiles[0];
                        }
                    }
                    if (File.Exists(resourceFilePath))
                    {
                        using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
                        {
                            resourceReader.BaseStream.Position = m_Offset;
                            m_AudioData = resourceReader.ReadBytes((int)m_Size);
                        }
                    }
                    else
                    {
                        if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
                        {
                            resourceReader.Position = m_Offset;
                            m_AudioData             = resourceReader.ReadBytes((int)m_Size);
                        }
                        else
                        {
                            MessageBox.Show($"can't find the resource file {resourceFileName}");
                        }
                    }
                }
                else
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = reader.ReadBytes((int)m_Size);
                    }
                }
            }
            else
            {
                preloadData.InfoText = "Compression format: ";

                if (sourceFile.version[0] < 5)
                {
                    switch (m_Type)
                    {
                    case AudioType.ACC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioType.AIFF:
                        preloadData.extension = ".aif";
                        preloadData.InfoText += "AIFF";
                        break;

                    case AudioType.IT:
                        preloadData.extension = ".it";
                        preloadData.InfoText += "Impulse tracker";
                        break;

                    case AudioType.MOD:
                        preloadData.extension = ".mod";
                        preloadData.InfoText += "Protracker / Fasttracker MOD";
                        break;

                    case AudioType.MPEG:
                        preloadData.extension = ".mp3";
                        preloadData.InfoText += "MP2/MP3 MPEG";
                        break;

                    case AudioType.OGGVORBIS:
                        preloadData.extension = ".ogg";
                        preloadData.InfoText += "Ogg vorbis";
                        break;

                    case AudioType.S3M:
                        preloadData.extension = ".s3m";
                        preloadData.InfoText += "ScreamTracker 3";
                        break;

                    case AudioType.WAV:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Microsoft WAV";
                        break;

                    case AudioType.XM:
                        preloadData.extension = ".xm";
                        preloadData.InfoText += "FastTracker 2 XM";
                        break;

                    case AudioType.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioType.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioType.AUDIOQUEUE:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "iPhone";
                        break;
                    }
                }
                else
                {
                    switch (m_CompressionFormat)
                    {
                    case AudioCompressionFormat.PCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "PCM";
                        break;

                    case AudioCompressionFormat.Vorbis:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Vorbis";
                        break;

                    case AudioCompressionFormat.ADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "ADPCM";
                        break;

                    case AudioCompressionFormat.MP3:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "MP3";
                        break;

                    case AudioCompressionFormat.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioCompressionFormat.HEVAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PSVita ADPCM";
                        break;

                    case AudioCompressionFormat.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioCompressionFormat.AAC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "AAC";
                        break;

                    case AudioCompressionFormat.GCADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Nintendo 3DS/Wii DSP";
                        break;

                    case AudioCompressionFormat.ATRAC9:
                        preloadData.extension = ".at9";
                        preloadData.InfoText += "PSVita ATRAC9";
                        break;
                    }
                }

                if (preloadData.extension == null)
                {
                    preloadData.extension = ".AudioClip";
                    preloadData.InfoText += "Unknown";
                }

                preloadData.InfoText += "\n3D: " + m_3D;

                preloadData.Text = m_Name;
                if (m_Source != null)
                {
                    preloadData.fullSize = preloadData.Size + (int)m_Size;
                }
            }
        }
		public bool IsHardwareSound(AudioCompressionFormat format)
		{
			return format == AudioCompressionFormat.VAG || format == AudioCompressionFormat.HEVAG;
		}