Exemplo n.º 1
0
 public RawAudioData(AudioClip Clip)
 {
     IsLoaded     = false;
     BaseClip     = Clip;
     SampleRate   = 0;
     ChannelCount = 0;
     Length       = 0f;
     RawData      = null;
     if (BaseClip == null)
     {
         Name = "NULL";
         return;
     }
     Name = Clip.name;
     //read in all data now so we can reference it as needed. (can only read from main thread)
     if (BaseClip.loadState != AudioDataLoadState.Loaded)
     {
         if (BaseClip.loadState == AudioDataLoadState.Unloaded && BaseClip.loadInBackground)   //not loaded yet and set to load in background. we need to start the load then wait.
         {
             BaseClip.LoadAudioData();
             return;
         }
         if (BaseClip.loadState == AudioDataLoadState.Loading) //not loaded yet but already started. we need to just wait
         {
             return;
         }
         if (!BaseClip.LoadAudioData())   //
         {
             Debug.LogError("Unable to load audio data for clip '" + BaseClip.name + "'!");
             Length = 0f;
             return;
         }
     }
     ReadAudioData();
 }
Exemplo n.º 2
0
 public void LoadAudioData()
 {
     if (_audioClip != null && _audioClip.loadState != AudioDataLoadState.Loaded)
     {
         _audioClip.LoadAudioData();
     }
     _loadAudioDataEventAction = true;
 }
Exemplo n.º 3
0
 private void LoadSoundConfigurationsFromPack(string packPath)
 {
     if (File.Exists(packPath + "/Sound Replacer.conf"))
     {
         string[] soundConfigurations = File.ReadAllLines(packPath + "/Sound Replacer.conf");
         foreach (string soundConfigLine in soundConfigurations)
         {
             string[] soundConfig = soundConfigLine.Split('|');
             if (soundConfig.Length == 2)
             {
                 WWW       www  = toWWW(packPath + "/" + soundConfig[1]);
                 AudioClip clip = www.GetAudioClip(true, false);
                 while (clip.loadState != AudioDataLoadState.Loaded && clip.loadState != AudioDataLoadState.Failed)
                 {
                     clip.LoadAudioData();
                 }
                 createIfSafe(ref soundReplacements, soundConfig[0], new SoundConfiguration(clip));
                 Log("Added replacement configuration for " + soundConfig[0] + " => " + packPath + "/" + soundConfig[1]);
             }
             else
             {
                 Log("Invalid replacement configuration: " + soundConfigLine);
             }
         }
     }
 }
Exemplo n.º 4
0
        public IEnumerator LoadAudioFiles(DirectoryInfo dir)
        {
            FileInfo[] files = new DirectoryInfo(dir.FullName + "/Audio").GetFiles("*.wav");
            foreach (FileInfo file in files)
            {
                GeneralManager.Instance.LogToFileOrConsole("[PromDate] Loading audio file: " + file.Name);
                WWW www = new WWW("file:///" + file.FullName);
                yield return(www);

                if (www.error != null)
                {
                    GeneralManager.Instance.LogToFileOrConsole(www.error);
                }
                AudioClip clip = www.GetAudioClip(false, false);
                clip.LoadAudioData();
                clip.name = file.Name.Split('.')[0];
                while (clip.loadState == AudioDataLoadState.Loading || clip.loadState == AudioDataLoadState.Unloaded)
                {
                    yield return(0);
                }
                AudioCategory category = AudioController.GetCategory(clip.name.Split('_')[0].ToUpper());
                if (category == null)
                {
                    category = AudioController.GetCategory("VOICE");
                }
                AudioItem audioItem = AudioController.AddToCategory(category, clip, clip.name);
                ((Dictionary <string, AudioItem>) typeof(AudioController).GetField("_audioItems", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(AudioController.Instance)).Add(audioItem.Name, audioItem);
                GeneralManager.Instance.LogToFileOrConsole("[PromDate] Finished loading audio: " + file.Name);
            }
        }
Exemplo n.º 5
0
        private IEnumerator LoadAudioDataCoroutine(AudioClip audioClip, System.Action OnLoadedAction = null)
        {
            //Clip is null, exiting early
            if (audioClip == null)
            {
                yield break;
            }

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            audioClip.LoadAudioData();

            //Wait until loading is done
            while (audioClip.loadState == AudioDataLoadState.Loading)
            {
                yield return(null);
            }

            if (audioClip.loadState == AudioDataLoadState.Failed)
            {
                Debug.LogWarning($"FAILED to load AudioClip '{audioClip.name}'!");
                yield break;
            }

            if (audioClip.loadState == AudioDataLoadState.Loaded)
            {
                //Debug.Log($"AudioClip '{clip.name}' is loaded!");
                OnLoadedAction?.Invoke();
            }

            stopwatch.Stop();
            Debug.Log($"Time to load AudioClip '{audioClip.name}': {stopwatch.ElapsedMilliseconds} ms");
        }
Exemplo n.º 6
0
    private void LoadSoundInternal(string assetBundleName, string soundName)
    {
        AudioClip clip = LoadClipFromBundle(assetBundleName, soundName);

        if (clip != null)
        {
            if (!clip.preloadAudioData)
            {
                clip.LoadAudioData();
            }

            PreloadedClip preloadedClip;
            if (_preloadedClips.TryGetValue(soundName, out preloadedClip))
            {
                preloadedClip.clip   = clip;
                preloadedClip.level += 1;
            }
            else
            {
                preloadedClip.clip  = clip;
                preloadedClip.level = 1;
                _preloadedClips.Add(soundName, preloadedClip);
            }
        }
    }
Exemplo n.º 7
0
    private void startGame()
    {
        // sphere.SetActive(false);

        // Get the skin and set to delfault if not found.
        int skin = PlayerPrefs.GetInt("skin");

        if (skin < 0 || skin > 2)
        {
            skin = 0;
        }
        // Assign the skin to the morin khuur sprite
        selectedMK.sprite = mkSprites[skin];

        // Get the notes from each indiv song
        TextAsset lsFile = null;

        ls = new LoadSong();
        string songChoice = PlayerPrefs.GetString("song_choice");

        // Since we had resource folder problems we define the song and file when starting
        if (songChoice.Equals("song1"))
        {
            clip   = songClip1;
            lsFile = lsFile1;
        }
        else if (songChoice.Equals("song2"))
        {
            clip   = songClip2;
            lsFile = lsFile2;
        }
        else if (songChoice.Equals("song3"))
        {
            clip   = songClip3;
            lsFile = lsFile3;
        }
        else
        {
            clip   = songClip1;
            lsFile = lsFile1;
            PlayerPrefs.SetString("song_choice", "song1");
        }

        ls.loadSong(lsFile);

        clip.LoadAudioData();
        // Ensures the clip is loaded before we continue.
        do
        {
        } while (clip.loadState != AudioDataLoadState.Loaded);

        // Assign the clip to the auto source
        song      = GetComponent <AudioSource>();
        song.clip = clip;

        paused = false;
        timeR  = song.clip.length;
        //song.time = song.clip.length - 10;
        song.Play();
    }
Exemplo n.º 8
0
    public void AddAudioClip(string inId, string inAddress)
    {
        AudioClip tClip = Resources.Load <AudioClip>(inAddress);

        audioClips.Add(inId, tClip);
        tClip.LoadAudioData();
    }
Exemplo n.º 9
0
    public void GetObjects(Sound s)
    {
        string file = s.themeName + "/" + s.stickerName;

        S3Client.GetObjectAsync(S3BucketName, file, (responseObj) =>

        {
            var response = responseObj.Response;

            if (response.ResponseStream != null)
            {
                AudioClip t      = new AudioClip();
                byte[] imageData = new byte[response.ResponseStream.Length];
                response.ResponseStream.Read(imageData, 0, (int)imageData.Length);
                t.LoadAudioData();
                t.name = s.stickerName;
                instantiateSounds(t, s);

                AudioClip soundInstance = Instantiate(t) as AudioClip;
            }
            else
            {
                Debug.Log("Nothing found in Bucket");
            }
        });
    }
Exemplo n.º 10
0
        public float[] LoadMonoSound(bool zeroPadding = false)
        {
            // Need all audio samples.  If in stereo, samples will return with left and right channels interweaved
            // [L,R,L,R,L,R]
            float[] multiChannelSamples = new float[audioClip.samples * audioClip.channels];
            audioClip.LoadAudioData();
            audioClip.GetData(multiChannelSamples, 0);

            // We only need to retain the samples for combined channels over the time domain
            int samples = audioClip.samples;

            if (zeroPadding)
            {
                samples += -audioClip.samples & FFTWindow - 1;
            }
            float[] preProcessedSamples    = new float[samples];
            int     numProcessed           = 0;
            float   combinedChannelAverage = 0f;

            for (int i = 0; i < multiChannelSamples.Length; i++)
            {
                combinedChannelAverage += multiChannelSamples[i];

                // Each time we have processed all channels samples for a point in time, we will store the average of the channels combined
                if ((i + 1) % audioClip.channels == 0)
                {
                    preProcessedSamples[numProcessed] = combinedChannelAverage / audioClip.channels;
                    numProcessed++;
                    combinedChannelAverage = 0f;
                }
            }
            //Debug.Log("Combine Channels done");
            //Debug.Log(preProcessedSamples.Length);
            return(preProcessedSamples);
        }
Exemplo n.º 11
0
    IEnumerator LoadMP3File(string path)
    {
        WWW www = new WWW("file://" + path);

        //Debug.Log ("loading " + path);
        yield return(www);

        if (www.error != null)
        {
            Debug.Log(www.error);
            yield break;
        }

        AudioClip clip = NAudioPlayer.FromMp3Data(www.bytes);

        clip.LoadAudioData();

        if (clip.loadState == AudioDataLoadState.Failed)
        {
            Debug.LogError("Unable to load file: " + path);
        }
        else
        {
            //Debug.Log ("done loading " + path);
            clip.name = Path.GetFileName(path);

            loadedMusics.Add(clip);

            MasterAudio.AddSongToPlaylist("Loaded Musics", clip);
        }

        loadingMusicsList.Remove(path);
    }
Exemplo n.º 12
0
 private IEnumerator Playing(AudioClip clip)
 {
     if (clip.loadState == AudioDataLoadState.Unloaded)
     {
         clip.LoadAudioData();
     }
     while (clip.loadState == AudioDataLoadState.Loading)
     {
         yield return(new WaitForSeconds(0.1f));
     }
     if (clip.loadState == AudioDataLoadState.Loaded)
     {
         _sourcePlayback.clip = clip;
         _sourcePlayback.Play();
         while (_sourcePlayback.isPlaying)
         {
             yield return(new WaitForSeconds(0.1f));
         }
         _sourcePlayback.Stop();
         _sourcePlayback.clip = null;
         if (OnPlaybackEnd != null)
         {
             OnPlaybackEnd.Invoke(true);
         }
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Import sound data from modding locations as an audio clip.
        /// </summary>
        private static bool TryImportAudioClip(string name, string extension, out AudioClip audioClip)
        {
            if (DaggerfallUnity.Settings.MeshAndTextureReplacement)
            {
                // Seek from loose files
                string path = Path.Combine(soundPath, name + extension);
                if (File.Exists(path))
                {
                    WWW www = new WWW("file://" + path);
                    audioClip = www.GetAudioClip();
                    DaggerfallUnity.Instance.StartCoroutine(LoadAudioData(www, audioClip));
                    return(true);
                }

                // Seek from mods
                if (ModManager.Instance != null && ModManager.Instance.TryGetAsset(name, false, out audioClip))
                {
                    if (audioClip.preloadAudioData || audioClip.LoadAudioData())
                    {
                        return(true);
                    }

                    Debug.LogErrorFormat("Failed to load audiodata for audioclip {0}", name);
                }
            }

            audioClip = null;
            return(false);
        }
        private void LoadSounds()
        {
            resourceManager.SoundResManager.LoadFileInfoList(GetFileInfosInStreamingFolder(constData.SoundsSubFolderPathInReadonlyDataFolderName, new string[] { "mp3" }));

            soundAssetBundle = GetAssetBundleByName(constData.SoundAssetBundleName);
            if (soundAssetBundle != null && constData.IsSoundABLoadedAllOnce)
            {
                string[] names = soundAssetBundle.GetAllAssetNames();
                for (int i = 0; i < names.Length; i++)
                {
                    string    name  = names[i];
                    string    key   = Path.GetFileName(name).Split('.')[0];
                    AudioClip audio = soundAssetBundle.LoadAsset <AudioClip>(key);
                    if (audio.LoadAudioData())
                    {
                        resourceManager.SoundResManager.ForceAdd(key, audio);
                    }
                    else
                    {
                        Debug.LogError($"AudioClip is not fully Loaded! name: {name}");
                    }
                }
                soundAssetBundle.Unload(false);
            }
        }
Exemplo n.º 15
0
    private void loadNextSample()
    {
        // If we have samples in our list
        if (sampleList.Count > 0)
        {
            // Take the first sample in the list
            currentClip = sampleList [0];

            // Now that we've got that sample stored as currentClip, remove it from sampleList
            sampleList.RemoveAt(0);

            sampleName = currentClip.name;

            if (!currentClip)
            {
                Debug.LogError("Error loading " + sampleName + " - not found");
                this.loadNextSample();
                return;
            }

            // Tell Unity to load the clip data from the device storage
            currentClip.LoadAudioData();

            // Send the sample data to Heavy
            extractSampleDataToHeavy();
        }
        else
        {
            // No samples left - we must be done
            Debug.Log("Done loading samples!");

            // Here is a good place to send a notification that all the
            // samples are now loaded to other parts of your Scene
        }
    }
Exemplo n.º 16
0
 private void NewSongSelected()
 {
     songFile          = new FileInfo(directorySelectorController.selectedItemFullName);
     songNameText.text = songFile.Name;
     project.songName  = songNameText.text;
     directorySelectorController.DeactivateSelection();
     if (songFile.Extension == ".wav" || songFile.Extension == ".ogg")
     {
         WWW www;
         www = new WWW("file:///" + songFile.FullName);
         while (!www.isDone)
         {
             ;                 //Wait until the song is fully downloaded
         }
         songAudioClip = www.GetAudioClip(true);
         songAudioClip.LoadAudioData();
     }
     else if (songFile.Extension == ".mp3")
     {
         AudioFileReader reader = new AudioFileReader(songFile.FullName);
         float[]         data   = new float[reader.Length / 4];
         reader.Read(data, 0, (int)reader.Length / 4);
         AudioClip newClip = AudioClip.Create("SongAudioClip", data.Length / reader.WaveFormat.Channels, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false);
         newClip.SetData(data, 0);
         songAudioClip = newClip;
         songAudioClip.LoadAudioData();
     }
     stage.musicSource.clip    = songAudioClip;
     stage.timeSlider.value    = 0.0f;
     stage.timeSlider.maxValue = songAudioClip.length;
     stage.OnSliderValueChanged();
 }
Exemplo n.º 17
0
    protected void LoadData()
    {
        this.Samples = new float[clip.samples];

        clip.LoadAudioData();
        clip.GetData(Samples, 0);
    }
Exemplo n.º 18
0
    /// <summary>
    /// Get an AudioClip at the given full path. Attempts to retrieve it from the AudioClipRegistry first by using folderRoot to extract the clip's name, otherwise attempts to load from disk.
    /// </summary>
    /// <param name="musicFilePath">Full path to a file.</param>
    /// <returns>AudioClip object on successful load, otherwise null.</returns>
    public static AudioClip getAudioClip(string folderRoot, string musicFilePath)
    {
        string    clipName = FileLoader.getRelativePathWithoutExtension(folderRoot, musicFilePath);
        AudioClip music    = AudioClipRegistry.Get(clipName);

        if (music != null)
        {
            return(music);
        }
        WWW www = new WWW(new Uri(musicFilePath).AbsoluteUri);

        while (!www.isDone)
        {
        }                       // hold up a bit while it's loading; delay isn't noticeable and loading will fail otherwise
        AudioType type = AudioType.UNKNOWN;

        if (musicFilePath.EndsWith(".ogg"))
        {
            type = AudioType.OGGVORBIS;
        }
        else if (musicFilePath.EndsWith(".wav"))
        {
            type = AudioType.WAV;
        }
        else
        {
            return(null);
        }
        music      = www.GetAudioClip(false, false, type);
        music.name = "File at " + musicFilePath;
        music.LoadAudioData();
        AudioClipRegistry.Set(clipName, music);
        return(music);
    }
Exemplo n.º 19
0
    public IEnumerator ProjectToLoadSelected(string fileName = null)
    {
        string   projectFullDir = fileName ?? directorySelectorController.selectedItemFullName;
        FileInfo projectFile;

        directorySelectorController.DeactivateSelection();
        dragAndDropFileName = null;
        yield return(StartCoroutine(projectSL.LoadProjectFromFile(res => project = res, res => songAudioClip = res, projectFullDir)));

        infoPanelButton.SetActive(true);
        chartsPanelButton.SetActive(true);
        songAudioClip.LoadAudioData();
        stage.musicSource.clip = songAudioClip;
        editPanelButton.SetActive(false);
        projectFile     = new FileInfo(projectFullDir);
        projectFileName = projectFile.Name.Remove(projectFile.Name.Length - 7, 7);
        projectFolder   = projectFile.FullName.Remove(projectFile.FullName.Length - projectFile.Name.Length, projectFile.Name.Length);
        filePanel.SetActive(false);
        currentInStage = -1;
        InfoInitialization();
        LvlInputFieldInit();
        yield return(new WaitForSeconds(3.0f));

        projectSL.loadCompleteText.SetActive(false);
    }
Exemplo n.º 20
0
 public void Btn_AAnuluj()
 {
     if (PanelWyjdz != null)
     {
         PanelWyjdz.SetActive(false);
         Guzik.LoadAudioData();
     }
 }
Exemplo n.º 21
0
 private void Awake()
 {
     animator    = GetComponent <Animator>();
     jumpingHash = Animator.StringToHash("Jumping");
     runningHash = Animator.StringToHash("Running");
     soundSystem = GetComponent <AudioSource>();
     jumpAudio.LoadAudioData();
 }
Exemplo n.º 22
0
 void Awake()
 {
     _selfCollider = GetComponent <CompositeCollider2D>();
     if (FallClip != null)
     {
         FallClip.LoadAudioData();
     }
 }
 //Initialization
 void Start()
 {
     spawnTime = spawnDelay;
     if (spawnSound != null)
     {
         spawnSound.LoadAudioData();
     }
 }
    private void Start()
    {
        FullSpaceClip.LoadAudioData();
        source     = this.GetComponent <AudioSource>();
        mainCamera = Camera.main;

        StartCoroutine(Spawn(delay));
    }
Exemplo n.º 25
0
    static int LoadAudioData(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AudioClip obj = LuaScriptMgr.GetUnityObject <AudioClip>(L, 1);
        bool      o   = obj.LoadAudioData();

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemplo n.º 26
0
    private static int LoadAudioData(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        AudioClip audioClip = (AudioClip)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AudioClip");
        bool      b         = audioClip.LoadAudioData();

        LuaScriptMgr.Push(L, b);
        return(1);
    }
Exemplo n.º 27
0
    // Start is called before the first frame update
    void Start()
    {
        vbBtnObj = GameObject.Find("btn");
        vbBtnObj.GetComponent <VirtualButtonBehaviour>().RegisterEventHandler(this);
        ani.GetComponent <Animator>();

        aud = GetComponent <AudioSource>();
        testTrack.LoadAudioData();
    }
 public static bool LoadIfPossible(this AudioClip clip)
 {
     if (clip.preloadAudioData)
     {
         return(false);
     }
     clip.LoadAudioData();
     return(true);
 }
Exemplo n.º 29
0
 protected override void OnTriggerEnter(Collider _collider)
 {
     if (_collider.gameObject.tag == "Player")
     {
         getitemSE.LoadAudioData();
         item_manager.ItemOnTriggerCall();
         AudioSource.PlayClipAtPoint(getitemSE, this.transform.position, 0.3f);
         Destroy(this.gameObject);
     }
 }
Exemplo n.º 30
0
    private void Start()
    {
        loopClip.LoadAudioData();
        introSource.clip = introClip;
        introSource.loop = false;
        introSource.Play();
        //musicSource.PlayOneShot(introClip, musicSource.volume);

        Invoke("PlayLoop", introClip.length + delay);
    }