82 lines
1.5 KiB
C
82 lines
1.5 KiB
C
|
/*
|
||
|
* WAV TO TEXT
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include <sndfile.h>
|
||
|
|
||
|
#include "support.h"
|
||
|
|
||
|
/* --------------------------------------------------------------- */
|
||
|
int convert_wav_to_text(char *infname)
|
||
|
{
|
||
|
SNDFILE * sndf;
|
||
|
SF_INFO sfinfo;
|
||
|
int foo, lu;
|
||
|
short * samples;
|
||
|
|
||
|
#if DEBUG_LEVEL
|
||
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, infname);
|
||
|
#endif
|
||
|
|
||
|
memset(&sfinfo, 0, sizeof(sfinfo)); /* be clean */
|
||
|
|
||
|
sndf = sf_open(infname, SFM_READ, &sfinfo);
|
||
|
if (sndf==NULL)
|
||
|
{
|
||
|
/*catch the snfile errmsg here XXX */
|
||
|
fprintf(stderr, "error sf_opening %s\n", infname);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
foo = display_sf_info(&sfinfo, "why not ?");
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: corrupted sf_info ?\n", __func__);
|
||
|
abort();
|
||
|
}
|
||
|
|
||
|
/* get memory for bufferins read from sound file */
|
||
|
if ( NULL == (samples = malloc(BUFFER_SIZE*sizeof(short))) )
|
||
|
{
|
||
|
perror("\n no memory in converter");
|
||
|
abort();
|
||
|
}
|
||
|
|
||
|
while ( (lu=sf_read_short(sndf, samples, BUFFER_SIZE)) > 0 )
|
||
|
{
|
||
|
fprintf(stderr, " LU = %5lu\n", lu);
|
||
|
|
||
|
}
|
||
|
/*
|
||
|
* job done, some cleanup
|
||
|
*/
|
||
|
free(samples);
|
||
|
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
/* --------------------------------------------------------------- */
|
||
|
void usage(void)
|
||
|
{
|
||
|
printf("usage:\n\twav2txt 1337.wav\n");
|
||
|
exit(0);
|
||
|
}
|
||
|
/* --------------------------------------------------------------- */
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
int foo;
|
||
|
|
||
|
print_version(argv[0]);
|
||
|
|
||
|
if (2 != argc) usage();
|
||
|
|
||
|
foo = convert_wav_to_text(argv[1]);
|
||
|
fprintf(stderr, "got a %d from converter\n", foo);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
/* --------------------------------------------------------------- */
|