### Install JACK and Example Tools Source: https://mu.krj.st/notes/jack_freebsd.html Installs the JACK audio connection kit and example tools using the FreeBSD package manager. ```bash $ pkg install audio/jack audio/jack-example-tools ``` -------------------------------- ### Start JACK server (OSS driver) Source: https://mu.krj.st/notes/jack_freebsd.html Starts the JACK audio server using the OSS driver. Recommended for basic setup. ```bash $ jackd -r -doss ``` -------------------------------- ### Install JACK and Dependencies on macOS Source: https://mu.krj.st/notes/jack_macos.html Installs the JACK audio server, qjackctl GUI, and pkg-config using Homebrew. Ensure Homebrew is installed first. ```bash $ brew install jack qjackctl pkg-config ``` -------------------------------- ### Install JACK on Arch-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs JACK2 and example tools on Arch-based systems. Ensure your user is added to the 'audio' and 'realtime' groups for proper functionality. ```bash $ pacman -S jack2 jack-example-tools realtime-privileges ``` ```bash $ usermod -aG audio,realtime $USER ``` -------------------------------- ### Command-line Execution Example Source: https://mu.krj.st/ext Example of how to run the LADSPA host from the command line, specifying the plugin file as an argument. ```bash $ ./host ./sinosc.so ``` -------------------------------- ### Configure Automatic Module Loading Source: https://mu.krj.st/osc_i/joystick.txt Example configuration for automatic module loading based on device types. Tailor these aliases and options to your specific hardware setup. ```bash alias tty-ldisc-2 serport alias char-major-13 input above input joydev ns558 analog options analog map=gamepad,none,2btn ``` -------------------------------- ### Install QJackCtl Source: https://mu.krj.st/notes/jack_freebsd.html Installs QJackCtl, a graphical front-end for the JACK server, using the FreeBSD package manager. ```bash $ pkg install qjackctl ``` -------------------------------- ### Start JACK server with specific parameters Source: https://mu.krj.st/notes/jack_freebsd.html Starts the JACK server with specified sampling rate and buffer size using the OSS driver. ```bash $ jackd -r -doss -r48000 -p1024 ``` -------------------------------- ### Install pkg-config Source: https://mu.krj.st/notes/jack_freebsd.html Installs the pkg-config utility, which is necessary for compiling JACK programs. ```bash $ pkg install pkgconf ``` -------------------------------- ### Example Device Output Source: https://mu.krj.st/notes/pipewire_linux.html Sample output from 'pw-cli list-objects Device', showing device details including 'device.name'. ```text id 43, type PipeWire:Interface:Device/3 object.serial = "45" factory.id = "14" client.id = "34" device.api = "alsa" device.description = "Built-in Audio" device.name = "alsa_card.pci-0000_00_1f.3" device.nick = "HDA Intel PCH" media.class = "Audio/Device" id 77, type PipeWire:Interface:Device/3 object.serial = "34705" factory.id = "14" client.id = "34" device.api = "alsa" device.description = "Focusrite Scarlett 2i2 2nd Gen" device.name = "alsa_card.usb-Focusrite_Scarlett_2i2_USB-00" device.nick = "Scarlett 2i2 USB" media.class = "Audio/Device" ``` -------------------------------- ### Start Cadence Source: https://mu.krj.st/notes/jack_linux.html Launches the Cadence GUI application. Use this to configure JACK server settings. ```bash $ cadence ``` -------------------------------- ### Start JACK server with ALSA backend Source: https://mu.krj.st/notes/jack_linux.html Starts the JACK audio server using the ALSA backend. This is a basic command; parameters like sample rate and buffer size might need adjustment based on your hardware. ```bash $ jackd -dalsa ``` -------------------------------- ### Start JACK server with specific parameters Source: https://mu.krj.st/notes/jack_linux.html Starts the JACK audio server with specified sample rate (-r) and period size (-p). Adjust these values if the default settings fail. ```bash $ jackd -dalsa -r48000 -p1024 ``` -------------------------------- ### Install PipeWire with JACK compatibility Source: https://mu.krj.st/notes/pipewire_linux.html Installs PipeWire, its JACK compatibility layer, wireplumber for session management, JACK example tools, and privileges for real-time operations. Run this command on Arch Linux. ```bash $ pacman -S pipewire pipewire-jack wireplumber \ jack-example-tools realtime-privileges ``` -------------------------------- ### Install Cadence on Arch-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs Cadence and pulseaudio-jack on Arch-based systems. Ensure you have the necessary permissions. ```bash $ pacman -S cadence pulseaudio-jack ``` -------------------------------- ### Install QJackCtl on Arch-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs QJackCtl and pulseaudio-jack on Arch-based systems. These are required for manual JACK server configuration. ```bash $ pacman -S qjackctl pulseaudio-jack ``` -------------------------------- ### Install QJackCtl on Debian-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs QJackCtl and pulseaudio-module-jack on Debian-based systems. These are necessary for manual JACK server configuration. ```bash $ apt install qjackctl pulseaudio-module-jack ``` -------------------------------- ### Example PulseAudio Sink Output Source: https://mu.krj.st/notes/pipewire_linux.html This is an example output from `pactl list short sinks`, showing available audio output devices and their properties. ```text 54 alsa_output.pci-0000_00_1f.3.analog-stereo PipeWire s32le 2ch 48000Hz SUSPENDED 34706 alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo PipeWire s32le 2ch 48000Hz SUSPENDED ``` -------------------------------- ### Download sine.c example Source: https://mu.krj.st/notes/jack_freebsd.html Downloads the sine.c source file, a test program for JACK, using curl. ```bash $ curl -OL https://mu.krj.st/files/sine.c ``` -------------------------------- ### Install qpwgraph for PipeWire graph visualization Source: https://mu.krj.st/notes/pipewire_linux.html Installs qpwgraph, a graphical interface for PipeWire that supports PipeWire-specific features like video connections, useful for visualizing the audio graph. ```bash $ pacman -S qpwgraph ``` -------------------------------- ### Install JACK on Debian-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs JACK2 and development libraries on Debian-based systems. Add your user to the 'audio' group for necessary permissions. ```bash $ apt install jackd2 libjack-jackd2-dev ``` ```bash $ usermod -aG audio $USER ``` -------------------------------- ### Observe HTTP GET Request Source: https://mu.krj.st/mix This is an example of an HTTP GET request sent by a web browser to a server listening on localhost:80. It requests the root directory. ```http GET / HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Upgrade-Insecure-Requests: 1 ``` -------------------------------- ### Example Node Name Output Source: https://mu.krj.st/notes/pipewire_linux.html Sample output from 'pw-cli list-objects Node | grep node.name', showing various node names. ```text node.name = "alsa_output.pci-0000_00_1f.3.analog-stereo" node.name = "alsa_input.pci-0000_00_1f.3.analog-stereo" node.name = "alsa_input.usb-Focusrite_Scarlett_2i2_USB-00.HiFi__Mic1__source" node.name = "alsa_input.usb-Focusrite_Scarlett_2i2_USB-00.HiFi__Mic1__source.split" node.name = "alsa_input.usb-Focusrite_Scarlett_2i2_USB-00.HiFi__Mic2__source" node.name = "alsa_input.usb-Focusrite_Scarlett_2i2_USB-00.HiFi__Mic2__source.split" node.name = "alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.HiFi__Line1__sink" node.name = "alsa_input.hw_USB_0" ``` -------------------------------- ### Example Ratio to Pole Calculation Source: https://mu.krj.st/adsr An example demonstrating the usage of the ratio2pole function with specific time and ratio values. The output represents the calculated pole. ```python ratio2pole(1, 0.001/1.001) ``` -------------------------------- ### Start JACK server with doas (root privileges) Source: https://mu.krj.st/notes/jack_freebsd.html Starts the JACK server with root privileges using 'doas' for improved real-time performance. ```bash $ doas jackd -doss ``` -------------------------------- ### Configure JACK Build Source: https://mu.krj.st/notes/jack_win.html Configure the JACK build process using the waf build system. Specify the installation prefix and check for GCC and G++ compilers. Ensure the prefix is set to MINGW_PREFIX for proper installation within the MinGW environment. ```bash $ ./waf configure \ --prefix=${MINGW_PREFIX} \ --check-c-compiler=gcc \ --check-cxx-compiler=g++ ``` -------------------------------- ### Initialize and Execute FFTW DFT Source: https://mu.krj.st/spectrm Initializes FFTW, populates input data, executes the DFT, and cleans up resources. Ensure FFTW is installed and linked. ```c #include #define N 16 static fftw_complex *in, *out; static fftw_plan p; void fftw_init(void) { in = fftw_alloc_complex(N); out = fftw_alloc_complex(N); p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); } void fftw_finish(void) { fftw_destroy_plan(p); fftw_free(in); fftw_free(out); } int main(void) { fftw_init(); // populate in fftw_execute(p); // use out fftw_finish(); return 0; } ``` -------------------------------- ### Install JACK Dependencies on MSYS2 Source: https://mu.krj.st/notes/jack_win.html Install essential dependencies for compiling JACK on MSYS2, including the MinGW-w64 toolchain, Python, and Git. Ensure these are installed before proceeding with JACK compilation. ```bash $ pacman -S mingw-w64-x86_64-toolchain python git ``` -------------------------------- ### Install JACK Source: https://mu.krj.st/notes/jack_win.html Install the compiled JACK components into the specified prefix. This command makes JACK available for use in your MSYS2/MinGW environment. ```bash $ ./waf install ``` -------------------------------- ### Complete FFTW DFT Example Source: https://mu.krj.st/spectrm A complete program demonstrating FFTW usage, including initialization, populating data, executing DFT, printing results, and cleanup. ```c void fftw_init(void) { in = fftw_alloc_complex(N); out = fftw_alloc_complex(N); p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); } void populate(void) { size_t n; for (n = 0; n < N; ++n) { in[n][0] = n/(double)N; in[n][1] = 0; } } void print_result(void) { size_t k; for (k = 0; k < N; ++k) { double re, im; re = out[k][0] / N; // <- normalization optional here im = out[k][1] / N; printf("%f\n", re*re + im*im); } } void fftw_finish(void) { fftw_destroy_plan(p); fftw_free(in); fftw_free(out); } int main(void) { fftw_init(); populate(); fftw_execute(p); print_result(); fftw_finish(); return 0; } ``` -------------------------------- ### Install Cadence on Debian-based systems Source: https://mu.krj.st/notes/jack_linux.html Installs Cadence and pulseaudio-jack on Debian-based systems. This involves adding a repository and updating package lists. ```bash $ sudo apt-get install apt-transport-https gpgv $ wget https://launchpad.net/~kxstudio-debian/+archive/kxstudio/+files/kxstudio-repos_10.0.3_all.deb $ sudo dpkg -i kxstudio-repos_10.0.3_all.deb $ apt update $ apt install pulseaudio-module-jack cadence ``` -------------------------------- ### Initialize liblo Server Source: https://mu.krj.st/mix Initializes the liblo server thread, sets up a handler for the /vol OSC message, and starts the server. ```c static char *port = "10000"; static lo_server_thread st = NULL; static void lo_init(void) { st = lo_server_thread_new(port, NULL); lo_server_thread_add_method(st, "/vol", "f", on_message, NULL); lo_server_thread_start(st); } ``` -------------------------------- ### Start UDP Server with Netcat Source: https://mu.krj.st/mix Start a UDP server using netcat, listening on port 10000. This is used to receive OSC messages, which are typically sent over UDP. ```bash $ nc -lup 10000 ``` -------------------------------- ### Cubic Scaling Example in Julia Source: https://mu.krj.st/mix This example demonstrates how to apply cubic scaling to a linear range and convert it to decibels. It uses a pipeline of functions to transform the data. ```julia 0:0.025:1 .|> (x -> x^3) .|> lin2db |> reverse .|> println; ``` -------------------------------- ### Start TCP Server with Netcat Source: https://mu.krj.st/mix Use netcat to start a TCP server listening on port 80. This is useful for observing HTTP requests from a web browser. You might need sudo to bind to ports below 1024. ```bash $ nc -lp 80 ``` -------------------------------- ### Control Rate Calculation Example Source: https://mu.krj.st/ctrl This example shows the calculation for control rate (kr) based on sampling rate (sr) and block size (nframes). It illustrates how to determine the frequency of parameter updates. ```plaintext kr = sr / nframes ``` -------------------------------- ### Compiling and Running Linear Interpolation Example Source: https://mu.krj.st/denormal Compiles and executes the C code that demonstrates potential numerical issues with floating-point linear interpolation. ```bash $ gcc float5.c && ./a.out ``` -------------------------------- ### Configure Spectrm Project Source: https://mu.krj.st/assignments/spectrm_s.html Run this command in the terminal to configure the spectrm project before compilation. Ensure all dependencies are installed. ```bash ./configure ``` -------------------------------- ### Download Sine Wave Test File Source: https://mu.krj.st/notes/jack_win.html Download the 'sine.c' source file using curl. This C program is used to test the JACK installation by generating a sine wave audio output. ```bash $ curl -OL https://mu.krj.st/files/sine.c ``` -------------------------------- ### Switch JACK Server Master Source: https://mu.krj.st/osc_i This command-line example shows how to switch the JACK server's master clock using `jack_control`. This is an external command and not part of the C code. ```bash $ jack_control sm ``` -------------------------------- ### Start OSC server thread with liblo Source: https://mu.krj.st/mix Initialize a liblo server thread to listen on a specific port and register a handler for incoming OSC messages with a given address pattern and type tag. ```c #include lo_server_thread st = lo_server_thread_new("10000", NULL); lo_server_thread_add_method(st, "/vol", "f", handler, NULL); lo_server_thread_start(st); ``` -------------------------------- ### Display Local IP Addresses Source: https://mu.krj.st/mix Example output from the 'ip addr' command, showing various IP addresses including the loopback address (127.0.0.1) and a dynamic global IP address. ```text inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host inet 10.104.18.213/20 brd 10.105.31.255 scope global dynamic noprefixroute wlp2s0 ``` -------------------------------- ### Main Program Loop Source: https://mu.krj.st/mix Initializes liblo and JACK, waits for user input, then cleans up JACK and liblo. ```c int main(void) { lo_init(); jack_init(); /* idle main thread */ getchar(); jack_finish(); lo_finish(); return 0; } ``` -------------------------------- ### LADSPA Host Main Function Source: https://mu.krj.st/ext Initializes the LADSPA host by loading a plugin, initializing JACK, activating the client, and then idling. Ensure plugin path is provided as an argument. ```c int main(int argc, char *argv[]) { if (argc < 2) { usage(argv[0]); return 1; } plugin_load(argv[1]); jack_init(descriptor->Label); ladspa_init(); jack_activate(client); /* idle main thread */ getchar(); jack_finish(); ladspa_finish(); plugin_unload(); return 0; } ``` -------------------------------- ### Initialize JACK Client Source: https://mu.krj.st/osc_i This function initializes a JACK client, retrieves the sample rate, registers a process callback, registers an output audio port, and activates the client. Ensure the JACK server is running or configured to start. ```c static void jack_init(void) { /* 1. open jack client */ client = jack_client_open("sine", JackNoStartServer, NULL); /* 2. get current sample rate */ sr = jack_get_sample_rate(client); /* 3. register process callback */ jack_set_process_callback(client, on_process, NULL); /* 4. register output audio port */ port_out = jack_port_register(client, "out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); /* 5. activate our client */ jack_activate(client); } ``` -------------------------------- ### Create a host program to load dynamic libraries Source: https://mu.krj.st/ext This C program uses `dlopen`, `dlsym`, and `dlclose` from `dlfcn.h` to load a dynamic library specified by a command-line argument, find and execute the `answer` function, and then unload the library. ```c /* host.c: the host */ #include #include #include int answer(void); typedef int (*answer_fn)(void); int main(int argc, char *argv[]) { answer_fn f; void *handle; if (argc < 2) return 1; handle = dlopen(argv[1], RTLD_NOW); f = dlsym(handle, "answer"); printf("%d\n", f()); dlclose(handle); return 0; } ``` -------------------------------- ### Install LADSPA Plugin Source: https://mu.krj.st/ext Installs the compiled LADSPA plugin to the system's plugin directory. The exact path may vary depending on your Linux distribution. ```bash $ install -m755 sinosc.so /usr/lib/ladspa ``` -------------------------------- ### Initialize and Run Ring Buffer Test Source: https://mu.krj.st/ctrl Sets up a ring buffer and creates two threads for writing and reading. Ensure compilation with -O2 and -pthread. ```c #define RB_SIZE 1024 static ringbuf *rb; int main(void) { pthread_t t1, t2; rb = rb_init(RB_SIZE); pthread_create(&t1, NULL, th_write, NULL); pthread_create(&t2, NULL, th_read, NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); rb_free(rb); return 0; } ``` -------------------------------- ### Update MSYS2 Package Database Source: https://mu.krj.st/notes/jack_win.html Refresh the package database for MSYS2 and install any available updates using the pacman package manager. This is a prerequisite for installing other packages. ```bash $ pacman -Syu ``` -------------------------------- ### Install ALSA and PulseAudio compatibility layers Source: https://mu.krj.st/notes/pipewire_linux.html Installs optional PipeWire compatibility layers for ALSA and PulseAudio, ensuring seamless integration with applications using these audio systems. ```bash $ pacman -S pipewire-alsa pipewire-pulseaudio ``` -------------------------------- ### Example of MOV instruction with memory dereference Source: https://mu.krj.st/denormal This assembly example demonstrates the `mov` instruction, contrasting it with `lea` by showing how it dereferences a memory address to load a value into a register. ```assembly mov rax, [1234] ; rax = *1234 ``` -------------------------------- ### Example of LEA instruction for immediate value Source: https://mu.krj.st/denormal This assembly example shows the `lea` instruction being used to load an immediate (constant) value into a register, highlighting its basic functionality. ```assembly lea rax, [1234] ; rax = 1234 ``` -------------------------------- ### Initialize JACK Client and Register Callback Source: https://mu.krj.st/files/sine.c This C code snippet initializes a JACK client, sets up a shutdown callback, and registers the audio processing callback. Ensure the JACK server is running before executing. ```c #include #include #include #include #include #include #define PI_F 3.14159265f static jack_client_t *client = NULL; static jack_port_t *port_out = NULL; static volatile int done = 0; static void die(const char *msg) { fprintf(stderr, "[error] %s\n", msg); if (client) jack_client_close(client); exit(EXIT_FAILURE); } static void info(const char *msg) { fprintf(stderr, "[info] %s\n", msg); } static void on_shutdown(void *arg) { client = NULL; die("jack server is down, exiting..."); } static void on_signal(int signum) { done = 1; } static int on_process(jack_nframes_t nframes, void *arg) { static float phs = 0; jack_default_audio_sample_t *out; jack_nframes_t i; out = jack_port_get_buffer(port_out, nframes); for (i = 0; i < nframes; ++i) { out[i] = 0.1f * sinf(2*PI_F*phs); phs += 0.01f; while (phs >= 1) phs--; } return 0; } int main(void) { const char **ports; client = jack_client_open("sine", JackNoStartServer, NULL); if (!client) die("fail to open client"); info("jack client opened"); jack_on_shutdown(client, on_shutdown, NULL); info("shutdown callback registered"); if (jack_set_process_callback(client, on_process, NULL)) die("fail to set up process callback"); info("process callback registered"); port_out = jack_port_register(client, "out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (!port_out) die("fail to register audio output port"); info("output port registered"); if (jack_activate(client)) die("fail to activate client"); info("jack client activated"); ports = jack_get_ports(client, NULL, NULL, JackPortIsInput|JackPortIsPhysical); if (ports) { int i; for (i = 0; ports[i]; ++i) jack_connect(client, jack_port_name(port_out), ports[i]); jack_free(ports); } signal(SIGINT, on_signal); signal(SIGTERM, on_signal); #ifndef _WIN32 signal(SIGQUIT, on_signal); signal(SIGHUP, on_signal); #endif info("done! press ctrl-c to exit"); while (!done) sleep(1); jack_deactivate(client); jack_client_close(client); return 0; } ``` -------------------------------- ### Launch QJackCtl Source: https://mu.krj.st/notes/jack_freebsd.html Launches the QJackCtl graphical interface for managing the JACK server. ```bash $ qjackctl ``` -------------------------------- ### Initialize JACK and Register Audio Ports Source: https://mu.krj.st/ext Initializes the JACK client, sets the process callback, and registers audio input/output ports based on the LADSPA descriptor. Memory is allocated for port pointers. ```c static jack_client_t *client; static size_t nports_in, nports_out; static jack_port_t **ports_in, **ports_out; static jack_nframes_t sr; static void jack_init(const char *name) { size_t i; size_t n_in = 0, n_out = 0; const LADSPA_PortDescriptor *ports = descriptor->PortDescriptors; client = jack_client_open(name, JackNoStartServer, NULL); jack_set_process_callback(client, on_process, NULL); sr = jack_get_sample_rate(client); /* 1. count # input/output audio ports */ for (i = 0; i < descriptor->PortCount; ++i) { if (!LADSPA_IS_PORT_AUDIO(ports[i])) continue; if (LADSPA_IS_PORT_INPUT(ports[i])) nports_in++; else if (LADSPA_IS_PORT_OUTPUT(ports[i])) nports_out++; } if (nports_in == 0 && nports_out == 0) die("no input or output audio ports"); /* 2. allocate memory to store port pointers */ if (nports_in > 0) { ports_in = calloc(nports_in, sizeof(jack_port_t *)); if (!ports_in) die("fail to allocate input ports"); } if (nports_out > 0) { ports_out = calloc(nports_out, sizeof(jack_port_t *)); if (!ports_out) die("fail to allocate output ports"); } /* 3. register ports to JACK */ for (i = 0; i < descriptor->PortCount; ++i) { if (!LADSPA_IS_PORT_AUDIO(ports[i])) continue; if (LADSPA_IS_PORT_INPUT(ports[i])) ports_in[n_in++] = jack_port_register( client, descriptor->PortNames[i], JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); else if (LADSPA_IS_PORT_OUTPUT(ports[i])) ports_out[n_out++] = jack_port_register( client, descriptor->PortNames[i], JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } } static void jack_finish(void) { jack_deactivate(client); jack_client_close(client); free(ports_in); free(ports_out); } ``` -------------------------------- ### Open qpwgraph for audio graph visualization Source: https://mu.krj.st/notes/pipewire_linux.html Launches the qpwgraph application, which provides a graphical view of the PipeWire audio graph, allowing users to see and manage connections between applications. ```bash $ qpwgraph ``` -------------------------------- ### Observe HTTP GET Request for Specific Path Source: https://mu.krj.st/mix This HTTP GET request is sent when requesting a specific path, such as 'localhost/test'. Note the difference in the first line compared to a root directory request. ```http GET /test HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Upgrade-Insecure-Requests: 1 ``` -------------------------------- ### Control Rate Numerical Example Source: https://mu.krj.st/ctrl This snippet provides a numerical example of control rate calculation, using a sampling rate of 48,000 and a block size of 512, resulting in a control rate of 93.75 Hz. ```plaintext 48000/512 ``` -------------------------------- ### Listing generated WAV files Source: https://mu.krj.st/wave Verify the creation of the output.wav file by listing all .wav files in the current directory. This command confirms that the program successfully generated the audio file. ```bash $ ls *.wav ``` -------------------------------- ### Initialize and Manage SDL for Framebuffer Rendering Source: https://mu.krj.st/spectrm Initializes SDL, creates a window and renderer, and sets up a texture for streaming pixel data. Handles SDL cleanup. ```c static int width, height; static SDL_Window *win; static SDL_Renderer *renderer; static SDL_Texture *texture; void gui_init(void) { SDL_Init(SDL_INIT_VIDEO); SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_ALLOW_HIGHDPI, &win, &renderer); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, width, height); } void gui_finish(void) { SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(win); SDL_Quit(); } ``` -------------------------------- ### Send OSC Volume Command Source: https://mu.krj.st/mix Example command to send an OSC message to set the volume to -6dB. ```bash $ oscsend localhost 10000 /vol f -6 ``` -------------------------------- ### Run the host program with a dynamic library Source: https://mu.krj.st/ext Execute the compiled host program, passing the path to a dynamic library as a command-line argument. The host will load the library and call its `answer` function. ```bash $ ./host ./lib1.so ``` ```bash $ ./host ./lib2.so ``` -------------------------------- ### GUI Frame and Label Drawing Example Source: https://mu.krj.st/spectrm Demonstrates the use of primitive drawing functions (fb_line, fb_rstr, fb_str, fb_cstr) to construct the static parts of a GUI, including an outer frame and various labels with different alignments. ```c /* axis */ fb_line(fb, padx-1, pady, padx+width, pady); fb_line(fb, padx-1, pady+height, padx+width, pady+height); fb_line(fb, padx-1, pady, padx-1, pady+height); fb_line(fb, padx+width, pady, padx+width, pady+height); /* labels */ fb_rstr(fb, padx-4, pady, "0"); fb_rstr(fb, padx-4, pady+height-7, "1"); fb_str(fb, padx-1, pady-12, "20Hz"); /* nyq_str generated dynamically */ fb_rstr(fb, padx+width, pady-12, nyq_str); fb_cstr(fb, padx+width/2, pady/2-4, "freq"); fb_cstr(fb, padx/2, pady+height/2-4, "mag"); ``` -------------------------------- ### Populating WAV Header Source: https://mu.krj.st/wave Prepare and populate the WAV header structure with calculated values for RIFF, FMT, and DATA chunks. This involves using `memcpy` for string identifiers and arithmetic for size and format fields. ```c #include #include struct wav_hdr hdr = {0}; FILE *fp = fopen("output.wav", "wb"); /* RIFF header */ memcpy(&hdr.riff.id, "RIFF", 4); hdr.riff.size = 36 + NSAMPLES*sizeof(sample_t); memcpy(&hdr.riff.type, "WAVE", 4); /* FMT chunk */ memcpy(&hdr.fmt.id, "fmt ", 4); hdr.fmt.size = 16; hdr.fmt.fmt_tag = 1; /* linear PCM */ hdr.fmt.channels = NCHANNELS; hdr.fmt.samples_per_sec = SR; hdr.fmt.bytes_per_sec = NCHANNELS*SR*sizeof(sample_t); hdr.fmt.block_align = NCHANNELS*sizeof(sample_t); hdr.fmt.bits_per_sample = 8*sizeof(sample_t); /* DATA header */ memcpy(&hdr.data.id, "data", 4); hdr.data.size = NSAMPLES*sizeof(sample_t); fwrite(&hdr, sizeof(struct wav_hdr), 1, fp); ``` -------------------------------- ### x86 Assembly Store Instructions Source: https://mu.krj.st/ctrl Example of two store instructions in x86 assembly. On x86, these are not reordered at runtime. ```assembly ; a = eax mov DWORD PTR [rip+0x2eee],eax ; b = 0 mov DWORD PTR [rip+0x2ee0],0x0 ``` -------------------------------- ### Initialize Wavetable (C) Source: https://mu.krj.st/assignments/osc_s.html Initializes a 1D wavetable with sine wave samples. This is a foundational step for wavetable synthesis. ```c #define N 512 static sample_t tbl[N]; static void tbl_init(void) { /* divide [0,1) into N evenly spaced samples */ float step = 1.f / N; for (size_t i = 0; i < N; ++i) tbl[i] = sinf(2*PI_F * i*step); } ``` -------------------------------- ### Get Number of Joystick Axes Source: https://mu.krj.st/osc_i/joystick-api.txt Uses the JSIOCGAXES IOCTL to retrieve the number of axes supported by the joystick device. ```c char number_of_axes; ioctl (fd, JSIOCGAXES, &number_of_axes); ``` -------------------------------- ### 1D Wavetable Interpolation Example Source: https://mu.krj.st/assignments/osc_s.html Illustrates the linear interpolation used in a 1D wavetable, serving as a basis for understanding 2D interpolation. ```c v0 = tbl[i]; v1 = tbl[(i+1) % N]; out = (1-fr)*v0 + fr*v1; ``` -------------------------------- ### Dynamic Linking Function Substitutions Source: https://mu.krj.st/ext Illustrates the necessary substitutions for dynamic linking functions between POSIX systems (like macOS) and Windows. ```c dlopen → LoadLibrary/LoadLibraryEx dlsym → GetProcAddress dlclose → FreeLibrary ``` -------------------------------- ### Joystick Initialization and Event Reading Source: https://mu.krj.st/osc_i/joystick-api.txt Demonstrates how to open a joystick device and read event data. It includes the structure of a joystick event and how to interpret its components. ```APIDOC ## Initialization and Event Reading ### Description This section covers the basic steps to initialize a joystick device and read event data from it. It includes code examples for opening the device and the structure of the `js_event`. ### Method System Calls (open, read) ### Endpoint `/dev/input/jsX` (where X is the joystick number) ### Parameters #### Path Parameters - **jsX** (string) - Required - The specific joystick device file. #### Query Parameters None #### Request Body None ### Request Example ```c #include #include #include int fd = open("/dev/input/js0", O_RDONLY); struct js_event e; read(fd, &e, sizeof(e)); ``` ### Response #### Success Response (200) - **js_event** (struct) - Contains event details. - **time** (unsigned int) - Event timestamp in milliseconds. - **value** (signed short) - Event value (axis position or button state). - **type** (unsigned char) - Event type (button, axis, init). - **number** (unsigned char) - Axis or button number. #### Response Example ```c struct js_event { __u32 time; __s16 value; __u8 type; __u8 number; }; ``` ### Error Handling - `open()` can fail if the device does not exist or permissions are denied. - `read()` can block if the device is opened in blocking mode and no events are available. ``` -------------------------------- ### Get JACK Buffer Size Source: https://mu.krj.st/notes/jack_macos.html Retrieves the current buffer size of the JACK server. This command requires the JACK server to be running. ```bash $ jack_bufsize ``` -------------------------------- ### 64-bit Global Variable Declaration Source: https://mu.krj.st/ctrl Declares a 64-bit unsigned integer variable 'p'. This variable is used in a multithreaded example to demonstrate torn reads. ```c uint64_t p; ``` -------------------------------- ### Link the host program with the dynamic linking library Source: https://mu.krj.st/ext When compiling the host program, link it with `libdl` using the `-ldl` flag to enable dynamic loading functionalities. ```bash $ gcc -o host host.c -ldl ``` -------------------------------- ### Example: Disabling Denormals for Performance (32-bit x86) Source: https://mu.krj.st/denormal Demonstrates using the denormal handling library to disable denormals before a computation loop on a 32-bit x86 system, then restoring the original state. This can significantly improve performance. ```c // disabled_32.c: denormal disabled (32-bit) #include #include #include "denormal.h" #define N 100000000 int main(void) { size_t i; float mem = 2*FLT_MIN; fpcr_t fpcr; fpcr = denormal_disable(); for (i = 0; i < N; ++i) mem = 0.999f * mem; printf("%g\n", mem); denormal_restore(fpcr); return 0; } ``` -------------------------------- ### Compile Sine Oscillator Program Source: https://mu.krj.st/osc_i This command compiles the `sine_simple.c` program, linking against the JACK and math libraries. Ensure you have the JACK development libraries installed. ```bash $ cc sine_simple.c -o sine -ljack -lm ``` -------------------------------- ### Main Thread DFT Input Preparation Source: https://mu.krj.st/spectrm This function runs in the main thread to prepare input for the DFT. It reads samples from the ring buffer, ensuring enough data is available, and then executes the DFT plan. Requires linking with -lfftw3f. ```c #define N 512 #define FFT_SIZE (N*sizeof(sample_t)) static sample_t *fft_in; // note that we are using the float variant of fftw // it needs to be linked with -lfftw3f static fftwf_complex *fft_out; static fftwf_plan fft_plan; static int render(void) { size_t avail; // read data from audio thread avail = rb_read_space(rb); if (avail < FFT_SIZE) return 0; rb_read_advance(rb, avail - FFT_SIZE); if (!rb_read(rb, fft_in, FFT_SIZE)) return 0; // execute fft fftwf_execute(fft_plan); // ... } ``` -------------------------------- ### Initialize Wavetable with Sine Values (Method 1) Source: https://mu.krj.st/osc_ii Initializes a static wavetable array by dividing the range [0,1) into N evenly spaced samples and calculating the sine for each. Ensure PI_F is defined. ```c #define N 512 static sample_t tbl[N]; static void tbl_init(void) { /* divide [0,1) into N evenly spaced samples */ float step = 1.f / N; for (size_t i = 0; i < N; ++i) tbl[i] = sinf(2*PI_F * i*step); } ``` -------------------------------- ### Compile sine.c with JACK flags Source: https://mu.krj.st/notes/jack_linux.html Compiles the sine.c program using gcc, linking against JACK libraries. Ensure pkg-config is available and JACK is installed. ```bash $ gcc sine.c $(pkg-config --cflags --libs jack) -lm ``` -------------------------------- ### C Static Variable Example Source: https://mu.krj.st/osc_i Demonstrates the behavior of static variables in C. A static variable is initialized only once and retains its value across function calls. ```c #include void func(void) { static int x = 0; // `x` is initialized only once across three // calls of `func` and the variable will get // incremented three times after these calls. // The final value of `x` will be 3. x++; printf("%d\n", x); } int main(void) { func(); // prints 1 func(); // prints 2 func(); // prints 3 return 0; } ```