void al_sourceplayv( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { if (NULL == alSourcePlayv) mogl_glunsupported("alSourcePlayv"); alSourcePlayv((ALsizei)mxGetScalar(prhs[0]), (const ALuint*)mxGetData(prhs[1])); }
//------------------------------------------------------------ void ofOpenALSoundPlayer::setPaused(bool bP){ if(sources.empty()) return; if(bP){ alSourcePausev(sources.size(),&sources[0]); }else{ alSourcePlayv(sources.size(),&sources[0]); } bPaused = bP; }
//------------------------------------------------------------ void ofOpenALSoundPlayer::threadedFunction(){ vector<vector<short> > multibuffer; multibuffer.resize(channels); while(isThreadRunning()){ cout << "threaded function" << endl; for(int i=0; i<int(sources.size())/channels; i++){ int processed; alGetSourcei(sources[i*channels], AL_BUFFERS_PROCESSED, &processed); while(processed--) { stream("",buffer); int numFrames = buffer.size()/channels; if(channels>1){ for(int j=0;j<channels;j++){ multibuffer[j].resize(buffer.size()/channels); for(int k=0;k<numFrames;k++){ multibuffer[j][k] = buffer[k*channels+j]; } ALuint albuffer; alSourceUnqueueBuffers(sources[i*channels+j], 1, &albuffer); alBufferData(albuffer,AL_FORMAT_MONO16,&multibuffer[j][0],buffer.size()*2/channels,samplerate); alSourceQueueBuffers(sources[i*channels+j], 1, &albuffer); } }else{ ALuint albuffer; alSourceUnqueueBuffers(sources[i], 1, &albuffer); alBufferData(albuffer,AL_FORMAT_MONO16,&buffer[0],buffer.size()*2/channels,samplerate); alSourceQueueBuffers(sources[i], 1, &albuffer); } if(stream_end){ break; } } ALint state; alGetSourcei(sources[i*channels],AL_SOURCE_STATE,&state); bool stream_running=false; //#ifdef OF_USING_MPG123 // stream_running = streamf || mp3streamf; //#else stream_running = streamf; //#endif if(state != AL_PLAYING && stream_running && !stream_end){ alSourcePlayv(channels,&sources[i*channels]); } stream_end = false; } timeSet = false; ofSleepMillis(1); } }
value lime_al_source_playv (value n, value sources) { int *data = val_array_int (sources); if (data) { alSourcePlayv (val_int (n), (ALuint*)data); } return alloc_null (); }
// ---------------------------------------------------------------------------- void ofOpenALSoundPlayer::play(){ std::unique_lock<std::mutex> lock(mutex); int err = glGetError(); // if the sound is set to multiplay, then create new sources, // do not multiplay on loop or we won't be able to stop it if (bMultiPlay && !bLoop){ sources.resize(sources.size()+channels); alGetError(); // Clear error. alGenSources(channels, &sources[sources.size()-channels]); err = alGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "play(): couldn't create multiplay stereo sources: " << (int) err << " " << getALErrorString(err); return; } for(int i=0;i<channels;i++){ alSourcei (sources[sources.size()-channels+i], AL_BUFFER, buffers[i] ); // only stereo panning if(i==0){ float pos[3] = {-1,0,0}; alSourcefv(sources[sources.size()-channels+i],AL_POSITION,pos); }else{ float pos[3] = {1,0,0}; alSourcefv(sources[sources.size()-channels+i],AL_POSITION,pos); } alSourcef (sources[sources.size()-channels+i], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[sources.size()-channels+i], AL_SOURCE_RELATIVE, AL_TRUE); } err = glGetError(); if (err != AL_NO_ERROR){ ofLogError("ofOpenALSoundPlayer") << "play(): couldn't assign multiplay buffers: " << (int) err << " " << getALErrorString(err); return; } } alSourcePlayv(channels,&sources[sources.size()-channels]); if(bMultiPlay){ ofAddListener(ofEvents().update,this,&ofOpenALSoundPlayer::update); } if(isStreaming){ setPosition(0); stream_end = false; startThread(true); } }
//------------------------------------------------------------ void ofOpenALSoundPlayer::setPaused(bool bP){ if(sources.empty()) return; if(bP){ alSourcePausev(sources.size(),&sources[0]); if(isStreaming){ stopThread(); } }else{ alSourcePlayv(sources.size(),&sources[0]); if(isStreaming){ startThread(); } } bPaused = bP; }
// ---------------------------------------------------------------------------- void ofOpenALSoundPlayer::play(){ // if the sound is set to multiplay, then create new sources, // do not multiplay on loop or we won't be able to stop it if (bMultiPlay && !bLoop){ sources.resize(sources.size()+channels); alGenSources(channels, &sources[sources.size()-channels]); if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: error creating multiplay stereo sources"); return; } for(int i=0;i<channels;i++){ alSourcei (sources[sources.size()-channels+i], AL_BUFFER, buffers[i] ); // only stereo panning if(i==0){ float pos[3] = {-1,0,0}; alSourcefv(sources[sources.size()-channels+i],AL_POSITION,pos); }else{ float pos[3] = {1,0,0}; alSourcefv(sources[sources.size()-channels+i],AL_POSITION,pos); } alSourcef (sources[sources.size()-channels+i], AL_ROLLOFF_FACTOR, 0.0); alSourcei (sources[sources.size()-channels+i], AL_SOURCE_RELATIVE, AL_TRUE); } if (alGetError() != AL_NO_ERROR){ ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: error assigning multiplay buffers"); return; } } alSourcePlayv(channels,&sources[sources.size()-channels]); // if(bMultiPlay){ ofAddListener(ofEvents().update,this,&ofOpenALSoundPlayer::update); // } if(isStreaming){ setPosition(0); stream_end = false; startThread(true,false); } }
/** * \brief write data into buffer and reset underrun flag */ static int play(struct ao *ao, void **data, int samples, int flags) { struct priv *p = ao->priv; ALint state; int num = samples / CHUNK_SAMPLES; for (int i = 0; i < num; i++) { for (int ch = 0; ch < ao->channels.num; ch++) { char *d = data[ch]; d += i * p->chunk_size; alBufferData(buffers[ch][cur_buf[ch]], p->al_format, d, p->chunk_size, ao->samplerate); alSourceQueueBuffers(sources[ch], 1, &buffers[ch][cur_buf[ch]]); cur_buf[ch] = (cur_buf[ch] + 1) % NUM_BUF; } } alGetSourcei(sources[0], AL_SOURCE_STATE, &state); if (state != AL_PLAYING) // checked here in case of an underrun alSourcePlayv(ao->channels.num, sources); return num * CHUNK_SAMPLES; }
void lime_al_source_playv (int n, value sources) { if (val_is_null (sources) == false) { int size = val_array_size (sources); ALuint* data = new ALuint[size]; for (int i = 0; i < size; ++i) { data[i] = (ALuint)val_int( val_array_i (sources, i) ); } alSourcePlayv (n, data); delete[] data; } }
/** * \brief write data into buffer and reset underrun flag */ static int play(void *data, int len, int flags) { ALint state; int i, j, k; int ch; int16_t *d = data; len /= ao_data.channels * CHUNK_SIZE; for (i = 0; i < len; i++) { for (ch = 0; ch < ao_data.channels; ch++) { for (j = 0, k = ch; j < CHUNK_SIZE / 2; j++, k += ao_data.channels) tmpbuf[j] = d[k]; alBufferData(buffers[ch][cur_buf[ch]], AL_FORMAT_MONO16, tmpbuf, CHUNK_SIZE, ao_data.samplerate); alSourceQueueBuffers(sources[ch], 1, &buffers[ch][cur_buf[ch]]); cur_buf[ch] = (cur_buf[ch] + 1) % NUM_BUF; } d += ao_data.channels * CHUNK_SIZE / 2; } alGetSourcei(sources[0], AL_SOURCE_STATE, &state); if (state != AL_PLAYING) // checked here in case of an underrun alSourcePlayv(ao_data.channels, sources); return len * ao_data.channels * CHUNK_SIZE; }
//***************************************************************************** // alSourcePlayv //***************************************************************************** // ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint* sourceNames) { AL_VOID_FXN(alSourcePlayv(n, sourceNames)); }
int main (int argc, const char * argv[]) { MyStreamPlayer player; // prepare the ExtAudioFile for reading CheckError(setUpExtAudioFile(&player), "Couldn't open ExtAudioFile") ; // set up OpenAL buffers ALCdevice* alDevice = alcOpenDevice(NULL); CheckALError ("Couldn't open AL device"); // default device ALCcontext* alContext = alcCreateContext(alDevice, 0); CheckALError ("Couldn't open AL context"); alcMakeContextCurrent (alContext); CheckALError ("Couldn't make AL context current"); ALuint buffers[BUFFER_COUNT]; alGenBuffers(BUFFER_COUNT, buffers); CheckALError ("Couldn't generate buffers"); for (int i=0; i<BUFFER_COUNT; i++) { fillALBuffer(&player, buffers[i]); } // set up streaming source alGenSources(1, player.sources); CheckALError ("Couldn't generate sources"); alSourcef(player.sources[0], AL_GAIN, AL_MAX_GAIN); CheckALError("Couldn't set source gain"); updateSourceLocation(player); CheckALError ("Couldn't set initial source position"); // queue up the buffers on the source alSourceQueueBuffers(player.sources[0], BUFFER_COUNT, buffers); CheckALError("Couldn't queue buffers on source"); // set up listener alListener3f (AL_POSITION, 0.0, 0.0, 0.0); CheckALError("Couldn't set listner position"); // start playing alSourcePlayv (1, player.sources); CheckALError ("Couldn't play"); // and wait printf("Playing...\n"); time_t startTime = time(NULL); do { // get next theta updateSourceLocation(player); CheckALError ("Couldn't set source position"); // refill buffers if needed refillALBuffers (&player); CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, false); } while (difftime(time(NULL), startTime) < RUN_TIME); // cleanup: alSourceStop(player.sources[0]); alDeleteSources(1, player.sources); alDeleteBuffers(BUFFER_COUNT, buffers); alcDestroyContext(alContext); alcCloseDevice(alDevice); printf ("Bottom of main\n"); }
/** * \brief resume playing, after audio_pause() */ static void audio_resume(struct ao *ao) { alSourcePlayv(ao->channels.num, sources); }
int main( int argc, char* argv[] ) { ALCdevice *dev; time_t shouldend; int attrlist[] = { ALC_FREQUENCY, DEFFREQ, ALC_INVALID }; char *musicitr = musicstr; ALfloat pitch = 1.0; int beats; char note; int i; dev = alcOpenDevice( NULL ); if( dev == NULL ) { return 1; } cc = alcCreateContext( dev, attrlist); if(cc == NULL) { alcCloseDevice( dev ); return 1; } alcMakeContextCurrent( cc ); fixup_function_pointers(); if(argc == 1) { init(WAVEFILE); } else { init(argv[1]); } while(*musicitr) { alSourceStop( chords[0] ); alSourceStop( chords[1] ); alSourceStop( chords[2] ); while(*musicitr == ' ') { musicitr++; } for(i = 0; i < 3; i++) { switch(*musicitr) { case 'c': pitch = 0.500010; break; case 'd': pitch = 0.561223; break; case 'e': pitch = 0.629967; break; case 'f': pitch = 0.667425; break; case 'g': pitch = 0.749164; break; case 'a': pitch = 0.840898; break; case 'b': pitch = 0.943870; break; case 'C': pitch = 1.0; break; case 'D': pitch = 1.122465; break; case 'E': pitch = 1.259933; break; case 'F': pitch = 1.339704; break; case 'G': pitch = 1.498309; break; case 'A': pitch = 1.681796; break; case 'B': pitch = 1.897754; break; default: fprintf(stderr, "unknown note %d\n", *musicitr); break; } note = *musicitr; musicitr++; /* skip note */ fprintf(stderr, "chord[%d] = %c\n", i, note); alSourcef(chords[i], AL_PITCH, pitch); } alSourcePlayv(3, chords); while(*musicitr == ' ') { musicitr++; } beats = (int) *musicitr - '0'; musicitr++; fprintf(stderr, "beats %d\n", beats); micro_sleep(beats / 4.0 * 1000000); } alcDestroyContext( cc ); alcCloseDevice( dev ); cleanup(); return 0; }
static PyObject* _sources_action (PyObject *self, PyObject *args, SourcesAction action) { unsigned int source; if (!CONTEXT_IS_CURRENT (((PySources*)self)->context)) { PyErr_SetString (PyExc_PyGameError, "source context is not current"); return NULL; } if (PySequence_Check (args)) { ALuint *sources; Py_ssize_t i; Py_ssize_t len = PySequence_Size (args); if (len > ((PySources*)self)->count) { PyErr_SetString (PyExc_ValueError, "sequence size exceeds the available sources"); return NULL; } sources = PyMem_New (ALuint, (ALsizei) len); if (!sources) return NULL; for (i = 0; i < len; i++) { if (!UintFromSeqIndex (args, i, &source)) { PyMem_Free (sources); return NULL; } sources[i] = source; } CLEAR_ALERROR_STATE (); switch (action) { case PLAY: alSourcePlayv ((ALsizei) len, sources); break; case PAUSE: alSourcePausev ((ALsizei) len, sources); break; case STOP: alSourceStopv ((ALsizei) len, sources); break; case REWIND: alSourceRewindv ((ALsizei) len, sources); break; default: break; } PyMem_Free (sources); if (SetALErrorException (alGetError (), 0)) return NULL; Py_RETURN_NONE; } else if (UintFromObj (args, &source)) { CLEAR_ALERROR_STATE (); switch (action) { case PLAY: alSourcePlay ((ALuint)source); break; case PAUSE: alSourcePause ((ALuint)source); break; case STOP: alSourceStop ((ALuint)source); break; case REWIND: alSourceRewind ((ALuint)source); break; } if (SetALErrorException (alGetError (), 0)) return NULL; Py_RETURN_NONE; } PyErr_SetString (PyExc_TypeError, "argument must be a sequence or positive integer"); return NULL; }
/** * \brief resume playing, after audio_pause() */ static void audio_resume(void) { alSourcePlayv(ao_data.channels, sources); }
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL10_nalSourcePlayv(JNIEnv *__env, jclass clazz, jint n, jlong sourcesAddress, jlong __functionAddress) { const ALuint *sources = (const ALuint *)(intptr_t)sourcesAddress; alSourcePlayvPROC alSourcePlayv = (alSourcePlayvPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) alSourcePlayv(n, sources); }
ALvoid CDECL wine_alSourcePlayv(ALsizei ns, const ALuint *sids) { alSourcePlayv(ns, sids); }