summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio/Buffer.h
AgeCommit message (Collapse)Author
2021-11-28LibAudio: New error propagation API in Loader and Bufferkleines Filmröllchen
Previously, a libc-like out-of-line error information was used in the loader and its plugins. Now, all functions that may fail to do their job return some sort of Result. The universally-used error type ist the new LoaderError, which can contain information about the general error category (such as file format, I/O, unimplemented features), an error description, and location information, such as file index or sample index. Additionally, the loader plugins try to do as little work as possible in their constructors. Right after being constructed, a user should call initialize() and check the errors returned from there. (This is done transparently by Loader itself.) If a constructor caused an error, the call to initialize should check and return it immediately. This opportunity was used to rework a lot of the internal error propagation in both loader classes, especially FlacLoader. Therefore, a couple of other refactorings may have sneaked in as well. The adoption of LibAudio users is minimal. Piano's adoption is not important, as the code will receive major refactoring in the near future anyways. SoundPlayer's adoption is also less important, as changes to refactor it are in the works as well. aplay's adoption is the best and may serve as an example for other users. It also includes new buffering behavior. Buffer also gets some attention, making it OOM-safe and thereby also propagating its errors to the user.
2021-11-28LibAudio: Buffer API improvementskleines Filmröllchen
This consists of two changes: First, a utility function create_empty allows the user to quickly create an empty buffer. Second, most creation functions now return a NonnullRefPtr, as their failure causes a VERIFY crash anyways.
2021-11-08LibAudio: Rename Audio::Frame -> Audio::SampleDavid Isaksson
"Frame" is an MPEG term, which is not only unintuitive but also overloaded with different meaning by other codecs (e.g. FLAC). Therefore, use the standard term Sample for the central audio structure. The class is also extracted to its own file, because it's becoming quite large. Bundling these two changes means not distributing similar modifications (changing names and paths) across commits. Co-authored-by: kleines Filmröllchen <malu.bertsch@gmail.com>
2021-11-08LibAudio: Refactor out linear_to_log function and add its inverseDavid Isaksson
The conversion from a linear scale (how we think about audio) to a logarithmic scale (how audio actually works) will be useful for other operations, so let's extract it to its own utility function. Its inverse will also allow reversible operations to be written more easily.
2021-11-08LibCore: Use ErrorOr<T> in Core::AnonymousBufferAndreas Kling
2021-09-12LibDSP+LibAudio: Use logarithmic scaling in delay effectkleines Filmröllchen
With logarithmic volume scaling, the delay effect can sound more natural.
2021-09-12Audio: Change how volume workskleines Filmröllchen
Across the entire audio system, audio now works in 0-1 terms instead of 0-100 as before. Therefore, volume is now a double instead of an int. The master volume of the AudioServer changes smoothly through a FadingProperty, preventing clicks. Finally, volume computations are done with logarithmic scaling, which is more natural for the human ear. Note that this could be 4-5 different commits, but as they change each other's code all the time, it makes no sense to split them up.
2021-08-31Libraries: Add LibDSPkleines Filmröllchen
LibDSP is a library for digital signal processing, and is primarily intended to support the future DAW version of Piano.
2021-08-27Userland+LibAudio: Make audio applications support dynamic sample ratekleines Filmröllchen
All audio applications (aplay, Piano, Sound Player) respect the ability of the system to have theoretically any sample rate. Therefore, they resample their own audio into the system sample rate. LibAudio previously had its loaders resample their own audio, even though they expose their sample rate. This is now changed. The loaders output audio data in their file's sample rate, which the user has to query and resample appropriately. Resampling code from Buffer, WavLoader and FlacLoader is removed. Note that these applications only check the sample rate at startup, which is reasonable (the user has to restart applications when changing the sample rate). Fully dynamic adaptation could both lead to errors and will require another IPC interface. This seems to be enough for now.
2021-08-18LibAudio: Resample with integer ratios instead of floatskleines Filmröllchen
Floating-point ratios are inherently imprecise, and can lead to unpredictable or nondeterministic behavior when resampling and expecting a certain number of resulting samples. Therefore, the resampler now uses integer ratios, with almost identical but fully predictable behavior. This also introduces the reset() function that the FLAC loader will use in the future.
2021-06-25LibAudio: Make ResampleHelper templated for different sample typeskleines Filmröllchen
Previously, ResampleHelper was fixed on handling double's, which makes it unsuitable for the upcoming FLAC loader that needs to resample integers. For this reason, ResampleHelper is templated to support theoretically any type of sample, though only the necessary i32 and double are templated right now. The ResampleHelper implementations are moved from WavLoader.cpp to Buffer.cpp. This also improves some imports in the WavLoader files.
2021-06-25LibAudio: Add the Int32 sample formatkleines Filmröllchen
The signed 32-bit PCM sample format is required for the FLAC standard.
2021-04-26LibAudio: Support 32 and 64-bit float WAV fileskleines Filmröllchen
LibAudio's WavLoader plugin for loading WAV files now supports loading audio files with 32-bit float or 64-bit float samples. By supporting these new non-int sample formats, Audio::Buffer now stores the sample format (out of a list of supported formats) instead of the raw bit depth. (The bit depth is easily calculated with pcm_bits_per_sample)
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-27Everywhere: rename 'Sample' type to 'Frame'Cesar Torres
Because it's what it really is. A frame is composed of 1 or more samples, in the case of SerenityOS 2 (stereo). This will make it less confusing for future mantainability.
2021-01-17AudioServer+LibAudio: Pass audio buffers as Core::AnonymousBufferAndreas Kling
This was the last remaining user of shbufs! :^)
2021-01-12Libraries: Move to Userland/Libraries/Andreas Kling