Example #1
0
            public override void Execute()
            {
                if (SimulationStep == 0)
                {
                    #region First step init
                    m_position = 0;
                    Owner.Features.Fill(0);
                    Owner.Label.Fill(0);

                    try
                    {   // load input data on simulation start
                        switch (Owner.m_UserInput)
                        {
                        case InputTypeEnum.SampleSound:
                            m_wavReader = new WavPlayer(GoodAI.SoundWorld.Properties.Resources.Digits_en_wav);
                            m_wavReader.m_SamplesPerSec = 32000;
                            m_wavReader.AttachTranscription(GoodAI.SoundWorld.Properties.Resources.Digits_en_txt);

                            m_InputData = m_wavReader.ReadShort(m_wavReader.m_length);
                            break;

                        case InputTypeEnum.UserDefined:
                            // reading corpus files
                            if (Owner.m_InputPathCorpus != "")
                            {
                                audio = Directory.GetFiles(Owner.m_InputPathCorpus, "*.wav");

                                m_wavReader = new WavPlayer(audio[m_currentCorpusFile]);
                                AttachTranscriptFileIfExists(audio[m_currentCorpusFile]);
                                m_currentCorpusFile = 1;
                                m_InputData         = m_wavReader.ReadShort(m_wavReader.m_length);
                            }
                            else
                            {
                                m_wavReader = new WavPlayer(Owner.m_InputPathAudio);
                                AttachTranscriptFileIfExists(Owner.m_InputPathAudio);
                                m_InputData = m_wavReader.ReadShort(m_wavReader.m_length);
                            }

                            break;
                        }
                    }
                    catch (Exception)
                    {
                        MyLog.ERROR.WriteLine("Not a valid sound device!");
                    }
                    #endregion
                }

                if (SimulationStep % ExpositionTime == 0)
                {
                    #region Every time step
                    if (m_InputData == null)
                    {
                        return;
                    }

                    int     size   = 0;
                    float[] result = new float[Owner.FeaturesCount];

                    // process data according to chosen feature type
                    switch (Owner.FeaturesType)
                    {
                    case FeatureType.Samples:
                        result = PrepareInputs(Owner.FeaturesCount);
                        break;

                    case FeatureType.FFT:
                        // input size must be power of 2 and double sized due to the mirror nature of FFT
                        size   = NextPowerOf2(Owner.FeaturesCount * 2);
                        result = PerformFFT(PrepareInputs(size));
                        //result = PerformFFT(GenerateSine(size));  // generate a test sine signal
                        break;

                    case FeatureType.MFCC:
                        result = WindowFunction.Hanning(PrepareInputs(256));
                        result = PerformFFT(result);
                        result = MFCC.Compute(result, player.m_SamplesPerSec, Owner.FeaturesCount);
                        break;

                    case FeatureType.LPC:
                        result = WindowFunction.Hanning(PrepareInputs(256));
                        result = LPC.Compute(result, Owner.FeaturesCount);
                        break;
                    }
                    #endregion

                    // flush processed features into GPU
                    Array.Clear(Owner.Features.Host, 0, Owner.Features.Count);
                    for (int i = 0; i < Owner.FeaturesCount; i++)
                    {
                        Owner.Features.Host[i] = result[i];
                    }
                    Owner.Features.SafeCopyToDevice();
                }
            }
Example #2
0
        static void Main(string[] args)
        {
            game     = new Game("My SFXT Playground", 640, 480, 60, 60);
            activity = new Activity(game);
            game.PushActivity(activity);

            var texturePacker = new TexturePacker(4096);

            /*
             * var basicSpriteTexture = new SFML.Graphics.Texture("BasicSprite.png");
             * ITexels basicSpriteTexels = new TexelsTexture(basicSpriteTexture);
             *
             * var animatedSpriteTexture = new SFML.Graphics.Texture("AnimatedSprite.png");
             * ITexels animatedSpriteTexels = new TexelsTexture(animatedSpriteTexture);
             */

            var basicSpriteTexels    = texturePacker.PackTexture(new SFML.Graphics.Texture("BasicSprite.png"));
            var animatedSpriteTexels = texturePacker.PackTexture(new SFML.Graphics.Texture("AnimatedSprite.png"));

            var playerEntity = new TestEntity(activity);

            //var lpcTexture = new TexelsTexture(new SFML.Graphics.Texture("LPCSprite.png"));
            var lpcTexture = texturePacker.PackTexture(new SFML.Graphics.Texture("LPCSprite.png"));

            var playerSprite = LPC.Create(playerEntity, lpcTexture);
            var runAnimation = new AnimatedSprite.LoopingAnimation();

            playerEntity.Scale = 1f;
            playerEntity.AddComponent(playerSprite);
            playerEntity.IsPlayerControlled = true;

            playerSprite.Play(LPC.IdleLoop);

            activity.AddEntity(playerEntity);

            activity.AddEntity(new ConsoleInfoEntity(activity));

            var mapEntity = new MapEntity(activity);

            mapEntity.Scale    = 2;
            mapEntity.Rotation = 20.0f;
            var tilesheet = new TexelsTexture(new SFML.Graphics.Texture("tilesheet.png"));
            var map       = new Tilemap(mapEntity, 64, 64, tilesheet);

            uint[][] tiles = new uint[25][];

            for (uint x = 0; x < 25; x++)
            {
                tiles[x] = new uint[25];

                for (int y = 0; y < 25; y++)
                {
                    tiles[x][y] = 18;
                }
            }

            for (int x = 0; x < 25; x++)
            {
                tiles[x][0]  = 1;
                tiles[x][24] = 35;
            }

            for (int y = 0; y < 25; y++)
            {
                tiles[0][y]  = 17;
                tiles[24][y] = 19;
            }

            tiles[0][0]   = 0;
            tiles[24][0]  = 2;
            tiles[0][24]  = 34;
            tiles[24][24] = 36;

            map.SetTileData(tiles);

            mapEntity.AddComponent(map);
            mapEntity.Layer--;

            activity.AddEntity(mapEntity);

            var rng = new Random();

            string[] filePaths = Directory.GetFiles("LPC-Prefabs");

            var textureList = new List <ITexels>();

            foreach (var file in filePaths)
            {
                textureList.Add(texturePacker.PackTexture(new Texture(file)));
            }

            for (int i = 0; i < 5000; i++)
            {
                var newEnt = new TestEntity(activity);
                newEnt.AddComponent(LPC.Create(newEnt, textureList[rng.Next(textureList.Count)]));
                newEnt.Position = map.GetRandomPoint(rng);
                activity.AddEntity(newEnt);
            }

            chaseEnt = playerEntity;
            activity.OnEntityAdded += CameraSetup;

            game.OnUpdateBegin += HandleFirstUpdate;

            game.Run();
        }