-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GuitarML sample rate correction filter (#267)
* GuitarML: Adding optional sample rate correction filter * Try to fix file chooser bug on Linux * Adjust makeup filter tuning * Apply clang-format * Fix ambiguous chowdsp::Version --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
920c4c2
commit c6104e2
Showing
9 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import numpy as np | ||
from scipy.io import wavfile | ||
import scipy.signal as signal | ||
import matplotlib.pyplot as plt | ||
import audio_dspy as adsp | ||
|
||
def freqSmooth(x, sm=1.0/24.0): | ||
s = sm if sm > 1.0 else np.sqrt(2.0**sm) | ||
N = len(x) | ||
y = np.zeros_like(x) | ||
for i in range(N): | ||
i1 = max(int(np.floor(i/s)), 0) | ||
i2 = min(int(np.floor(i*s)+1), N-1) | ||
if i2 > i1: | ||
y[i] = np.mean(x[i1:i2]) | ||
return y | ||
|
||
def plot_fft(sig, fs, gain=1): | ||
b,a = adsp.design_highshelf(1000, 0.7071, gain, fs) | ||
xx = signal.lfilter(b, a, sig) | ||
|
||
freqs = np.fft.rfftfreq(len(xx), 1.0 / fs) | ||
fft = freqSmooth(np.fft.rfft(xx), 1.0) | ||
plt.semilogx(freqs, 20 * np.log10(np.abs(fft))) | ||
|
||
fs, x = wavfile.read("noise_48k.wav") | ||
print(fs) | ||
plot_fft(x, fs) | ||
|
||
fs, x = wavfile.read("noise_96k.wav") | ||
print(fs) | ||
plot_fft(x, fs) #, 1 / 2) | ||
|
||
fs, x = wavfile.read("noise_192k.wav") | ||
print(fs) | ||
plot_fft(x, fs) #, 1 / 4) | ||
|
||
plt.xlim(20, 28000) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "GuitarMLFilterDesigner.h" | ||
#include "../BYOD.h" | ||
|
||
GuitarMLFilterDesigner::GuitarMLFilterDesigner() | ||
{ | ||
this->commandOption = "--guitarml-filter"; | ||
this->argumentDescription = "--guitarml-filter"; | ||
this->shortDescription = "Generates files for GuitarML filter design"; | ||
this->longDescription = ""; | ||
this->command = [=] (const ArgumentList& args) | ||
{ generateFiles (args); }; | ||
} | ||
|
||
void GuitarMLFilterDesigner::generateFiles ([[maybe_unused]] const ArgumentList& args) | ||
{ | ||
static constexpr int bufferSize = 8192; | ||
chowdsp::AudioFileSaveLoadHelper saveLoadHelper; | ||
|
||
chowdsp::Noise<float> noiseGenerator; | ||
noiseGenerator.setGainDecibels (0.0f); | ||
noiseGenerator.setSeed (123); | ||
noiseGenerator.setNoiseType (chowdsp::Noise<float>::NoiseType::Normal); | ||
|
||
const auto factory = ProcessorStore::getStoreMap().at ("GuitarML"); | ||
const auto processFile = [&factory, | ||
&saveLoadHelper, | ||
&noiseGenerator] (const juce::String& filePath, double sampleRate) | ||
{ | ||
const auto file = File { filePath }; | ||
std::cout << "Rendering file " << file.getFullPathName() << " at sample rate " << sampleRate << std::endl; | ||
|
||
noiseGenerator.prepare ({ sampleRate, (uint32_t) bufferSize, 1 }); | ||
|
||
auto processor = factory (nullptr); | ||
processor->getParameters()[3]->setValueNotifyingHost (1.0f); | ||
processor->prepareProcessing (sampleRate, bufferSize); | ||
|
||
AudioBuffer<float> buffer { 1, bufferSize }; | ||
buffer.clear(); | ||
auto&& block = dsp::AudioBlock<float> { buffer }; | ||
|
||
noiseGenerator.process (dsp::ProcessContextReplacing<float> { block }); | ||
buffer.clear(); | ||
noiseGenerator.process (dsp::ProcessContextReplacing<float> { block }); | ||
processor->processAudioBlock (buffer); | ||
|
||
file.deleteFile(); | ||
saveLoadHelper.saveBufferToFile (filePath, buffer, sampleRate); | ||
}; | ||
|
||
processFile ("noise_48k.wav", 48000.0); | ||
processFile ("noise_96k.wav", 96000.0); | ||
processFile ("noise_192k.wav", 192000.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "../pch.h" | ||
|
||
class GuitarMLFilterDesigner : public ConsoleApplication::Command | ||
{ | ||
public: | ||
GuitarMLFilterDesigner(); | ||
|
||
private: | ||
/** Generates files for plotting GuitarML frequency content */ | ||
static void generateFiles (const ArgumentList& args); | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GuitarMLFilterDesigner) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters