franta-hg@0: /** franta-hg@0: * DJM-Fix franta-hg@0: * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) franta-hg@0: * franta-hg@0: * This program is free software: you can redistribute it and/or modify franta-hg@0: * it under the terms of the GNU General Public License as published by franta-hg@0: * the Free Software Foundation, version 3 of the License. franta-hg@0: * franta-hg@0: * This program is distributed in the hope that it will be useful, franta-hg@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@0: * GNU General Public License for more details. franta-hg@0: * franta-hg@0: * You should have received a copy of the GNU General Public License franta-hg@0: * along with this program. If not, see . franta-hg@0: */ franta-hg@0: franta-hg@1: #include franta-hg@1: #include franta-hg@2: #include franta-hg@2: #include franta-hg@2: #include franta-hg@5: #include franta-hg@1: franta-hg@1: #include "DJMFix.h" franta-hg@2: #include "AlsaBridge.h" franta-hg@2: franta-hg@5: static std::atomic run{true}; franta-hg@2: franta-hg@2: void interrupt(int signal) { franta-hg@2: run = false; franta-hg@2: std::cerr << "interrupt()" << std::endl; // TODO: do not mess STDIO franta-hg@2: } franta-hg@1: franta-hg@10: /** franta-hg@10: * The support for Pioneer DJ DJM-250MK2 (an external USB sound card / mixer) was added to the Linux (kernel) by these patches: franta-hg@10: * franta-hg@10: * - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/sound/usb?id=73d8c94084341e2895169a0462dbc18167f01683 (playback) franta-hg@10: * - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/sound/usb?id=14335d8b9e1a2bf006f9d969a103f9731cabb210 (recording) franta-hg@10: * - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/sound/usb?id=cdc01a1558dedcee3daee7e1802d0349a07edb87 (mixer setup) franta-hg@10: * franta-hg@10: * These patches are enough for playback and for recording from post CH faders. franta-hg@10: * franta-hg@10: * However this mixer is somehow incapacitated and if we want to record the raw signal from the PHONO or LINE channels, franta-hg@10: * we only get silence. This feature is important for DVS (Digital Vinyl Systems) setups where franta-hg@10: * the timecode signal from special control vinyls flows from mixer to the computer franta-hg@10: * where it is interpreted in a software like MIXXX and used for controlling the playback of files on our computer. franta-hg@10: * The signal (usually music) from these files flows back to the mixer and then to speakers and headphones. franta-hg@10: * franta-hg@10: * To make this work and enjoy all the features of the device we have bought, we need to tell the mixer that we franta-hg@10: * want the signal instead of silence on given channels. And this is the purpose of the djm-fix utility and franta-hg@10: * it is done by sending some magic packet to the mixer. franta-hg@10: * franta-hg@10: * Implementation of this magic in the AlsaBridge.cpp file is based on publicly available documentation franta-hg@10: * that can be found at . franta-hg@10: * This page pointed me to the proper hash function (according to the constants, it is bit uncommon but publicly known Fowler–Noll–Vo hash function, FNV) franta-hg@10: * and some magic bits. I wrote this standalone C++ program that talks with the mixer over MIDI SysEx messages and does the magic. franta-hg@10: * franta-hg@10: * When this program is started, it finds the mixer and makes it fully working. franta-hg@10: * It needs to be running all the time, otherwise we will get silence on the PHONO/LINE channels again. franta-hg@10: * franta-hg@10: * Install dependencies: franta-hg@10: * apt install mercurial make pkg-config g++ libasound2-dev # in Debian or Ubuntu (it will be similar in other distributions) franta-hg@10: * franta-hg@10: * Download djm-fix: franta-hg@10: * hg clone https://hg.frantovo.cz/midi/djm-fix/ # primary source franta-hg@10: * hg clone https://hg.globalcode.info/midi/djm-fix/ # or we can use this mirror franta-hg@10: * franta-hg@10: * Compile: franta-hg@10: * make # we can skip this step, it will be compiled on the first run franta-hg@10: * franta-hg@10: * Run: franta-hg@10: * make run franta-hg@10: * franta-hg@10: * Stop: franta-hg@10: * press Ctrl+C franta-hg@10: */ franta-hg@10: franta-hg@0: int main(int argc, char**argv) { franta-hg@5: std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search franta-hg@10: franta-hg@2: signal(SIGINT, interrupt); franta-hg@2: std::unique_ptr djmFix(djmfix::create()); franta-hg@5: std::unique_ptr alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName)); franta-hg@1: franta-hg@2: alsaBridge->start(); franta-hg@2: while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100)); franta-hg@2: alsaBridge->stop(); franta-hg@1: franta-hg@0: return 0; franta-hg@0: }