Skip to content

Commit

Permalink
Put ParamBlocks in SYSRAM, make local copy to DDR RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Nov 2, 2023
1 parent ac7c2da commit e49bc6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
17 changes: 9 additions & 8 deletions firmware/src/audio/audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,35 @@ AudioStream::AudioStream(PatchPlayer &patchplayer,
}

auto audio_callback = [this]<unsigned block>() {
Debug::Pin0::high();
Debug::Pin4::high();

load_lpf += (load_measure.get_last_measurement_load_float() - load_lpf) * 0.05f;
param_blocks[block].metaparams.audio_load = static_cast<uint8_t>(load_lpf * 100.f);

HWSemaphore<block == 0 ? ParamsBuf1Lock : ParamsBuf2Lock>::lock();
HWSemaphore<block == 0 ? ParamsBuf2Lock : ParamsBuf1Lock>::unlock();

// 100us for a 128 block size, or 48us for a 64 block size = +0.75us/frame
// Makes midi poly 4 note loop go from 2.2us to 600ns per frame = -1.6us/frame => net 0.85us/frame = 4%
// Plus, probably benefits from knob mappings
mdrivlib::SystemCache::invalidate_dcache_by_range(&param_blocks[block], sizeof(ParamBlock));
// Copy from non-cacheable SYSRAM to cachable DDR: improves performance
local_p = param_blocks[block];

load_measure.start_measurement();

if (check_patch_loading())
process_nopatch(audio_blocks[1 - block], param_blocks[block]);
process_nopatch(audio_blocks[1 - block], local_p);
else
process(audio_blocks[1 - block], param_blocks[block]);
process(audio_blocks[1 - block], local_p);

load_measure.end_measurement();

sync_params.write_sync(param_state, param_blocks[block].metaparams);
param_state.reset_change_flags();
mdrivlib::SystemCache::clean_dcache_by_range(&sync_params, sizeof sync_params);

// copy analyzed signals back to shared param block (so GUI thread can access it)
param_blocks[block].metaparams.ins = local_p.metaparams.ins;
mdrivlib::SystemCache::clean_dcache_by_range(&param_blocks[block].metaparams, sizeof(MetaParams));

Debug::Pin0::low();
Debug::Pin4::low();
};

codec_.set_callbacks([audio_callback]() { audio_callback.operator()<0>(); },
Expand Down
1 change: 1 addition & 0 deletions firmware/src/audio/audio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private:
float mute_ctr = 1.f;
uint32_t halves_muted = 0;
bool ext_audio_connected = false;
ParamBlock local_p;

AudioConf::SampleT get_audio_output(int output_id);
void set_input(int input_id, AudioConf::SampleT in);
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/core_a7/static_buffers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static inline volatile __attribute__((section(".ddma"))) PatchICCMessage icc_sha
static inline __attribute__((section(".ddma"))) PatchFileList shared_patch_file_list;
//^^^ shared_patch_file_list is just a span (ptr and size)

static inline /*__attribute__((section(".sysram")))*/ DoubleBufParamBlock param_blocks; // 4380 * 2
static inline __attribute__((section(".sysram"))) DoubleBufParamBlock param_blocks;
static inline __attribute__((section(".sysram"))) DoubleAuxStreamBlock auxsignal_block;

static inline __attribute__((section(".virtdrive"))) RamDisk<RamDiskSizeBytes, RamDiskBlockSize> virtdrive;
Expand All @@ -46,7 +46,7 @@ static void init() {
}
block.metaparams.clear();
}
mdrivlib::SystemCache::clean_dcache_by_range(&param_blocks, sizeof param_blocks);
// mdrivlib::SystemCache::clean_dcache_by_range(&param_blocks, sizeof param_blocks);
}
}; // namespace StaticBuffers

Expand Down

0 comments on commit e49bc6e

Please sign in to comment.