예제 #1
0
        void DoLoading(object obj)
        {
            Wavefile  wave   = m_Wavefile;
            Mp3Stream stream = (Mp3Stream)obj;

            BlockArray <Sample> array = wave.m_Samples;

            //SafeStream safeStream = new SafeStream(stream);

            Sample[] sample = new Sample[10000];
            byte[]   buffer = new byte[sample.Length * 4];

            Thread.Sleep(1000);

            while (true)             //safeStream.Position < safeStream.Length)
            {
                //int count;
                //int countMax = (int)Math.Min(1024, (safeStream.Length - safeStream.Position)/4);
                //for (count=0; count <countMax; count ++)
                //{
                //    //sample[count] = new Sample(ReadI2(safeStream), ReadI2(safeStream));
                //    sample[count] = ReadSI2(safeStream);
                //}

                int byteCount = stream.Read(buffer, 0, buffer.Length);
                if (byteCount == 0)
                {
                    break;
                }

                int sampleCount = byteCount / 4;

                for (int i = 0, j = 0; i < sampleCount; i++, j += 4)
                {
                    sample[i] = new Sample((short)(buffer[j] | buffer[j + 1] << 8),
                                           (short)(buffer[j + 2] | buffer[j + 3] << 8));
                }

                array.Write(sample, 0, sampleCount);
                Thread.Sleep(0);
            }

            stream.Dispose();
            wave.FinishedLoading = true;
        }