mirror of
https://github.com/Mr-Wiseguy/Zelda64Recomp.git
synced 2024-11-26 06:34:20 +01:00
Fixed audio channels getting swapped twice
This commit is contained in:
parent
976bfa1969
commit
b7b7658431
@ -23,31 +23,15 @@ void ultramodern::set_audio_frequency(uint32_t freq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ultramodern::queue_audio_buffer(RDRAM_ARG PTR(int16_t) audio_data_, uint32_t byte_count) {
|
void ultramodern::queue_audio_buffer(RDRAM_ARG PTR(int16_t) audio_data_, uint32_t byte_count) {
|
||||||
// Buffer for holding the output of swapping the audio channels. This is reused across
|
|
||||||
// calls to reduce runtime allocations.
|
|
||||||
static std::vector<int16_t> swap_buffer;
|
|
||||||
|
|
||||||
// Ensure that the byte count is an integer multiple of samples.
|
// Ensure that the byte count is an integer multiple of samples.
|
||||||
assert((byte_count & 1) == 0);
|
assert((byte_count & 1) == 0);
|
||||||
|
|
||||||
// Calculate the number of samples from the number of bytes.
|
// Calculate the number of samples from the number of bytes.
|
||||||
uint32_t sample_count = byte_count / sizeof(int16_t);
|
uint32_t sample_count = byte_count / sizeof(int16_t);
|
||||||
|
|
||||||
// Make sure the swap buffer is large enough to hold all the incoming audio data.
|
|
||||||
if (sample_count > swap_buffer.size()) {
|
|
||||||
swap_buffer.resize(sample_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swap the audio channels into the swap buffer to correct for the address xor caused by endianness handling.
|
|
||||||
int16_t* audio_data = TO_PTR(int16_t, audio_data_);
|
|
||||||
for (size_t i = 0; i < sample_count; i += 2) {
|
|
||||||
swap_buffer[i + 0] = audio_data[i + 1];
|
|
||||||
swap_buffer[i + 1] = audio_data[i + 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queue the swapped audio data.
|
// Queue the swapped audio data.
|
||||||
if (audio_callbacks.queue_samples) {
|
if (audio_callbacks.queue_samples) {
|
||||||
audio_callbacks.queue_samples(swap_buffer.data(), sample_count);
|
audio_callbacks.queue_samples(TO_PTR(int16_t, audio_data_), sample_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user