Beispiel #1
0
 public void PlayLocal(string audioName, int pitch = -1, SoundContext sound_context = SoundContext.Default)
 {
     if ((!Game1.eventUp || sound_context != SoundContext.NPC) && Game1.currentLocation == location)
     {
         _PlayAudio(audioName, pitch);
     }
 }
Beispiel #2
0
        private bool IsRegular(WordPair wordPair, IWordAlignerResult alignerResult, Alignment <Word, ShapeNode> alignment, int column,
                               Ngram <Segment> v)
        {
            VarietyPair  vp      = wordPair.VarietyPair;
            SoundContext context = alignment.ToSoundContext(_segmentPool, 0, column, alignerResult.WordAligner.ContextualSoundClasses);
            FrequencyDistribution <Ngram <Segment> > freqDist = vp.CognateSoundCorrespondenceFrequencyDistribution[context];
            int threshold;

            if (AutomaticRegularCorrespondenceThreshold)
            {
                int seg2Count = vp.CognateSoundCorrespondenceFrequencyDistribution.Conditions
                                .Where(sc => sc.LeftEnvironment == context.LeftEnvironment && sc.RightEnvironment == context.RightEnvironment)
                                .Sum(sc => vp.CognateSoundCorrespondenceFrequencyDistribution[sc][v]);
                if (!_regularCorrespondenceThresholdTable.TryGetThreshold(vp.CognateCount, freqDist.SampleOutcomeCount, seg2Count,
                                                                          out threshold))
                {
                    threshold = DefaultRegularCorrespondenceThreshold;
                }
            }
            else
            {
                threshold = DefaultRegularCorrespondenceThreshold;
            }
            return(freqDist[v] >= threshold);
        }
Beispiel #3
0
        private int GetMaxSoundChangeScore(Word word, ShapeNode node, Word otherWord)
        {
            if (word.Variety == otherWord.Variety)
            {
                return(0);
            }

            VarietyPair varietyPair = word.Variety.VarietyPairs[otherWord.Variety];

            if (varietyPair.SoundChangeProbabilityDistribution == null)
            {
                return(0);
            }

            double prob;

            if (varietyPair.Variety1 == word.Variety)
            {
                SoundContext lhs = node.ToSoundContext(_segmentPool, _contextualSoundClasses);
                prob = varietyPair.DefaultCorrespondenceProbability;
                IProbabilityDistribution <Ngram <Segment> > probDist;
                if (varietyPair.SoundChangeProbabilityDistribution.TryGetProbabilityDistribution(lhs, out probDist) && probDist.Samples.Count > 0)
                {
                    prob = probDist.Samples.Max(nseg => probDist[nseg]);
                }
            }
            else
            {
                Ngram <Segment> corr = _segmentPool.GetExisting(node);
                prob = varietyPair.SoundChangeProbabilityDistribution.Conditions.Count == 0 ? 0
                                        : varietyPair.SoundChangeProbabilityDistribution.Conditions.Max(lhs => varietyPair.SoundChangeProbabilityDistribution[lhs][corr]);
            }
            return((int)(MaxSoundChangeScore * prob));
        }
Beispiel #4
0
        private void UpdateSelectedChangeWordPairs(WordPairsViewModel wordPairs)
        {
            IWordAligner aligner = _projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];

            wordPairs.SelectedCorrespondenceWordPairs.Clear();
            foreach (WordPairViewModel wordPair in wordPairs.WordPairs)
            {
                bool selected = false;
                foreach (AlignedNodeViewModel node in wordPair.AlignedNodes)
                {
                    if (_selectedSoundChange == null)
                    {
                        node.IsSelected = false;
                    }
                    else
                    {
                        SoundContext    lhs  = wordPair.DomainAlignment.ToSoundContext(_segmentPool, 0, node.Column, aligner.ContextualSoundClasses);
                        Ngram <Segment> corr = wordPair.DomainAlignment[1, node.Column].ToNgram(_segmentPool);
                        node.IsSelected = lhs.Equals(_selectedSoundChange.DomainSoundChangeLhs) && corr.Equals(_selectedSoundChange.DomainCorrespondence);
                        if (node.IsSelected)
                        {
                            selected = true;
                        }
                    }
                }

                if (selected)
                {
                    wordPairs.SelectedCorrespondenceWordPairs.Add(wordPair);
                }
            }
        }
Beispiel #5
0
        public SoundController(SoundContext context)
        {
            _context = context;

            if (_context.Sounds.Count() == 0)
            {
                string[] directories = Directory.GetDirectories("./wwwroot/sounds/");

                for (int x = 0; x < directories.Length; x++)
                {
                    string[] files = Directory.GetFiles(directories[x], "*.wav", SearchOption.TopDirectoryOnly);
                    string   type  = directories[x].Substring(17);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string url             = files[i].Substring(9);
                        int    titleStartIndex = url.IndexOf('/', 8) + 1;
                        //I really want to put titleEndex but like... I feel like it would be confusing when you read it for the first time. But I think it's funny.
                        int    titleEndIndex = url.IndexOf('.', url.Length - 5);
                        string title         = url.Substring(titleStartIndex, titleEndIndex - titleStartIndex);
                        _ = _context.Sounds.Add(new SoundItem {
                            url = url, title = title, type = type
                        });
                        _context.SaveChanges();
                    }
                }
            }
        }
Beispiel #6
0
 public void PlayLocalAt(string audioName, Vector2 position, int pitch = -1, SoundContext sound_context = SoundContext.Default)
 {
     if (position == Vector2.Zero || Utility.isOnScreen(position * 64f, 384))
     {
         PlayLocal(audioName, pitch, sound_context);
     }
 }
Beispiel #7
0
 public void PlayLocalAt(string audioName, Vector2 position, int pitch = -1, SoundContext sound_context = SoundContext.Default)
 {
     if (CanHear(position))
     {
         PlayLocal(audioName, pitch, sound_context);
     }
 }
Beispiel #8
0
 public SoundChangeViewModel(SoundContext lhs, Ngram<Segment> correspondence, double probability, int frequency)
 {
     _domainLhs = lhs;
     _correspondence = correspondence;
     _lhs = new SoundChangeLhsViewModel(lhs);
     _prob = probability;
     _frequency = frequency;
 }
Beispiel #9
0
 public ServerSoundEntityFactory(SoundContext context,
                                 PlayerContext playerContext,
                                 IEntityIdGenerator idGenerator,
                                 ICurrentTime currentTime,
                                 ISoundConfigManager soundConfigManager) : base(context, idGenerator, currentTime, soundConfigManager)
 {
     _playerContext = playerContext;
 }
Beispiel #10
0
 public SoundChangeViewModel(SoundContext lhs, Ngram <Segment> correspondence, double probability, int frequency)
 {
     _domainLhs      = lhs;
     _correspondence = correspondence;
     _lhs            = new SoundChangeLhsViewModel(lhs);
     _prob           = probability;
     _frequency      = frequency;
 }
Beispiel #11
0
        private void handleAudioEvent(BinaryReader reader)
        {
            string       audioName = reader.ReadString();
            Vector2      position  = reader.ReadVector2();
            int          pitch     = reader.ReadInt32();
            SoundContext context   = (SoundContext)reader.ReadInt32();

            PlayLocalAt(audioName, position, pitch, context);
        }
Beispiel #12
0
 public Sound(Uri filePath, string soundName, string fileName, SoundContext soundContext, SoundType soundType, byte[] resource)
 {
     FilePath     = filePath;
     SoundName    = soundName;
     FileName     = fileName;
     SoundContext = soundContext;
     SoundType    = soundType;
     Resource     = resource;
 }
Beispiel #13
0
 private void UpdateCognateCorrespondenceCounts(IWordAligner aligner, ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> > cognateCorrCounts,
                                                Alignment <Word, ShapeNode> alignment)
 {
     for (int column = 0; column < alignment.ColumnCount; column++)
     {
         SoundContext    lhs  = alignment.ToSoundContext(_segmentPool, 0, column, aligner.ContextualSoundClasses);
         Ngram <Segment> corr = alignment[1, column].ToNgram(_segmentPool);
         cognateCorrCounts[lhs].Increment(corr);
     }
 }
Beispiel #14
0
 public ClientSoundEntityFactory(SoundContext context,
                                 IEntityIdGenerator idGenerator,
                                 ICurrentTime currentTime,
                                 ISoundConfigManager soundConfigManager)
 {
     _soundContext       = context;
     _idGenerator        = idGenerator;
     _currentTime        = currentTime;
     _soundConfigManager = soundConfigManager;
 }
Beispiel #15
0
        public VarietyPair ToVarietyPair(SegmentPool segmentPool, CogProject project)
        {
            var vp = new VarietyPair(project.Varieties[Variety1], project.Varieties[Variety2])
            {
                PhoneticSimilarityScore          = PhoneticSimilarityScore,
                LexicalSimilarityScore           = LexicalSimilarityScore,
                DefaultCorrespondenceProbability = DefaultCorrespondenceProbability
            };
            var wordPairs = new Dictionary <WordPairSurrogate, WordPair>();

            vp.WordPairs.AddRange(_wordPairs.Select(surrogate => wordPairs.GetValue(surrogate, () => surrogate.ToWordPair(project, vp))));
            var soundChanges = new ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> >();

            foreach (KeyValuePair <SoundContextSurrogate, Tuple <string[], int>[]> fd in _soundChanges)
            {
                SoundContext ctxt = fd.Key.ToSoundContext(project, segmentPool);
                FrequencyDistribution <Ngram <Segment> > freqDist = soundChanges[ctxt];
                foreach (Tuple <string[], int> sample in fd.Value)
                {
                    Ngram <Segment> corr = sample.Item1 == null ? new Ngram <Segment>() : new Ngram <Segment>(sample.Item1.Select(segmentPool.GetExisting));
                    freqDist.Increment(corr, sample.Item2);
                }
            }
            vp.SoundChangeFrequencyDistribution = soundChanges;
            IWordAligner aligner       = project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];
            int          segmentCount  = vp.Variety2.SegmentFrequencyDistribution.ObservedSamples.Count;
            int          possCorrCount = aligner.ExpansionCompressionEnabled ? (segmentCount * segmentCount) + segmentCount + 1 : segmentCount + 1;

            vp.SoundChangeProbabilityDistribution = new ConditionalProbabilityDistribution <SoundContext, Ngram <Segment> >(soundChanges,
                                                                                                                            (sc, freqDist) => new WittenBellProbabilityDistribution <Ngram <Segment> >(freqDist, possCorrCount));

            foreach (KeyValuePair <string, List <SoundCorrespondenceSurrogate> > kvp in _soundCorrespondenceCollections)
            {
                if (kvp.Value != null)
                {
                    FeatureSymbol pos = null;
                    switch (kvp.Key)
                    {
                    case "onset":
                        pos = CogFeatureSystem.Onset;
                        break;

                    case "nucleus":
                        pos = CogFeatureSystem.Nucleus;
                        break;

                    case "coda":
                        pos = CogFeatureSystem.Coda;
                        break;
                    }
                    vp.SoundCorrespondenceCollections[pos].AddRange(kvp.Value.Select(surrogate => surrogate.ToSoundCorrespondence(segmentPool, wordPairs)));
                }
            }
            return(vp);
        }
Beispiel #16
0
 public void Play(string audioName, SoundContext soundContext = SoundContext.Default)
 {
     audioEvent.Fire(delegate(BinaryWriter writer)
     {
         writer.Write(audioName);
         writer.WriteVector2(Vector2.Zero);
         writer.Write(-1);
         writer.Write((int)soundContext);
     });
     audioEvent.Poll();
 }
Beispiel #17
0
 public void PlayPitched(string audioName, Vector2 position, int pitch, SoundContext soundContext = SoundContext.Default)
 {
     audioEvent.Fire(delegate(BinaryWriter writer)
     {
         writer.Write(audioName);
         writer.WriteVector2(position);
         writer.Write(pitch);
         writer.Write((int)soundContext);
     });
     audioEvent.Poll();
 }
Beispiel #18
0
 public void PlayLocal(string audioName, int pitch = -1, SoundContext sound_context = SoundContext.Default)
 {
     if ((!Game1.eventUp || sound_context != SoundContext.NPC) && Game1.currentLocation == location)
     {
         if (pitch == -1)
         {
             Game1.playSound(audioName);
         }
         else
         {
             Game1.playSoundPitched(audioName, pitch);
         }
     }
 }
Beispiel #19
0
        private void UpdateCounts(IWordAligner aligner, ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> > counts, Alignment <Word, ShapeNode> alignment)
        {
            if (alignment.NormalizedScore < _initialAlignmentThreshold)
            {
                return;
            }

            for (int column = 0; column < alignment.ColumnCount; column++)
            {
                SoundContext    lhs  = alignment.ToSoundContext(_segmentPool, 0, column, aligner.ContextualSoundClasses);
                Ngram <Segment> corr = alignment[1, column].ToNgram(_segmentPool);
                counts[lhs].Increment(corr);
            }
        }
Beispiel #20
0
 public void Play(string audioName, SoundContext soundContext = SoundContext.Default)
 {
     if (CanShortcutPlay(Vector2.Zero, soundContext))
     {
         _PlayAudio(audioName, -1);
         return;
     }
     audioEvent.Fire(delegate(BinaryWriter writer)
     {
         writer.Write(audioName);
         writer.WriteVector2(Vector2.Zero);
         writer.Write(-1);
         writer.Write((int)soundContext);
     });
     audioEvent.Poll();
 }
Beispiel #21
0
 public void PlayPitched(string audioName, Vector2 position, int pitch, SoundContext soundContext = SoundContext.Default)
 {
     if (CanShortcutPlay(Vector2.Zero, soundContext))
     {
         _PlayAudio(audioName, pitch);
         return;
     }
     audioEvent.Fire(delegate(BinaryWriter writer)
     {
         writer.Write(audioName);
         writer.WriteVector2(position);
         writer.Write(pitch);
         writer.Write((int)soundContext);
     });
     audioEvent.Poll();
 }
 public PlayerSoundManager(PlayerEntity playerEntity,
                           SoundContext soundContext,
                           IPlayerSoundConfigManager playerSoundConfigManager,
                           ISoundConfigManager soundConfigManager,
                           ISoundEntityFactory soundEntityFactory,
                           ITerrainManager terrainManager,
                           IMapConfigManager mapConfigManager)
 {
     _soundConfigManager = soundConfigManager;
     _soundEntityFactory = soundEntityFactory;
     _playerEntity       = playerEntity;
     _soundContext       = soundContext;
     _soundConvert       = new SoundConverter(soundConfigManager,
                                              playerSoundConfigManager,
                                              terrainManager,
                                              mapConfigManager);
 }
 public WeaponLogicComponentsFactory(
     Contexts contexts,
     IEntityIdGenerator entityIdGenerator,
     ICurrentTime currentTime,
     IAttachmentManager attachmentManager,
     ISoundEntityFactory soundEntityFactory,
     IBulletEntityFactory bulletEntityFactory) : base(attachmentManager)
 {
     _bulletContext       = contexts.bullet;
     _throwingContext     = contexts.throwing;
     _clientEffectContext = contexts.clientEffect;
     _soundContext        = contexts.sound;
     _entityIdGenerator   = entityIdGenerator;
     _currentTime         = currentTime;
     _attachmentManager   = attachmentManager;
     _soundEntityFactory  = soundEntityFactory;
     _bulletEntityFactory = bulletEntityFactory;
 }
Beispiel #24
0
        public bool CanShortcutPlay(Vector2 position, SoundContext sound_context)
        {
            if (!LocalMultiplayer.IsLocalMultiplayer(is_local_only: true))
            {
                return(false);
            }
            if (Game1.eventUp && sound_context == SoundContext.NPC)
            {
                return(false);
            }
            if ((location == null || location == Game1.currentLocation) && CanHear(position))
            {
                return(true);
            }
            bool someone_can_hear = false;

            if (location != null)
            {
                foreach (Game1 gameInstance in GameRunner.instance.gameInstances)
                {
                    if (gameInstance.instanceGameLocation == location)
                    {
                        someone_can_hear = true;
                        break;
                    }
                }
                if (someone_can_hear && position != Vector2.Zero)
                {
                    someone_can_hear = false;
                    GameRunner.instance.ExecuteForInstances(delegate
                    {
                        if (!someone_can_hear && location == Game1.currentLocation && CanHear(position))
                        {
                            someone_can_hear = true;
                        }
                    });
                }
                return(someone_can_hear);
            }
            return(true);
        }
Beispiel #25
0
        private void E(VarietyPair pair)
        {
            ICognateIdentifier cognateIdentifier = _project.CognateIdentifiers[CognateIdentifierId];
            var          cognateCorrCounts       = new ConditionalFrequencyDistribution <SoundContext, Ngram <Segment> >();
            IWordAligner aligner      = _project.WordAligners[AlignerId];
            int          cognateCount = 0;
            double       totalScore   = 0;

            foreach (WordPair wordPair in pair.WordPairs)
            {
                IWordAlignerResult alignerResult = aligner.Compute(wordPair);
                cognateIdentifier.UpdatePredictedCognacy(wordPair, alignerResult);
                Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
                if (wordPair.Cognacy)
                {
                    for (int column = 0; column < alignment.ColumnCount; column++)
                    {
                        SoundContext    lhs  = alignment.ToSoundContext(_segmentPool, 0, column, aligner.ContextualSoundClasses);
                        Ngram <Segment> corr = alignment[1, column].ToNgram(_segmentPool);
                        cognateCorrCounts[lhs].Increment(corr);
                    }
                    cognateCount++;
                }
                wordPair.PhoneticSimilarityScore = alignment.NormalizedScore;
                totalScore += wordPair.PhoneticSimilarityScore;
            }

            pair.CognateCount = cognateCount;
            pair.CognateSoundCorrespondenceFrequencyDistribution = cognateCorrCounts;
            if (pair.WordPairs.Count == 0)
            {
                pair.LexicalSimilarityScore  = 0;
                pair.PhoneticSimilarityScore = 0;
            }
            else
            {
                pair.LexicalSimilarityScore  = (double)cognateCount / pair.WordPairs.Count;
                pair.PhoneticSimilarityScore = totalScore / pair.WordPairs.Count;
            }
        }
Beispiel #26
0
 public SoundContextSurrogate(SoundContext ctxt)
 {
     LeftEnvironment = ctxt.LeftEnvironment == null ? null : ctxt.LeftEnvironment.Name;
     _target = ctxt.Target.Select(seg => seg.StrRep).ToList();
     RightEnvironment = ctxt.RightEnvironment == null ? null : ctxt.RightEnvironment.Name;
 }
Beispiel #27
0
 public SoundGameContext(SoundContext context, Bin2D <IGameEntity> bin) : base(context, SoundComponentsLookup.componentTypes, bin)
 {
     _context = context;
 }
 public SoundLimitSystem(SoundContext soundContext)
 {
     _playOnceSoundGroup = soundContext.GetGroup(SoundMatcher.PlayOnce);
 }
Beispiel #29
0
        private int GetSoundChangeScore(Word sequence1, ShapeNode p1, ShapeNode p2, Word sequence2, ShapeNode q1, ShapeNode q2)
        {
            if (sequence1.Variety == sequence2.Variety)
            {
                return(0);
            }

            VarietyPair varietyPair = sequence1.Variety.VarietyPairs[sequence2.Variety];

            if (varietyPair.SoundChangeProbabilityDistribution == null)
            {
                return(0);
            }

            if (sequence1.Variety == varietyPair.Variety2)
            {
                ShapeNode tempNode = p1;
                p1 = q1;
                q1 = tempNode;

                tempNode = p2;
                p2       = q2;
                q2       = tempNode;
            }

            Ngram <Segment> target;

            if (p1 == null)
            {
                target = new Ngram <Segment>();
            }
            else
            {
                Segment targetSegment = _segmentPool.GetExisting(p1);
                target = p2 == null ? targetSegment : new Ngram <Segment>(targetSegment, _segmentPool.GetExisting(p2));
            }

            Ngram <Segment> corr;

            if (q1 == null)
            {
                corr = new Ngram <Segment>();
            }
            else
            {
                Segment corrSegment = _segmentPool.GetExisting(q1);
                corr = q2 == null ? corrSegment : new Ngram <Segment>(corrSegment, _segmentPool.GetExisting(q2));
            }

            ShapeNode  leftNode = p1 == null ? p2 : p1.GetPrev(NodeFilter);
            SoundClass leftEnv;

            if (leftNode == null || !_contextualSoundClasses.TryGetMatchingSoundClass(_segmentPool, leftNode, out leftEnv))
            {
                leftEnv = null;
            }
            ShapeNode  pRight    = p2 ?? p1;
            ShapeNode  rightNode = pRight == null ? null : pRight.GetNext(NodeFilter);
            SoundClass rightEnv;

            if (rightNode == null || !_contextualSoundClasses.TryGetMatchingSoundClass(_segmentPool, rightNode, out rightEnv))
            {
                rightEnv = null;
            }

            var lhs = new SoundContext(leftEnv, target, rightEnv);
            IProbabilityDistribution <Ngram <Segment> > probDist;
            double prob = varietyPair.SoundChangeProbabilityDistribution.TryGetProbabilityDistribution(lhs, out probDist) ? probDist[corr]
                                : varietyPair.DefaultCorrespondenceProbability;

            return((int)(MaxSoundChangeScore * prob));
        }
Beispiel #30
0
 public SoundEngine(SoundContext soundContext)
 {
     this.soundContext     = soundContext;
     this.backgroundPlayer = new BasicSoundPlayer();
     this.soundPlayer      = new BasicSoundPlayer();
 }
Beispiel #31
0
 public ClientSoundAutoStopSystem(SoundContext soundContext, ISoundPlayer soundPlayer, SoundParentController soundParentController)
 {
     _playingSoundGroup     = soundContext.GetGroup(SoundMatcher.Playing);
     _soundPlayer           = soundPlayer;
     _soundParentController = soundParentController;
 }
Beispiel #32
0
 public SoundContextSurrogate(SoundContext ctxt)
 {
     LeftEnvironment  = ctxt.LeftEnvironment == null ? null : ctxt.LeftEnvironment.Name;
     _target          = ctxt.Target.Select(seg => seg.StrRep).ToList();
     RightEnvironment = ctxt.RightEnvironment == null ? null : ctxt.RightEnvironment.Name;
 }