OpenClonk
C4SoundLoaders::WavLoader Class Reference

#include <C4SoundLoaders.h>

Inheritance diagram for C4SoundLoaders::WavLoader:
[legend]
Collaboration diagram for C4SoundLoaders::WavLoader:
[legend]

Public Member Functions

bool ReadInfo (SoundInfo *result, BYTE *data, size_t data_length, uint32_t) override
 

Public Attributes

SoundLoadernext
 

Static Public Attributes

static const int OPTION_Raw = 1
 
static SoundLoaderfirst_loader
 

Static Protected Attributes

static WavLoader singleton
 

Detailed Description

Definition at line 101 of file C4SoundLoaders.h.

Member Function Documentation

◆ ReadInfo()

bool WavLoader::ReadInfo ( SoundInfo result,
BYTE data,
size_t  data_length,
uint32_t   
)
overridevirtual

Implements C4SoundLoaders::SoundLoader.

Definition at line 242 of file C4SoundLoaders.cpp.

243 {
244  // load WAV resource
246  ALuint wav = alutCreateBufferFromFileImage((const ALvoid *)data, data_length);
247  if (wav == AL_NONE)
248  {
249  return false;
250  }
251 
252  // get information about sound
253  ALint freq, chans, bits, size;
254  alGetBufferi(wav, AL_FREQUENCY, &freq);
255  result->sample_rate = freq;
256  alGetBufferi(wav, AL_CHANNELS, &chans);
257  alGetBufferi(wav, AL_BITS, &bits);
258  alGetBufferi(wav, AL_SIZE, &size);
259  if (chans == 1)
260  if (bits == 8)
261  result->format = AL_FORMAT_MONO8;
262  else
263  result->format = AL_FORMAT_MONO16;
264  else
265  if (bits == 8)
266  result->format = AL_FORMAT_STEREO8;
267  else
268  result->format = AL_FORMAT_STEREO16;
269  // can't find any function to determine sample length
270  // just calc ourselves
271  result->sample_length = double(size) / double(bits*chans*freq/8);
272  // buffer loaded
273  result->final_handle = wav;
274  return true;
275 }
C4Application Application
Definition: C4Globals.cpp:44
C4MusicSystem MusicSystem
Definition: C4Application.h:41
void SelectContext()

References Application, C4SoundLoaders::SoundInfo::final_handle, C4SoundLoaders::SoundInfo::format, C4Application::MusicSystem, C4SoundLoaders::SoundInfo::sample_length, C4SoundLoaders::SoundInfo::sample_rate, and C4MusicSystem::SelectContext().

Here is the call graph for this function:

Member Data Documentation

◆ first_loader

SoundLoader * SoundLoader::first_loader
staticinherited

◆ next

SoundLoader* C4SoundLoaders::SoundLoader::next
inherited

◆ OPTION_Raw

const int C4SoundLoaders::SoundLoader::OPTION_Raw = 1
staticinherited

Definition at line 41 of file C4SoundLoaders.h.

Referenced by C4SoundEffect::Load().

◆ singleton

WavLoader WavLoader::singleton
staticprotected

Definition at line 106 of file C4SoundLoaders.h.


The documentation for this class was generated from the following files: