Skip to content

Commit

Permalink
Read config file before starting audio
Browse files Browse the repository at this point in the history
This way settings that affect audio can be read in before audio starts.

Since the config file is now read before starting audio, it is possible
to start in light or normal mode as configured.

If light mode was configured, then previously audio would be started in
normal mode and then immediatly switch to light mode after processing a
few callbacks.
  • Loading branch information
xyzzy42 committed Apr 18, 2021
1 parent 6db5467 commit 4282a1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int paudio_callback(const void *input_buffer,
return 0;
}

int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
int start_portaudio(int *nominal_sample_rate, double *real_sample_rate, bool light)
{
if(pthread_mutex_init(&audio_mutex,NULL)) {
error("Failed to setup audio mutex");
Expand Down Expand Up @@ -122,7 +122,7 @@ int start_portaudio(int *nominal_sample_rate, double *real_sample_rate)
}
if(channels > 2) channels = 2;
info.channels = channels;
info.light = false;
info.light = light;
err = Pa_OpenDefaultStream(&stream,channels,0,paFloat32,PA_SAMPLE_RATE,paFramesPerBufferUnspecified,paudio_callback,&info);
if(err!=paNoError)
goto error;
Expand Down
10 changes: 5 additions & 5 deletions src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,6 @@ static void start_interface(GApplication* app, void *p)

struct main_window *w = malloc(sizeof(struct main_window));

if(start_portaudio(&w->nominal_sr, &real_sr)) {
g_application_quit(app);
return;
}

w->app = GTK_APPLICATION(app);

w->zombie = 0;
Expand All @@ -934,6 +929,11 @@ static void start_interface(GApplication* app, void *p)

load_config(w);

if(start_portaudio(&w->nominal_sr, &real_sr, w->is_light)) {
g_application_quit(app);
return;
}

if(w->la < MIN_LA || w->la > MAX_LA) w->la = DEFAULT_LA;
if(w->bph < MIN_BPH || w->bph > MAX_BPH) w->bph = 0;
if(w->cal < MIN_CAL || w->cal > MAX_CAL)
Expand Down
2 changes: 1 addition & 1 deletion src/tg.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct processing_data {
int is_light;
};

int start_portaudio(int *nominal_sample_rate, double *real_sample_rate);
int start_portaudio(int *nominal_sample_rate, double *real_sample_rate, bool light);
int terminate_portaudio();
uint64_t get_timestamp(int light);
int analyze_pa_data(struct processing_data *pd, int bph, double la, uint64_t events_from);
Expand Down

0 comments on commit 4282a1c

Please sign in to comment.