public void Initialize(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem) { StopMusic(); soundEngine.StopAllSounds(); if (sounds != null) { foreach (var soundSource in sounds.Values) { if (soundSource != null) { soundSource.Dispose(); } } } this.loaders = loaders; this.fileSystem = fileSystem; Func <ISoundFormat, ISoundSource> loadIntoMemory = soundFormat => soundEngine.AddSoundSourceFromMemory( soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate); sounds = new Cache <string, ISoundSource>(filename => LoadSound(filename, loadIntoMemory)); currentSounds = new Dictionary <uint, ISound>(); video = null; }
ISoundSource LoadSound(string filename) { if (!Game.ModData.ModFiles.Exists(filename)) { Log.Write("sound", "LoadSound, file does not exist: {0}", filename); return(null); } using (var stream = Game.ModData.ModFiles.Open(filename)) { byte[] rawData; int channels; int sampleBits; int sampleRate; foreach (var loader in Game.ModData.SoundLoaders) { stream.Position = 0; if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate)) { return(soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate)); } } throw new InvalidDataException(filename + " is not a valid sound file!"); } }
ISoundSource LoadSound(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem, string filename) { if (!fileSystem.Exists(filename)) { Log.Write("sound", "LoadSound, file does not exist: {0}", filename); return(null); } using (var stream = fileSystem.Open(filename)) { ISoundFormat soundFormat; foreach (var loader in loaders) { stream.Position = 0; if (loader.TryParseSound(stream, out soundFormat)) { var source = soundEngine.AddSoundSourceFromMemory( soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate); soundFormat.Dispose(); return(source); } } } throw new InvalidDataException(filename + " is not a valid sound file!"); }
public SFX(byte[] song, string name) { ISoundEngine sfx = new ISoundEngine(); ISoundSource source = sfx.AddSoundSourceFromMemory(song, name); sfx.Play2D(source, false, false, true); }
public IrrklangPlayer(AudioClip clip) { if (!File.Exists(clip.CacheFileName)) { throw new AGSEditorException("AudioClip file is missing from the audio cache"); } if (Utilities.IsMonoRunning()) { _soundEngine = new ISoundEngine(SoundOutputDriver.AutoDetect); } else { // explicitly ask for the software driver as there seem to // be issues with ISound returning bad data when re-using // the same source and certain audio drivers _soundEngine = new ISoundEngine(SoundOutputDriver.WinMM); } // we have to read it into memory and then play from memory, // because the built-in Irrklang play from file function keeps // the file open and locked byte[] audioData = File.ReadAllBytes(clip.CacheFileName); _source = _soundEngine.AddSoundSourceFromMemory(audioData, clip.CacheFileName); _audioClip = clip; }
public void LoadMusic(ISoundEngine engine) { Stream stream = Application.GetResourceStream(GetFileUri()).Stream; int lenght = (int)stream.Length; byte[] buffer = new byte[lenght]; try { int count; int sum = 0; while ((count = stream.Read(buffer, sum, lenght - sum)) > 0) { sum += count; } } finally { stream.Close(); } engine.AddSoundSourceFromMemory(buffer, SoundName); }
static public void play(byte[] song, string name, bool repeat) { stop(); source = bgm.AddSoundSourceFromMemory(song, name); bgm.Play2D(source, repeat, false, true); }
static void Main(string[] args) { // start the sound engine with default parameters ISoundEngine engine = new ISoundEngine(); // To make irrKlang know about the memory we want to play, we register // the memory chunk as a sound source. We specify the name "testsound.wav", so // we can use the name later for playing back the sound. Note that you // could also specify a better fitting name like "ok.wav". // The method AddSoundSourceFromMemory() also returns a pointer to the created sound source, // it can be used as parameter for play2D() later, if you don't want to // play sounds via string names. ISoundSource source = engine.AddSoundSourceFromMemory(SoundDataArray, "testsound.wav"); // now play the sound until user presses 'q' Console.Out.WriteLine("\nPlaying sounds directly from memory"); Console.Out.WriteLine("Press any key to play some sound, press 'q' to quit."); do { // play the sound we added to memory engine.Play2D("testsound.wav"); }while(_getch() != 'q'); // user pressed 'q' key, cancel }
public SFX(byte[] song, string name) { ISoundEngine sfx = new ISoundEngine(); ISoundSource source = sfx.AddSoundSourceFromMemory(song, name); sfx.Play2D(source, false, false, true); }
private void addsource(ISoundEngine e, string path, string name) { using (FileStream s = new FileStream(path, FileMode.Open)) { byte[] SBuffer = new byte[s.Length]; s.Read(SBuffer, 0, (int)s.Length); // ISoundSource iss = e.AddSoundSourceFromMemory(SBuffer, name); // sourceKick = e.AddSoundSourceFromMemory(SBuffer, name); // so = e.AddSoundSourceFromMemory(SBuffer, name); sounds.Add(name); } }
public IrrklangPlayer(AudioClip clip) { if (!File.Exists(clip.CacheFileName)) { throw new AGSEditorException("AudioClip file is missing from the audio cache"); } _soundEngine = new ISoundEngine(SoundOutputDriver.AutoDetect); // we have to read it into memory and then play from memory, // because the built-in Irrklang play from file function keeps // the file open and locked byte[] audioData = File.ReadAllBytes(clip.CacheFileName); _source = _soundEngine.AddSoundSourceFromMemory(audioData, clip.CacheFileName); _audioClip = clip; }
public static void LoadSound(string name, string path) { List <byte> bin = new List <byte>(); using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { while (br.BaseStream.Position != br.BaseStream.Length) { bin.Add(br.ReadByte()); } } } //sounds.Add(name, bin.ToArray()); engine.AddSoundSourceFromMemory(bin.ToArray(), name); }
public bool Play(AudioClip clip) { if (!File.Exists(clip.CacheFileName)) { return(false); } // we have to read it into memory and then play from memory, // because the built-in Irrklang play from file function keeps // the file open and locked byte[] audioData = File.ReadAllBytes(clip.CacheFileName); ISoundSource source = _soundEngine.AddSoundSourceFromMemory(audioData, clip.CacheFileName); _soundPlaying = _soundEngine.Play2D(source, false, false, false); if (_soundPlaying == null) { return(false); } _audioClip = clip; _soundPlaying.setSoundStopEventReceiver(this); return(true); }
static ISoundSource LoadWave(WavLoader wave) { return(soundEngine.AddSoundSourceFromMemory(wave.RawOutput, wave.Channels, wave.BitsPerSample, wave.SampleRate)); }
static ISoundSource LoadSoundRaw(byte[] rawData) { return(soundEngine.AddSoundSourceFromMemory(rawData, 1, 16, 22050)); }
static void Main(string[] args) { // start the sound engine with default parameters ISoundEngine engine = new ISoundEngine(); // To make irrKlang know about the memory we want to play, we register // the memory chunk as a sound source. We specify the name "testsound.wav", so // we can use the name later for playing back the sound. Note that you // could also specify a better fitting name like "ok.wav". // The method AddSoundSourceFromMemory() also returns a pointer to the created sound source, // it can be used as parameter for play2D() later, if you don't want to // play sounds via string names. ISoundSource source = engine.AddSoundSourceFromMemory(SoundDataArray, "testsound.wav"); // now play the sound until user presses 'q' Console.Out.WriteLine("\nPlaying sounds directly from memory"); Console.Out.WriteLine("Press any key to play some sound, press 'q' to quit."); do { // play the sound we added to memory engine.Play2D("testsound.wav"); } while(_getch() != 'q'); // user pressed 'q' key, cancel }