Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Added a simple pitch shifter
Browse files Browse the repository at this point in the history
  • Loading branch information
weespin committed Nov 8, 2020
1 parent 6c6e4d9 commit 6bce57d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 11 deletions.
4 changes: 2 additions & 2 deletions AcapellaDownloader/AcapellaDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="NAudio, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.4\lib\net35\NAudio.dll</HintPath>
<Reference Include="NAudio, Version=1.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.10.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
40 changes: 40 additions & 0 deletions AcapellaDownloader/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 34 additions & 8 deletions AcapellaDownloader/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;

namespace AcapellaDownloader
{
public partial class Form1 : Form
{
private float VoiceVolume = 1;
private const string _noText = "You did not enter the text";
private float VoiceVolume = 1f;
private float Pitch = 1f;
private const string _noText = "You did not enter the text";
private const string _noVoice = "Please select a voice";
public const string downloadError = "A download error has occurred";
public const string downloaded = "Done!";
SmbPitchShiftingSampleProvider PitchProvider;
public Form1()
{
InitializeComponent();
InitializeComponent();
}
private void btnDownload_Click(object sender, EventArgs e)
{
Expand All @@ -30,10 +33,12 @@ private void btnDownload_Click(object sender, EventArgs e)
var s = dialog.ShowDialog();
if (s == DialogResult.OK)
{
using (var web = new WebClient())
{
web.DownloadFile(soundLink, dialog.FileName);
MessageBox.Show(downloaded);
using (var mf = new MediaFoundationReader(soundLink))
{
PitchProvider = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono());
PitchProvider.PitchFactor = Pitch;
MediaFoundationEncoder.EncodeToMp3(PitchProvider.ToWaveProvider(), dialog.FileName, 48000);
MessageBox.Show(downloaded);
}
}
}
Expand Down Expand Up @@ -99,11 +104,14 @@ void PlaySound(string link, int WaveOutDeviceId)
using (var wo = new WaveOutEvent())
{
wo.DeviceNumber = WaveOutDeviceId;
wo.Init(mf);
PitchProvider = new SmbPitchShiftingSampleProvider(mf.ToSampleProvider().ToMono());
PitchProvider.PitchFactor = Pitch;
wo.Init(PitchProvider);
wo.Volume = VoiceVolume;
wo.Play();
while (wo.PlaybackState == PlaybackState.Playing)
{
PitchProvider.PitchFactor = Pitch;
wo.Volume = VoiceVolume;
Thread.Sleep(500);
}
Expand Down Expand Up @@ -144,5 +152,23 @@ private void slVolume_VolumeChanged(object sender, EventArgs e)
VoiceVolume = slVolume.Volume;
}

private void tbPitch_Scroll(object sender, EventArgs e)
{
if (tbPitch.Value > 11)
{
Pitch =((tbPitch.Value - 1) / 10f);
}
else if (tbPitch.Value < 11)
{
Pitch = (((tbPitch.Value - 1) / 10f * 0.5f) + 0.5f);
}
else
{
Pitch = 1f;
}

lbl_pitchValue.Text = Pitch.ToString();

}
}
}
2 changes: 1 addition & 1 deletion AcapellaDownloader/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NAudio" version="1.8.4" targetFramework="net461" />
<package id="NAudio" version="1.10.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
</packages>

0 comments on commit 6bce57d

Please sign in to comment.