Last active
August 29, 2015 14:20
-
-
Save ha7ilm/6b0cd9f4b04300d33602 to your computer and use it in GitHub Desktop.
Shifts one channel of a 16-bit stereo audio file (for I/Q phase correction)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/tcc -run | |
#include <stdio.h> | |
#include <stdlib.h> | |
//dependencies: sudo apt-get install tcc | |
//usage: cat sine.raw | ./stereo_phaseshift.c > sine2.raw | |
//d gives the number of samples to shift: | |
int d=5, i; | |
short gs() | |
{ | |
int x,y; | |
if(((x=getchar())==EOF)||(y=getchar())==EOF) abort(); | |
return (x&0xff)|((y&0xff)<<8); | |
} | |
void ps(short x){putchar(x&0xff);putchar(x>>8);} | |
int main() | |
{ | |
short*left=malloc(d*sizeof(short)*2*2); | |
short*right=left+d*sizeof(short)*2; | |
for(;;) | |
{ | |
memmove(left,left+d,d*sizeof(short)); | |
memmove(right,right+d,d*sizeof(short)); | |
for(i=0;i<d;i++) {left[i+d]=gs();right[i+d]=gs();} | |
for(i=0;i<d;i++) {ps(left[i+d]);ps(right[i]);} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result should look like this:
http://ha5kfu.sch.bme.hu/up/levelezes/phaseshift.png