void OpenALAudio::yield() { /* FIXME: This object causes a frame flip. Looks like a hack that could * use some fixing. */ VgaFrontLock vgaLock; StreamMap::iterator si; for (si = this->streams.begin(); si != this->streams.end();) { ALint state; StreamContext *sc; sc = si->second; if (sc->stream_data()) { ++si; continue; } alGetSourcei(sc->source, AL_SOURCE_STATE, &state); if (state == AL_STOPPED) { delete sc; this->streams.erase(si++); continue; } ++si; } }
/* * in - wav file stream to play. Claims ownership and will delete it. * vol - volume/panning * * return: 1 on success, 0 on failure */ int OpenALAudio::play_long_wav(InputStream *in, const DsVolume &vol) { const int BUFFER_COUNT = 4; StreamContext *sc = NULL; WavStream *ws = NULL; int id; assert(this->wav_init_flag); ws = new WavStream; if (!ws->open(in)) { delete in; goto err; } sc = new StreamContext; if (!sc->init(ws)) goto err; set_source_panning(sc->source, vol.ds_pan); set_source_volume(sc->source, vol.ds_vol + this->wav_volume); if (!check_al()) goto err; sc->stream_data(BUFFER_COUNT); id = unused_key(&this->streams); this->streams[id] = sc; return id; err: delete sc; delete ws; return 0; }