Madwin74

Synthesizer pedal emulator

May 16th, 2023
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.15 KB | Source Code | 0 0
  1. /***********************************************************
  2.  ***********************************************************
  3.  **                                                       **
  4.  **   Codesnippets written by Madwin for MMP 2023         **
  5.  **                                                       **
  6.  **   Not to be used freely. the code still has errors    **
  7.  **   It's intended to be used as starting point.         **
  8.  **   Code has not been checked and might still need      **
  9.  **   (a lot of) work.                                    **
  10.  **                                                       **
  11.  **   ℗ & © MadMedia Productions 2023                     **
  12.  **                                                       **
  13.  ***********************************************************
  14.  ***********************************************************
  15.  **                                                       **
  16.  **   -- Disclaimer: --                                   **
  17.  **                                                       **
  18.  **   If code is used in private projects and/or for      **
  19.  **   study purposes please mention resource. Any other   **
  20.  **   use -whether commercial or non-commercial- is not   **
  21.  **   condoned by the author and violates his intent.     **
  22.  **                                                       **
  23.  **   [email protected]                             **
  24.  **                                                       **
  25.  ***********************************************************
  26.  ***********************************************************/
  27.  
  28.  
  29.  
  30. using CSCore;
  31. using CSCore.SoundIn;
  32. using CSCore.Streams;
  33. using CSCore.Streams.Effects;
  34. using CSCore.WaveTables;
  35.  
  36. public class BossSY1Emulator
  37. {
  38.     private ISoundIn soundIn;
  39.     private IWaveSource waveSource;
  40.     private ISampleSource sampleSource;
  41.     private EffectChain effectChain;
  42.  
  43.     // Control parameters
  44.     public float Effect { get; set; }
  45.     public float Direct { get; set; }
  46.     public float Tone { get; set; }
  47.     public float Rate { get; set; }
  48.     public float Depth { get; set; }
  49.     public float Variation { get; set; }
  50.     public int Type { get; set; } // 0 = Lead 1, 1 = Lead 2, 2 = Pad, 3 = Bass, 4 = STR, 5 = Organ, 6 = Bell, 7 = SFX 1, 8 = SFX 2, 9 = SEQ 1, 10 = SEQ 2
  51.  
  52.     public BossSY1Emulator()
  53.     {
  54.         soundIn = new WasapiLoopbackCapture();
  55.         waveSource = new SoundInSource(soundIn);
  56.         sampleSource = waveSource.ToSampleSource().ToStereo();
  57.         effectChain = new EffectChain();
  58.  
  59.         // Add your desired effects here based on control parameters
  60.         effectChain.Add(new DelayEffect { WetDryMix = Effect });
  61.         effectChain.Add(new ToneFilter { CutOff = Tone });
  62.  
  63.         // Select sound type based on Type parameter
  64.         switch (Type)
  65.         {
  66.             case 0: // Lead 1
  67.                 effectChain.Add(new SineGenerator(440f)); // Replace with your own lead 1 sound generator
  68.                 break;
  69.             case 1: // Lead 2
  70.                 effectChain.Add(new SineGenerator(880f)); // Replace with your own lead 2 sound generator
  71.                 break;
  72.             case 2: // Pad
  73.                 effectChain.Add(new SquareGenerator(440f)); // Replace with your own pad sound generator
  74.                 break;
  75.             case 3: // Bass
  76.                 effectChain.Add(new SawtoothGenerator(220f)); // Replace with your own bass sound generator
  77.                 break;
  78.             case 4: // STR
  79.                 effectChain.Add(new TriangleGenerator(440f)); // Replace with your own STR sound generator
  80.                 break;
  81.             case 5: // Organ
  82.                 effectChain.Add(new SquareGenerator(440f)); // Replace with your own organ sound generator
  83.                 break;
  84.             case 6: // Bell
  85.                 effectChain.Add(new SineGenerator(880f)); // Replace with your own bell sound generator
  86.                 break;
  87.             case 7: // SFX 1
  88.                 effectChain.Add(new WhiteNoiseGenerator()); // Replace with your own SFX 1 sound generator
  89.                 break;
  90.             case 8: // SFX 2
  91.                 effectChain.Add(new PinkNoiseGenerator()); // Replace with your own SFX 2 sound generator
  92.                 break;
  93.             case 9: // SEQ 1
  94.                 effectChain.Add(new SawtoothGenerator(440f)); // Replace with your own SEQ 1 sound generator
  95.                 break;
  96.             case 10: // SEQ 2
  97.                 effectChain.Add(new TriangleGenerator(440f)); // Replace with your own SEQ 2 sound generator
  98.                 break;
  99.             default:
  100.                 break;
  101.         }
  102.  
  103.         sampleSource = effectChain.ToSampleSource();
  104.     }
  105.  
  106.     public void Start()
  107.     {
  108.         soundIn.Start();
  109.     }
  110.  
  111. public void Stop()
  112. {
  113.     soundIn.Stop();
  114. }
  115.  
  116. public ISampleSource GetOutputSource()
  117. {
  118.     return sampleSource;
  119. }
  120.  
  121. }
  122.  
  123. /*
  124.  
  125.  
  126. I've added the control parameters (`Effect`, `Direct`, `Tone`, `Rate`, `Depth`, `Variation`, `Type`) as properties of the
  127. `BossSY1Emulator` class. You can set these parameters to adjust the behavior of the synthesizer emulation.
  128.  
  129. The effects in the `effectChain` have been updated to include a `DelayEffect` with the `WetDryMix` parameter set to the
  130. `Effect` value, and a `ToneFilter` with the `CutOff` parameter set to the `Tone` value.
  131.  
  132. Based on the `Type` parameter, the appropriate sound generator is added to the `effectChain`. You can replace the placeholder
  133. sound generators (`SineGenerator`, `SquareGenerator`, `SawtoothGenerator`, `TriangleGenerator`, `WhiteNoiseGenerator`,
  134. `PinkNoiseGenerator`) with your own implementation or use other sound generation techniques to create the desired synth sounds.
  135.  
  136. Now you can create an instance of the `BossSY1Emulator` class, set the control parameters, and retrieve the output
  137. `ISampleSource` using the `GetOutputSource` method. This `ISampleSource` object can be used for real-time audio processing or playback.
  138.  
  139. Remember to add the necessary CSCore NuGet package to your project. Additionally, make sure to replace the placeholder sound generators
  140. with your own sound generation logic or use appropriate libraries for generating the desired synth sounds.
  141. */
Advertisement
Add Comment
Please, Sign In to add comment