int fm_player_open(fm_player_t *pl, fm_player_config_t *config) { pl->config = *config; if (strcmp(config->driver, "pifm") == 0) { float f = atof(config->dev); if (f < 1) f = 102.4; printf("Player audio driver: pifm\n"); printf("Player sample rate: %d Hz\n", config->rate); printf("Player FM fequency: %f Hz\n", f); config->channels = 1; fm_setup_fm(); fm_setup_dma(f); } else { ao_sample_format ao_fmt; ao_fmt.rate = config->rate; ao_fmt.channels = config->channels; ao_fmt.bits = mpg123_encsize(config->encoding) * 8; ao_fmt.byte_format = AO_FMT_NATIVE; ao_fmt.matrix = 0; int driver = ao_driver_id(config->driver); if (driver == -1) { return -1; } ao_info *driver_info = ao_driver_info(driver); printf("Player audio driver: %s\n", driver_info->name); printf("Player sample rate: %d Hz\n", pl->config.rate); ao_option *options = NULL; if (config->dev[0] != '\0') { ao_append_option(&options, "dev", config->dev); } pl->dev = ao_open_live(driver, &ao_fmt, options); ao_free_options(options); if (pl->dev == NULL) return -1; } pl->mh = mpg123_new(NULL, NULL); mpg123_format_none(pl->mh); mpg123_format(pl->mh, config->rate, config->channels, config->encoding); pl->curl = curl_easy_init(); curl_easy_setopt(pl->curl, CURLOPT_WRITEFUNCTION, download_callback); curl_easy_setopt(pl->curl, CURLOPT_WRITEDATA, pl); pl->tid_ack = 0; pthread_mutex_init(&pl->mutex_status, NULL); pthread_cond_init(&pl->cond_play, NULL); pl->status = FM_PLAYER_STOP; return 0; }
static ao_device * audio_open_device(shairplay_options_t *opt, int bits, int channels, int samplerate) { ao_device *device = NULL; ao_option *ao_options = NULL; ao_sample_format format; int driver_id; /* Get the libao driver ID */ if (strlen(opt->ao_driver)) { driver_id = ao_driver_id(opt->ao_driver); } else { driver_id = ao_default_driver_id(); } /* Add all available libao options */ if (strlen(opt->ao_devicename)) { ao_append_option(&ao_options, "dev", opt->ao_devicename); } if (strlen(opt->ao_deviceid)) { ao_append_option(&ao_options, "id", opt->ao_deviceid); } /* Set audio format */ memset(&format, 0, sizeof(format)); format.bits = bits; format.channels = channels; format.rate = samplerate; format.byte_format = AO_FMT_NATIVE; /* Try opening the actual device */ device = ao_open_live(driver_id, &format, ao_options); ao_free_options(ao_options); return device; }
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; }
ao_device *init_ao(AVCodecContext *codec_ctx) { int driver = ao_default_driver_id(); ao_sample_format sformat; AVSampleFormat sample_format = codec_ctx->sample_fmt; switch(sample_format) { case AV_SAMPLE_FMT_U8: sformat.bits = 8; break; case AV_SAMPLE_FMT_S16: sformat.bits = 16; break; case AV_SAMPLE_FMT_S32: sformat.bits = 32; break; default: sformat.bits = 8; break; } sformat.channels = codec_ctx->channels; sformat.rate = codec_ctx->sample_rate; sformat.byte_format = AO_FMT_NATIVE; sformat.matrix = 0; ao_device *device = ao_open_live(driver, &sformat, NULL); return device; }
BOOL wave_out_set_format(WAVEFORMATEX * pwfx) { ao_sample_format format; format.bits = pwfx->wBitsPerSample; format.channels = pwfx->nChannels; g_channels = pwfx->nChannels; format.rate = 44100; g_samplerate = pwfx->nSamplesPerSec; format.byte_format = AO_FMT_LITTLE; g_samplewidth = pwfx->wBitsPerSample / 8; if (o_device != NULL) ao_close(o_device); o_device = ao_open_live(default_driver, &format, NULL); if (o_device == NULL) { return False; } g_reopened = True; return True; }
RD_BOOL libao_set_format(RD_WAVEFORMATEX * pwfx) { ao_sample_format format; memset(&format, 0, sizeof(format)); format.bits = pwfx->wBitsPerSample; format.channels = pwfx->nChannels; format.rate = 44100; format.byte_format = AO_FMT_NATIVE; if (o_device != NULL) ao_close(o_device); o_device = ao_open_live(default_driver, &format, NULL); if (o_device == NULL) { return False; } if (rdpsnd_dsp_resample_set(44100, pwfx->wBitsPerSample, pwfx->nChannels) == False) { return False; } reopened = True; return True; }
int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le) { lt_debug("%s ch %d srate %d bits %d le %d adevice %p\n", __func__, ch, srate, bits, le, adevice);; int driver; int byte_format = le ? AO_FMT_LITTLE : AO_FMT_BIG; if (sformat.bits != bits || sformat.channels != ch || sformat.rate != srate || sformat.byte_format != byte_format || adevice == NULL) { driver = ao_default_driver_id(); sformat.bits = bits; sformat.channels = ch; sformat.rate = srate; sformat.byte_format = byte_format; sformat.matrix = 0; if (adevice) ao_close(adevice); adevice = ao_open_live(driver, &sformat, NULL); ao_info *ai = ao_driver_info(driver); lt_info("%s: changed params ch %d srate %d bits %d le %d adevice %p\n", __func__, ch, srate, bits, le, adevice);; lt_info("libao driver: %d name '%s' short '%s' author '%s'\n", driver, ai->name, ai->short_name, ai->author); } 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; }
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; }
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; }
size_t play_stream(void *buffer, size_t size, size_t nmemb, void *userp) { int err; off_t frame_offset; unsigned char *audio; size_t done; ao_sample_format format; int channels, encoding; long rate; mpg123_feed(mh, (const unsigned char*) buffer, size * nmemb); do { err = mpg123_decode_frame(mh, &frame_offset, &audio, &done); switch(err) { case MPG123_NEW_FORMAT: mpg123_getformat(mh, &rate, &channels, &encoding); format.bits = mpg123_encsize(encoding) * BITS; format.rate = rate; format.channels = channels; format.byte_format = AO_FMT_NATIVE; format.matrix = 0; dev = ao_open_live(ao_default_driver_id(), &format, NULL); break; case MPG123_OK: ao_play(dev, audio, done); break; case MPG123_NEED_MORE: break; default: break; } } while(done > 0); return size * nmemb; }
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; }
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; }
void aoinit_fmt(int channels, int frequency) { format.bits = 16; format.channels = channels; format.rate = frequency; format.byte_format = AO_FMT_LITTLE; device = ao_open_live(ao_driver, &format, NULL); if(!device) ao_error(""); }
void au_playWait(int snd){ if(!mute || effects){ //need to repeat this code because au_deinitEach() calls exit(); default_driver = ao_default_driver_id(); device = ao_open_live(default_driver, &format, NULL); ao_play(device, sounds[snd], sz[snd]); ao_close(device); } }
void mp3_init(char *mp3_file_0, char *mp3_file_1) { int err; int channels, encoding; long rate; mpg123_init(); mh_0 = mpg123_new(NULL, &err); mp3_buffer_size = mpg123_outblock(mh_0); mp3_buffer = malloc(mp3_buffer_size * sizeof(unsigned char)); mpg123_open(mh_0, mp3_file_0); mpg123_getformat(mh_0, &rate, &channels, &encoding); printf("0: %s: rate: %ld channels: %d encoding: %d\n", mp3_file_0, rate, channels, encoding); memset(&mp3_format, 0, sizeof(mp3_format)); mp3_format.bits = mpg123_encsize(encoding) * 8; mp3_format.channels = channels; mp3_format.rate = rate; // -- Open driver -- // mp3_device_0 = ao_open_live(ao_default_driver_id(), &mp3_format, NULL); // no options if (mp3_device_0 == NULL) { fprintf(stderr, "Error opening device 0 .\n"); } mh_1 = mpg123_new(NULL, &err); mpg123_open(mh_1, mp3_file_1); mpg123_getformat(mh_1, &rate, &channels, &encoding); printf("1: %s: rate: %ld channels: %d encoding: %d\n", mp3_file_1, rate, channels, encoding); memset(&mp3_format, 0, sizeof(mp3_format)); mp3_format.bits = mpg123_encsize(encoding) * 8; mp3_format.channels = channels; mp3_format.rate = rate; // -- Open driver -- // mp3_device_1 = ao_open_live(ao_default_driver_id(), &mp3_format, NULL); // no options if (mp3_device_1 == NULL) { fprintf(stderr, "Error opening device 1.\n"); } }
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; }
static enum mad_flow output( void * data, const struct mad_header * head, struct mad_pcm * pcm) { struct stream * ptr = (struct stream *) data; unsigned nchan = pcm->channels, rate = pcm->samplerate; register unsigned nsample = pcm->length; mad_fixed_t * left = pcm->samples[0], * right = pcm->samples[1]; char *stream, *stream_ptr; head = NULL; if((signed) rate != ptr->fmt.rate || (signed) nchan != ptr->fmt.channels) { ptr->fmt.rate = rate; ptr->fmt.channels = nchan; if(ptr->device != NULL) ao_close(ptr->device); ptr->device = ao_open_live(ptr->driver_id, & ptr->fmt, NULL); if(NULL == ptr->device) { fprintf(stderr, "Unable to open device. %s.\n", strerror(errno)); return MAD_FLOW_BREAK; } } stream_ptr = stream = malloc(pcm->length * (pcm->channels == 2 ? 4 : 2)); assert(stream != NULL); read_from_pipe(ptr->pipefd); while(nsample--) { signed int sample; sample = scale(* left++); /* to byteswap or not to byteswap? */ #ifdef WORDS_BIGENDIAN *stream_ptr++ = (sample >> 8) & 0xFF; *stream_ptr++ = (sample & 0xFF); #else *stream_ptr++ = (sample & 0xFF); *stream_ptr++ = (sample >> 8) & 0xFF; #endif if(nchan == 2) { sample = scale(* right++); #ifdef WORDS_BIGENDIAN *stream_ptr++ = (sample >> 8) & 0xFF; *stream_ptr++ = (sample & 0xFF); #else *stream_ptr++ = (sample & 0xFF); *stream_ptr++ = (sample >> 8) & 0xFF; #endif } }
void output_ao::open() { /* connection already established */ if (is_open()) { return; } device = ao_open_live(driver, &format, options); if (device == NULL) { throw output_error(ao_strerror(errno)); } }
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; }
void play_sampled (char *data, size_t len) { ao_device *device = ao_open_live(DEFAULT, &format, NULL); if (!device) { LOGE("%p (could not open audio device)", (void *) (device)); return; } if (!ao_play(device, data, len)) { LOGE("%p (device could not play sample)", (void *) (device)); } if (!ao_close(device)) { LOGW("%p (could not close audio device)", (void *) (device)); } }
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; }
/* Opens the audio device with the appropriate parameters */ static int set_sample_format(VGMSTREAM *vgms) { ao_sample_format format; memset(&format, 0, sizeof(format)); format.bits = 8 * sizeof(sample); format.channels = vgms->channels; format.rate = vgms->sample_rate; format.byte_format = #ifdef LITTLE_ENDIAN_OUTPUT AO_FMT_LITTLE #else AO_FMT_BIG #endif ; if (memcmp(&format, ¤t_sample_format, sizeof(format))) { /* Sample format has changed, so (re-)open audio device */ ao_info *info = ao_driver_info(driver_id); if (!info) return -1; if ((info->type == AO_TYPE_FILE) != !!out_filename) { if (out_filename) fprintf(stderr, "Live output driver \"%s\" does not take an output file\n", info->short_name); else fprintf(stderr, "File output driver \"%s\" requires an output filename\n", info->short_name); return -1; } if (device) ao_close(device); memcpy(¤t_sample_format, &format, sizeof(format)); if (out_filename) device = ao_open_file(driver_id, out_filename, 1, &format, device_options); else device = ao_open_live(driver_id, &format, device_options); if (!device) { fprintf(stderr, "Error opening \"%s\" audio device\n", info->short_name); 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; }
int openOutputDevice() { ao_sample_format aofrmt; memset( &aofrmt, 0, sizeof(ao_sample_format)); aofrmt.bits = SAMPLE_BITS; aofrmt.rate = SAMPLE_RATE; aofrmt.channels = SAMPLE_CHANNELS; aofrmt.byte_format = SAMPLE_FORMAT; closeOutputDevice(); aodev = ao_open_live(aodriverid, &aofrmt, NULL); if ( !aodev ) return -1; return 0; }
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(); }
static enum mad_flow output(void *data, const struct mad_header *header, struct mad_pcm *pcm) { struct stream *ptr = (struct stream *)data; register unsigned nsamples = pcm->length; unsigned nchannels = pcm->channels, rate = pcm->samplerate; const mad_fixed_t *left_ch = pcm->samples[0], *right_ch = pcm->samples[1]; char *stream, *stream_ptr; if((signed)rate != ptr->fmt.rate || (signed)nchannels != ptr->fmt.channels) { ptr->fmt.rate = rate; ptr->fmt.channels = nchannels; if(ptr->device != NULL) { ao_close(ptr->device); } ptr->device = ao_open_live(ptr->driver_id, &ptr->fmt, NULL); if(NULL == ptr->device) { fprintf(stderr, "unable to open device: %s", strerror(errno)); return MAD_FLOW_STOP; } } stream_ptr = stream = malloc(pcm->length * (pcm->channels == 2 ? 4 : 2)); register signed sample; while(nsamples--) { sample = scale(*left_ch++); *stream_ptr++ = (sample >> 0) & 0xFF; *stream_ptr++ = (sample >> 8) & 0xFF; if(2 == nchannels) { sample = scale(*right_ch++); *stream_ptr++ = (sample >> 0) & 0xFF; *stream_ptr++ = (sample >> 8) & 0xFF; } }