diff --git a/debian/changelog b/debian/changelog index 985221c..cbda2f9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +linamp (1.2.1) bookworm; urgency=medium + + * Bugfix: Fixed glitches on spectrum analyzer for views that use audiospectrumcatpure class (CD player, Bluetooth player) + * Bugfix: Fixed spectrum analyzer not showing spectrum of right channel on file player + * Bugfix: Fix crashes on CD player when a request to musicbrainz fails + + -- Rodrigo Méndez Tue, 10 Dec 2024 23:22:00 -0600 + linamp (1.2.0) bookworm; urgency=medium * Bugfix: After boot and loading the first file into the playlist, playback fails. diff --git a/python/linamp/cdplayer.py b/python/linamp/cdplayer.py index 969563a..4c25797 100644 --- a/python/linamp/cdplayer.py +++ b/python/linamp/cdplayer.py @@ -75,7 +75,7 @@ def fetchdata(): result = musicbrainzngs.get_releases_by_discid( disc.id, includes=["artists", "recordings"] ) # get data from Musicbrainz - except musicbrainzngs.ResponseError: + except Exception: print( "disc not found or bad response, using cdtxt instead" ) # if not available search for cdtext @@ -148,6 +148,15 @@ def fetchdata(): artists[t - i_first_track] = value pass d.close() + + # artists and track_list should be arrays of strings, make sure they are: + for i, artist in enumerate(artists): + if type(artist) is not str: + artists[i] = "Unknown" + for i, track in enumerate(track_list): + if type(track) is not str: + track_list[i] = f"Track {i + 1}" + return artists, track_list, album, i_tracks, durations, is_data_tracks diff --git a/src/audiosource-base/audiosourcewspectrumcapture.cpp b/src/audiosource-base/audiosourcewspectrumcapture.cpp index b689f99..08257ba 100644 --- a/src/audiosource-base/audiosourcewspectrumcapture.cpp +++ b/src/audiosource-base/audiosourcewspectrumcapture.cpp @@ -8,17 +8,6 @@ bool globalAudioSourceWSpectrumCaptureInstanceIsRunning = false; -bool is_valid_sample(QByteArray *sample) -{ - // Greedy: suposing that 100 is enough - for(int i = 0; i < 100; i++) { - if(sample->at(i) != 0) { - return true; - } - } - return false; -} - /* our data processing function is in general: * * struct pw_buffer *b; @@ -204,7 +193,7 @@ void AudioSourceWSpectrumCapture::pwLoop() &pwData); struct spa_audio_info_raw audio_info; - audio_info.format = SPA_AUDIO_FORMAT_S16_LE; + audio_info.format = SPA_AUDIO_FORMAT_S16P; audio_info.channels = SPECTRUM_DATA_CHANNELS; audio_info.rate = SPECTRUM_DATA_SAMPLE_RATE; params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, @@ -238,10 +227,6 @@ void AudioSourceWSpectrumCapture::emitData() return; } - if(!is_valid_sample(pwData.sample)) { - return; - } - emit dataEmitted(*pwData.sample, spectrumDataFormat); pwData.sample->clear(); delete pwData.sampleStream; diff --git a/src/view-player/spectrumwidget.cpp b/src/view-player/spectrumwidget.cpp index 11c90ff..8a5029d 100644 --- a/src/view-player/spectrumwidget.cpp +++ b/src/view-player/spectrumwidget.cpp @@ -19,11 +19,11 @@ float pcmToFloat(qint16 pcm) static void floatPcmToMono(const float *data, float *mono, int channels) { if (channels == 1) { - memcpy(mono, data, sizeof(float) * 512); + memcpy(mono, data, sizeof(float) * N); } else { float *set = mono; - while (set < &mono[512]) { + while (set < &mono[N]) { *set++ = (data[0] + data[1]) / 2; data += channels; } @@ -185,7 +185,7 @@ void SpectrumWidget::paintEvent (QPaintEvent *) if(m_playing) { float mono[N]; float freq[N / 2]; - int channels = 2; // TODO get from format + int channels = m_format.channelCount(); floatPcmToMono(m_data, mono, channels); calc_freq(mono, freq); @@ -225,20 +225,31 @@ void SpectrumWidget::setData(const QByteArray &data, QAudioFormat format) m_format = format; Q_ASSERT(m_format.sampleFormat() == QAudioFormat::Int16); + if(m_format.sampleFormat() != QAudioFormat::Int16) { + // Bad sample format, only Int16 is currently supported + return; + } + const int bytesPerFrame = format.bytesPerFrame(); + Q_ASSERT(bytesPerFrame == 4); // Expecting Stereo Int16 + + if(bytesPerFrame != 4) { + // Bad bytes per frame, expecting 4 (Int16 Stereo) + return; + } - if(data.length() < DFT_SIZE * 4) { + if(data.length() < DFT_SIZE * bytesPerFrame) { // Not enough data for processing, ignore return; } const char *ptr = data.constData(); - for (int i = 0; i < DFT_SIZE * 2; ++i) { + for (int i = 0; i < DFT_SIZE * bytesPerFrame; ++i) { const qint16 pcmSample = *reinterpret_cast(ptr); // Scale down to range [-1.0, 1.0] float floatSample = pcmToFloat(pcmSample); m_data[i] = floatSample; - ptr += bytesPerFrame; + ptr += 2; } } diff --git a/src/view-player/spectrumwidget.h b/src/view-player/spectrumwidget.h index f8d2062..41d234a 100644 --- a/src/view-player/spectrumwidget.h +++ b/src/view-player/spectrumwidget.h @@ -21,7 +21,7 @@ class SpectrumWidget : public QWidget void paintEvent (QPaintEvent *); private: - float m_data[DFT_SIZE * 2]; + float m_data[DFT_SIZE * 4]; float m_xscale[N_BANDS + 1]; int m_bandValues[N_BANDS + 1]; int m_bandDelays[N_BANDS + 1];