diff --git a/.gitignore b/.gitignore index 28c3d33..0de70fc 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,11 @@ __pycache__/ ### IDEs and code editors ### +# Visual Studio +.vs/ +*.sln +*.vcxproj* + # Visual Studio Code .vscode/ *.code-workspace diff --git a/src/chip/channels/siopm_channel_sampler.cpp b/src/chip/channels/siopm_channel_sampler.cpp index 56fc30a..fad6de6 100644 --- a/src/chip/channels/siopm_channel_sampler.cpp +++ b/src/chip/channels/siopm_channel_sampler.cpp @@ -120,7 +120,7 @@ void SiOPMChannelSampler::buffer(int p_length) { SiOPMStream *stream = _streams[i] ? _streams[i] : _sound_chip->get_stream_slot(i); if (stream) { double volume = _volumes[i] * _expression * _sound_chip->get_sampler_volume(); - stream->write_from_vector(_sample_data->get_wave_data(), _sample_index, _buffer_index, processed, volume, _sample_pan, _sample_data->get_channel_count()); + stream->write_from_vector(&_sample_data->get_wave_data(), _sample_index, _buffer_index, processed, volume, _sample_pan, _sample_data->get_channel_count()); } } } @@ -128,7 +128,7 @@ void SiOPMChannelSampler::buffer(int p_length) { SiOPMStream *stream = _streams[0] ? _streams[0] : _sound_chip->get_output_stream(); double volume = _volumes[0] * _expression * _sound_chip->get_sampler_volume(); - stream->write_from_vector(_sample_data->get_wave_data(), _sample_index, _buffer_index, processed, volume, _sample_pan, _sample_data->get_channel_count()); + stream->write_from_vector(&_sample_data->get_wave_data(), _sample_index, _buffer_index, processed, volume, _sample_pan, _sample_data->get_channel_count()); } _sample_index += processed; diff --git a/src/chip/siopm_sound_chip.cpp b/src/chip/siopm_sound_chip.cpp index f4586e4..60b13c6 100644 --- a/src/chip/siopm_sound_chip.cpp +++ b/src/chip/siopm_sound_chip.cpp @@ -10,12 +10,8 @@ #include "chip/siopm_operator_params.h" #include "chip/siopm_stream.h" -Vector SiOPMSoundChip::get_output_buffer() const { - return output_stream->get_buffer(); -} - -void SiOPMSoundChip::set_output_buffer(Vector p_buffer) { - output_stream->set_buffer(p_buffer); +Vector *SiOPMSoundChip::get_output_buffer_ptr() { + return output_stream->get_buffer_ptr(); } int SiOPMSoundChip::get_channel_count() const { diff --git a/src/chip/siopm_sound_chip.h b/src/chip/siopm_sound_chip.h index 0c968de..96ca3d1 100644 --- a/src/chip/siopm_sound_chip.h +++ b/src/chip/siopm_sound_chip.h @@ -47,8 +47,7 @@ class SiOPMSoundChip : public Object { SinglyLinkedList *get_zero_buffer() const { return zero_buffer; } SiOPMStream *get_output_stream() const { return output_stream; } - Vector get_output_buffer() const; - void set_output_buffer(Vector p_buffer); + Vector *get_output_buffer_ptr(); int get_channel_count() const; SiOPMStream *get_stream_slot(int p_slot) const { return stream_slot[p_slot]; } diff --git a/src/chip/siopm_stream.cpp b/src/chip/siopm_stream.cpp index b28b211..b0e1a39 100644 --- a/src/chip/siopm_stream.cpp +++ b/src/chip/siopm_stream.cpp @@ -108,7 +108,7 @@ void SiOPMStream::write_stereo(SinglyLinkedList *p_left, SinglyLinkedList p_data, int p_start_data, int p_start_buffer, int p_length, double p_volume, int p_pan, int p_sample_channel_count) { +void SiOPMStream::write_from_vector(Vector *p_data, int p_start_data, int p_start_buffer, int p_length, double p_volume, int p_pan, int p_sample_channel_count) { double volume = p_volume; if (channels == 2) { @@ -120,10 +120,10 @@ void SiOPMStream::write_from_vector(Vector p_data, int p_start_data, int int buffer_size = (p_start_data + p_length) << 1; for (int j = p_start_data << 1, i = p_start_buffer << 1; j < buffer_size;) { - buffer.write[i] += p_data[j] * volume_left; + buffer.write[i] += (*p_data)[j] * volume_left; j++; i++; - buffer.write[i] += p_data[j] * volume_right; + buffer.write[i] += (*p_data)[j] * volume_right; j++; i++; } @@ -133,9 +133,9 @@ void SiOPMStream::write_from_vector(Vector p_data, int p_start_data, int int buffer_size = p_start_data + p_length; for (int j = p_start_data, i = p_start_buffer << 1; j < buffer_size; j++) { - buffer.write[i] += p_data[j] * volume_left; + buffer.write[i] += (*p_data)[j] * volume_left; i++; - buffer.write[i] += p_data[j] * volume_right; + buffer.write[i] += (*p_data)[j] * volume_right; i++; } } @@ -145,9 +145,9 @@ void SiOPMStream::write_from_vector(Vector p_data, int p_start_data, int int buffer_size = (p_start_data + p_length) << 1; for (int j = p_start_data << 1, i = p_start_buffer << 1; j < buffer_size;) { - buffer.write[i] += (p_data[j] + p_data[j + 1]) * volume; + buffer.write[i] += ((*p_data)[j] + (*p_data)[j + 1]) * volume; i++; - buffer.write[i] += (p_data[j] + p_data[j + 1]) * volume; + buffer.write[i] += ((*p_data)[j] + (*p_data)[j + 1]) * volume; i++; j += 2; } @@ -155,9 +155,9 @@ void SiOPMStream::write_from_vector(Vector p_data, int p_start_data, int int buffer_size = p_start_data + p_length; for (int j = p_start_data, i = p_start_buffer << 1; j < buffer_size; j++) { - buffer.write[i] += p_data[j] * volume; + buffer.write[i] += (*p_data)[j] * volume; i++; - buffer.write[i] += p_data[j] * volume; + buffer.write[i] += (*p_data)[j] * volume; i++; } } diff --git a/src/chip/siopm_stream.h b/src/chip/siopm_stream.h index 27ce9e5..e054de4 100644 --- a/src/chip/siopm_stream.h +++ b/src/chip/siopm_stream.h @@ -22,6 +22,7 @@ class SiOPMStream { void set_channel_count(int p_value) { channels = p_value; } Vector get_buffer() const { return buffer; } + Vector *get_buffer_ptr() { return &buffer; } void set_buffer(Vector p_buffer) { buffer = p_buffer; } void resize(int p_length); @@ -31,7 +32,7 @@ class SiOPMStream { void write(SinglyLinkedList *p_data, int p_start, int p_length, double p_volume, int p_pan); void write_stereo(SinglyLinkedList *p_left, SinglyLinkedList *p_right, int p_start, int p_length, double p_volume, int p_pan); - void write_from_vector(Vector p_data, int p_start_data, int p_start_buffer, int p_length, double p_volume, int p_pan, int p_sample_channel_count); + void write_from_vector(Vector *p_data, int p_start_data, int p_start_buffer, int p_length, double p_volume, int p_pan, int p_sample_channel_count); SiOPMStream() {} ~SiOPMStream() {} diff --git a/src/effector/si_effect_stream.cpp b/src/effector/si_effect_stream.cpp index 95a2f5b..81ec9bc 100644 --- a/src/effector/si_effect_stream.cpp +++ b/src/effector/si_effect_stream.cpp @@ -79,15 +79,13 @@ int SiEffectStream::prepare_process() { } int SiEffectStream::process(int p_start_idx, int p_length, bool p_write_in_stream) { - Vector buffer = _stream->get_buffer(); + Vector *buffer = _stream->get_buffer_ptr(); int channel_count = _stream->get_channel_count(); for (int i = 0; i < _chain.size(); i++) { - channel_count = _chain[i]->process(channel_count, &buffer, p_start_idx, p_length); + channel_count = _chain[i]->process(channel_count, buffer, p_start_idx, p_length); } - _stream->set_buffer(buffer); - if (p_write_in_stream) { if (_has_effect_send) { for (int i = 0; i < SiOPMSoundChip::STREAM_SEND_SIZE; i++) { diff --git a/src/effector/si_effector.cpp b/src/effector/si_effector.cpp index 2380057..c32399d 100644 --- a/src/effector/si_effector.cpp +++ b/src/effector/si_effector.cpp @@ -264,13 +264,11 @@ void SiEffector::end_process() { if (effect->is_outputting_directly()) { effect->process(0, _sound_chip->get_buffer_length(), false); - // TODO: Is this the best way to do this — to copy the buffer over? - Vector buffer = effect->get_stream()->get_buffer(); - Vector output = _sound_chip->get_output_buffer(); - for (int j = 0; j < output.size(); j++) { - output.write[j] += buffer[j]; + Vector *buffer = effect->get_stream()->get_buffer_ptr(); + Vector *output = _sound_chip->get_output_stream()->get_buffer_ptr(); + for (int j = 0; j < output->size(); j++) { + output->write[j] += (*buffer)[j]; } - _sound_chip->set_output_buffer(output); } else { effect->process(0, _sound_chip->get_buffer_length(), true); } diff --git a/src/sion_driver.cpp b/src/sion_driver.cpp index cb9705c..0b9945c 100644 --- a/src/sion_driver.cpp +++ b/src/sion_driver.cpp @@ -398,16 +398,16 @@ bool SiONDriver::_rendering() { _render_buffer.resize_zeroed(_render_buffer_index + buffer_extension); } - // Copy the output. - Vector output_buffer = sound_chip->get_output_buffer(); + // Read the output. + Vector *output_buffer = sound_chip->get_output_buffer_ptr(); if (_render_buffer_channel_count == 2) { for (int i = 0, j = _render_buffer_index; i < rendering_length; i++, j++) { - _render_buffer.write[j] = output_buffer[i]; + _render_buffer.write[j] = (*output_buffer)[i]; } } else { for (int i = 0, j = _render_buffer_index; i < rendering_length; i += 2, j++) { - _render_buffer.write[j] = output_buffer[i]; + _render_buffer.write[j] = (*output_buffer)[i]; } } @@ -464,9 +464,9 @@ void SiONDriver::_streaming() { _performance_stats.average_processing_time = _performance_stats.total_processing_time * _performance_stats.total_processing_time_ratio; // Write samples. - Vector output_buffer = sound_chip->get_output_buffer(); - for (int i = 0; i < output_buffer.size(); i += 2) { - stream_buffer.push_back(Vector2(output_buffer[i], output_buffer[i + 1])); + Vector *output_buffer = sound_chip->get_output_buffer_ptr(); + for (int i = 0; i < output_buffer->size(); i += 2) { + stream_buffer.push_back(Vector2((*output_buffer)[i], (*output_buffer)[i + 1])); } _audio_playback->push_buffer(stream_buffer);