1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:37:34 +00:00

LibAudio: Remove frame-wise copys from FlacLoader

Previously, FlacLoader would read the data for each frame into a
separate vector, which are then combined via extend() in the end. This
incurs an avoidable copy per frame. By having the next_frame() function
write into a given Span, there's only one vector allocated per call to
get_more_samples().

This increases performance by at least 100% realtime, as measured by
abench, from about 1200%-1300% to (usually) 1400% on complex test files.
This commit is contained in:
kleines Filmröllchen 2021-12-17 18:42:36 +01:00 committed by Andreas Kling
parent 30130904f5
commit b48badc3b6
2 changed files with 42 additions and 30 deletions

View file

@ -111,8 +111,8 @@ private:
// Either returns the metadata block or sets error message.
// Additionally, increments m_data_start_location past the read meta block.
ErrorOr<FlacRawMetadataBlock, LoaderError> next_meta_block(InputBitStream& bit_input);
// Fetches and sets the next FLAC frame
MaybeLoaderError next_frame();
// Fetches and writes the next FLAC frame
MaybeLoaderError next_frame(Span<Sample>);
// Helper of next_frame that fetches a sub frame's header
ErrorOr<FlacSubframeHeader, LoaderError> next_subframe_header(InputBitStream& bit_input, u8 channel_index);
// Helper of next_frame that decompresses a subframe
@ -151,7 +151,8 @@ private:
u64 m_data_start_location { 0 };
OwnPtr<FlacInputStream<FLAC_BUFFER_SIZE>> m_stream;
Optional<FlacFrameHeader> m_current_frame;
Vector<Sample> m_current_frame_data;
// Whatever the last get_more_samples() call couldn't return gets stored here.
Vector<Sample, FLAC_BUFFER_SIZE> m_unread_data;
u64 m_current_sample_or_frame { 0 };
};