Example #1
0
/**
 * @brief Loads a sound into the sound_list.
 *
 *    @param filename Name fo the file to load.
 *    @return The SDL_Mixer of the loaded chunk.
 *
 * @sa sound_makeList
 */
int sound_mix_load( alSound *s, const char *filename )
{
   SDL_RWops *rw;
   int freq, bytes, channels;
   Uint16 format;

   /* get the file data buffer from packfile */
   rw = ndata_rwops( filename );

   /* bind to buffer */
   s->u.mix.buf = Mix_LoadWAV_RW(rw,1);
   if (s->u.mix.buf == NULL) {
      DEBUG("Unable to load sound '%s': %s", filename, Mix_GetError());
      return -1;
   }

   /* Get spec. */
   Mix_QuerySpec( &freq, &format, &channels );
   switch (format) {
      case AUDIO_U8:
      case AUDIO_S8:
         bytes = 1;
         break;
      default:
         bytes = 2;
         break;
   }

   /* Set length. */
   s->length = (double)s->u.mix.buf->alen / (double)(freq*bytes*channels);

   return 0;
}
Example #2
0
/**
 * @brief Loads the sound.
 *
 *    @param snd Sound to load.
 *    @param filename Name of the file to load into sound.
 */
int sound_al_load( alSound *snd, const char *filename )
{
   int ret;
   SDL_RWops *rw;
   OggVorbis_File vf;
   ALint freq, bits, channels, size;

   /* get the file data buffer from packfile */
   rw = ndata_rwops( filename );

   /* Check to see if it's an OGG. */
   if (ov_test_callbacks( rw, &vf, NULL, 0, sound_al_ovcall_noclose )==0) {
      ret = sound_al_loadOgg( snd, &vf );
   }
   /* Otherwise try WAV. */
   else {
      /* Destroy the partially loaded vorbisfile. */
      ov_clear(&vf);

      /* Try to load Wav. */
      ret = sound_al_loadWav( snd, rw );
   }

   /* Close RWops. */
   SDL_RWclose(rw);

   /* Failed to load. */
   if (ret != 0) {
      WARN("Failed to load sound file '%s'.", filename);
      return ret;
   }

   soundLock();

   /* Get the length of the sound. */
   alGetBufferi( snd->u.al.buf, AL_FREQUENCY, &freq );
   alGetBufferi( snd->u.al.buf, AL_BITS, &bits );
   alGetBufferi( snd->u.al.buf, AL_CHANNELS, &channels );
   alGetBufferi( snd->u.al.buf, AL_SIZE, &size );
   if ((freq==0) || (bits==0) || (channels==0)) {
      WARN("Something went wrong when loading sound file '%s'.", filename);
      snd->length = 0;
   }
   else
      snd->length = (double)size / (double)(freq * (bits/8) * channels);

   /* Check for errors. */
   al_checkErr();

   soundUnlock();

   return 0;
}
Example #3
0
File: naev.c Project: ekrumme/naev
/**
 * @brief Sets the window caption.
 */
static void window_caption (void)
{
   char buf[PATH_MAX];
   SDL_RWops *rw;

   /* Set caption. */
   snprintf(buf, PATH_MAX ,APPNAME" - %s", ndata_name());
   SDL_WM_SetCaption(buf, APPNAME);

   /* Set icon. */
   rw = ndata_rwops( "gfx/icon.png" );
   if (rw == NULL) {
      WARN("Icon (gfx/icon.png) not found!");
      return;
   }
   naev_icon = IMG_Load_RW( rw, 1 );
   if (naev_icon == NULL) {
      WARN("Unable to load gfx/icon.png!");
      return;
   }
   SDL_WM_SetIcon( naev_icon, NULL );
}
Example #4
0
/**
 * @brief Loads the music by name.
 *
 *    @param name Name of the file to load.
 */
int music_load( const char* name )
{
   SDL_RWops *rw;
   char filename[PATH_MAX];

   if (music_disabled)
      return 0;

   /* Free current music if needed. */
   music_free();

   /* Load new music. */
   music_name  = strdup(name);
   music_start = SDL_GetTicks();
   snprintf( filename, PATH_MAX, MUSIC_PREFIX"%s"MUSIC_SUFFIX, name);
   rw = ndata_rwops( filename );
   if (rw == NULL) {
      WARN("Music '%s' not found.", filename);
      return -1;
   }
   music_sys_load( name, rw );

   return 0;
}