Exemplo n.º 1
0
 private void PlatformLoadAudioStream(Stream s)
 {
     var data = new byte[s.Length];
     s.Read(data, 0, (int)s.Length);
     
     _audioBuffer = new Sound(data);
 }
Exemplo n.º 2
0
        public Town(EntityState es)
            : base(es)
        {
            Body = new Body(this, Vector2.Zero, new Vector2(20,15));
            Components.Add(Body);

            TileRender = new TileRender(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/town"), new Vector2(20, 15));
            Render = TileRender;
            Render.Scale = 6f;
            Render.Layer = 1f;
            Components.Add(Render);

            Body.Position = new Vector2(StateRef.GameRef.Viewport.Width/2 - Render.DrawRect.Width / 2, 450);
            DeadCityAnim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/deadcity"), new Vector2(20, 15), 4, "deadtown");
            DeadCityAnim.Layer = 1f;
            DeadCityAnim.Scale = 6.0f;

            Health = new Health(this, 100);
            Health.HurtEvent += ChangeColor;

            TileRender.Index = 2;
            Components.Add(Health);

            Gun = new Gun(this);
            Components.Add(Gun);

            Cursor = new Cursor(StateRef, this);
            StateRef.AddEntity(Cursor);

            Collision = new Collision(this);
            Components.Add(Collision);

            _fire = new Sound(this, es.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/bombfire"));
            Components.Add(_fire);
        }
Exemplo n.º 3
0
        public Bomb(EntityState es, Vector2 position, float angle, float thrust)
            : base(es)
        {
            Body = new Body(this, position) {Angle = angle};
            Components.Add(Body);

            Physics = new Physics(this);
            Physics.Thrust(thrust);
            Components.Add(Physics);

            _explodeanim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/explosion"),
                new Vector2(16,16), 30, "explode");
            _explodeanim.Layer = 0.2f;
            _explodeanim.Scale = 2.5f;
            _explodeanim.LastFrameEvent += Destroy;

            Render = new Render(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/bomb"));
            Render.Layer = 0.1f;
            Render.Scale = 1.5f;
            Components.Add(Render);

            Collision = new Collision(this);
            Collision.CollideEvent += CollisionHandler;
            Components.Add(Collision);

            _ee = new ExplosionEmitter(this);
            Components.Add(_ee);

            _se = new SmokeEmitter(this);
            Components.Add(_se);

            _explodesound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/explosion"));
            _explodesound.Volume = .5f;
            Components.Add(_explodesound);
        }
 private void PlatformInitialize(byte[] buffer, int sampleRate, int channels)
 {            
     var audioData = AudioUtil.FormatWavData(buffer, sampleRate, channels);
     _audioBuffer = new Sound(audioData);
         
     _soundPlayer = _audioBuffer.CreatePlayer();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Erstellt eine neue SoundEffect-Datei mit dem angegebenen Anzeigenamen und des angegebenen SoundEffect-Objekts.
 /// </summary>
 public SoundEffectFile(string name, SoundEffect soundEffect, Sound soundType)
 {
     Name = name;
     SoundEffect = soundEffect;
     Instance = soundEffect.CreateInstance ();
     SoundType = soundType;
 }
Exemplo n.º 6
0
 private void PlatformDispose(bool disposing)
 {
     if (disposing)
     {
         if (_audioBuffer != null)
             _audioBuffer.Dispose();
     }
     _audioBuffer = null;
 }
Exemplo n.º 7
0
        public bool Play()
        {
            if (_sound == null)
			    _sound = Sound.Create(_name, _volume, false);

			_sound.Play();
			
			return true;
        }
Exemplo n.º 8
0
		internal SoundEffect(string fileName)
		{
			_name = fileName;		
			
			if (_name == string.Empty )
			{
			  throw new FileNotFoundException("Supported Sound Effect formats are wav, mp3, acc, aiff");
			}
			
			_sound = new Sound(_name, 1.0f, false);
		}
        private void PlatformDispose(bool disposing)
        {
		    if (disposing)
            {
                if (_soundPlayer != null)
                {
                    _soundPlayer.Stop();
                    _soundPlayer.Dispose();
                }
                if (_audioBuffer != null)
                    _audioBuffer.Dispose();
            }
            _soundPlayer = null;
            _audioBuffer = null;
            soundState = SoundState.Stopped;
        }
Exemplo n.º 10
0
        public SnailsPace()
        {
            if (_instance != null)
            {
                throw new Exception("There was an attempt to create two Snail's Pace instances.");
            }
            _instance = this;

            graphics = new GraphicsDeviceManager(this);
            inputManager = new Input();
            soundManager = new Sound();
            gameConfig = new GameConfig();
            videoConfig = new VideoConfig();
            highScoreList = new Objects.HighScoreList();

            initializeGameScreens();
        }
Exemplo n.º 11
0
        public Soldier(EntityState es)
            : base(es)
        {
            Points = 10;

            Body = new Body(this, Vector2.Zero);
            Components.Add(Body);
            _soldieranim = new Animation(this, es.GameRef.Game.Content.Load<Texture2D>(@"game/soldier"), new Vector2(5, 10), 4,
                                   "soldier");
            Render = _soldieranim;
            Render.Flip = (_rand.RandomBool()) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            Render.Layer = .5f;
            _soldieranim.Start();
            Components.Add(Render);

            Body.Position.Y = 520 -  _rand.Next(-10,10);
            Body.Position.X = (Render.Flip == SpriteEffects.None) ? es.GameRef.Viewport.Right + 10 : -10;

            Collision = new Collision(this);
            Components.Add(Collision);

            Physics = new Physics(this);
            Physics.Velocity.X = (Render.Flip == SpriteEffects.None) ? -.25f : .25f;
            Components.Add(Physics);

            Health = new Health(this, 1);
            Health.DiedEvent += OnDeath;
            Components.Add(Health);

            _attacktimer = new Timer(this);
            _attacktimer.Milliseconds = 500;
            _attacktimer.LastEvent += OnAttackTimer;
            Components.Add(_attacktimer);

            _ge = new GibEmitter(this);
            Components.Add(_ge);

            _hitsound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/hit"));
            Components.Add(_hitsound);

            _attacksound = new Sound(this, StateRef.GameRef.Game.Content.Load<SoundEffect>(@"game/sounds/shoot"));
            _attacksound.Volume = .3f;
            Components.Add(_attacksound);
        }
Exemplo n.º 12
0
 public void Play(Sound sound)
 {
     switch (sound)
       {
     case Sound.Background:
       MediaPlayer.Play(background);
       MediaPlayer.IsRepeating = true;
       break;
     case Sound.Bounce:
       bounce.Play(0.1f, 0, 0);
       break;
     case Sound.Collide:
       //collide.Play(0.5f, 0, 0);
       break;
     case Sound.Hurt:
       hurt.Play();
       break;
       }
 }
Exemplo n.º 13
0
        public XactSound(SoundBank soundBank, BinaryReader soundReader, uint soundOffset)
        {
            long oldPosition = soundReader.BaseStream.Position;
            soundReader.BaseStream.Seek (soundOffset, SeekOrigin.Begin);

            byte flags = soundReader.ReadByte ();
            complexSound = (flags & 1) != 0;

            uint category = soundReader.ReadUInt16 ();
            soundReader.ReadByte (); //unkn
            uint volume = soundReader.ReadUInt16 (); //maybe pitch?
            soundReader.ReadByte (); //unkn
            uint entryLength = soundReader.ReadUInt16 ();

            uint numClips = 0;
            if (complexSound) {
                numClips = (uint)soundReader.ReadByte ();
            } else {
                uint trackIndex = soundReader.ReadUInt16 ();
                byte waveBankIndex = soundReader.ReadByte ();
                wave = soundBank.GetWave(waveBankIndex, trackIndex);
            }

            if ( (flags & 0x1E) != 0 ) {
                uint extraDataLen = soundReader.ReadUInt16 ();
                //TODO: Parse RPC+DSP stuff

                soundReader.BaseStream.Seek (extraDataLen, SeekOrigin.Current);
            }

            if (complexSound) {
                soundClips = new XactClip[numClips];
                for (int i=0; i<numClips; i++) {
                    soundReader.ReadByte (); //unkn
                    uint clipOffset = soundReader.ReadUInt32 ();
                    soundReader.ReadUInt32 (); //unkn

                    soundClips[i] = new XactClip(soundBank, soundReader, clipOffset);
                }
            }

            soundReader.BaseStream.Seek (oldPosition, SeekOrigin.Begin);
        }
Exemplo n.º 14
0
        public OggVorbisFile(string name, string filepath, Sound soundType)
        {
            Name = name;
            string cachefile = SystemInfo.DecodedMusicCache
                               + SystemInfo.PathSeparator.ToString ()
                               + soundType.ToString ()
                               + "_"
                               + name.GetHashCode ().ToString ()
                               + ".wav";

            Log.BlockList (id: 33, before: "  - ", after: "", begin: "Load ogg audio files:", end: "");
            Log.BlockList (id: 34, before: "  - ", after: "", begin: "Decode ogg audio files:", end: "");

            byte[] data;
            try {
                Log.ListElement (33, "[", soundType, "] ", name);
                data = File.ReadAllBytes (cachefile);
            }
            catch (Exception) {
                Log.ListElement (34, "[", soundType, "] ", name);
                OggDecoder decoder = new OggDecoder ();
                decoder.Initialize (TitleContainer.OpenStream (filepath));
                data = decoder.SelectMany (chunk => chunk.Bytes.Take (chunk.Length)).ToArray ();
                using (MemoryStream stream = new MemoryStream ())
                using (BinaryWriter writer = new BinaryWriter (stream)) {
                    WriteWave (writer, decoder.Stereo ? 2 : 1, decoder.SampleRate, data);
                    stream.Position = 0;
                    data = stream.ToArray ();
                }
                File.WriteAllBytes (cachefile, data);
            }

            using (MemoryStream stream = new MemoryStream (data)) {
                stream.Position = 0;
                SoundEffect soundEffect = SoundEffect.FromStream (stream);
                internalFile = new SoundEffectFile (name, soundEffect, soundType);
            }
        }
Exemplo n.º 15
0
        public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
        {
#if DIRECTX            
            Initialize(new WaveFormat(sampleRate, (int)channels), buffer, 0, buffer.Length, 0, buffer.Length);
#else
            //buffer should contain 16-bit PCM wave data
			short bitsPerSample = 16;

            _name = "";

			using (var mStream = new MemoryStream(44+buffer.Length))
            using (var writer = new BinaryWriter(mStream))
            {
                writer.Write("RIFF".ToCharArray()); //chunk id
                writer.Write((int)(36 + buffer.Length)); //chunk size
                writer.Write("WAVE".ToCharArray()); //RIFF type

                writer.Write("fmt ".ToCharArray()); //chunk id
                writer.Write((int)16); //format header size
                writer.Write((short)1); //format (PCM)
                writer.Write((short)channels);
                writer.Write((int)sampleRate);
                short blockAlign = (short)((bitsPerSample / 8) * (int)channels);
                writer.Write((int)(sampleRate * blockAlign)); //byte rate
                writer.Write((short)blockAlign);
                writer.Write((short)bitsPerSample);

                writer.Write("data".ToCharArray()); //chunk id
                writer.Write((int)buffer.Length); //data size 	MonoGame.Framework.Windows8.DLL!Microsoft.Xna.Framework.Audio.Sound.Sound(byte[] audiodata, float volume, bool looping) Line 199	C#

                writer.Write(buffer);

                _data = mStream.ToArray();
            }

			_sound = new Sound(_data, 1.0f, false);
#endif
        }
Exemplo n.º 16
0
 public void Dispose()
 {
     if (_sound != null)
         _sound.Dispose();
     _sound = null;
     mData = null;
 }
Exemplo n.º 17
0
		//SoundEffect from playable audio data
		internal SoundEffect(string name, byte[] data)
		{
			_data = data;
			_name = name;
			_sound = new Sound(_data, 1.0f, false);
		}        
Exemplo n.º 18
0
        internal SoundEffect(Stream s)
        {
#if !DIRECTX
            var data = new byte[s.Length];
            s.Read(data, 0, (int)s.Length);

            _data = data;
            _sound = new Sound(_data, 1.0f, false);
#endif
        }
Exemplo n.º 19
0
 public void Play(Sound sound)
 {
     sounds[sound.ToString()].Play();
 }
Exemplo n.º 20
0
        public static Sound CreateAndPlay(string url, float volume, bool looping)
        {
            Sound sound = new Sound(url, volume, looping);

            sound.Play();

            return sound;
        }
Exemplo n.º 21
0
 public SoundManager(Sound sound, bool Loop)
 {
     Load(sound);
     soundInstance.IsLooped = Loop;
 }
Exemplo n.º 22
0
        public WaveBank(AudioEngine audioEngine, string nonStreamingWaveBankFilename)
        {
            //XWB PARSING
            //Adapted from MonoXNA
            //Originally adaped from Luigi Auriemma's unxwb

            audioEngine.Wavebanks.Add(this);
            WaveBankHeader wavebankheader;
            WaveBankData   wavebankdata;
            WaveBankEntry  wavebankentry;

            wavebankdata.EntryNameElementSize = 0;
            wavebankdata.CompactFormat        = 0;
            wavebankdata.Alignment            = 0;

            wavebankentry.Format            = 0;
            wavebankentry.PlayRegion.Length = 0;
            wavebankentry.PlayRegion.Offset = 0;

            int wavebank_offset = 0;

            // Check for windows-style directory separator character
            nonStreamingWaveBankFilename = nonStreamingWaveBankFilename.Replace('\\', Path.DirectorySeparatorChar);

            BinaryReader reader = new BinaryReader(new FileStream(nonStreamingWaveBankFilename, FileMode.Open));

            reader.ReadBytes(4);

            wavebankheader.Version = reader.ReadInt32();

            int last_segment = 4;

            //if (wavebankheader.Version == 1) goto WAVEBANKDATA;
            if (wavebankheader.Version <= 3)
            {
                last_segment = 3;
            }
            if (wavebankheader.Version >= 42)
            {
                reader.ReadInt32();                                  // skip HeaderVersion
            }
            wavebankheader.Segments = new Segment[5];

            for (int i = 0; i <= last_segment; i++)
            {
                wavebankheader.Segments[i].Offset = reader.ReadInt32();
                wavebankheader.Segments[i].Length = reader.ReadInt32();
            }

            reader.BaseStream.Seek(wavebankheader.Segments[0].Offset, SeekOrigin.Begin);

            //WAVEBANKDATA:

            wavebankdata.Flags      = reader.ReadInt32();
            wavebankdata.EntryCount = reader.ReadInt32();

            if ((wavebankheader.Version == 2) || (wavebankheader.Version == 3))
            {
                wavebankdata.BankName = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(16)).Replace("\0", "");
            }
            else
            {
                wavebankdata.BankName = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(64)).Replace("\0", "");
            }

            BankName = wavebankdata.BankName;

            if (wavebankheader.Version == 1)
            {
                //wavebank_offset = (int)ftell(fd) - file_offset;
                wavebankdata.EntryMetaDataElementSize = 20;
            }
            else
            {
                wavebankdata.EntryMetaDataElementSize = reader.ReadInt32();
                wavebankdata.EntryNameElementSize     = reader.ReadInt32();
                wavebankdata.Alignment = reader.ReadInt32();
                wavebank_offset        = wavebankheader.Segments[1].Offset; //METADATASEGMENT
            }

            int compact_format;

            if ((wavebankdata.Flags & Flag_Compact) != 0)
            {
                compact_format = reader.ReadInt32();
            }

            int playregion_offset = wavebankheader.Segments[last_segment].Offset;

            if (playregion_offset == 0)
            {
                playregion_offset =
                    wavebank_offset +
                    (wavebankdata.EntryCount * wavebankdata.EntryMetaDataElementSize);
            }

            int segidx_entry_name = 2;

            if (wavebankheader.Version >= 42)
            {
                segidx_entry_name = 3;
            }

            int waveentry_offset = wavebankheader.Segments[segidx_entry_name].Offset;

            if ((wavebankheader.Segments[segidx_entry_name].Offset != 0) &&
                (wavebankheader.Segments[segidx_entry_name].Length != 0))
            {
                if (wavebankdata.EntryNameElementSize == -1)
                {
                    wavebankdata.EntryNameElementSize = 0;
                }
                byte[] entry_name = new byte[wavebankdata.EntryNameElementSize + 1];
                entry_name[wavebankdata.EntryNameElementSize] = 0;
            }

            sounds = new Sound[wavebankdata.EntryCount];

            for (int current_entry = 0; current_entry < wavebankdata.EntryCount; current_entry++)
            {
                reader.BaseStream.Seek(wavebank_offset, SeekOrigin.Begin);
                //SHOWFILEOFF;

                //memset(&wavebankentry, 0, sizeof(wavebankentry));


                if ((wavebankdata.Flags & Flag_Compact) != 0)
                {
                    int len = reader.ReadInt32();
                    wavebankentry.Format            = wavebankdata.CompactFormat;
                    wavebankentry.PlayRegion.Offset = (len & ((1 << 21) - 1)) * wavebankdata.Alignment;
                    wavebankentry.PlayRegion.Length = (len >> 21) & ((1 << 11) - 1);

                    // workaround because I don't know how to handke the deviation length

                    reader.BaseStream.Seek(wavebank_offset + wavebankdata.EntryMetaDataElementSize, SeekOrigin.Begin);
                    //MYFSEEK(wavebank_offset + wavebankdata.dwEntryMetaDataElementSize); // seek to the next
                    if (current_entry == (wavebankdata.EntryCount - 1))
                    {              // the last track
                        len = wavebankheader.Segments[last_segment].Length;
                    }
                    else
                    {
                        len = ((reader.ReadInt32() & ((1 << 21) - 1)) * wavebankdata.Alignment);
                    }
                    wavebankentry.PlayRegion.Length =
                        len -                             // next offset
                        wavebankentry.PlayRegion.Offset;  // current offset
                    goto wavebank_handle;
                }

                if (wavebankheader.Version == 1)
                {
                    wavebankentry.Format            = reader.ReadInt32();
                    wavebankentry.PlayRegion.Offset = reader.ReadInt32();
                    wavebankentry.PlayRegion.Length = reader.ReadInt32();
                    wavebankentry.LoopRegion.Offset = reader.ReadInt32();
                    wavebankentry.LoopRegion.Length = reader.ReadInt32();
                }
                else
                {
                    if (wavebankdata.EntryMetaDataElementSize >= 4)
                    {
                        wavebankentry.FlagsAndDuration = reader.ReadInt32();
                    }
                    if (wavebankdata.EntryMetaDataElementSize >= 8)
                    {
                        wavebankentry.Format = reader.ReadInt32();
                    }
                    if (wavebankdata.EntryMetaDataElementSize >= 12)
                    {
                        wavebankentry.PlayRegion.Offset = reader.ReadInt32();
                    }
                    if (wavebankdata.EntryMetaDataElementSize >= 16)
                    {
                        wavebankentry.PlayRegion.Length = reader.ReadInt32();
                    }
                    if (wavebankdata.EntryMetaDataElementSize >= 20)
                    {
                        wavebankentry.LoopRegion.Offset = reader.ReadInt32();
                    }
                    if (wavebankdata.EntryMetaDataElementSize >= 24)
                    {
                        wavebankentry.LoopRegion.Length = reader.ReadInt32();
                    }
                }

                if (wavebankdata.EntryMetaDataElementSize < 24)
                {                              // work-around
                    if (wavebankentry.PlayRegion.Length != 0)
                    {
                        wavebankentry.PlayRegion.Length = wavebankheader.Segments[last_segment].Length;
                    }
                }// else if(wavebankdata.EntryMetaDataElementSize > sizeof(WaveBankEntry)) {    // skip unused fields
                //   MYFSEEK(wavebank_offset + wavebankdata.EntryMetaDataElementSize);
                //}

wavebank_handle:
                wavebank_offset += wavebankdata.EntryMetaDataElementSize;
                wavebankentry.PlayRegion.Offset += playregion_offset;

                // Parse WAVEBANKMINIWAVEFORMAT

                int codec;
                int chans;
                int rate;
                int align;
                int bits;

                if (wavebankheader.Version == 1)
                {         // I'm not 100% sure if the following is correct
                    // version 1:
                    // 1 00000000 000101011000100010 0 001 0
                    // | |         |                 | |   |
                    // | |         |                 | |   wFormatTag
                    // | |         |                 | nChannels
                    // | |         |                 ???
                    // | |         nSamplesPerSec
                    // | wBlockAlign
                    // wBitsPerSample

                    codec = (wavebankentry.Format) & ((1 << 1) - 1);
                    chans = (wavebankentry.Format >> (1)) & ((1 << 3) - 1);
                    rate  = (wavebankentry.Format >> (1 + 3 + 1)) & ((1 << 18) - 1);
                    align = (wavebankentry.Format >> (1 + 3 + 1 + 18)) & ((1 << 8) - 1);
                    bits  = (wavebankentry.Format >> (1 + 3 + 1 + 18 + 8)) & ((1 << 1) - 1);

                    /*} else if(wavebankheader.dwVersion == 23) { // I'm not 100% sure if the following is correct
                     *  // version 23:
                     *  // 1000000000 001011101110000000 001 1
                     *  // | |        |                  |   |
                     *  // | |        |                  |   ???
                     *  // | |        |                  nChannels?
                     *  // | |        nSamplesPerSec
                     *  // | ???
                     *  // !!!UNKNOWN FORMAT!!!
                     *
                     *  //codec = -1;
                     *  //chans = (wavebankentry.Format >>  1) & ((1 <<  3) - 1);
                     *  //rate  = (wavebankentry.Format >>  4) & ((1 << 18) - 1);
                     *  //bits  = (wavebankentry.Format >> 31) & ((1 <<  1) - 1);
                     *  codec = (wavebankentry.Format                    ) & ((1 <<  1) - 1);
                     *  chans = (wavebankentry.Format >> (1)             ) & ((1 <<  3) - 1);
                     *  rate  = (wavebankentry.Format >> (1 + 3)         ) & ((1 << 18) - 1);
                     *  align = (wavebankentry.Format >> (1 + 3 + 18)    ) & ((1 <<  9) - 1);
                     *  bits  = (wavebankentry.Format >> (1 + 3 + 18 + 9)) & ((1 <<  1) - 1); */
                }
                else
                {
                    // 0 00000000 000111110100000000 010 01
                    // | |        |                  |   |
                    // | |        |                  |   wFormatTag
                    // | |        |                  nChannels
                    // | |        nSamplesPerSec
                    // | wBlockAlign
                    // wBitsPerSample

                    codec = (wavebankentry.Format) & ((1 << 2) - 1);
                    chans = (wavebankentry.Format >> (2)) & ((1 << 3) - 1);
                    rate  = (wavebankentry.Format >> (2 + 3)) & ((1 << 18) - 1);
                    align = (wavebankentry.Format >> (2 + 3 + 18)) & ((1 << 8) - 1);
                    bits  = (wavebankentry.Format >> (2 + 3 + 18 + 8)) & ((1 << 1) - 1);
                }

                reader.BaseStream.Seek(wavebankentry.PlayRegion.Offset, SeekOrigin.Begin);
                byte[] audiodata = reader.ReadBytes(wavebankentry.PlayRegion.Length);

                if (codec == MiniFormatTag_PCM)
                {
                    //write PCM data into a wav

                    MemoryStream mStream = new MemoryStream(44 + audiodata.Length);
                    BinaryWriter writer  = new BinaryWriter(mStream);

                    writer.Write("RIFF".ToCharArray());
                    writer.Write((int)(36 + audiodata.Length));
                    writer.Write("WAVE".ToCharArray());

                    writer.Write("fmt ".ToCharArray());
                    writer.Write((int)16);           //header size
                    writer.Write((short)1);          //format (PCM)
                    writer.Write((short)chans);
                    writer.Write((int)rate);         //sample rate
                    writer.Write((int)rate * align); //byte rate
                    writer.Write((short)align);
                    writer.Write((short)bits);

                    writer.Write("data".ToCharArray());
                    writer.Write((int)audiodata.Length);
                    writer.Write(audiodata);

                    writer.Close();
                    mStream.Close();

                    sounds[current_entry] = new Sound(mStream.ToArray(), 1.0f, false);
                }
                else if (codec == MiniForamtTag_WMA)     //WMA or xWMA (or XMA2)
                {
                    byte[] wmaSig = { 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x0, 0xaa, 0x0, 0x62, 0xce, 0x6c };

                    bool isWma = true;
                    for (int i = 0; i < wmaSig.Length; i++)
                    {
                        if (wmaSig[i] != audiodata[i])
                        {
                            isWma = false;
                            break;
                        }
                    }

                    if (isWma)
                    {
                        //WMA data can be played directly

                        //hack - NSSound can't play non-wav from data
                        string     wavFileName = Path.GetTempFileName().Replace(".tmp", ".wma");
                        FileStream wmaFile     = new FileStream(wavFileName, FileMode.Create, FileAccess.ReadWrite);
                        wmaFile.Write(audiodata, 0, audiodata.Length);
                        wmaFile.Close();

                        sounds[current_entry] = new Sound(wavFileName, 1.0f, false);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Exemplo n.º 23
0
 internal Cue(string cuename, Sound sound)
 {
     _name = cuename;
     _sound = sound;
 }
Exemplo n.º 24
0
        /* Creates a standalone SoundEffectInstance from given wavedata. */
        internal SoundEffectInstance(byte[] buffer, int sampleRate, int channels)
        {
            // buffer should contain 16-bit PCM wave data
            short bitsPerSample = 16;

            using (var mStream = new MemoryStream(44+buffer.Length))
            using (var writer = new BinaryWriter(mStream))
            {
                writer.Write("RIFF".ToCharArray()); //chunk id
                writer.Write((int)(36 + buffer.Length)); //chunk size
                writer.Write("WAVE".ToCharArray()); //RIFF type

                writer.Write("fmt ".ToCharArray()); //chunk id
                writer.Write((int)16); //format header size
                writer.Write((short)1); //format (PCM)
                writer.Write((short)channels);
                writer.Write((int)sampleRate);
                short blockAlign = (short)((bitsPerSample / 8) * (int)channels);
                writer.Write((int)(sampleRate * blockAlign)); //byte rate
                writer.Write((short)blockAlign);
                writer.Write((short)bitsPerSample);

                writer.Write("data".ToCharArray()); //chunk id
                writer.Write((int)buffer.Length); //data size

                writer.Write(buffer);

                _sound = new Sound(mStream.ToArray(), 1.0f, false);
                _sound.Rate = sampleRate;
            }
        }
Exemplo n.º 25
0
 private void LoadOggAudioFile(string filepath, string name, Sound soundType)
 {
     try {
         // erstelle ein OggVorbisFile-Objekt
         AudioFiles [soundType].Add (new OggVorbisFile (name, filepath, soundType));
     }
     catch (Exception ex) {
         // egal, warum das laden nicht klappt; mehr als die Fehlermeldung anzeigen
         // macht wegen einer fehlenden Musikdatei keinen Sinn
         Log.Debug ("Failed to load ogg audio file (", soundType, "): ", filepath);
         Log.Debug (ex);
     }
 }
Exemplo n.º 26
0
 public void PlaySound(Sound sound)
 {
     Log.Debug ("Sound: ", sound);
     if (AudioFiles [sound].Count > 0) {
         AudioFiles [sound].RandomElement ().Play ();
     }
     else {
         Log.Debug ("There are no audio files for: ", sound);
     }
 }
Exemplo n.º 27
0
 public static float Volume(Sound soundType)
 {
     return VolumeMap [soundType];
 }
Exemplo n.º 28
0
        // get some new randomness in this sucker
        public void Reroll()
        {
            try
            {
                // new sound instance plz
                _sound = null;

                int totWeight = 0;
                for (int i = 0; i < mData.mEntries.Length; i++)
                {
                    totWeight += mData.mEntries[i]._weight;
                }

                int weight = 0;
                switch (mData.mVariation)
                {
                    case 0: //kOrdered
                        mData.currIdx++;
                        if (mData.currIdx >= mData.mEntries.Length)
                            mData.currIdx = 0;
                        break;
                    case 2://kRandom
                        weight = GSGE.RandomMath.RandomInt(totWeight);
                        totWeight = 0;
                        mData.currIdx = 0;
                        for (int i = 0; i < mData.mEntries.Length; i++)
                        {
                            totWeight += mData.mEntries[i]._weight;
                            if (weight < totWeight)
                            {
                                mData.currIdx = i;
                                break;
                            }
                        }
                        break;
                    case 3://kRandomNoImmediateRepeat
                        if (mData.currIdx >= 0 && mData.currIdx < mData.mEntries.Length)
                            totWeight -= mData.mEntries[mData.currIdx]._weight;
                        else
                            mData.currIdx = 0;

                        weight = GSGE.RandomMath.RandomInt(totWeight);
                        totWeight = 0;
                        for (int i = 0; i < mData.mEntries.Length; i++)
                        {
                            if (i == mData.currIdx)
                                continue;

                            totWeight += mData.mEntries[i]._weight;
                            if (weight < totWeight)
                            {
                                mData.currIdx = i;
                                break;
                            }
                        }

                        break;
                    case 4://kShuffle
                        mData.shuffleIdx++;
                        if (mData.shuffleIdx >= mData.mEntries.Length)
                        {
                            mData.shuffleIdx = 0;

                            int i;

                            // reorder next random set
                            List<int> ls = new List<int>();
                            for (i = 0; i < mData.mEntries.Length; i++)
                            {
                                ls.Add(i);
                            }

                            i = 0;
                            while (ls.Count > 0)
                            {
                                int idx = GSGE.RandomMath.RandomInt(ls.Count);
                                mData.shuffle[i] = ls[idx];
                                ls.RemoveAt(idx);
                                i++;
                            }
                        }
                        mData.currIdx = mData.shuffle[mData.shuffleIdx];
                        break;
                    default:
                        throw new NotImplementedException();

                }
            }
            catch (Exception)
            {
                mData.currIdx = 0;
            }

            if (0 <= mData.currIdx && mData.currIdx < mData.mEntries.Length)
            {
                PlayWaveHelper pwh = mData.mEntries[mData.currIdx];

                AudioEngine audioengine = AudioManager.GetAudioManager().GetAudioEngine();
                foreach (WaveBank wavebank in audioengine.Wavebanks)
                {
                    if (wavebank.IsLoaded && wavebank.BankName == pwh._bankname)
                    {
                        if (0 <= pwh._index && wavebank.mSounds.Length > pwh._index)
                        {
                            SoundData sd = wavebank.mSounds[pwh._index];
                            sd.Looping = mData.mLoopCount == 255;
                            _sound = new Sound(sd);
                        }
                        break;
                    }
                }
                //GSGE.Debug.assert(_sound != null);

                mVolVar = RandomMath.RandomBetween(mData.mVolumeVariationMin, mData.mVolumeVariationMax) + mData.mVolume;
                mPitchVar = RandomMath.RandomBetween(mData.mPitchVariationMin, mData.mPitchVariationMax);
            }
        }
Exemplo n.º 29
0
 private void Load(Sound sound)
 {
     string file = Utils.GetCurrentDirectory() + "\\Data\\Sound\\" + sound.ToString() + ".wav";
     this.sound = Utils.LoadSound(file);
     soundInstance = this.sound.CreateInstance();
 }
Exemplo n.º 30
0
 public static void SetVolume(Sound soundType, float volume)
 {
     volume = ValidVolume (volume);
     VolumeMap [soundType] = volume;
     Config.Default ["volume", soundType.ToString (), 1] = volume;
     Log.Debug ("Set Volume (", soundType, "): ", volume);
 }
Exemplo n.º 31
0
		public SoundEffectInstance CreateInstance ()
		{
			var instance = new SoundEffectInstance();
			_sound = new Sound( _name, MasterVolume, false);
			instance.Sound = _sound;
			return instance;
			
		}