Sign in to follow this  
Followers 0
Peter123

Waves in binary

4 posts in this topic

Hallo, I need a program or something like that to transform sound waves in zeros( 0 ) and ones ( 1 ) - ASCII codes please help :rolleyes:

Not sure what you are asking, but if you wanted (say) a 16bit value for each sound sample you could use a combination of SOX and something to dump the output (maybe hexdump can do it).

SOX (http://sox.sourceforge.net/) can convert between many audio file formats, convert to raw.

0

Share this post


Link to post
Share on other sites

Hallo, I need a program or something like that to transform sound waves in zeros( 0 ) and ones ( 1 ) - ASCII codes please help :rolleyes:

Ok, I'm not sure what you need this for but this takes a .wav file as an argument and outputs 0s and 1s:


#include <stdio.h>

void out8(unsigned char in) {
int i;
for(i=0;i<8;i++)
putchar('0'+((in>>i)&1));
}

int main(int argc, char **argv) {
FILE *fp;
int i;
unsigned char dat;
if(argc<2) return 0;
if((fp=fopen(argv[1],"rb"))<=0) {
perror(argv[1]);
exit(-1);
}
if(fseek(fp, 44, SEEK_SET)<0) {
perror("seek");
return 0;
}
for(;;i++) {
if(fread(&dat,1, 1, fp)==0)
if(feof(fp)) return 0;
out8(dat);
if((i&4) == 4) fflush(stdout);
}
}

Edited by SigFLUP
0

Share this post


Link to post
Share on other sites

Hallo, I need a program or something like that to transform sound waves in zeros( 0 ) and ones ( 1 ) - ASCII codes please help :rolleyes:

Not sure what you are asking, but if you wanted (say) a 16bit value for each sound sample you could use a combination of SOX and something to dump the output (maybe hexdump can do it).

SOX (http://sox.sourceforge.net/) can convert between many audio file formats, convert to raw.

I think this might work but did you use it? Can you tell me with witch command to use and what type of file i need. Thanks in advance.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0