MyApp(){ lpf.type(LOW_PASS); // Set filter to low-pass response lpf.res(4); // Set resonance amount to emphasize filter env.attack(0.01); // Set short (10 ms) attack env.decay(0.4); // Set longer (400 ms) decay tmr.freq(120./60.*4.); // Set timer frequency to 120 BPM tmr.phaseMax(); // Ensures timer triggers on first sample modCutoff.period(30); // Set period of cutoff modulation modCutoff.phase(0.5); // Start half-way through cycle freq.lag(0.1); // Lag time of portamento effect step=0; }
void Cascade::setLayout (const LayoutBase& proto) { const int numPoles = proto.getNumPoles(); m_numStages = (numPoles + 1)/ 2; assert (m_numStages <= m_maxStages); Biquad* stage = m_stageArray; for (int i = 0; i < m_numStages; ++i, ++stage) stage->setPoleZeroPair (proto[i]); applyScale (proto.getNormalGain() / std::abs (response (proto.getNormalW() / (2 * doublePi)))); }
void Cascade::setLayout (const LayoutBase& proto) { const int numPoles = proto.getNumPoles(); m_numStages = (numPoles + 1)/ 2; if (m_numStages > m_maxStages) throw std::invalid_argument("Number of stages is larger than the max stages."); Biquad* stage = m_stageArray; for (int i = 0; i < m_numStages; ++i, ++stage) stage->setPoleZeroPair (proto[i]); applyScale (proto.getNormalGain() / std::abs (response (proto.getNormalW() / (2 * doublePi)))); }
void onAudio(AudioIOData& io){ while(io()){ if(tmr()){ // Our sequence of pitches float pitches[] = {0,0,12,0,0,10,-5,0}; // Map pitch class to a frequency in Hz float f = 55 * pow(2, pitches[step]/12.); // Increment step counter step = (step + 1) % 8; // Set new target frequence of portamento freq = f; // Restart envelope using a soft reset (to avoid clicks) env.resetSoft(); } // Set saw frequency from portamento filter saw.freq(freq()); // Get next envelope value float e = env(); // Map envelope value to cutoff frequency lpf.freq(e * (modCutoff.paraU()*6000 + 500) + 40); // Generate next saw sample float s = saw() * 0.3; // Filter saw sample s = lpf(s) * e; // Send sample to DAC io.out(0) = io.out(1) = s; } }
int main() { tmr.period(3); // Reset the envelope every 3 seconds env.attack(0.01); // Attack time env.decay(0.05); // Decay time // Delays, lowpass, and allpass filters setup code goes here // lpf.type(LOW_PASS); lpf.freq(2600); lpf.res(sqrt(2.0)/2.0); AudioIO audioIO(frameCount, samplingRate, audioCallBack, NULL, channelsOut, channelsIn); Sync::master().spu(audioIO.framesPerSecond()); audioIO.start(); printf("Press 'enter' to quit...\n"); getchar(); return 0; }
HRTFKernel::HRTFKernel(AudioChannel* channel, size_t fftSize, float sampleRate, bool bassBoost) : m_frameDelay(0) , m_sampleRate(sampleRate) { ASSERT(channel); // Determine the leading delay (average group delay) for the response. m_frameDelay = extractAverageGroupDelay(channel, fftSize / 2); float* impulseResponse = channel->data(); size_t responseLength = channel->length(); if (bassBoost) { // Run through some post-processing to boost the bass a little -- the HRTF's seem to be a little bass-deficient. // FIXME: this post-processing should have already been applied to the HRTF file resources. Once the files are put into this form, // then this code path can be removed along with the bassBoost parameter. Biquad filter; filter.setLowShelfParams(700.0 / nyquist(), 6.0); // boost 6dB at 700Hz filter.process(impulseResponse, impulseResponse, responseLength); } // We need to truncate to fit into 1/2 the FFT size (with zero padding) in order to do proper convolution. size_t truncatedResponseLength = min(responseLength, fftSize / 2); // truncate if necessary to max impulse response length allowed by FFT // Quick fade-out (apply window) at truncation point unsigned numberOfFadeOutFrames = static_cast<unsigned>(sampleRate / 4410); // 10 sample-frames @44.1KHz sample-rate ASSERT(numberOfFadeOutFrames < truncatedResponseLength); if (numberOfFadeOutFrames < truncatedResponseLength) { for (unsigned i = truncatedResponseLength - numberOfFadeOutFrames; i < truncatedResponseLength; ++i) { float x = 1.0f - static_cast<float>(i - (truncatedResponseLength - numberOfFadeOutFrames)) / numberOfFadeOutFrames; impulseResponse[i] *= x; } } m_fftFrame = adoptPtr(new FFTFrame(fftSize)); m_fftFrame->doPaddedFFT(impulseResponse, truncatedResponseLength); }
void audioCB(AudioIOData& io){ while(io()){ if(tmr()){ switch(cnt){ case 0: filt.type(Filter::LP); printf("Low-pass\n"); break; case 1: filt.type(Filter::HP); printf("High-pass\n"); break; case 2: filt.type(Filter::BP); printf("Band-pass\n"); break; case 3: filt.type(Filter::BR); printf("Band-reject\n"); break; } ++cnt %= 4; } float cutoff = scl::pow3(mod.triU()) * 10000; filt.res(4); filt.freq(cutoff); float s = filt(src()); io.out(0) = io.out(1) = s * 0.1f; } }