29 #include "nomlib/audio/AL/SoundFile.hpp"
34 SoundFile::SoundFile (
void )
36 NOM_LOG_TRACE ( NOM );
43 SoundFile::~SoundFile (
void )
45 NOM_LOG_TRACE ( NOM );
74 bool SoundFile::open (
const std::string& filename )
78 this->
fp = std::shared_ptr<SNDFILE> ( sf_open ( filename.c_str(), SFM_READ, &info ), sf_close );
80 if ( this->
fp.get() == nullptr )
82 NOM_LOG_ERR ( NOM,
"Could not not audio file: " + filename );
91 switch ( info.channels )
94 case 1: this->
channel_format = alGetEnumValue (
"AL_FORMAT_MONO16" );
break;
95 case 2: this->
channel_format = alGetEnumValue (
"AL_FORMAT_STEREO16" );
break;
96 case 4: this->
channel_format = alGetEnumValue (
"AL_FORMAT_QUAD16" );
break;
97 case 6: this->
channel_format = alGetEnumValue (
"AL_FORMAT_51CHN16" );
break;
98 case 7: this->
channel_format = alGetEnumValue (
"AL_FORMAT_61CHN16" );
break;
99 case 8: this->
channel_format = alGetEnumValue (
"AL_FORMAT_71CHN16" );
break;
105 bool SoundFile::read ( std::vector<int16>& data )
107 size_t read_size = 0;
108 std::vector<int16> read_buffer;
109 read_buffer.resize ( BUFFER_SIZE );
111 while ( ( read_size = sf_read_short ( this->
fp.get(), read_buffer.data(), read_buffer.size() ) ) != 0 )
113 data.insert ( data.end(), read_buffer.begin(), read_buffer.begin() + read_size);
uint32 getChannelCount(void) const
Obtain number of channels used by audio file.
uint32 getChannelFormat(void) const
Obtain channel format; used internally by OpenAL.
uint32 getSampleRate(void) const
Obtain audio sampling rate; this is the number of samples per second.
uint32 channel_count
Number of audio channels used by sound.
uint32 sample_rate
Number of samples per second.
std::shared_ptr< SNDFILE > fp
SNDFILE* file descriptor.
size_t getDataByteSize(void) const
Obtain audio data size in bytes.
size_t getSampleCount(void) const
Obtain number of samples in audio file.
int32 channel_format
OpenAL compatible audio channels used by sound.
std::size_t sample_count
Total number of samples in the file.