Ejemplo n.º 1
0
bool wxSound::Create(const wxString& fileName, bool isResource)
{
    wxASSERT_MSG( !isResource,
             _T("Loading sound from resources is only supported on Windows") );

    Free();

    wxFile fileWave;
    if (!fileWave.Open(fileName, wxFile::read))
    {
        return false;
    }

    wxFileOffset len = fileWave.Length();
    wxUint8 *data = new wxUint8[len];
    if (fileWave.Read(data, len) != len)
    {
        wxLogError(_("Couldn't load sound data from '%s'."), fileName.c_str());
        return false;
    }

    if (!LoadWAV(data, len, false))
    {
        wxLogError(_("Sound file '%s' is in unsupported format."),
                   fileName.c_str());
        return false;
    }

    return true;
}
Ejemplo n.º 2
0
/* return CVT from AGG::Cache */
const std::vector<u8> & AGG::Cache::GetWAV(const M82::m82_t m82)
{
    const std::vector<u8> & v = wav_cache[m82];

    if(v.empty()) LoadWAV(m82);

    return v;
}
	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.º 4
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;
	}
}
Ejemplo n.º 5
0
bool wxSound::Create(int size, const wxByte* data)
{
    wxASSERT( data != NULL );

    Free();
    if (!LoadWAV(data, size, true))
    {
        wxLogError(_("Sound data are in unsupported format."));
        return false;
    }
    return true;
}
Ejemplo n.º 6
0
unsigned char *BBWin8Game::LoadAudioData( String path,int *length,int *channels,int *format,int *hertz ){

	FILE *f=OpenFile( path,"rb" );
	if( !f ) return 0;
	
	unsigned char *data=0;
	
	if( path.ToLower().EndsWith( ".wav" ) ){
	
		data=LoadWAV( f,length,channels,format,hertz );
		
	}else if( path.ToLower().EndsWith( ".ogg" ) ){
	
//		data=loadOGG( f,length,channels,format,hertz );
	}
	
	fclose( f );
	
	gc_force_sweep=true;
	
	return data;
}
Ejemplo n.º 7
0
bool wxSound::Create(const wxString& fileName,
                     bool WXUNUSED_UNLESS_DEBUG(isResource))
{
    wxASSERT_MSG( !isResource,
             wxT("Loading sound from resources is only supported on Windows") );

    Free();

    wxFile fileWave;
    if (!fileWave.Open(fileName, wxFile::read))
    {
        return false;
    }

    wxFileOffset lenOrig = fileWave.Length();
    if ( lenOrig == wxInvalidOffset )
        return false;

    size_t len = wx_truncate_cast(size_t, lenOrig);
    wxUint8 *data = new wxUint8[len];
    if ( fileWave.Read(data, len) != lenOrig )
    {
        delete [] data;
        wxLogError(_("Couldn't load sound data from '%s'."), fileName.c_str());
        return false;
    }

    if (!LoadWAV(data, len, false))
    {
        delete [] data;
        wxLogError(_("Sound file '%s' is in unsupported format."),
                   fileName.c_str());
        return false;
    }

    return true;
}
Ejemplo n.º 8
0
bool OCPN_Sound::Create(const wxString& fileName, bool isResource)
{
    m_OK = false;

    FreeMem();

    wxFile fileWave;
    if (!fileWave.Open(fileName, wxFile::read))
    {
        return false;
    }

    wxFileOffset lenOrig = fileWave.Length();
    if ( lenOrig == wxInvalidOffset )
        return false;

    size_t len = wx_truncate_cast(size_t, lenOrig);
    wxUint8 *data = new wxUint8[len];
    if ( fileWave.Read(data, len) != lenOrig )
    {
        delete [] data;
        wxLogError(_("Couldn't load sound data from '%s'."), fileName.c_str());
        return false;
    }
    
    if (!LoadWAV(data, len, true))
    {
        delete [] data;
        wxLogError(_("Sound file '%s' is in unsupported format."),
                   fileName.c_str());
        return false;
    }
    
    sdata = m_osdata->m_data;           //The raw sound data
    sindex = 0;
    smax_samples = m_osdata->m_samples;
 
    PaError err;
    m_stream = NULL;
    
    /* Open an audio I/O stream. */
    err = Pa_OpenDefaultStream( &m_stream,
                                0, /* no input channels */
                                m_osdata->m_channels, 
                                paInt16, 
                                m_osdata->m_samplingRate,
                                256, /* frames per buffer, i.e. the number
                                of sample frames that PortAudio will
                                request from the callback. Many apps
                                may want to use
                                paFramesPerBufferUnspecified, which
                                tells PortAudio to pick the best,
                                possibly changing, buffer size.*/
                                OCPNSoundCallback, /* this is your callback function */
                                sdata ); /*This is a pointer that will be passed to
                                your callback*/
    if( err != paNoError )
        printf( "PortAudio Create() error: %s\n", Pa_GetErrorText( err ) );

    err = Pa_SetStreamFinishedCallback( m_stream, OCPNSoundFinishedCallback ); 
    if( err != paNoError )
        printf( "PortAudio SetStreamFinishedCallback() error: %s\n", Pa_GetErrorText( err ) );
    
    m_OK = true;
    
    return true;
}
Ejemplo n.º 9
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.º 10
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;
}