示例#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 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);
        }
示例#3
0
        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));
            }
        }
示例#4
0
        public MusicPcm(RiffWaveRiff aRiffFile)
        {
            Name     = aRiffFile.name;
            Waveform = new WaveformReaderPcm(aRiffFile, false);

            Length = new SoundTime(Waveform.format.sampleRate, Waveform.format.samples);

            RiffWaveSmpl lRiffWaveSmpl = ( RiffWaveSmpl )aRiffFile.GetChunk(RiffWaveSmpl.ID);

            if (lRiffWaveSmpl != null)
            {
                loopList = new List <List <LoopInformation> >();

                int lIndex      = -1;
                int lLoopLength = -1;

                for (int i = 0; i < lRiffWaveSmpl.sampleLoops; i++)
                {
                    SampleLoop lLoop = lRiffWaveSmpl.sampleLoopList[i];

                    if (( int )(lLoop.end - lLoop.start) == lLoopLength)
                    {
                    }
                    else
                    {
                        loopList.Add(new List <LoopInformation>());
                        lLoopLength = ( int )(lLoop.end - lLoop.start);
                        lIndex++;
                    }

                    loopList[lIndex].Add(new LoopInformation(Length.sampleRate, ( int )lLoop.start, ( int )lLoop.end));
                }
            }
            else
            {
                loopList = new List <List <LoopInformation> >();
                loopList.Add(new List <LoopInformation>());
                loopList[0].Add(new LoopInformation(Length.sampleRate, -1, -1));
            }

            Loop = GetLoop(0, 0);
        }
示例#5
0
        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);
            }
        }
示例#6
0
        public static void OverrideSampleLoop(RiffWaveRiff lRiffWaveRiff, int aStart, int aEnd)
        {
            Logger.BreakDebug("OverrideSampleLoop");

            RiffWaveSmpl lRiffWaveSmpl = ( RiffWaveSmpl )lRiffWaveRiff.GetChunk(RiffWaveSmpl.ID);

            if (lRiffWaveSmpl == null)
            {
                List <SampleLoop> lSampleLoopList = new List <SampleLoop>();
                lSampleLoopList.Add(new SampleLoop(0, 0, ( UInt32 )aStart, ( UInt32 )aEnd, 0, 0));
                lRiffWaveSmpl = new RiffWaveSmpl(0, 0, 0, 60, 0, 0, 0, 1, 0, lSampleLoopList);
                lRiffWaveRiff.AddChunk(lRiffWaveSmpl);
            }
            else
            {
                List <SampleLoop> lSmplLoopList = new List <SampleLoop>();
                lSmplLoopList.Add(new SampleLoop(0, 0, ( UInt32 )aStart, ( UInt32 )aEnd, 0, 0));
                lRiffWaveRiff.OverrideChunk(new RiffWaveSmpl(lRiffWaveSmpl, lSmplLoopList));
            }
        }
示例#7
0
        public void UpdateMesh()
        {
            try
            {
                MusicPcm lMusicPcm = ( MusicPcm )player.Music;

                if (lMusicPcm != null)
                {
                    RiffWaveRiff lRiffWaveRiff = new RiffWaveRiff(player.GetFilePath());
                    WaveformPcm  lWaveform     = new WaveformPcm(lRiffWaveRiff);
                    sbyte[]      lWaveformByte = lWaveform.data.sampleByteArray[0];

                    componentWaveform.Set(player, lWaveformByte);
                    componentWaveformSmall.Set(player, lWaveformByte);
                }

                componentWaveform.UpdateVertex(player, scale, positionWaveform);
            }
            catch (Exception e)
            {
                Logger.Warning("Execpstion:" + e);
            }
        }
示例#8
0
        public static void OverrideCuePoint(RiffWaveRiff lRiffWaveRiff, int aStart, int aEnd)
        {
            Logger.BreakDebug("OverrideCuePoint");

            RiffWaveCue_ lRiffWaveCue_ = ( RiffWaveCue_ )lRiffWaveRiff.GetChunk(RiffWaveCue_.ID);

            if (lRiffWaveCue_ == null)
            {
                List <CuePoint> lCuePointList = new List <CuePoint>();
                lCuePointList.Add(new CuePoint(1, ( UInt32 )aStart, "data", 0, 0, ( UInt32 )aStart));
                lCuePointList.Add(new CuePoint(2, ( UInt32 )aEnd, "data", 0, 0, ( UInt32 )aEnd));
                lRiffWaveCue_ = new RiffWaveCue_(lCuePointList);
                lRiffWaveRiff.AddChunk(lRiffWaveCue_);
            }
            else
            {
                List <CuePoint> lCuePointList = new List <CuePoint>();
                lCuePointList.Add(new CuePoint(0, ( UInt32 )aStart, "data", 0, 0, ( UInt32 )aStart));
                lCuePointList.Add(new CuePoint(1, ( UInt32 )aEnd, "data", 0, 0, ( UInt32 )aEnd));
                lRiffWaveCue_ = new RiffWaveCue_(lCuePointList);
                lRiffWaveRiff.OverrideChunk(lRiffWaveCue_);
            }
        }
示例#9
0
        private string CreateSfzList(string aDirectory)
        {
            Dictionary <int, string> lFileNameDictionary = new Dictionary <int, string>();
            Dictionary <int, int>    lToneDictionary     = new Dictionary <int, int>();

            string lDirectoryName = Path.GetFileName(aDirectory);

            string[] lFilePathArray = Directory.GetFiles(aDirectory, "*.wav", SearchOption.TopDirectoryOnly);
            Dictionary <string, int> lLoopStartDictionary = new Dictionary <string, int>();
            Dictionary <string, int> lLoopEndDictionary   = new Dictionary <string, int>();

            for (int i = 0; i < lFilePathArray.Length; i++)
            {
                string   lFileName = Path.GetFileName(lFilePathArray[i]);
                string[] separatedStringArrayDot = lFileName.Split('.');
                int      separatedNumDot         = separatedStringArrayDot.Length;

                lLoopStartDictionary.Add(lFileName, 0);
                lLoopEndDictionary.Add(lFileName, 0);

                if (separatedNumDot >= 3)
                {
                    string pitchNotation = separatedStringArrayDot[separatedNumDot - 2];

                    string[] separateStringArrayAtmark = pitchNotation.Split('@');
                    int      separatedNumAtmark        = separateStringArrayAtmark.Length;

                    if (separatedNumAtmark >= 1)
                    {
                        int keycenterActual      = GetPitchNotation(separateStringArrayAtmark[0]);
                        int keycenterDestination = keycenterActual;

                        if (separatedNumAtmark == 2)
                        {
                            keycenterDestination = GetPitchNotation(separateStringArrayAtmark[1]);
                        }

                        if (lFileNameDictionary.ContainsKey(keycenterDestination) == false)
                        {
                            lFileNameDictionary.Add(keycenterDestination, Path.GetFileName(lFilePathArray[i]));
                        }

                        if (lToneDictionary.ContainsKey(keycenterDestination) == false)
                        {
                            lToneDictionary.Add(keycenterDestination, (keycenterActual - keycenterDestination) * 100);
                        }
                    }
                }

                RiffWaveRiff lRiffWaveRiff = new RiffWaveRiff(lFilePathArray[i]);
                RiffWaveSmpl lRiffWaveSmpl = ( RiffWaveSmpl )lRiffWaveRiff.GetChunk(RiffWaveSmpl.ID);

                if (lRiffWaveSmpl != null)
                {
                    if (lRiffWaveSmpl.sampleLoopList[0] != null)
                    {
                        SampleLoop lLoop = lRiffWaveSmpl.sampleLoopList[0];
                        lLoopStartDictionary[lFileName] = ( int )lLoop.start;
                        lLoopEndDictionary[lFileName]   = ( int )lLoop.end;
                    }
                }
            }

            string lSfz = "";

            lSfz += "<group>\n";
            lSfz += "loop_mode=no_loop\n";
            //sfz += "loop_mode=loop_continuous\n";
            lSfz += "ampeg_release=0.250\n";
            lSfz += "\n";

            int lokey = 0;
            int hikey = 127;

            for (int i = 0; i < 128; i++)
            {
                if (lFileNameDictionary.ContainsKey(i) == true)
                {
                    lSfz += "<region>\n";
                    lSfz += "sample=" + lDirectoryName + "/" + lFileNameDictionary[i] + "\n";

                    lSfz += "pitch_keycenter=" + i + "\n";

                    for (hikey = i + 1; hikey < 127; hikey++)
                    {
                        if (lFileNameDictionary.ContainsKey(hikey) == true)
                        {
                            hikey--;
                            break;
                        }
                    }

                    lSfz += "lokey=" + lokey + "\n";
                    lSfz += "hikey=" + hikey + "\n";

                    if (lLoopStartDictionary[lFileNameDictionary[i]] != 0 || lLoopEndDictionary[lFileNameDictionary[i]] != 0)
                    {
                        lSfz += "loop_start=" + lLoopStartDictionary[lFileNameDictionary[i]] + "\n";
                        lSfz += "loop_end=" + lLoopEndDictionary[lFileNameDictionary[i]] + "\n";
                    }

                    if (lToneDictionary.ContainsKey(i) == true)
                    {
                        lSfz += "tune=" + lToneDictionary[i] + "\n";
                    }
                    else
                    {
                        lSfz += "tune=0\n";
                    }

                    lSfz += "\n";

                    lokey = hikey + 1;
                }
            }

            return(lSfz);
        }
示例#10
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 );
			}
		}