Skip to content

Commit

Permalink
Use Kinc's separate audio channels
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 29, 2024
1 parent a065806 commit 098ccf5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Backends/Kinc-hxcpp/lib/khalib/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ static void run(void *param) {
next.data.sound.samples[i * 2 + 0] = (float)(sound->left[i] / 32767.0);
next.data.sound.samples[i * 2 + 1] = (float)(sound->right[i] / 32767.0);
}
next.data.sound.channels = sound->format.channels;
next.data.sound.sample_rate = sound->format.samples_per_second;
next.data.sound.length =
(sound->size / (sound->format.bits_per_sample / 8) / sound->format.channels) / (float)sound->format.samples_per_second;
next.data.sound.channels = sound->channel_count;
next.data.sound.sample_rate = sound->samples_per_second;
next.data.sound.length = (sound->size / (sound->bits_per_sample / 8) / sound->channel_count) / (float)sound->samples_per_second;
kinc_a1_sound_destroy(sound);
}
else {
Expand Down
12 changes: 7 additions & 5 deletions Backends/Kinc-hxcpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace {
#endif
bool mixThreadregistered = false;

void mix(kinc_a2_buffer_t *buffer, int samples, void *userdata) {
void mix(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) {
using namespace Kore;

int t0 = 99;
Expand All @@ -226,7 +226,7 @@ namespace {
}
#endif

::kha::audio2::Audio_obj::_callCallback(samples, buffer->format.samples_per_second);
::kha::audio2::Audio_obj::_callCallback(samples * 2, kinc_a2_samples_per_second());

#ifdef KORE_MULTITHREADED_AUDIO
if (mixThreadregistered) {
Expand All @@ -236,8 +236,10 @@ namespace {

for (int i = 0; i < samples; ++i) {
float value = ::kha::audio2::Audio_obj::_readSample();
*(float *)&buffer->data[buffer->write_location] = value;
buffer->write_location += 4;
buffer->channels[0][buffer->write_location] = value;
value = ::kha::audio2::Audio_obj::_readSample();
buffer->channels[1][buffer->write_location] = value;
buffer->write_location += 1;
if (buffer->write_location >= buffer->data_size) {
buffer->write_location = 0;
}
Expand Down Expand Up @@ -342,7 +344,7 @@ void post_kinc_init() {
void kha_kinc_init_audio(void) {
kinc_a2_set_callback(mix, nullptr);
kinc_a2_init();
::kha::audio2::Audio_obj::samplesPerSecond = kinc_a2_samples_per_second;
::kha::audio2::Audio_obj::samplesPerSecond = kinc_a2_samples_per_second();
}

void run_kinc() {
Expand Down

0 comments on commit 098ccf5

Please sign in to comment.