Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 from nyanpasu64/hires-fft-v2
Browse files Browse the repository at this point in the history
Hi-res FFT v2
  • Loading branch information
nyanpasu64 authored Mar 22, 2018
2 parents 16a3f58 + 2f176ba commit 9e37598
Show file tree
Hide file tree
Showing 14 changed files with 1,778 additions and 1,815 deletions.
3 changes: 2 additions & 1 deletion 0CC-FamiTracker.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
<ClCompile Include="Source\StretchDlg.cpp" />
<ClCompile Include="Source\SwapDlg.cpp" />
<ClCompile Include="Source\TransposeDlg.cpp" />
<ClCompile Include="Source\VisualizerBase.cpp" />
<ClCompile Include="Source\WaveEditor.cpp" />
<ClCompile Include="Source\GraphEditor.cpp" />
<ClCompile Include="Source\SequenceEditor.cpp" />
Expand Down Expand Up @@ -504,6 +505,7 @@
<ClInclude Include="Source\StretchDlg.h" />
<ClInclude Include="Source\SwapDlg.h" />
<ClInclude Include="Source\TransposeDlg.h" />
<ClInclude Include="Source\VisualizerBase.h" />
<ClInclude Include="Source\WaveformGenerator.h" />
<ClInclude Include="Source\WavegenBuiltin.h" />
<ClInclude Include="Source\WinSDK\VersionHelpers.h" />
Expand Down Expand Up @@ -593,7 +595,6 @@
<ClInclude Include="Source\ChunkRenderBinary.h" />
<ClInclude Include="Source\ChunkRenderText.h" />
<ClInclude Include="Source\TextExporter.h" />
<ClInclude Include="Source\FFT\Complex.h" />
<ClInclude Include="Source\FFT\FftBuffer.h" />
<ClInclude Include="Source\MIDI.h" />
<ClInclude Include="Source\DSample.h" />
Expand Down
2,846 changes: 1,423 additions & 1,423 deletions 0CC-FamiTracker.vcxproj.filters

Large diffs are not rendered by default.

45 changes: 0 additions & 45 deletions Source/FFT/Complex.h

This file was deleted.

12 changes: 9 additions & 3 deletions Source/FFT/FftBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ constexpr std::array<T, N> make_hann_window() {
template <std::size_t N>
class FftBuffer {
public:
static constexpr std::size_t GetPoints() noexcept {
return N;
}

void Reset() {
samples_.fill({ });
buffer_.fill({ });
Expand All @@ -53,16 +57,18 @@ class FftBuffer {

template <typename InputIt>
void CopyIn(InputIt Samples, std::size_t SampleCount) {
if (SampleCount > std::size(samples_))
return;
if (SampleCount > GetPoints()) {
SampleCount = GetPoints();
std::advance(Samples, SampleCount - GetPoints());
}
std::copy(samples_.cbegin() + SampleCount, samples_.cend(), samples_.begin());
std::transform(Samples, Samples + SampleCount, samples_.begin(), [] (auto x) {
return std::complex<double>(x, 0);
});
}

double GetIntensity(int i) const {
const double sqrtpoints = 1 << (FFT::details::floor_log2(N) / 2);
const double sqrtpoints = 1 << (FFT::details::floor_log2(GetPoints()) / 2);
return std::abs(buffer_[i]) / sqrtpoints;
}

Expand Down
50 changes: 50 additions & 0 deletions Source/VisualizerBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
** FamiTracker - NES/Famicom sound tracker
** Copyright (C) 2005-2014 Jonathan Liss
**
** 0CC-FamiTracker is (C) 2014-2017 HertzDevil
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Library General Public License for more details. To obtain a
** copy of the GNU Library General Public License, write to the Free
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** Any permitted reproduction of these routines, in whole or in part,
** must bear this legend.
*/

#include "VisualizerBase.h"

void CVisualizerBase::Create(int Width, int Height)
{
memset(&m_bmi, 0, sizeof(BITMAPINFO));
m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biBitCount = 32;
m_bmi.bmiHeader.biHeight = -Height;
m_bmi.bmiHeader.biWidth = Width;
m_bmi.bmiHeader.biPlanes = 1;

m_iWidth = Width;
m_iHeight = Height;
m_pBlitBuffer = std::make_unique<COLORREF[]>(Width * Height); // // //
}

void CVisualizerBase::SetSampleData(short *pSamples, unsigned int iCount)
{
m_pSamples = pSamples;
m_iSampleCount = iCount;
}

void CVisualizerBase::Display(CDC *pDC, bool bPaintMsg) { // // //
StretchDIBits(pDC->m_hDC,
0, 0, m_iWidth, m_iHeight,
0, 0, m_iWidth, m_iHeight,
m_pBlitBuffer.get(), &m_bmi, DIB_RGB_COLORS, SRCCOPY);
}
53 changes: 53 additions & 0 deletions Source/VisualizerBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
** FamiTracker - NES/Famicom sound tracker
** Copyright (C) 2005-2014 Jonathan Liss
**
** 0CC-FamiTracker is (C) 2014-2017 HertzDevil
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Library General Public License for more details. To obtain a
** copy of the GNU Library General Public License, write to the Free
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** Any permitted reproduction of these routines, in whole or in part,
** must bear this legend.
*/


#pragma once

#include "stdafx.h"
#include <memory> // // //

class CVisualizerBase { // // //
public:
virtual ~CVisualizerBase() = default;

// Create the visualizer
virtual void Create(int Width, int Height);
// Set rate of samples
virtual void SetSampleRate(int SampleRate) = 0;
// Set new sample data
virtual void SetSampleData(short *iSamples, unsigned int iCount);
// Render an image from the sample data
virtual void Draw() = 0;
// Display the image
virtual void Display(CDC *pDC, bool bPaintMsg); // // //

protected:
BITMAPINFO m_bmi;
std::unique_ptr<COLORREF[]> m_pBlitBuffer; // // //

int m_iWidth = 0;
int m_iHeight = 0;

unsigned int m_iSampleCount = 0;
short *m_pSamples = nullptr;
};
Loading

0 comments on commit 9e37598

Please sign in to comment.