Skip to content

Commit

Permalink
Refactor: Spectrum —> FreqSpectrum
Browse files Browse the repository at this point in the history
Remedy collision with TuningLib Spectrum:

https://github.com/celesteh/TuningLib/blob/master/Spectrum.sc
  • Loading branch information
joslloand committed Sep 12, 2019
1 parent 8717462 commit 1d4f21d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Classes/Spectrum.sc → Classes/FreqSpectrum.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// may want to change the superclass
Spectrum : Number {
FreqSpectrum : Number {
var <>magnitude, <>phase;

*new { arg magnitude, phase;
Expand All @@ -22,7 +22,7 @@ Spectrum : Number {

*newComplex { arg complex;
var polar = complex.asPolar;
^Spectrum.new(polar.magnitude, polar.phase)
^FreqSpectrum.new(polar.magnitude, polar.phase)
}

*logShelf { arg size, freq0, freq1, gainDC, gainNy, sampleRate;
Expand Down Expand Up @@ -71,7 +71,7 @@ Spectrum : Number {
}
});

^Spectrum.new(mag)
^FreqSpectrum.new(mag)
}

rho { ^magnitude }
Expand All @@ -83,7 +83,7 @@ Spectrum : Number {
real { ^(magnitude * cos(phase)).as(Signal) }
imag { ^(magnitude * sin(phase)).as(Signal) }

asSpectrum { ^this }
asFreqSpectrum { ^this }
asPolar { ^Polar.new(magnitude, phase) }
asComplex { ^Complex.new(this.real, this.imag) }

Expand Down Expand Up @@ -207,7 +207,7 @@ Spectrum : Number {
}

// math
neg { ^Spectrum.new(magnitude, phase + pi) }
neg { ^FreqSpectrum.new(magnitude, phase + pi) }

// math - in place
invert { phase = phase + pi }
Expand Down Expand Up @@ -262,7 +262,7 @@ Spectrum : Number {
}

printOn { arg stream;
stream << "Spectrum( " << magnitude << ", " << phase << " )";
stream << "FreqSpectrum( " << magnitude << ", " << phase << " )";
}

storeArgs { ^[magnitude, phase] }
Expand Down
6 changes: 3 additions & 3 deletions Classes/extComplex.sc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

+ Complex {

// Spectrum class
*newSpectrum { arg spectrum;
// FreqSpectrum class
*newFreqSpectrum { arg spectrum;
^spectrum.asComplex
}

asSpectrum { ^Spectrum.newComplex(this) }
asFreqSpectrum { ^FreqSpectrum.newComplex(this) }

// could add to MathLib Quark...
rotate { arg angle;
Expand Down
10 changes: 5 additions & 5 deletions Classes/extSignal.sc
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@

rcomplex = this.rfft(cosTable); // real fft

complex = Spectrum.newComplex(
complex = FreqSpectrum.newComplex(
rcomplex.real.rfftToFft(rcomplex.imag) // mirror spectrum
).linearPhase(sym).asComplex; // mirrored linearPhase
rcomplexLin = complex.real.fftToRfft(complex.imag); // discard negative freqs

rcomplexLin.real.irfft(rcomplexLin.imag, cosTable) // irfft
}, { // czt via dft
complex = Spectrum.newComplex(
complex = FreqSpectrum.newComplex(
this.dft(Signal.newClear(this.size)) // dft
).linearPhase(sym).asComplex;

Expand Down Expand Up @@ -407,14 +407,14 @@

rcomplex = osThis.rfft(cosTable); // real fft

complex = Spectrum.newComplex(
complex = FreqSpectrum.newComplex(
rcomplex.real.rfftToFft(rcomplex.imag) // mirror spectrum
).minimumPhase(mindb).asComplex; // mirrored minimumPhase
rcomplexMin = complex.real.fftToRfft(complex.imag); // discard negative freqs

rcomplexMin.real.irfft(rcomplexMin.imag, cosTable).keep(this.size) // irfft
}, { // czt via dft
complex = Spectrum.newComplex(
complex = FreqSpectrum.newComplex(
osThis.dft(Signal.newClear(osSize)) // dft
).minimumPhase(mindb).asComplex;

Expand Down Expand Up @@ -1215,7 +1215,7 @@
var spectrum, complex;

// complex spectrum
spectrum = Spectrum.logShelf(size, freq0, freq1, gainDC, gainNy, sampleRate);
spectrum = FreqSpectrum.logShelf(size, freq0, freq1, gainDC, gainNy, sampleRate);

// assign phase
(phase == \min).if({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
TITLE:: Spectrum
TITLE:: FreqSpectrum
summary:: Spectral processing
categories:: Math
related:: Classes/Signal, Classes/Polar, Classes/Complex

DESCRIPTION::
A Spectrum represents a sampled function in the frequency domain, in a polar form.
A FreqSpectrum represents a sampled function in the frequency domain, in a polar form.

CLASSMETHODS::

Expand All @@ -21,7 +21,7 @@ code::
~phase = Array.with(0.0) ++ ~randRadian ++ Array.with(0.0) ++ (~randRadian.reverse.neg); // 0.0 at DC & Nyquist, otherwise, symmetric random

// design allpass spectrum
~spectrum = Spectrum.new(phase: ~phase);
~spectrum = FreqSpectrum.new(phase: ~phase);

// synthesize REAL kernel
~signal = ~spectrum.real.ifft(~spectrum.imag, ~cosTable).real;
Expand All @@ -30,10 +30,10 @@ code::
::

argument:: magnitude
Spectrum magnitude. If code::nil:: set to 1.
Frequency domain magnitude. If code::nil:: set to 1.

argument:: phase
Spectrum phase. If code::nil:: set to 0.
Frequency domain phase. If code::nil:: set to 0.



Expand All @@ -55,7 +55,7 @@ code::
~complex = ~real.fft(~imag, ~cosTable);

// spectrum
~spectrum = Spectrum.newComplex(~complex);
~spectrum = FreqSpectrum.newComplex(~complex);

~spectrum.magnitude.plot("magnitude");
::
Expand Down Expand Up @@ -90,7 +90,7 @@ The sample rate, in Hz.
INSTANCEMETHODS::

METHOD:: size
Spectrum size.
FreqSpectrum size.


subsection:: Frequeny
Expand Down Expand Up @@ -135,7 +135,7 @@ code::
~complex = ~real.fft(~imag, ~cosTable);

// spectrum
~spectrum = Spectrum.newComplex(~complex).normalize;
~spectrum = FreqSpectrum.newComplex(~complex).normalize;

~spectrum.magnitude.plot("magnitude");
::
Expand Down Expand Up @@ -221,7 +221,7 @@ Return the imaginary part of the complex spectrum.



PRIVATE:: hash, storeArgs, printOn, asSpectrum
PRIVATE:: hash, storeArgs, printOn, asFreqSpectrum


EXAMPLES::
Expand Down
2 changes: 1 addition & 1 deletion HelpSource/Classes/Signal.ext.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ See link::#*readWave:: discussion above.
METHOD:: logShelf

Return a log shelf filter kernel.FOOTNOTE::Baird, J; Jackson, B; and D McGrath. “Raised Cosine Equalization Utilizing Log Scale Filter Synthesis.“ 117th Audio Engineering Society Convention, San Francisco, USA. October 2004. Permalink: link::http://www.aes.org/e-lib/browse.cfm?elib=12914::
:: See also: link::Classes/Spectrum#*logShelf::.
:: See also: link::Classes/FreqSpectrum#*logShelf::.


argument:: size
Expand Down

0 comments on commit 1d4f21d

Please sign in to comment.