public static OutputGeneric <T, PlayFileWithEffectsGeneratorParams <T, W>, W> Do( string baseName, GetDestinationMethod <T> getDestination, CreateDestinationHandlerMethod <T, W> createDestinationHandler, W destinationHandlerArguments, GeneratorMainLoopMethod <T, PlayFileWithEffectsGeneratorParams <T, W>, W> generatorMainLoop, PlayFileWithEffectsGeneratorParams <T, W> generatorParams, GeneratorCompletionMethod <PlayFileWithEffectsGeneratorParams <T, W> > generatorCompletion, IMainWindowServices mainWindow, NumChannelsType channels, NumBitsType bits, int samplingRate, int oversamplingFactor, bool showProgressWindow, bool modal) { // prerequisites return(OutputGeneric <T, PlayFileWithEffectsGeneratorParams <T, W>, W> .Do( baseName, getDestination, createDestinationHandler, destinationHandlerArguments, generatorMainLoop, generatorParams, generatorCompletion, channels, bits, samplingRate, oversamplingFactor, showProgressWindow, modal)); }
public static void Completion( PlayFileWithEffectsGeneratorParams <T, W> generatorParams, ref ClipInfo clipInfo) { if (generatorParams.synthState != null) { Synthesizer.SynthStateRec.FinalizeSynthesizer( generatorParams.synthState, (generatorParams.result == Synthesizer.SynthErrorCodes.eSynthDone) && (generatorParams.exception == null) /*writeOutputLogs*/); generatorParams.synthState = null; } if (generatorParams.reader != null) { generatorParams.reader.Close(); generatorParams.reader = null; } if (generatorParams.stream != null) { generatorParams.stream.Close(); generatorParams.stream = null; } string interactionLogFinal = generatorParams.interactionLog.ToString(); if (interactionLogFinal.Length != 0) { IInteractionWindowService interaction = generatorParams.mainWindow.GetInteractionWindow(); interaction.Append(interactionLogFinal); } string message = null; if (generatorParams.exception != null) { message = generatorParams.exception.ToString(); } else if (generatorParams.result != Synthesizer.SynthErrorCodes.eSynthDone) { message = Synthesizer.GetErrorMessage(generatorParams.result, generatorParams.errorInfo); } if (message != null) { MessageBox.Show(message, "Synthesis Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void buttonStop_Click(object sender, EventArgs e) { if (state != null) { state.stopper.Stop(); state = null; } #if false if (generatorParams.exception != null) { MessageBox.Show(generatorParams.exception.ToString()); } state = null; generatorParams = null; #endif }
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(); } }
private void buttonPlay_Click(object sender, EventArgs e) { MainWindow.DoAutosaveGlobally(); if (!mainWindow.MakeUpToDate()) { return; } Synthesizer.EffectSpecListRec effectSpec; if (!BuildThis(out effectSpec)) { return; } const double BufferDuration = 2f; #if false if (state != null) { state.stopper.Stop(); } state = null; #endif Stream stream = new FileStream(textBoxAudioFilePath.Text, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.BufferSize); AudioFileReader reader = null; try { reader = new WAVReader(stream); } catch (FormatException) { try { stream.Seek(0, SeekOrigin.Begin); reader = new AIFFReader(stream); } catch (FormatException) { MessageBox.Show("File is not a recognized AIFF or WAV file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #if true // prevents "Add New Data Source..." from working #if false state = #endif PlayFileWithEffectsGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .Do( Path.GetFileNameWithoutExtension(textBoxAudioFilePath.Text), OutputDeviceEnumerator.OutputDeviceGetDestination, OutputDeviceEnumerator.CreateOutputDeviceDestinationHandler, new OutputDeviceArguments(BufferDuration), PlayFileWithEffectsGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .MainLoop, #if false generatorParams = #endif new PlayFileWithEffectsGeneratorParams <OutputDeviceDestination, OutputDeviceArguments>( stream, reader, effectSpec, mainWindow), PlayFileWithEffectsGeneratorParams <OutputDeviceDestination, OutputDeviceArguments> .Completion, mainWindow, reader.NumChannels, reader.NumBits, reader.SamplingRate, 1 /*oversampling*/, true /*showProgressWindow*/, true /*modal*/); #endif }