Buffer* LoadBuffer(const char* name, const char* type, const char* data, size_t size)
	{
		if (strcasecmp(type,"wav") == 0) return LoadWAV(name,data,size);
		if (strcasecmp(type,"ogg") == 0) return LoadOGG(name,data,size);
		// add more file formats here
		
		freeslw::ErrorPrintf("File extension \"%s\" is not supported",type);
		
		return 0;
	}
Ejemplo n.º 2
0
bool SoundBuffer::Load(const std::string & filename, const SoundInfo & sound_device_info, std::ostream & error_output)
{
	if (filename.find(".wav") != std::string::npos)
		return LoadWAV(filename, sound_device_info, error_output);
	else if (filename.find(".ogg") != std::string::npos)
		return LoadOGG(filename, sound_device_info, error_output);
	else
	{
		error_output << "Unable to determine file type from filename: " << filename << std::endl;
		return false;
	}
}
void OnStart( const std::string& RootPath )
{
	g_FrameBuffer = ( unsigned char* )malloc( ImageWidth * ImageHeight * 4 );
	memset( g_FrameBuffer, 0xFF, ImageWidth * ImageHeight * 4 );

	LoadOGG();
	LoadModPlug();

	g_FS = new FileSystem();
	g_FS->Mount( "." );
#if defined(ANDROID)
	g_FS->Mount( RootPath );
	g_FS->AddAliasMountPoint( RootPath, "assets" );
#endif
	g_Audio.Start( iThread::Priority_Normal );
	g_Sound.Start( iThread::Priority_Normal );
}
Ejemplo n.º 4
0
// Load sound to memory
Sound LoadSound(char *fileName)
{
    Sound sound;
    Wave wave;
    
    // NOTE: The entire file is loaded to memory to play it all at once (no-streaming)
    
    // Audio file loading
    // NOTE: Buffer space is allocated inside function, Wave must be freed
    
    if (strcmp(GetExtension(fileName),"wav") == 0) wave = LoadWAV(fileName);
    else if (strcmp(GetExtension(fileName),"ogg") == 0) wave = LoadOGG(fileName);
    else TraceLog(WARNING, "[%s] Sound extension not recognized, it can't be loaded", fileName);
    
    if (wave.data != NULL)
    {
        ALenum format = 0;
        // The OpenAL format is worked out by looking at the number of channels and the bits per sample
        if (wave.channels == 1) 
        {
            if (wave.bitsPerSample == 8 ) format = AL_FORMAT_MONO8;
            else if (wave.bitsPerSample == 16) format = AL_FORMAT_MONO16;
        } 
        else if (wave.channels == 2) 
        {
            if (wave.bitsPerSample == 8 ) format = AL_FORMAT_STEREO8;
            else if (wave.bitsPerSample == 16) format = AL_FORMAT_STEREO16;
        }
        
        // Create an audio source
        ALuint source;
        alGenSources(1, &source);            // Generate pointer to audio source

        alSourcef(source, AL_PITCH, 1);    
        alSourcef(source, AL_GAIN, 1);
        alSource3f(source, AL_POSITION, 0, 0, 0);
        alSource3f(source, AL_VELOCITY, 0, 0, 0);
        alSourcei(source, AL_LOOPING, AL_FALSE);
        
        // Convert loaded data to OpenAL buffer
        //----------------------------------------
        ALuint buffer;
        alGenBuffers(1, &buffer);            // Generate pointer to buffer

        // Upload sound data to buffer
        alBufferData(buffer, format, wave.data, wave.dataSize, wave.sampleRate);

        // Attach sound buffer to source
        alSourcei(source, AL_BUFFER, buffer);
        
        // Unallocate WAV data
        UnloadWave(wave);
        
        TraceLog(INFO, "[%s] Sound file loaded successfully", fileName);  
        TraceLog(INFO, "[%s] Sample rate: %i - Channels: %i", fileName, wave.sampleRate, wave.channels);
        
        sound.source = source;
        sound.buffer = buffer;
    }
    
    return sound;
}
Ejemplo n.º 5
0
int SoundManager::LoadSound(char* fname, int TypePath)
{
  if (!fm.LoadFile(fname,TypePath))
  {
    FONLINE_LOG("Ошибка - Загрузка звука - Звук |%s| не найден\n",fname);
    return 0;
  }

  char* ext=strstr(fname,".");

  if(!ext)
  {
    fm.UnloadFile();
    FONLINE_LOG("Ошибка - Загрузка звука - Нет расширения у файла:|%s|\n",fname);
    return 0;
  }

  WAVEFORMATEX fmt;
  ZeroMemory(&fmt,sizeof(WAVEFORMATEX));

  unsigned char* smplData=NULL;
  uint32_t sizeData=0;

  if(!stricmp(ext,".wav"))
  {
    if (!LoadWAV(&fmt, &smplData, &sizeData)) {
      if (smplData != NULL) {
        delete [] smplData;
        smplData = NULL;
      }
      fm.UnloadFile();
      return 0;
    }
  }
  else if(!stricmp(ext,".acm"))
  {
    if(!LoadACM(&fmt,&smplData,&sizeData)) {
      if (smplData != NULL) {
        delete [] smplData;
        smplData = NULL;
      }
      fm.UnloadFile();
      return 0;
    }
  } else if (!stricmp(ext, ".ogg")) {
    char full_path[256];
    if  (!fm.GetFullPath(fname,TypePath,&full_path[0])) {
      if (smplData != NULL) {
        delete [] smplData;
        smplData = NULL;
      }
      fm.UnloadFile();
      return 0;
    }
    if (!LoadOGG(&fmt,&smplData,&sizeData,&full_path[0])) {
      if (smplData != NULL) {
        delete [] smplData;
        smplData = NULL;
      }
      fm.UnloadFile();
      return 0;
    }
  } else {
    fm.UnloadFile();
    FONLINE_LOG("Ошибка - Загрузка звука - Неизвестный формат файла звука |%s|\n",fname);
    return 0;
  }

  fm.UnloadFile();

  DSBUFFERDESC dsbd;
  ZeroMemory(&dsbd,sizeof(DSBUFFERDESC));

  dsbd.dwBufferBytes=sizeData;
  dsbd.dwFlags=DSBCAPS_STATIC;// | DSBCAPS_LOCSOFTWARE |DSSCL_PRIORITY ;
  dsbd.dwSize=sizeof(DSBUFFERDESC);
  dsbd.lpwfxFormat=&fmt;
  dsbd.dwReserved=0;

  Sound* nsnd=new Sound;

  if (lpDS->CreateSoundBuffer(&dsbd,&nsnd->buf,0) != DS_OK) {
    if (smplData != NULL) {
      delete [] smplData;
      smplData = NULL;
    }
    FONLINE_LOG("Ошибка - Загрузка звука - Неудалось создать буфер для звука\n");
    return 0;
  }

  void *pDst=0;
  DWORD wSize=0;

  if (nsnd->buf->Lock(0, 0, &pDst, &wSize, 0, 0, DSBLOCK_ENTIREBUFFER) != DS_OK) {
    if (smplData != NULL) {
      delete [] smplData;
      smplData = NULL;
    }
    FONLINE_LOG("Ошибка - Загрузка звука - Невозможно заблокировать память\n");
    return 0;
  }

  memcpy(pDst, smplData, wSize);

  if (smplData != NULL) {
    delete [] smplData;
    smplData = NULL;
  }

  nsnd->buf->Unlock(pDst,wSize,0,0);

  cur_snd++;

  sounds.insert(sound_map::value_type(cur_snd,nsnd));

  return cur_snd;
}