int cst_track_save_est_binary(cst_track *t, const char *filename) { cst_file fd; float foo; int i, j; if ((fd = cst_fopen(filename, CST_OPEN_WRITE | CST_OPEN_BINARY)) == NULL) { cst_errmsg("cst_track_save_est_binary: can't open file \"%s\"\n", filename); return -1; } cst_fprintf(fd, "EST_File Track\n"); cst_fprintf(fd, "DataType binary\n"); cst_fprintf(fd, "ByteOrder %s\n", CST_LITTLE_ENDIAN ? BYTE_ORDER_LITTLE : BYTE_ORDER_BIG); cst_fprintf(fd, "NumFrames %d\n", t->num_frames); cst_fprintf(fd, "NumChannels %d\n", t->num_channels); cst_fprintf(fd, "BreaksPresent true\n"); cst_fprintf(fd, "EST_Header_End\n"); foo = 1.0; /* put a bogus 'breaks' value in for now */ for (i = 0; i < t->num_frames; i++) { cst_fwrite(fd, t->times + i, sizeof(float), 1); cst_fwrite(fd, &foo, sizeof(float), 1); for (j = 0; j < t->num_channels; j++) cst_fwrite(fd, &(t->frames[i][j]), sizeof(float), 1); } cst_fclose(fd); return 0; }
static int play_wave_from_socket(snd_header *header,int audiostream) { /* Read audio from stream and play it to audio device, converting */ /* it to pcm if required */ int num_samples; int sample_width; cst_audiodev *audio_device; int q,i,n,r; unsigned char bytes[CST_AUDIOBUFFSIZE]; short shorts[CST_AUDIOBUFFSIZE]; cst_file fff; fff = cst_fopen("/tmp/awb.wav",CST_OPEN_WRITE|CST_OPEN_BINARY); if ((audio_device = audio_open(header->sample_rate,1, (header->encoding == CST_SND_SHORT) ? CST_AUDIO_LINEAR16 : CST_AUDIO_LINEAR8)) == NULL) { cst_errmsg("play_wave_from_socket: can't open audio device\n"); return -1; } if (header->encoding == CST_SND_SHORT) sample_width = 2; else sample_width = 1; num_samples = header->data_size / sample_width; /* we naively let the num_channels sort itself out */ for (i=0; i < num_samples; i += r/2) { if (num_samples > i+CST_AUDIOBUFFSIZE) n = CST_AUDIOBUFFSIZE; else n = num_samples-i; if (header->encoding == CST_SND_ULAW) { r = read(audiostream,bytes,n); for (q=0; q<r; q++) shorts[q] = cst_ulaw_to_short(bytes[q]); r *= 2; } else /* if (header->encoding == CST_SND_SHORT) */ { r = read(audiostream,shorts,n*2); if (CST_LITTLE_ENDIAN) for (q=0; q<r/2; q++) shorts[q] = SWAPSHORT(shorts[q]); } if (r <= 0) { /* I'm not getting any data from the server */ audio_close(audio_device); return CST_ERROR_FORMAT; } for (q=r; q > 0; q-=n) { n = audio_write(audio_device,shorts,q); cst_fwrite(fff,shorts,2,q); if (n <= 0) { audio_close(audio_device); return CST_ERROR_FORMAT; } } } audio_close(audio_device); cst_fclose(fff); return CST_OK_FORMAT; }