/* this routine saves the data in the provided sample storage object as a WAVE */ /* formatted file. it handles any error reporting to the user. the object is */ /* NOT disposed, so the caller has to do that. */ public static void ExportWAVSample( SampleStorageActualRec TheSample, int SamplingRate) { string path; using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Filter = "WAV Audio File (.wav)|*.wav"; DialogResult result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } path = dialog.FileName; } using (Stream outputStream = new FileStream( path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, Constants.BufferSize)) { using (WAVWriter outputWriter = new WAVWriter( outputStream, TheSample.NumChannels, TheSample.NumBits, SamplingRate)) { outputWriter.WritePoints( TheSample.Buffer, 0, TheSample.NumPoints); } } }
public override void Unbuild() { SampleData = null; }
public override bool EnsureBuilt( bool force, PcodeSystem.IEvaluationContext pcodeEnvironment, BuildFailedCallback failedCallback) { if (!force && (SampleData != null)) { return(true); } SampleData = null; PcodeRec FuncCode; if (!BuildCode(failedCallback, out FuncCode)) { return(false); } using (ParamStackRec ParamList = new ParamStackRec()) { ArrayHandleFloat dataHandleLeft = new ArrayHandleFloat(new float[0]); ArrayHandleFloat dataHandleRight = new ArrayHandleFloat(new float[0]); int initialCapacity = 1 /*loopstart1*/ + 1 /*loopstart2*/ + 1 /*loopstart3*/ + 1 /*loopend1*/ + 1 /*loopend2*/ + 1 /*loopend3*/ + 1 /*origin*/ + 1 /*samplingrate*/ + 1 /*naturalfrequency*/ + (NumChannels == NumChannelsType.eSampleStereo ? 2 : 1) /*data or leftdata/rightdata */ + 1 /*retaddr*/; ParamList.EmptyParamStackEnsureCapacity(initialCapacity); ParamList.AddIntegerToStack(LoopStart1); ParamList.AddIntegerToStack(LoopStart2); ParamList.AddIntegerToStack(LoopStart3); ParamList.AddIntegerToStack(LoopEnd1); ParamList.AddIntegerToStack(LoopEnd2); ParamList.AddIntegerToStack(LoopEnd3); ParamList.AddIntegerToStack(Origin); ParamList.AddIntegerToStack(SamplingRate); ParamList.AddDoubleToStack(NaturalFrequency); if (NumChannels == NumChannelsType.eSampleStereo) { ParamList.AddArrayToStack(dataHandleLeft); ParamList.AddArrayToStack(dataHandleRight); } else { ParamList.AddArrayToStack(dataHandleLeft); } ParamList.AddIntegerToStack(0); /* return address placeholder */ CodeCenterRec CodeCenter = ((Document)Parent).CodeCenter; EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, CodeCenter, out ErrorInfo, pcodeEnvironment); if (EvaluationError != EvalErrors.eEvalNoError) { failedCallback( this, new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, CodeCenter)); return(false); } Debug.Assert(ParamList.GetStackNumElements() == initialCapacity); // args - retaddr + return value #if DEBUG ParamList.Elements[9].AssertFloatArray(); #endif dataHandleLeft = ParamList.Elements[9].reference.arrayHandleFloat; if (NumChannels == NumChannelsType.eSampleStereo) { #if DEBUG ParamList.Elements[10].AssertFloatArray(); #endif dataHandleRight = ParamList.Elements[10].reference.arrayHandleFloat; } if (NumChannels == NumChannelsType.eSampleStereo) { float[] Left = dataHandleLeft.floats; float[] Right = dataHandleRight.floats; if (Left.Length != Right.Length) { failedCallback( this, new PcodeEvaluationErrorInfo( "<anonymous>", "Left and Right algorithmic sample arrays are not the same size.", 1)); return(false); } SampleData = new SampleStorageActualRec(Left.Length, NumBitsType.Max, NumChannels); for (int i = 0; i < Left.Length; i++) { SampleData[2 * i + 0] = Left[i]; SampleData[2 * i + 1] = Right[i]; } } else { float[] Mono = dataHandleLeft.floats; SampleData = new SampleStorageActualRec(Mono.Length, NumBitsType.Max, NumChannels); for (int i = 0; i < Mono.Length; i++) { SampleData[i] = Mono[i]; } } } return(true); }