Skip to content

Commit

Permalink
more comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sellicott committed Dec 7, 2018
1 parent 8f7dd56 commit f079c3d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
22 changes: 11 additions & 11 deletions FilterProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ using std::array;
using std::uint8_t;
using std::int16_t;


ReverbUnit::ReverbUnit(float feedbackGain_) :
reverb_gain(0.6),
// Constructor implementation
FilterProject::FilterProject(float feedbackGain_) :
//initilize filters
allpass1(4410, 0.6),
allpass2(1470, -0.6),
Expand Down Expand Up @@ -72,25 +71,26 @@ uint8_t* ReverbUnit::get_samples(uint8_t* samples, size_t num_samples) {
return reinterpret_cast<uint8_t*>(samples);
}

ReverbUnit::outType ReverbUnit::do_filtering(outType new_x) {
FilterProject::outType FilterProject::do_filtering(outType new_x) {
auto &d = *delay.get();

// the coefficient on the d.back() sets how long the reverb
// will sustain: larger = longer
auto x = 0.7*new_x + feedbackGain*d.back();

//run through the all pass filters
auto temp = allpass1.do_filtering(x);
temp = allpass2.do_filtering(temp);
temp = allpass3.do_filtering(temp);
temp = allpass4.do_filtering(temp);
temp = firFilter.do_filtering(temp);
// run through the all pass filters
// chain the outputs end to end
auto y1 = allpass1.do_filtering(x);
auto y2 = allpass2.do_filtering(y1);
auto y3 = allpass3.do_filtering(y2);
auto y4 = allpass4.do_filtering(y3);
auto y5 = firFilter.do_filtering(y4);

d.pop_back();
d.push_front(temp);

//add a bit of an FIR filter here, smooth the output
auto y = temp + 0.5*d[2*2940] + 0.25*d[2*2*2940] + 0.125*d.back();
auto y = temp + 0.5*d[2*2940] + 0.25*d[2*2*2940] + 0.125*[3*2*2940];
return y;
}

Expand Down
14 changes: 7 additions & 7 deletions FilterProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ using std::array;


class ReverbUnit {
using outType = int32_t;
using deque = std::deque<outType>;
using buffPtr = std::unique_ptr<deque>;
private:
using outType = int16_t;
using deque = std::deque<outType>;
using buffPtr = std::unique_ptr<deque>;

public:
ReverbUnit(float feedbackGain_ = 0.25);
~ReverbUnit() = default;
//constructor
FilterProject(float feedbackGain_ = 0.25);

// the decoder and playback programs need the take the samples in the form of 8-bit integers
uint8_t* get_samples(uint8_t* samples, size_t num_samples);

private:

float reverb_gain;
//define the names of the filters I will be using
AllpassFilter allpass1;
AllpassFilter allpass2;
AllpassFilter allpass3;
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ is meant to be typed into a terminal (command line) on the pi. Remember that pre

To get the project working start with a raspberry pi with a bootable sd card.
The pi should be running, logged in, with a keyboard and screen plugged connected, **and connected to the internet**.
You probably should also disable the pi's GUI, as it isn't necessary, and will just bog down the pi.

Steps to filtering goodness
1. Change the keyboard layout (it defaults to a UK layout)
Expand Down Expand Up @@ -76,9 +77,12 @@ Steps to filtering goodness
```
This will (hopefully) build all of the code needed to run your project.

6. Now you need some great music
Put your files on a flash drive, the connect the drive to the pi. Next copy the files
into the directory with the code. Your flash drive will be in the /media/pi/name_of_your_drive.
6. Now you need some great music:

Put your files on a flash drive and connect the drive to the pi. Next, copy the files
into the project directory.

Your flash drive will be in the /media/pi/name_of_your_drive folder on the pi.
Assuming that your file is on the root directory of your flash drive:
```
cp /media/pi/name_of_drive your_snazzy_audio_file.mp3 ./
Expand All @@ -93,6 +97,19 @@ Steps to filtering goodness
```
Note that the input audio file can be in almost any format.

# Implementing Filters
# The Code
In the FilterProject.cpp file the function do_filtering implements the filters for the project.
(The main file calls another function get_samples() which calls )
(The main file calls another function get_samples() which calls do_filtering() in order to apply the filter to the buffer
provided by the audio decoder program.)

In my project I used this function to chain togeter all of the other filters I used
(four allpass filters and a few FIR filters). These filters are implemented as c++ objects, meaining they need to be instantiated
(they are defined near the end of FilterProject.h). I do this in the *base initilization section*
(right after the beginning of the constructor, you remember CS1220 don't you?) of the FilterProject class.

The actual filters for the project are implemented in the files
(AllpassFilter.cpp)[./AllpassFilter.cpp], (FIRFilter.cpp)[./FIRFilter.cpp] and their corresponding .h files (AllpassFilter.h)[./AllpassFilter.h]
(FIRFilter.h)[./FIRFilter.h]. You can probably copy these files when implementing your own filters (or just use my FIR filter code as-is).

## Implementing Filters

0 comments on commit f079c3d

Please sign in to comment.