### Installation Command for CMAKE Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/paplay/CMakeLists.txt Calls a custom 'my_install' macro to handle the installation of the 'paplay' executable. This abstracts the platform-specific installation steps. ```cmake my_install(paplay) ``` -------------------------------- ### Custom Installation Command (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/distort/CMakeLists.txt Invokes a custom CMake macro named 'my_install' to handle the installation of the 'distort' executable. The specifics of the installation are defined within the 'my_install' macro itself. ```cmake my_install(distort) ``` -------------------------------- ### Custom Install Command (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/listaudevs/CMakeLists.txt Applies a custom installation command named 'my_install' to the 'listaudevs' executable. This likely handles project-specific installation procedures beyond standard CMake targets. ```cmake my_install(listaudevs) ``` -------------------------------- ### Custom Install Rule (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/repitch/CMakeLists.txt Applies a custom installation rule to the 'repitch' target. This is likely a user-defined macro or function (my_install) that handles the installation process for the executable. ```cmake my_install(repitch) ``` -------------------------------- ### Define Executable 'tapdelay' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/reverb/CMakeLists.txt Sets up the 'tapdelay' executable target using 'tdelaymain.cpp', 'reverberator.cpp', and 'wavetable.cpp' as sources. It links against 'sfsys', 'pvxio2', and libraries from 'EXTRA_LIBRARIES'. The 'my_install' command handles its installation. ```cmake add_executable(tapdelay tdelaymain.cpp reverberator.cpp wavetable.cpp) target_link_libraries(tapdelay sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(tapdelay) ``` -------------------------------- ### Custom Installation Command Source: https://github.com/composersdesktop/cdp8/blob/main/dev/texture/CMakeLists.txt Applies a custom installation rule to the 'texture' executable target, likely defined elsewhere in the build system. ```cmake my_install(texture) ``` -------------------------------- ### Define Executables and Link Libraries Source: https://github.com/composersdesktop/cdp8/blob/main/dev/standnew/CMakeLists.txt Defines various executables for the project, specifying their source files and the libraries they depend on. Each executable is then processed by a custom 'my_install' command. This snippet covers the common pattern of building and installing multiple tools. ```cmake add_executable(asciiget asciiget.c) target_link_libraries(asciiget ${EXTRA_LIBRARIES}) my_install(asciiget) add_executable(caltrain caltrain.c) target_link_libraries(caltrain cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(caltrain) add_executable(clicknew clicknew.c) target_link_libraries(clicknew cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(clicknew) add_executable(clip clip.c) target_link_libraries(clip cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(clip) add_executable(convert_to_midi convert_to_midi.c) target_link_libraries(convert_to_midi ${EXTRA_LIBRARIES}) my_install(convert_to_midi) add_executable(distcut distcut.c) target_link_libraries(distcut cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(distcut) add_executable(distmark distmark.c) target_link_libraries(distmark cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(distmark) add_executable(distmore distmore.c) target_link_libraries(distmore cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(distmore) add_executable(distrep distrep.c) target_link_libraries(distrep cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(distrep) add_executable(distshift distshift.c) target_link_libraries(distshift cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(distshift) # OUT? # add_executable(distwarp distwarp.c) # target_link_libraries(distwarp cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) # my_install(distwarp) add_executable(envcut envcut.c) target_link_libraries(envcut cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(envcut) # add_executable(envnu_other envnu_other.c) # target_link_libraries(envnu_other cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) # my_install(envnu_other) add_executable(envspeak envspeak.c) target_link_libraries(envspeak cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(envspeak) #waiting for code fix from TW #add_executable(extspeak extspeak.c) #target_link_libraries(extspeak cdp2k sfsys pvxio2 aaio ${EXTRA_LIBRARIES}) #my_install(extspeak) add_executable(fractal fractal.c) target_link_libraries(fractal cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(fractal) # OUT ? add_executable(fturanal fturanal.c) target_link_libraries(fturanal cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(fturanal) # headview.c ? add_executable(hover2 hover2.c) target_link_libraries(hover2 cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(hover2) # OUT (too many problems, undeclared variables) # add_executable(integrate integrate.c) # target_link_libraries(integrate ${EXTRA_LIBRARIES}) # my_install(integrate) add_executable(onset onset.c) target_link_libraries(onset cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(onset) add_executable(pairex pairex.c) target_link_libraries(pairex cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(pairex) add_executable(partition partition.c) target_link_libraries(partition cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(partition) add_executable(phasor phasor.c) target_link_libraries(phasor cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(phasor) add_executable(quirk quirk.c) target_link_libraries(quirk cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(quirk) add_executable(repair repair.c) target_link_libraries(repair cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(repair) #add_executable(rotate rotate.c) #target_link_libraries(rotate ${EXTRA_LIBRARIES}) #my_install(rotate) # scales.c ignore: just textual exploratory comments add_executable(specenv specenv.c) target_link_libraries(specenv cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(specenv) add_executable(speculate speculation.c) target_link_libraries(speculate cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(speculate) add_executable(spike spike.c) target_link_libraries(spike cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(spike) # OUT (ID 'SUPERLOOP' not found) # add_executable(superloop superloop.c) # target_link_libraries(superloop cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) # my_install(superloop) add_executable(suppress suppress.c) target_link_libraries(suppress cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(suppress) # excluded by TW (standalone.h) # add_executable(toptail toptail.c) # target_link_libraries(toptail cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) # my_install(toptail) add_executable(tostereo tostereo.c) target_link_libraries(tostereo cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(tostereo) add_executable(matrix unitary_matrix.c) target_link_libraries(matrix cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(matrix) ``` -------------------------------- ### CPack Installer Configuration (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/CMakeLists.txt Configures CPack to build an installer package for the project, setting package name, license file, and version information. ```cmake set (CPACK_PACKAGE_NAME "cdp") set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") set (CPACK_PACKAGE_VERSION "8.0.1") set (CPACK_PACKAGE_VERSION_MAJOR "8") set (CPACK_PACKAGE_VERSION_MINOR "0") set (CPACK_PACKAGE_VERSION_PATCH "1") include (CPack) ``` -------------------------------- ### Define Executable 'reverb' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/reverb/CMakeLists.txt Defines the 'reverb' executable target. It compiles 'reverb.cpp', 'reverberator.cpp', and 'wavetable.cpp'. The executable is linked with 'portsf', 'sfsys', 'pvxio2', and custom libraries from 'EXTRA_LIBRARIES'. It's then installed via 'my_install'. ```cmake add_executable(reverb reverb.cpp reverberator.cpp wavetable.cpp) target_link_libraries(reverb portsf sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(reverb) ``` -------------------------------- ### Install CMake on macOS Source: https://github.com/composersdesktop/cdp8/blob/main/building.txt Installs CMake on macOS using the Homebrew package manager. CMake is a cross-platform build system generator. ```bash brew install cmake ``` -------------------------------- ### CMake: Add Executable and Link Libraries Source: https://github.com/composersdesktop/cdp8/blob/main/dev/science/CMakeLists.txt This snippet shows how to define an executable in CMake, specifying its source file and the libraries it needs to link against. Dependencies include cdp2k, sfsys, pvxio2, and potentially EXTRA_LIBRARIES. The my_install command is used for post-build installation. ```cmake add_executable(flatten flatten.c) target_link_libraries(flatten cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(flatten) ``` ```cmake add_executable(impulse impulse.c) target_link_libraries(impulse cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(impulse) ``` ```cmake add_executable(motor motor.c) target_link_libraries(motor cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(motor) ``` ```cmake add_executable(multiosc multiosc.c) target_link_libraries(multiosc cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(multiosc) ``` ```cmake add_executable(multisynth multisynth.c) target_link_libraries(multisynth cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(multisynth) ``` ```cmake add_executable(newscales newscales.c) target_link_libraries(newscales cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(newscales) ``` ```cmake add_executable(notchinvert notchinvert.c) target_link_libraries(notchinvert cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(notchinvert) ``` ```cmake add_executable(peakiso peakiso.c) target_link_libraries(peakiso cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(peakiso) ``` ```cmake add_executable(pulser pulser.c) target_link_libraries(pulser cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(pulser) ``` ```cmake add_executable(refocus refocus.c) target_link_libraries(refocus cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(refocus) ``` ```cmake add_executable(repeater repeater.c) target_link_libraries(repeater cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(repeater) ``` ```cmake add_executable(rotor rotor.c) target_link_libraries(rotor cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(rotor) ``` ```cmake add_executable(scramble scramble.c) target_link_libraries(scramble cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(scramble) ``` ```cmake add_executable(smooth smooth.c) target_link_libraries(smooth cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(smooth) ``` ```cmake add_executable(sorter sorter.c) target_link_libraries(sorter cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(sorter) ``` ```cmake add_executable(specanal specanal.c) target_link_libraries(specanal cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(specanal) ``` ```cmake add_executable(specav specav.c) target_link_libraries(specav cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(specav) ``` ```cmake add_executable(specfnu specfnu.c) target_link_libraries(specfnu cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(specfnu) ``` ```cmake add_executable(specfold specfold.c) target_link_libraries(specfold cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(specfold) ``` ```cmake add_executable(spectstr spectstr.c) target_link_libraries(spectstr cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(spectstr) ``` ```cmake add_executable(spectune spectune.c) target_link_libraries(spectune cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(spectune) ``` ```cmake add_executable(spin spin.c) target_link_libraries(spin cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(spin) ``` ```cmake add_executable(splinter splinter.c) target_link_libraries(splinter cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(splinter) ``` ```cmake add_executable(stutter stutter.c) target_link_libraries(stutter cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(stutter) ``` -------------------------------- ### Define Executable and Link Libraries (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/science/CMakeLists.txt This CMake code defines an executable target, specifies its source file, and links it against a set of libraries. It also includes a custom installation command. This pattern is repeated for multiple executables. ```cmake add_executable(synfilt synfilt.c) target_link_libraries(synfilt cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(synfilt) ``` ```cmake add_executable(synspline synspline.c) target_link_libraries(synspline cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(synspline) ``` ```cmake add_executable(tesselate tesselate.c) target_link_libraries(tesselate cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(tesselate) ``` ```cmake add_executable(tremenv tremenv.c) target_link_libraries(tremenv cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(tremenv) ``` ```cmake add_executable(ts timeseries.c) target_link_libraries(ts cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(ts) ``` ```cmake add_executable(tweet tweet.c) target_link_libraries(tweet cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(tweet) ``` ```cmake add_executable(unknot unknot.c) target_link_libraries(unknot cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(unknot) ``` ```cmake add_executable(verges verges.c) target_link_libraries(verges cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(verges) ``` ```cmake add_executable(waveform waveform.c) target_link_libraries(waveform cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(waveform) ``` -------------------------------- ### Define Executable 'rmresp' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/reverb/CMakeLists.txt Creates an executable target named 'rmresp' from the 'roomresp.cpp' source file. It links against libraries specified in 'EXTRA_LIBRARIES' and is subsequently installed using the 'my_install' command. ```cmake add_executable(rmresp roomresp.cpp) target_link_libraries(rmresp ${EXTRA_LIBRARIES}) my_install(rmresp) ``` -------------------------------- ### Build Executable 'getcol' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/tabedit/CMakeLists.txt Defines the 'getcol' executable, linking it with specified libraries and installing it. This target is built from a single C source file. ```cmake add_executable(getcol getcol.c) target_link_libraries(getcol cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(getcol) ``` -------------------------------- ### Define Executable with Minimal Linking (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/science/CMakeLists.txt This CMake code defines an executable target, 'tsconvert', and links it only against the ${EXTRA_LIBRARIES}. It also includes a custom installation command. This differs from other executables by having fewer library dependencies. ```cmake add_executable(tsconvert ts_convert.c) target_link_libraries(tsconvert ${EXTRA_LIBRARIES}) my_install(tsconvert) ``` -------------------------------- ### Define Executable 'rmverb' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/reverb/CMakeLists.txt Adds an executable target named 'rmverb'. It compiles the specified C++ source files and links against the 'portsf', 'sfsys', and any libraries defined in 'EXTRA_LIBRARIES'. Finally, it installs the executable using a custom 'my_install' command. ```cmake add_executable(rmverb rmverb.cpp reverberator.cpp wavetable.cpp) target_link_libraries(rmverb portsf sfsys ${EXTRA_LIBRARIES}) my_install(rmverb) ``` -------------------------------- ### Define Executable with Conditional Linking (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/science/CMakeLists.txt This CMake code defines an executable target, 'newsynth', and conditionally links different libraries based on the operating system. It links 'aaio' only when not on a Windows platform. It also includes a custom installation command. ```cmake add_executable(newsynth synthesis.c) if(WIN32) target_link_libraries(newsynth cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) else() target_link_libraries(newsynth cdp2k sfsys pvxio2 aaio ${EXTRA_LIBRARIES}) endif() my_install(newsynth) ``` -------------------------------- ### Process Multichannel Audio File (C) Source: https://context7.com/composersdesktop/cdp8/llms.txt Reads an input multichannel audio file and writes it to an output file, applying per-channel processing. It detects the input channel format and applies example effects like reducing the center channel and boosting the LFE channel for 5.1 formats. Dependencies include 'sfsys.h'. ```c #include "sfsys.h" #include #include int process_multichannel_file(const char *infile, const char *outfile) { int ifd, ofd; SFPROPS props; float *buffer; int buffer_frames = 1024; int samples_read; sflinit("mc_process"); ifd = sndopenEx(infile, 0, CDP_OPEN_RDONLY); if (ifd < 0) { sfperror("Cannot open input"); sffinish(); return -1; } snd_headread(ifd, &props); printf("Processing %d-channel file\n", props.chans); printf("Channel format: "); switch (props.chformat) { case MC_STEREO: printf("Stereo\n"); break; case MC_QUAD: printf("Quadraphonic\n"); break; case MC_DOLBY_5_1: printf("Dolby 5.1\n"); break; case MC_SURR_7_1: printf("7.1 Surround\n"); break; default: printf("Custom (%d channels)\n", props.chans); } ofd = sndcreat_ex(outfile, 0, &props, SFILE_CDP, CDP_CREATE_NORMAL); if (ofd < 0) { sfperror("Cannot create output"); sndclose(ifd); sffinish(); return -1; } // Allocate buffer for interleaved samples buffer = (float*)malloc(buffer_frames * props.chans * sizeof(float)); // Process with per-channel effects while ((samples_read = fgetfbufEx(buffer, buffer_frames * props.chans, ifd, 1)) > 0) { int frames = samples_read / props.chans; for (int frame = 0; frame < frames; frame++) { for (int ch = 0; ch < props.chans; ch++) { int idx = frame * props.chans + ch; // Apply channel-specific processing // Example: reduce center channel by 3dB if (props.chformat == MC_DOLBY_5_1 && ch == 2) { buffer[idx] *= 0.707f; // -3dB } // Example: boost LFE by 6dB if (props.chformat == MC_DOLBY_5_1 && ch == 3) { buffer[idx] *= 2.0f; // +6dB } } } fputfbufEx(buffer, samples_read, ofd); } free(buffer); sndclose(ifd); sndclose(ofd); sffinish(); return 0; } ``` -------------------------------- ### Reverse PVOCEX File Source: https://context7.com/composersdesktop/cdp8/llms.txt Reverses the order of frames in a PVOCEX file and writes the result to a new output file. It reads frames from the input file in reverse order, starting from the last frame and moving towards the first, then writes them sequentially to the output file. Dependencies include `pvfileio.h`, `stdio.h`, and `stdlib.h`. It takes input and output file paths as arguments, returning 0 on success or -1 on error. ```c // Reverse PVOCEX file int reverse_pvocex(const char *infile, const char *outfile) { int pvfd_in, pvfd_out; PVOCDATA pvdata; WAVEFORMATEX wfmt; float *frame_buffer; int total_frames; init_pvsys(); pvfd_in = pvoc_openfile(infile, &pvdata, &wfmt); if (pvfd_in < 0) return -1; total_frames = pvoc_framecount(pvfd_in); pvfd_out = pvoc_createfile(outfile, (pvdata.nAnalysisBins - 1) * 2, pvdata.dwOverlap, wfmt.nChannels, pvdata.wAnalFormat, wfmt.nSamplesPerSec, STYPE_IEEE_FLOAT, pvdata.wWindowType, pvdata.fWindowParam, NULL, pvdata.dwWinlen); if (pvfd_out < 0) { pvoc_closefile(pvfd_in); return -1; } frame_buffer = (float*)malloc(pvdata.nAnalysisBins * 2 * sizeof(float)); // Read frames in reverse order for (int i = total_frames - 1; i >= 0; i--) { pvoc_seek_mcframe(pvfd_in, i, SEEK_SET); if (pvoc_getframes(pvfd_in, frame_buffer, 1) == 1) { pvoc_putframes(pvfd_out, frame_buffer, 1); } } free(frame_buffer); pvoc_closefile(pvfd_in); pvoc_closefile(pvfd_out); pvsys_release(); return 0; } ``` -------------------------------- ### CDP Sound File System Initialization and Basic Audio I/O in C Source: https://context7.com/composersdesktop/cdp8/llms.txt Demonstrates initializing the CDP sound file system using sflinit(), opening input/output WAV files, reading file properties, processing audio data by applying a gain reduction, and writing the modified data. It concludes with closing files and finishing the sound file system. ```c #include "sfsys.h" int main(int argc, char *argv[]) { int ifd, ofd; SFPROPS props; float buffer[1024]; int samples_read; // Initialize sound file system if (sflinit("myprogram")) { sfperror("CDP: initialization failed"); return -1; } // Open input file read-only ifd = sndopenEx("input.wav", 0, CDP_OPEN_RDONLY); if (ifd < 0) { sfperror("Cannot open input file"); sffinish(); return -1; } // Read file properties if (snd_headread(ifd, &props) < 0) { sfperror("Cannot read file header"); sndclose(ifd); sffinish(); return -1; } printf("Sample rate: %d Hz\n", props.srate); printf("Channels: %d\n", props.chans); printf("Format: %s\n", props.format == WAVE ? "WAV" : props.format == AIFF ? "AIFF" : "Other"); // Create output file with same properties ofd = sndcreat_ex("output.wav", 0, &props, SFILE_CDP, CDP_CREATE_NORMAL); if (ofd < 0) { sfperror("Cannot create output file"); sndclose(ifd); sffinish(); return -1; } // Process audio: read, modify, write while ((samples_read = fgetfbufEx(buffer, 1024, ifd, 1)) > 0) { // Apply gain of 0.5 for (int i = 0; i < samples_read; i++) { buffer[i] *= 0.5f; } if (fputfbufEx(buffer, samples_read, ofd) != samples_read) { sfperror("Write error"); break; } } // Cleanup sndclose(ifd); sndclose(ofd); sffinish(); return 0; } ``` -------------------------------- ### Create PVOCEX Analysis File in C Source: https://context7.com/composersdesktop/cdp8/llms.txt This C function generates a PVOCEX analysis file from an input audio file. It handles system initialization, file opening, PVOCEX file creation with specified parameters (FFT size, hop size, format, sample rate, etc.), buffer allocation, and writing analysis frames. It includes pseudo-code for the FFT analysis step and proper cleanup of resources. Dependencies include 'pvfileio.h', 'sfsys.h', and standard math libraries. ```c #include "pvfileio.h" #include "sfsys.h" #include #define FFT_SIZE 2048 #define OVERLAP 512 #define SAMPLERATE 44100 int create_pvoc_analysis(const char *infile, const char *outfile) { int ifd, pvfd; SFPROPS props; PVOCDATA pvdata; float *input_buffer; float *analysis_frame; int analysis_bins; int frames_written = 0; // Initialize systems if (sflinit("pvoc_anal") || init_pvsys()) { fprintf(stderr, "Initialization failed\n"); return -1; } // Open input file ifd = sndopenEx(infile, 0, CDP_OPEN_RDONLY); if (ifd < 0) { sfperror("Cannot open input"); return -1; } snd_headread(ifd, &props); // Analysis bins = (FFT_SIZE/2) + 1 analysis_bins = (FFT_SIZE / 2) + 1; // Create PVOCEX file with amplitude-frequency pairs pvfd = pvoc_createfile(outfile, FFT_SIZE, // FFT length OVERLAP, // Hop size (samples) props.chans, // Channels PVOC_AMP_FREQ, // Format: amp/freq pairs SAMPLERATE, // Sample rate STYPE_IEEE_FLOAT, // Source format PVOCVOC_HANN, // Hann window 0.0f, // Window param (unused for Hann) NULL, // Custom window (NULL = use standard) FFT_SIZE); if (pvfd < 0) { fprintf(stderr, "PVOC create error: %s\n", pvoc_errorstr()); sndclose(ifd); return -1; } // Allocate buffers input_buffer = (float*)malloc(FFT_SIZE * sizeof(float)); analysis_frame = (float*)malloc(analysis_bins * 2 * sizeof(float)); // Analysis loop (simplified - real implementation needs FFT) int samples_read; while ((samples_read = fgetfbufEx(input_buffer, OVERLAP, ifd, 1)) == OVERLAP) { // Perform FFT analysis (pseudo-code) // Real implementation would call fftmx() or similar for (int i = 0; i < analysis_bins; i++) { // Frame format: [amp0, freq0, amp1, freq1, ...] analysis_frame[i * 2] = 0.0f; // Amplitude analysis_frame[i * 2 + 1] = (float)i * SAMPLERATE / FFT_SIZE; // Frequency (Hz) } // Write analysis frame if (pvoc_putframes(pvfd, analysis_frame, 1) < 0) { fprintf(stderr, "Write error: %s\n", pvoc_errorstr()); break; } frames_written++; } printf("Wrote %d analysis frames\n", frames_written); // Cleanup free(input_buffer); free(analysis_frame); pvoc_closefile(pvfd); sndclose(ifd); pvsys_release(); sffinish(); return 0; } ``` -------------------------------- ### Portaudio Configure for ASIO (MinGW) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/pamingwbuild.txt Configures Portaudio to use ASIO support on MinGW. It sets the host OS to mingw, activates ASIO API, disables Jack, and specifies the ASIO SDK directory. This command generates the Makefile for building. ```bash ./configure --with-host_os=mingw --with-winapi=asio --without-jack --enable-shared=no --enable-debug-output=no --with-asiodir=./ASIOSDK2 ``` -------------------------------- ### Build wrappage Executable and Link Libraries (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/standalone/CMakeLists.txt Defines the 'wrappage' executable with 'wrappage.c' as its source. It links against 'cdp2k', 'sfsys', 'pvxio2', and 'EXTRA_LIBRARIES'. The custom 'my_install' function is subsequently called. ```cmake add_executable(wrappage wrappage.c) target_link_libraries(wrappage cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(wrappage ) ``` -------------------------------- ### Custom Install Rule (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/submix/CMakeLists.txt Applies a custom installation rule to the 'submix' target. This likely involves a user-defined CMake macro 'my_install' to handle deployment. ```cmake my_install(submix) ``` -------------------------------- ### Extract Segment from PVOCEX File Source: https://context7.com/composersdesktop/cdp8/llms.txt Extracts a specified range of frames (from start_frame to end_frame) from an input PVOCEX file and writes them to an output file. It handles file opening, seeking to the desired start frame, reading frames in blocks, and writing them to a new file. Dependencies include `pvfileio.h`, `stdio.h`, and `stdlib.h`. It takes input file path, start frame, end frame, and output file path as arguments, returning 0 on success or -1 on error. ```c #include "pvfileio.h" #include #include int extract_pvoc_segment(const char *infile, int start_frame, int end_frame, const char *outfile) { int pvfd_in, pvfd_out; PVOCDATA pvdata; WAVEFORMATEX wfmt; float *frame_buffer; int total_frames, frames_to_copy; init_pvsys(); pvfd_in = pvoc_openfile(infile, &pvdata, &wfmt); if (pvfd_in < 0) { fprintf(stderr, "Open error: %s\n", pvoc_errorstr()); return -1; } total_frames = pvoc_framecount(pvfd_in); if (end_frame > total_frames) end_frame = total_frames; if (start_frame < 0) start_frame = 0; frames_to_copy = end_frame - start_frame; printf("Extracting frames %d to %d (%d frames)\n", start_frame, end_frame, frames_to_copy); // Seek to start frame if (pvoc_seek_mcframe(pvfd_in, start_frame, SEEK_SET) < 0) { fprintf(stderr, "Seek error: %s\n", pvoc_errorstr()); pvoc_closefile(pvfd_in); return -1; } // Verify position int current_pos = pvoc_framepos(pvfd_in); printf("Current position: frame %d\n", current_pos); // Create output file pvfd_out = pvoc_createfile(outfile, (pvdata.nAnalysisBins - 1) * 2, pvdata.dwOverlap, wfmt.nChannels, pvdata.wAnalFormat, wfmt.nSamplesPerSec, STYPE_IEEE_FLOAT, pvdata.wWindowType, pvdata.fWindowParam, NULL, pvdata.dwWinlen); if (pvfd_out < 0) { fprintf(stderr, "Create error: %s\n", pvoc_errorstr()); pvoc_closefile(pvfd_in); return -1; } // Allocate buffer for multiple frames int buffer_frames = 100; frame_buffer = (float*)malloc(pvdata.nAnalysisBins * 2 * buffer_frames * sizeof(float)); // Copy frames in blocks int remaining = frames_to_copy; while (remaining > 0) { int to_read = (remaining < buffer_frames) ? remaining : buffer_frames; int frames_read = pvoc_getframes(pvfd_in, frame_buffer, to_read); if (frames_read <= 0) break; if (pvoc_putframes(pvfd_out, frame_buffer, frames_read) < 0) { fprintf(stderr, "Write error: %s\n", pvoc_errorstr()); break; } remaining -= frames_read; } printf("Copied %d frames\n", frames_to_copy - remaining); free(frame_buffer); pvoc_closefile(pvfd_in); pvoc_closefile(pvfd_out); pvsys_release(); return 0; } ``` -------------------------------- ### Build Executable 'putcol' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/tabedit/CMakeLists.txt Defines the 'putcol' executable, linking it with specified libraries and installing it. This target is built from a single C source file. ```cmake add_executable(putcol putcol.c) target_link_libraries(putcol cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(putcol) ``` -------------------------------- ### CDP System - Core Audio File I/O API Source: https://context7.com/composersdesktop/cdp8/llms.txt This section details the essential functions for initializing the sound file system and performing basic audio file operations such as opening, reading properties, creating, and writing audio data using the CDP System. ```APIDOC ## Sound File System Initialization and Management ### Description Initializes the sound file system and demonstrates opening input and creating output audio files, reading file properties, and processing audio data by applying a gain reduction. ### Method C Function Calls ### Endpoint N/A (This is a C API, not a REST endpoint) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include "sfsys.h" int main(int argc, char *argv[]) { int ifd, ofd; SFPROPS props; float buffer[1024]; int samples_read; // Initialize sound file system if (sflinit("myprogram")) { sfperror("CDP: initialization failed"); return -1; } // Open input file read-only ifd = sndopenEx("input.wav", 0, CDP_OPEN_RDONLY); if (ifd < 0) { sfperror("Cannot open input file"); sffinish(); return -1; } // Read file properties if (snd_headread(ifd, &props) < 0) { sfperror("Cannot read file header"); sndclose(ifd); sffinish(); return -1; } printf("Sample rate: %d Hz\n", props.srate); printf("Channels: %d\n", props.chans); printf("Format: %s\n", props.format == WAVE ? "WAV" : props.format == AIFF ? "AIFF" : "Other"); // Create output file with same properties ofd = sndcreat_ex("output.wav", 0, &props, SFILE_CDP, CDP_CREATE_NORMAL); if (ofd < 0) { sfperror("Cannot create output file"); sndclose(ifd); sffinish(); return -1; } // Process audio: read, modify, write while ((samples_read = fgetfbufEx(buffer, 1024, ifd, 1)) > 0) { // Apply gain of 0.5 for (int i = 0; i < samples_read; i++) { buffer[i] *= 0.5f; } if (fputfbufEx(buffer, samples_read, ofd) != samples_read) { sfperror("Write error"); break; } } // Cleanup sndclose(ifd); sndclose(ofd); sffinish(); return 0; } ``` ### Response #### Success Response (0 for success, -1 for failure) This function does not return a typical HTTP response. Success is indicated by the program completing without error codes or segfaults. Errors are reported via `sfperror`. #### Response Example N/A (Console output for properties, error messages via `sfperror`) ``` -------------------------------- ### Define C Executable and Link Libraries (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/mctools/CMakeLists.txt Defines C executables, specifies their source files (single C file), and links them against necessary libraries including 'portsf', 'sfsys', 'pvxio2', and a variable '${EXTRA_LIBRARIES}'. Also includes a custom 'my_install' command for each executable. Dependencies: CMake, 'portsf', 'sfsys', 'pvxio2', '${EXTRA_LIBRARIES}'. ```cmake add_executable(fmdcode fmdcode.c fmhfuncs.c) target_link_libraries(fmdcode portsf ${EXTRA_LIBRARIES}) my_install(fmdcode) add_executable(channelx channel.c) target_link_libraries(channelx portsf m ${EXTRA_LIBRARIES}) my_install(channelx) add_executable(chorder chorder.c) target_link_libraries(chorder portsf ${EXTRA_LIBRARIES}) my_install(chorder) add_executable(chxformat chxformat.c) target_link_libraries(chxformat portsf ${EXTRA_LIBRARIES}) my_install(chxformat) add_executable(copysfx copysf.c) target_link_libraries(copysfx portsf ${EXTRA_LIBRARIES}) my_install(copysfx) add_executable(interlx interlx.c) target_link_libraries(interlx portsf ${EXTRA_LIBRARIES}) my_install(interlx) add_executable(nmix nmix.c) target_link_libraries(nmix portsf ${EXTRA_LIBRARIES}) my_install(nmix) add_executable(njoin njoin.c) target_link_libraries(njoin portsf ${EXTRA_LIBRARIES}) my_install(njoin) add_executable(sfprops sfprops.c) target_link_libraries(sfprops sfsys pvxio2 ${EXTRA_LIBRARIES}) ``` -------------------------------- ### Build Executable 'vectors' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/tabedit/CMakeLists.txt Defines the 'vectors' executable, linking it with specified libraries and installing it. It compiles a single C source file into an executable target. ```cmake add_executable(vectors vectors.c) target_link_libraries(vectors cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(vectors) ``` -------------------------------- ### Build Portaudio Static Library (MinGW) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/pamingwbuild.txt Builds the static library 'libportaudio.a' using the 'make' command. This command should be run after configuring and modifying the Makefile. The resulting library is placed in the local hidden directory (lib/.libs) and is intended for use by audio programs. ```bash make ``` -------------------------------- ### Library Discovery and Linking (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/listaudevs/CMakeLists.txt Locates and links necessary libraries for the project, such as CoreAudio, AudioToolbox, PortAudio, and platform-specific libraries like 'dsound', 'winmm', and 'pthread'. Defines the order and names of libraries to be linked. ```cmake if(APPLE) find_library(COREAUDIOLIB CoreAudio) find_library(AUDIOTOOLBOX AudioToolbox) find_library(AULIB AudioUnit) find_library(CARBONLIB Carbon) link_directories (/usr/local/lib) find_library(PA NAMES libportaudio.a) set(EXTRA_LIBRARIES1 ${PA} ${COREAUDIOLIB} ${AUDIOTOOLBOX} ${AULIB} ${CARBONLIB} ${EXTRA_LIBRARIES}) else() if(MINGW OR MSVC) link_directories(/usr/local/lib) find_library(PA NAMES libportaudio.a) # NB winmm must appear after any module that references it. Yes, that's weird. set(EXTRA_LIBRARIES1 dsound winspool ${PA} winmm ${EXTRA_LIBRARIES}) else() link_directories (/usr/local/lib) find_library(PA NAMES libportaudio.a) set(EXTRA_LIBRARIES1 pthread ${PA} ${EXTRA_LIBRARIES} jack asound) endif() endif() link_directories(../../lib) include_directories( ../../../include ../include ../portaudio/include ../portaudio/src/common ) target_link_libraries(listaudevs ${EXTRA_LIBRARIES1}) ``` -------------------------------- ### Build Executable 'columns' (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/tabedit/CMakeLists.txt Defines the 'columns' executable, linking it with specified libraries and installing it. It compiles multiple C source files into a single executable target. ```cmake add_executable(columns columns0.c columns1.c columns2.c columns3.c columns4.c columns5.c columns6.c) target_link_libraries(columns cdp2k sfsys pvxio2 ${EXTRA_LIBRARIES}) my_install(columns) ``` -------------------------------- ### macOS Specific Settings (CMake) Source: https://github.com/composersdesktop/cdp8/blob/main/CMakeLists.txt Configures macOS-specific build settings, including the framework installation path and the default system root SDK. It sets the deployment target to 10.9 if the SDK is found. ```cmake if(APPLE) if(BUILD_INSTALLER) set(CS_FRAMEWORK_DEST "${CMAKE_INSTALL_PREFIX}") endif() set(DEFAULT_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/) if(NOT CMAKE_OSX_SYSROOT AND EXISTS ${DEFAULT_OSX_SYSROOT}) set(CMAKE_OSX_SYSROOT ${DEFAULT_OSX_SYSROOT}) endif() if(EXISTS ${CMAKE_OSX_SYSROOT}) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9) endif() endif() ``` -------------------------------- ### Portaudio Configure for DirectSound (MinGW) Source: https://github.com/composersdesktop/cdp8/blob/main/dev/externals/paprogs/pamingwbuild.txt Configures Portaudio to use DirectSound support on MinGW. It sets the host OS to mingw, activates the DirectX API, disables Jack, and specifies the DirectSound SDK directory. This command generates the Makefile for building. ```bash ./configure --with-host_os=mingw --with-winapi=directx --without-jack --enable-shared=no --enable-debug-output=no --with-dxdir=/home/Richard/dx9mgw ```