Exemple #1
0
        void LoadSampleFromStreamingAssets(GATDataAllocationMode mode, GATSampleInfo info, Dictionary <string, GATData> loadedSamples)
        {
            AGATAudioFile file;
            string        path;

            GATData[] loadedChannels;
            int       i;

            path = info.GetStreamingAssetFullPath();

            using (file = AGATAudioFile.OpenAudioFileAtPath(path))
            {
                loadedChannels = GATAudioLoader.SharedInstance.LoadSync(file, mode);
            }

            if (loadedChannels.Length == 1)
            {
                loadedSamples.Add(info.Name, loadedChannels[0]);
                return;
            }

            for (i = 0; i < loadedChannels.Length; i++)
            {
                loadedSamples.Add(string.Format("{0}_{1}", info.Name, i), loadedChannels[i]);
            }
        }
Exemple #2
0
 public void AddSample( string pathInResources, string guid, int numChannels, int samplesPerChannel, bool isStreamingAsset )
 {
     GATSampleInfo info = new GATSampleInfo( pathInResources, guid, numChannels, samplesPerChannel, isStreamingAsset );
     _sampleInfos.Add ( info );
     _totalUncompressedBytes += info.UncompressedBytesInMemory;
     _humanReadableUncompressedSize = null;
 }
Exemple #3
0
        public void AddSample(string pathInResources, string guid, int numChannels, int samplesPerChannel, bool isStreamingAsset)
        {
            GATSampleInfo info = new GATSampleInfo(pathInResources, guid, numChannels, samplesPerChannel, isStreamingAsset);

            _sampleInfos.Add(info);
            _totalUncompressedBytes       += info.UncompressedBytesInMemory;
            _humanReadableUncompressedSize = null;
        }
Exemple #4
0
        IEnumerator LoadSampleFromResources(GATDataAllocationMode mode, GATSampleInfo info, Dictionary <string, GATData> loadedSamples)
        {
            AudioClip clip;

            /*
             #if UNITY_EDITOR
             * if( Application.isPlaying ) //GZComment: simplifies memory management when trying things out in the editor, where performance is not crucial.
             * {
             *      clip = Resources.Load( info.PathInResources ) as AudioClip;
             *      if( clip == null )
             *      {
             *              Debug.LogError( "No Clip at path: " + info.PathInResources);
             *      }
             * }
             * else
             * {
             *      mode = GATDataAllocationMode.Unmanaged;
             *      string assetPath = AssetDatabase.GUIDToAssetPath( info.GUID );
             *      clip = AssetDatabase.LoadAssetAtPath( assetPath, typeof( AudioClip ) ) as AudioClip;
             * }
             *
             #else
             */
            clip = Resources.Load(info.PathInResources) as AudioClip;
            //#endif

            while (clip.loadState != AudioDataLoadState.Loaded)
            {
                yield return(null);
            }
            if (info.NumChannels == 1)
            {
                GATData data;
                data = clip.ToGATData(mode);
                loadedSamples.Add(info.Name, data);
            }
            else
            {
                GATData[] channelsData = clip.ExtractChannels(mode);
                for (int i = 0; i < info.NumChannels; i++)
                {
                    loadedSamples.Add(string.Format("{0}_{1}", info.Name, i), channelsData[i]);
                    //Debug.Log("loaded " + string.Format("{0}_{1}", info.Name, i));
                }
            }
            clipsLoaded++;


                        #if UNITY_EDITOR
            if (Application.isPlaying)
            {
                Resources.UnloadAsset(( Object )clip);
            }
                        #else
            Resources.UnloadAsset(clip);
                        #endif
        }
Exemple #5
0
        void LoadSampleFromResources(GATDataAllocationMode mode, GATSampleInfo info, Dictionary <string, GATData> loadedSamples)
        {
            AudioClip clip;

                        #if UNITY_EDITOR
            if (Application.isPlaying)              //GZComment: simplifies memory management when trying things out in the editor, where performance is not crucial.
            {
                clip = Resources.Load(info.PathInResources) as AudioClip;
                if (clip == null)
                {
                    Debug.LogError("No Clip at path: " + info.PathInResources);
                }
            }
            else
            {
                mode = GATDataAllocationMode.Unmanaged;
                string assetPath = AssetDatabase.GUIDToAssetPath(info.GUID);
                clip = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AudioClip)) as AudioClip;
            }
                        #else
            clip = Resources.Load(info.PathInResources) as AudioClip;
                        #endif


            if (info.NumChannels == 1)
            {
                GATData data;
                data = clip.ToGATData(mode);
                loadedSamples.Add(info.Name, data);
            }
            else
            {
                GATData[] channelsData = clip.ExtractChannels(mode);
                for (int i = 0; i < info.NumChannels; i++)
                {
                    loadedSamples.Add(string.Format("{0}_{1}", info.Name, i), channelsData[i]);
                }
            }

                        #if UNITY_EDITOR
            if (Application.isPlaying)
            {
                Resources.UnloadAsset(( Object )clip);
            }
                        #else
            Resources.UnloadAsset(clip);
                        #endif
        }
Exemple #6
0
 void LoadSample(GATSampleInfo info, Dictionary <string, GATData> target, GATDataAllocationMode allocationMode)
 {
     if (info.IsStreamingAsset)
     {
                         #if UNITY_EDITOR
         if (Application.isPlaying == false)
         {
             LoadSampleFromResources(GATDataAllocationMode.Unmanaged, info, target);
             return;
         }
                         #endif
         LoadSampleFromStreamingAssets(allocationMode, info, target);
     }
     else
     {
         LoadSampleFromResources(allocationMode, info, target);
     }
 }
Exemple #7
0
        void LoadSample(GATSampleInfo info, Dictionary <string, GATData> target, GATDataAllocationMode allocationMode)
        {
            if (info.IsStreamingAsset)
            {
                                #if UNITY_EDITOR
                if (Application.isPlaying == false)
                {
                    Debug.Log("Editor only ResourcesAsset");
                    LoadSampleFromResources(GATDataAllocationMode.Unmanaged, info, target);
                    return;
                }
#endif
                Debug.Log("StreamingAsset");
                LoadSampleFromStreamingAssets(allocationMode, info, target);
            }
            else
            {
                UnitySingleton <CoroutineMaster> .Instance.StartCoroutine(LoadSampleFromResources(allocationMode, info, target));
            }
        }
Exemple #8
0
 public void RemoveSample(GATSampleInfo sampleInfo)
 {
     _sampleInfos.Remove(sampleInfo);
     _totalUncompressedBytes       -= sampleInfo.UncompressedBytesInMemory;
     _humanReadableUncompressedSize = null;
 }
Exemple #9
0
    bool DrawOkSample( GATSampleInfo info )
    {
        bool remove = false;

        GUILayout.BeginHorizontal();
        info.Name = EditorGUILayout.TextField( "Name in Bank:", info.Name, GUILayout.ExpandWidth( false ) );

        if( GUILayout.Button( "Select", __smallerButtons ) )
        {
            Selection.activeObject = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( info.GUID ), typeof( AudioClip ) );
        }

        GUI.color = Color.red;
        if( GUILayout.Button( "Remove", __smallerButtons ) )
        {
            _soundBank.RemoveSample( info );
            EditorUtility.SetDirty( _soundBank );
            remove = true;
        }

        GUILayout.EndHorizontal();

        GUI.color = Color.white;

        GUILayout.BeginHorizontal();

        info.MidiCode = EditorGUILayout.IntField( "MidiCode: ", info.MidiCode, GUILayout.Width( 110f ) );
        GUILayout.Label( GATMidiHelper.MidiCodeToString( info.MidiCode ) );
        GUILayout.EndHorizontal();
        return !remove;
    }
Exemple #10
0
    bool DrawNotInResourcesSample( GATSampleInfo info )
    {
        bool remove = false;

        GUILayout.Label( string.Format( "Sample {0} not in a Resources folder!", info.Name ) );

        GUILayout.BeginHorizontal();
        if( GUILayout.Button( "Select", __smallerButtons ) )
        {
            Selection.activeObject = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( info.GUID ), typeof( AudioClip ) );
        }

        if( GUILayout.Button( "Remove", __smallerButtons ) )
        {
            _soundBank.RemoveSample( info );
            EditorUtility.SetDirty( _soundBank );
            remove = true;
        }
        GUILayout.EndHorizontal();

        return !remove;
    }
Exemple #11
0
    bool DrawNotFoundSample( GATSampleInfo info )
    {
        bool remove = false;

        GUILayout.Label( string.Format( "Sample {0} not found!", info.Name ) );

        GUILayout.BeginHorizontal();
        if( GUILayout.Button( "Remove", __smallerButtons ) )
        {
            _soundBank.RemoveSample( info );
            EditorUtility.SetDirty( _soundBank );
            remove = true;
        }
        GUILayout.EndHorizontal();

        return !remove;
    }
Exemple #12
0
    bool DrawMovedSample( GATSampleInfo info )
    {
        bool remove = false;

        GUILayout.Label( string.Format( "Sample {0}'s path has changed.", info.Name ) );

        GUILayout.BeginHorizontal();
        if( GUILayout.Button( "Select", __smallerButtons ) )
        {
            Selection.activeObject = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( info.GUID ), typeof( AudioClip ) );
        }

        GUI.backgroundColor = Color.green;
        if( GUILayout.Button( "Update", __smallerButtons ) )
        {
            info.UpdatePathInResources();
            EditorUtility.SetDirty( _soundBank );
        }

        GUI.backgroundColor = Color.red;
        if( GUILayout.Button( "Remove", __smallerButtons ) )
        {
            _soundBank.RemoveSample( info );
            EditorUtility.SetDirty( _soundBank );
            remove = true;
        }

        GUILayout.EndHorizontal();

        return !remove;
    }
Exemple #13
0
        void LoadSampleFromStreamingAssets( GATDataAllocationMode mode, GATSampleInfo info, Dictionary< string, GATData > loadedSamples )
        {
            AGATAudioFile file;
            string path;
            GATData[] loadedChannels;
            int i;

            path = info.GetStreamingAssetFullPath();

            using( file = AGATAudioFile.OpenAudioFileAtPath( path ) )
            {
                loadedChannels = GATAudioLoader.SharedInstance.LoadSync( file, mode );
            }

            if( loadedChannels.Length == 1 )
            {
                loadedSamples.Add( info.Name, loadedChannels[ 0 ] );
                return;
            }

            for( i = 0; i < loadedChannels.Length; i++ )
            {
                loadedSamples.Add( string.Format( "{0}_{1}", info.Name, i ), loadedChannels[ i ] );
            }
        }
Exemple #14
0
        void LoadSampleFromResources( GATDataAllocationMode mode, GATSampleInfo info, Dictionary< string, GATData > loadedSamples )
        {
            AudioClip clip;
            #if UNITY_EDITOR
            if( Application.isPlaying ) //GZComment: simplifies memory management when trying things out in the editor, where performance is not crucial.
            {
                clip = Resources.Load( info.PathInResources ) as AudioClip;
                if( clip == null )
                {
                    Debug.LogError( "No Clip at path: " + info.PathInResources);
                }
            }
            else
            {
                mode = GATDataAllocationMode.Unmanaged;
                string assetPath = AssetDatabase.GUIDToAssetPath( info.GUID );
                clip = AssetDatabase.LoadAssetAtPath( assetPath, typeof( AudioClip ) ) as AudioClip;
            }

            #else
            clip = Resources.Load( info.PathInResources ) as AudioClip;
            #endif

            if( info.NumChannels == 1 )
            {
                GATData data;
                data = clip.ToGATData( mode );
                loadedSamples.Add( info.Name, data );
            }
            else
            {
                GATData[] channelsData = clip.ExtractChannels( mode );
                for( int i = 0; i < info.NumChannels; i++ )
                {
                    loadedSamples.Add( string.Format( "{0}_{1}", info.Name, i ), channelsData[i] );
                }
            }

            #if UNITY_EDITOR
            if( Application.isPlaying )
            {
                Resources.UnloadAsset( ( Object )clip );
            }
            #else
            Resources.UnloadAsset( clip );
            #endif
        }
Exemple #15
0
 void LoadSample( GATSampleInfo info, Dictionary< string, GATData > target, GATDataAllocationMode allocationMode )
 {
     if( info.IsStreamingAsset )
     {
         #if UNITY_EDITOR
         if( Application.isPlaying == false )
         {
             LoadSampleFromResources( GATDataAllocationMode.Unmanaged, info, target );
             return;
         }
         #endif
         LoadSampleFromStreamingAssets( allocationMode, info, target );
     }
     else
     {
         LoadSampleFromResources( allocationMode, info, target );
     }
 }
Exemple #16
0
 public void RemoveSample( GATSampleInfo sampleInfo )
 {
     _sampleInfos.Remove( sampleInfo );
     _totalUncompressedBytes -= sampleInfo.UncompressedBytesInMemory;
     _humanReadableUncompressedSize = null;
 }