예제 #1
0
        public static void Execute(string aFilePathOutput, LoopInformation aLoopInformation)
        {
            RiffWaveRiff lRiffWaveRiff = ( RiffWaveRiff )PoolCollection.GetRiffWave(aFilePathOutput);

            WaveformReaderPcm waveform = new WaveformReaderPcm(lRiffWaveRiff, true);

            OverrideCuePoint(lRiffWaveRiff, ( int )aLoopInformation.start.sample, ( int )aLoopInformation.end.sample);
            OverrideSampleLoop(lRiffWaveRiff, ( int )aLoopInformation.start.sample, ( int )aLoopInformation.end.sample);

            Byte[]       lDataArrayRead = null;
            RiffWaveData dataChunk      = ( RiffWaveData )lRiffWaveRiff.GetChunk(RiffWaveData.ID);

            using (FileStream u = new FileStream(lRiffWaveRiff.name, FileMode.Open, FileAccess.Read))
            {
                AByteArray l = new ByteArrayLittle(u);

                int bytePosition = ( int )dataChunk.position;

                l.SetPosition(bytePosition);

                lDataArrayRead = l.ReadBytes(dataChunk.Size);
            }

            Byte[] lDataArrayWrite = lDataArrayRead;

            if (IsCutLast == true)
            {
                int lLength = ( int )(aLoopInformation.end.sample + 1) * waveform.format.channels * (waveform.format.sampleBits / 8);
                Logger.BreakDebug("End:" + aLoopInformation.end.sample);

                lDataArrayWrite = new Byte[lLength];

                for (int i = 0; i < lLength; i++)
                {
                    lDataArrayWrite[i] = lDataArrayRead[i];
                }
            }

            SetDataArray(lRiffWaveRiff, lDataArrayWrite);

            MemoryStream    lMemoryStreamWrite = new MemoryStream(( int )lRiffWaveRiff.Size + 8);
            ByteArrayLittle lByteArray         = new ByteArrayLittle(lMemoryStreamWrite);

            lRiffWaveRiff.WriteByteArray(lByteArray);

            Logger.BreakDebug("WriteByteArray");
            Logger.BreakDebug("Out:" + aFilePathOutput);

            try
            {
                using (FileStream u = new FileStream(aFilePathOutput, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    u.Write(lMemoryStreamWrite.GetBuffer(), 0, ( int )lMemoryStreamWrite.Length);
                }
            }
            catch (Exception aExpection)
            {
                Logger.BreakError("Write Exception:" + aExpection);
            }
        }
예제 #2
0
        public XmFile(Stream aStream)
        {
            ByteArray lByteArray = new ByteArrayLittle(aStream);

            idText        = lByteArray.ReadString(17);
            moduleName    = lByteArray.ReadString(20);
            _1A           = lByteArray.ReadByte();
            trackerName   = lByteArray.ReadString(20);
            versionNumber = lByteArray.ReadUInt16();

            headerSize          = lByteArray.ReadUInt32();
            songLength          = lByteArray.ReadUInt16();
            restartPosition     = lByteArray.ReadUInt16();
            numberOfChannels    = lByteArray.ReadUInt16();
            numberOfPatterns    = lByteArray.ReadUInt16();
            numberOfInstruments = lByteArray.ReadUInt16();
            flags             = lByteArray.ReadUInt16();
            defaultTempo      = lByteArray.ReadUInt16();
            defaultBpm        = lByteArray.ReadUInt16();
            patternOrderTable = lByteArray.ReadBytes(256);

            patternChunkArray    = new PatternChunk[numberOfPatterns];
            instrumentChunkArray = new InstrumentChunk[numberOfInstruments];

            for (int i = 0; i < numberOfPatterns; i++)
            {
                patternChunkArray[i] = new PatternChunk(lByteArray);
            }

            for (int i = 0; i < numberOfInstruments; i++)
            {
                instrumentChunkArray[i] = new InstrumentChunk(lByteArray);
            }
        }
예제 #3
0
        public static void Execute(FileInfo aFileInput, string aFilePathOutput, List <double> aProgressList, int aIndex)
        {
            RiffFile          lRiffFile          = ( RiffFile )PoolCollection.poolWav.Get(aFileInput.FullName);
            RiffChunkListWave lRiffChunkListWave = ( RiffChunkListWave )lRiffFile.riffChunkList;

            WaveformBase waveform = LoaderWaveform.Load(aFileInput.FullName);

            SByte[] lSampleArray = new SByte[waveform.format.samples];

            for (int i = 0; i < waveform.format.samples; i++)
            {
                lSampleArray[i] = ( SByte )(waveform.data.GetSampleData(0, i) >> 8);
            }

            List <LoopInformation> lLoopList = null;

            try
            {
                lLoopList = LoopSearchTool.Execute(lSampleArray, aProgressList, aIndex);
            }
            catch (Exception aExpection)
            {
                UnityEngine.Debug.Log(aExpection.ToString() + ":LoopTool Exception");
            }

            //for( int i = 0; i < lLoopList.Count; i++ )
            if (lLoopList.Count >= 1)
            {
                //lRiffChunkListWave.AddCuePoint( ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
                //lRiffChunkListWave.AddSampleLoop( ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
                lRiffChunkListWave.AddCuePoint(( int )lLoopList[0].start.sample, ( int )lLoopList[0].end.sample);
                lRiffChunkListWave.AddSampleLoop(( int )lLoopList[0].start.sample, ( int )lLoopList[0].end.sample);
            }

            Byte[] lDataArrayRead = null;

            using (FileStream u = new FileStream(lRiffFile.name, FileMode.Open, FileAccess.Read))
            {
                ByteArray l = new ByteArrayLittle(u);

                int bytePosition = ( int )lRiffChunkListWave.dataChunk.position;

                l.SetPosition(bytePosition);

                lDataArrayRead = l.ReadBytes(lRiffChunkListWave.dataChunk.size);
            }

            Byte[] lDataArrayWrite = lDataArrayRead;

            if (IsCutLast == true)
            {
                lDataArrayWrite = new Byte[(( int )lLoopList[0].end.sample + 1) * 4];

                for (int i = 0; i < (lLoopList[0].end.sample + 1) * 4; i++)
                {
                    lDataArrayWrite[i] = lDataArrayRead[i];
                }
            }

            for (int i = 0; i < 64; i++)
            {
                Logger.LogDebug(i.ToString() + ":" + lDataArrayWrite[i]);
            }

            lRiffChunkListWave.SetDataArray(lDataArrayWrite);

            MemoryStream    lMemoryStreamWrite = new MemoryStream(( int )lRiffChunkListWave.size + 8);
            ByteArrayLittle lByteArray         = new ByteArrayLittle(lMemoryStreamWrite);

            //lByteArrayRead.Open();
            lRiffFile.WriteByteArray(null, lByteArray);
            //lByteArrayRead.Close();

            using (FileStream u = new FileStream(aFilePathOutput, FileMode.Create, FileAccess.Write))
            {
                u.Write(lMemoryStreamWrite.GetBuffer(), 0, ( int )lMemoryStreamWrite.Length);
            }
        }
예제 #4
0
		public static void Execute( string aFilePathInput, string aFilePathOutput, InputMusicInformation aData )
		{
			RiffWaveRiff lRiffWaveRiff = ( RiffWaveRiff )PoolCollection.GetRiffWave( aFilePathInput );

			WaveformPcm lWaveform = new WaveformPcm( lRiffWaveRiff );

			SByte[] lSampleArray = new SByte[lWaveform.format.samples];
			
			lSampleArray = lWaveform.data.sampleByteArray[0];

			List<LoopInformation> lLoopList = null;

			try
			{
				if( lWaveform.format.samples > 44100 * 16 )
				{
					lLoopList = LoopSearchTool.Execute( lSampleArray, aData, aFilePathInput );
				}
				else
				{
					lLoopList = LoopSearchToolSoundfont.Execute( lSampleArray, aData, aFilePathInput );
				}
			}
			catch( Exception aExpection )
			{
				Logger.BreakError( aExpection.ToString() + ":LoopTool Exception" );
			}

			for( int i = 0; i < lLoopList.Count; i++ )
			{
				AddCuePoint( lRiffWaveRiff, ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
				AddSampleLoop( lRiffWaveRiff, ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
			}

			Byte[] lDataArrayRead = null;
			RiffWaveData dataChunk = ( RiffWaveData )lRiffWaveRiff.GetChunk( RiffWaveData.ID );
			
			using ( FileStream u = new FileStream( lRiffWaveRiff.name, FileMode.Open, FileAccess.Read ) )
			{
				AByteArray l = new ByteArrayLittle( u );
				
				int bytePosition = ( int )dataChunk.position;

				l.SetPosition( bytePosition );
				
				lDataArrayRead = l.ReadBytes( dataChunk.Size );
			}

			SetDataArray( lRiffWaveRiff, lDataArrayRead );
			
			Logger.BreakDebug( "lMemoryStreamWrite" );

			MemoryStream lMemoryStreamWrite = new MemoryStream( ( int )lRiffWaveRiff.Size + 8 );
			ByteArrayLittle lByteArray = new ByteArrayLittle( lMemoryStreamWrite );

			lRiffWaveRiff.WriteByteArray( lByteArray );
			
			Logger.BreakDebug( "WriteByteArray" );
			Logger.BreakDebug( "Out:" + aFilePathOutput );
			
			try
			{
				using( FileStream u = new FileStream( aFilePathOutput, FileMode.Create, FileAccess.Write, FileShare.Read ) )
				{
					u.Write( lMemoryStreamWrite.GetBuffer(), 0, ( int )lMemoryStreamWrite.Length );
				}
			}
			catch( Exception aExpection )
			{
				Logger.BreakError( "Write Exception:" + aExpection );
			}
		}