Skip to content

Instantly share code, notes, and snippets.

@ha7ilm ha7ilm/stereo_phaseshift.c
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.