mirror of
https://github.com/alexkay/spek.git
synced 2025-06-06 18:33:14 +03:00
parent
0e76ccb55a
commit
3cc57547c7
@ -56,6 +56,9 @@ On OS X use the Command key instead of Ctrl.
|
|||||||
`s`, `S`
|
`s`, `S`
|
||||||
: Change the DFT window size.
|
: Change the DFT window size.
|
||||||
|
|
||||||
|
`p`, `P`
|
||||||
|
: Change the palette.
|
||||||
|
|
||||||
# FILES
|
# FILES
|
||||||
|
|
||||||
*~/.config/spek/preferences*
|
*~/.config/spek/preferences*
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "spek-palette.h"
|
#include "spek-palette.h"
|
||||||
|
|
||||||
// Modified version of Dan Bruton's algorithm:
|
// Modified version of Dan Bruton's algorithm:
|
||||||
// http://www.physics.sfasu.edu/astro/color/spectra.html
|
// http://www.physics.sfasu.edu/astro/color/spectra.html
|
||||||
uint32_t spek_palette_spectrum(double level)
|
static uint32_t spectrum(double level)
|
||||||
{
|
{
|
||||||
level *= 0.6625;
|
level *= 0.6625;
|
||||||
double r = 0.0, g = 0.0, b = 0.0;
|
double r = 0.0, g = 0.0, b = 0.0;
|
||||||
@ -41,3 +43,21 @@ uint32_t spek_palette_spectrum(double level)
|
|||||||
uint32_t bb = (uint32_t) (b * cf + 0.5);
|
uint32_t bb = (uint32_t) (b * cf + 0.5);
|
||||||
return (rr << 16) + (gg << 8) + bb;
|
return (rr << 16) + (gg << 8) + bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t mono(double level)
|
||||||
|
{
|
||||||
|
uint32_t v = (uint32_t) (level * 255.0 + 0.5);
|
||||||
|
return (v << 16) + (v << 8) + v;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t spek_palette(enum palette palette, double level) {
|
||||||
|
switch (palette) {
|
||||||
|
case PALETTE_SPECTRUM:
|
||||||
|
return spectrum(level);
|
||||||
|
case PALETTE_MONO:
|
||||||
|
return mono(level);
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,4 +2,11 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t spek_palette_spectrum(double level);
|
enum palette {
|
||||||
|
PALETTE_SPECTRUM,
|
||||||
|
PALETTE_MONO,
|
||||||
|
PALETTE_COUNT,
|
||||||
|
PALETTE_DEFAULT = PALETTE_SPECTRUM,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t spek_palette(enum palette palette, double level);
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "spek-audio.h"
|
#include "spek-audio.h"
|
||||||
#include "spek-events.h"
|
#include "spek-events.h"
|
||||||
#include "spek-fft.h"
|
#include "spek-fft.h"
|
||||||
#include "spek-palette.h"
|
|
||||||
#include "spek-pipeline.h"
|
#include "spek-pipeline.h"
|
||||||
#include "spek-platform.h"
|
#include "spek-platform.h"
|
||||||
#include "spek-ruler.h"
|
#include "spek-ruler.h"
|
||||||
@ -51,7 +50,8 @@ SpekSpectrogram::SpekSpectrogram(wxFrame *parent) :
|
|||||||
pipeline(NULL),
|
pipeline(NULL),
|
||||||
duration(0.0),
|
duration(0.0),
|
||||||
sample_rate(0),
|
sample_rate(0),
|
||||||
palette(),
|
palette(PALETTE_DEFAULT),
|
||||||
|
palette_image(),
|
||||||
image(1, 1),
|
image(1, 1),
|
||||||
prev_width(-1),
|
prev_width(-1),
|
||||||
fft_bits(FFT_BITS),
|
fft_bits(FFT_BITS),
|
||||||
@ -108,6 +108,12 @@ void SpekSpectrogram::on_char(wxKeyEvent& evt)
|
|||||||
} else if (N && evt.GetKeyCode() == 's') {
|
} else if (N && evt.GetKeyCode() == 's') {
|
||||||
this->fft_bits = spek_max(this->fft_bits - 1, MIN_FFT_BITS);
|
this->fft_bits = spek_max(this->fft_bits - 1, MIN_FFT_BITS);
|
||||||
this->create_palette();
|
this->create_palette();
|
||||||
|
} else if (S && evt.GetKeyCode() == 'P') {
|
||||||
|
this->palette = (enum palette) ((this->palette + 1) % PALETTE_COUNT);
|
||||||
|
this->create_palette();
|
||||||
|
} else if (N && evt.GetKeyCode() == 'p') {
|
||||||
|
this->palette = (enum palette) ((this->palette - 1 + PALETTE_COUNT) % PALETTE_COUNT);
|
||||||
|
this->create_palette();
|
||||||
} else {
|
} else {
|
||||||
evt.Skip();
|
evt.Skip();
|
||||||
return;
|
return;
|
||||||
@ -150,7 +156,7 @@ void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event)
|
|||||||
for (int y = 0; y < bands; y++) {
|
for (int y = 0; y < bands; y++) {
|
||||||
double value = fmin(this->urange, fmax(this->lrange, values[y]));
|
double value = fmin(this->urange, fmax(this->lrange, values[y]));
|
||||||
double level = (value - this->lrange) / range;
|
double level = (value - this->lrange) / range;
|
||||||
uint32_t color = spek_palette_spectrum(level);
|
uint32_t color = spek_palette(this->palette, level);
|
||||||
this->image.SetRGB(
|
this->image.SetRGB(
|
||||||
sample,
|
sample,
|
||||||
bands - y - 1,
|
bands - y - 1,
|
||||||
@ -301,7 +307,7 @@ void SpekSpectrogram::render(wxDC& dc)
|
|||||||
|
|
||||||
// The palette.
|
// The palette.
|
||||||
if (h - TPAD - BPAD > 0) {
|
if (h - TPAD - BPAD > 0) {
|
||||||
wxBitmap bmp(this->palette.Scale(RULER, h - TPAD - BPAD + 1));
|
wxBitmap bmp(this->palette_image.Scale(RULER, h - TPAD - BPAD + 1));
|
||||||
dc.DrawBitmap(bmp, w - RPAD + GAP, TPAD);
|
dc.DrawBitmap(bmp, w - RPAD + GAP, TPAD);
|
||||||
|
|
||||||
// Prepare to draw the ruler.
|
// Prepare to draw the ruler.
|
||||||
@ -379,10 +385,10 @@ void SpekSpectrogram::stop()
|
|||||||
|
|
||||||
void SpekSpectrogram::create_palette()
|
void SpekSpectrogram::create_palette()
|
||||||
{
|
{
|
||||||
this->palette.Create(RULER, bits_to_bands(this->fft_bits));
|
this->palette_image.Create(RULER, bits_to_bands(this->fft_bits));
|
||||||
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_spectrum(y / (double)bits_to_bands(this->fft_bits));
|
uint32_t color = spek_palette(this->palette, y / (double)bits_to_bands(this->fft_bits));
|
||||||
this->palette.SetRGB(
|
this->palette_image.SetRGB(
|
||||||
wxRect(0, bits_to_bands(this->fft_bits) - y - 1, RULER, 1),
|
wxRect(0, bits_to_bands(this->fft_bits) - y - 1, RULER, 1),
|
||||||
color >> 16,
|
color >> 16,
|
||||||
(color >> 8) & 0xFF,
|
(color >> 8) & 0xFF,
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
|
|
||||||
|
#include "spek-palette.h"
|
||||||
|
|
||||||
class Audio;
|
class Audio;
|
||||||
class FFT;
|
class FFT;
|
||||||
class SpekHaveSampleEvent;
|
class SpekHaveSampleEvent;
|
||||||
@ -36,7 +38,8 @@ private:
|
|||||||
wxString desc;
|
wxString desc;
|
||||||
double duration;
|
double duration;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
wxImage palette;
|
enum palette palette;
|
||||||
|
wxImage palette_image;
|
||||||
wxImage image;
|
wxImage image;
|
||||||
int prev_width;
|
int prev_width;
|
||||||
int fft_bits;
|
int fft_bits;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user