Convert Figma logo to code with AI

cycfi logoq

C++ Library for Audio Digital Signal Processing

1,149
151
1,149
4

Top Related Projects

7,002

Super-project for modularized Boost

20,408

A modern formatting library

Abseil Common Libraries (C++)

28,056

An open-source C++ library developed and used at Facebook.

23,832

Fast C++ logging library.

42,154

JSON for Modern C++

Quick Overview

Q is a cross-platform C++ library for audio digital signal processing. It provides a collection of efficient and easy-to-use DSP building blocks, designed to be flexible and modular for various audio applications. Q aims to simplify the development of audio software while maintaining high performance.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux)
  • Efficient and optimized DSP algorithms
  • Modular design for easy integration and customization
  • Comprehensive documentation and examples

Cons

  • Steep learning curve for beginners in DSP
  • Limited community support compared to more established audio libraries
  • Requires C++ knowledge, which may not be suitable for all developers
  • Some advanced features may require additional dependencies

Code Examples

  1. Creating a simple sine wave generator:
#include <q/support/literals.hpp>
#include <q/synth/sin.hpp>

using namespace cycfi::q;
using namespace literals;

auto freq = 440_Hz;
auto sps = 44100_Hz;
auto period = sps / freq;

sin_synth sin{freq, sps};
auto y = sin();
  1. Applying a low-pass filter to an audio signal:
#include <q/support/literals.hpp>
#include <q/fx/lowpass.hpp>

using namespace cycfi::q;
using namespace literals;

auto cutoff = 1000_Hz;
auto sps = 44100_Hz;

one_pole_lowpass lp{cutoff, sps};
float sample = 0.5f;
auto filtered_sample = lp(sample);
  1. Creating an envelope generator:
#include <q/support/literals.hpp>
#include <q/envelope/adsr.hpp>

using namespace cycfi::q;
using namespace literals;

auto attack = 10_ms;
auto decay = 100_ms;
auto sustain = 0.7f;
auto release = 200_ms;
auto sps = 44100_Hz;

adsr env{attack, decay, sustain, release, sps};
env.trigger(1.0f);
auto y = env();

Getting Started

  1. Clone the repository:

    git clone https://github.com/cycfi/q.git
    
  2. Include Q in your project:

    #include <q/q.hpp>
    
  3. Link against the Q library in your build system.

  4. Use Q components in your code:

    #include <q/support/literals.hpp>
    #include <q/synth/sin.hpp>
    
    using namespace cycfi::q;
    using namespace literals;
    
    auto freq = 440_Hz;
    auto sps = 44100_Hz;
    sin_synth sin{freq, sps};
    auto sample = sin();
    

Competitor Comparisons

7,002

Super-project for modularized Boost

Pros of Boost

  • Extensive library collection covering a wide range of functionalities
  • Long-standing reputation and widespread adoption in the C++ community
  • Comprehensive documentation and active community support

Cons of Boost

  • Large codebase can lead to longer compilation times
  • Some components may be considered outdated or overly complex
  • Steeper learning curve for beginners due to its vast scope

Code Comparison

Boost example (using Boost.Asio for asynchronous operations):

#include <boost/asio.hpp>

boost::asio::io_context io;
boost::asio::steady_timer timer(io, boost::asio::chrono::seconds(5));
timer.async_wait([](const boost::system::error_code& error) {
    std::cout << "Timer expired!" << std::endl;
});

Q example (using Q's event system):

#include <q/support/literals.hpp>
#include <q/channel.hpp>

auto timer = q::timer<>::create(5_s);
timer->wait([](q::timer_event const& ev) {
    std::cout << "Timer expired!" << std::endl;
});

Both examples demonstrate asynchronous timer functionality, but Q's syntax appears more concise and modern. However, Boost offers a broader range of utilities beyond just asynchronous operations, making it suitable for more diverse project requirements.

20,408

A modern formatting library

Pros of fmt

  • Widely adopted and battle-tested in production environments
  • Extensive documentation and community support
  • Faster compilation times due to simpler implementation

Cons of fmt

  • Limited to string formatting and output
  • Lacks advanced features for complex data manipulation
  • May require additional libraries for more sophisticated text processing

Code Comparison

fmt:

#include <fmt/core.h>

std::string result = fmt::format("Hello, {}!", name);
fmt::print("The answer is {}.", 42);

q:

#include <q/support/literals.hpp>

auto result = "Hello, %1!"_format(name);
print("The answer is %1."_format(42));

Summary

fmt is a popular, well-established library focused on efficient string formatting and output. It offers excellent performance and wide platform support. q, on the other hand, is a more comprehensive library that includes string formatting along with other features like coroutines and signals/slots. While fmt excels in simplicity and speed for basic formatting tasks, q provides a broader set of tools for complex application development, albeit with a steeper learning curve and potentially longer compilation times.

Abseil Common Libraries (C++)

Pros of abseil-cpp

  • Broader scope with a comprehensive set of C++ libraries
  • Backed by Google, ensuring long-term support and updates
  • Extensive documentation and examples

Cons of abseil-cpp

  • Larger codebase, potentially increasing compilation times
  • May include unnecessary features for projects with specific needs
  • Steeper learning curve due to its extensive API

Code Comparison

q:

auto c = channel<int>{};
c.send(42);
int result;
c.receive(result);

abseil-cpp:

absl::Notification done;
absl::BlockingQueue<int> queue;
queue.Push(42);
int result = queue.Pop();
done.Notify();

Summary

q focuses on lightweight, composable concurrency primitives, while abseil-cpp offers a broader set of C++ utilities. q may be more suitable for projects requiring specific concurrency features, whereas abseil-cpp provides a comprehensive toolkit for various C++ development needs. The choice between them depends on project requirements, team familiarity, and desired feature set.

28,056

An open-source C++ library developed and used at Facebook.

Pros of Folly

  • Extensive library with a wide range of utilities and components
  • Backed by Facebook, ensuring active maintenance and updates
  • Well-documented with comprehensive examples and use cases

Cons of Folly

  • Large codebase, which may increase compilation times and binary size
  • Steeper learning curve due to its extensive feature set
  • May include unnecessary components for smaller projects

Code Comparison

Folly (using folly::Optional):

#include <folly/Optional.h>

folly::Optional<int> maybeGetValue() {
  if (condition)
    return 42;
  return folly::none;
}

Q (using q::optional):

#include <q/support/optional.hpp>

q::optional<int> maybeGetValue() {
  if (condition)
    return 42;
  return q::nullopt;
}

Both libraries provide similar functionality for optional values, but Folly's implementation is part of a larger ecosystem, while Q focuses on being lightweight and modular.

23,832

Fast C++ logging library.

Pros of spdlog

  • Wider adoption and more mature project with a larger community
  • Extensive documentation and examples
  • Supports various logging targets (console, file, syslog, etc.)

Cons of spdlog

  • Heavier and more complex than q
  • May have a steeper learning curve for simple use cases

Code Comparison

spdlog:

#include "spdlog/spdlog.h"

int main() {
    spdlog::info("Welcome to spdlog!");
    spdlog::error("Some error message with arg: {}", 1);
}

q:

#include <q/support/logger.hpp>

int main() {
    q::logger::info("Welcome to q!");
    q::logger::error("Some error message with arg: {}", 1);
}

Both libraries offer similar syntax for basic logging operations. spdlog provides more advanced features and configuration options, while q focuses on simplicity and lightweight implementation.

spdlog is better suited for larger projects requiring extensive logging capabilities, whereas q might be preferable for smaller projects or those prioritizing minimal overhead. The choice between the two depends on the specific requirements of your project and the desired balance between features and simplicity.

42,154

JSON for Modern C++

Pros of json

  • Widely adopted and battle-tested JSON library for C++
  • Extensive documentation and community support
  • Header-only library, easy to integrate into projects

Cons of json

  • Focused solely on JSON parsing and manipulation
  • May have higher memory usage for large JSON structures
  • Steeper learning curve for advanced features

Code Comparison

json:

#include <nlohmann/json.hpp>
using json = nlohmann::json;

json j = {
  {"name", "John"},
  {"age", 30},
  {"city", "New York"}
};
std::string serialized = j.dump();

q:

#include <q/support/json.hpp>
namespace json = cycfi::q::json;

json::object obj;
obj["name"] = "John";
obj["age"] = 30;
obj["city"] = "New York";
std::string serialized = json::stringify(obj);

Summary

While json is a specialized JSON library with extensive features, q is a more general-purpose library that includes JSON support among other functionalities. json offers a more comprehensive JSON-specific toolset, while q provides a simpler API for basic JSON operations within a broader framework. The choice between them depends on the project's specific requirements and the developer's familiarity with each library's ecosystem.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Q-Logo Audio DSP Library

CMake Build Matrix

Introduction

Q is a cross-platform C++ library for audio digital signal processing. Q is named after the "Q factor," a dimensionless parameter that describes the quality of a resonant circuit. The Q DSP Library is designed to be simple and elegant, as the simplicity of its name suggests, and efficient enough to run on small microcontrollers.

Q simplifies complex DSP programming tasks without sacrificing readability by leveraging the power of modern C++ and efficient use of functional programming techniques, especially function composition using fine-grained and reusable function objects (both stateless and stateful).

Q is the host of some experimental Music related DSP facilities the author has accumulated over the years as part of research and development, and will continue to evolve to accommodate more facilities necessary for the fulfillment of various Music related projects.

The library is Open Source and released under the very liberal MIT license.

NOTE: The library has now reached version 1.0 and has stabilized. The documentation is in sync with the code in the master branch. Any future changes will be developed in feature branches and merged incrementally to the master branch. The develop branch will cease to exist. The API is now stable, and any changes will be documented accordingly.

Versions will be in separate branches. The master branch will target the latest version. Currently, it targets v1.5, which will be a significant departure from v1.0, when completed. This update includes the retirement of the BACF (bitstream autocorrelation) based pitch detector and the introduction of a new, much better pitch detection algorithm with integrated onset detection.

Overview

The Q library comprises of two layers:

  1. q_io: Audio and MIDI I/O layer. The q_io layer provides cross-platform audio and MIDI host connectivity straight out of the box. The q_io layer is optional. The q_lib layer is usable without it.

  2. q_lib: The core DSP library, q_lib is a no-frills, lightweight, header-only library.

Dependencies

The dependencies are determined by the arrows.

  • q_io has very minimal dependencies (portaudio and portmidi) with very loose coupling via thin wrappers that are easy to transplant and port to a host, with or without an operating system, such as an audio plugin or direct to hardware ADC and DAC.

  • q_io is used in the tests and examples, but can be easily replaced by other mechanisms in an application. DAW (digital audio workstations), for example, have their own audio and MIDI I/O mechanisms.

  • q_lib has no dependencies except the standard c++ library.

The q_io layer provides cross-platform audio and MIDI host connectivity straight out of the box. The q_io layer is optional. The q_lib layer is usable without it. q_io is used in the tests and examples, but can be easily replaced by other mechanisms in an application.

Documentation

About the Author

Joel got into electronics and programming in the 80s because almost everything in music, his first love, is becoming electronic and digital. Since then, he builds his own guitars, effect boxes and synths. He enjoys playing distortion-laden rock guitar, composes and produces his own music in his home studio.

Joel de Guzman is the principal architect and engineer at Cycfi Research. He is a software engineer specializing in advanced C++ and an advocate of Open Source. He has authored a number of highly successful Open Source projects such as Boost.Spirit, Boost.Phoenix and Boost.Fusion. These libraries are all part of the Boost Libraries, a well respected, peer-reviewed, Open Source, collaborative development effort.

Discord

Feel free to join the discord channel for discussion and chat with the developer.

Copyright (c) 2014-2024 Joel de Guzman. All rights reserved. Distributed under the MIT License