diff --git a/src/engine/gstengine.cpp b/src/engine/gstengine.cpp index 738d941bf..81d187ada 100644 --- a/src/engine/gstengine.cpp +++ b/src/engine/gstengine.cpp @@ -822,9 +822,12 @@ void GstEngine::UpdateScope(const int chunk_length) { scope_chunk_++; - if (buffer_format_.startsWith("S16") || - buffer_format_.startsWith("U16") || - buffer_format_.startsWith("S32")) { + if (buffer_format_.startsWith("S16LE") || + buffer_format_.startsWith("U16LE") || + buffer_format_.startsWith("S24LE") || + buffer_format_.startsWith("S32LE") || + buffer_format_.startsWith("F32LE") + ) { memcpy(dest, source, bytes); } else { diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index b67e17d70..01e6927c0 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -110,7 +110,8 @@ GstEnginePipeline::GstEnginePipeline(GstEngine *engine) about_to_finish_cb_id_(-1), bus_cb_id_(-1), discovery_finished_cb_id_(-1), - discovery_discovered_cb_id_(-1) + discovery_discovered_cb_id_(-1), + unsupported_analyzer_(false) { if (!sElementDeleter) { @@ -427,6 +428,8 @@ bool GstEnginePipeline::InitAudioBin() { } } + unsupported_analyzer_ = false; + return true; } @@ -576,7 +579,10 @@ GstPadProbeReturn GstEnginePipeline::HandoffCallback(GstPad *pad, GstPadProbeInf GstBuffer *buf = gst_pad_probe_info_get_buffer(info); GstBuffer *buf16 = nullptr; - if (format.startsWith("S32")) { + if (format.startsWith("S16LE")) { + instance->unsupported_analyzer_ = false; + } + else if (format.startsWith("S32LE")) { GstMapInfo map_info; gst_buffer_map(buf, &map_info, GST_MAP_READ); @@ -593,6 +599,55 @@ GstPadProbeReturn GstEnginePipeline::HandoffCallback(GstPad *pad, GstPadProbeInf buf16 = gst_buffer_new_wrapped(d, buf16_size); GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) * channels, rate); buf = buf16; + + instance->unsupported_analyzer_ = false; + } + + else if (format.startsWith("F32LE")) { + + GstMapInfo map_info; + gst_buffer_map(buf, &map_info, GST_MAP_READ); + + float *s = reinterpret_cast(map_info.data); + int samples = (map_info.size / sizeof(float)) / channels; + int buf16_size = samples * sizeof(int16_t) * channels; + int16_t *d = static_cast(g_malloc(buf16_size)); + memset(d, 0, buf16_size); + for (int i = 0 ; i < (samples * channels) ; ++i) { + float sample_float = (s[i] * 32768.0); + d[i] = static_cast(sample_float); + } + gst_buffer_unmap(buf, &map_info); + buf16 = gst_buffer_new_wrapped(d, buf16_size); + GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) * channels, rate); + buf = buf16; + + instance->unsupported_analyzer_ = false; + } + else if (format.startsWith("S24LE")) { + + GstMapInfo map_info; + gst_buffer_map(buf, &map_info, GST_MAP_READ); + + char *s24 = reinterpret_cast(map_info.data); + int samples = (map_info.size / sizeof(char)) / channels; + int buf16_size = samples * sizeof(int16_t) * channels; + int16_t *s16 = static_cast(g_malloc(buf16_size)); + memset(s16, 0, buf16_size); + for (int i = 0 ; i < (samples * channels) ; ++i) { + s16[i] = *(reinterpret_cast(s24+1)); + s24 += 3; + } + gst_buffer_unmap(buf, &map_info); + buf16 = gst_buffer_new_wrapped(s16, buf16_size); + GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) * channels, rate); + buf = buf16; + + instance->unsupported_analyzer_ = false; + } + else if (!instance->unsupported_analyzer_) { + instance->unsupported_analyzer_ = true; + qLog(Debug) << "Unsupported audio format for the analyzer" << format; } QList consumers; diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index 903920a2a..05025ca74 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -285,6 +285,8 @@ class GstEnginePipeline : public QObject { GstSegment last_playbin_segment_; + bool unsupported_analyzer_; + }; #endif // GSTENGINEPIPELINE_H