void play_file(unsigned rate, unsigned channels, int fd, unsigned count) { next = malloc(count); if (!next) { fprintf(stderr,"could not allocate %d bytes\n", count); return; } if (read(fd, next, count) != count) { fprintf(stderr,"could not read %d bytes\n", count); return; } avail = count; pcm_play(rate, channels, fill_buffer, 0); }
int main(int argc, char *argv[]) { (void)argc; (void)argv; if (pcm_open() < 0) { printf("pcm_open error\n"); return 1; } int16_t data16[] = { 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, 0, 11585, 16384, 11585, 0, -11585, -16384, -11585, }; char data8[sizeof(data16) / sizeof(data16[0])]; for (int i = 0; i < (int)sizeof(data8); i++) { data8[i] = data16[i] >> 8; } int count = 5 * 10; // 10s while (count--) { pcm_play((void*)data16, sizeof(data16)); } pcm_close(); return 0; }
static void play_file(struct audtest_config *config, unsigned rate, unsigned channels, int fd, unsigned count) { next = (char*)malloc(count); printf(" play_file: count=%d,next=%p\n", count,next); if (!next) { fprintf(stderr,"could not allocate %d bytes\n", count); return; } if (read(fd, next, count) != count) { fprintf(stderr,"could not read %d bytes\n", count); return; } avail = count; pcm_play(config, rate, channels, fill_buffer, 0); }