Skip to content

Commit

Permalink
Merge pull request #10 from LancerMar/haotian
Browse files Browse the repository at this point in the history
Haotian
  • Loading branch information
LancerMar authored Apr 8, 2022
2 parents 1d9aed5 + 3c46f43 commit e91dcfe
Show file tree
Hide file tree
Showing 33 changed files with 765 additions and 384 deletions.
39 changes: 28 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.7.0)

project(GuitarTuner VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

project(GuitarTuner VERSION 1.0.0 LANGUAGES CXX)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(FFTW3)
find_package(Threads)
find_package(iir)

set(SRC
src/i2s_printer.cpp
src/i2s_mems_mic.cpp)
add_subdirectory(src)
add_subdirectory(test)
enable_testing()
add_test(NAME GuitarTunerTest COMMAND Test)

set(SRC
src/FftClass.cpp
src/i2s_mems_mic.cpp
src/App.cpp
src/lp.cpp
src/main.cxx
src/window.cpp
src/MyThread.cpp
src/Global.cpp)

add_library(source_test src/lp.cpp src/i2s_mems_mic.cpp src/Global.cpp)
add_executable(guitartuner ${SRC})


if(FFTW3_FOUND)
include_directories(${FFTW3_INCLUDE_DIRS})
link_directories(${FFTW3_LIBRARY_DIRS})
Expand All @@ -27,5 +43,6 @@ else(FFTW3_FOUND)
message(FATAL_ERROR "FFTW3 not found")
endif(FFTW3_FOUND)


target_link_libraries(guitartuner asound ${CMAKE_THREAD_LIB_INIT})
target_link_libraries(guitartuner iir)
target_link_libraries(guitartuner Qt5::Widgets asound ${CMAKE_THREAD_LIB_INIT})
target_link_libraries(guitartuner qwt-qt5)
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get install libasound2-dev python3-pip libboost-test-dev libfftw3-dev
sudo apt-get install libasound2-dev python3-pip libboost-test-dev libfftw3-dev qtdeclarative5-dev-tools libqwt-qt5-dev qtmultimedia5-dev
```
Then get the driver

Expand All @@ -14,6 +15,9 @@ sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2smic.py
sudo python3 i2smic.py
```
```
sudo ldconfig
```
You can choose to auto-load module and then reboot machine now.

# compile
Expand Down
58 changes: 58 additions & 0 deletions src/App.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "App.h"
#include "window.h"
#include <array>

App::App() {
fft = new FftClass();
lp = new Lp(SAMPLE_RATE);
window = new Window(fft->array);
window->show();
}

/*
* lowpass process data
*/
int* App::lpData(int *buffer_tmp){
for(int i = 0; i < FFT_BUFFER_SIZE;i++){
data[i] = lp->filter((*buffer_tmp));
buffer_tmp++;
}
return data;
}

/*
* fft process data(why frame?)
*/
void App::fftData(int32_t* buffer, int frames) {
fft->fill_buffer(buffer);
fft->update();
}

/*
* plot frequency buffer data
*
void App::plotBuffer(double *arr) {
window->updateBuffer(arr);
}
*/
/*
* setup driver params
*/
void App::setup(){
mic.registercallback(this);
mic.open_pcm();
mic.set_params();
}

/*
* start data acquistion
*/
void App::run(){
mic.run();
}

App::~App(){
delete fft;
delete lp;
delete window;
}
43 changes: 43 additions & 0 deletions src/App.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef APP_H
#define APP_H

#include "DriverCallback.h"
#include "i2s_mems_mic.h"
#include "FftClass.h"
#include "lp.h"
#include "window.h"
#include <array>


class App : public DriverCallback{

public:
/* constructor */
App();

/* implement fft process function */
void fftData(int32_t*, int) override;

/* implement lowpass data function*/
int* lpData(int *) override;

/* setup application */
void setup();

/* start application */
void run();

/* destructor */
~App();

private:
FftClass *fft;
I2Smic mic; //default-initialise object
Lp *lp;
Window *window;

int data[FFT_BUFFER_SIZE];
};

#endif

1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

61 changes: 61 additions & 0 deletions src/CppThread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef __CPP_THREAD_H_
#define __CPP_THREAD_H_

/**
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* (C) 2020-2022, Bernd Porr <[email protected]>
**/

#include <thread>

/**
* A thin wrapper around the C++ thread model to avoid
* a static callback. Instead just inherit this class
* and overload run() which then runs in this thread.
* This is header-only so that it can be performed
* inline for max performance.
**/
class CppThread {

public:
/**
* Starts the thread.
**/
inline void start() {
if (nullptr == uthread) {
uthread = new std::thread(CppThread::exec, this);
}
}

/**
* Waits for the thread to terminate.
**/
inline void join() {
if (nullptr != uthread) {
uthread->join();
delete uthread;
uthread = nullptr;
}
}

protected:
/**
* This method does all the work of this thread.
* Overload this abstract function with
* a real one doing the actual work of this thread.
**/
virtual void run() = 0;

private:
// pointer to the thread
std::thread* uthread = nullptr;
// static function which points back to the instance
static void exec(CppThread* cppThread) {
cppThread->run();
}
};


#endif
54 changes: 0 additions & 54 deletions src/DataProcess.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions src/DataProcess.h

This file was deleted.

13 changes: 13 additions & 0 deletions src/DriverCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DRIVERCALLBACK_H
#define DRIVERCALLBACK_H


class DriverCallback {
public:
//virtual functions to be overriden
virtual void fftData(int *, int) = 0;//fft process
virtual int* lpData(int *) = 0;// low pass data

};

#endif
Loading

0 comments on commit e91dcfe

Please sign in to comment.