diff --git a/lib/include/bofstd/bofaudiostandard.h b/lib/include/bofstd/bofaudiostandard.h index 018a208..41890ae 100644 --- a/lib/include/bofstd/bofaudiostandard.h +++ b/lib/include/bofstd/bofaudiostandard.h @@ -44,8 +44,8 @@ enum class BOF_WAVE_FORM_TYPE BOF_WAVE_FORM_TYPE_SAW_TOOTH, BOF_WAVE_FORM_TYPE_MAX }; - -bool Bof_GenerateWaveform(BOF_WAVE_FORM_TYPE _WaveForm_E, float _Amplitude_f, float _Frequency_f, float _SampleRate_f, uint32_t _ChunkSize_U32, float *_pDataY_f, float &_rPhase_f); +template +bool Bof_GenerateWaveform(BOF_WAVE_FORM_TYPE _WaveForm_E, T _Amplitude_f, float _Frequency_f, float _SampleRate_f, uint32_t _ChunkSize_U32, T *_pDataY, float &_rPhase_f); class BOFSTD_EXPORT BofAudioStandard { diff --git a/lib/src/bofaudiostandard.cpp b/lib/src/bofaudiostandard.cpp index c4087df..7b4c17d 100644 --- a/lib/src/bofaudiostandard.cpp +++ b/lib/src/bofaudiostandard.cpp @@ -27,15 +27,15 @@ #include BEGIN_BOF_NAMESPACE() -bool Bof_GenerateWaveform(BOF_WAVE_FORM_TYPE _WaveForm_E, float _Amplitude_f, float _Frequency_f, - float _SampleRate_f, uint32_t _ChunkSize_U32, float *_pDataY_f, float &_rPhase_f) +template +bool Bof_GenerateWaveform(BOF_WAVE_FORM_TYPE _WaveForm_E, T _Amplitude, float _Frequency_f, float _SampleRate_f, uint32_t _ChunkSize_U32, T *_pDataY, float &_rPhase_f) { bool Rts_B = false; uint32_t i_U32; float IncPhase_f, Phase_f, PeriodFactor_f; //_pDataX_f tested below !! - if ((_WaveForm_E < BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_MAX) && (_Amplitude_f > 0.0f) && (_Frequency_f > 0.0f) && (_SampleRate_f > 0.0f) && (_ChunkSize_U32) && (_pDataY_f)) + if ((_WaveForm_E < BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_MAX) && (_Amplitude) && (_Frequency_f > 0.0f) && (_SampleRate_f > 0.0f) && (_ChunkSize_U32) && (_pDataY)) { Rts_B = true; // After _SampleRate_f / _Frequency_f we have covered 2 M_PI, so for Fr 440 Fe 44100 we roll over angle after 100 sample->So for a chunk of 1024 byte we have 10 sinus @@ -52,28 +52,28 @@ bool Bof_GenerateWaveform(BOF_WAVE_FORM_TYPE _WaveForm_E, float _Amplitude_f, fl case BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_SINUS: for (i_U32 = 0; i_U32 < _ChunkSize_U32; i_U32++) { - _pDataY_f[i_U32] = _Amplitude_f * sin(Phase_f); + _pDataY[i_U32] = static_cast(static_cast(_Amplitude) * sin(Phase_f)); Phase_f += IncPhase_f; } break; case BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_SQUARE: for (i_U32 = 0; i_U32 < _ChunkSize_U32; i_U32++) { - _pDataY_f[i_U32] = (sin(Phase_f) >= 0) ? _Amplitude_f : -_Amplitude_f; + _pDataY[i_U32] = (sin(Phase_f) >= 0) ? static_cast(_Amplitude) : static_cast(-_Amplitude); Phase_f += IncPhase_f; } break; case BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_TRIANGLE: for (i_U32 = 0; i_U32 < _ChunkSize_U32; i_U32++) { - _pDataY_f[i_U32] = (_Amplitude_f * fabs(fmod(Phase_f * PeriodFactor_f, 4.0f) - 2.0f)) - _Amplitude_f; + _pDataY[i_U32] = static_cast((static_cast(_Amplitude) * fabs(fmod(Phase_f * PeriodFactor_f, 4.0f) - 2.0f)) - static_cast(_Amplitude)); Phase_f += IncPhase_f; } break; case BOF_WAVE_FORM_TYPE::BOF_WAVE_FORM_TYPE_SAW_TOOTH: for (i_U32 = 0; i_U32 < _ChunkSize_U32; i_U32++) { - _pDataY_f[i_U32] = (_Amplitude_f * (2.0f * fmod(Phase_f * PeriodFactor_f * 0.25f, 1.0f)) - _Amplitude_f); + _pDataY[i_U32] = static_cast((static_cast(_Amplitude) * (2.0f * fmod(Phase_f * PeriodFactor_f * 0.25f, 1.0f)) - static_cast(_Amplitude))); Phase_f += IncPhase_f; } break;