Skip to content

Instantly share code, notes, and snippets.

@ha7ilm
Last active August 29, 2015 14:20
Show Gist options
  • Save ha7ilm/6b0cd9f4b04300d33602 to your computer and use it in GitHub Desktop.
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)
#!/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]);}
}
}
@ha7ilm
Copy link
Author

ha7ilm commented May 9, 2015

The result should look like this:

http://ha5kfu.sch.bme.hu/up/levelezes/phaseshift.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment