diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 417d7011bc..4a1c8a81e2 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -436,6 +436,7 @@ if (BUILD_LAGOM) PDF Protocol Regex + RIFF SoftGPU SQL Syntax diff --git a/Meta/gn/secondary/Userland/Libraries/LibAudio/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibAudio/BUILD.gn index 389b1bf3e6..ecc0991daf 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibAudio/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibAudio/BUILD.gn @@ -13,7 +13,6 @@ shared_library("LibAudio") { "PlaybackStream.cpp", "QOALoader.cpp", "QOATypes.cpp", - "RIFFTypes.cpp", "SampleFormats.cpp", "UserSampleQueue.cpp", "VorbisComment.cpp", diff --git a/Userland/Libraries/CMakeLists.txt b/Userland/Libraries/CMakeLists.txt index 35db099544..a058b8d62f 100644 --- a/Userland/Libraries/CMakeLists.txt +++ b/Userland/Libraries/CMakeLists.txt @@ -47,6 +47,7 @@ add_subdirectory(LibPCIDB) add_subdirectory(LibPDF) add_subdirectory(LibProtocol) add_subdirectory(LibRegex) +add_subdirectory(LibRIFF) add_subdirectory(LibSanitizer) add_subdirectory(LibSoftGPU) add_subdirectory(LibSQL) diff --git a/Userland/Libraries/LibAudio/CMakeLists.txt b/Userland/Libraries/LibAudio/CMakeLists.txt index ba39124605..6f50e24dd5 100644 --- a/Userland/Libraries/LibAudio/CMakeLists.txt +++ b/Userland/Libraries/LibAudio/CMakeLists.txt @@ -2,7 +2,6 @@ set(SOURCES GenericTypes.cpp SampleFormats.cpp Loader.cpp - RIFFTypes.cpp WavLoader.cpp FlacLoader.cpp FlacWriter.cpp @@ -36,7 +35,7 @@ if (HAVE_PULSEAUDIO) endif() serenity_lib(LibAudio audio) -target_link_libraries(LibAudio PRIVATE LibCore LibIPC LibThreading LibUnicode LibCrypto) +target_link_libraries(LibAudio PRIVATE LibCore LibRIFF LibIPC LibThreading LibUnicode LibCrypto) if (HAVE_PULSEAUDIO) target_link_libraries(LibAudio PRIVATE pulse) diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index a5077361a2..b4edfa795b 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -7,7 +7,7 @@ #include "WavLoader.h" #include "LoaderError.h" -#include "RIFFTypes.h" +#include "WavTypes.h" #include #include #include @@ -36,7 +36,7 @@ bool WavLoaderPlugin::sniff(SeekableStream& stream) return false; auto wave = stream.read_value(); - return !wave.is_error() && wave.value() == RIFF::wave_subformat_id; + return !wave.is_error() && wave.value() == Wav::wave_subformat_id; } ErrorOr, LoaderError> WavLoaderPlugin::create(NonnullOwnPtr stream) @@ -191,14 +191,14 @@ MaybeLoaderError WavLoaderPlugin::parse_header() TRY(m_stream->read_value>()); // File size header auto wave = TRY(m_stream->read_value()); - CHECK(wave == RIFF::wave_subformat_id, LoaderError::Category::Format, "WAVE subformat id invalid"); + CHECK(wave == Wav::wave_subformat_id, LoaderError::Category::Format, "WAVE subformat id invalid"); auto format_chunk = TRY(m_stream->read_value()); - CHECK(format_chunk.id.as_ascii_string() == RIFF::format_chunk_id, LoaderError::Category::Format, "FMT chunk id invalid"); + CHECK(format_chunk.id.as_ascii_string() == Wav::format_chunk_id, LoaderError::Category::Format, "FMT chunk id invalid"); auto format_stream = format_chunk.data_stream(); u16 audio_format = TRY(format_stream.read_value>()); - CHECK(audio_format == to_underlying(RIFF::WaveFormat::Pcm) || audio_format == to_underlying(RIFF::WaveFormat::IEEEFloat) || audio_format == to_underlying(RIFF::WaveFormat::Extensible), + CHECK(audio_format == to_underlying(Wav::WaveFormat::Pcm) || audio_format == to_underlying(Wav::WaveFormat::IEEEFloat) || audio_format == to_underlying(Wav::WaveFormat::Extensible), LoaderError::Category::Unimplemented, "Audio format not supported"); m_num_channels = TRY(format_stream.read_value>()); @@ -211,7 +211,7 @@ MaybeLoaderError WavLoaderPlugin::parse_header() u16 bits_per_sample = TRY(format_stream.read_value>()); - if (audio_format == to_underlying(RIFF::WaveFormat::Extensible)) { + if (audio_format == to_underlying(Wav::WaveFormat::Extensible)) { CHECK(format_chunk.size == 40, LoaderError::Category::Format, "Extensible fmt size is not 40 bytes"); // Discard everything until the GUID. @@ -220,12 +220,12 @@ MaybeLoaderError WavLoaderPlugin::parse_header() // Get the underlying audio format from the first two bytes of GUID u16 guid_subformat = TRY(format_stream.read_value>()); - CHECK(guid_subformat == to_underlying(RIFF::WaveFormat::Pcm) || guid_subformat == to_underlying(RIFF::WaveFormat::IEEEFloat), LoaderError::Category::Unimplemented, "GUID SubFormat not supported"); + CHECK(guid_subformat == to_underlying(Wav::WaveFormat::Pcm) || guid_subformat == to_underlying(Wav::WaveFormat::IEEEFloat), LoaderError::Category::Unimplemented, "GUID SubFormat not supported"); audio_format = guid_subformat; } - if (audio_format == to_underlying(RIFF::WaveFormat::Pcm)) { + if (audio_format == to_underlying(Wav::WaveFormat::Pcm)) { CHECK(bits_per_sample == 8 || bits_per_sample == 16 || bits_per_sample == 24, LoaderError::Category::Unimplemented, "PCM bits per sample not supported"); // We only support 8-24 bit audio right now because other formats are uncommon @@ -236,7 +236,7 @@ MaybeLoaderError WavLoaderPlugin::parse_header() } else if (bits_per_sample == 24) { m_sample_format = PcmSampleFormat::Int24; } - } else if (audio_format == to_underlying(RIFF::WaveFormat::IEEEFloat)) { + } else if (audio_format == to_underlying(Wav::WaveFormat::IEEEFloat)) { CHECK(bits_per_sample == 32 || bits_per_sample == 64, LoaderError::Category::Unimplemented, "Float bits per sample not supported"); // Again, only the common 32 and 64 bit @@ -256,7 +256,7 @@ MaybeLoaderError WavLoaderPlugin::parse_header() bool found_data = false; while (!found_data) { auto chunk_header = TRY(m_stream->read_value()); - if (chunk_header == RIFF::data_chunk_id) { + if (chunk_header == Wav::data_chunk_id) { found_data = true; } else { TRY(m_stream->seek(-RIFF::chunk_id_size, SeekMode::FromCurrentPosition)); @@ -269,7 +269,7 @@ MaybeLoaderError WavLoaderPlugin::parse_header() } auto list = maybe_list.release_value(); - if (list.type == RIFF::info_chunk_id) { + if (list.type == Wav::info_chunk_id) { auto maybe_error = load_wav_info_block(move(list.chunks)); if (maybe_error.is_error()) dbgln("WAV Warning: INFO chunk invalid, error: {}", maybe_error.release_error()); diff --git a/Userland/Libraries/LibAudio/WavLoader.h b/Userland/Libraries/LibAudio/WavLoader.h index 1a06c8c08c..d6dfa1a41c 100644 --- a/Userland/Libraries/LibAudio/WavLoader.h +++ b/Userland/Libraries/LibAudio/WavLoader.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace Audio { diff --git a/Userland/Libraries/LibAudio/WavTypes.h b/Userland/Libraries/LibAudio/WavTypes.h new file mode 100644 index 0000000000..cdef737108 --- /dev/null +++ b/Userland/Libraries/LibAudio/WavTypes.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Audio::Wav { + +static constexpr StringView const wave_subformat_id = "WAVE"sv; +static constexpr StringView const data_chunk_id = "data"sv; +static constexpr StringView const info_chunk_id = "INFO"sv; +static constexpr StringView const format_chunk_id = "fmt "sv; + +// Constants for handling WAVE header data. +enum class WaveFormat : u32 { + Pcm = 0x0001, // WAVE_FORMAT_PCM + IEEEFloat = 0x0003, // WAVE_FORMAT_IEEE_FLOAT + ALaw = 0x0006, // 8-bit ITU-T G.711 A-law + MuLaw = 0x0007, // 8-bit ITU-T G.711 µ-law + Extensible = 0xFFFE, // Determined by SubFormat +}; + +} diff --git a/Userland/Libraries/LibAudio/WavWriter.cpp b/Userland/Libraries/LibAudio/WavWriter.cpp index 4999b6a9e6..89bdb1a998 100644 --- a/Userland/Libraries/LibAudio/WavWriter.cpp +++ b/Userland/Libraries/LibAudio/WavWriter.cpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace Audio { @@ -111,7 +112,7 @@ ErrorOr WavWriter::write_header() static u32 fmt_size = 16; TRY(m_file->write_value(fmt_size)); - static u16 audio_format = to_underlying(RIFF::WaveFormat::Pcm); + static u16 audio_format = to_underlying(Wav::WaveFormat::Pcm); TRY(m_file->write_value(audio_format)); TRY(m_file->write_value(m_num_channels)); diff --git a/Userland/Libraries/LibRIFF/CMakeLists.txt b/Userland/Libraries/LibRIFF/CMakeLists.txt new file mode 100644 index 0000000000..4a13da1b6c --- /dev/null +++ b/Userland/Libraries/LibRIFF/CMakeLists.txt @@ -0,0 +1,6 @@ +set(SOURCES + Types.cpp +) + +serenity_lib(LibRIFF riff) +target_link_libraries(LibRIFF PRIVATE LibCore) diff --git a/Userland/Libraries/LibAudio/RIFFTypes.cpp b/Userland/Libraries/LibRIFF/Types.cpp similarity index 97% rename from Userland/Libraries/LibAudio/RIFFTypes.cpp rename to Userland/Libraries/LibRIFF/Types.cpp index b1cf1daf95..03002e8225 100644 --- a/Userland/Libraries/LibAudio/RIFFTypes.cpp +++ b/Userland/Libraries/LibRIFF/Types.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "RIFFTypes.h" +#include "Types.h" #include #include #include #include -namespace Audio::RIFF { +namespace RIFF { ErrorOr ChunkID::read_from_stream(Stream& stream) { diff --git a/Userland/Libraries/LibAudio/RIFFTypes.h b/Userland/Libraries/LibRIFF/Types.h similarity index 64% rename from Userland/Libraries/LibAudio/RIFFTypes.h rename to Userland/Libraries/LibRIFF/Types.h index e2c54b37e8..b17829dd89 100644 --- a/Userland/Libraries/LibAudio/RIFFTypes.h +++ b/Userland/Libraries/LibRIFF/Types.h @@ -12,24 +12,10 @@ #include #include -// RIFF-specific type definitions necessary for handling WAVE files. -namespace Audio::RIFF { +namespace RIFF { static constexpr StringView const riff_magic = "RIFF"sv; -static constexpr StringView const wave_subformat_id = "WAVE"sv; -static constexpr StringView const data_chunk_id = "data"sv; static constexpr StringView const list_chunk_id = "LIST"sv; -static constexpr StringView const info_chunk_id = "INFO"sv; -static constexpr StringView const format_chunk_id = "fmt "sv; - -// Constants for handling WAVE header data. -enum class WaveFormat : u32 { - Pcm = 0x0001, // WAVE_FORMAT_PCM - IEEEFloat = 0x0003, // WAVE_FORMAT_IEEE_FLOAT - ALaw = 0x0006, // 8-bit ITU-T G.711 A-law - MuLaw = 0x0007, // 8-bit ITU-T G.711 µ-law - Extensible = 0xFFFE, // Determined by SubFormat -}; static constexpr size_t const chunk_id_size = 4;