예제 #1
0
void SoundPlayer::play(std::string filename) {
	if(__SoundPlayer_audio_is_disabled) {
		return;
	}

	pthread_mutex_lock(&control_mutex);
	_player_stop();
	pthread_mutex_lock(&player_mutex);

	stop = true;

	stream = alureCreateStreamFromFile(filename.c_str(), 19200, 2, buf);

	if(stream == AL_NONE) {
		printf("Error loading file %s: %s\n", filename.c_str(), alureGetErrorString());
	}else if(!ALSources::get(sourceID)) {
		printf("No OpenAL sources available\n");
		alureDestroyStream(stream, 1, buf);
	} else {
		stop = paused = false;
		alSourcef(sourceID, AL_GAIN, volume);
		alSource3f(sourceID, AL_POSITION, x, y, z);
		alurePlaySourceStream(sourceID, stream, 2, 0, stopped_callback, this);
	}

	pthread_mutex_unlock(&control_mutex);
}
예제 #2
0
파일: Sound.cpp 프로젝트: adam000/Apollo
static void MusicEndCallback(void* ud, ALuint source)
{
	alureDestroyStream(currentMusicStream, 2, musicBufs);
	currentMusicStream = NULL;
	currentMusicName = "";
	free(ud);
}
예제 #3
0
void SoundPlayer::_player_stop() {
	if(!stop) {
		stop = paused = true;
		alureStopSource(sourceID, AL_FALSE);
		alureDestroyStream(stream, 1, buf);
		ALSources::release(sourceID);
		pthread_mutex_unlock(&player_mutex);
	}
}
예제 #4
0
void killSoundStuff () {
	if (! soundOK) return;

	SilenceIKillYou = true;
	for (int i = 0; i < MAX_SAMPLES; i ++) {
		if (soundCache[i].playing) {
			if (! alureStopSource(soundCache[i].playingOnSource, AL_TRUE)) {
				debugOut( "Failed to stop source: %s\n",
							alureGetErrorString());
			}
		}

		if (soundCache[i].stream != NULL) {
			if (! alureDestroyStream(soundCache[i].stream, 0, NULL)) {
				debugOut("Failed to destroy stream: %s\n",
							alureGetErrorString());
			}
		}
	}

	for (int i = 0; i < MAX_MODS; i ++) {
		if (modCache[i].playing) {
			if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) {
				debugOut( "Failed to stop source: %s\n",
							alureGetErrorString());
			}
		}

		if (modCache[i].stream != NULL) {
			if (! alureDestroyStream(modCache[i].stream, 0, NULL)) {
				debugOut("Failed to destroy stream: %s\n",
							alureGetErrorString());
			}
		}
	}

	SilenceIKillYou = false;

	alureShutdownDevice();
}
예제 #5
0
static void mod_eos_callback(void *cacheIndex, ALuint source)
{
	int *a = (int*)cacheIndex;
	alDeleteSources(1, &source);
	if(alGetError() != AL_NO_ERROR)
	{
		debugOut("Failed to delete OpenAL source!\n");
	}
	modCache[*a].playingOnSource = 0;
	if (! alureDestroyStream(modCache[*a].stream, 0, NULL)) {
		debugOut("Failed to destroy stream: %s\n",
				alureGetErrorString());
	}
	modCache[*a].stream = NULL;
	modCache[*a].playing = false;
}
예제 #6
0
void freeSound (int a) {
	if (! soundOK) return;
	// Clear OpenAL errors to make sure they don't block anything:
	alGetError();

	SilenceIKillYou = true;

	if (soundCache[a].playing) {
		if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) {
			debugOut( "Failed to stop source: %s\n",
						alureGetErrorString());
		}
	}
	if (! alureDestroyStream(soundCache[a].stream, 0, NULL)) {
		debugOut("Failed to destroy stream: %s\n",
					alureGetErrorString());
	}
	soundCache[a].stream = NULL;
	soundCache[a].fileLoaded = -1;

	SilenceIKillYou = false;
}
예제 #7
0
int main () {
  if (!alureInitDevice(NULL, NULL)) {
    std::fprintf(stderr, "Failed to open OpenAL device: %s\n", alureGetErrorString());
    return 1;
  }

  alGenSources(1, &src);
  if (alGetError() != AL_NO_ERROR) {
    std::fprintf(stderr, "Failed to create OpenAL source!\n");
    alureShutdownDevice();
    return 1;
  }

  // Seeting Blip Buffer

  synth.treble_eq( -18.0f );

  synth.volume (0.80);
  synth.output (&blipbuf);

  // Init Blip Buffer with a buffer of 250ms (second paramter is time in ms)
  if ( blipbuf.set_sample_rate( SR, 1000 / 4 ) ) {
    std::fprintf(stderr, "Failed to create Blip Buffer! Our of Memory\n");
    alureShutdownDevice();
    return 1;
  }
  blipbuf.clock_rate( blipbuf.sample_rate() );
  blipbuf.bass_freq(300); // Equalization like a TV speaker

  stream = alureCreateStreamFromCallback (StreamCB, nullptr, AL_FORMAT_MONO16, SR, SR/2, 0, nullptr);

  if(!stream) {
    std::fprintf(stderr, "Error creating stream! %s\n",  alureGetErrorString());
    alDeleteSources(1, &src);

    alureShutdownDevice();
    return 1;
  }

  if (!alurePlaySourceStream(src, stream, 4, 0, eos_callback, NULL)) {
    std::fprintf(stderr, "Failed to play stream: %s\n", alureGetErrorString());
    isdone = 1;
  }

  alureUpdateInterval(0.005f); // Should be a independint thread  playing the stream

  while(!isdone) {
    freq -= 1;
    if (freq < 1) {
      freq = 600;
    }

    alureSleep(0.02f);
  }
  alureStopSource(src, AL_FALSE);

  alDeleteSources(1, &src);
  alureDestroyStream(stream, 0, NULL);

  alureShutdownDevice();
  return 0;
}