mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 02:23:01 +01:00
Fixed some build errors
This commit is contained in:
parent
bc94e08970
commit
f0f1138c54
@ -192,7 +192,8 @@ int start_transmission(ToxWindow *self)
|
||||
|
||||
set_call(&ASettins.calls[self->call_idx], _True);
|
||||
|
||||
if ( open_primary_device(input, &ASettins.calls[self->call_idx].in_idx) != de_None )
|
||||
if ( open_primary_device(input, &ASettins.calls[self->call_idx].in_idx,
|
||||
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration) != de_None )
|
||||
line_info_add(self, NULL, NULL, NULL, "Failed to open input device!", SYS_MSG, 0, 0);
|
||||
|
||||
if ( register_device_callback(self->call_idx, ASettins.calls[self->call_idx].in_idx,
|
||||
@ -200,7 +201,8 @@ int start_transmission(ToxWindow *self)
|
||||
/* Set VAD as true for all; TODO: Make it more dynamic */
|
||||
line_info_add(self, NULL, NULL, NULL, "Failed to register input handler!", SYS_MSG, 0, 0);
|
||||
|
||||
if ( open_primary_device(output, &ASettins.calls[self->call_idx].out_idx) != de_None ) {
|
||||
if ( open_primary_device(output, &ASettins.calls[self->call_idx].out_idx,
|
||||
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration) != de_None ) {
|
||||
line_info_add(self, NULL, NULL, NULL, "Failed to open output device!", SYS_MSG, 0, 0);
|
||||
ASettins.calls[self->call_idx].has_output = 0;
|
||||
}
|
||||
@ -617,14 +619,16 @@ void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (
|
||||
if (type == output) {
|
||||
pthread_mutex_lock(&this_call->mutex);
|
||||
close_device(output, this_call->out_idx);
|
||||
this_call->has_output = open_device(output, selection, &this_call->out_idx)
|
||||
this_call->has_output = open_device(output, selection, &this_call->out_idx,
|
||||
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration)
|
||||
== de_None ? 1 : 0;
|
||||
pthread_mutex_unlock(&this_call->mutex);
|
||||
}
|
||||
else {
|
||||
/* TODO: check for failure */
|
||||
close_device(input, this_call->in_idx);
|
||||
open_device(input, selection, &this_call->in_idx);
|
||||
open_device(input, selection, &this_call->in_idx,
|
||||
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration);
|
||||
/* Set VAD as true for all; TODO: Make it more dynamic */
|
||||
register_device_callback(self->call_idx, this_call->in_idx, read_device_callback, &self->call_idx, _True);
|
||||
}
|
||||
|
@ -27,8 +27,6 @@
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#define VAD_THRESHOLD_DEFAULT 40.0
|
||||
|
||||
typedef enum _AudioError {
|
||||
ae_None = 0,
|
||||
ae_StartingCaptureDevice = 1 << 0,
|
||||
|
@ -611,6 +611,7 @@ void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
|
||||
#endif /* _SOUND_NOTIFY */
|
||||
}
|
||||
|
||||
#ifdef _AUDIO
|
||||
static void init_infobox(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
@ -623,10 +624,11 @@ static void init_infobox(ToxWindow *self)
|
||||
|
||||
ctx->infobox.win = newwin(INFOBOX_HEIGHT, INFOBOX_WIDTH + 1, 1, x2 - INFOBOX_WIDTH);
|
||||
ctx->infobox.starttime = get_unix_time();
|
||||
ctx->infobox.vad_lvl = VAD_THRESHOLD_DEFAULT;
|
||||
ctx->infobox.vad_lvl = user_settings_->VAD_treshold;
|
||||
ctx->infobox.active = true;
|
||||
strcpy(ctx->infobox.timestr, "00");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void kill_infobox(ToxWindow *self)
|
||||
{
|
||||
|
61
src/device.c
61
src/device.c
@ -20,8 +20,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#ifdef _AUDIO
|
||||
#include "audio_call.h"
|
||||
#endif
|
||||
|
||||
#include "line_info.h"
|
||||
#include "settings.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenAL/al.h>
|
||||
@ -37,12 +43,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <tox/toxav.h>
|
||||
|
||||
#define openal_bufs 5
|
||||
#define sample_rate 48000
|
||||
#define OPENAL_BUFS 5
|
||||
#define inline__ inline __attribute__((always_inline))
|
||||
#define frame_size (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000)
|
||||
|
||||
extern struct user_settings *user_settings_;
|
||||
|
||||
typedef struct _Device {
|
||||
ALCdevice *dhndl; /* Handle of device selected/opened */
|
||||
@ -51,13 +55,17 @@ typedef struct _Device {
|
||||
void* cb_data; /* Data to be passed to callback */
|
||||
int32_t call_idx; /* ToxAv call index */
|
||||
|
||||
uint32_t source, buffers[openal_bufs]; /* Playback source/buffers */
|
||||
uint32_t source, buffers[OPENAL_BUFS]; /* Playback source/buffers */
|
||||
size_t ref_count;
|
||||
int32_t selection;
|
||||
_Bool enable_VAD;
|
||||
_Bool muted;
|
||||
float VAD_treshold; /* 40 is usually recommended value */
|
||||
pthread_mutex_t mutex[1];
|
||||
uint32_t sample_rate;
|
||||
uint32_t frame_duration;
|
||||
#ifdef _AUDIO
|
||||
float VAD_treshold; /* 40 is usually recommended value */
|
||||
#endif
|
||||
} Device;
|
||||
|
||||
const char *ddevice_names[2]; /* Default device */
|
||||
@ -125,7 +133,7 @@ DeviceError init_devices()
|
||||
av = av_;
|
||||
#endif /* _AUDIO */
|
||||
|
||||
return (DeviceError) ae_None;
|
||||
return (DeviceError) de_None;
|
||||
}
|
||||
|
||||
DeviceError terminate_devices()
|
||||
@ -136,7 +144,7 @@ DeviceError terminate_devices()
|
||||
|
||||
pthread_mutex_destroy(&mutex);
|
||||
|
||||
return (DeviceError) ae_None;
|
||||
return (DeviceError) de_None;
|
||||
}
|
||||
|
||||
DeviceError device_mute(DeviceType type, uint32_t device_idx)
|
||||
@ -157,6 +165,7 @@ DeviceError device_mute(DeviceType type, uint32_t device_idx)
|
||||
return de_None;
|
||||
}
|
||||
|
||||
#ifdef _AUDIO
|
||||
DeviceError device_set_VAD_treshold(uint32_t device_idx, float value)
|
||||
{
|
||||
if (device_idx >= MAX_DEVICES) return de_InvalidSelection;
|
||||
@ -174,6 +183,8 @@ DeviceError device_set_VAD_treshold(uint32_t device_idx, float value)
|
||||
unlock;
|
||||
return de_None;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
DeviceError set_primary_device(DeviceType type, int32_t selection)
|
||||
{
|
||||
@ -183,28 +194,33 @@ DeviceError set_primary_device(DeviceType type, int32_t selection)
|
||||
return de_None;
|
||||
}
|
||||
|
||||
DeviceError open_primary_device(DeviceType type, uint32_t* device_idx)
|
||||
DeviceError open_primary_device(DeviceType type, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration)
|
||||
{
|
||||
return open_device(type, primary_device[type], device_idx);
|
||||
return open_device(type, primary_device[type], device_idx, sample_rate, frame_duration);
|
||||
}
|
||||
|
||||
|
||||
// TODO: generate buffers separately
|
||||
DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx)
|
||||
DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration)
|
||||
{
|
||||
if (size[type] <= selection || selection < 0) return de_InvalidSelection;
|
||||
|
||||
lock;
|
||||
|
||||
const uint32_t frame_size = (sample_rate * frame_duration / 1000);
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; i < MAX_DEVICES && running[type][i] != NULL; i ++);
|
||||
|
||||
if (i == MAX_DEVICES) { unlock; return de_AllDevicesBusy; }
|
||||
else *device_idx = i;
|
||||
|
||||
Device* device = running[type][*device_idx] = calloc(1, sizeof(Device));;
|
||||
Device* device = running[type][*device_idx] = calloc(1, sizeof(Device));
|
||||
device->selection = selection;
|
||||
|
||||
device->sample_rate = sample_rate;
|
||||
device->frame_duration = frame_duration;
|
||||
|
||||
for (i = 0; i < *device_idx; i ++) { /* Check if any previous has the same selection */
|
||||
if ( running[type][i]->selection == selection ) {
|
||||
device->dhndl = running[type][i]->dhndl;
|
||||
@ -222,8 +238,10 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
||||
|
||||
if (type == input) {
|
||||
device->dhndl = alcCaptureOpenDevice(devices_names[type][selection],
|
||||
av_DefaultSettings.audio_sample_rate, AL_FORMAT_MONO16, frame_size * 2);
|
||||
device->VAD_treshold = VAD_THRESHOLD_DEFAULT;
|
||||
sample_rate, AL_FORMAT_MONO16, frame_size * 2);
|
||||
#ifdef _AUDIO
|
||||
device->VAD_treshold = user_settings_->VAD_treshold;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
device->dhndl = alcOpenDevice(devices_names[type][selection]);
|
||||
@ -237,18 +255,18 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
||||
device->ctx = alcCreateContext(device->dhndl, NULL);
|
||||
alcMakeContextCurrent(device->ctx);
|
||||
|
||||
alGenBuffers(openal_bufs, device->buffers);
|
||||
alGenBuffers(OPENAL_BUFS, device->buffers);
|
||||
alGenSources((uint32_t)1, &device->source);
|
||||
alSourcei(device->source, AL_LOOPING, AL_FALSE);
|
||||
|
||||
uint16_t zeros[frame_size];
|
||||
memset(zeros, 0, frame_size*2);
|
||||
|
||||
for ( i =0; i < openal_bufs; ++i) {
|
||||
for ( i =0; i < OPENAL_BUFS; ++i) {
|
||||
alBufferData(device->buffers[i], AL_FORMAT_MONO16, zeros, frame_size*2, sample_rate);
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(device->source, openal_bufs, device->buffers);
|
||||
alSourceQueueBuffers(device->source, OPENAL_BUFS, device->buffers);
|
||||
alSourcePlay(device->source);
|
||||
}
|
||||
|
||||
@ -294,7 +312,7 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
||||
if (alcGetCurrentContext() != device->ctx) alcMakeContextCurrent(device->ctx);
|
||||
|
||||
alDeleteSources(1, &device->source);
|
||||
alDeleteBuffers(openal_bufs, device->buffers);
|
||||
alDeleteBuffers(OPENAL_BUFS, device->buffers);
|
||||
|
||||
if ( !alcCloseDevice(device->dhndl) ) rc = de_AlError;
|
||||
alcMakeContextCurrent(NULL);
|
||||
@ -354,7 +372,7 @@ inline__ DeviceError write_out(uint32_t device_idx, int16_t* data, uint32_t leng
|
||||
}
|
||||
|
||||
|
||||
alBufferData(bufid, AL_FORMAT_MONO16, data, lenght * 2 * channels, av_DefaultSettings.audio_sample_rate);
|
||||
alBufferData(bufid, AL_FORMAT_MONO16, data, lenght * 2 * channels, device->sample_rate);
|
||||
alSourceQueueBuffers(device->source, 1, &bufid);
|
||||
|
||||
ALint state;
|
||||
@ -376,7 +394,6 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source
|
||||
uint32_t i;
|
||||
int32_t sample = 0;
|
||||
|
||||
int f_size = frame_size;
|
||||
|
||||
while (thread_running)
|
||||
{
|
||||
@ -390,6 +407,8 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source
|
||||
{
|
||||
alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample);
|
||||
|
||||
int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000);
|
||||
|
||||
if (sample < f_size) {
|
||||
unlock;
|
||||
continue;
|
||||
|
@ -71,12 +71,14 @@ void* get_device_callback_data(uint32_t device_idx);
|
||||
/* toggle device mute */
|
||||
DeviceError device_mute(DeviceType type, uint32_t device_idx);
|
||||
|
||||
#ifdef _AUDIO
|
||||
DeviceError device_set_VAD_treshold(uint32_t device_idx, float value);
|
||||
#endif
|
||||
|
||||
DeviceError set_primary_device(DeviceType type, int32_t selection);
|
||||
DeviceError open_primary_device(DeviceType type, uint32_t* device_idx);
|
||||
DeviceError open_primary_device(DeviceType type, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration);
|
||||
/* Start device */
|
||||
DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx);
|
||||
DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration);
|
||||
/* Stop device */
|
||||
DeviceError close_device(DeviceType type, uint32_t device_idx);
|
||||
|
||||
|
@ -74,7 +74,7 @@ struct _ActiveSounds {
|
||||
uint32_t buffer;
|
||||
_Bool active;
|
||||
_Bool looping;
|
||||
} actives[ACTIVE_SOUNDS_MAX] = {0};
|
||||
} actives[ACTIVE_SOUNDS_MAX] = {{0}};
|
||||
#endif
|
||||
/**********************************************************************************/
|
||||
/**********************************************************************************/
|
||||
@ -154,6 +154,7 @@ void* do_playing(void* _p)
|
||||
pthread_mutex_unlock(Control.poll_mutex);
|
||||
usleep(10000);
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -190,7 +191,7 @@ int play_source(uint32_t source, uint32_t buffer, _Bool looping)
|
||||
int init_notify(int login_cooldown)
|
||||
{
|
||||
#ifdef _SOUND_NOTIFY
|
||||
if (open_primary_device(output, &Control.device_idx) != de_None)
|
||||
if (open_primary_device(output, &Control.device_idx, 48000, 20) != de_None)
|
||||
return -1;
|
||||
|
||||
pthread_mutex_init(Control.poll_mutex, NULL);
|
||||
@ -248,7 +249,7 @@ int play_sound_internal(Notification what, _Bool loop)
|
||||
uint32_t source;
|
||||
uint32_t buffer;
|
||||
|
||||
alutLoadWAVFile(Control.sounds[what], &format, (void**)&data, &buffer_size, &clockrate, &loop_);
|
||||
alutLoadWAVFile((signed char*)Control.sounds[what], &format, (void**)&data, &buffer_size, &clockrate, &loop_);
|
||||
alGenSources(1, &source);
|
||||
alGenBuffers(1, &buffer);
|
||||
alBufferData(buffer, format, data, buffer_size, clockrate);
|
||||
|
Loading…
Reference in New Issue
Block a user