I finally understood the mystery of why size_t is accidentally working in ConsumeBuffer: all my FLACs are S24LE, I just tested now one of my own songs which are S16LE and the correct int16 aapproach works for detecting and interacting audio with visuals! Therefore Im trying now to make a ConsumeBuffer with lasers to determine automatically the format and width: (but no luck making S24LE to work)
#include <QtCore/QtEndian> void VisualizationSDL2::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) { Q_UNUSED(pipeline_id); GstMapInfo map; gst_buffer_map(buffer, &map, GST_MAP_READ); if (projectm_instance_) { unsigned int sample_count = 0; const int16_t *int16_data = nullptr; const float *float_data = nullptr; if (format == QStringLiteral("S16LE") || format == QStringLiteral("S16BE")) { sample_count = map.size / sizeof(int16_t) / 2; int16_data = reinterpret_cast<const int16_t *>(map.data); if (format == QStringLiteral("S16BE")) { // Convert big-endian to little-endian if necessary std::vector<int16_t> temp_data(sample_count * 2); for (unsigned int i = 0; i < sample_count * 2; ++i) { temp_data[i] = qFromBigEndian(int16_data[i]); } int16_data = temp_data.data(); } projectm_pcm_add_int16(projectm_instance_, int16_data, sample_count, PROJECTM_STEREO); } else if (format == QStringLiteral("F32LE") || format == QStringLiteral("F32BE")) { sample_count = map.size / sizeof(float) / 2; float_data = reinterpret_cast<const float *>(map.data); if (format == QStringLiteral("F32BE")) { // Convert big-endian to little-endian if necessary std::vector<float> temp_data(sample_count * 2); for (unsigned int i = 0; i < sample_count * 2; ++i) { temp_data[i] = qFromBigEndian(float_data[i]); } float_data = temp_data.data(); } projectm_pcm_add_float(projectm_instance_, float_data, sample_count, PROJECTM_STEREO); } else if (format == QStringLiteral("S24LE")) { // Handle 24-bit audio (3 bytes per sample) sample_count = map.size / 3 / 2; std::vector<int16_t> int16_samples(sample_count * 2); for (unsigned int i = 0; i < sample_count * 2; ++i) { int16_samples[i] = static_cast<int16_t>((map.data[i * 3 + 2] << 8) | map.data[i * 3 + 1]); } projectm_pcm_add_int16(projectm_instance_, int16_samples.data(), sample_count, PROJECTM_STEREO); } gst_buffer_unmap(buffer, &map); } gst_buffer_unref(buffer); }