Ejemplo n.º 1
0
        public MidiFile(Stream aStream)
        {
            ByteArray byteArray = new ByteArrayBig(aStream);

            ReadMidiHeader(byteArray);
            ReadMidiTrack(byteArray);
        }
Ejemplo n.º 2
0
        public MusicAiff(FormFile aFormFile)
        {
            FormChunkListAiff lAiffForm = ( FormChunkListAiff )aFormFile.formChunkList;

            FormChunkSsnd lSsndChunk = lAiffForm.chunkSsnd;

            name = aFormFile.name;
            int position = ( int )lSsndChunk.position;
            int length   = lSsndChunk.dataSize;

            FormChunkComm lChunkComm = lAiffForm.chunkComm;

            Channels     = lChunkComm.numberOfChannels;
            SampleRate   = ( int )lChunkComm.sampleRate;
            sampleBits   = lChunkComm.bitsPerSamples;
            SampleLength = length / (sampleBits / 8) / Channels;

            sampleMeanArray = new float[SampleLength];

            if (name != null)
            {
                using (FileStream u = new FileStream(name, FileMode.Open, FileAccess.Read))
                {
                    ByteArray lByteArray = new ByteArrayBig(u);

                    lByteArray.SetPosition(position);

                    for (int i = 0; i < SampleLength; i++)
                    {
                        float value = 0.0f;

                        for (int j = 0; j < Channels; j++)
                        {
                            if (sampleBits == 16)
                            {
                                value += ( float )lByteArray.ReadInt16() / ( float )0x8000;
                            }
                            else if (sampleBits == 24)
                            {
                                value += ( float )lByteArray.ReadInt24() / ( float )0x800000;
                            }
                        }

                        sampleMeanArray[i] = value / Channels;
                    }
                }
            }

            int lSampleLoopStart = 0;
            int lSampleLoopEnd   = 0;

            Loop = new List <List <LoopInformation> >();
            Loop.Add(new List <LoopInformation>());
            Loop[0].Add(new LoopInformation(SampleRate, lSampleLoopStart, lSampleLoopEnd));
        }
Ejemplo n.º 3
0
        public AdxFile(Stream aStream)
        {
            ByteArray lByteArray = new ByteArrayBig(aStream);

            sampleArray = new float[2][];

            adxHeader = new AdxHeader(lByteArray);
            adxData   = new AdxData(lByteArray, adxHeader);

            sampleArray = adxData.GetSampleArray();
        }
Ejemplo n.º 4
0
        public AhxHeader(Stream aStream)
        {
            ByteArray lByteArray = new ByteArrayBig(aStream);

            offset_table    = new int[5][];
            offset_table[0] = offset_table0;
            offset_table[1] = offset_table1;
            offset_table[2] = offset_table2;
            offset_table[3] = offset_table3;
            offset_table[4] = offset_table4;
            //fseek( fp, 0, SEEK_END );
            int src_buf_len = lByteArray.Length;

            //int src_buf_rem = src_buf_len;
            Byte[] src_buf_set = new Byte[src_buf_len];
            //fseek( fp, 0, SEEK_SET );
            //fread( src_buf_set, 1, src_buf_len, fp );
            //src_buf = src_buf_set;
            //fclose( fp );

            int ahx_count = 0;

            //while( aByteArray.Position < aByteArray.GetLength() )
            //{
            int lIndexAhxHed;
            int lIndexAhxFot;

            UInt16 head   = lByteArray.ReadUInt16();
            UInt16 offset = lByteArray.ReadUInt16();

            //UnityEngine.Debug.LogError( "head:" + head );
            //UnityEngine.Debug.LogError( "offset:" + offset.ToString( "X4" ) );
            lIndexAhxHed = 0;
            lIndexAhxFot = lByteArray.Find(AHXFOT);

            //UnityEngine.Debug.LogError( "lIndexAhxHed:" + lIndexAhxHed );
            //UnityEngine.Debug.LogError( "lIndexAhxFot:" + lIndexAhxFot );

            //ahx_hed = lByteArray.ReadString( AHXHED.Length - 1 );//memmem( src_buf, src_buf_rem, AHXHED, sizeof( AHXHED ) - 1 );
            //ahx_fot = lByteArray.ReadString( AHXFOT.Length - 1 );//memmem( src_buf, src_buf_rem, AHXFOT, sizeof( AHXFOT ) - 1 );

            lByteArray.AddPosition(offset - 6);

            if (head != 0x8000 || lIndexAhxFot == -1)
            {
                Logger.LogError("head != 0x8000 || lIndexAhxFot == -1");
                lByteArray.SetPosition(lByteArray.Length);                   //src_buf_rem = 0;
            }
            else if (lByteArray.Find(AHXCHK, 0) == -1)                       //strncmp( ahx_hed + 30, AHXCHK, sizeof( AHXCHK ) - 1 ) != 0 )
            {
                Logger.LogError("lByteArrayChk.Find( AHXCHK, 0 ) == -1");
                lByteArray.AddPosition(1);                          //src_buf++;
                //src_buf_rem--;
            }
            else
            {
                lByteArray.AddPosition(6);
                //UnityEngine.Debug.LogError( "Adde:" + lByteArray.Position.ToString( "X8" ) );
                int          lLengthAhxBuf = lIndexAhxFot + 12 - lByteArray.Position;               //ahx_buf_len = ahx_fot + 12 - ahx_hed;
                Byte[]       ahx_buf       = lByteArray.ReadBytes(( UInt32 )lLengthAhxBuf);         //ahx_buf = malloc( ahx_buf_len );
                MemoryStream lMemoryStream = new MemoryStream(ahx_buf);
                ByteArray    lByteArrayBuf = new ByteArrayBig(lMemoryStream);

                ahx_count++;

                //int lLengthAhxBuf = lIndexAhxFot + 12 - lIndexAhxHed;//ahx_buf_len = ahx_fot + 12 - ahx_hed;
                //Byte[] ahx_buf = lByteArray.ReadBytes( lLengthAhxBuf );//ahx_buf = malloc( ahx_buf_len );
                //memcpy( ahx_buf, ahx_hed, ahx_buf_len );
                lByteArray.SetPosition(0);
                UInt32 uint1 = lByteArray.ReadUInt32();
                UInt32 uint2 = lByteArray.ReadUInt32();
                UInt32 uint3 = lByteArray.ReadUInt32();
                UInt32 uint4 = lByteArray.ReadUInt32();
                UInt32 uint5 = lByteArray.ReadUInt32();
                UInt32 uint6 = lByteArray.ReadUInt32();
                UInt32 uint7 = lByteArray.ReadUInt32();
                UInt32 uint8 = lByteArray.ReadUInt32();

                //UnityEngine.Debug.LogError( "1:" + uint1 );
                //UnityEngine.Debug.LogError( "2:" + uint2 );
                //UnityEngine.Debug.LogError( "3:" + uint3 );
                //UnityEngine.Debug.LogError( "4:" + uint4 );
                //UnityEngine.Debug.LogError( "5:" + uint5 );
                //UnityEngine.Debug.LogError( "6:" + uint6 );
                //UnityEngine.Debug.LogError( "7:" + uint7 );
                //UnityEngine.Debug.LogError( "8:" + uint8 );

                int     wav_buf_len = ( int )(uint4 * 2);                                 //wav_buf_len = getlongb( ahx_buf + 12 ) * 2;
                Int16[] wav_buf     = new Int16[wav_buf_len + 1152 * 16];                 //wav_buf = malloc( wav_buf_len + 1152 * 16 ); //modify : from ExtractData; //+1152*2); margen = layer-2 frame size
                wav_buf_len = decode_ahx(lByteArrayBuf, ahx_buf, wav_buf, lLengthAhxBuf); //modify : from ExtractData

                sampleArray    = new float[2][];
                sampleArray[0] = new float[wav_buf_len + 1152 * 16];
                sampleArray[1] = new float[wav_buf_len + 1152 * 16];

                for (int i = 0; i < wav_buf_len + 1152 * 16; i++)
                {
                    sampleArray[0][i] = ( float )wav_buf[i] / 0x8000;
                    sampleArray[1][i] = ( float )wav_buf[i] / 0x8000;
                }
            }
            //}
        }