Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b14caaf
Merge remote-tracking branch 'vacaboja/master'
Dec 18, 2015
2c77e39
GTK+ 3 upgrade.
wahlstedt Dec 19, 2015
5071d4c
Fix renamed cairo context variable in debug.
wahlstedt Dec 20, 2015
a2fd763
More comments added
wahlstedt Dec 21, 2015
abcc6ef
Replaced sprintf() with snprintf()
wahlstedt Dec 21, 2015
612898b
Added CSS styling
wahlstedt Dec 21, 2015
1f8687e
More comments added.
wahlstedt Dec 23, 2015
a6694b3
Separate labels for info text.
wahlstedt Jan 2, 2016
6ba5f36
Remove unused print_number function.
wahlstedt Jan 3, 2016
239f441
Alternate colors for tic/tocs in the paperstrip.
wahlstedt Jan 3, 2016
6725331
Start of settings window + mouse wheel paperstrip zooming.
wahlstedt Jan 8, 2016
4b894c7
Save/load settings to disk.
wahlstedt Jan 9, 2016
ed7a2dc
Hooked up audio input settings.
wahlstedt Jan 11, 2016
b5dab89
Stop the timeout when exiting app in order to prevent invalid calls t…
wahlstedt Jan 12, 2016
d73f75a
Added prefs.c to the Makefile
wahlstedt Jan 12, 2016
ef9149c
Info text alignment improvements.
wahlstedt Jan 15, 2016
bef1490
Further info text improvements.
wahlstedt Jan 15, 2016
834dcde
Cleanup spaces to tabs in css file.
wahlstedt Jan 15, 2016
09af52a
Cancel button in settings dialog.
wahlstedt Feb 9, 2016
c51c25d
Removed unused variable.
wahlstedt Feb 9, 2016
0fb9f6c
More unused variables deleted.
wahlstedt Feb 10, 2016
a505216
Allow for decimal lift angles as requested on WUS.
wahlstedt Feb 10, 2016
9a2402d
Screenshot feature.
wahlstedt Feb 16, 2016
9dccd27
Date formatting tweak in screenshot filenames.
wahlstedt Feb 17, 2016
47d72e5
Whitespace fixes.
wahlstedt Feb 19, 2016
d6fc45d
Cleaner screenshots by hiding the buttons below the paperstrip.
wahlstedt Feb 19, 2016
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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
VERSION = 0.2.3
VERSION = 0.3

CC = gcc

CFLAGS = -Wall -O3 -DVERSION='"$(VERSION)"' `pkg-config --cflags gtk+-2.0 portaudio-2.0 fftw3f`
LDFLAGS = -lm `pkg-config --libs gtk+-2.0 portaudio-2.0 fftw3f`
CFLAGS = -Wall -O3 -DVERSION='"$(VERSION)"' `pkg-config --cflags gtk+-3.0 portaudio-2.0 fftw3f`
LDFLAGS = -lm `pkg-config --libs gtk+-3.0 portaudio-2.0 fftw3f`

CFILES = interface.c algo.c audio.c
CFILES = interface.c algo.c audio.c prefs.c
HFILES = tg.h
ALLFILES = $(CFILES) $(HFILES) Makefile

Expand Down
4 changes: 3 additions & 1 deletion algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,20 @@ void setup_buffers(struct processing_buffers *b)
#endif
}

/* Create a copy of a processing buffer */
struct processing_buffers *pb_clone(struct processing_buffers *p)
{
struct processing_buffers *new = malloc(sizeof(struct processing_buffers));
new->sample_rate = p->sample_rate;
new->waveform = malloc(new->sample_rate * sizeof(float));
memcpy(new->waveform, p->waveform, new->sample_rate * sizeof(float));
memcpy(new->waveform, p->waveform, new->sample_rate * sizeof(float)); // Copy over waveform data

#ifdef DEBUG
new->debug = malloc(p->sample_count * sizeof(float));
memcpy(new->debug, p->debug, p->sample_count * sizeof(float));
#endif

// Copy over the rest of the variables
new->sample_count = p->sample_count;
new->period = p->period;
new->sigma = p->sigma;
Expand Down
84 changes: 72 additions & 12 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#include "tg.h"
#include <portaudio.h>

volatile float pa_buffers[2][PA_BUFF_SIZE];
volatile int write_pointer = 0;
volatile uint64_t timestamp = 0;
volatile float pa_buffers[2][PA_BUFF_SIZE]; // Buffers to store the audio sample data
volatile int write_pointer = 0; // Current write position in the buffers
volatile uint64_t timestamp = 0; // Running timestamp

/* Callback function that consume audio in response to requests from an active PortAudio stream */
int paudio_callback(const void *input_buffer,
void *output_buffer,
unsigned long frame_count,
Expand All @@ -31,17 +32,19 @@ int paudio_callback(const void *input_buffer,
void *data)
{
unsigned long i;
// Copy the sample data to pa_buffers[] (Mac mini gets 512 samples on each callback)
for(i=0; i < frame_count; i++) {
pa_buffers[0][write_pointer] = ((float *)input_buffer)[2*i];
pa_buffers[1][write_pointer] = ((float *)input_buffer)[2*i + 1];
if(write_pointer < PA_BUFF_SIZE - 1) write_pointer++;
else write_pointer = 0;
timestamp++;
else write_pointer = 0; // Wrap over when reaching the buffer end
timestamp++; // Increase timestamp for each frame TODO: Move outside loop?
}
return 0;
}

int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
/* Set up PA to continuously sample audio and store in buffers */
int start_portaudio(int *nominal_sample_rate, double *real_sample_rate, char* name)
{
PaStream *stream;

Expand All @@ -51,7 +54,36 @@ int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
if(err!=paNoError)
goto error;

err = Pa_OpenDefaultStream(&stream,2,0,paFloat32,PA_SAMPLE_RATE,paFramesPerBufferUnspecified,paudio_callback,x);
PaStreamParameters inputParameters;
inputParameters.channelCount = 2; // Stereo
inputParameters.sampleFormat = paFloat32;
// inputParameters.suggestedLatency = ;
inputParameters.hostApiSpecificStreamInfo = NULL;
inputParameters.device = Pa_GetDefaultInputDevice(); // Default input device

// Try to locate the device selected in settings
int nDevices = Pa_GetDeviceCount();
for (int dev = 0; dev < nDevices; dev++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(dev);
if (info->maxInputChannels > 0) {
// Only check sources that has inputs
if (strcmp(info->name, name) == 0) {
inputParameters.device = dev;
break;
}
}
}

// Open the audio stream
err = Pa_OpenStream(&stream,
&inputParameters,
NULL, // outputParameters
PA_SAMPLE_RATE,
paFramesPerBufferUnspecified, // Frames per buffer
paNoFlag,
paudio_callback,
x);

*x = stream;
if(err!=paNoError)
goto error;
Expand All @@ -66,7 +98,7 @@ int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
*real_sample_rate = info->sampleRate / 2;
#else
*nominal_sample_rate = PA_SAMPLE_RATE;
*real_sample_rate = info->sampleRate;
*real_sample_rate = info->sampleRate; // Actual sample rate, reported by PortAudio
#endif
debug("sample rate: nominal = %d real = %f\n",*nominal_sample_rate,*real_sample_rate);

Expand All @@ -80,11 +112,11 @@ int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
int analyze_pa_data(struct processing_buffers *p, int bph, uint64_t events_from)
{
static uint64_t last_tic = 0;
int wp = write_pointer;
int wp = write_pointer; // Current write position in the buffers
uint64_t ts = timestamp;
if(wp < 0 || wp >= PA_BUFF_SIZE) wp = 0;
if(wp < 0 || wp >= PA_BUFF_SIZE) wp = 0; // Sanity check for the buffer pointer
#ifdef LIGHT
if(wp % 2) wp--;
if(wp % 2) wp--; // Make sure pointer is even.
ts /= 2;
#endif
int i;
Expand All @@ -97,7 +129,7 @@ int analyze_pa_data(struct processing_buffers *p, int bph, uint64_t events_from)
#endif
if(k < 0) k += PA_BUFF_SIZE;
for(j=0; j < p[i].sample_count; j++) {
p[i].samples[j] = pa_buffers[0][k] + pa_buffers[1][k];
p[i].samples[j] = pa_buffers[0][k] + pa_buffers[1][k]; // Merge stereo into mono(?)
#ifdef LIGHT
k += 2;
#else
Expand All @@ -122,3 +154,31 @@ int analyze_pa_data(struct processing_buffers *p, int bph, uint64_t events_from)
debug("---\n");
return i;
}

/* Returns the number of input sources */
int num_inputs() {
int inputs = 0;
// Gather list of hosts that have inputs.
int nDevices = Pa_GetDeviceCount();
for (int dev = 0; dev < nDevices; dev++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(dev);
if (info->maxInputChannels > 0) {
inputs++;
}
}
return inputs;
}

/* Get name of specified input */
const char * input_name(int i) {
int num = 0;
int nDevices = Pa_GetDeviceCount();
for (int dev = 0; dev < nDevices; dev++) {
const PaDeviceInfo *info = Pa_GetDeviceInfo(dev);
if (info->maxInputChannels > 0) {
// Only count source that has input
if (++num == i) return info->name;
}
}
return NULL;
}
Loading