mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Updated PitShift to use a single delay line and updated effects.cpp for new RtAudio API.
This commit is contained in:
@@ -11,7 +11,7 @@ namespace stk {
|
|||||||
\brief STK simple pitch shifter effect class.
|
\brief STK simple pitch shifter effect class.
|
||||||
|
|
||||||
This class implements a simple pitch shifter
|
This class implements a simple pitch shifter
|
||||||
using delay lines.
|
using a delay line.
|
||||||
|
|
||||||
by Perry R. Cook and Gary P. Scavone, 1995--2021.
|
by Perry R. Cook and Gary P. Scavone, 1995--2021.
|
||||||
*/
|
*/
|
||||||
@@ -61,7 +61,7 @@ class PitShift : public Effect
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
DelayL delayLine_[2];
|
DelayL delayLine_;
|
||||||
StkFloat delay_[2];
|
StkFloat delay_[2];
|
||||||
StkFloat env_[2];
|
StkFloat env_[2];
|
||||||
StkFloat rate_;
|
StkFloat rate_;
|
||||||
@@ -83,16 +83,15 @@ inline StkFloat PitShift :: tick( StkFloat input )
|
|||||||
while ( delay_[1] < 12 ) delay_[1] += delayLength_;
|
while ( delay_[1] < 12 ) delay_[1] += delayLength_;
|
||||||
|
|
||||||
// Set the new delay line lengths.
|
// Set the new delay line lengths.
|
||||||
delayLine_[0].setDelay( delay_[0] );
|
delayLine_.setDelay( delay_[0] );
|
||||||
delayLine_[1].setDelay( delay_[1] );
|
|
||||||
|
|
||||||
// Calculate a triangular envelope.
|
// Calculate a triangular envelope.
|
||||||
env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
|
env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
|
||||||
env_[0] = 1.0 - env_[1];
|
env_[0] = 1.0 - env_[1];
|
||||||
|
|
||||||
// Delay input and apply envelope.
|
// Delay input and apply envelope.
|
||||||
lastFrame_[0] = env_[0] * delayLine_[0].tick( input );
|
lastFrame_[0] = env_[1] * delayLine_.tapOut( delay_[1] );
|
||||||
lastFrame_[0] += env_[1] * delayLine_[1].tick( input );
|
lastFrame_[0] = +env_[0] * delayLine_.tick( input );
|
||||||
|
|
||||||
// Compute effect mix and output.
|
// Compute effect mix and output.
|
||||||
lastFrame_[0] *= effectMix_;
|
lastFrame_[0] *= effectMix_;
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ int main( int argc, char *argv[] )
|
|||||||
// If you want to change the default sample rate (set in Stk.h), do
|
// If you want to change the default sample rate (set in Stk.h), do
|
||||||
// it before instantiating any objects! If the sample rate is
|
// it before instantiating any objects! If the sample rate is
|
||||||
// specified in the command line, it will override this setting.
|
// specified in the command line, it will override this setting.
|
||||||
Stk::setSampleRate( 44100.0 );
|
Stk::setSampleRate( 48000.0 );
|
||||||
|
|
||||||
// Parse the command-line arguments.
|
// Parse the command-line arguments.
|
||||||
unsigned int port = 2001;
|
unsigned int port = 2001;
|
||||||
@@ -253,11 +253,8 @@ int main( int argc, char *argv[] )
|
|||||||
iparameters.deviceId = adac.getDefaultInputDevice();
|
iparameters.deviceId = adac.getDefaultInputDevice();
|
||||||
iparameters.nChannels = 1;
|
iparameters.nChannels = 1;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( adac.openStream( &oparameters, &iparameters, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
adac.openStream( &oparameters, &iparameters, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << adac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,11 +264,8 @@ int main( int argc, char *argv[] )
|
|||||||
(void) signal( SIGINT, finish );
|
(void) signal( SIGINT, finish );
|
||||||
|
|
||||||
// If realtime output, set our callback function and start the dac.
|
// If realtime output, set our callback function and start the dac.
|
||||||
try {
|
if ( adac.startStream() ) {
|
||||||
adac.startStream();
|
std::cout << adac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,12 +276,7 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shut down the output stream.
|
// Shut down the output stream.
|
||||||
try {
|
|
||||||
adac.closeStream();
|
adac.closeStream();
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
\brief STK simple pitch shifter effect class.
|
\brief STK simple pitch shifter effect class.
|
||||||
|
|
||||||
This class implements a simple pitch shifter
|
This class implements a simple pitch shifter
|
||||||
using delay lines.
|
using a delay line.
|
||||||
|
|
||||||
by Perry R. Cook and Gary P. Scavone, 1995--2021.
|
by Perry R. Cook and Gary P. Scavone, 1995--2021.
|
||||||
*/
|
*/
|
||||||
@@ -21,18 +21,15 @@ PitShift :: PitShift( void )
|
|||||||
delay_[0] = 12;
|
delay_[0] = 12;
|
||||||
delay_[1] = maxDelay / 2;
|
delay_[1] = maxDelay / 2;
|
||||||
|
|
||||||
delayLine_[0].setMaximumDelay( maxDelay );
|
delayLine_.setMaximumDelay( maxDelay );
|
||||||
delayLine_[0].setDelay( delay_[0] );
|
delayLine_.setDelay( delay_[0] );
|
||||||
delayLine_[1].setMaximumDelay( maxDelay );
|
|
||||||
delayLine_[1].setDelay( delay_[1] );
|
|
||||||
effectMix_ = 0.5;
|
effectMix_ = 0.5;
|
||||||
rate_ = 1.0;
|
rate_ = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PitShift :: clear()
|
void PitShift :: clear()
|
||||||
{
|
{
|
||||||
delayLine_[0].clear();
|
delayLine_.clear();
|
||||||
delayLine_[1].clear();
|
|
||||||
lastFrame_[0] = 0.0;
|
lastFrame_[0] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user