// // AudioScope.h // interace/src/audio // // Created by Stephen Birarda on 2014-12-16. // 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 // #ifndef hifi_AudioScope_h #define hifi_AudioScope_h #include #include #include #include #include class AudioScope : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY Q_PROPERTY(QVector scopeInput READ getScopeInput) Q_PROPERTY(QVector scopeOutputLeft READ getScopeOutputLeft) Q_PROPERTY(QVector scopeOutputRight READ getScopeOutputRight) Q_PROPERTY(QVector triggerInput READ getTriggerInput) Q_PROPERTY(QVector triggerOutputLeft READ getTriggerOutputLeft) Q_PROPERTY(QVector triggerOutputRight READ getTriggerOutputRight) public: // Audio scope methods for allocation/deallocation void allocateScope(); void freeScope(); void reallocateScope(int frames); public slots: void toggle() { setVisible(!_isEnabled); } void setVisible(bool visible); bool getVisible() const { return _isEnabled; } void togglePause() { setPause(!_isPaused); } void setPause(bool paused) { _isPaused = paused; emit pauseChanged(); } bool getPause() { return _isPaused; } void toggleTrigger() { _autoTrigger = !_autoTrigger; } bool getAutoTrigger() { return _autoTrigger; } void setAutoTrigger(bool autoTrigger) { _isTriggered = false; _autoTrigger = autoTrigger; } void setTriggerValues(int x, int y) { _triggerValues.x = x; _triggerValues.y = y; } void setTriggered(bool triggered) { _isTriggered = triggered; } bool getTriggered() { return _isTriggered; } float getFramesPerSecond(); int getFramesPerScope() { return _framesPerScope; } void selectAudioScopeFiveFrames(); void selectAudioScopeTwentyFrames(); void selectAudioScopeFiftyFrames(); QVector getScopeInput() { return _scopeInputData; }; QVector getScopeOutputLeft() { return _scopeOutputLeftData; }; QVector getScopeOutputRight() { return _scopeOutputRightData; }; QVector getTriggerInput() { return _triggerInputData; }; QVector getTriggerOutputLeft() { return _triggerOutputLeftData; }; QVector getTriggerOutputRight() { return _triggerOutputRightData; }; void setLocalEcho(bool serverEcho); void setServerEcho(bool serverEcho); signals: void pauseChanged(); void triggered(); protected: AudioScope(); private slots: void addStereoSilenceToScope(int silentSamplesPerChannel); void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel); void addStereoSamplesToScope(const QByteArray& samples); void addInputToScope(const QByteArray& inputSamples); private: // Audio scope methods for data acquisition int addBufferToScope(QByteArray* byteArray, int frameOffset, const int16_t* source, int sourceSamples, unsigned int sourceChannel, unsigned int sourceNumberOfChannels, float fade = 1.0f); int addSilenceToScope(QByteArray* byteArray, int frameOffset, int silentSamples); QVector getScopeVector(const QByteArray* scope, int offset); bool shouldTrigger(const QVector& scope); void computeInputData(); void computeOutputData(); void storeTriggerValues(); bool _isEnabled; bool _isPaused; bool _isTriggered; bool _autoTrigger; int _scopeInputOffset; int _scopeOutputOffset; int _framesPerScope; int _samplesPerScope; QByteArray* _scopeInput; QByteArray* _scopeOutputLeft; QByteArray* _scopeOutputRight; QByteArray _scopeLastFrame; QVector _scopeInputData; QVector _scopeOutputLeftData; QVector _scopeOutputRightData; QVector _triggerInputData; QVector _triggerOutputLeftData; QVector _triggerOutputRightData; glm::ivec2 _triggerValues; int _audioScopeBackground; int _audioScopeGrid; int _inputID; int _outputLeftID; int _outputRightD; }; #endif // hifi_AudioScope_h