Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support to initialize ofxFft processors with ofSoundStreamSettings #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions example-basic/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ void ofApp::setup() {
drawBins.resize(fft->getBinSize());
middleBins.resize(fft->getBinSize());
audioBins.resize(fft->getBinSize());

ofSoundStreamSettings settings;
soundStream.printDeviceList();
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.bufferSize = bufferSize;
settings.numInputChannels = 1;
// the rest of ofSoundStreamSetting defaults are good to go
soundStream.setup(settings);
soundStream.setInput(this);

// 0 output channels,
// 1 input channel
// 44100 samples per second
// [bins] samples per buffer
// 4 num buffers (latency)

ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);
//ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);

ofBackground(0, 0, 0);
}
Expand Down
1 change: 1 addition & 0 deletions example-basic/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ofApp : public ofBaseApp {

int plotHeight, bufferSize;

ofSoundStream soundStream;
ofxFft* fft;

ofMutex soundMutex;
Expand Down
12 changes: 11 additions & 1 deletion example-easy/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
void ofApp::setup() {
ofSetVerticalSync(true);
ofSetFrameRate(60);
fft.setup(16384);

ofSoundStreamSettings settings;
ofSoundStream soundStream;
soundStream.printDeviceList();
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.numInputChannels = 1;
fft.setup(settings, 16384);
//fft.setup(16384);
}

void ofApp::update() {
Expand Down
14 changes: 13 additions & 1 deletion example-eq/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ void ofApp::setup() {
appWidth = ofGetWidth();
appHeight = ofGetHeight();

ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);
ofSoundStreamSettings settings;
soundStream.printDeviceList();
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.bufferSize = bufferSize;
settings.numInputChannels = 1;
// the rest of ofSoundStreamSetting defaults are good to go
soundStream.setup(settings);
soundStream.setInput(this);

//ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);

ofBackground(0, 0, 0);
}
Expand Down
1 change: 1 addition & 0 deletions example-eq/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ofApp : public ofBaseApp {

int plotHeight, bufferSize;

ofSoundStream soundStream;
ofxFft* fft;

float* audioInput;
Expand Down
13 changes: 11 additions & 2 deletions example-process-input/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
void ofApp::setup() {
ofSetVerticalSync(true);
ofSetFrameRate(60);
fft.setup();


ofSoundStreamSettings settings;
ofSoundStream soundStream;
soundStream.printDeviceList();
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.numInputChannels = 1;

fft.setup(settings);
}

void ofApp::update() {
Expand Down
16 changes: 14 additions & 2 deletions example-visualize/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ void ofApp::setup() {
middleBins.resize(fft->getBinSize());
audioBins.resize(fft->getBinSize());

ofSoundStreamSettings settings;
soundStream.printDeviceList();
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
//settings.setInListener(this);
settings.bufferSize = bufferSize;
settings.numInputChannels = 1;
// the rest of ofSoundStreamSetting defaults are good to go
soundStream.setup(settings);
soundStream.setInput(this);

// 0 output channels,
// 1 input channel
// 44100 samples per second
// [bins] samples per buffer
// 4 num buffers (latency)

ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);
//ofSoundStreamSetup(0, 1, this, 44100, bufferSize, 4);

mode = SINE;
appWidth = ofGetWidth();
Expand Down
1 change: 1 addition & 0 deletions example-visualize/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ofApp : public ofBaseApp {

int plotHeight, bufferSize;

ofSoundStream soundStream;
ofxFft* fft;

int spectrogramOffset;
Expand Down
26 changes: 22 additions & 4 deletions src/ofxEasyFft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ofxEasyFft::~ofxEasyFft(){
stream.close();
}

void ofxEasyFft::setup(int bufferSize, fftWindowType windowType, fftImplementation implementation, int audioBufferSize, int audioSampleRate) {
void ofxEasyFft::setup(ofSoundStreamSettings settings, int bufferSize, fftWindowType windowType, fftImplementation implementation) {
int audioBufferSize = settings.bufferSize;
if(bufferSize < audioBufferSize) {
ofLogWarning("ofxEasyFft") << "bufferSize (" << bufferSize << ") less than audioBufferSize (" << audioBufferSize << "), using " << audioBufferSize;
bufferSize = audioBufferSize;
Expand All @@ -21,9 +22,26 @@ void ofxEasyFft::setup(int bufferSize, fftWindowType windowType, fftImplementati
audioBack.resize(bufferSize);
audioRaw.resize(bufferSize);

stream.getDeviceList();
stream.setup(0, 1, audioSampleRate, audioBufferSize, 2);
stream.setInput(this);
stream.setup(settings);
//stream.setup(0, 1, audioSampleRate, audioBufferSize, 2);
stream.setInput(this);

}

void ofxEasyFft::setup(int bufferSize, fftWindowType windowType, fftImplementation implementation, int audioBufferSize, int audioSampleRate) {
ofSoundStreamSettings settings;

stream.printDeviceList();

auto devices = stream.getMatchingDevices("default");
if(!devices.empty()){
settings.setInDevice(devices[0]);
}

settings.sampleRate = audioSampleRate;
settings.bufferSize = audioBufferSize;
settings.numInputChannels = 1;
setup(settings, bufferSize, windowType, implementation);
}

void ofxEasyFft::setUseNormalization(bool useNormalization) {
Expand Down
4 changes: 4 additions & 0 deletions src/ofxEasyFft.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class ofxEasyFft : public ofBaseSoundInput{
public:
ofxEasyFft();
~ofxEasyFft();
void setup(ofSoundStreamSettings settings,
int bufferSize = 512,
fftWindowType windowType = OF_FFT_WINDOW_HAMMING,
fftImplementation implementation = OF_FFT_BASIC);
void setup(int bufferSize = 512,
fftWindowType windowType = OF_FFT_WINDOW_HAMMING,
fftImplementation implementation = OF_FFT_BASIC,
Expand Down
10 changes: 7 additions & 3 deletions src/ofxProcessFFT.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "ofxProcessFFT.h"

void ProcessFFT::setup(){

ofSoundStreamSettings settings;
setup(settings);
}

//---------------------------------------------
void ProcessFFT::setup(ofSoundStreamSettings settings) {
scaleFactor = 10000;
numBins = 16384;

fft.setup(numBins); //default
fft.setup(settings, numBins); //default
fft.setUseNormalization(false);

graphMaxSize = 200; //approx 10sec of history at 60fps
Expand All @@ -27,7 +32,6 @@ void ProcessFFT::setup(){

normalize = false;
volumeRange = 400; //only used if normalize is false

}

//---------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/ofxProcessFFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ProcessFFT {
ofxEasyFft fft;

void setup(); //whether you want your sounds in a 0-1 range or a 0-volumeRange - setting volume range doesn't matter if you're normalizing
void setup(ofSoundStreamSettings settings);
void update();
//For Debugging audio trends
void drawHistoryGraph(ofPoint pt, fftRangeType drawType);
Expand Down