slightly more usable sound support

This commit is contained in:
Chris Forbes
2009-10-14 20:12:28 +13:00
parent 60a24a5415
commit 1c7bf80166
2 changed files with 23 additions and 8 deletions

View File

@@ -4,7 +4,8 @@ using OpenRa.Game.Graphics;
using OpenRa.TechTree; using OpenRa.TechTree;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using IrrKlang; using IrrKlang;
using IjwFramework.Collections;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -57,20 +58,32 @@ namespace OpenRa.Game
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
worldRenderer = new WorldRenderer(renderer, this); worldRenderer = new WorldRenderer(renderer, this);
var sound = AudLoader.LoadSound(FileSystem.Open("intro.aud"));
soundEngine = new ISoundEngine(); soundEngine = new ISoundEngine();
sounds = new Cache<string, ISoundSource>(LoadSound);
var soundSource = soundEngine.AddSoundSourceFromPCMData(sound, "intro.aud",
PlaySound("intro.aud", false);
}
readonly Cache<string, ISoundSource> sounds;
ISoundSource LoadSound(string filename)
{
var data = AudLoader.LoadSound(FileSystem.Open(filename));
return soundEngine.AddSoundSourceFromPCMData(data, filename,
new AudioFormat() new AudioFormat()
{ {
ChannelCount = 1, ChannelCount = 1,
FrameCount = sound.Length / 2, FrameCount = data.Length / 2,
Format = SampleFormat.Signed16Bit, Format = SampleFormat.Signed16Bit,
SampleRate = 22050 SampleRate = 22050
}); });
}
soundEngine.Play2D(soundSource, true, false, true); public void PlaySound(string name, bool loop)
{
var sound = sounds[name];
// todo: positioning
soundEngine.Play2D(sound, loop, false, false);
} }
public void Tick() public void Tick()

View File

@@ -30,7 +30,9 @@ namespace OpenRa.Game
FileSystem.Mount(new Package("conquer.mix")); FileSystem.Mount(new Package("conquer.mix"));
FileSystem.Mount(new Package("hires.mix")); FileSystem.Mount(new Package("hires.mix"));
FileSystem.Mount(new Package("general.mix")); FileSystem.Mount(new Package("general.mix"));
FileSystem.Mount(new Package("local.mix")); FileSystem.Mount(new Package("local.mix"));
FileSystem.Mount(new Package("sounds.mix"));
FileSystem.Mount(new Package("speech.mix"));
FormBorderStyle = FormBorderStyle.None; FormBorderStyle = FormBorderStyle.None;
BackColor = Color.Black; BackColor = Color.Black;