Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     time              = 0;
     isPlayingMusic    = false;
     audio             = GetComponent <AudioSource>();
     soundEventHandler = this;
 }
Exemplo n.º 2
0
            /// <summary>
            /// 线程函数处理:正常工作数据处理
            /// </summary>
            void ThreadWorkWaveStart()
            {
                while (true)
                {
                    WorkBytesEvent.WaitOne();
                    var r = new byte[4];
                    for (int i = 0; i < ConstUdpArg.ARRAY_NUM; i++)
                    {
                        for (int j = 0; j < ConstUdpArg.WORK_FRAME_NUMS * ConstUdpArg.WORK_FRAME_LENGTH; j++)
                        {
                            r[0] = WorkWaveBytes[i][j * 4 + 3];
                            r[1] = WorkWaveBytes[i][j * 4 + 2];
                            r[2] = WorkWaveBytes[i][j * 4 + 1];
                            r[3] = WorkWaveBytes[i][j * 4];
                            int   a   = BitConverter.ToInt32(r, 0);
                            float tmp = a / 1048576.0f;
                            //                        float tmp = a / 2.0f;
                            WorkWaveFloats[i][j] = tmp;

                            //听音数据处理
                            float f = WorkWaveFloats[i][j] * ListenCoefficent;
                            short sh;
                            if (f > 32767)
                            {
                                sh = 32767;
                            }
                            else if (f <= -32767)
                            {
                                sh = -32767;
                            }
                            else
                            {
                                sh = (short)f;
                            }
                            var x = BitConverter.GetBytes(sh);
                            Array.Copy(x, 0, PlayWaveBytes[i], j * 2, 2);
                        }
                    }
                    var offset = ConstUdpArg.offsetArray[0];
                    WorkWavefdatas = WorkWaveFloats[offset - 1];
                    WorkEnergyEvent.Set();
                    FreqWaveEvent.Set();


                    if (PreGraphEventHandler != null)
                    {
                        PreGraphEventHandler.Invoke(null, WorkWavefdatas);
                    }
                    //            if (BckGraphEventHandler != null) BckGraphEventHandler.Invoke(null, WorkWaveTwo);

                    if (SoundEventHandler != null)
                    {
                        int channel = 0;
                        if (channel > 0)
                        {
                            SoundEventHandler.Invoke(null, PlayWaveBytes[channel]);
                        }
                    }
                }
            }
Exemplo n.º 3
0
	public void SetEndHandler(SoundEventHandler handler)
	{
		m_OnLifeEnd = handler;
	}