1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SYNTHMARK_VOICE_BASE_H 18 #define SYNTHMARK_VOICE_BASE_H 19 20 #include <cstdint> 21 #include "SynthTools.h" 22 #include "UnitGenerator.h" 23 24 namespace marksynth { 25 /** 26 * Base class for building synthesizers. 27 */ 28 class VoiceBase : public UnitGenerator 29 { 30 public: VoiceBase()31 VoiceBase() 32 : mPitch(60.0) // MIDI Middle C is 60 33 , mVelocity(1.0) // normalized 34 { 35 } 36 37 virtual ~VoiceBase() = default; 38 setPitch(synth_float_t pitch)39 void setPitch(synth_float_t pitch) { 40 mPitch = pitch; 41 } 42 noteOn(synth_float_t pitch,synth_float_t velocity)43 void noteOn(synth_float_t pitch, synth_float_t velocity) { 44 mVelocity = velocity; 45 mPitch = pitch; 46 } 47 noteOff()48 void noteOff() { 49 } 50 51 virtual void generate(int32_t numFrames) = 0; 52 53 protected: 54 synth_float_t mPitch; 55 synth_float_t mVelocity; 56 }; 57 }; 58 #endif // SYNTHMARK_VOICE_BASE_H 59