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); } }
public WaveformReaderPcm(RiffWaveRiff aRiffWaveRiff, bool aIsOnMemory) { RiffWaveData lRiffWaveData = ( RiffWaveData )aRiffWaveRiff.GetChunk(RiffWaveData.ID); int lPosition = ( int )lRiffWaveData.position; int lLength = ( int )lRiffWaveData.Size; RiffWaveFmt_ lRiffWaveFmt_ = ( RiffWaveFmt_ )aRiffWaveRiff.GetChunk(RiffWaveFmt_.ID); int lChannels = lRiffWaveFmt_.channels; int lSampleRate = ( int )lRiffWaveFmt_.samplesPerSec; int lSampleBits = lRiffWaveFmt_.bitsPerSample; int lSamples = lLength / (lSampleBits / 8) / lChannels; format = new WaweformFormat(lChannels, lSamples, lSampleRate, lSampleBits); reader = new WaveformReader(format, aRiffWaveRiff.name, lPosition, aIsOnMemory, AByteArray.Endian.Little); }
public static void SetDataArray(RiffWaveRiff lRiffWaveRiff, Byte[] aSampleData) { Logger.BreakDebug("SetDataArray"); RiffWaveData dataChunk = ( RiffWaveData )lRiffWaveRiff.GetChunk(RiffWaveData.ID); if (dataChunk == null) { // Error. } else { MemoryStream lMemoryStream = new MemoryStream(aSampleData); AByteArray lByteArray = new ByteArrayLittle(lMemoryStream); lByteArray.WriteBytes(new byte[dataChunk.position]); lRiffWaveRiff.OverrideChunk(new RiffWaveData(RiffWaveData.ID, ( UInt32 )aSampleData.Length, lByteArray, lRiffWaveRiff)); } }
public WaveformPcm(RiffWaveRiff aRiffFile) { RiffWaveData lRiffWaveData = ( RiffWaveData )aRiffFile.GetChunk(RiffWaveData.ID); int lPosition = ( int )lRiffWaveData.position; int lLength = ( int )lRiffWaveData.Size; RiffWaveFmt_ lRiffWaveFmt_ = ( RiffWaveFmt_ )aRiffFile.GetChunk(RiffWaveFmt_.ID); int lChannels = lRiffWaveFmt_.channels; int lSampleRate = ( int )lRiffWaveFmt_.samplesPerSec; int lSampleBits = lRiffWaveFmt_.bitsPerSample; int lSamples = lLength / (lSampleBits / 8) / lChannels; format = new WaweformFormat(lChannels, lSamples, lSampleRate, lSampleBits); using (FileStream u = new FileStream(aRiffFile.name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { AByteArray lByteArray = new ByteArrayLittle(u); data = new WaveformData(format, lByteArray, lPosition); } }
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 ); } }