- col << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green << Qt::green ;
- col << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow << Qt::yellow ;
- col << Qt::darkYellow << Qt::darkYellow << Qt::darkYellow;
- col << Qt::red << Qt::red;
+ setMinimumWidth(10);
+ dbscale << 0 << -1 << -2 << -3 << -4 << -5 << -6 << -8 << -10 << -20 << -40 ;
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+ m_aMonitoringEnabled = new QAction(i18n("Monitor audio signal"), this);
+ m_aMonitoringEnabled->setCheckable(true);
+ m_aMonitoringEnabled->setChecked(true);
+ connect(m_aMonitoringEnabled, SIGNAL(toggled(bool)), this, SLOT(slotSwitchAudioMonitoring(bool)));
+ connect(&m_timer,SIGNAL(timeout()),this,SLOT(slotNoAudioTimeout()));
+ addAction(m_aMonitoringEnabled);
+}
+
+AudioSignal::~AudioSignal()
+{
+ delete m_aMonitoringEnabled;
+}
+
+bool AudioSignal::monitoringEnabled() const
+{
+ return m_aMonitoringEnabled->isChecked();
+}
+
+void AudioSignal::slotReceiveAudio(const QVector<int16_t>& data, int, int num_channels, int samples){
+
+ int num_samples = samples > 200 ? 200 : samples;
+
+ QByteArray channels;
+ int num_oversample=0;
+ for (int i = 0; i < num_channels; i++) {
+ long val = 0;
+ double over1=0.0;
+ double over2=0.0;
+ for (int s = 0; s < num_samples; s ++) {
+ int sample=abs(data[i+s*num_channels] / 128);
+ val += sample;
+ if (sample==128){
+ num_oversample++;
+ }else{
+ num_oversample=0;
+ }
+ //if 3 samples over max => 1 peak over 0 db (0db=40.0)
+ if (num_oversample>3){
+ over1=41.0/42.0*127;
+ }
+ // 10 samples @max => show max signal
+ if (num_oversample>10){
+ over2=127;
+ }
+
+
+
+ }
+ //max amplitude = 40/42, 3to10 oversamples=41, more then 10 oversamples=42
+ if (over2>0.0){
+ channels.append(over2);
+ } else if (over1>0.0){
+ channels.append(over1);
+ }else
+ channels.append(val / num_samples*40.0/42.0);
+ }
+ showAudio(channels);
+ m_timer.start(1000);