Пример #1
0
DWORD ISndStreamWAV::GetCurrentTime()
{
    // return total time in ms
    if (GetSampleRate()>0)
        return (DWORD)sf_seek( m_pSndFile, 0, SEEK_CUR )/GetSampleRate()*1000;
    return 0;
}
    void prepareToPlay()
    {
        if (juceFilter != 0)
        {
#if ! JucePlugin_IsSynth
            juceFilter->setPlayConfigDetails (GetInput(0)->GetStreamFormat().mChannelsPerFrame,
#else
            juceFilter->setPlayConfigDetails (0,
#endif
                                              GetOutput(0)->GetStreamFormat().mChannelsPerFrame,
                                              GetSampleRate(),
                                              GetMaxFramesPerSlice());

            bufferSpace.setSize (juceFilter->getNumInputChannels() + juceFilter->getNumOutputChannels(),
                                 GetMaxFramesPerSlice() + 32);

            juceFilter->prepareToPlay (GetSampleRate(),
                                       GetMaxFramesPerSlice());

            midiEvents.clear();

            juce_free (channels);
            channels = (float**) juce_calloc (sizeof (float*) * jmax (juceFilter->getNumInputChannels(),
                                                                      juceFilter->getNumOutputChannels()) + 4);

            prepared = true;
        }
Пример #3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	karoke::karoke
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
karoke::karoke(AudioUnit component)
	: AUEffectBase(component, false)
{
	CreateElements();
	CAStreamBasicDescription streamDescIn;
	streamDescIn.SetCanonical(NUM_INPUTS, false);	// number of input channels
	streamDescIn.mSampleRate = GetSampleRate();
	
	CAStreamBasicDescription streamDescOut;
	streamDescOut.SetCanonical(NUM_OUTPUTS, false);	// number of output channels
	streamDescOut.mSampleRate = GetSampleRate();
	
	Inputs().GetIOElement(0)->SetStreamFormat(streamDescIn);
	Outputs().GetIOElement(0)->SetStreamFormat(streamDescOut);
	
	Globals()->UseIndexedParameters(kNumberOfParameters);
	SetParameter(kParam_One, kDefaultValue_ParamOne );
        
#if AU_DEBUG_DISPATCHER
	mDebugDispatcher = new AUDebugDispatcher (this);
#endif
	
	mLeftFilter = new FirFilter(200);
	mLeftFilter->setCoeffecients(lp_200, 200);
	mRightFilter = new FirFilter(200);
	mRightFilter->setCoeffecients(lp_200, 200);
}
Пример #4
0
void IPlugConvoEngine::Reset()
{
	TRACE; IMutexLock lock(this);

	// Detect a change in sample rate.
	if (GetSampleRate() != mSampleRate)
	{
		mSampleRate = GetSampleRate();

		const int irLength = sizeof(mIR) / sizeof(mIR[0]);
		const double irSampleRate = 44100.;
		mImpulse.SetNumChannels(1);

		#if defined(_USE_WDL_RESAMPLER)
			mResampler.SetMode(false, 0, true); // Sinc, default size
			mResampler.SetFeedMode(true); // Input driven
		#elif defined(_USE_R8BRAIN)
			if (mResampler) delete mResampler;
			mResampler = new CDSPResampler16IR(irSampleRate, mSampleRate, mBlockLength);
		#endif

		// Resample the impulse response.
		int len = mImpulse.SetLength(ResampleLength(irLength, irSampleRate, mSampleRate));
		if (len) Resample(mIR, irLength, irSampleRate, mImpulse.impulses[0].Get(), len, mSampleRate);

		// Tie the impulse response to the convolution engine.
		mEngine.SetImpulse(&mImpulse);
	}
}
Пример #5
0
	void Synthesis::Reset()
	{
		TRACE;
		IMutexLock lock(this);
		mOscillator.setSampleRate(GetSampleRate());
		mEnvelopeGenerator.setSampleRate(GetSampleRate());
	}
Пример #6
0
DWORD ISndStreamWAV::GetTotalTime()
{
    // return total time in ms
    if (GetSampleRate()>0)
        return m_dwSamples/GetSampleRate()*1000;
    return 0;
}
Пример #7
0
INT MPEGHeader::CalcFrameSize()
{
	m_nFrameSize=0;

	if (GetSampleRate()==0)
	{
		ASSERT(FALSE);
		return 0;
	}

	switch (GetLayer())
	{
		case 1:
			m_nFrameSize = (12 * GetBitRate()*1000)/GetSampleRate();
			if (m_RawMPEGHeader.Padding)
				m_nFrameSize++;
			m_nFrameSize  <<= 2;		// one slot is 4 bytes long
		break;
		case 2:
		case 3:
			m_nFrameSize = (144 * GetBitRate()*1000) / GetSampleRate();

			if (m_RawMPEGHeader.Version == MPEG_II)
				m_nFrameSize/=2;

			if (m_RawMPEGHeader.Padding)
				m_nFrameSize++;
		break;
		default:
			ASSERT(FALSE);
	}

	return m_nFrameSize;
}
    Float64 GetLatency()
    {
        jassert (GetSampleRate() > 0);

        if (GetSampleRate() <= 0)
            return 0.0;

        return juceFilter->getLatencySamples() / GetSampleRate();
    }
Пример #9
0
//--------------------------------------------------------------------------------
OSStatus SubSynth::GetProperty(AudioUnitPropertyID inPropertyID, AudioUnitScope inScope, AudioUnitElement inElement, void * outData)
{
	if (inScope == kAudioUnitScope_Global)
	{
		switch (inPropertyID)
		{
			case kAudioUnitProperty_ParameterValueFromString:
			{
				AudioUnitParameterValueFromString * name = (AudioUnitParameterValueFromString*)outData;
				if (name->inString == NULL)
					return kAudioUnitErr_InvalidPropertyValue;
				double paramValue_literal = CFStringGetDoubleValue(name->inString);
				switch (name->inParamID)
				{
					case kParam_Tune:
						if (paramValue_literal <= 0.0)
							name->outValue = 0.0;	// XXX avoid log10(0) or log10(-X)
						else
							name->outValue = (log10(paramValue_literal / (0.0726 * GetSampleRate())) + 2.5) / 1.5;
						break;
					case kParam_Release:
						return kAudioUnitErr_PropertyNotInUse;	// XXX I can't figure out how to invert this one
					default:
						return kAudioUnitErr_InvalidParameter;
				}
				return noErr;
			}

			case kAudioUnitProperty_ParameterStringFromValue:
			{
				AudioUnitParameterStringFromValue * name = (AudioUnitParameterStringFromValue*)outData;
				double paramValue = (name->inValue == NULL) ? GetParameter(name->inParamID) : *(name->inValue);
				int precision = 0;
				switch (name->inParamID)
				{
					case kParam_Tune:
						paramValue = 0.0726 * GetSampleRate() * pow(10.0, -2.5 + (1.5 * paramValue));
						precision = 3;
						break;
					case kParam_Release:
						paramValue = GetReleaseTimeForParamValue(paramValue);
						precision = 1;
						break;
					default:
						return kAudioUnitErr_InvalidParameter;
				}
				name->outString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%.*f"), precision, paramValue);
				if (name->outString == NULL)
					return coreFoundationUnknownErr;
				return noErr;
			}
		}
	}

	return AUEffectBase::GetProperty(inPropertyID, inScope, inElement, outData);
}
Пример #10
0
void CWaveInstrumentB::Start()
{
    m_wavePlayer.SetSampleRate(GetSampleRate());
    m_wavePlayer.Start();
	
	m_ar.SetSource(&m_wavePlayer);
	m_ar.SetSampleRate(GetSampleRate());
	m_ar.SetDuration(m_duration);
	m_ar.Start();

}
Пример #11
0
void ATKColoredExpander::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);
  
  switch (paramIdx)
  {
    case kPower:
    {
      auto power = GetParam(kPower)->Value();
      if (power == 0)
      {
        powerFilter.set_memory(0);
      }
      else
      {
        powerFilter.set_memory(std::exp(-1e3 / (power * GetSampleRate())));
      }
      break;
    }
    case kThreshold:
      gainExpanderFilter.set_threshold(std::pow(10, GetParam(kThreshold)->Value() / 10));
      break;
    case kSlope:
      gainExpanderFilter.set_ratio(GetParam(kSlope)->Value());
      break;
    case kSoftness:
      gainExpanderFilter.set_softness(std::pow(10, GetParam(kSoftness)->Value()));
      break;
    case kColored:
      gainExpanderFilter.set_color(GetParam(kColored)->Value());
      break;
    case kQuality:
      gainExpanderFilter.set_quality(GetParam(kQuality)->Value());
      break;
    case kAttack:
      attackReleaseFilter.set_attack(std::exp(-1e3/(GetParam(kAttack)->Value() * GetSampleRate()))); // in ms
      break;
    case kRelease:
      attackReleaseFilter.set_release(std::exp(-1e3/(GetParam(kRelease)->Value() * GetSampleRate()))); // in ms
      break;
    case kMaxReduction:
      gainExpanderFilter.set_max_reduction_db(GetParam(kMaxReduction)->Value());
      break;
    case kMakeup:
      volumeFilter.set_volume_db(GetParam(kMakeup)->Value());
      break;
    case kDryWet:
      drywetFilter.set_dry(GetParam(kDryWet)->Value());
      break;
      
    default:
      break;
  }
}
void CSubtractiveAmplitudeFilter::Start()
{
	mTime = 0;
	mEnvelope->SetDuration(mDuration);
	mEnvelope->SetSampleRate(GetSampleRate());
	mEnvelope->Start();
}
Пример #13
0
//--------------------------------------------------------------------------------
double SubSynth::GetReleaseTimeForParamValue(double inLinearValue)
{
	inLinearValue = 1.0 - pow(10.0, -2.0 - (3.0 * inLinearValue));
	if (inLinearValue == 0.0)
		inLinearValue = 10.0;	// XXX avoid log10(0) and division by 0
	return -301.03 / (GetSampleRate() * log10(fabs(inLinearValue)));
}
Пример #14
0
/*--------------------------------------------------------------------------------*/
bool ADMRIFFFile::CreateExtraChunks()
{
  bool success = true;

  if (adm)
  {
    RIFFChunk *chunk;
    uint64_t  chnalen;
    uint8_t   *chna;
    uint_t i, nchannels = GetChannels();

    success = true;

    for (i = 0; i < nchannels; i++)
    {
      ADMAudioTrack *track;

      // create chna track data
      if ((track = adm->CreateTrack(i)) != NULL)
      {
        track->SetSampleRate(GetSampleRate());
        track->SetBitDepth(GetBitsPerSample());
      }
    }

    if (!admfile.empty())
    {
      // create ADM structure (content and objects from file)
      if (adm->CreateFromFile(admfile.c_str()))
      {
        // can prepare cursors now since all objects have been created
        PrepareCursors();
      }
      else
      {
        BBCERROR("Unable to create ADM structure from '%s'", admfile.c_str());
        success = false;
      }
    }

    // get ADM object to create chna chunk
    if ((chna = adm->GetChna(chnalen)) != NULL)
    {
      // and add it to the RIFF file
      if ((chunk = AddChunk(chna_ID)) != NULL)
      {
        success &= chunk->CreateChunkData(chna, chnalen);
      }
      else BBCERROR("Failed to add chna chunk");

      // don't need the raw data any more
      delete[] chna;
    }
    else BBCERROR("No chna data available");

    success &= (AddChunk(axml_ID) != NULL);
  }

  return success;
}
Пример #15
0
BOOL OSndStreamWAV::OpenStream( const CUString& strFileName )
{
	SF_INFO wfInfo;

    memset(&wfInfo,0,sizeof(SF_INFO));
	wfInfo.samplerate  = GetSampleRate();
	wfInfo.frames      = -1;
	wfInfo.sections	   = 1;
	wfInfo.channels    = GetChannels();
	wfInfo.format      = (SF_FORMAT_WAV | m_OutputFormat) ;

	// Set file name
	SetFileName(strFileName);
	
    CUStringConvert strCnv;

	// Open stream
    #ifdef _UNICODE
    if (! (m_pSndFile = sf_open(	(const tchar*)strCnv.ToT( GetFileName() + _W( "." ) + GetFileExtention() ),
									SFM_WRITE,
									&wfInfo ) ) )
    #else
	if (! (m_pSndFile = sf_open(	strCnv.ToT( GetFileName() + _W( "." ) + GetFileExtention() ),
									SFM_WRITE,
									&wfInfo ) ) )
    #endif
	{
		ASSERT( FALSE );
		return FALSE;
	}

	// return Success
	return TRUE;
}
Пример #16
0
void ATKStereoCompressor::Reset()
{
  TRACE;
  IMutexLock lock(this);
  
  int sampling_rate = GetSampleRate();
  
  if (sampling_rate != endpoint.get_input_sampling_rate())
  {
    inLFilter.set_input_sampling_rate(sampling_rate);
    inLFilter.set_output_sampling_rate(sampling_rate);
    inRFilter.set_input_sampling_rate(sampling_rate);
    inRFilter.set_output_sampling_rate(sampling_rate);
    outLFilter.set_input_sampling_rate(sampling_rate);
    outLFilter.set_output_sampling_rate(sampling_rate);
    outRFilter.set_input_sampling_rate(sampling_rate);
    outRFilter.set_output_sampling_rate(sampling_rate);

    middlesidesplitFilter.set_input_sampling_rate(sampling_rate);
    middlesidesplitFilter.set_output_sampling_rate(sampling_rate);
    volumesplitFilter.set_input_sampling_rate(sampling_rate);
    volumesplitFilter.set_output_sampling_rate(sampling_rate);
    middlesidemergeFilter.set_input_sampling_rate(sampling_rate);
    middlesidemergeFilter.set_output_sampling_rate(sampling_rate);
    volumemergeFilter.set_input_sampling_rate(sampling_rate);
    volumemergeFilter.set_output_sampling_rate(sampling_rate);
    sumFilter.set_input_sampling_rate(sampling_rate);
    sumFilter.set_output_sampling_rate(sampling_rate);

    powerFilter1.set_input_sampling_rate(sampling_rate);
    powerFilter1.set_output_sampling_rate(sampling_rate);
    attackReleaseFilter1.set_input_sampling_rate(sampling_rate);
    attackReleaseFilter1.set_output_sampling_rate(sampling_rate);
    gainCompressorFilter1.set_input_sampling_rate(sampling_rate);
    gainCompressorFilter1.set_output_sampling_rate(sampling_rate);
    makeupFilter1.set_input_sampling_rate(sampling_rate);
    makeupFilter1.set_output_sampling_rate(sampling_rate);

    powerFilter2.set_input_sampling_rate(sampling_rate);
    powerFilter2.set_output_sampling_rate(sampling_rate);
    attackReleaseFilter2.set_input_sampling_rate(sampling_rate);
    attackReleaseFilter2.set_output_sampling_rate(sampling_rate);
    gainCompressorFilter2.set_input_sampling_rate(sampling_rate);
    gainCompressorFilter2.set_output_sampling_rate(sampling_rate);
    makeupFilter2.set_input_sampling_rate(sampling_rate);
    makeupFilter2.set_output_sampling_rate(sampling_rate);

    applyGainFilter.set_input_sampling_rate(sampling_rate);
    applyGainFilter.set_output_sampling_rate(sampling_rate);
    drywetFilter.set_input_sampling_rate(sampling_rate);
    drywetFilter.set_output_sampling_rate(sampling_rate);
    endpoint.set_input_sampling_rate(sampling_rate);
    endpoint.set_output_sampling_rate(sampling_rate);

    attackReleaseFilter1.set_release(std::exp(-1e3 / (GetParam(kAttack1)->Value() * sampling_rate))); // in ms
    attackReleaseFilter1.set_attack(std::exp(-1e3 / (GetParam(kRelease1)->Value() * sampling_rate))); // in ms
    attackReleaseFilter2.set_release(std::exp(-1e3 / (GetParam(kAttack2)->Value() * sampling_rate))); // in ms
    attackReleaseFilter2.set_attack(std::exp(-1e3 / (GetParam(kRelease2)->Value() * sampling_rate))); // in ms
  }
}
Пример #17
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	RadioEffectUnit::RadioEffectUnit
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RadioEffectUnit::RadioEffectUnit(AudioUnit Component)
	: AUEffectBase(Component)
{
	CreateElements();

	if (!bGLocalized) {		
		// Because we are in a component, we need to load our bundle by identifier so we can access our localized strings
		// It is important that the string passed here exactly matches that in the Info.plist Identifier string
		CFBundleRef bundle = CFBundleGetBundleWithIdentifier( CFSTR("com.epicgames.audiounit.radio") );
		
		if (bundle != NULL) {
			kChebyshevPowerMultiplierName = CFCopyLocalizedStringFromTableInBundle(kChebyshevPowerMultiplierName, CFSTR("Localizable"), bundle, CFSTR(""));
			kChebyshevPowerName = CFCopyLocalizedStringFromTableInBundle(kChebyshevPowerName, CFSTR("Localizable"), bundle, CFSTR(""));
			kChebyshevMultiplierName = CFCopyLocalizedStringFromTableInBundle(kChebyshevMultiplierName, CFSTR("Localizable"), bundle, CFSTR(""));	
			kChebyshevCubedMultiplierName = CFCopyLocalizedStringFromTableInBundle(kChebyshevCubedMultiplierName, CFSTR("Localizable"), bundle, CFSTR(""));	
		}
		bGLocalized = TRUE; //so never pass the test again...
	}

	GFinalBandPassFilter.Initialize( 2000.0f, 400.0f, GetSampleRate() );

	SetParameter(RadioParam_ChebyshevPowerMultiplier, 	kDefaultValue_ChebyshevPowerMultiplier );
	SetParameter(RadioParam_ChebyshevPower, 			kDefaultValue_ChebyshevPower );
	SetParameter(RadioParam_ChebyshevMultiplier, 		kDefaultValue_ChebyshevMultiplier );
	SetParameter(RadioParam_ChebyshevCubedMultiplier,	kDefaultValue_ChebyshevCubedMultiplier );
}
Пример #18
0
void Synthesis::Reset()
{
  TRACE;
  IMutexLock lock(this);
  double sampleRate = GetSampleRate();
  VoiceManager::getInstance().setSampleRate(sampleRate);
}
Пример #19
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	FilterKernel::GetFrequencyResponse()
//
//		returns scalar magnitude response
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double FilterKernel::GetFrequencyResponse( double inFreq /* in Hertz */ )
{
	float srate = GetSampleRate();
	
	double scaledFrequency = 2.0 * inFreq / srate;
	
	// frequency on unit circle in z-plane
	double zr = cos(M_PI * scaledFrequency);
	double zi = sin(M_PI * scaledFrequency);
	
	// zeros response
	double num_r = mA0*(zr*zr - zi*zi) + mA1*zr + mA2;
	double num_i = 2.0*mA0*zr*zi + mA1*zi;
	
	double num_mag = sqrt(num_r*num_r + num_i*num_i);
	
	// poles response
	double den_r = zr*zr - zi*zi + mB1*zr + mB2;
	double den_i = 2.0*zr*zi + mB1*zi;
	
	double den_mag = sqrt(den_r*den_r + den_i*den_i);
	
	// total response
	double response = num_mag  / den_mag;

	
	return response;
}
Пример #20
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	TremoloUnit::TremoloUnitKernel::TremoloUnitKernel()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is the constructor for the TremoloUnitKernel helper class, which holds the DSP code 
//  for the audio unit. TremoloUnit is an n-to-n audio unit; one kernel object gets built for 
//  each channel in the audio unit.
//
// The first line of the method consists of the constructor method declarator and constructor-
//  initializer. In addition to calling the appropriate superclasses, this code initializes two 
//  member variables:
//
// mCurrentScale:		a factor for correlating points in the current wave table to
//						the audio signal sampling frequency. to produce the desired
//						tremolo frequency
// mSamplesProcessed:	a global count of samples processed. it allows the tremolo effect
//						to be continuous over data input buffer boundaries
//
// (In the Xcode template, the header file contains the call to the superclass constructor.)
TremoloUnit::TremoloUnitKernel::TremoloUnitKernel (AUEffectBase *inAudioUnit ) : AUKernelBase (inAudioUnit),
	mSamplesProcessed (0), mCurrentScale (0)
{	
	// Generates a wave table that represents one cycle of a sine wave, normalized so that
	//  it never goes negative and so it ranges between 0 and 1; this sine wave specifies 
	//  how to vary the volume during one cycle of tremolo.
	for (int i = 0; i < kWaveArraySize; ++i) {
		double radians = i * 2.0 * pi / kWaveArraySize;
		mSine [i] = (sin (radians) + 1.0) * 0.5;
	}

	// Does the same for a pseudo square wave, with nice rounded corners to avoid pops.
	for (int i = 0; i < kWaveArraySize; ++i) {
		double radians = i * 2.0 * pi / kWaveArraySize;
		radians = radians + 0.32; // shift the wave over for a smoother start
		mSquare [i] =
			(
				sin (radians) +	// Sums the odd harmonics, scaled for a nice final waveform
				0.3 * sin (3 * radians) +
				0.15 * sin (5 * radians) +
				0.075 * sin (7 * radians) +
				0.0375 * sin (9 * radians) +
				0.01875 * sin (11 * radians) +
				0.009375 * sin (13 * radians) +
				0.8			// Shifts the value so it doesn't go negative.
			) * 0.63;		// Scales the waveform so the peak value is close 
							//  to unity gain.
	}

	// Gets the samples per second of the audio stream provided to the audio unit. 
	// Obtaining this value here in the constructor assumes that the sample rate
	// will not change during one instantiation of the audio unit.
	mSampleFrequency = GetSampleRate ();
}
Пример #21
0
void IPlugInstrument::Reset()
{
	TRACE;
	IMutexLock lock(this);

	mSamplePeriod = 1./GetSampleRate();
}
Пример #22
0
__int64 ISndStreamWAV::Seek( __int64 ddwOffset, UINT nFrom )
{
    __int64	ddwFilePosition = 0;
    int		nPercent = (int)ddwOffset;

    // Flush the stream
    Flush();

    switch ( nFrom )
    {
    case SEEK_PERCENT:
        if ( nPercent<0  ) nPercent= 0;
        if ( nPercent>99 ) nPercent=99;
        ddwFilePosition= (__int64)( nPercent * m_ddwTotalFileSize / 100.0 );
        break;

    case SEEK_TIME:
        ddwFilePosition= (__int64)( ddwOffset / 1000.0 * GetSampleRate() );
        break;
    default:
        ASSERT( FALSE );
        break;
    }

    ddwFilePosition = ddwFilePosition / 4 * 4;

    // Seek to the desired position
    sf_seek( m_pSndFile, ddwFilePosition, SEEK_SET );

    return ddwFilePosition;
}
Пример #23
0
void ATKTransientSplitter::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);
  
  switch (paramIdx)
  {
    case kPower:
    {
      auto power = GetParam(kPower)->Value();
      if (power == 0)
      {
        powerFilter.set_memory(0);
      }
      else
      {
        powerFilter.set_memory(std::exp(-1e3 / (power * GetSampleRate())));
      }
      break;
    }
    case kThreshold:
      gainSwellFilter.set_threshold(std::pow(10, GetParam(kThreshold)->Value() / 10));
      break;
    case kSlope:
      gainSwellFilter.set_ratio(GetParam(kSlope)->Value());
      break;
    case kSoftness:
      gainSwellFilter.set_softness(std::pow(10, GetParam(kSoftness)->Value()));
      break;
    case kAttack:
      slowAttackReleaseFilter.set_attack(std::exp(-1e3/(GetParam(kAttack)->Value() * GetSampleRate()))); // in ms
      fastAttackReleaseFilter.set_attack(std::exp(-1e3/(GetParam(kAttack)->Value() * GetSampleRate() * GetParam(kAttackRatio)->Value() / 100))); // in ms
      break;
    case kAttackRatio:
      fastAttackReleaseFilter.set_attack(std::exp(-1e3/(GetParam(kAttack)->Value() * GetSampleRate() * GetParam(kAttackRatio)->Value() / 100))); // in ms
      break;
    case kRelease:
      fastAttackReleaseFilter.set_release(std::exp(-1e3/(GetParam(kRelease)->Value() * GetSampleRate()))); // in ms
      slowAttackReleaseFilter.set_release(std::exp(-1e3/(GetParam(kRelease)->Value() * GetSampleRate() * GetParam(kReleaseRatio)->Value() / 100))); // in ms
      break;
    case kReleaseRatio:
      slowAttackReleaseFilter.set_release(std::exp(-1e3/(GetParam(kRelease)->Value() * GetSampleRate() * GetParam(kReleaseRatio)->Value() / 100))); // in ms
      break;
      
    default:
      break;
  }
}
Пример #24
0
void DspOscillator::_BuildLookup()
{
    float posFrac = _lookupLength <= 0 ? 0 : (float)_lastPos / (float)_lookupLength;
    float angleInc = TWOPI * GetFreq() / GetSampleRate();

    _lookupLength = (int)((float)GetSampleRate() / GetFreq());

    _signal.resize(GetBufferSize());
    _signalLookup.resize(_lookupLength);

    for (int i = 0; i < _lookupLength; i++)
    {
        _signalLookup[i] = sin(angleInc * i) * GetAmpl();
    }

    _lastPos = (int)(posFrac * (float)_lookupLength + 0.5f);  // calculate new position (round up)
}
Пример #25
0
//--------------------------------------------------------------------------------
float Tracker::TrackerKernel::filterFreq(float hz)
{
	float j, k, r=0.999f;

	j = r * r - 1;
	k = 2.f - 2.f * r * r * cosf(0.647f * hz / (float)GetSampleRate() );
	return (sqrtf(k*k - 4.f*j*j) - k) / (2.f*j);
}
Пример #26
0
DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
{
	//
	// Set the sample rate
	//
	DWORD dwControlReg = MIA_48000;

	switch ( dwNewSampleRate )
	{
		case 96000 :
			dwControlReg = MIA_96000;
			break;
			
		case 88200 :
			dwControlReg = MIA_88200;
			break;
			
		case 44100 : 
			dwControlReg = MIA_44100;
			break;
			
		case 32000 :
			dwControlReg = MIA_32000;
			break;
	}

	//
	// Override the clock setting if this Mia is set to S/PDIF clock
	//	
	if ( ECHO_CLOCK_SPDIF == GetInputClock() )
		dwControlReg |= MIA_SPDIF;
	
	//
	//	Set the control register if it has changed
	//
	if (dwControlReg != GetControlRegister())
	{
		if ( !WaitForHandshake() )
			return 0xffffffff;

		//
		// Set the values in the comm page; the dwSampleRate
		// field isn't used by the DSP, but is read by the call
		// to GetSampleRate below
		//		
		m_pDspCommPage->dwSampleRate = SWAP( dwNewSampleRate );
		SetControlRegister( dwControlReg );

		//
		//	Poke the DSP
		// 
		ClearHandshake();
		SendVector( DSP_VC_UPDATE_CLOCKS );
	}
	
	return GetSampleRate();
		
} // DWORD CMiaDspCommObject::SetSampleRate( DWORD dwNewSampleRate )
Пример #27
0
Zstort::Zstort(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mGain(1.)
{
  TRACE;

  //arguments are: name, defaultVal, minVal, maxVal, step, label
  GetParam(kGain)->InitDouble("Gain", 8., 0., 100.0, 0.01, "%");
  GetParam(kGain)->SetShape(2.);

  GetParam(kTremDepth)->InitDouble("TremDepth", 100., 0., 100.0, 0.01, "%");
  GetParam(kTremDepth)->SetShape(2.);

  GetParam(kTremFreq)->InitDouble("TremFreq", 4., 0.01, 15, 0.01, "hz");
  //GetParam(kTremFreq)->SetShape(2.);
  
  GetParam(kDist)->InitDouble("Distortion", 100., 0.1, 100., 0.01, "%");
  GetParam(kDist)->SetShape(2.);

  GetParam(kBits)->InitInt("BitRate", 32, 1, 32, "bits");

  GetParam(kRate)->InitInt("RateReduction", 1, 1, 32, "x");


  IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
  pGraphics->AttachPanelBackground(&COLOR_BLACK);
 
  IRECT distRect(kDistX, kDistY - 5, 200, 80.);
  IText textProps3(14, &COLOR_RED, "Arial", IText::kStyleItalic, IText::kAlignNear, 0, IText::kQualityDefault);
  pGraphics->AttachControl(new ITextControl(this, IRECT(kDistX, kDistY -25, 200, 80), &textProps3, "Distortion"));
  pGraphics->AttachControl(new ITextControl(this, IRECT(kGainX, kGainY - 25, 200, 80), &textProps3, "Gain"));
  pGraphics->AttachControl(new ITextControl(this, IRECT(kTremDepthX, kTremDepthY - 25, 200, 80), &textProps3, "Tremolo Depth"));
  pGraphics->AttachControl(new ITextControl(this, IRECT(kTremFreqX, kTremFreqY - 25, 200, 80), &textProps3, "Tremolo\nFrequency"));
  pGraphics->AttachControl(new ITextControl(this, IRECT(kRateX, kRateY - 25, 200, 80), &textProps3, "Sample Rate\nReduction"));
  pGraphics->AttachControl(new ITextControl(this, IRECT(kBitsX, kBitsY - 25, 200, 80), &textProps3, "BitCrusher"));
  
  //attempt at updating values live -can't seem to redraw
  distIdx = pGraphics->AttachControl(new ITextControl(this, IRECT(200, 300, 200, 80), &textProps3, "Distortion: xx!"));


  IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);

  pGraphics->AttachControl(new IKnobMultiControl(this, kGainX, kGainY, kGain, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kTremDepthX, kTremDepthY, kTremDepth, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kTremFreqX, kTremFreqY, kTremFreq, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kDistX, kDistY, kDist, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kBitsX, kBitsY, kBits, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kRateX, kRateY, kRate, &knob));

  AttachGraphics(pGraphics);

  //MakePreset("preset 1", ... );
  MakeDefaultPreset((char *) "-", kNumPrograms);

  this->distortion = new DistortionProcessor(1.);
  this->bitCrusher = new BitCrushProcessor(32);
  this->rateReducer = new SampleRateReductionProcessor(1);
  this->trem = new TremoloProcessor(4., 1, 2, GetSampleRate());
}
Пример #28
0
void AutoTalent::Reset()
{
  TRACE;
  IMutexLock lock(this);
  
  unsigned long sr = GetSampleRate();
  
  if( fs != sr) init(sr);
}
Пример #29
0
XnStatus XnAudioStream::CalcRequiredSize(XnUInt32* pnRequiredSize) const
{
    XnUInt32 nSampleSize = 2 * m_nMaxNumberOfChannels; // 16-bit per channel (2 bytes)
    XnUInt32 nSamples = (XnUInt32)(GetSampleRate() * XN_AUDIO_STREAM_BUFFER_SIZE_IN_SECONDS);

    *pnRequiredSize = nSamples * nSampleSize;

    return (XN_STATUS_OK);
}
Пример #30
0
//--------------------------------------------------------------------------------
void Tracker::TrackerKernel::Reset()
{
	dphi = 100.f / (float)GetSampleRate(); //initial pitch
	min = (long) (GetSampleRate() / 30.0); //lower limit

	phi = 0.0f;
	buf1 = 0.0f;
	buf2 = 0.0f;
	dn = 0.0f;
	bold = 0.0f;
	env = 0.0f;
	saw = 0.0f;
	dsaw = 0.0f;
	buf3 = 0.0f;
	buf4 = 0.0f;
	num = 0;
	sig = 0;
}