Skip to content

Commit

Permalink
Add zoom functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
miek committed Jun 21, 2015
1 parent 8b64973 commit d740c0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 25 additions & 3 deletions inputsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ InputSource::InputSource(const char *filename, int fft_size) {
for (int i = 0; i < m_fft_size; i++) {
m_window[i] = 0.5f * (1.0f - cos(M_TAU * i / (m_fft_size - 1)));
}

m_zoom = 0;
m_max_zoom = floor(log2(m_fft_size));
}

InputSource::~InputSource() {
Expand All @@ -44,7 +47,7 @@ InputSource::~InputSource() {
}

void InputSource::GetViewport(float *dest, int x, int y, int width, int height, int zoom) {
fftwf_complex *sample_ptr = &m_data[y * m_fft_size];
fftwf_complex *sample_ptr = &m_data[y * GetOverlap()];

for (int i = 0; i < height; i++) {
memcpy(m_fftw_in, sample_ptr, m_fft_size * sizeof(fftw_complex));
Expand All @@ -66,14 +69,33 @@ void InputSource::GetViewport(float *dest, int x, int y, int width, int height,
*dest = magdb;
dest++;
}
sample_ptr += m_fft_size;
sample_ptr += GetOverlap();
}
}

int InputSource::GetHeight() {
return m_file_size / sizeof(fftwf_complex) / m_fft_size;
int lines = m_file_size / sizeof(fftwf_complex) / GetOverlap();
// Force height to be a multiple of overlap size
return (lines / GetOverlap()) * GetOverlap();
}

int InputSource::GetWidth() {
return m_fft_size;
}

void InputSource::ZoomIn() {
m_zoom++;
if (m_max_zoom > m_max_zoom)
m_zoom = m_max_zoom;

}

void InputSource::ZoomOut() {
m_zoom--;
if (m_zoom < 0)
m_zoom = 0;
}

int InputSource::GetOverlap() {
int increment = m_fft_size / pow(2, m_zoom);
}
8 changes: 8 additions & 0 deletions inputsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class InputSource
fftwf_plan m_fftw_plan;

float *m_window;

int m_zoom;
int m_max_zoom;

int GetOverlap();


public:
Expand All @@ -25,6 +30,9 @@ class InputSource
void GetViewport(float *dest, int x, int y, int width, int height, int zoom);
int GetHeight();
int GetWidth();

void ZoomIn();
void ZoomOut();
};

#endif

0 comments on commit d740c0d

Please sign in to comment.