You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
accuratevibrato/accurate_vibrato2.h

61 lines
2.4 KiB

/* Accurate Vibrato object 2
* Copyright (c) 2020, Mark Tillotson, markt@chaos.org.uk
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __ACCURATE_VIBRATO2_h__
#define __ACCURATE_VIBRATO2_h__
#include <Arduino.h>
#include <Audio.h>
#include <AudioStream.h>
#if AUDIO_BLOCK_SAMPLES != 128
# error "Only works for AUDIO_BLOCK_SAMPLES == 128 currently"
#endif
#define VIBRATO_SINC_SAMPLES 16 // assumed in code to be even
#define VIBRATO_SINC_SAMPLES_FULL 10 // the range of sinc samples with no tapering applied
// so the sinc index varies -16 -- +16, with cosine tapering applied outside the range -10 -- +10
// Reasonable compromise between speed and effect accuracy. For better accuracy use 24 & 16
// about 10% CPU on 600MHz T4, 40% CPU on 150MHz T4
class AudioEffectHighQualityVibrato : public AudioStream
{
public:
AudioEffectHighQualityVibrato(void) ;// : AudioStream(1, inputQueueArray) {}
void modulation (float hertz, float percent) ;
virtual void update(void);
private:
audio_block_t * inputQueueArray[1];
uint32_t mod_phase_acc ;
uint32_t mod_phase_inc ;
float buffer [4 * AUDIO_BLOCK_SAMPLES] ;
int bptr, cptr ; // circular buffer indices
float mod_depth ; // fixpoint 8.24 modulation depth in samples, must stay in range -126.0 -> +126.0
static float cos_table [VIBRATO_SINC_SAMPLES+1] ;
};
#endif