void MonitorAudioLevel::refreshScope(const QSize& /*size*/, bool /*full*/) { SharedFrame sFrame; while (m_queue.count() > 0) { sFrame = m_queue.pop(); if (sFrame.is_valid() && sFrame.get_audio_samples() > 0) { mlt_audio_format format = mlt_audio_s16; int channels = sFrame.get_audio_channels(); int frequency = sFrame.get_audio_frequency(); int samples = sFrame.get_audio_samples(); Mlt::Frame mFrame = sFrame.clone(true, false, false); m_filter->process(mFrame); mFrame.get_audio( format, frequency, channels, samples ); if (samples == 0) { // There was an error processing audio from frame continue; } QVector<int> levels; for (int i = 0; i < audioChannels; i++) { QString s = QString("meta.media.audio_level.%1").arg(i); double audioLevel = mFrame.get_double(s.toLatin1().constData()); if (audioLevel == 0.0) { levels << -100; } else { levels << (int) levelToDB(audioLevel); } } QMetaObject::invokeMethod(this, "setAudioValues", Qt::QueuedConnection, Q_ARG(const QVector<int>&, levels)); } }
void AudioPeakMeterScopeWidget::refreshScope(const QSize& /*size*/, bool /*full*/) { SharedFrame sFrame; while (m_queue.count() > 0) { sFrame = m_queue.pop(); if (sFrame.is_valid() && sFrame.get_audio_samples() > 0) { mlt_audio_format format = mlt_audio_s16; int channels = sFrame.get_audio_channels(); int frequency = sFrame.get_audio_frequency(); int samples = sFrame.get_audio_samples(); Mlt::Frame mFrame = sFrame.clone(true, false, false); m_filter->process(mFrame); mFrame.get_audio( format, frequency, channels, samples ); QVector<double> levels; for (int i = 0; i < channels; i++) { QString s = QString("meta.media.audio_level.%1").arg(i); double audioLevel = mFrame.get_double(s.toLatin1().constData()); if (audioLevel == 0.0) { levels << -100.0; } else { levels << 20 * log10(audioLevel); } } QMetaObject::invokeMethod(m_audioMeter, "showAudio", Qt::QueuedConnection, Q_ARG(const QVector<double>&, levels)); } }
void AudioGraphSpectrum::processSpectrum(const SharedFrame&frame) { if (!isVisible()) return; mlt_audio_format format = mlt_audio_s16; int channels = frame.get_audio_channels(); int frequency = frame.get_audio_frequency(); int samples = frame.get_audio_samples(); Mlt::Frame mFrame = frame.clone(true, false, false); m_filter->process(mFrame); mFrame.get_audio( format, frequency, channels, samples ); QVector<double> bands(AUDIBLE_BAND_COUNT); float* bins = (float*)m_filter->get_data("bins"); int bin_count = m_filter->get_int("bin_count"); double bin_width = m_filter->get_double("bin_width"); int band = 0; bool firstBandFound = false; for (int bin = 0; bin < bin_count; bin++) { // Loop through all the FFT bins and align bin frequencies with // band frequencies. double F = bin_width * (double)bin; if (!firstBandFound) { // Skip bins that come before the first band. if (BAND_TAB[band + FIRST_AUDIBLE_BAND_INDEX].low > F) { continue; } else { firstBandFound = true; bands[band] = bins[bin]; } } else if (BAND_TAB[band + FIRST_AUDIBLE_BAND_INDEX].high < F) { // This bin is outside of this band - move to the next band. band++; if ((band + FIRST_AUDIBLE_BAND_INDEX) > LAST_AUDIBLE_BAND_INDEX) { // Skip bins that come after the last band. break; } bands[band] = bins[bin]; } else if (bands[band] < bins[bin] ) { // Pick the highest bin level within this band to represent the // whole band. bands[band] = bins[bin]; } } // At this point, bands contains the magnitude of the signal for each // band. Convert to dB. for (band = 0; band < bands.size(); band++) { double mag = bands[band]; double dB = mag > 0.0 ? 20 * log10( mag ) : -1000.0; bands[band] = dB; } // Update the audio signal widget QMetaObject::invokeMethod(m_graphWidget, "showAudio", Qt::QueuedConnection, Q_ARG(const QVector<double>&, bands)); }