Madwin74

Boss CE-2w Chorus

May 9th, 2023
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | Source Code | 0 0
  1. /***********************************************************
  2.  **                                                       **
  3.  **   Codesnippets written by Madwin for MMP 2023         **
  4.  **                                                       **
  5.  **   Not to be used freely. the code still has errors    **
  6.  **   It's intended to be used as starting point.         **
  7.  **   Code has not been checked and might still need      **
  8.  **   (a lot of) work.                                    **
  9.  **                                                       **
  10.  **   © MadMedia Productions 2023                         **
  11.  **                                                       **
  12.  ***********************************************************/
  13.  
  14.  
  15.  
  16. //  C# class that emulates a Boss CE-2w Chorus pedal using the
  17. //  CSCore library to process live audio input in real-time:
  18.  
  19.  
  20.  
  21. using CSCore;
  22. using CSCore.DSP;
  23. using CSCore.SoundIn;
  24. using CSCore.Streams;
  25. using CSCore.Streams.Effects;
  26.  
  27. public class BossCE2wChorus
  28. {
  29.     private readonly IWaveSource _waveSource;
  30.     private readonly Chorus _chorus;
  31.  
  32.     public BossCE2wChorus(IWaveSource waveSource)
  33.     {
  34.         _waveSource = waveSource;
  35.  
  36.         // Set up the chorus effect
  37.         _chorus = new Chorus
  38.         {
  39.             WetDryMix = 0.5f,
  40.             Depth = 0.1f,
  41.             Feedback = 0.1f,
  42.             Frequency = 0.3f,
  43.             Delay = 0.003f,
  44.         };
  45.     }
  46.  
  47.     public IWaveSource GetOutputSource()
  48.     {
  49.         // Apply the chorus effect to the input source and return the output
  50.         return new DmoEffectStream(_waveSource, _chorus.ToDmoProvider(), DmoStreamFlags.None);
  51.     }
  52. }
  53.  
  54.  
  55. ///////////////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////
  57.  
  58.  
  59. //  Here's an example of how you could use this class to process
  60. //  live audio input in real-time:
  61.  
  62.  
  63.  
  64. using CSCore;
  65. using CSCore.CoreAudioAPI;
  66. using CSCore.SoundIn;
  67. using CSCore.Streams;
  68.  
  69. public static class Program
  70. {
  71.     public static void Main()
  72.     {
  73.         // Set up the audio capture device
  74.         var captureDevice = new WasapiCapture(true, AudioClientShareMode.Shared, 100);
  75.  
  76.         // Set up the output device
  77.         var playbackDevice = new WasapiOut();
  78.  
  79.         // Set up the chorus effect
  80.         var chorus = new BossCE2wChorus(captureDevice);
  81.  
  82.         // Set up the output source
  83.         var outputSource = new SingleBlockNotificationStream(chorus.GetOutputSource());
  84.  
  85.         // Start capturing and playing back audio
  86.         captureDevice.Initialize();
  87.         captureDevice.Start();
  88.         playbackDevice.Initialize(outputSource);
  89.         playbackDevice.Play();
  90.  
  91.         // Wait for the user to press a key
  92.         Console.ReadKey();
  93.  
  94.         // Stop capturing and playing back audio
  95.         captureDevice.Stop();
  96.         captureDevice.Dispose();
  97.         playbackDevice.Stop();
  98.         playbackDevice.Dispose();
  99.     }
  100. }
  101.  
  102. /*
  103. This example sets up a live audio capture device using the CSCore library, applies the Boss CE-2w Chorus effect to the captured audio in real-time using the BossCE2wChorus class we defined earlier, and plays back the processed audio using another CSCore device. Note that this example only captures and plays back audio for a short period of time in response to a user key press, but you could easily modify it to capture and play back audio indefinitely.
  104. */
Advertisement
Add Comment
Please, Sign In to add comment