const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } int hz = GetDriverParamInt(parm, "hz", 44100); _buffer_size = GetDriverParamInt(parm, "samples", 1024) * hz / 11025; _stream = play_audio_stream(_buffer_size, 16, true, hz, 255, 128); MxInitialize(hz); return NULL; }
static int logg_play_stream(LOGG_Stream* s) { int len; int i; s->current_page = 0; s->playing_page = -1; len = logg_bufsize / (s->stereo ? 2 : 1) / (s->bits / (sizeof(char)*8)); s->audio_stream = play_audio_stream(len, s->bits, s->stereo, s->freq, s->volume, s->pan); if (!s->audio_stream) { return 1; } for (i = 0; i < OGG_PAGES_TO_BUFFER; i++) { s->buf[i] = malloc(logg_bufsize); if (!s->buf[i]) { logg_destroy_stream(s); return 1; } if (read_ogg_data(s) < 0) { return 1; } } return 0; }
int alogg_play_ex_oggstream(ALOGG_OGGSTREAM *ogg, int buffer_len, int vol, int pan, int speed) { int samples; /* continue only if we are not already playing it */ if (alogg_is_playing_oggstream(ogg)) return ALOGG_OK; /* check the buffer is big enough*/ if (buffer_len < 4096) return ALOGG_PLAY_BUFFERTOOSMALL; /* create a new audiostream and play it */ samples = buffer_len / (ogg->stereo ? 2 : 1) / 2; /* / 2 = 16 bits samples */ ogg->audiostream = play_audio_stream(samples, 16, ogg->stereo, ogg->freq, vol, pan); ogg->audiostream_buffer_len = samples * (ogg->stereo ? 2 : 1) * 2; /* * 2 = 16 bits samples */ ogg->wait_for_audio_stop = 0; if (speed != 1000) adjust_sample(ogg->audiostream->samp, vol, pan, speed, TRUE); /* if the user asked for autopolling, install the interrupt now */ if (ogg->auto_polling) { LOCK_FUNCTION(alogg_autopoll_oggstream); install_param_int(&alogg_autopoll_oggstream, (void *)ogg, ogg->auto_poll_speed); } return ALOGG_OK; }
void saPlayStreamedSampleBase( int channel, signed char *data, int len, int freq, int volume, int bits , int pan ){ // This one should leave most of the sync work to allegro int pos; void *buff; // position in the stream unsigned short *dout; signed short *din; int i; if (bits == 8) { fprintf(stderr,"error: Can't play 8 bits\n"); // Just because I don't want to bother with this now. return; } if( audio_sample_rate == 0 || channel >= NUMVOICES ) return; if( SndMachine == NULL ) return; if( !playing[channel] ){ if( stream[channel] ){ stop_audio_stream(stream[channel]); free_audio_stream_buffer(stream[channel]); stream[channel] = NULL; } if (!(stream[channel] = play_audio_stream(len,bits,0,freq,volume,pan))){ return; } playing[channel] = 1; /* use front surface */ // Wait for the buffer to be ready... while (!(buff = get_audio_stream_buffer(stream[channel]))); //print_debug("first stream entry. [%d:%d:%d:%d]\n", channel, len, freq, volume ); } if (!(buff = get_audio_stream_buffer(stream[channel]))) { fprintf(stderr,"init stream impossible : buffer NULL\n"); return; } // fprintf(stderr,"len memcpy : %d\n",len); dout=buff; din = ((signed short*)data); for (i=0; i<len; i+=2) *(dout++) = *(din++)^0x8000; //fprintf(stderr,"set chanel vol = %d\n",volume); }
AL_DUH_PLAYER *al_start_duh(DUH *duh, int n_channels, long pos, float volume, long bufsize, int freq) { AL_DUH_PLAYER *dp; /* This restriction is imposed by Allegro. */ ASSERT(n_channels > 0); ASSERT(n_channels <= 2); if (!duh) return NULL; dp = malloc(sizeof(*dp)); if (!dp) return NULL; dp->flags = ADP_PLAYING; dp->bufsize = bufsize; dp->freq = freq; dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); if (!dp->stream) { free(dp); return NULL; } voice_set_priority(dp->stream->voice, 255); dp->sigrenderer = duh_start_sigrenderer(duh, 0, n_channels, pos); if (!dp->sigrenderer) { stop_audio_stream(dp->stream); free(dp); return NULL; } dp->volume = volume; dp->silentcount = 0; return dp; }
AL_DUH_PLAYER *al_duh_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer, float volume, long bufsize, int freq) { AL_DUH_PLAYER *dp; int n_channels; if (!sigrenderer) return NULL; dp = malloc(sizeof(*dp)); if (!dp) return NULL; n_channels = duh_sigrenderer_get_n_channels(sigrenderer); /* This restriction is imposed by Allegro. */ ASSERT(n_channels > 0); ASSERT(n_channels <= 2); dp->flags = ADP_PLAYING; dp->bufsize = bufsize; dp->freq = freq; dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); if (!dp->stream) { free(dp); return NULL; } voice_set_priority(dp->stream->voice, 255); dp->sigrenderer = sigrenderer; dp->volume = volume; dp->silentcount = 0; return dp; }
const char *SoundDriver_Allegro::Start(const char * const *parm) { if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) { DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error); return "Failed to set up Allegro"; } _allegro_instance_count++; /* Initialise the sound */ if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) { DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error); return "Failed to set up Allegro sound"; } /* Okay, there's no soundcard */ if (digi_card == DIGI_NONE) { DEBUG(driver, 0, "allegro: no sound card found"); return "No sound card found"; } _stream = play_audio_stream(BUFFER_SIZE, 16, true, 44100, 255, 128); MxInitialize(44100); return NULL; }
void CSoundStream::Play () { if (!m_pStream) m_pStream = play_audio_stream(FRAGMENT_SIZE, SOUND_BITS, 1, SOUND_FREQ, 255, 128); }