int main(int argc, char* argv[]) { id = argc; Audio audio; char input; for (unsigned int i = 8192; i > 2; i /= 2) { audio.start(i); sleep(1); audio.stop(); } }
int cui_main(int argc, char *argv[]) { uint32_t tid = syscall_mthread_create(inputLoop); struct audio_data_format defaultFormat = {0, 2, 16, 4400}; Audio* audio = new Audio(&defaultFormat, AUDIO_OUTPUT); if (-1 == audio->start()) { _printf("Can not connect to AUDIO server!\n"); } strings oggFiles; if (strcmp(argv[1], "-d") == 0 && argc > 2) { listOggfiles(argv[2], oggFiles); } else { for (int i = 1; i < argc; i++) { oggFiles.push_back(argv[i]); } } for (int i = 0; i < oggFiles.size(); i++) { FILE* fp = fopen(oggFiles[i].data(), "rb"); if (NULL == fp) { fprintf(stderr, "File open error: %s.\n", oggFiles[i].data()); delete audio; return -1; } OggVorbis_File vf; if (ov_open(fp, &vf, NULL, 0) < 0) { fprintf(stderr, "Skipped, %s does not appear to be an Ogg bitstream.\n", argv[i]); continue; } char** infoTexts = ov_comment(&vf, -1)->user_comments; vorbis_info* vi=ov_info(&vf, -1); while(*infoTexts) { fprintf(stderr, "%s\n", *infoTexts); ++infoTexts; } // fprintf(stderr, "\nBitstream is %d channel, %dHz\n", vi->channels, vi->rate); // fprintf(stderr, "\nDecoded length: %d samples\n",(long)ov_pcm_total(&vf, -1)); // fprintf(stderr, "Encoded by: %s\n\n", ov_comment(&vf, -1)->vendor); struct audio_data_format format = {0, vi->channels, 16, vi->rate}; audio->setFormat(&format); int current_section; char pcmout[4096]; fprintf(stdout, "key q(quit) <=(prev) =>(next)\n"); for (;;) { switch(command) { case COMMAND_FORWARD: command = COMMAND_NONE; goto replay; case COMMAND_BACKWARD: command = COMMAND_NONE; i -= 2; goto replay; case COMMAND_EXIT: i = oggFiles.size(); goto replay; case COMMAND_VOLUME_UP: case COMMAND_VOLUME_DOWN: break; default: break; } long ret = ov_read(&vf, pcmout, sizeof(pcmout), ¤t_section); if (ret == 0) { break; } else if (ret < 0) { fprintf(stderr, "Warning data broken? %s\n", argv[i]); } else { audio->write(pcmout, ret); } } replay: fclose(fp); } audio->stop(); delete audio; // cleanup causes crash! // ov_clear(&vf); }