Skip to content

Commit

Permalink
Style code format clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Feb 9, 2023
1 parent cfb9c9f commit 0fcd961
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 44 deletions.
36 changes: 19 additions & 17 deletions src/spek-audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ class AudioFileImpl : public AudioFile
int audio_stream, const std::string& codec_name, int bit_rate, int sample_rate,
int bits_per_sample, int streams, int channels, double duration
);
~AudioFileImpl() override;
void start(int channel, int samples) override;
int read() override;

AudioError get_error() const override { return this->error; }
std::string get_codec_name() const override { return this->codec_name; }
int get_bit_rate() const override { return this->bit_rate; }
int get_sample_rate() const override { return this->sample_rate; }
int get_bits_per_sample() const override { return this->bits_per_sample; }
int get_streams() const override { return this->streams; }
int get_channels() const override { return this->channels; }
double get_duration() const override { return this->duration; }
const float *get_buffer() const override { return this->buffer; }
int64_t get_frames_per_interval() const override { return this->frames_per_interval; }
int64_t get_error_per_interval() const override { return this->error_per_interval; }
int64_t get_error_base() const override { return this->error_base; }
~AudioFileImpl();

virtual void start(int channel, int samples) override final;
virtual int read() override final;

virtual AudioError get_error() const override { return this->error; }
virtual std::string get_codec_name() const override { return this->codec_name; }
virtual int get_bit_rate() const override { return this->bit_rate; }
virtual int get_sample_rate() const override { return this->sample_rate; }
virtual int get_bits_per_sample() const override { return this->bits_per_sample; }
virtual int get_streams() const override { return this->streams; }
virtual int get_channels() const override { return this->channels; }
virtual double get_duration() const override { return this->duration; }
virtual const float *get_buffer() const override { return this->buffer; }
virtual int64_t get_frames_per_interval() const override { return this->frames_per_interval; }
virtual int64_t get_error_per_interval() const override { return this->error_per_interval; }
virtual int64_t get_error_base() const override { return this->error_base; }

private:
AudioError error;
Expand All @@ -63,6 +64,7 @@ class AudioFileImpl : public AudioFile
int64_t frames_per_interval;
int64_t error_per_interval;
int64_t error_base;

};


Expand Down Expand Up @@ -101,7 +103,7 @@ std::unique_ptr<AudioFile> Audio::open(const std::string& file_name, int stream)
int audio_stream = -1;
int streams = 0;
if (!error) {
for (unsigned int i = 0; i < format_context->nb_streams; i++) {
for (unsigned int i = 0; i < format_context->nb_streams; ++i) {
if (format_context->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
if (stream == streams) {
audio_stream = i;
Expand Down
1 change: 1 addition & 0 deletions src/spek-audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AudioFile
virtual int64_t get_frames_per_interval() const = 0;
virtual int64_t get_error_per_interval() const = 0;
virtual int64_t get_error_base() const = 0;

};

enum class AudioError
Expand Down
7 changes: 4 additions & 3 deletions src/spek-fft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class FFTPlanImpl : public FFTPlan
{
public:
FFTPlanImpl(int nbits);
~FFTPlanImpl() override;
~FFTPlanImpl();

void execute() override;
virtual void execute() override final;

private:
struct RDFTContext *cx;

};

std::unique_ptr<FFTPlan> FFT::create(int nbits)
Expand All @@ -42,7 +43,7 @@ void FFTPlanImpl::execute()
const float n2 = n * n;
this->set_output(0, 10.0f * log10f(this->get_input(0) * this->get_input(0) / n2));
this->set_output(n / 2, 10.0f * log10f(this->get_input(1) * this->get_input(1) / n2));
for (int i = 1; i < n / 2; i++) {
for (int i = 1; i < n / 2; ++i) {
const float re = this->get_input(i * 2);
const float im = this->get_input(i * 2 + 1);
this->set_output(i, 10.0f * log10f((re * re + im * im) / n2));
Expand Down
3 changes: 3 additions & 0 deletions src/spek-fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class FFT
{
public:
FFT() {}

std::unique_ptr<FFTPlan> create(int nbits);

};

class FFTPlan
Expand Down Expand Up @@ -51,6 +53,7 @@ class FFTPlan
int output_size;
float *input;
std::vector<float> output;

};

#endif
2 changes: 1 addition & 1 deletion src/spek-palette.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static QVector<QColor> globalGolors = { QColor(0, 0, 0),
void createGradientTable()
{
int numbers = 6;
for (int i = 0; i < GRADIENT_TABLE_SIZE; i++) {
for (int i = 0; i < GRADIENT_TABLE_SIZE; ++i) {
double position = (double)i/GRADIENT_TABLE_SIZE;
/* if position > 1 then we have repetition of colors it maybe useful */
if (position > 1.0) {
Expand Down
11 changes: 6 additions & 5 deletions src/spek-pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct spek_pipeline
bool has_worker_cond;
bool worker_done;
volatile bool quit;

};

// Forward declarations.
Expand Down Expand Up @@ -221,7 +222,7 @@ std::string spek_pipeline_desc(const struct spek_pipeline *pipeline)
default:
assert(false);
}
if (window_function_name.size()) {
if (window_function_name.length()) {
items.push_back("F:" + window_function_name);
}
}
Expand Down Expand Up @@ -371,7 +372,7 @@ static float get_window(enum window_function f, int i, float *coss, int n)
case WINDOW_HAMMING:
return 0.53836f - 0.46164f * coss[i];
case WINDOW_BLACKMAN_HARRIS:
return 0.35875f - 0.48829f * coss[i] + 0.14128f * coss[2*i % n] - 0.01168f * coss[3*i % n];
return 0.35875f - 0.48829f * coss[i] + 0.14128f * coss[2 * i % n] - 0.01168f * coss[3 * i % n];
default:
assert(false);
return 0.0f;
Expand Down Expand Up @@ -427,14 +428,14 @@ static void * worker_func(void *pp)

if (frames % p->nfft == 0 || ((int_full || int_over) && num_fft == 0)) {
prev_head = head;
for (int i = 0; i < p->nfft; i++) {
for (int i = 0; i < p->nfft; ++i) {
float val = p->input[(p->input_size + head - p->nfft + i) % p->input_size];
val *= get_window(p->window_function, i, p->coss, p->nfft);
p->fft->set_input(i, val);
}
p->fft->execute();
num_fft++;
for (int i = 0; i < p->fft->get_output_size(); i++) {
for (int i = 0; i < p->fft->get_output_size(); ++i) {
p->output[i] += p->fft->get_output(i);
}
}
Expand All @@ -447,7 +448,7 @@ static void * worker_func(void *pp)
acc_error += p->file->get_error_per_interval();
}

for (int i = 0; i < p->fft->get_output_size(); i++) {
for (int i = 0; i < p->fft->get_output_size(); ++i) {
p->output[i] /= num_fft;
}

Expand Down
3 changes: 2 additions & 1 deletion src/spek-pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class AudioFile;
class FFTPlan;
struct spek_pipeline;

enum window_function {
enum window_function
{
WINDOW_HANN,
WINDOW_HAMMING,
WINDOW_BLACKMAN_HARRIS,
Expand Down
13 changes: 6 additions & 7 deletions src/spek-ruler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <cmath>
#include <QFontMetrics>
#include <QApplication>

SpekRuler::SpekRuler(
int x, int y, Position pos, QString sample_label,
Expand All @@ -18,9 +17,9 @@ SpekRuler::SpekRuler(

void SpekRuler::draw(QPainter &dc)
{
const QFontMetrics ft(dc.font());
const int w = QtFontWidth(ft, sample_label);
const int h = ft.height();
const QFontMetrics ftm(dc.font());
const int w = QtFontWidth(ftm, sample_label);
const int h = ftm.height();
const int len = this->pos == TOP || this->pos == BOTTOM ? w : h;

// Select the factor to use, we want some space between the labels.
Expand Down Expand Up @@ -55,9 +54,9 @@ void SpekRuler::draw_tick(QPainter &dc, int tick)
const int value = this->pos == TOP || this->pos == BOTTOM ? tick : this->max_units + this->min_units - tick;
const double p = this->offset + this->scale * (value - min_units);

const QFontMetrics ft(dc.font());
const int w = QtFontWidth(ft, sample_label);
const int h = -ft.height() / 2;
const QFontMetrics ftm(dc.font());
const int w = QtFontWidth(ftm, sample_label);
const int h = -ftm.height() / 2;

if (this->pos == TOP) {
dc.drawText(this->x + p - w / 2, this->y - GAP - h, label);
Expand Down
1 change: 1 addition & 0 deletions src/spek-ruler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SpekRuler
double scale;
double offset;
formatter_cb formatter;

};

#endif
15 changes: 7 additions & 8 deletions src/spek-spectrogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <QPainter>
#include <QDateTime>
#include <QKeyEvent>
#include <QApplication>

enum
{
Expand Down Expand Up @@ -78,7 +77,7 @@ void SpekSpectrogram::save(const QString& path)

void SpekSpectrogram::keyPressEvent(QKeyEvent *event)
{
switch(event->key()) {
switch (event->key()) {
case Qt::Key_C:
if (this->channels) {
if (event->modifiers() == Qt::NoModifier) { // 'c'
Expand Down Expand Up @@ -310,7 +309,7 @@ static void pipeline_cb(int bands, int sample, float *values, void *cb_data)

// TODO: check image size, quit if wrong.
const double range = spek->getURange() - spek->getLRange();
for (int y = 0; y < bands; y++) {
for (int y = 0; y < bands; ++y) {
const double value = fmin(spek->getURange(), fmax(spek->getLRange(), values[y]));
const double level = (value - spek->getLRange()) / range;
const uint32_t color = spek_palette(spek->getPalette(), level);
Expand Down Expand Up @@ -363,7 +362,7 @@ void SpekSpectrogram::stop()
void SpekSpectrogram::create_palette()
{
this->palette_image = QImage(RULER, bits_to_bands(this->fft_bits), QImage::Format_RGB32);
for (int y = 0; y < bits_to_bands(this->fft_bits); y++) {
for (int y = 0; y < bits_to_bands(this->fft_bits); ++y) {
uint32_t color = spek_palette(this->palette, y / (double)bits_to_bands(this->fft_bits));
for (int j =0; j < RULER; ++j) {
this->palette_image.setPixel(
Expand All @@ -382,8 +381,8 @@ static QString trim(QPainter *dc, const QString& s, int length, bool trim_end)
}

// Check if the entire string fits.
const QFontMetrics ft(dc->font());
int w = QtFontWidth(ft, s);
const QFontMetrics ftm(dc->font());
int w = QtFontWidth(ftm, s);
if (w <= length) {
return s;
}
Expand All @@ -393,8 +392,8 @@ static QString trim(QPainter *dc, const QString& s, int length, bool trim_end)
int i = 0;
int k = s.length();
while (k - i > 1) {
int j = (i + k) / 2;
w = QtFontWidth(ft, trim_end ? s.mid(0, j) + fix : fix + s.mid(j));
const int j = (i + k) / 2;
w = QtFontWidth(ftm, trim_end ? s.mid(0, j) + fix : fix + s.mid(j));
if (trim_end != (w > length)) {
i = j;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/spek-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int spek_vercmp(const char *a, const char *b)
char *i, *j;
while (true) {
i = j = NULL;
long x = strtol(a, &i, 10);
long y = strtol(b, &j, 10);
const long x = strtol(a, &i, 10);
const long y = strtol(b, &j, 10);

if (x < y) {
return -1;
Expand Down

0 comments on commit 0fcd961

Please sign in to comment.