Skip to content

Commit

Permalink
Merge pull request #13 from Rodmg/develop
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
Rodmg authored Dec 12, 2024
2 parents 21a6ec7 + 06d3571 commit aa1b1a8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> 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.
Expand Down
11 changes: 10 additions & 1 deletion python/linamp/cdplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
17 changes: 1 addition & 16 deletions src/audiosource-base/audiosourcewspectrumcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions src/view-player/spectrumwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<const qint16 *>(ptr);
// Scale down to range [-1.0, 1.0]
float floatSample = pcmToFloat(pcmSample);
m_data[i] = floatSample;
ptr += bytesPerFrame;
ptr += 2;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/view-player/spectrumwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit aa1b1a8

Please sign in to comment.