Example #1
0
        /*
         *      public static void AudioPlay(object nativeSound)
         *      {
         *              SdlDotNet.Audio.Sound sdlSound = (SdlDotNet.Audio.Sound)nativeSound;
         *              try
         *              {
         *                      sdlSound.Play();
         *              }
         *              catch (SdlDotNet.Core.SdlException)
         *              {
         *                      // No free channels or other hardware exceptions should just fail silently (no pun intended).
         *              }
         *      }//*/

        public static void AudioStop(object nativeSound)
        {
            SdlDotNet.Audio.Sound sdlSound = (SdlDotNet.Audio.Sound)nativeSound;
            try
            {
                sdlSound.Stop();
            }
            catch (SdlDotNet.Core.SdlException) { }
        }
Example #2
0
 private void play(SdlDotNet.Audio.Sound input, int volume)
 {
     if (input != null)
     {
         input.NumberOfChannels = 1000;
         input.Volume           = volume;
         input.Play();
     }
 }
Example #3
0
        private void init_hash_sdl()
        {
            samples = new Hashtable();
            DirectoryInfo[] instrument_dir;
            try
            {
                DirectoryInfo di    = new DirectoryInfo(Directory.GetCurrentDirectory());
                bool          found = false;
                for (int j = 0; (j < 3) && (found == false); j++)
                {
                    for (int i = 0; i < di.GetDirectories().Length; i++)
                    {
                        if (di.GetDirectories()[i].Name == "ogg")
                        {
                            instrument_dir = di.GetDirectories()[i].GetDirectories();
                            foreach (DirectoryInfo d in instrument_dir)
                            {
                                Sound_List temp = new Sound_List();
                                try
                                {
                                    foreach (FileInfo f in d.GetFiles())
                                    {
                                        if (f.Extension.ToLower() == ".ogg")
                                        {
                                            Sound_Stream_sdl sound = new SdlDotNet.Audio.Sound(f.FullName);
                                            if (sound == null)
                                            {
                                                throw (new Exception("Sound " + f.FullName.ToString() + " not working"));
                                            }
                                            temp.Add(sound);
                                        }
                                    }
                                }

                                catch (Exception e)
                                {
                                    MessageBox.Show("error with directory " + d.Name.ToString() + "\n" + e.ToString());
                                }
                                samples.Add(((string)d.Name.ToLower()), temp);
                            }
                            found = true;
                        }
                    }
                    di = di.Parent;
                }
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show(e.ToString() + e.Message.ToString());
            }
        }
 public Pistol(Surface video, Point positionHero, int angle, Manager manager) : base(video, positionHero)
 {
     this.video   = video;
     this.angle   = angle;
     this.manager = manager;
     weaponSound  = new SdlDotNet.Audio.Sound(@"Assets\Sounds\pistol_sound.wav");
     posRelToHero = positionHero;
     rndm         = new Random();
     bulletList   = new List <Bullet>();
     cooldown     = 500; // in ms
     damage       = 4;
     pistolRight  = new Surface(@"Assets\Sprites\guns\pistol_r.png");
     pistolLeft   = pistolRight.CreateFlippedHorizontalSurface();
 }
Example #5
0
 public static object AudioSoundPlay(object rawRes, double volume, double pan)
 {
     SdlDotNet.Audio.Sound sfx = (SdlDotNet.Audio.Sound)rawRes;
     try
     {
         SdlDotNet.Audio.Channel channel = sfx.Play();
         AudioApplyVolumeAndPan(channel, volume, pan);
         return(channel);
     }
     catch (SdlDotNet.Core.SdlException)
     {
         return(null);
     }
 }
Example #6
0
        public static void AudioSoundStop(object rawChannel, object rawResource, int resourceId, bool isActivelyPlaying, bool isHardStop)
        {
            SdlDotNet.Audio.Channel channel  = (SdlDotNet.Audio.Channel)rawChannel;
            SdlDotNet.Audio.Sound   resource = (SdlDotNet.Audio.Sound)rawResource;

            if (isHardStop)
            {
                channel.Stop();
            }
            else if (isActivelyPlaying)
            {
                channel.Pause();
            }
        }
 public Smg(Surface video, Point positionHero, int angle, Manager manager) : base(video, positionHero)
 {
     this.video   = video;
     this.angle   = angle;
     this.manager = manager;
     weaponSound  = new SdlDotNet.Audio.Sound(@"Assets\Sounds\smg_sound.wav");
     posRelToHero = positionHero;
     rndm         = new Random();
     bulletList   = new List <Bullet>();
     cooldown     = 250;
     damage       = 2;
     smgRight     = new Surface(@"Assets\Sprites\guns\smg_r.png");
     smgLeft      = smgRight.CreateFlippedHorizontalSurface();
     smgToUse     = smgRight;    // zichtbare smg
 }
Example #8
0
        private void Init()
        {
            useSound = true;
            byte[] BeepData = new byte[Sharp8.Properties.Resources.beep.Length];
            Sharp8.Properties.Resources.beep.Read(BeepData, 0, (int)Sharp8.Properties.Resources.beep.Length);
            BeepSound = new SdlDotNet.Audio.Sound(BeepData);
            BeepChan  = BeepSound.Play(true);
            BeepChan.Pause();
            memory      = new MemoryHandler();
            registers   = new byte[0x10];
            RandGen     = new Random();
            surfaceOut  = Video.CreateRgbSurface(640, 320);
            PixelB      = Video.CreateRgbSurface(10, 10);
            PixelW      = Video.CreateRgbSurface(10, 10);
            SCHIPPixelB = Video.CreateRgbSurface(5, 5);
            SCHIPPixelW = Video.CreateRgbSurface(5, 5);
            PixelB.Fill(Color.Black);
            PixelW.Fill(Color.White);
            SCHIPPixelB.Fill(Color.Black);
            SCHIPPixelW.Fill(Color.White);
            ScreenData = new bool[128, 64];

            programStack = new Stack <ushort>(16);
        }
Example #9
0
        /// <summary>
        /// Parse the VDX to locate individual chunks
        /// </summary>
        private void parseVDX(GJD.RLData? rlData)
        {
            long stop;
            // Final stream position
            if (rlData.HasValue)
            {
                stop = rlData.Value.offset + rlData.Value.length;
            }
            else
            {
                stop = file.BaseStream.Length;
            }
            VDXHeader header = new VDXHeader();
            VDXChunkHeader chunk = new VDXChunkHeader();

            // Initialise queue's
            audioOffsets = new Queue<long>();
            videoOffsets = new Queue<long>();

            // Read VDX header
            header.ID = file.ReadUInt16();
            if (header.ID != 0x9267)
                throw new Exception("Invalid VDX header");

            header.Unknown1 = file.ReadByte();
            header.Unknown2 = file.ReadByte();
            header.Unknown3 = file.ReadByte();
            header.Unknown4 = file.ReadByte();
            header.FPS = file.ReadUInt16();

            //fps = (byte)header.FPS;
            try
            {
                while (file.BaseStream.Position < stop)
                {
                    // Read VDX chunk header
                    chunk = readChunkHeader();

                    // Add offsets where appropriate
                    switch (chunk.BlockType)
                    {
                        case VDXBlockType.Video:
                            videoFrames++;
                            goto case VDXBlockType.Zero;
                        case VDXBlockType.Zero:
                            videoMaster.Enqueue(file.BaseStream.Position - VDXChunkHeader.size);
                            break;
                        case VDXBlockType.Sound:
                            audioOffsets.Enqueue(file.BaseStream.Position - VDXChunkHeader.size);
                            break;
                        case VDXBlockType.Image:
                            imageOffset = file.BaseStream.Position - VDXChunkHeader.size;
                            break;
                    }

                    // Seek to next chunk
                    file.BaseStream.Seek(chunk.DataSize, System.IO.SeekOrigin.Current);
                }
            } catch {
                audio = null;
                videoFrames = 1;

            }
        }
Example #10
0
        /// <summary>
        /// Separate out audio stream for playback
        /// </summary>
        private void parseAudio()
        {
            // Check for null audio
            if (audioOffsets.Count == 0)
                return;

            // Set up buffer
            MemoryStream buffer = new MemoryStream();
            buffer.Write(WavHeader, 0, WavHeader.Length);

            while (audioOffsets.Count > 0)
            {
                // Find next audio chunk
                file.BaseStream.Seek(audioOffsets.Dequeue(), System.IO.SeekOrigin.Begin);

                // Read header
                VDXChunkHeader chunk = readChunkHeader();

                if (chunk.BlockType != VDXBlockType.Sound)
                    throw new Exception("Invalid block type");

                // Check for compression
                if (chunk.LengthBits == 0 || chunk.LengthMask == 0)
                {
                    // No compression - direct copy
                    byte[] t;// = new byte[chunk.DataSize];
                    t = file.ReadBytes(chunk.DataSize);
                    buffer.Write(t, 0, t.Length);
                }
                else
                {
                    // Decompress and copy
                    System.IO.MemoryStream t;
                    decompress(file, ref chunk, out t);
                    t.Position = 0;
                    t.WriteTo(buffer);
                }
            }

            // Little messy but only runs on VDX load at this stage
            byte[] audiob = buffer.ToArray();
            int g = audiob.Length - 8;

            audiob[7] = (byte)((g & 0xFF000000) >> 24);
            audiob[6] = (byte)((g & 0xFF0000) >> 16);
            audiob[5] = (byte)((g & 0xFF00) >> 8);
            audiob[4] = (byte)(g & 0xFF);

            g = audiob.Length - 44;

            audiob[43] = (byte)((g & 0xFF000000) >> 24);
            audiob[42] = (byte)((g & 0xFF0000) >> 16);
            audiob[41] = (byte)((g & 0xFF00) >> 8);
            audiob[40] = (byte)(g & 0xFF);

            audioLength = Math.Ceiling(g / (decimal)22);
            audioBuffer = audiob;
            audio = new SdlDotNet.Audio.Sound(audiob);
        }