@ -36,9 +36,9 @@ public:
}
}
void SetWaveIndex ( std : : size_t index ) ;
void SetWaveIndex ( std : : size_t index ) ;
std : : vector < s16 > DequeueSamples ( std : : size_t sample_count );
std : : vector < s16 > DequeueSamples ( std : : size_t sample_count , Memory : : Memory & memory );
void UpdateState ( ) ;
void UpdateState ( ) ;
void RefreshBuffer ( ) ;
void RefreshBuffer ( Memory : : Memory & memory ) ;
private :
private :
bool is_in_use { } ;
bool is_in_use { } ;
@ -66,17 +66,18 @@ public:
return info ;
return info ;
}
}
void UpdateState ( ) ;
void UpdateState ( Memory : : Memory & memory ) ;
private :
private :
EffectOutStatus out_status { } ;
EffectOutStatus out_status { } ;
EffectInStatus info { } ;
EffectInStatus info { } ;
} ;
} ;
AudioRenderer : : AudioRenderer ( Core : : Timing : : CoreTiming & core_timing , AudioRendererParameter params ,
AudioRenderer : : AudioRenderer ( Core : : Timing : : CoreTiming & core_timing , Memory : : Memory & memory_ ,
AudioRendererParameter params ,
std : : shared_ptr < Kernel : : WritableEvent > buffer_event ,
std : : shared_ptr < Kernel : : WritableEvent > buffer_event ,
std : : size_t instance_number )
std : : size_t instance_number )
: worker_params { params } , buffer_event { buffer_event } , voices ( params . voice_count ) ,
: worker_params { params } , buffer_event { buffer_event } , voices ( params . voice_count ) ,
effects ( params . effect_count ) {
effects ( params . effect_count ) , memory { memory_ } {
audio_out = std : : make_unique < AudioCore : : AudioOut > ( ) ;
audio_out = std : : make_unique < AudioCore : : AudioOut > ( ) ;
stream = audio_out - > OpenStream ( core_timing , STREAM_SAMPLE_RATE , STREAM_NUM_CHANNELS ,
stream = audio_out - > OpenStream ( core_timing , STREAM_SAMPLE_RATE , STREAM_NUM_CHANNELS ,
@ -162,7 +163,7 @@ std::vector<u8> AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_
}
}
for ( auto & effect : effects ) {
for ( auto & effect : effects ) {
effect . UpdateState ( ) ;
effect . UpdateState ( memory ) ;
}
}
// Release previous buffers and queue next ones for playback
// Release previous buffers and queue next ones for playback
@ -206,13 +207,14 @@ void AudioRenderer::VoiceState::SetWaveIndex(std::size_t index) {
is_refresh_pending = true ;
is_refresh_pending = true ;
}
}
std : : vector < s16 > AudioRenderer : : VoiceState : : DequeueSamples ( std : : size_t sample_count ) {
std : : vector < s16 > AudioRenderer : : VoiceState : : DequeueSamples ( std : : size_t sample_count ,
Memory : : Memory & memory ) {
if ( ! IsPlaying ( ) ) {
if ( ! IsPlaying ( ) ) {
return { } ;
return { } ;
}
}
if ( is_refresh_pending ) {
if ( is_refresh_pending ) {
RefreshBuffer ( ) ;
RefreshBuffer ( memory ) ;
}
}
const std : : size_t max_size { samples . size ( ) - offset } ;
const std : : size_t max_size { samples . size ( ) - offset } ;
@ -256,7 +258,7 @@ void AudioRenderer::VoiceState::UpdateState() {
is_in_use = info . is_in_use ;
is_in_use = info . is_in_use ;
}
}
void AudioRenderer : : VoiceState : : RefreshBuffer ( ) {
void AudioRenderer : : VoiceState : : RefreshBuffer ( Memory : : Memory & memory ) {
std : : vector < s16 > new_samples ( info . wave_buffer [ wave_index ] . buffer_sz / sizeof ( s16 ) ) ;
std : : vector < s16 > new_samples ( info . wave_buffer [ wave_index ] . buffer_sz / sizeof ( s16 ) ) ;
Memory : : ReadBlock ( info . wave_buffer [ wave_index ] . buffer_addr , new_samples . data ( ) ,
Memory : : ReadBlock ( info . wave_buffer [ wave_index ] . buffer_addr , new_samples . data ( ) ,
info . wave_buffer [ wave_index ] . buffer_sz ) ;
info . wave_buffer [ wave_index ] . buffer_sz ) ;
@ -307,7 +309,7 @@ void AudioRenderer::VoiceState::RefreshBuffer() {
is_refresh_pending = false ;
is_refresh_pending = false ;
}
}
void AudioRenderer : : EffectState : : UpdateState ( ) {
void AudioRenderer : : EffectState : : UpdateState ( Memory : : Memory & memory ) {
if ( info . is_new ) {
if ( info . is_new ) {
out_status . state = EffectStatus : : New ;
out_status . state = EffectStatus : : New ;
} else {
} else {
@ -340,7 +342,7 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
std : : size_t offset { } ;
std : : size_t offset { } ;
s64 samples_remaining { BUFFER_SIZE } ;
s64 samples_remaining { BUFFER_SIZE } ;
while ( samples_remaining > 0 ) {
while ( samples_remaining > 0 ) {
const std : : vector < s16 > samples { voice . DequeueSamples ( samples_remaining )} ;
const std : : vector < s16 > samples { voice . DequeueSamples ( samples_remaining , memory )} ;
if ( samples . empty ( ) ) {
if ( samples . empty ( ) ) {
break ;
break ;