Renamed AudioDriver audio_input_* vars to input_*
This commit is contained in:
parent
dd8a0b92e0
commit
597301db34
7 changed files with 50 additions and 60 deletions
|
@ -174,9 +174,9 @@ Error AudioDriverCoreAudio::init() {
|
|||
unsigned int buffer_size = buffer_frames * channels;
|
||||
samples_in.resize(buffer_size);
|
||||
input_buf.resize(buffer_size);
|
||||
audio_input_buffer.resize(buffer_size * 8);
|
||||
audio_input_position = 0;
|
||||
audio_input_size = 0;
|
||||
input_buffer.resize(buffer_size * 8);
|
||||
input_position = 0;
|
||||
input_size = 0;
|
||||
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_line("CoreAudio: detected " + itos(channels) + " channels");
|
||||
|
@ -247,17 +247,6 @@ OSStatus AudioDriverCoreAudio::output_callback(void *inRefCon,
|
|||
return 0;
|
||||
};
|
||||
|
||||
void AudioDriverCoreAudio::_input_write_sample(int32_t sample) {
|
||||
|
||||
audio_input_buffer.write[audio_input_position++] = sample;
|
||||
if (audio_input_position >= audio_input_buffer.size()) {
|
||||
audio_input_position = 0;
|
||||
}
|
||||
if (audio_input_size < audio_input_buffer.size()) {
|
||||
audio_input_size++;
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus AudioDriverCoreAudio::input_callback(void *inRefCon,
|
||||
AudioUnitRenderActionFlags *ioActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
|
@ -281,11 +270,11 @@ OSStatus AudioDriverCoreAudio::input_callback(void *inRefCon,
|
|||
if (result == noErr) {
|
||||
for (int i = 0; i < inNumberFrames * ad->capture_channels; i++) {
|
||||
int32_t sample = ad->input_buf[i] << 16;
|
||||
ad->_input_write_sample(sample);
|
||||
ad->input_buffer_write(sample);
|
||||
|
||||
if (ad->capture_channels == 1) {
|
||||
// In case input device is single channel convert it to Stereo
|
||||
ad->_input_write_sample(sample);
|
||||
ad->input_buffer_write(sample);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -545,8 +534,8 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
|||
ERR_FAIL_COND(result != noErr);
|
||||
|
||||
// Reset audio input to keep synchronisation.
|
||||
audio_input_position = 0;
|
||||
audio_input_size = 0;
|
||||
input_position = 0;
|
||||
input_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ class AudioDriverCoreAudio : public AudioDriver {
|
|||
#ifdef OSX_ENABLED
|
||||
Array _get_device_list(bool capture = false);
|
||||
void _set_device(const String &device, bool capture = false);
|
||||
void _input_write_sample(int32_t sample);
|
||||
|
||||
static OSStatus input_device_address_cb(AudioObjectID inObjectID,
|
||||
UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
|
||||
|
|
|
@ -380,7 +380,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) {
|
|||
size_t bytes = pa_stream_readable_size(ad->pa_rec_str);
|
||||
if (bytes > 0) {
|
||||
const void *ptr = NULL;
|
||||
size_t maxbytes = ad->audio_input_buffer.size() * sizeof(int16_t);
|
||||
size_t maxbytes = ad->input_buffer.size() * sizeof(int16_t);
|
||||
|
||||
bytes = MIN(bytes, maxbytes);
|
||||
ret = pa_stream_peek(ad->pa_rec_str, &ptr, &bytes);
|
||||
|
@ -389,9 +389,9 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) {
|
|||
} else {
|
||||
int16_t *srcptr = (int16_t *)ptr;
|
||||
for (size_t i = bytes >> 1; i > 0; i--) {
|
||||
ad->audio_input_buffer.write[ad->audio_input_position++] = int32_t(*srcptr++) << 16;
|
||||
if (ad->audio_input_position >= ad->audio_input_buffer.size()) {
|
||||
ad->audio_input_position = 0;
|
||||
ad->input_buffer.write[ad->input_position++] = int32_t(*srcptr++) << 16;
|
||||
if (ad->input_position >= ad->input_buffer.size()) {
|
||||
ad->input_position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,11 +601,11 @@ Error AudioDriverPulseAudio::capture_init_device() {
|
|||
ERR_FAIL_V(ERR_CANT_OPEN);
|
||||
}
|
||||
|
||||
audio_input_buffer.resize(input_buffer_frames * 8);
|
||||
for (int i = 0; i < audio_input_buffer.size(); i++) {
|
||||
audio_input_buffer.write[i] = 0;
|
||||
input_buffer.resize(input_buffer_frames * 8);
|
||||
for (int i = 0; i < input_buffer.size(); i++) {
|
||||
input_buffer.write[i] = 0;
|
||||
}
|
||||
audio_input_position = 0;
|
||||
input_position = 0;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -320,8 +320,8 @@ Error AudioDriverWASAPI::init_render_device(bool reinit) {
|
|||
// Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels)
|
||||
samples_in.resize(buffer_frames * channels);
|
||||
|
||||
audio_input_position = 0;
|
||||
audio_input_size = 0;
|
||||
input_position = 0;
|
||||
input_size = 0;
|
||||
|
||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||
print_line("WASAPI: detected " + itos(channels) + " channels");
|
||||
|
@ -343,12 +343,9 @@ Error AudioDriverWASAPI::init_capture_device(bool reinit) {
|
|||
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
|
||||
|
||||
// Set the buffer size
|
||||
audio_input_buffer.resize(max_frames * CAPTURE_BUFFER_CHANNELS);
|
||||
for (int i = 0; i < audio_input_buffer.size(); i++) {
|
||||
audio_input_buffer.write[i] = 0;
|
||||
}
|
||||
audio_input_position = 0;
|
||||
audio_input_size = 0;
|
||||
input_buffer.resize(max_frames * CAPTURE_BUFFER_CHANNELS);
|
||||
input_position = 0;
|
||||
input_size = 0;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -682,31 +679,24 @@ void AudioDriverWASAPI::thread_func(void *p_udata) {
|
|||
|
||||
// fixme: Only works for floating point atm
|
||||
for (int j = 0; j < num_frames_available; j++) {
|
||||
int32_t sample_channel[CAPTURE_BUFFER_CHANNELS];
|
||||
int32_t l, r;
|
||||
|
||||
if (flags & AUDCLNT_BUFFERFLAGS_SILENT) {
|
||||
sample_channel[0] = sample_channel[1] = 0;
|
||||
l = r = 0;
|
||||
} else {
|
||||
if (ad->audio_input.channels == 2) {
|
||||
sample_channel[0] = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * 2);
|
||||
sample_channel[1] = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * 2 + 1);
|
||||
l = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * 2);
|
||||
r = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j * 2 + 1);
|
||||
} else if (ad->audio_input.channels == 1) {
|
||||
sample_channel[0] = sample_channel[1] = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j);
|
||||
l = r = read_sample(ad->audio_input.format_tag, ad->audio_input.bits_per_sample, data, j);
|
||||
} else {
|
||||
sample_channel[0] = sample_channel[1] = 0;
|
||||
l = r = 0;
|
||||
ERR_PRINT("WASAPI: unsupported channel count in microphone!");
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < CAPTURE_BUFFER_CHANNELS; k++) {
|
||||
ad->audio_input_buffer.write[ad->audio_input_position++] = sample_channel[k];
|
||||
if (ad->audio_input_position >= ad->audio_input_buffer.size()) {
|
||||
ad->audio_input_position = 0;
|
||||
}
|
||||
if (ad->audio_input_size < ad->audio_input_buffer.size()) {
|
||||
ad->audio_input_size++;
|
||||
}
|
||||
}
|
||||
input_buffer_write(l);
|
||||
input_buffer_write(r);
|
||||
}
|
||||
|
||||
read_frames += num_frames_available;
|
||||
|
|
|
@ -134,18 +134,18 @@ void AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_fr
|
|||
|
||||
AudioDriver::get_singleton()->lock();
|
||||
|
||||
Vector<int32_t> buf = AudioDriver::get_singleton()->get_audio_input_buffer();
|
||||
unsigned int audio_input_size = AudioDriver::get_singleton()->get_audio_input_size();
|
||||
Vector<int32_t> buf = AudioDriver::get_singleton()->get_input_buffer();
|
||||
unsigned int input_size = AudioDriver::get_singleton()->get_input_size();
|
||||
|
||||
// p_frames is multipled by two since an AudioFrame is stereo
|
||||
if ((p_frames * 2) > audio_input_size) {
|
||||
if ((p_frames * 2) > input_size) {
|
||||
for (int i = 0; i < p_frames; i++) {
|
||||
p_buffer[i] = AudioFrame(0.0f, 0.0f);
|
||||
}
|
||||
input_ofs = 0;
|
||||
} else {
|
||||
for (int i = 0; i < p_frames; i++) {
|
||||
if (audio_input_size >= input_ofs) {
|
||||
if (input_size >= input_ofs) {
|
||||
float l = (buf[input_ofs++] >> 16) / 32768.f;
|
||||
if (input_ofs >= buf.size()) {
|
||||
input_ofs = 0;
|
||||
|
|
|
@ -80,6 +80,17 @@ double AudioDriver::get_mix_time() const {
|
|||
return total;
|
||||
}
|
||||
|
||||
void AudioDriver::input_buffer_write(int32_t sample) {
|
||||
|
||||
input_buffer.write[input_position++] = sample;
|
||||
if (input_position >= input_buffer.size()) {
|
||||
input_position = 0;
|
||||
}
|
||||
if (input_size < input_buffer.size()) {
|
||||
input_size++;
|
||||
}
|
||||
}
|
||||
|
||||
AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
|
||||
switch (p_channels) {
|
||||
case 4: return SPEAKER_SURROUND_31;
|
||||
|
|
|
@ -53,12 +53,13 @@ class AudioDriver {
|
|||
#endif
|
||||
|
||||
protected:
|
||||
Vector<int32_t> audio_input_buffer;
|
||||
unsigned int audio_input_position;
|
||||
unsigned int audio_input_size;
|
||||
Vector<int32_t> input_buffer;
|
||||
unsigned int input_position;
|
||||
unsigned int input_size;
|
||||
|
||||
void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
|
||||
void update_mix_time(int p_frames);
|
||||
void input_buffer_write(int32_t sample);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
_FORCE_INLINE_ void start_counting_ticks() { prof_ticks = OS::get_singleton()->get_ticks_usec(); }
|
||||
|
@ -108,9 +109,9 @@ public:
|
|||
SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;
|
||||
int get_total_channels_by_speaker_mode(SpeakerMode) const;
|
||||
|
||||
Vector<int32_t> get_audio_input_buffer() { return audio_input_buffer; }
|
||||
unsigned int get_audio_input_position() { return audio_input_position; }
|
||||
unsigned int get_audio_input_size() { return audio_input_size; }
|
||||
Vector<int32_t> get_input_buffer() { return input_buffer; }
|
||||
unsigned int get_input_position() { return input_position; }
|
||||
unsigned int get_input_size() { return input_size; }
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
uint64_t get_profiling_time() const { return prof_time; }
|
||||
|
|
Loading…
Reference in a new issue