author František Kučera <>
Mon, 04 Jan 2021 00:15:56 +0100
changeset 10 4d95b089457d
parent 5 ef8f4023e32e
child 11 5b351628a377
permissions -rw-r--r--

 * DJM-Fix
 * Copyright © 2020 František Kučera (,
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <>.

#include <memory>
#include <iostream>
#include <chrono>
#include <thread>
#include <csignal>
#include <atomic>

#include "DJMFix.h"
#include "AlsaBridge.h"

static std::atomic<bool> run{true};

void interrupt(int signal) {
	run = false;
	std::cerr << "interrupt()" << std::endl; // TODO: do not mess STDIO

 * The support for Pioneer DJ DJM-250MK2 (an external USB sound card / mixer) was added to the Linux (kernel) by these patches:
 *  - (playback)
 *  - (recording)
 *  - (mixer setup)
 * These patches are enough for playback and for recording from post CH faders.
 * However this mixer is somehow incapacitated and if we want to record the raw signal from the PHONO or LINE channels,
 * we only get silence. This feature is important for DVS (Digital Vinyl Systems) setups where
 * the timecode signal from special control vinyls flows from mixer to the computer
 * where it is interpreted in a software like MIXXX and used for controlling the playback of files on our computer.
 * The signal (usually music) from these files flows back to the mixer and then to speakers and headphones.
 * To make this work and enjoy all the features of the device we have bought, we need to tell the mixer that we
 * want the signal instead of silence on given channels. And this is the purpose of the djm-fix utility and
 * it is done by sending some magic packet to the mixer.
 * Implementation of this magic in the AlsaBridge.cpp file is based on publicly available documentation
 * that can be found at <>.
 * 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)
 * and some magic bits. I wrote this standalone C++ program that talks with the mixer over MIDI SysEx messages and does the magic.
 * When this program is started, it finds the mixer and makes it fully working.
 * It needs to be running all the time, otherwise we will get silence on the PHONO/LINE channels again.
 * Install dependencies:
 *   apt install mercurial make pkg-config g++ libasound2-dev    # in Debian or Ubuntu (it will be similar in other distributions)
 * Download djm-fix:
 *   hg clone               # primary source
 *   hg clone           # or we can use this mirror
 * Compile:
 *   make                                                        # we can skip this step, it will be compiled on the first run
 * Run:
 *   make run
 * Stop:
 *   press Ctrl+C

int main(int argc, char**argv) {
	std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search

	signal(SIGINT, interrupt);
	std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
	std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName));

	while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));

	return 0;