void processWAVFiles(const char *inputDir, const char *outputDir) {

  /* Get the names of all the audio files. */
  DIR *d;
  struct dirent *dir;
  d = opendir(inputDir);
  size_t count = 0;
  if (d)
  {
    while ((dir = readdir(d)) != NULL)
    {
      if (strstr(dir->d_name, "wav") != NULL) {
        count++;
        printf("%s\n", dir->d_name);
      }
        
    }
    char **files = (char **)malloc(count * sizeof(char *));
    
    d = opendir(inputDir);
    size_t idx = 0;
    while ((dir = readdir(d)) != NULL)
    {
      if (strstr(dir->d_name, "wav") != NULL) {
        files[idx] = (char *)malloc(sizeof(inputDir) + sizeof(dir->d_name) + 1);
        files[idx] = dir->d_name;
        
        idx++;
      }
    }

    closedir(d);
    printf("Reading\n");


    /* Read in the WAV files */
    for (int i = 0; i < count; i++) {
      char *file = files[i];

      char str[sizeof(char *) * sizeof(file) + 100];
      strcpy(str, inputDir);
      strcat(str, "/");
      strcat(str, file);
      
      char outstring[100] = "";
      strcat(outstring, outputDir);
      strcat(outstring, "/");
      
      char buffer[10];
      sprintf(buffer, "%d", i+1);
      strcat(outstring, buffer);
        
      printf("%s\n", outstring);
      openWAV(str, outstring);
    }

    free(files);

  }
  else {
      printf("Need directory \"%s\" with wav files", inputDir);
  }
}
Ejemplo n.º 2
0
void initOpenAL() {
	
	ALenum errorNum = alGetError();
	// initialise OpenAL
	ALCdevice* device = alcOpenDevice(NULL);
	ALCcontext* context = alcCreateContext(device, NULL);
	alcMakeContextCurrent(context);
	
	errorNum = alGetError();
	
	alListener3f(AL_POSITION, 0, 0, 0);
	
	errorNum = alGetError();
	
	alListener3f(AL_VELOCITY, 0, 0, 0);
	
	errorNum = alGetError();
	
	ALfloat listenerOri[]={0.0,0.0,1.0, 0.0,1.0,0.0};
	
	alListenerfv(AL_ORIENTATION, listenerOri);
	
	errorNum = alGetError();
	
	alGenSources(1, &hitSound);
	alGenSources(1, &spinSound);
	alGenSources(1, &deadSound);
	alGenSources(1, &scoreSound);
	alGenSources(1, &music);
	
	errorNum = alGetError();
	
	alSourcef(hitSound, AL_PITCH, 1);
	alSourcef(spinSound, AL_PITCH, 1);
	alSourcef(deadSound, AL_PITCH, 1);
	alSourcef(scoreSound, AL_PITCH, 1);
	alSourcef(music, AL_PITCH, 1);
	
	alSourcef(hitSound, AL_GAIN, 1);
	alSourcef(spinSound, AL_GAIN, 1);
	alSourcef(deadSound, AL_GAIN, 0.4);
	alSourcef(scoreSound, AL_GAIN, 0.6);
	alSourcef(music, AL_GAIN, 0.4);
	
	alSource3f(hitSound, AL_POSITION, 0, 0, 0);
	alSource3f(spinSound, AL_POSITION, 0, 0, 0);
	alSource3f(deadSound, AL_POSITION, 0, 0, 0);
	alSource3f(scoreSound, AL_POSITION, 0, 0, 0);
	alSource3f(music, AL_POSITION, 0, 0, 0);
	
	alSource3f(hitSound, AL_VELOCITY, 0, 0, 0);
	alSource3f(spinSound, AL_VELOCITY, 0, 0, 0);
	alSource3f(deadSound, AL_VELOCITY, 0, 0, 0);
	alSource3f(scoreSound, AL_VELOCITY, 0, 0, 0);
	alSource3f(music, AL_VELOCITY, 0, 0, 0);
	
	alSourcei(hitSound, AL_LOOPING, AL_FALSE);
	alSourcei(spinSound, AL_LOOPING, AL_FALSE);
	alSourcei(deadSound, AL_LOOPING, AL_FALSE);
	alSourcei(scoreSound, AL_LOOPING, AL_FALSE);
	alSourcei(music, AL_LOOPING, AL_FALSE);
	
	errorNum = alGetError();
	
	openWAV("arcade.wav", &hitSound);
	openWAV("powerup.wav", &spinSound);
	openWAV("pulsegun.wav", &deadSound);
	openWAV("spaceship_hit.wav", &scoreSound);
	openWAV("depthcharge_music.wav", &music);
	
	printf("Error after alBufferData, before alSourcePlay: %x\n", alGetError());
	
	playMusic();
	
	errorNum = alGetError();
	if (errorNum != AL_NO_ERROR) {
		printf("Error starting playback: %x", errorNum);
	}
}