Пример #1
0
        protected override void HandleDataReady(object sender, SoundDataReadyEventArgs args)
        {
            lock (thisLock)
            {
                frequency = args.Frequency;
                short[] addtionalData = new short[addtionalDataBufferTime * channelCount * frequency];

                if (args.DataParcelNumber == 1)
                {
                    dataBuffer  = new short[args.SoundData.Length];
                    soundBuffer = new CircularBuffer(args.SoundData.Length);
                    soundBuffer.Push(args.SoundData);
                    Array.Copy(args.SoundData, dataBuffer, args.SoundData.Length);
                }
                else
                {
                    Array.Copy(args.SoundData, 0, addtionalData, 0, addtionalData.Length);
                    soundBuffer.Push(addtionalData);
                    DetectionResult detectionTimes = SoundProcessor.DetectJingle(soundBuffer.Buffer, startJingle.SoundDataBuffer.Buffer, endJingle.SoundDataBuffer.Buffer);

                    SoundDataReadyEventArgs dataSet = new SoundDataReadyEventArgs(dataBuffer.Length, frequency, dataBuffer, adState);

                    adKilling(ref dataSet, detectionTimes.StartJingleIndex, detectionTimes.EndJingleIndex);
#if DEBUG
                    Debug.WriteLine(detectionTimes.StartJingleIndex / (double)(frequency * sizeof(short)));
                    Debug.WriteLine(detectionTimes.EndJingleIndex / (double)(frequency * sizeof(short)));
#endif

                    base.OnDataReady(dataSet);
                    soundBuffer = new CircularBuffer(args.SoundData.Length);
                    soundBuffer.Push(args.SoundData);
                    adState = dataSet.AdState;

                    dataBuffer = new short[args.SoundData.Length];
                    Array.Copy(args.SoundData, dataBuffer, args.SoundData.Length);

                    if (args.LastDataParcel)
                    {
                        detectionTimes = SoundProcessor.DetectJingle(soundBuffer.Buffer, startJingle.SoundDataBuffer.Buffer, endJingle.SoundDataBuffer.Buffer);
                        adKilling(ref dataSet, detectionTimes.StartJingleIndex, detectionTimes.EndJingleIndex);
#if DEBUG
                        Debug.WriteLine(detectionTimes.StartJingleIndex / (double)(frequency * sizeof(short)));
                        Debug.WriteLine(detectionTimes.EndJingleIndex / (double)(frequency * sizeof(short)));
#endif
                        base.OnDataReady(dataSet);
                    }
                }
            }
        }
Пример #2
0
        public static DetectionResult DetectJingle(short[] data, short[] startJingle, short[] endJingle)
        {
            DetectionResult detectionTimes = new DetectionResult(SoundProcessor.FindPattern(data, startJingle), SoundProcessor.FindPattern(data, endJingle));

            return(detectionTimes);
        }