mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-06 08:24:29 +01:00
Add method for getting raw samples from InputSource
This commit is contained in:
@@ -17,6 +17,7 @@ InputSource::InputSource(const char *filename, int fft_size) {
|
||||
if (fstat(fileno(m_file), &sb) != 0)
|
||||
throw std::runtime_error("Error fstating file");
|
||||
m_file_size = sb.st_size;
|
||||
sampleCount = m_file_size / sizeof(fftwf_complex);
|
||||
|
||||
m_data = (fftwf_complex*)mmap(NULL, m_file_size, PROT_READ, MAP_SHARED, fileno(m_file), 0);
|
||||
if (m_data == 0)
|
||||
@@ -37,6 +38,15 @@ void InputSource::cleanupFFTW() {
|
||||
if (m_fftw_out != nullptr) fftwf_free(m_fftw_out);
|
||||
}
|
||||
|
||||
bool InputSource::getSamples(fftwf_complex *dest, int start, int length)
|
||||
{
|
||||
if (start + length >= sampleCount)
|
||||
return false;
|
||||
|
||||
memcpy(dest, &m_data[start], length * sizeof(fftwf_complex));
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputSource::getViewport(float *dest, int x, int y, int width, int height, int zoom) {
|
||||
|
||||
fftwf_complex *sample_ptr = &m_data[y * getFFTStride()];
|
||||
|
||||
Reference in New Issue
Block a user