Properly handle Partner CTR audio

This commit is contained in:
Lorenzooone
2026-01-12 12:54:51 +01:00
parent 2197dbb9ca
commit 3dc7b032a8
7 changed files with 53 additions and 4 deletions

View File

@@ -24,9 +24,8 @@ Audio::Audio(AudioData *audio_data) {
this->audio_data = audio_data;
// Consume old events
this->buffer = new std::int16_t[MAX_SAMPLES_IN * (MAX_MAX_AUDIO_LATENCY + 1)];
this->change_sample_rate(SAMPLE_RATE_DS);
this->audio_data->check_audio_restart_request();
sf::SoundStream::initialize(AUDIO_CHANNELS, SAMPLE_RATE_BASE, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0 / SAMPLE_RATE_DIVISOR);
start_audio();
setVolume(0);
this->final_volume = 0;
@@ -35,6 +34,41 @@ Audio::Audio(AudioData *audio_data) {
Audio::~Audio() {
delete []this->buffer;
}
AudioSampleRate Audio::get_current_sample_rate() {
return this->current_sample_rate;
}
void Audio::change_sample_rate(AudioSampleRate target) {
if(target == this->current_sample_rate)
return;
switch(target) {
case SAMPLE_RATE_DS:
sf::SoundStream::initialize(AUDIO_CHANNELS, SAMPLE_RATE_DS_BASE, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0 / SAMPLE_RATE_DS_DIVISOR);
break;
case SAMPLE_RATE_48K:
sf::SoundStream::initialize(AUDIO_CHANNELS, 48000, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0);
break;
case SAMPLE_RATE_44_1K:
sf::SoundStream::initialize(AUDIO_CHANNELS, 44100, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0);
break;
case SAMPLE_RATE_32K:
sf::SoundStream::initialize(AUDIO_CHANNELS, 32000, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0);
break;
case SAMPLE_RATE_32768:
sf::SoundStream::initialize(AUDIO_CHANNELS, 32768, {sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight});
this->setPitch(1.0);
break;
default:
break;
}
this->current_sample_rate = target;
}
void Audio::update_volume() {
int new_final_volume = this->audio_data->get_final_volume();