Skip to content

Commit

Permalink
Common parts out, nem simplex project.
Browse files Browse the repository at this point in the history
Overdrive / distorion experimentation.
  • Loading branch information
MiklosPathy committed Feb 11, 2018
1 parent a423995 commit 9f74970
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PunkOrgan/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Slider x:Name="slider_Bending" Value="{Binding Bending}" HorizontalAlignment="Left" Margin="10,277,0,0" VerticalAlignment="Top" Width="581" Maximum="200" Minimum="-200" SmallChange="1" MouseLeftButtonUp="slider_Bending_MouseLeftButtonUp"/>
<Slider x:Name="slider_Leslie_Freq" Value="{Binding Leslie_Freq}" HorizontalAlignment="Left" Height="148" Margin="460,10,0,0" VerticalAlignment="Top" Width="20" Orientation="Vertical"/>
<Slider x:Name="slider_Leslie_Rate" Value="{Binding Leslie_Rate}" HorizontalAlignment="Left" Height="148" Margin="485,10,0,0" VerticalAlignment="Top" Width="20" Orientation="Vertical" Maximum="50"/>
<Slider x:Name="slider_OverDrive" Value="{Binding OverDrive}" HorizontalAlignment="Left" Height="148" Margin="412,10,0,0" VerticalAlignment="Top" Width="20" Orientation="Vertical" SmallChange="1" Maximum="100"/>
<Slider x:Name="slider_OverDrive" Value="{Binding OverDrive}" HorizontalAlignment="Left" Height="148" Margin="412,10,0,0" VerticalAlignment="Top" Width="20" Orientation="Vertical" SmallChange="1" Maximum="100" Minimum="10"/>
<Label x:Name="label" Content="Overdrive" HorizontalAlignment="Left" Margin="368,136,0,0" VerticalAlignment="Top" Height="26" RenderTransformOrigin="1.054,0.904">
<Label.RenderTransform>
<TransformGroup>
Expand Down
27 changes: 25 additions & 2 deletions PunkOrgan/PunkHammond.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public PunkHammond()

CurrentPolyphony = 3;

OverDrive = 0;
OverDrive = 10;

}

Expand Down Expand Up @@ -90,7 +90,8 @@ public override int Read(short[] buffer, int offset, int sampleCount)
//The 90 divider is for the drawbars. There are 9 of them. They have 10 position here.
currentsamplevalue = currentsamplevalue / 90 * short.MaxValue / CurrentPolyphony;

currentsamplevalue = overdrive(currentsamplevalue);
if (overDrive != 10) currentsamplevalue = overdrive(currentsamplevalue * overDrive / 10);
//currentsamplevalue = distortion(currentsamplevalue, overDrive / 10, 1);


currentsamplevalue = currentsamplevalue + echobuffer[limitechophase(echophase + Echo_Freq)] * Echo_Rate / 100;
Expand All @@ -105,6 +106,7 @@ public override int Read(short[] buffer, int offset, int sampleCount)
return sampleCount;
}

//Buffer looping
private int limitechophase(int phase)
{
return phase < echobuffersize ? phase : phase - echobuffersize;
Expand Down Expand Up @@ -146,5 +148,26 @@ private double overdrive(double input) //by Schetzen Formula
}
return signinput * short.MaxValue;
}

private double distortion(double x, double gain, double mix)
{
// Distortion based on an exponential function
// x - input
// gain - amount of distortion, >0->
// mix - mix of original and distorted sound, 1=only distorted
if (x == 0) return 0;
x = x / short.MaxValue;

double y = x / Math.Abs(x) * (1 - Math.Pow(Math.E, gain * x * x / Math.Abs(x)));
return y * short.MaxValue;


//double q = x * gain / Math.Abs(x);
//double z = Math.Sign(-q) * (1 - Math.Exp(Math.Sign(-q) * q));
//double y = mix * z * Math.Abs(x) / Math.Abs(z) + (1 - mix) * x;
//y = y * Math.Abs(x) / Math.Abs(y);


}
}
}

0 comments on commit 9f74970

Please sign in to comment.