Skip to content

Instantly share code, notes, and snippets.

View Roman-Port's full-sized avatar

Roman Port Roman-Port

View GitHub Profile
@Roman-Port
Roman-Port / gist:0f95f3739ee0bd5158ea4cd43c94e8f9
Created December 3, 2023 03:32
FFMPEG Stereo Difference Split and Join
Creates L+R and L-R channels:
ffmpeg -i test.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo[l][r];[r]volume=volume=-1[ri];[l][ri]amix=inputs=2[diff];[0:a]channelsplit=channel_layout=stereo[l][r];[l][r]amix=inputs=2:weights=0.5[add]" -map "[add]" add.wav -map "[diff]" diff.wav
Merges L+R and L-R back into a stereo file, identical to the original input:
ffmpeg -i add.wav -i diff.wav -filter_complex "[1:a]volume=volume=-1[diffi];[0:a][1:a]amix=inputs=2[l];[0:a][diffi]amix=inputs=2[r];[l][r]join=inputs=2:channel_layout=stereo[outpre];[outpre]volume=volume=2[out]" -map "[out]" testout.wav
@Roman-Port
Roman-Port / gist:f0bc984150a75b76031569412d9345f7
Created December 3, 2023 02:55
FFMPEG create stereo difference
ffmpeg -i input.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo[l][r];[r]volume=volume=-1[ri];[l][ri]amix=inputs=2[diff]" -map "[diff]" diff.wav
@Roman-Port
Roman-Port / gist:be1c4097dfcce623bf9a52707a72d812
Created October 31, 2022 05:43
Repairing Windows Powershell Text Mangling When Piping to File
Hi! Quick tip I found out for anyone (or myself) who accidentally piped or concatenated important data to a file with Powershell and found that text was mangled. You might see "’" converted to "ΓÇÖ" or "Mötley Crüe" converted to "M├╢tley Cr├╝e" for example.
To fix, simply run this command in Powershell after editing the input and output filenames:
```
Get-Content [input] | Out-File [output] -Encoding Oem
```
@Roman-Port
Roman-Port / BufferedTreeView.cs
Created August 8, 2022 17:09
Finally, double-buffered, non-flickering WinForms TreeView in Windows 10
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
namespace DddProperyEditorGUI.Util
{
/*
* Mostly based off of https://sites.google.com/a/nomad-net.info/dev/articles/double-buffered-tree-and-list-views
* Updated to work with Windows 10 by RomanPort
@Roman-Port
Roman-Port / core.c
Created July 17, 2022 01:53
STM32F746 I2s IQ recorder to SD card
#include "core.h"
#include "main.h"
#include "fatfs.h"
#define RECORDER_STATUS_DISABLED 0 // Recorder is off.
#define RECORDER_STATUS_RECORDING 1 // Recording normally.
#define RECORDER_BUFFER_STATUS_AVAILABLE 0 // Buffer is available for writing
#define RECORDER_BUFFER_STATUS_PENDING 1 // Waiting to write to disk
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <driver/i2s.h>
#define SAMPLE_RATE 325000
#define BITS_PER_SAMPLE 16
uint8_t buffer[1024];
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include <driver/i2s.h>
static const char *TAG = "example";
void run_benchmark() {
int target = 2600000 * 5;
int blockSize = sizeof(buffer);
while (blockSize >= 256) {
//Do benchmark
FILE* output = fopen("/sdcard/out.bin", "wb");
int64_t start = esp_timer_get_time();
int remaining = target;
while (remaining > 0) {
remaining -= fwrite(buffer, 1, blockSize > remaining ? remaining : blockSize, output);
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include <driver/i2s.h>
static const char *TAG = "example";
// PLEASE DO NOT COPY+PASTE THIS, PLEASE!!!
// prints the biggest gainers (and ties) in the dataset
private static void examplePrintSummaryVar(Quote[] data) {
//Set up
double maxValue = 0; // stores the maximum value we've seen in the dataset so far
Quote[] ties = new Quote[data.length]; // stores all of the elements with the maximum value we've seen (PS: Using a list if you know how is more efficient)
int tiesCount = 0; // stores the number of ties we've seen so far
//Loop through everything we have in data