mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 11:33:44 +02:00
Merge pull request #3422 from chansensturm/audio-temp
Implement Gordon-Smith 2-pole quadrature oscillator
This commit is contained in:
commit
a9206e0e85
3 changed files with 49 additions and 48 deletions
|
@ -506,30 +506,34 @@ void Audio::handleAudioInput() {
|
|||
|
||||
QByteArray inputByteArray = _inputDevice->readAll();
|
||||
|
||||
int16_t* inputFrameData = (int16_t*)inputByteArray.data();
|
||||
const int inputFrameCount = inputByteArray.size() / sizeof(int16_t);
|
||||
if (!_muted && (_audioSourceInjectEnabled || _peqEnabled)) {
|
||||
|
||||
int16_t* inputFrameData = (int16_t*)inputByteArray.data();
|
||||
const int inputFrameCount = inputByteArray.size() / sizeof(int16_t);
|
||||
|
||||
_inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, false /*copy in*/);
|
||||
_inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, false /*copy in*/);
|
||||
|
||||
// _inputGain.render(_inputFrameBuffer); // input/mic gain+mute
|
||||
|
||||
// Add audio source injection if enabled
|
||||
if (_audioSourceInjectEnabled && !_muted) {
|
||||
|
||||
if (_toneSourceEnabled) { // sine generator
|
||||
_toneSource.render(_inputFrameBuffer);
|
||||
#if ENABLE_INPUT_GAIN
|
||||
_inputGain.render(_inputFrameBuffer); // input/mic gain+mute
|
||||
#endif
|
||||
// Add audio source injection if enabled
|
||||
if (_audioSourceInjectEnabled) {
|
||||
|
||||
if (_toneSourceEnabled) { // sine generator
|
||||
_toneSource.render(_inputFrameBuffer);
|
||||
}
|
||||
else if(_noiseSourceEnabled) { // pink noise generator
|
||||
_noiseSource.render(_inputFrameBuffer);
|
||||
}
|
||||
_sourceGain.render(_inputFrameBuffer); // post gain
|
||||
}
|
||||
else if(_noiseSourceEnabled) { // pink noise generator
|
||||
_noiseSource.render(_inputFrameBuffer);
|
||||
if (_peqEnabled) {
|
||||
_peq.render(_inputFrameBuffer); // 3-band parametric eq
|
||||
}
|
||||
_sourceGain.render(_inputFrameBuffer); // post gain
|
||||
}
|
||||
if (_peqEnabled && !_muted) {
|
||||
_peq.render(_inputFrameBuffer); // 3-band parametric eq
|
||||
}
|
||||
|
||||
_inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, true /*copy out*/);
|
||||
|
||||
_inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, true /*copy out*/);
|
||||
}
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::EchoLocalAudio) && !_muted && _audioOutput) {
|
||||
// if this person wants local loopback add that to the locally injected audio
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
//
|
||||
// AudioSourceTone.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Craig Hansen-Sturm on 8/10/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <SharedUtil.h>
|
||||
#include "AudioRingBuffer.h"
|
||||
#include "AudioFormat.h"
|
||||
#include "AudioBuffer.h"
|
||||
#include "AudioSourceTone.h"
|
||||
|
||||
uint32_t AudioSourceTone::_frameOffset = 0;
|
|
@ -12,13 +12,23 @@
|
|||
#ifndef hifi_AudioSourceTone_h
|
||||
#define hifi_AudioSourceTone_h
|
||||
|
||||
// Implements a two-pole Gordon-Smith oscillator
|
||||
class AudioSourceTone
|
||||
{
|
||||
static uint32_t _frameOffset;
|
||||
float32_t _frequency;
|
||||
float32_t _amplitude;
|
||||
float32_t _sampleRate;
|
||||
float32_t _omega;
|
||||
float32_t _epsilon;
|
||||
float32_t _yq1;
|
||||
float32_t _y1;
|
||||
|
||||
void updateCoefficients() {
|
||||
_omega = _frequency / _sampleRate * TWO_PI;
|
||||
_epsilon = 2.0f * sinf(_omega / 2.0f);
|
||||
_yq1 = cosf(-1.0f * _omega);
|
||||
_y1 = sinf(+1.0f * _omega);
|
||||
}
|
||||
|
||||
public:
|
||||
AudioSourceTone() {
|
||||
|
@ -30,22 +40,22 @@ public:
|
|||
}
|
||||
|
||||
void initialize() {
|
||||
_frameOffset = 0;
|
||||
setParameters(SAMPLE_RATE, 220.0f, 0.9f);
|
||||
const float32_t FREQUENCY_220_HZ = 220.0f;
|
||||
const float32_t GAIN_MINUS_3DB = 0.708f;
|
||||
setParameters(SAMPLE_RATE, FREQUENCY_220_HZ, GAIN_MINUS_3DB);
|
||||
}
|
||||
|
||||
void finalize() {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_frameOffset = 0;
|
||||
}
|
||||
|
||||
void setParameters(const float32_t sampleRate, const float32_t frequency, const float32_t amplitude) {
|
||||
_sampleRate = std::max(sampleRate, 1.0f);
|
||||
_frequency = std::max(frequency, 1.0f);
|
||||
_amplitude = std::max(amplitude, 1.0f);
|
||||
_omega = _frequency / _sampleRate * TWO_PI;
|
||||
updateCoefficients();
|
||||
}
|
||||
|
||||
void getParameters(float32_t& sampleRate, float32_t& frequency, float32_t& amplitude) {
|
||||
|
@ -56,15 +66,22 @@ public:
|
|||
|
||||
void render(AudioBufferFloat32& frameBuffer) {
|
||||
|
||||
// note: this is a placeholder implementation. final version will not include any transcendental ops in our render loop
|
||||
|
||||
float32_t** samples = frameBuffer.getFrameData();
|
||||
float32_t yq;
|
||||
float32_t y;
|
||||
for (uint16_t i = 0; i < frameBuffer.getFrameCount(); ++i) {
|
||||
|
||||
yq = _yq1 - (_epsilon * _y1);
|
||||
y = _y1 + (_epsilon * yq);
|
||||
|
||||
// update delays
|
||||
_yq1 = yq;
|
||||
_y1 = y;
|
||||
|
||||
for (uint16_t j = 0; j < frameBuffer.getChannelCount(); ++j) {
|
||||
samples[j][i] = sinf((i + _frameOffset) * _omega);
|
||||
samples[j][i] = _amplitude * y;
|
||||
}
|
||||
}
|
||||
_frameOffset += frameBuffer.getFrameCount();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue