int main(int argc, char *argv[]){ if(argc < 2) return 0; ao_initialize(); mpg123_init(); mh = mpg123_new(NULL, NULL); mpg123_open_feed(mh); CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, play_stream); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_perform(curl); curl_easy_cleanup(curl); mpg123_close(mh); mpg123_delete(mh); mpg123_exit(); ao_close(dev); ao_shutdown(); return 0; }
void show_ao_device_info(FILE *fp) { int driver_count; ao_info **devices; int i; ao_initialize(); fputs("Output device name (ao only):" NLS " -o device ", fp); devices = ao_driver_info_list(&driver_count); if (driver_count < 1) { fputs("*no device found*" NLS, fp); } else { fputs("[ ", fp); for(i = 0; i < driver_count; i++) { if (devices[i]->type == AO_TYPE_LIVE) fprintf(fp, "%s ", devices[i]->short_name); } fputs("]", fp); } ao_shutdown(); }
static int detect(void) { int driver_id, result = 0; ao_sample_format ao_sample_format_ctx; ao_device *ao_device_ctx; ao_initialize(); /* Only succeed in autodetect mode when pulseaudio is available! */ driver_id = ao_driver_id("pulse"); ao_sample_format_ctx.rate = 44100; ao_sample_format_ctx.bits = 16; ao_sample_format_ctx.channels = 2; ao_sample_format_ctx.byte_format = AO_FMT_NATIVE; ao_sample_format_ctx.matrix = NULL; if ((ao_device_ctx = ao_open_live(driver_id, &ao_sample_format_ctx, NULL))) { result = 1; ao_close(ao_device_ctx); } ao_shutdown(); return result; }
/* global initialization * * XXX: in theory we can select the filters/formats we want to support, but * this does not work in practise. */ void BarPlayerInit () { ao_initialize (); av_log_set_level (AV_LOG_FATAL); av_register_all (); avfilter_register_all (); avformat_network_init (); }
void beep_init(void) { if (initialized) return; memset(&g_beep, 0, sizeof(g_beep)); ao_initialize(); //g_beep.driver = ao_default_driver_id(); /* FIXME: on my system the default Alsa doesn't work, only pulse. */ g_beep.driver = ao_driver_id("pulse"); if (g_beep.driver < 0) { fputs("error getting default driver\n", stderr); return; } g_beep.fmt.bits = 8; g_beep.fmt.rate = 8000; g_beep.fmt.channels = 1; g_beep.device = ao_open_live(g_beep.driver, &(g_beep.fmt), NULL); if (g_beep.device == NULL) { fprintf(stderr, "error opening default device for live playback: %s\n", strerror(errno)); return; } initialized = 1; }
/* * Initialize libao * */ int libao_init_device (void *unused) { (void) unused; /* don't warn */ ao_initialize (); return 0; }
s32 sal_AudioInit(s32 rate, s32 bits, s32 stereo, s32 Hz) { ao_sample_format ao_format; stereo = stereo ? 2 : 1; ao_initialize(); ao_sample_format ao = {bits, rate, stereo, AO_FMT_LITTLE, NULL}; memset(&ao_format, 0, sizeof(ao_format)); ao_format.bits = bits; ao_format.rate = rate; ao_format.channels = stereo; ao_format.byte_format = AO_FMT_LITTLE; ao_dev = ao_open_live(ao_default_driver_id(), &ao_format, NULL /* no options */); if (!ao_dev) { perror("Failed to open sound.\n"); printf("Failed to open sound.\n"); return SAL_ERROR; } mSoundSampleCount = (rate/Hz) * (stereo); /* mSoundBufferSize = mSoundSampleCount * (bits >> 3); */ mSoundBufferSize = mSoundSampleCount * ((bits==16)?2:1); mStereo = stereo; mSb=0; return SAL_OK; }
BOOL wave_out_open(void) { ao_sample_format format; ao_initialize(); default_driver = ao_default_driver_id(); format.bits = 16; format.channels = 2; g_channels = 2; format.rate = 44100; g_samplerate = 44100; format.byte_format = AO_FMT_LITTLE; o_device = ao_open_live(default_driver, &format, NULL); if (o_device == NULL) { return False; } g_dsp_fd = 0; queue_lo = queue_hi = 0; g_reopened = True; return True; }
int audio_init(const struct uade_config *uc) { int driver; if (uade_no_audio_output) return 1; process_config_options(uc); ao_initialize(); if (uade_output_file_name[0]) { driver = ao_driver_id(uade_output_file_format[0] ? uade_output_file_format : "wav"); if (driver < 0) { __android_log_print(ANDROID_LOG_VERBOSE, "UADE", "Invalid libao driver\n"); return 0; } libao_device = ao_open_file(driver, uade_output_file_name, 1, &format, NULL); } else { driver = ao_default_driver_id(); libao_device = ao_open_live(driver, &format, options); } if (libao_device == NULL) { __android_log_print(ANDROID_LOG_VERBOSE, "UADE", "Can not open ao device: %d\n", errno); return 0; } return 1; }
RD_BOOL libao_open(void) { ao_sample_format format; ao_initialize(); if (libao_device) { default_driver = ao_driver_id(libao_device); } else { default_driver = ao_default_driver_id(); } memset(&format, 0, sizeof(format)); format.bits = 16; format.channels = 2; format.rate = 44100; format.byte_format = AO_FMT_NATIVE; o_device = ao_open_live(default_driver, &format, NULL); if (o_device == NULL) { return False; } reopened = True; return True; }
int main(int argc, char *argv[]) { ao_device *device; ao_sample_format fmt; double duration = NOTE_LENGTH; float octave_mult = 1.0f; if (argc == 2); // do nothing else if (argc == 3) { sscanf(argv[2], "%lf", &duration); if (duration < 0) { printf("Note length can't be negative!\n"); return 1; } } else { printf("Usage: %s notes [length]\n", argv[0]); return 3; } fmt.bits = 16; fmt.rate = SAMPLE_RATE; fmt.channels = 1; fmt.byte_format = AO_FMT_NATIVE; fmt.matrix = NULL; ao_initialize(); device = ao_open_live(ao_default_driver_id(), &fmt, NULL); if (!device) { printf("Error %d opening audio device!\n", errno); return 2; } int i; for (i=0; i<strlen(argv[1]); i++) { char ch = argv[1][i]; char capital; switch (ch) { case '-': octave_mult *= 0.5f; break; case '+': octave_mult *= 2.0f; break; default: capital = ('A' <= ch && ch <= 'G'); if (capital) octave_mult *= 2.0f; play_note(device, tofreq(ch) * octave_mult, duration); if (capital) octave_mult *= 0.5f; break; //not needed, but good practice } } ao_close(device); ao_shutdown(); return 0; }
/* Sound Thread*/ static void *gp2x_sound_thread_play(unsigned sampleRate_, unsigned bufferSize_) { #ifndef NOSOUND ao_initialize(); }
/*=export_func optionProcess * * what: this is the main option processing routine * * arg: + tOptions* + opts + program options descriptor + * arg: + int + a_ct + program arg count + * arg: + char** + a_v + program arg vector + * * ret_type: int * ret_desc: the count of the arguments processed * * doc: * * This is the main entry point for processing options. It is intended * that this procedure be called once at the beginning of the execution of * a program. Depending on options selected earlier, it is sometimes * necessary to stop and restart option processing, or to select completely * different sets of options. This can be done easily, but you generally * do not want to do this. * * The number of arguments processed always includes the program name. * If one of the arguments is "--", then it is counted and the processing * stops. If an error was encountered and errors are to be tolerated, then * the returned value is the index of the argument causing the error. * A hyphen by itself ("-") will also cause processing to stop and will * @emph{not} be counted among the processed arguments. A hyphen by itself * is treated as an operand. Encountering an operand stops option * processing. * * err: Errors will cause diagnostics to be printed. @code{exit(3)} may * or may not be called. It depends upon whether or not the options * were generated with the "allow-errors" attribute, or if the * ERRSKIP_OPTERR or ERRSTOP_OPTERR macros were invoked. =*/ int optionProcess(tOptions * opts, int a_ct, char ** a_v) { if (! SUCCESSFUL(validate_struct(opts, a_v[0]))) ao_bug(zbad_data_msg); /* * Establish the real program name, the program full path, * and do all the presetting the first time thru only. */ if (! ao_initialize(opts, a_ct, a_v)) return 0; /* * IF we are (re)starting, * THEN reset option location */ if (opts->curOptIdx <= 0) { opts->curOptIdx = 1; opts->pzCurOpt = NULL; } if (! SUCCESSFUL(regular_opts(opts))) return (int)opts->origArgCt; /* * IF there were no errors * AND we have RC/INI files * AND there is a request to save the files * THEN do that now before testing for conflicts. * (conflicts are ignored in preset options) */ switch (opts->specOptIdx.save_opts) { case 0: case NO_EQUIVALENT: break; default: { tOptDesc * od = opts->pOptDesc + opts->specOptIdx.save_opts; if (SELECTED_OPT(od)) { optionSaveFile(opts); option_exits(EXIT_SUCCESS); } } } /* * IF we are checking for errors, * THEN look for too few occurrences of required options */ if (((opts->fOptSet & OPTPROC_ERRSTOP) != 0) && (! is_consistent(opts))) (*opts->pUsageProc)(opts, EXIT_FAILURE); return (int)opts->curOptIdx; }
void init_ao( session_t *sess ) { if( ao_thread != 0 ) return; ao_initialize(); output_buffer_size = 4 * (sess->frame_size+3); output_buffer = malloc(output_buffer_size); int driver; if (libao_driver) { // if a libao driver is specified on the command line, use that driver = ao_driver_id(libao_driver); if (driver == -1) { debugp( DEBUGP_DEFAULT, 0, "Could not find requested ao driver" ); kill( getpid(), SIGINT ); } } else { // otherwise choose the default driver = ao_default_driver_id(); } ao_sample_format fmt; memset(&fmt, 0, sizeof(fmt)); fmt.bits = 16; fmt.rate = sess->sample_rate; fmt.channels = NUM_CHANNELS; fmt.byte_format = AO_FMT_NATIVE; ao_option *ao_opts = NULL; if(libao_deviceid) { ao_append_option(&ao_opts, "id", libao_deviceid); } else if(libao_devicename){ ao_append_option(&ao_opts, "dev", libao_devicename); // Old libao versions (for example, 0.8.8) only support // "dsp" instead of "dev". ao_append_option(&ao_opts, "dsp", libao_devicename); } dev = ao_open_live(driver, &fmt, ao_opts); if (dev == NULL) { debugp( DEBUGP_DEFAULT, 0, "Could not open ao device (%d)", errno); kill( getpid(), SIGINT ); } if(pthread_create( &ao_thread, NULL, ao_thread_func, NULL )) { debugp( DEBUGP_DEFAULT, 0, "Could not start ao_thread\n" ); kill( getpid(), SIGINT ); } return; }
static ad_device_data * sound_ao_create(Lisp_Object ao_options) { int driver; ao_device *device; ao_option *options; ao_sample_format *fmt; /* result */ sound_ao_data_t *aod; /* option keywords */ Lisp_Object opt_driver; char *optext_driver = NULL; /* parse options */ opt_driver = Fplist_get(ao_options, intern(":driver"), Qnil); if (!NILP(opt_driver) && !STRINGP(opt_driver)) { wrong_type_argument(Qstringp, opt_driver); return NULL; } else if (STRINGP(opt_driver)) optext_driver = (char*)XSTRING_DATA(opt_driver); /* -- initialise -- */ ao_initialize(); fmt = xmalloc(sizeof(ao_sample_format)); /* -- Setup for driver -- */ if (optext_driver != NULL) driver = ao_driver_id(optext_driver); else driver = ao_default_driver_id(); /* just some generics */ fmt->channels = 2; fmt->rate = 44100; fmt->bits = 16; fmt->byte_format = AO_FMT_LITTLE; options = NULL; /* -- Open driver -- */ device = ao_open_live(driver, fmt, options); if (device == NULL) { message(GETTEXT("audio-ao: Unsupported driver.")); xfree(fmt); aod = NULL; } else { aod = xnew_and_zero(sound_ao_data_t); aod->ad = device; aod->options = NULL; aod->fmt = fmt; aod->driver_id = driver; } return aod; }
void gp2x_init(void) { printf("KEYBOARD = %d\n", OpenKeyboard()); printf("GRAPHICS = %d\n", EnterGraphicsMode()); printf("entering init()\n"); fflush(stdout); gp2x_screen = malloc(320*240*2 + 320*2); memset(gp2x_screen, 0, 320*240*2 + 320*2); struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; // Open the file for reading and writing fbfd = open("/dev/fb0", O_RDWR); if (!fbfd) { printf("Error: cannot open framebuffer device.\n"); exit(1); } printf("The framebuffer device was opened successfully.\n"); // Get fixed screen information if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { printf("Error reading fixed information.\n"); exit(2); } // Get variable screen information if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error reading variable information.\n"); exit(3); } printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel ); // Figure out the size of the screen in bytes screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; // Map the device to memory fbp = (unsigned short *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory.\n"); exit(4); } printf("The framebuffer device was mapped to memory successfully.\n"); memset(fbp, 0, screensize); inputfd = open("/dev/event0", O_RDWR | O_NONBLOCK); // snd ao_initialize(); //while(jz_lcdregl[0xa8>>2] & 1); //jz_lcdregl[0xa4>>2] = 0; //printf("PGIOD = %x\n", jz_gpioregl[0x300>>2]); }
void aoinit(unsigned char *driver) { printf("- initialize audio device\n"); ao_initialize(); if(driver) { ao_driver = (ao_driver < 0) ? atoi(driver) : ao_driver_id(driver); } else { ao_driver = ao_default_driver_id(); } if(ao_driver < 0) ao_error(driver); }
cAudio::cAudio(void *, void *, void *) { thread_started = false; if (!HAL_nodec) dmxbuf = (uint8_t *)malloc(DMX_BUF_SZ); bufpos = 0; curr_pts = 0; gThiz = this; ao_initialize(); }
VoxPlayer::VoxPlayer() { pthread_mutex_init(&m_cs, NULL); mpg123_init(); ao_initialize(); m_playpath = ""; m_isplaying = false; m_interrupt = false; setThreadName("PLAY"); }
int main(int argc, char **argv) { fd_set read_fd_set; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; int input_fd = serial_init("/dev/tty.usbserial-A4013GAY", 9600); // int input_fd = STDIN_FILENO; // -- Initialize -- // ao_initialize(); sin_init(); mp3_init("hey.mp3", "ho.mp3"); write(input_fd, "s", 1); for (;;) { FD_ZERO(&read_fd_set); FD_SET(input_fd, &read_fd_set); if (select(FD_SETSIZE, &read_fd_set, NULL, NULL, &tv) < 0) { perror("select"); exit(1); } if (FD_ISSET(input_fd, &read_fd_set)) { handleInput(input_fd); } switch (global_mode) { case SQUARE_WAVE_MODE: case SAWTOOTH_WAV_MODE: case MP3_MODE: mp3_play(); break; case SIN_WAVE_MODE: default: sin_play(); break; } } ao_shutdown(); return 0; }
struct AOutput * aout_init(void) { struct AOutput * ao = (struct AOutput *) malloc(sizeof(struct AOutput)); ao_initialize(); ao->default_driver = ao_default_driver_id(); ao->format.bits = 16; ao->format.channels = 2; ao->format.rate = 44100; ao->format.byte_format = AO_FMT_LITTLE; ao->format.matrix = "L,R"; ao->device = ao_open_live(ao->default_driver, &(ao->format), NULL); return ao; }
static int open_output(void) { int driver_id; ao_initialize(); if (dpm.name == NULL) { driver_id = ao_default_driver_id(); } else { ao_info *device; driver_id = ao_driver_id(dpm.name); if ((device = ao_driver_info(driver_id)) == NULL) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: driver is not supported.", dpm.name); return -1; } if (device->type == AO_TYPE_FILE) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: file output is not supported.", dpm.name); return -1; } } if (driver_id == -1) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s", dpm.name, strerror(errno)); return -1; } /* They can't mean these */ dpm.encoding &= ~(PE_ULAW|PE_ALAW|PE_BYTESWAP); ao_sample_format_ctx.channels = (dpm.encoding & PE_MONO) ? 1 : 2; ao_sample_format_ctx.rate = dpm.rate; ao_sample_format_ctx.byte_format = AO_FMT_NATIVE; ao_sample_format_ctx.bits = (dpm.encoding & PE_24BIT) ? 24 : 0; ao_sample_format_ctx.bits = (dpm.encoding & PE_16BIT) ? 16 : 0; if (ao_sample_format_ctx.bits == 0) ao_sample_format_ctx.bits = 8; if ((ao_device_ctx = ao_open_live(driver_id, &ao_sample_format_ctx, NULL /* no options */)) == NULL) { ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s", dpm.name, strerror(errno)); return -1; } return 0; }
int muroard_driver_init(const char * dev) { ao_sample_format format; int driver; #ifdef HAVE_LIBAO_MATRIX char * map = NULL; #endif ao_initialize(); if ( dev == NULL ) { driver = ao_default_driver_id(); } else { driver = ao_driver_id(dev); } if (driver < 0) return -1; muroard_memzero(&format, sizeof(format)); format.bits = 16; format.channels = muroard_state_member(sa_channels); format.rate = muroard_state_member(sa_rate); format.byte_format = AO_FMT_NATIVE; #ifdef HAVE_LIBAO_MATRIX switch (muroard_state_member(sa_channels)) { case 1: map = "M"; break; case 2: map = "L,R"; break; case 3: map = "L,R,C"; break; case 4: map = "L,R,BL,BR"; break; case 5: map = "L,R,C,BL,BR"; break; case 6: map = "L,R,C,LFE,BL,BR"; break; } if ( map != NULL ) { format.matrix = map; } #endif muroard_state_member(driver_vp) = ao_open_live(driver, &format, NULL /* no options */); if ( muroard_state_member(driver_vp) == NULL ) return -1; return 0; }
int AudioPlayer_AO::pcmSetup() { /* -- Initialize -- */ ao_initialize(); /* -- Setup for default driver -- */ pcm_driver = ao_default_driver_id(); /* -- Open driver -- */ pcm_device = ao_open_live(pcm_driver, &pcm_format, 0 /* no options */); if (pcm_device == 0) { fprintf(stderr, "Error opening device.\n"); return -1; } return 0; }
ao_t* aodev_new(void) { log_debug("new"); static int initialize = 1; if (initialize) { initialize = 0; ao_initialize(); atexit(ao_shutdown); } ao_t* handle = (ao_t*) mc_malloc(sizeof(ao_t)); handle->driver = ao_default_driver_id(); handle->device = NULL; return handle; }
int main(int argc, char** argv) { int d,x; char *samps; //initialise AO ao_device *ao; ao_sample_format form; ao_initialize(); d=ao_default_driver_id(); form.bits=8; form.rate=DDS_FREQ; form.channels=1; form.byte_format=AO_FMT_NATIVE; #ifdef TO_FILE ao=ao_open_file(ao_driver_id("wav"),"music.wav",1,&form,NULL); #else ao=ao_open_live(d,&form,NULL); if (ao==NULL) { printf("Error opening device %d\n"); exit(0); } #endif //Libao is opened and initialised now. //allocate sample buffer samps=malloc(AO_BUFF); d=0; //reset player player_reset(); while(1) { //generate AO_BUFF samples, advance the player 60 times per second for (x=0; x<AO_BUFF; x++) { d++; if (d>(DDS_FREQ/PLAYER_FREQ)) { d=0; player_tick(); } samps[x]=dds_get_next_sample()<<5; } //let libao play the samples ao_play(ao,samps,AO_BUFF); } //never happens because the while() above ao_close(ao); ao_shutdown(); }
int register_aplayer() { // starts the audio relates structures, allowing // sound to be "played" ao_initialize(); // starts the registration of the audio subsystem // by registering all the resources av_register_all(); #ifdef _DEBUG av_log_set_level(AV_LOG_DEBUG); #else av_log_set_level(AV_LOG_ERROR); #endif return 0; }
void play(FILE *fp) { struct stream data; struct mad_decoder dec; memset(&data, 0, sizeof data); data.fp = fp; if(NULL == data.fp) { fprintf(stderr, "stream is null\n"); return; } ao_initialize(); data.driver_id = ao_default_driver_id(); if(-1 == data.driver_id) { fprintf(stderr, "no driver has been found: %s", strerror(errno)); return; } data.fmt.bits = 16; data.fmt.rate = 44100; data.fmt.channels = 2; data.fmt.byte_format = AO_FMT_NATIVE; data.device = ao_open_live(data.driver_id, &data.fmt, NULL); if(NULL == data.device) { fprintf(stderr, "unable to open device: %s", strerror(errno)); return; } mad_decoder_init(&dec, &data, input, NULL, NULL, output, NULL, NULL); mad_decoder_run(&dec, MAD_DECODER_MODE_SYNC); mad_decoder_finish(&dec); ao_close(data.device); ao_shutdown(); }
int audio_init(int frequency, int buffer_time) { int driver; ao_sample_format format; ao_initialize(); format.bits = UADE_BYTES_PER_SAMPLE * 8; format.channels = UADE_CHANNELS; format.rate = frequency; format.byte_format = AO_FMT_NATIVE; driver = ao_default_driver_id(); if (buffer_time > 0) { char val[32]; snprintf(val, sizeof val, "%d", buffer_time); libao_device = ao_open_live(driver, &format, & (ao_option) { .key = "buffer_time", .value = val });
int AoEngine::doInit(const int rate, unsigned /*latency*/) { ao_initialize(); aoDevice = NULL; ao_sample_format sampleFormat = { 16, rate, 2, AO_FMT_NATIVE }; int aoDriverId = ao_default_driver_id(); if (aoDriverId != -1) { aoDevice = ao_open_live(aoDriverId, &sampleFormat, NULL); } if (aoDevice == NULL) { ao_shutdown(); return -1; } return sampleFormat.rate; }