int sound_output(unsigned char * buffer, int len)
{
unsigned char * morse_table[256] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "---...", "-.-.-.", NULL, "-...-", NULL, "..--..",
".--.-.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", NULL, NULL, NULL, NULL, "..--.-",
NULL, ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", NULL, NULL, NULL, NULL, NULL,
};
unsigned char * sound_buffer;
struct sio_hdl * sd;
int flag_space;
int inpos;
int symbol;
int offset;
int i;
for (i=0; i<256; i++) {
if (morse_table[i]==NULL) {
morse_table[i]=morse_table['?'];
}
}
sound_buffer=malloc(8*1024*1024);
offset=0;
flag_space=1;
#define CHAR *(buffer+inpos)
#define MCHAR morse_table[CHAR]
#define SYMBOL (*(MCHAR+symbol))
for (inpos=0; inpos<len; inpos++) {
for (symbol=0; symbol < strlen(MCHAR); symbol++) {
sound_output_samples(sound_buffer, &offset, (SYMBOL=='.' ? 1 : 3) * DIT, 1);
sound_output_samples(sound_buffer, &offset, DIT, 0);
}
sound_output_samples(sound_buffer, &offset, (CHAR == ' ' ? (flag_space==0 ? 7*DIT : 0) : 2*DIT), 0);
flag_space=(CHAR == ' ' ? 1 : 0);
}
sio_write(sd, sound_buffer, offset);
free(sound_buffer);
return (0);
}