mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-16 23:13:03 +01:00
This should fix audio problem
This commit is contained in:
parent
784883f773
commit
b10eebd77e
48
src/device.c
48
src/device.c
@ -61,7 +61,7 @@ typedef struct Device {
|
|||||||
int32_t call_idx; /* ToxAv call index */
|
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;
|
uint32_t ref_count;
|
||||||
int32_t selection;
|
int32_t selection;
|
||||||
bool enable_VAD;
|
bool enable_VAD;
|
||||||
bool muted;
|
bool muted;
|
||||||
@ -77,7 +77,7 @@ typedef struct Device {
|
|||||||
const char *ddevice_names[2]; /* Default device */
|
const char *ddevice_names[2]; /* Default device */
|
||||||
const char *devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
const char *devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
||||||
static int size[2]; /* Size of above containers */
|
static int size[2]; /* Size of above containers */
|
||||||
Device *running[2][MAX_DEVICES]; /* Running devices */
|
Device *running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */
|
||||||
uint32_t primary_device[2]; /* Primary device */
|
uint32_t primary_device[2]; /* Primary device */
|
||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
@ -220,6 +220,18 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
|||||||
if (i == MAX_DEVICES) { unlock; return de_AllDevicesBusy; }
|
if (i == MAX_DEVICES) { unlock; return de_AllDevicesBusy; }
|
||||||
else *device_idx = i;
|
else *device_idx = i;
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_DEVICES; i ++) { /* Check if any device has the same selection */
|
||||||
|
if ( running[type][i] && running[type][i]->selection == selection ) {
|
||||||
|
// printf("a%d-%d:%p ", selection, i, running[type][i]->dhndl);
|
||||||
|
|
||||||
|
running[type][*device_idx] = running[type][i];
|
||||||
|
running[type][i]->ref_count ++;
|
||||||
|
|
||||||
|
unlock;
|
||||||
|
return de_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Device* device = running[type][*device_idx] = calloc(1, sizeof(Device));
|
Device* device = running[type][*device_idx] = calloc(1, sizeof(Device));
|
||||||
device->selection = selection;
|
device->selection = selection;
|
||||||
|
|
||||||
@ -233,28 +245,6 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
|
|||||||
return de_InternalError;
|
return de_InternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (type == output) {
|
|
||||||
device->ctx = running[type][i]->ctx;
|
|
||||||
memcpy(device->buffers, running[type][i]->buffers, sizeof(running[type][i]->buffers));
|
|
||||||
device->source = running[type][i]->source;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (running[type][i]->ref_count)
|
|
||||||
device->ref_count = running[type][i]->ref_count;
|
|
||||||
else
|
|
||||||
device->ref_count = running[type][i]->ref_count = calloc(1, sizeof(size_t));
|
|
||||||
|
|
||||||
*device->ref_count++;
|
|
||||||
|
|
||||||
unlock;
|
|
||||||
return de_None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == input) {
|
if (type == input) {
|
||||||
device->dhndl = alcCaptureOpenDevice(devices_names[type][selection],
|
device->dhndl = alcCaptureOpenDevice(devices_names[type][selection],
|
||||||
sample_rate, device->sound_mode, frame_size * 2);
|
sample_rate, device->sound_mode, frame_size * 2);
|
||||||
@ -320,10 +310,9 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
|
|
||||||
running[type][device_idx] = NULL;
|
running[type][device_idx] = NULL;
|
||||||
|
|
||||||
/* Once copied device->ref_count will be set to 1; not 2
|
if ( !device->ref_count ) {
|
||||||
*/
|
|
||||||
if ( !(device->ref_count) || *(device->ref_count) ) {
|
|
||||||
|
|
||||||
|
// printf("Closed device ");
|
||||||
|
|
||||||
if (type == input) {
|
if (type == input) {
|
||||||
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
|
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
|
||||||
@ -338,11 +327,10 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
|
|||||||
alcMakeContextCurrent(NULL);
|
alcMakeContextCurrent(NULL);
|
||||||
if ( device->ctx ) alcDestroyContext(device->ctx);
|
if ( device->ctx ) alcDestroyContext(device->ctx);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (device->ref_count) *(device->ref_count)--;
|
|
||||||
|
|
||||||
/* Just pop the reference */
|
|
||||||
free(device);
|
free(device);
|
||||||
|
}
|
||||||
|
else device->ref_count--;
|
||||||
|
|
||||||
unlock;
|
unlock;
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -180,6 +180,7 @@ bool m_open_device()
|
|||||||
|
|
||||||
/* Blah error check */
|
/* Blah error check */
|
||||||
open_primary_device(output, &Control.device_idx, 48000, 20, 1);
|
open_primary_device(output, &Control.device_idx, 48000, 20, 1);
|
||||||
|
|
||||||
return (device_opened = true);
|
return (device_opened = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user