1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-14 05:23:01 +01:00

Fix cross-client audio issue

This commit is contained in:
Jfreegman 2016-04-05 00:49:46 -04:00
parent e73ac9b6a4
commit 4e0e322e32
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 13 additions and 11 deletions

View File

@ -103,7 +103,8 @@ void callback_call_canceled ( uint32_t friend_number );
void callback_call_rejected ( uint32_t friend_number );
void callback_call_ended ( uint32_t friend_number );
void write_device_callback( uint32_t friend_number, const int16_t* PCM, uint16_t size );
void write_device_callback( uint32_t friend_number, const int16_t* PCM, uint16_t sample_count, uint8_t channels,
uint32_t sample_rate );
static void print_err (ToxWindow *self, const char *error_str)
{
@ -120,9 +121,9 @@ ToxAV *init_audio(ToxWindow *self, Tox *tox)
CallControl.av = toxav_new(tox, &error);
CallControl.audio_enabled = true;
CallControl.audio_bit_rate = 48;
CallControl.audio_bit_rate = 64;
CallControl.audio_sample_rate = 48000;
CallControl.audio_frame_duration = 10;
CallControl.audio_frame_duration = 20;
CallControl.audio_channels = 1;
#ifndef VIDEO
@ -180,10 +181,11 @@ void read_device_callback(const int16_t* captured, uint32_t size, void* data)
{}
}
void write_device_callback(uint32_t friend_number, const int16_t* PCM, uint16_t size)
void write_device_callback(uint32_t friend_number, const int16_t* PCM, uint16_t sample_count, uint8_t channels,
uint32_t sample_rate)
{
if ( CallControl.calls[friend_number].ttas )
write_out(CallControl.calls[friend_number].out_idx, PCM, size, CallControl.audio_channels);
write_out(CallControl.calls[friend_number].out_idx, PCM, sample_count, channels, sample_rate);
}
int start_transmission(ToxWindow *self, Call *call)
@ -328,7 +330,7 @@ void receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
int16_t const *pcm, size_t sample_count,
uint8_t channels, uint32_t sampling_rate, void *user_data)
{
write_device_callback(friend_number, pcm, frame_size);
write_device_callback(friend_number, pcm, sample_count, channels, sampling_rate);
}
void audio_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate,

View File

@ -357,7 +357,8 @@ DeviceError register_device_callback( int32_t friend_number, uint32_t device_idx
return de_None;
}
inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels)
inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t sample_count, uint8_t channels,
uint32_t sample_rate)
{
if (device_idx >= MAX_DEVICES) return de_InvalidSelection;
@ -386,7 +387,7 @@ inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_
}
alBufferData(bufid, device->sound_mode, data, length * 2 * channels, device->sample_rate);
alBufferData(bufid, channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, data, sample_count * 2 * channels, sample_rate);
alSourceQueueBuffers(device->source, 1, &bufid);
ALint state;

View File

@ -22,7 +22,7 @@
/*
* You can have multiple sources (Input devices) but only one output device.
* Pass buffers to output device via write();
* Pass buffers to output device via write();
* Read from running input device(s) via select()/callback combo.
*/
@ -82,7 +82,7 @@ DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx
DeviceError close_device(DeviceType type, uint32_t device_idx);
/* Write data to device */
DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels);
DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels, uint32_t sample_rate);
void print_devices(ToxWindow* self, DeviceType type);
void get_primary_device_name(DeviceType type, char *buf, int size);

View File

@ -580,7 +580,6 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id)
alDeleteSources(1, &actives[id].source);
alDeleteBuffers(1,&actives[id].buffer);
alGenSources(1, &actives[id].source);
alGenBuffers(1, &actives[id].buffer);
actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]);