void play() { alSourcePlay(name_); check_error("alSourcePlay (source::play)"); }
void raptorsound() { alSourcePlay(alSource[4]); }
void SoundSource::play() { // Play the source alSourcePlay( uiSource); }
VOID OpenALAudioContext::PlaySource( AUDIO_SOURCE_HANDLER source ) { OpenALSource* pSource = (OpenALSource*)source; alSourcePlay( pSource->GetID() ); }
void dino_sound() { static int n = -1; n = (n + 1) % 5; alSourcePlay(dinoSour[n]); }
void OGGMusic::_thread_play_pause_stop() { int buffers=0; total_reads=0; actual_reads=0; buffer_unqueue = 0; if (_buffer[0]==0) return; while (1) { WaitForSingleObject(_state_changed,500); ResetEvent(_state_changed); switch (_current_playing_state) { case PLAY: nprocessed = 0; EnterCriticalSection(_openal_access); alGetSourcei(_source[0],AL_BUFFERS_PROCESSED,&nprocessed); for (int i=0;i<nprocessed;i++) { buffer_unqueue = 0; alSourceUnqueueBuffers(_source[0],1,&buffer_unqueue); while (actual_reads!=_stream_block_size && actual_reads+total_reads<_sound_data_size) { actual_reads += ov_read(&_ogg_file,_sound_data[0]+actual_reads,_stream_block_size-actual_reads,0,2,1,&bitstream); } total_reads += actual_reads; if (actual_reads!=0) { alBufferData(buffer_unqueue,AL_FORMAT_STEREO16,_sound_data[0],actual_reads,_frequency); alSourceQueueBuffers(_source[0],1,&buffer_unqueue); } actual_reads = 0; ALint sstate; alGetSourcei(_source[0],AL_SOURCE_STATE,&sstate); if (sstate!=AL_PLAYING) { ALint nqueue; alGetSourcei(_source[0],AL_BUFFERS_QUEUED,&nqueue); if (nqueue) { alSourcePlay(_source[0]); } else { _current_playing_state = STOP; SetEvent(_state_changed); } } } LeaveCriticalSection(_openal_access); break; case PAUSE: printf("PAUSING\n"); EnterCriticalSection(_openal_access); alSourceStop(_source[0]); alGetSourcei(_source[0],AL_BUFFERS_QUEUED,&buffers); for (int i=0;i<buffers;i++) alSourceUnqueueBuffers(_source[0],1,&buffer_unqueue); LeaveCriticalSection(_openal_access); _current_playing_state = STANDBY; break; case STOP: printf("STOPING\n"); total_reads = 0; EnterCriticalSection(_openal_access); alSourceStop(_source[0]); alGetSourcei(_source[0],AL_BUFFERS_QUEUED,&buffers); for (int i=0;i<buffers;i++) alSourceUnqueueBuffers(_source[0],1,&buffer_unqueue); ov_raw_seek(&_ogg_file,0); LeaveCriticalSection(_openal_access); _current_playing_state = STANDBY; break; case STANDBY: break; default: break; } } }
void SoundManager::Play(int src_index) { AL_CHECK_ERR(alSourcePlay(sources[src_index])); }
/* --==================================================================-- -- Function: play -- Edited By: Brian McGlauflin -- Modified: Mar 5, 2007 -- Parameters: -- Returns: -- Description: Begins music playback --==================================================================-- */ void MusicManager::play() { if(status == IS_PLAYING) return; status = IS_PLAYING; alSourcePlay(source); }
int main(int argc, char *argv[]) { ALenum format; ALsizei size, freq; ALvoid *data; /* setup camera position and orientation */ cameraAngle = 0.0f; cameraPosition[0] = 0.0f; cameraPosition[1] = 0.8f; cameraPosition[2] = 0.0f; cameraOrientation[0] = cos(2.0 * M_PI * cameraAngle / 360.0); cameraOrientation[1] = 0.0f; cameraOrientation[2] = sin(2.0 * M_PI * cameraAngle / 360.0); cameraOrientation[3] = 0.0f; cameraOrientation[4] = 1.0f; cameraOrientation[5] = 0.0f; /* setup radar and phase position */ radarPosition[0] = 5.0f; radarPosition[1] = 0.0f; radarPosition[2] = 0.0f; phaserPosition[0] = 2.0f; phaserPosition[1] = 0.0f; phaserPosition[2] = 0.0f; radarLightAngle = 0.0f; phaserPlaying = AL_FALSE; /* initialize GLUT */ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition(200, 100); glutInitWindowSize(320, 240); glutCreateWindow("XL Demo"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(special); glutReshapeFunc(reshape); glutIdleFunc(idle); glEnable(GL_CULL_FACE); /* initialize ALUT */ alutInit(&argc, argv); /* set up the buffers */ alGenBuffers(1, &radarBuffer); alGenBuffers(1, &phaserBuffer); alutLoadWAV(kRadarFileName, &format, &data, &size, &freq); alBufferData(radarBuffer, format, data, size, freq); free(data); alutLoadWAV(kPhaserFileName, &format, &data, &size, &freq); alBufferData(phaserBuffer, format, data, size, freq); free(data); /* set up the sources */ alGenSources(1, &radarSource); alGenSources(1, &phaserSource); alSourcefv(radarSource, AL_POSITION, radarPosition); alSourcef(radarSource, AL_GAIN, 1.0f); alSourcef(radarSource, AL_PITCH, 1.0f); alSourcei(radarSource, AL_BUFFER, radarBuffer); alSourcei(radarSource, AL_LOOPING, AL_TRUE); alSourcefv(phaserSource, AL_POSITION, phaserPosition); alSourcef(phaserSource, AL_GAIN, 1.0f); alSourcef(phaserSource, AL_PITCH, 1.0f); alSourcei(phaserSource, AL_BUFFER, phaserBuffer); alSourcei(phaserSource, AL_LOOPING, AL_FALSE); /* start the radar */ alSourcePlay(radarSource); /* GLUT event loop */ glutMainLoop(); /* shutdown alut */ alutExit(); return 0; }
void MADStream::play() { alCheck(alSourcePlay(alSource)); }
void MADStream::stop() { stopped = true; alCheck(alSourcePlay(alSource)); }
void SoundStream::streamData() { // Create the buffers alCheck(alGenBuffers(BufferCount, m_buffers)); for (int i = 0; i < BufferCount; ++i) m_endBuffers[i] = false; // Fill the queue bool requestStop = fillQueue(); // Play the sound alCheck(alSourcePlay(m_source)); while (m_isStreaming) { // The stream has been interrupted! if (SoundSource::getStatus() == Stopped) { if (!requestStop) { // Just continue alCheck(alSourcePlay(m_source)); } else { // End streaming m_isStreaming = false; } } // Get the number of buffers that have been processed (ie. ready for reuse) ALint nbProcessed = 0; alCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed)); while (nbProcessed--) { // Pop the first unused buffer from the queue ALuint buffer; alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer)); // Find its number unsigned int bufferNum = 0; for (int i = 0; i < BufferCount; ++i) if (m_buffers[i] == buffer) { bufferNum = i; break; } // Retrieve its size and add it to the samples count if (m_endBuffers[bufferNum]) { // This was the last buffer: reset the sample count m_samplesProcessed = 0; m_endBuffers[bufferNum] = false; } else { ALint size, bits; alCheck(alGetBufferi(buffer, AL_SIZE, &size)); alCheck(alGetBufferi(buffer, AL_BITS, &bits)); m_samplesProcessed += size / (bits / 8); } // Fill it and push it back into the playing queue if (!requestStop) { if (fillAndPushBuffer(bufferNum)) requestStop = true; } } // Leave some time for the other threads if the stream is still playing if (SoundSource::getStatus() != Stopped) sleep(milliseconds(10)); } // Stop the playback alCheck(alSourceStop(m_source)); // Unqueue any buffer left in the queue clearQueue(); // Delete the buffers alCheck(alSourcei(m_source, AL_BUFFER, 0)); alCheck(alDeleteBuffers(BufferCount, m_buffers)); }
void *decode_audio_thread(void *arg) { INFO("Started decode audio thread!"); av_session_t *_phone = arg; _phone->running_decaud = 1; //int recved_size; //uint8_t dest [RTP_PAYLOAD_SIZE]; int frame_size = AUDIO_FRAME_SIZE; //int data_size; ALCdevice *dev; ALCcontext *ctx; ALuint source, *buffers; dev = alcOpenDevice(NULL); ctx = alcCreateContext(dev, NULL); alcMakeContextCurrent(ctx); int openal_buffers = 5; buffers = calloc(sizeof(ALuint) * openal_buffers, 1); alGenBuffers(openal_buffers, buffers); alGenSources((ALuint)1, &source); alSourcei(source, AL_LOOPING, AL_FALSE); ALuint buffer; ALint ready; uint16_t zeros[frame_size]; memset(zeros, 0, frame_size); int16_t PCM[frame_size]; int i; for (i = 0; i < openal_buffers; ++i) { alBufferData(buffers[i], AL_FORMAT_MONO16, zeros, frame_size, 48000); } alSourceQueueBuffers(source, openal_buffers, buffers); alSourcePlay(source); if (alGetError() != AL_NO_ERROR) { fprintf(stderr, "Error starting audio\n"); goto ending; } int dec_frame_len = 0; while (_phone->running_decaud) { alGetSourcei(source, AL_BUFFERS_PROCESSED, &ready); if (ready <= 0) continue; dec_frame_len = toxav_recv_audio(_phone->av, frame_size, PCM); /* Play the packet */ if (dec_frame_len > 0) { alSourceUnqueueBuffers(source, 1, &buffer); alBufferData(buffer, AL_FORMAT_MONO16, PCM, dec_frame_len * 2 * 1, 48000); int error = alGetError(); if (error != AL_NO_ERROR) { fprintf(stderr, "Error setting buffer %d\n", error); break; } alSourceQueueBuffers(source, 1, &buffer); if (alGetError() != AL_NO_ERROR) { fprintf(stderr, "Error: could not buffer audio\n"); break; } alGetSourcei(source, AL_SOURCE_STATE, &ready); if (ready != AL_PLAYING) alSourcePlay(source); } usleep(1000); } ending: /* clean up codecs */ //pthread_mutex_lock(&cs->ctrl_mutex); /* alDeleteSources(1, &source); alDeleteBuffers(openal_buffers, buffers); alcMakeContextCurrent(NULL); alcDestroyContext(ctx); alcCloseDevice(dev); */ //pthread_mutex_unlock(&cs->ctrl_mutex); _phone->running_decaud = -1; pthread_exit ( NULL ); }
void Audio::playSource(ALuint Source) { alSourcePlay(Source); }
void Music::MusicThread() { // Allocation des buffers de streaming ALuint buffers[NAZARA_AUDIO_STREAMED_BUFFER_COUNT]; alGenBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers); for (unsigned int i = 0; i < NAZARA_AUDIO_STREAMED_BUFFER_COUNT; ++i) { if (FillAndQueueBuffer(buffers[i])) break; // Nous avons atteint la fin du stream, inutile de rajouter des buffers } alSourcePlay(m_source); // Boucle de lecture (remplissage de nouveaux buffers au fur et à mesure) while (m_impl->streaming) { // La lecture s'est arrêtée, nous avons atteint la fin du stream SoundStatus status = GetInternalStatus(); if (status == SoundStatus_Stopped) { m_impl->streaming = false; break; } Nz::LockGuard lock(m_impl->bufferLock); // On traite les buffers lus ALint processedCount = 0; alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &processedCount); while (processedCount--) { ALuint buffer; alSourceUnqueueBuffers(m_source, 1, &buffer); ALint bits, size; alGetBufferi(buffer, AL_BITS, &bits); alGetBufferi(buffer, AL_SIZE, &size); if (bits != 0) m_impl->processedSamples += (8 * size) / bits; if (FillAndQueueBuffer(buffer)) break; } lock.Unlock(); // On retourne dormir un peu Thread::Sleep(50); } // Arrêt de la lecture du son (dans le cas où ça ne serait pas déjà fait) alSourceStop(m_source); // On supprime les buffers du stream ALint queuedBufferCount; alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queuedBufferCount); ALuint buffer; for (ALint i = 0; i < queuedBufferCount; ++i) alSourceUnqueueBuffers(m_source, 1, &buffer); alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers); }
void S_PlayClip(Clip* c, AudioSource* source, bool repeating) { alSourcei(source->sourceID, AL_BUFFER, c->bufferID); alSourcei(source->sourceID, AL_LOOPING, repeating ? AL_TRUE : AL_FALSE); alSourcePlay(source->sourceID); }
int main( int argc, char* argv[] ) { ALCdevice *dev; FILE *fh; time_t shouldend; int blah = 0; struct stat sbuf; int speed; void *data; int size; char *fname; int i = 0; dev = alcOpenDevice( NULL ); if( dev == NULL ) { return 1; } /* Initialize ALUT. */ context_id = alcCreateContext( dev, NULL ); if(context_id == NULL) { alcCloseDevice( dev ); return 1; } alcMakeContextCurrent( context_id ); fixup_function_pointers(); init( ); if(argc == 1) { fname = MP3_FILE; } else { fname = argv[1]; } if(stat(fname, &sbuf) == -1) { perror(fname); return errno; } size = sbuf.st_size; data = malloc(size); if(data == NULL) { exit(1); } fh = fopen(fname, "rb"); if(fh == NULL) { fprintf(stderr, "Could not open %s\n", fname); free(data); exit(1); } fread(data, 1, size, fh); alutLoadMP3p = (mp3Loader *) alGetProcAddress((ALubyte *) MP3_FUNC); if(alutLoadMP3p == NULL) { free(data); fprintf(stderr, "Could not GetProc %s\n", (ALubyte *) MP3_FUNC); exit(-4); } for(i = 0; i < MAX_SOURCES; i++) { if(alutLoadMP3p(mp3buf[i], data, size) != AL_TRUE) { fprintf(stderr, "alutLoadMP3p failed\n"); exit(-2); } alSourcePlay(mp3source[i]); micro_sleep(80000); } free( data ); while(SourceIsPlaying(mp3source[0]) == AL_TRUE) { sleep(1); } cleanup(); alcCloseDevice( dev ); return 0; }
void Audio_Play(struct haudio *handle) { alSourcePlay(handle->source); }
void SoundStream::streamData() { bool requestStop = false; { Lock lock(m_threadMutex); // Check if the thread was launched Stopped if (m_threadStartState == Stopped) { m_isStreaming = false; return; } } // Create the buffers alCheck(alGenBuffers(BufferCount, m_buffers)); for (int i = 0; i < BufferCount; ++i) m_endBuffers[i] = false; // Fill the queue requestStop = fillQueue(); // Play the sound alCheck(alSourcePlay(m_source)); { Lock lock(m_threadMutex); // Check if the thread was launched Paused if (m_threadStartState == Paused) alCheck(alSourcePause(m_source)); } for (;;) { { Lock lock(m_threadMutex); if (!m_isStreaming) break; } // The stream has been interrupted! if (SoundSource::getStatus() == Stopped) { if (!requestStop) { // Just continue alCheck(alSourcePlay(m_source)); } else { // End streaming Lock lock(m_threadMutex); m_isStreaming = false; } } // Get the number of buffers that have been processed (i.e. ready for reuse) ALint nbProcessed = 0; alCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed)); while (nbProcessed--) { // Pop the first unused buffer from the queue ALuint buffer; alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer)); // Find its number unsigned int bufferNum = 0; for (int i = 0; i < BufferCount; ++i) if (m_buffers[i] == buffer) { bufferNum = i; break; } // Retrieve its size and add it to the samples count if (m_endBuffers[bufferNum]) { // This was the last buffer: reset the sample count m_samplesProcessed = 0; m_endBuffers[bufferNum] = false; } else { ALint size, bits; alCheck(alGetBufferi(buffer, AL_SIZE, &size)); alCheck(alGetBufferi(buffer, AL_BITS, &bits)); // Bits can be 0 if the format or parameters are corrupt, avoid division by zero if (bits == 0) { err() << "Bits in sound stream are 0: make sure that the audio format is not corrupt " << "and initialize() has been called correctly" << std::endl; // Abort streaming (exit main loop) Lock lock(m_threadMutex); m_isStreaming = false; requestStop = true; break; } else { m_samplesProcessed += size / (bits / 8); } } // Fill it and push it back into the playing queue if (!requestStop) { if (fillAndPushBuffer(bufferNum)) requestStop = true; } } // Leave some time for the other threads if the stream is still playing if (SoundSource::getStatus() != Stopped) sleep(milliseconds(10)); } // Stop the playback alCheck(alSourceStop(m_source)); // Dequeue any buffer left in the queue clearQueue(); // Delete the buffers alCheck(alSourcei(m_source, AL_BUFFER, 0)); alCheck(alDeleteBuffers(BufferCount, m_buffers)); }
// Performs an (instantaneous) DMA. void ai_dma(struct ai_controller *ai) { struct bus_controller *bus; // Shove things into the audio context, slide the window. memcpy(&bus, ai, sizeof(bus)); // Need to raise an interrupt when the DMA engine // is doing the last 8-byte data bus transfer... if (likely(ai->fifo[ai->fifo_ri].length > 0)) { unsigned freq = (double) NTSC_DAC_FREQ / (ai->regs[AI_DACRATE_REG] + 1); unsigned samples = ai->fifo[ai->fifo_ri].length / 4;// - 1; // Shovel things into the audio context. uint8_t buf[0x40000]; unsigned i; ALuint buffer; ALint val; alGetSourcei(ai->ctx.source, AL_BUFFERS_PROCESSED, &val); if (val) { for (i = 0; i < ai->fifo[ai->fifo_ri].length / 4; i++) { uint32_t word; // Byteswap audio buffer to native format. // TODO: Can we specify endian-ness somehow? memcpy(&word, bus->ri->ram + (ai->fifo[ ai->fifo_ri].address + sizeof(word) * i), sizeof(word)); word = byteswap_32(word); memcpy(buf + sizeof(word) * i, &word, sizeof(word)); } alSourceUnqueueBuffers(ai->ctx.source, 1, &buffer); alBufferData(buffer, AL_FORMAT_STEREO16, buf, ai->fifo[ai->fifo_ri].length, 44100 /* ai->ctx.frequency */); alSourceQueueBuffers(ai->ctx.source, 1, &buffer); alGetSourcei(ai->ctx.source, AL_SOURCE_STATE, &val); if(val != AL_PLAYING) alSourcePlay(ai->ctx.source); if (alGetError() != AL_NO_ERROR) { fprintf(stderr, "OpenAL is angry!\n"); exit(255); } } ai->counter = (62500000.0 / freq) * samples; //printf("Wait %lu cycles to raise interrupt.\n", ai->counter); } // If the length was zero, just interrupt now? else { signal_rcp_interrupt(bus->vr4300, MI_INTR_AI); ai->fifo_ri = (ai->fifo_ri == 1) ? 0 : 1; ai->regs[AI_STATUS_REG] &= ~0x80000001; ai->counter = 0xFFFFFFFFU; ai->fifo_count--; } if (ai->fifo_count > 0) ai->regs[AI_STATUS_REG] |= 0x40000000; }
/** * @brief The music thread. * * @param unused Unused. */ static int music_thread( void* unused ) { (void)unused; int ret; int active = 0; /* active buffer */ ALint state; ALuint removed[2]; ALenum value; music_state_t cur_state; ALfloat gain; int fadein_start = 0; uint32_t fade, fade_timer = 0; while (1) { /* Handle states. */ musicLock(); /* Handle new command. */ switch (music_command) { case MUSIC_CMD_KILL: if (music_state != MUSIC_STATE_IDLE) music_state = MUSIC_STATE_STOPPING; else { music_state = MUSIC_STATE_DEAD; } /* Does not clear command. */ break; case MUSIC_CMD_STOP: /* Notify of stopped. */ if (music_state == MUSIC_STATE_IDLE) SDL_CondBroadcast( music_state_cond ); else music_state = MUSIC_STATE_STOPPING; break; case MUSIC_CMD_PLAY: /* Set appropriate state. */ if (music_state == MUSIC_STATE_PAUSING) music_state = MUSIC_STATE_RESUMING; else if (music_state == MUSIC_STATE_FADEIN) fade_timer = SDL_GetTicks() - MUSIC_FADEIN_DELAY; else music_state = MUSIC_STATE_LOADING; /* Disable fadein. */ fadein_start = 0; /* Clear command. */ music_command = MUSIC_CMD_NONE; SDL_CondBroadcast( music_state_cond ); break; case MUSIC_CMD_FADEOUT: /* Notify of stopped. */ if (music_state != MUSIC_STATE_IDLE) { music_state = MUSIC_STATE_FADEOUT; /* Set timer. */ fade_timer = SDL_GetTicks(); } /* Clear command. */ music_command = MUSIC_CMD_NONE; SDL_CondBroadcast( music_state_cond ); break; case MUSIC_CMD_FADEIN: if ((music_state == MUSIC_STATE_FADEIN) || (music_state == MUSIC_STATE_PLAYING)) SDL_CondBroadcast( music_state_cond ); else { music_state = MUSIC_STATE_LOADING; /* Set timer. */ fade_timer = SDL_GetTicks(); fadein_start = 1; } /* Clear command. */ music_command = MUSIC_CMD_NONE; break; case MUSIC_CMD_PAUSE: if (music_state == MUSIC_STATE_PAUSED) SDL_CondBroadcast( music_state_cond ); else if ((music_state == MUSIC_STATE_PLAYING) || (music_state == MUSIC_STATE_FADEIN)) music_state = MUSIC_STATE_PAUSING; music_command = MUSIC_CMD_NONE; break; case MUSIC_CMD_NONE: break; } cur_state = music_state; musicUnlock(); /* * Main processing loop. */ switch (cur_state) { /* * Basically send a message that thread is up and running. */ case MUSIC_STATE_STARTUP: musicLock(); music_state = MUSIC_STATE_IDLE; SDL_CondBroadcast( music_state_cond ); musicUnlock(); break; /* * We died. */ case MUSIC_STATE_DEAD: musicLock(); music_state = MUSIC_STATE_DEAD; SDL_CondBroadcast( music_state_cond ); musicUnlock(); return 0; break; /* * Delays at the end. */ case MUSIC_STATE_PAUSED: case MUSIC_STATE_IDLE: break; /* * Resumes the paused song. */ case MUSIC_STATE_RESUMING: soundLock(); alSourcePlay( music_source ); alSourcef( music_source, AL_GAIN, music_vol ); /* Check for errors. */ al_checkErr(); soundUnlock(); musicLock(); music_state = MUSIC_STATE_PLAYING; SDL_CondBroadcast( music_state_cond ); musicUnlock(); break; /* * Pause the song. */ case MUSIC_STATE_PAUSING: soundLock(); alSourcePause( music_source ); /* Check for errors. */ al_checkErr(); soundUnlock(); musicLock(); music_state = MUSIC_STATE_PAUSED; SDL_CondBroadcast( music_state_cond ); musicUnlock(); break; /* * Stop song setting to IDLE. */ case MUSIC_STATE_STOPPING: soundLock(); /* Stop and remove buffers. */ alSourceStop( music_source ); alGetSourcei( music_source, AL_BUFFERS_PROCESSED, &value ); if (value > 0) alSourceUnqueueBuffers( music_source, value, removed ); /* Clear timer. */ fade_timer = 0; /* Reset volume. */ alSourcef( music_source, AL_GAIN, music_vol ); soundUnlock(); musicLock(); music_state = MUSIC_STATE_IDLE; SDL_CondBroadcast( music_state_cond ); if (!music_forced) music_rechoose(); musicUnlock(); break; /* * Load the song. */ case MUSIC_STATE_LOADING: /* Load buffer and start playing. */ active = 0; /* load first buffer */ ret = stream_loadBuffer( music_buffer[active] ); soundLock(); alSourceQueueBuffers( music_source, 1, &music_buffer[active] ); /* Special case NULL file or error. */ if (ret < 0) { soundUnlock(); /* Force state to stopped. */ musicLock(); music_state = MUSIC_STATE_IDLE; SDL_CondBroadcast( music_state_cond ); if (!music_forced) music_rechoose(); musicUnlock(); break; } /* Force volume level. */ alSourcef( music_source, AL_GAIN, (fadein_start) ? 0. : music_vol ); /* Start playing. */ alSourcePlay( music_source ); /* Check for errors. */ al_checkErr(); soundUnlock(); /* Special case of a very short song. */ if (ret > 1) { active = -1; musicLock(); if (fadein_start) music_state = MUSIC_STATE_FADEIN; else music_state = MUSIC_STATE_PLAYING; SDL_CondBroadcast( music_state_cond ); musicUnlock(); break; } /* Load second buffer. */ active = 1; ret = stream_loadBuffer( music_buffer[active] ); if (ret < 0) { active = -1; } else { soundLock(); alSourceQueueBuffers( music_source, 1, &music_buffer[active] ); /* Check for errors. */ al_checkErr(); soundUnlock(); active = 1 - active; } musicLock(); if (fadein_start) music_state = MUSIC_STATE_FADEIN; else music_state = MUSIC_STATE_PLAYING; SDL_CondBroadcast( music_state_cond ); musicUnlock(); break; /* * Fades in the music. */ case MUSIC_STATE_FADEOUT: case MUSIC_STATE_FADEIN: /* See if must still fade. */ fade = SDL_GetTicks() - fade_timer; if (cur_state == MUSIC_STATE_FADEIN) { if (fade < MUSIC_FADEIN_DELAY) { gain = (ALfloat)fade / (ALfloat)MUSIC_FADEIN_DELAY; soundLock(); alSourcef( music_source, AL_GAIN, gain*music_vol ); /* Check for errors. */ al_checkErr(); soundUnlock(); } /* No need to fade anymore. */ else { /* Set volume to normal level. */ soundLock(); alSourcef( music_source, AL_GAIN, music_vol ); /* Check for errors. */ al_checkErr(); soundUnlock(); /* Change state to playing. */ musicLock(); music_state = MUSIC_STATE_PLAYING; musicUnlock(); } } else if (cur_state == MUSIC_STATE_FADEOUT) { if (fade < MUSIC_FADEOUT_DELAY) { gain = 1. - (ALfloat)fade / (ALfloat)MUSIC_FADEOUT_DELAY; soundLock(); alSourcef( music_source, AL_GAIN, gain*music_vol ); /* Check for errors. */ al_checkErr(); soundUnlock(); } else { /* Music should stop. */ musicLock(); music_state = MUSIC_STATE_STOPPING; musicUnlock(); break; } } /* Purpose fallthrough. */ /* * Play the song if needed. */ case MUSIC_STATE_PLAYING: /* Special case where file has ended. */ if (active < 0) { soundLock(); alGetSourcei( music_source, AL_SOURCE_STATE, &state ); if (state == AL_STOPPED) { alGetSourcei( music_source, AL_BUFFERS_PROCESSED, &value ); if (value > 0) alSourceUnqueueBuffers( music_source, value, removed ); soundUnlock(); musicLock(); music_state = MUSIC_STATE_IDLE; if (!music_forced) music_rechoose(); musicUnlock(); break; } soundUnlock(); break; } soundLock(); /* See if needs another buffer set. */ alGetSourcei( music_source, AL_BUFFERS_PROCESSED, &state ); if (state > 0) { /* refill active buffer */ alSourceUnqueueBuffers( music_source, 1, removed ); ret = stream_loadBuffer( music_buffer[active] ); if (ret < 0) { active = -1; } else { alSourceQueueBuffers( music_source, 1, &music_buffer[active] ); active = 1 - active; } } /* Check for errors. */ al_checkErr(); soundUnlock(); } /* * Global thread delay. */ SDL_Delay(0); } return 0; }
void Sound::play() { alCheck(alSourcePlay(m_source)); }
//function to play sound void openal_sound() { alSourcePlay(alSource[nsound]); }
void alSourcePlayv(ALsizei n, ALuint *sources) { DEBUGLOGCALL(LCF_OPENAL); for (int i=0; i<n; i++) alSourcePlay(sources[i]); }
void emptysound(Game *game) { alSourcePlay(alSource[3]); }
/*! * \brief Plays the music * * \remark Produces a NazaraError if the sound is not playable with NAZARA_AUDIO_SAFE defined */ void Sound::Play() { NazaraAssert(IsPlayable(), "Music is not playable"); alSourcePlay(m_source); }
void bitesound() { alSourcePlay(alSource[5]); }
void Audio::play(const SoundSourceID source){ alSourcePlay(soundSources[source].source); }
// TODO: generate buffers separately DeviceError open_device(DeviceType type, int32_t selection, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration, uint8_t channels) { if (size[type] <= selection || selection < 0) return de_InvalidSelection; if (channels != 1 && channels != 2) return de_UnsupportedMode; lock; const uint32_t frame_size = (sample_rate * frame_duration / 1000); uint32_t i; for (i = 0; i < MAX_DEVICES && running[type][i] != NULL; ++i); if (i == MAX_DEVICES) { unlock; return de_AllDevicesBusy; } else *device_idx = i; for (i = 0; i < MAX_DEVICES; i ++) { /* Check if any device has the same selection */ if ( running[type][i] && running[type][i]->selection == selection ) { // printf("a%d-%d:%p ", selection, i, running[type][i]->dhndl); running[type][*device_idx] = running[type][i]; running[type][i]->ref_count ++; unlock; return de_None; } } Device* device = running[type][*device_idx] = calloc(1, sizeof(Device)); device->selection = selection; device->sample_rate = sample_rate; device->frame_duration = frame_duration; device->sound_mode = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; if (pthread_mutex_init(device->mutex, NULL) != 0) { free(device); unlock; return de_InternalError; } if (type == input) { device->dhndl = alcCaptureOpenDevice(devices_names[type][selection], sample_rate, device->sound_mode, frame_size * 2); #ifdef AUDIO device->VAD_treshold = user_settings->VAD_treshold; #endif } else { device->dhndl = alcOpenDevice(devices_names[type][selection]); if ( !device->dhndl ) { free(device); running[type][*device_idx] = NULL; unlock; return de_FailedStart; } device->ctx = alcCreateContext(device->dhndl, NULL); alcMakeContextCurrent(device->ctx); alGenBuffers(OPENAL_BUFS, device->buffers); alGenSources((uint32_t)1, &device->source); alSourcei(device->source, AL_LOOPING, AL_FALSE); uint16_t zeros[frame_size]; memset(zeros, 0, frame_size*2); for ( i = 0; i < OPENAL_BUFS; ++i ) { alBufferData(device->buffers[i], device->sound_mode, zeros, frame_size*2, sample_rate); } alSourceQueueBuffers(device->source, OPENAL_BUFS, device->buffers); alSourcePlay(device->source); } if (alcGetError(device->dhndl) != AL_NO_ERROR) { free(device); running[type][*device_idx] = NULL; unlock; return de_FailedStart; } if (type == input) { alcCaptureStart(device->dhndl); thread_paused = false; } unlock; return de_None; }
void SonicDog::startPlaying() { // find out if the client wants the sound to play bool can_play, once, removed; removed = false; pthread_mutex_lock( &play_lock_ ); can_play = playing_; pthread_mutex_unlock( &play_lock_ ); while ( can_play ) { pthread_mutex_lock( &q_lock_ ); while ( play_q_.size() == 0 && !exit_ ) { pthread_cond_wait( &empty_q_lock_, &q_lock_ ); } // check that we can keep playing after being woken up if ( exit_ ) { pthread_mutex_unlock( &q_lock_ ); pthread_exit( 0 ); } // there's stuff in the queue so pop off a source SoundSrc *src = play_q_.front(); play_q_.pop(); pthread_mutex_unlock( &q_lock_ ); once = src->once; do { // play the sound at least once if ( once ) pthread_mutex_lock( &turns_lock_ ); alSourcePlay( src->source ); alutSleep( src->pause ); if ( once ) pthread_mutex_unlock( &turns_lock_ ); if ( !once ) alSourcef( src->source, AL_PITCH, calculatePitch( src->source ) ); // check that we can keep playing pthread_mutex_lock( &play_lock_ ); can_play = playing_; pthread_mutex_unlock( &play_lock_ ); if ( !once ) { bool paused; // check if we're paused pthread_mutex_lock( &pause_lock_ ); BoolMap::iterator p = paused_.find( src->id ); assert( p != paused_.end() ); paused = p->second; while ( paused ) { pthread_cond_wait( &pause_cond_lock_, &pause_lock_ ); BoolMap::iterator p = paused_.find( src->id ); assert( p != paused_.end() ); paused = p->second; } pthread_mutex_unlock( &pause_lock_ ); // check if we've been removed pthread_mutex_lock( &remove_lock_ ); BoolMap::iterator cont = removed_.find( src->id ); if ( cont != removed_.end() ) { removed = cont->second; } pthread_mutex_unlock( &remove_lock_ ); } } while ( can_play && !once && !removed ); // remove this source if wasn't meant to be played only once if ( !src->once ) { // remove this source from the source map if it's in there pthread_mutex_lock( &sources_lock_ ); SoundMap::iterator itr = sources_.find( src->id ); if ( itr != sources_.end() ) { sources_.erase( itr ); } pthread_mutex_unlock( &sources_lock_ ); } // we're done with the source so clean it up alDeleteSources( 1, &(src->source) ); alDeleteBuffers( 1, &(src->buffer) ); delete src; } // we've been stopped, so exit the thread pthread_exit( 0 ); }