public static WaveHeader ReadWaveHeader(Stream stream) { if (stream == null) { return((WaveHeader)null); } using (BinaryReader reader = new BinaryReader(stream)) return(WaveHeader.ReadWaveHeader(reader)); }
public static AudioClip Load( string path, long SongLength, uAudio.uAudio_backend.uAudio uAudio, ref string szErrorMs) { string extension = Path.GetExtension(path); if (extension == ".wav" || extension == ".WAV") { WaveHeader waveHeader = WaveHeader.ReadWaveHeader(path); float[] rangedRawData = ExternalAudioClip.CreateRangedRawData(path, waveHeader.TrueWavBufIndex, waveHeader.TrueSamples, (int)waveHeader.Channels, (int)waveHeader.BitPerSample); return(rangedRawData.Length == 0 ? (AudioClip)null : ExternalAudioClip.CreateClip(Path.GetFileNameWithoutExtension(path), rangedRawData, waveHeader.TrueSamples, (int)waveHeader.Channels, waveHeader.Frequency)); } if (!(extension == ".mp3") && !(extension == ".MP3")) { return((AudioClip)null); } mp3AudioClip._uAudio = uAudio; AudioClip audioClip = mp3AudioClip.LoadMp3(path, SongLength); szErrorMs = mp3AudioClip.szErrorMs; return(audioClip); }
public static WaveHeader ReadWaveHeader(string path) { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) return(WaveHeader.ReadWaveHeader((Stream)fileStream)); }