### Integrate libbw64 with CMake Source: https://github.com/ebu/libbw64/blob/master/docs/getting_started.rst Examples showing how to use libbw64 in a project, either by finding an installed package or by adding it as a CMake subproject. ```cmake cmake_minimum_required(VERSION 3.8) project(libbw64_example VERSION 1.0.0 LANGUAGES CXX) find_package(bw64 REQUIRED) add_executable(example example.cpp) target_link_libraries(example PRIVATE bw64) ``` ```cmake cmake_minimum_required(VERSION 3.5) project(libbw64_example VERSION 1.0.0 LANGUAGES CXX) add_subdirectory(submodules/libbw64) add_executable(example example.cpp) target_link_libraries(example PRIVATE bw64) ``` -------------------------------- ### Write BW64 file Source: https://github.com/ebu/libbw64/blob/master/README.md Example showing how to initialize a BW64 writer and stream audio data to a file. ```cpp #include #include #include const unsigned int BLOCK_SIZE = 4096; int main(int argc, char const* argv[]) { if (argc != 2) { std::cout << "usage: " << argv[0] << " [OUTFILE]" << std::endl; exit(1); } auto outFile = bw64::writeFile(argv[1]); std::vector buffer(BLOCK_SIZE); for (int i = 0; i < 100; ++i) { outFile->write(&buffer.front(), BLOCK_SIZE); } return 0; } ``` -------------------------------- ### Integrate libbw64 with CMake Source: https://github.com/ebu/libbw64/blob/master/README.md Examples of how to link libbw64 into a project using CMake, either as an installed package or a subproject. ```cmake cmake_minimum_required(VERSION 3.5) project(libbw64_example VERSION 1.0.0 LANGUAGES CXX) find_package(bw64 REQUIRED) add_executable(example example.cpp) target_link_libraries(example PRIVATE bw64) ``` ```cmake cmake_minimum_required(VERSION 3.5) project(libbw64_example VERSION 1.0.0 LANGUAGES CXX) add_subdirectory(submodules/libbw64) add_executable(example example.cpp) target_link_libraries(example PRIVATE bw64) ``` -------------------------------- ### Manual Compilation and Installation Source: https://github.com/ebu/libbw64/blob/master/docs/getting_started.rst Steps to clone the repository and build the library from source using CMake on Unix-like systems. ```console git clone git@github.com:irt-open-source/libbw64.git cd libbw64 mkdir build && cd build cmake .. make make install ``` -------------------------------- ### Read BW64 file Source: https://github.com/ebu/libbw64/blob/master/README.md Example showing how to open a BW64 file, access its metadata chunks, and read audio data into a buffer. ```cpp #include #include #include const unsigned int BLOCK_SIZE = 4096; int main(int argc, char const* argv[]) { if (argc != 2) { std::cout << "usage: " << argv[0] << " [INFILE]" << std::endl; exit(1); } auto inFile = bw64::readFile(argv[1]); auto axmlChunk = inFile->axmlChunk(); auto chnaChunk = inFile->chnaChunk(); std::vector buffer(BLOCK_SIZE * inFile->channels()); while (!inFile->eof()) { auto readFrames = inFile->read(&buffer[0], BLOCK_SIZE); } return 0; } ``` -------------------------------- ### Package and Install Configuration Source: https://github.com/ebu/libbw64/blob/master/src/CMakeLists.txt Handles the generation of CMake package configuration files and defines installation rules for headers, binaries, and export targets. ```cmake if(BW64_PACKAGE_AND_INSTALL) include(CMakePackageConfigHelpers) configure_package_config_file(${PROJECT_SOURCE_DIR}/config/bw64Config.cmake.in ${PROJECT_BINARY_DIR}/bw64Config.cmake INSTALL_DESTINATION ${INSTALL_CMAKE_DIR} PATH_VARS INSTALL_INCLUDE_DIR INSTALL_LIB_DIR INSTALL_CMAKE_DIR) write_basic_package_version_file(${PROJECT_BINARY_DIR}/bw64ConfigVersion.cmake COMPATIBILITY SameMajorVersion) install(TARGETS bw64 EXPORT bw64Targets LIBRARY DESTINATION "${INSTALL_LIB_DIR}" RUNTIME DESTINATION "${INSTALL_LIB_DIR}" ARCHIVE DESTINATION "${INSTALL_LIB_DIR}") endif() ``` -------------------------------- ### Install libbw64 via Homebrew Source: https://github.com/ebu/libbw64/blob/master/README.md Commands to install the libbw64 library on macOS using the EBU NGA homebrew tap. ```shell brew tap ebu/homebrew-nga brew install libbw64 ``` -------------------------------- ### Copy and Convert Audio Files with BW64 Source: https://context7.com/ebu/libbw64/llms.txt This C++ example demonstrates how to copy audio files using the BW64 library. It reads an input file and writes to an output file, preserving the original format parameters like channels, sample rate, and bit depth. The library handles PCM encoding/decoding transparently. ```cpp #include #include #include int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Usage: " << argv[0] << " input.wav output.wav" << std::endl; return 1; } auto inFile = bw64::readFile(argv[1]); // Create output with same format as input auto outFile = bw64::writeFile( argv[2], inFile->channels(), inFile->sampleRate(), inFile->bitDepth() ); // Copy audio data in blocks const unsigned int BLOCK_SIZE = 4096; std::vector buffer(BLOCK_SIZE * inFile->channels()); while (!inFile->eof()) { auto readFrames = inFile->read(&buffer[0], BLOCK_SIZE); outFile->write(&buffer[0], readFrames); } std::cout << "Copied " << outFile->framesWritten() << " frames" << std::endl; return 0; } ``` -------------------------------- ### Install libbw64 via Homebrew Source: https://github.com/ebu/libbw64/blob/master/docs/getting_started.rst Commands to install the libbw64 library on macOS using the IRT NGA Homebrew tap. ```console brew tap irt-open-source/homebrew-nga brew install libbw64 ``` -------------------------------- ### Write BW64 Files with ADM Metadata Source: https://context7.com/ebu/libbw64/llms.txt This C++ example illustrates how to create BW64 files with embedded AXML and CHNA chunks. It shows the creation of `ChnaChunk` and `AxmlChunk` objects with sample data and then passes them to `bw64::writeFile()`. Metadata chunks are written before the audio data, as recommended. ```cpp #include #include #include int main() { // Create CHNA chunk with audio ID mappings auto chnaChunk = std::make_shared(); // Add AudioId entries (trackIndex is 1-based) chnaChunk->addAudioId(bw64::AudioId( 1, // Track index (1-based) "ATU_00000001", // audioTrackUID (max 12 chars) "AT_00010001_01", // audioTrackFormatID (max 14 chars) "AP_00010001" // audioPackFormatID (max 11 chars) )); chnaChunk->addAudioId(bw64::AudioId( 2, "ATU_00000002", "AT_00010002_01", "AP_00010001" )); // Create AXML chunk with ADM XML content std::string admXml = R"(<\?xml version=\"1.0\" encoding=\"UTF-8\"\?> )"; auto axmlChunk = std::make_shared(admXml); // Create BW64 file with metadata chunks auto outFile = bw64::writeFile( "output_with_adm.wav", 2, // channels 48000, // sample rate 24, // bit depth chnaChunk, // CHNA chunk axmlChunk // AXML chunk ); // Write audio data... std::vector silence(4096 * 2, 0.0f); outFile->write(&silence[0], 4096); outFile->close(); return 0; } ``` -------------------------------- ### Write BW64 Files with bw64::writeFile in C++ Source: https://context7.com/ebu/libbw64/llms.txt Illustrates how to create a new BW64 file for writing using `bw64::writeFile`. The function allows specifying channels, sample rate, and bit depth, with defaults provided. This example demonstrates generating stereo sine wave audio data as interleaved floating-point samples and writing it to the file, which are then automatically encoded to the target bit depth. The code shows how to track frames written and finalize the file by calling `close()`. ```cpp #include #include #include int main() { // Create a stereo 48kHz 24-bit BW64 file auto outFile = bw64::writeFile("output.wav", 2, 48000, 24); // Generate 5 seconds of stereo sine wave const float FREQUENCY = 440.0f; // Hz const float DURATION = 5.0f; // seconds const float PI = 3.14159265358979323846f; const uint32_t BLOCK_SIZE = 512; uint64_t totalFrames = static_cast(DURATION * outFile->sampleRate()); float phase = 0.0f; float phaseIncrement = 2.0f * PI * FREQUENCY / outFile->sampleRate(); std::vector buffer(BLOCK_SIZE * outFile->channels()); while (outFile->framesWritten() < totalFrames) { uint32_t framesToWrite = std::min( static_cast(BLOCK_SIZE), totalFrames - outFile->framesWritten() ); for (uint32_t i = 0; i < framesToWrite; ++i) { float sample = 0.5f * std::sin(phase); // 50% amplitude buffer[i * 2] = sample; // Left channel buffer[i * 2 + 1] = sample; // Right channel phase = std::fmod(phase + phaseIncrement, 2.0f * PI); } // Write interleaved float samples (automatically encoded to PCM) outFile->write(&buffer[0], framesToWrite); } // Query frames written std::cout << "Frames written: " << outFile->framesWritten() << std::endl; // Finalize and close (writes final chunk sizes) outFile->close(); return 0; } ``` -------------------------------- ### Read CHNA Chunk (Channel Allocation) from BW64 File Source: https://context7.com/ebu/libbw64/llms.txt This C++ example demonstrates how to retrieve channel-to-ADM track UID mapping from a BW64 file using the `chnaChunk()` method. It checks for the CHNA chunk's existence and prints information about the number of tracks, UIDs, and details of each audio ID entry, including track index, UID, and format references. ```cpp #include #include int main(int argc, char* argv[]) { auto bw64File = bw64::readFile(argv[1]); // Check for CHNA chunk using fourCC utility if (bw64File->hasChunk(bw64::utils::fourCC("chna"))) { auto chna = bw64File->chnaChunk(); std::cout << "CHNA Chunk Info:" << std::endl; std::cout << " Number of tracks: " << chna->numTracks() << std::endl; std::cout << " Number of UIDs: " << chna->numUids() << std::endl; std::cout << "Audio IDs:" << std::endl; for (const auto& audioId : chna->audioIds()) { std::cout << " Track " << audioId.trackIndex() << ": " << "UID=" << audioId.uid() << ", " << "TrackRef=" << audioId.trackRef() << ", " << "PackRef=" << audioId.packRef() << std::endl; } } return 0; } ``` -------------------------------- ### Read AXML Chunk (ADM Metadata) from BW64 File Source: https://context7.com/ebu/libbw64/llms.txt This C++ example shows how to extract the Audio Definition Model (ADM) XML metadata from a BW64 file using the `axmlChunk()` method. It checks for the presence of the AXML chunk and prints its content to standard output. The extracted XML can be further parsed for structured access to ADM elements. ```cpp #include #include #include int main(int argc, char* argv[]) { auto bw64File = bw64::readFile(argv[1]); // Check if AXML chunk exists if (bw64File->axmlChunk()) { // Get XML content as string std::stringstream xmlStream; bw64File->axmlChunk()->write(xmlStream); std::string admXml = xmlStream.str(); std::cout << "ADM XML Metadata:" << std::endl; std::cout << admXml << std::endl; // The XML can be parsed with libadm or another XML library // for structured access to ADM elements } else { std::cerr << "No axml chunk found in file" << std::endl; } return 0; } ``` -------------------------------- ### Define Interface Library and Include Directories Source: https://github.com/ebu/libbw64/blob/master/src/CMakeLists.txt This snippet creates an interface library named 'bw64' and configures the include directories for both build-time and installation-time environments. ```cmake add_library(bw64 INTERFACE) target_include_directories(bw64 INTERFACE $ $ $ ) ``` -------------------------------- ### Read BW64 File Structure in C++ Source: https://github.com/ebu/libbw64/blob/master/docs/tutorial.rst This snippet shows the basic structure for reading a BW64 file. It initializes the reader, sets up a buffer, and loops to read audio data in blocks. It highlights the channel-interleaved sample format and automatic file closing. ```cpp #include #include const unsigned int BLOCK_SIZE = 4096; int main(int argc, char const* argv[]) { if (argc != 2) { std::cout << "usage: " << argv[0] << " [INFILE]" << std::endl; exit(1); } auto inFile = bw64::readFile(argv[1]); std::vector buffer(BLOCK_SIZE * inFile->channels()); while (!inFile->eof()) { auto readFrames = inFile->read(&buffer[0], BLOCK_SIZE); // TODO: process samples } return 0; } ``` -------------------------------- ### Write BW64 File in C++ Source: https://github.com/ebu/libbw64/blob/master/docs/tutorial.rst This code extends the reading functionality to also write to a BW64 file. It initializes an output file using parameters from the input file and writes the read audio data. It emphasizes the need to include CHNA and AXML chunks and the interleaved sample order for writing. ```cpp #include #include const unsigned int BLOCK_SIZE = 4096; int main(int argc, char const* argv[]) { if (argc != 3) { std::cout << "usage: " << argv[0] << " [INFILE] [OUTFILE]" << std::endl; exit(1); } auto inFile = bw64::readFile(argv[1]); auto outFile = bw64::writeFile(argv[2], inFile->channels(), inFile->sampleRate(), inFile->bitDepth(), inFile->chnaChunk(), inFile->axmlChunk()); std::vector buffer(BLOCK_SIZE * inFile->channels()); while (!inFile->eof()) { auto readFrames = inFile->read(&buffer[0], BLOCK_SIZE); // TODO: process samples outFile->write(&buffer[0], readFrames); } return 0; } ``` -------------------------------- ### Read BW64 Files with bw64::readFile in C++ Source: https://context7.com/ebu/libbw64/llms.txt Demonstrates how to open a BW64/RF64/RIFF-WAVE file for reading using `bw64::readFile`. It shows how to query audio format properties like channels, sample rate, bit depth, and total frames. The code also illustrates reading audio samples in blocks into a float buffer and processing them. The file is automatically closed when the reader object goes out of scope. ```cpp #include #include #include int main() { // Open a BW64 file for reading auto inFile = bw64::readFile("input.wav"); // Query audio format properties std::cout << "Format tag: " << inFile->formatTag() << std::endl; // 1 = PCM std::cout << "Channels: " << inFile->channels() << std::endl; // e.g., 2 std::cout << "Sample rate: " << inFile->sampleRate() << std::endl; // e.g., 48000 std::cout << "Bit depth: " << inFile->bitDepth() << std::endl; // 16, 24, or 32 std::cout << "Total frames: " << inFile->numberOfFrames() << std::endl; std::cout << "Block alignment: " << inFile->blockAlignment() << std::endl; // Read audio samples in blocks const unsigned int BLOCK_SIZE = 4096; std::vector buffer(BLOCK_SIZE * inFile->channels()); while (!inFile->eof()) { // Read returns number of frames actually read uint64_t framesRead = inFile->read(&buffer[0], BLOCK_SIZE); // Process interleaved float samples in range [-1.0, 1.0] for (uint64_t i = 0; i < framesRead * inFile->channels(); ++i) { // buffer[i] contains sample data } } // File is automatically closed when inFile goes out of scope // For explicit error handling, call close() before destruction inFile->close(); return 0; } ``` -------------------------------- ### Build libbw64 manually Source: https://github.com/ebu/libbw64/blob/master/README.md Steps to clone the repository and build the library from source using CMake. ```shell git clone git@github.com:ebu/libbw64.git cd libbw64 mkdir build && cd build cmake .. make make install ``` -------------------------------- ### Manage FormatInfoChunk Specifications Source: https://context7.com/ebu/libbw64/llms.txt Shows how to instantiate and inspect FormatInfoChunk objects for audio format validation. It highlights how the library handles invalid configurations by throwing runtime errors. ```cpp #include #include #include int main() { // Create format chunk directly auto formatChunk = std::make_shared( 2, // channels 96000, // sample rate 24 // bits per sample ); std::cout << "Format chunk properties:" << std::endl; std::cout << " Format tag: " << formatChunk->formatTag() << std::endl; std::cout << " Channel count: " << formatChunk->channelCount() << std::endl; std::cout << " Sample rate: " << formatChunk->sampleRate() << std::endl; std::cout << " Bits per sample: " << formatChunk->bitsPerSample() << std::endl; std::cout << " Block alignment: " << formatChunk->blockAlignment() << std::endl; std::cout << " Bytes per second: " << formatChunk->bytesPerSecond() << std::endl; std::cout << " Chunk size: " << formatChunk->size() << std::endl; // Validation: these will throw std::runtime_error try { // Invalid: 0 channels auto invalid1 = std::make_shared(0, 48000, 24); } catch (const std::runtime_error& e) { std::cout << "Caught: " << e.what() << std::endl; } try { // Invalid: unsupported bit depth auto invalid2 = std::make_shared(2, 48000, 20); } catch (const std::runtime_error& e) { std::cout << "Caught: " << e.what() << std::endl; } return 0; } ``` -------------------------------- ### Configure RF64 Compatibility Mode in libbw64 Source: https://context7.com/ebu/libbw64/llms.txt Demonstrates how to enable the RF64 identifier for large audio files exceeding 4GB. This ensures compatibility with systems that require RF64 headers instead of standard BW64. ```cpp #include #include int main() { auto outFile = bw64::writeFile("large_file.wav", 2, 48000, 24); // Enable RF64 identifier for large files (instead of BW64) outFile->useRf64Id(true); // Write large amount of data... std::vector buffer(4096 * 2, 0.0f); // Write enough data to exceed 4GB for (uint64_t i = 0; i < 1000000; ++i) { outFile->write(&buffer[0], 4096); } // File will use RF64 header if > 4GB, RIFF if <= 4GB std::cout << "Is BW64/RF64 file: " << (outFile->isBw64File() ? "yes" : "no") << std::endl; outFile->close(); return 0; } ``` -------------------------------- ### FourCC Handling and PCM Conversion in C++ Source: https://context7.com/ebu/libbw64/llms.txt Demonstrates the usage of FourCC conversion utilities to convert between string representations and integer IDs, and shows how to encode and decode PCM audio samples between float and 24-bit integer formats. This snippet highlights the independent usability of these helper functions. ```cpp #include #include #include int main() { // FourCC conversion utilities uint32_t chunkId = bw64::utils::fourCC("data"); std::string chunkName = bw64::utils::fourCCToStr(chunkId); std::cout << "Chunk ID: " << chunkId << " = '" << chunkName << "'" << std::endl; // Common chunk IDs std::cout << "Common chunks:" << std::endl; std::cout << " fmt : " << bw64::utils::fourCC("fmt ") << std::endl; std::cout << " data: " << bw64::utils::fourCC("data") << std::endl; std::cout << " axml: " << bw64::utils::fourCC("axml") << std::endl; std::cout << " chna: " << bw64::utils::fourCC("chna") << std::endl; std::cout << " ds64: " << bw64::utils::fourCC("ds64") << std::endl; // Manual PCM encoding/decoding (used internally) std::vector floatSamples = {0.0f, 0.5f, -0.5f, 1.0f, -1.0f}; std::vector pcmBuffer(floatSamples.size() * 3); // 24-bit = 3 bytes // Encode float samples to 24-bit PCM bw64::utils::encodePcmSamples( floatSamples.data(), pcmBuffer.data(), floatSamples.size(), 24 // bits per sample ); // Decode back to float std::vector decoded(floatSamples.size()); bw64::utils::decodePcmSamples( pcmBuffer.data(), decoded.data(), decoded.size(), 24 ); std::cout << "Decoded samples: "; for (float s : decoded) { std::cout << s << " "; } std::cout << std::endl; return 0; } ``` -------------------------------- ### Adjust Gain in BW64 File using C++ Source: https://github.com/ebu/libbw64/blob/master/docs/tutorial.rst This snippet adds signal processing to the BW64 file manipulation. It reads an input file, creates an output file, and applies a gain factor to each audio sample using std::transform before writing to the output. The gain is provided as a command-line argument. ```cpp #include #include #include #include const unsigned int BLOCK_SIZE = 4096; int main(int argc, char const* argv[]) { if (argc != 4) { std::cout << "usage: " << argv[0] << " [INFILE] [OUTFILE] [GAIN]" << std::endl; exit(1); } auto inFile = bw64::readFile(argv[1]); auto outFile = bw64::writeFile(argv[2], inFile->channels(), inFile->sampleRate(), inFile->bitDepth(), inFile->chnaChunk(), inFile->axmlChunk()); std::vector buffer(BLOCK_SIZE * inFile->channels()); float gain = atof(argv[3]); while (!inFile->eof()) { auto readFrames = inFile->read(&buffer[0], BLOCK_SIZE); std::transform(buffer.begin(), buffer.end(), buffer.begin(), [gain](float value) { return value * gain; }); outFile->write(&buffer[0], readFrames); } return 0; } ``` -------------------------------- ### PCM Sample Conversion Source: https://context7.com/ebu/libbw64/llms.txt Provides utilities for encoding and decoding PCM audio samples between floating-point representations and raw byte buffers. ```APIDOC ## PCM Sample Conversion ### Description Functions to encode float samples into PCM buffers or decode PCM buffers back into floating-point arrays. ### Methods - `bw64::utils::encodePcmSamples(const float* src, char* dst, size_t count, int bitsPerSample)` - `bw64::utils::decodePcmSamples(const char* src, float* dst, size_t count, int bitsPerSample)` ### Parameters - **src** (pointer) - Source buffer - **dst** (pointer) - Destination buffer - **count** (size_t) - Number of samples to process - **bitsPerSample** (int) - Bit depth (e.g., 16, 24, 32) ### Request Example ```cpp bw64::utils::encodePcmSamples(floatSamples.data(), pcmBuffer.data(), count, 24); ``` ``` -------------------------------- ### Seek Audio Data in libbw64 Source: https://context7.com/ebu/libbw64/llms.txt Demonstrates random access within audio data using seek() and tell() methods, supporting absolute, relative, and end-of-file positioning. ```cpp #include #include #include int main(int argc, char* argv[]) { auto inFile = bw64::readFile(argv[1]); std::cout << "Total frames: " << inFile->numberOfFrames() << std::endl; uint64_t middleFrame = inFile->numberOfFrames() / 2; inFile->seek(middleFrame, std::ios::beg); std::cout << "Position after seek to middle: " << inFile->tell() << std::endl; std::vector buffer(1024 * inFile->channels()); inFile->read(&buffer[0], 1024); std::cout << "Position after read: " << inFile->tell() << std::endl; inFile->seek(-512, std::ios::cur); std::cout << "Position after relative seek: " << inFile->tell() << std::endl; inFile->seek(-1000, std::ios::end); std::cout << "Position near end: " << inFile->tell() << std::endl; inFile->seek(0, std::ios::end); std::cout << "At EOF: " << (inFile->eof() ? "yes" : "no") << std::endl; return 0; } ``` -------------------------------- ### Instantiate Bw64 Unit Tests (CMake) Source: https://github.com/ebu/libbw64/blob/master/tests/CMakeLists.txt These CMake commands instantiate the `add_bw64_test` function to create specific unit test executables for different components of the Bw64 library, such as 'utils', 'chunk', and 'file'. ```cmake add_bw64_test(utils_tests) add_bw64_test(chunk_tests) add_bw64_test(file_tests) ``` -------------------------------- ### Define Bw64 Unit Test Executable (CMake) Source: https://github.com/ebu/libbw64/blob/master/tests/CMakeLists.txt This CMake function `add_bw64_test` simplifies the creation of unit test executables. It compiles a C++ source file into an executable, links it with the `bw64` library and `catch2` testing framework, sets necessary include directories, and registers it as a CTest test case. ```cmake include(${PROJECT_SOURCE_DIR}/submodules/catch2.cmake) # --- unit tests --- function(add_bw64_test name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} PRIVATE bw64 catch2 ) target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/submodules ) add_test( NAME ${name} COMMAND $ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/test_data" ) endfunction() ``` -------------------------------- ### Append AXML Chunk in libbw64 Source: https://context7.com/ebu/libbw64/llms.txt Shows how to add an AXML metadata chunk to a file after audio data has been written. The chunk is finalized when the file is closed. ```cpp #include #include #include int main() { auto outFile = bw64::writeFile("output.wav", 2, 48000, 24); std::vector buffer(4096 * 2); for (int i = 0; i < 100; ++i) { outFile->write(&buffer[0], 4096); } std::string admXml = "..."; outFile->setAxmlChunk(std::make_shared(admXml)); outFile->close(); return 0; } ``` -------------------------------- ### File Operations API Source: https://github.com/ebu/libbw64/blob/master/docs/reference.rst Functions used to initialize file reading and writing processes in libbw64. ```APIDOC ## bw64::readFile ### Description Opens a BW64 file for reading and returns a Bw64Reader instance. ### Method Function Call ### Parameters #### Arguments - **path** (std::string) - Required - The file system path to the BW64 file. ### Response - **Bw64Reader** (Object) - A reader object configured for the specified file. ``` ```APIDOC ## bw64::writeFile ### Description Creates or opens a BW64 file for writing and returns a Bw64Writer instance. ### Method Function Call ### Parameters #### Arguments - **path** (std::string) - Required - The target file path. - **options** (WriterOptions) - Optional - Configuration for the BW64 writer. ### Response - **Bw64Writer** (Object) - A writer object ready to accept audio data and chunks. ``` -------------------------------- ### Configure C++ Standard Support Source: https://github.com/ebu/libbw64/blob/master/src/CMakeLists.txt Sets the required C++11 features for the library. It handles version-specific CMake logic to ensure compatibility with older CMake versions. ```cmake if ({CMAKE_VERSION} VERSION_LESS "3.8.0") target_compile_features(bw64 INTERFACE cxx_auto_type cxx_nullptr cxx_range_for) else() target_compile_features(bw64 INTERFACE cxx_std_11) endif() ``` -------------------------------- ### Inspect File Chunks in libbw64 Source: https://context7.com/ebu/libbw64/llms.txt Provides a method to list all chunks present in a BW64 file, check for specific chunk types, and identify the file format using fourCC utilities. ```cpp #include #include int main(int argc, char* argv[]) { auto bw64File = bw64::readFile(argv[1]); std::cout << "File format: "; switch (bw64File->fileFormat()) { case bw64::utils::fourCC("RIFF"): std::cout << "RIFF"; break; case bw64::utils::fourCC("BW64"): std::cout << "BW64"; break; case bw64::utils::fourCC("RF64"): std::cout << "RF64"; break; } std::cout << std::endl; std::cout << "Chunks found:" << std::endl; for (const auto& chunk : bw64File->chunks()) { std::cout << " '" << bw64::utils::fourCCToStr(chunk.id) << "' " << "size=" << chunk.size << " " << "position=" << chunk.position << std::endl; } if (bw64File->hasChunk(bw64::utils::fourCC("bext"))) { std::cout << "File contains broadcast extension chunk" << std::endl; } return 0; } ``` -------------------------------- ### Update CHNA Chunk in libbw64 Source: https://context7.com/ebu/libbw64/llms.txt Demonstrates how to set or update the CHNA chunk after a file has been opened and audio writing has commenced. This supports pre-allocated space for up to 1024 UIDs. ```cpp #include #include #include int main() { auto outFile = bw64::writeFile("output.wav", 4, 48000, 24); std::vector buffer(1024 * 4, 0.0f); outFile->write(&buffer[0], 1024); auto chnaChunk = std::make_shared(std::vector{ bw64::AudioId(1, "ATU_00000001", "AT_00010001_01", "AP_00010001"), bw64::AudioId(2, "ATU_00000002", "AT_00010002_01", "AP_00010001"), bw64::AudioId(3, "ATU_00000003", "AT_00010003_01", "AP_00010002"), bw64::AudioId(4, "ATU_00000004", "AT_00010004_01", "AP_00010002") }); outFile->setChnaChunk(chnaChunk); outFile->write(&buffer[0], 1024); outFile->close(); return 0; } ``` -------------------------------- ### Copy Test Data for Unit Tests (CMake) Source: https://github.com/ebu/libbw64/blob/master/tests/CMakeLists.txt This CMake command copies the 'test_data' directory from the current source directory to the binary build directory. This ensures that unit tests, when executed, can access their required data files relative to their running location. ```cmake # copy test files so unit test can find them relative to their running location # when executed as "test" target file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/test_data" DESTINATION ${CMAKE_BINARY_DIR}) ``` -------------------------------- ### FourCC Conversion Utilities Source: https://context7.com/ebu/libbw64/llms.txt Provides methods to convert string-based FourCC identifiers to 32-bit integers and vice versa, essential for identifying RIFF/BW64 chunks. ```APIDOC ## FourCC Conversion Utilities ### Description Helper functions to manage FourCC identifiers used in RIFF/BW64 file structures. ### Methods - `bw64::utils::fourCC(const char* str)`: Converts a 4-character string to a uint32_t. - `bw64::utils::fourCCToStr(uint32_t id)`: Converts a uint32_t identifier back to a string. ### Request Example ```cpp uint32_t chunkId = bw64::utils::fourCC("data"); std::string chunkName = bw64::utils::fourCCToStr(chunkId); ``` ``` -------------------------------- ### Chunk Management API Source: https://github.com/ebu/libbw64/blob/master/docs/reference.rst Classes representing the various metadata and data chunks within a BW64 file structure. ```APIDOC ## Chunk Classes ### Description Base and derived classes for managing file chunks including AXML, CHNA, and Data chunks. ### Classes - **bw64::AxmlChunk** - Handles XML metadata embedded in the file. - **bw64::ChnaChunk** - Manages the Channel Assignment metadata. - **bw64::DataChunk** - Represents the primary audio data section. - **bw64::FormatInfoChunk** - Contains essential format information (sample rate, bit depth, etc.). ### Usage These classes are typically accessed via the Bw64Reader or Bw64Writer instances to inspect or modify file metadata. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.