public static void MainLoop <U>( AudioFilePlayGeneratorParams <T, W> generatorParams, Synthesizer.DataOutCallbackMethod <OutputGeneric <T, U, W> > dataCallback, OutputGeneric <T, U, W> dataCallbackState, Synthesizer.StopTask stopper) { try { const int NUMPOINTS = 256; float[] buffer = new float[NUMPOINTS]; float[] buffer2 = new float[NUMPOINTS * 2]; int c; while ((c = generatorParams.reader.ReadPoints(buffer, 0, buffer.Length)) != 0) { if (stopper.Stopped) { break; } if (generatorParams.reader.NumChannels == NumChannelsType.eSampleStereo) { dataCallback( dataCallbackState, buffer, 0, c / 2); } else { for (int i = 0; i < c; i++) { buffer2[2 * i + 0] = buffer[i]; buffer2[2 * i + 1] = buffer[i]; } dataCallback( dataCallbackState, buffer2, 0, c); } } } catch (Exception exception) { generatorParams.exception = exception; stopper.Stop(); } }
public static void SynthesizerMainLoop <U>( SynthesizerGeneratorParams <T, W> generatorParams, Synthesizer.DataOutCallbackMethod <OutputGeneric <T, U, W> > dataCallback, OutputGeneric <T, U, W> dataCallbackState, Synthesizer.StopTask stopper) { try { generatorParams.result = Synthesizer.DoSynthesizer( generatorParams.document, dataCallback, dataCallbackState, generatorParams.listOfTracks, generatorParams.keyTrack, generatorParams.frameToStartAt, generatorParams.samplingRate * generatorParams.oversamplingFactor, generatorParams.oversamplingFactor, generatorParams.envelopeRate, generatorParams.defaultBeatsPerMinute, generatorParams.overallVolumeScalingReciprocal, generatorParams.scanningGap, stopper, generatorParams.showSummary, out generatorParams.errorInfo, generatorParams.interactionLog, generatorParams.deterministic, generatorParams.randomSeed, generatorParams.automationSettings); } catch (Exception exception) { Program.WriteLog("SynthesizerMainLoop", exception.ToString()); generatorParams.exception = exception; stopper.Stop(); } finally { generatorParams.completed = true; } }
public static void MainLoop<U>( WaveTableTestGeneratorParams<T, W> generatorParams, Synthesizer.DataOutCallbackMethod<OutputGeneric<T, U, W>> dataCallback, OutputGeneric<T, U, W> dataCallbackState, Synthesizer.StopTask stopper) { try { // Unoptimized - since only one runs at a time this codepath is not perf critical (unlike the // resampler loops in the synth engine) int NumTables = generatorParams.data.NumTables; float[][] ReferenceArray = new float[NumTables][]; for (int i = 0; i < NumTables; i++) { ReferenceArray[i] = generatorParams.data.ListOfTables[i].frames; } int PlaybackSamplingRate = generatorParams.samplingRate; if (PlaybackSamplingRate < Constants.MINSAMPLINGRATE) { PlaybackSamplingRate = Constants.MINSAMPLINGRATE; } if (PlaybackSamplingRate > Constants.MAXSAMPLINGRATE) { PlaybackSamplingRate = Constants.MAXSAMPLINGRATE; } int FramesPerTable = generatorParams.data.NumFrames; /* this is the initial index into the wave table */ Synthesizer.Fixed64 WaveformIndex = new Synthesizer.Fixed64(); /* this is the 16.16 bit fixed point number used to increment the index */ /* into the wave table */ Synthesizer.Fixed64 WaveformIncrementor = new Synthesizer.Fixed64( FramesPerTable * generatorParams.frequency / PlaybackSamplingRate); /* the number of times each wave slice has to be used */ int NumberOfIterationsAttack = (int)(generatorParams.attack * PlaybackSamplingRate); int NumberOfIterationsDecay = (int)(generatorParams.decay * PlaybackSamplingRate); const int SOUNDBUFFERLENGTHFRAMES = 256; float[] OutputBuffer = new float[SOUNDBUFFERLENGTHFRAMES * 2]; int OutputIndex = 0; for (int i = 0; i < NumberOfIterationsAttack + NumberOfIterationsDecay; i++) { /* compute wave table index for attack/decay phase */ double TableIndex; if (i < NumberOfIterationsAttack) { TableIndex = (double)i / NumberOfIterationsAttack; } else { TableIndex = (double)(NumberOfIterationsDecay + NumberOfIterationsAttack - i) / NumberOfIterationsDecay; } float Value = Synthesizer.WaveTableIndexer( WaveformIndex.Double, TableIndex * (NumTables - 1), NumTables, FramesPerTable, ReferenceArray, true/*EnableCrossWaveTableInterpolation*/); WaveformIndex += WaveformIncrementor; OutputBuffer[2 * OutputIndex + 0] = OutputBuffer[2 * OutputIndex + 1] = Value * .5f; OutputIndex++; if (OutputIndex == SOUNDBUFFERLENGTHFRAMES) { dataCallback( dataCallbackState, OutputBuffer, 0, SOUNDBUFFERLENGTHFRAMES); OutputIndex = 0; if (stopper.Stopped) { return; } } } dataCallback( dataCallbackState, OutputBuffer, 0, OutputIndex); } catch (Exception exception) { generatorParams.exception = exception; stopper.Stop(); } }
public static void MainLoop <U>( PlayFileWithEffectsGeneratorParams <T, W> generatorParams, Synthesizer.DataOutCallbackMethod <OutputGeneric <T, U, W> > dataCallback, OutputGeneric <T, U, W> dataCallbackState, Synthesizer.StopTask stopper) { try { generatorParams.result = Synthesizer.SynthStateRec.InitializeSynthesizer( out generatorParams.synthState, generatorParams.mainWindow.Document, new List <TrackObjectRec>(), null, 0 /*FrameToStartAt*/, generatorParams.reader.SamplingRate, 1 /*Oversampling*/, generatorParams.mainWindow.Document.EnvelopeUpdateRate, (LargeBCDType)generatorParams.mainWindow.Document.DefaultBeatsPerMinute, 1 /*OverallVolumeScalingReciprocal*/, (LargeBCDType)0d /*ScanningGap*/, out generatorParams.errorInfo, TextWriter.Synchronized(generatorParams.interactionLog), generatorParams.mainWindow.Document.Deterministic, generatorParams.mainWindow.Document.Seed, new Synthesizer.AutomationSettings()); if (generatorParams.result != Synthesizer.SynthErrorCodes.eSynthDone) { return; } // HACK! generatorParams.result = Synthesizer.NewTrackEffectGenerator( generatorParams.effectSpec, generatorParams.synthState.SynthParams0, out generatorParams.synthState.ScoreEffectProcessor); if (generatorParams.result != Synthesizer.SynthErrorCodes.eSynthDone) { return; } while (!stopper.Stopped) { // TODO: shouldn't ask for nAllocatedPointsOneChannel, that's slightly inaccurate. Should // use the clock logic in SynthGenerateOneCycle -- see e.g. nActualFrames int c; if (generatorParams.reader.NumChannels == NumChannelsType.eSampleMono) { c = generatorParams.reader.ReadPoints( generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceLOffset, generatorParams.synthState.SynthParams0.nAllocatedPointsOneChannel); Synthesizer.FloatVectorCopy( generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceLOffset, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceROffset, c); } else { c = generatorParams.reader.ReadPoints( generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.SectionWorkspaceLOffset, generatorParams.synthState.SynthParams0.nAllocatedPointsOneChannel * 2); c /= 2; Synthesizer.FloatVectorMakeUninterleaved( generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.SectionWorkspaceLOffset, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceLOffset, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceROffset, c); } if (c == 0) { break; } // HACK! // Should create specialized version of Synthesizer.SynthGenerateOneCycle that does this Synthesizer.UpdateStateTrackEffectGenerator( generatorParams.synthState.ScoreEffectProcessor, generatorParams.synthState.SynthParams0); Synthesizer.ApplyTrackEffectGenerator( generatorParams.synthState.ScoreEffectProcessor, generatorParams.synthState.SynthParams0.workspace, c, generatorParams.synthState.SynthParams0.ScoreWorkspaceLOffset, generatorParams.synthState.SynthParams0.ScoreWorkspaceROffset, generatorParams.synthState.SynthParams0); Synthesizer.FloatVectorMakeInterleaved( generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceLOffset, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.ScoreWorkspaceROffset, c, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.SectionWorkspaceLOffset); dataCallback( dataCallbackState, generatorParams.synthState.SynthParams0.workspace, generatorParams.synthState.SynthParams0.SectionWorkspaceLOffset, c); } } catch (Exception exception) { generatorParams.exception = exception; stopper.Stop(); } }