Example #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);
            }
        }
        public GeneratorEnvelope(SoundfontBase aSoundfont, byte aVelocity, double aSecondsSustain = 0.0d)
        {
            soundfont = aSoundfont;

            waveform = aSoundfont.waveform;

            secondsSustain = aSecondsSustain;
            samplePosition = soundfont.soundinfo.offset;

            volume = ( float )Math.Pow(10.0d, ( double )aSoundfont.soundinfo.volume / 20.0d) * ( float )aVelocity / 8.0f;
            double lCenterFrequency = 440.0d * Math.Pow(2.0d, (( double )aSoundfont.soundinfo.pitchKeyCenter - 69.0d) / 12.0d);

            sampleSpeed = waveform.format.sampleRate / lCenterFrequency;

            generatorEnvelopeCurrent = GeneratorEnvelopeSet.generatorEnvelopeDelay;

            timeElapsedDelay   = 0.0d;
            timeElapsedAttack  = 0.0d;
            timeElapsedHold    = 0.0d;
            timeElapsedDecay   = 0.0d;
            timeElapsedSustain = 0.0d;
            timeElapsedRelease = 0.0d;
            timeElapsedEnd     = 0.0d;
            timeElapsedSum     = 0.0d;

            aSoundfont.waveform.reader.GetSample(0, 0);
        }
        public static float Calculate(WaveformReaderPcm aWaveformPcm, int aChannel, double aSampleCurrent)
        {
            float  a = aWaveformPcm.reader.GetSample(aChannel, ( int )aSampleCurrent);
            float  b = aWaveformPcm.reader.GetSample(aChannel, ( int )aSampleCurrent + 1);
            double positionDifference = aSampleCurrent - ( int )aSampleCurrent;

            return(( float )(a + (b - a) * positionDifference));
        }
Example #4
0
        public MusicPcm(FormAiffForm aFormFile)
        {
            Name     = aFormFile.name;
            Waveform = new WaveformReaderPcm(aFormFile, false);
            Length   = new SoundTime(Waveform.format.sampleRate, Waveform.format.samples);

            loopList = new List <List <LoopInformation> >();
            loopList.Add(new List <LoopInformation>());
            loopList[0].Add(new LoopInformation(Length.sampleRate, -1, -1));
        }
Example #5
0
        public SynthesizerPcm(WaveformReaderPcm aWaveform, LoopInformation aLoop)
        {
            waveform = aWaveform;

            oneSampelList = new Dictionary <int, SoundTime>();
            Position      = new SoundTime(waveform.format.sampleRate, 0);
            Elapsed       = new SoundTime(waveform.format.sampleRate, 0);

            loop   = aLoop;
            isLoop = false;
        }
Example #6
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);
        }