#include <cstdio>#include <vector>#include <vorbis/vorbisfile.h>#include <AL/al.h>#include <AL/alut.h>#include "Log.h"#include "soundfile.h"Include dependency graph for soundfile.cpp:

Go to the source code of this file.
Defines | |
| #define | BUFFER_SIZE 32768 |
Functions | |
| bool | LoadOgg (const char *fileName, ALuint *buffer) |
| ALuint | GenSource () |
| ALuint | GenSource (ALuint buffer) |
| #define BUFFER_SIZE 32768 |
| ALuint GenSource | ( | ALuint | buffer | ) |
Definition at line 121 of file soundfile.cpp.
References GenSource().
00121 { 00122 ALuint source = GenSource(); 00123 00124 if (source == 0) { 00125 return source; 00126 } 00127 00128 alSourcei(source, AL_BUFFER, buffer); 00129 00130 return source; 00131 }
| ALuint GenSource | ( | ) |
Definition at line 100 of file soundfile.cpp.
Referenced by GenSource(), and OpenALSource::OpenALSource().
00100 { 00101 ALuint source; 00102 bool looping = false; 00103 ALfloat sourcePos[] = {0.0, 0.0, 0.0}; 00104 ALfloat sourceVel[] = {0.0, 0.0, 0.0}; 00105 00106 // Bind buffer with a source. 00107 alGenSources(1, &source); 00108 00109 if (alGetError() != AL_NO_ERROR) 00110 return 0; 00111 00112 alSourcef(source, AL_PITCH, 1.0); 00113 alSourcef(source, AL_GAIN, 1.0); 00114 alSourcefv(source, AL_POSITION, sourcePos); 00115 alSourcefv(source, AL_VELOCITY, sourceVel); 00116 alSourcei(source, AL_LOOPING, looping); 00117 00118 return source; 00119 }
| bool LoadOgg | ( | const char * | fileName, | |
| ALuint * | buffer | |||
| ) |
Definition at line 17 of file soundfile.cpp.
References BUFFER_SIZE.
Referenced by SoundResource::Load().
00017 { 00018 int endian = 0; // 0 for Little-Endian, 1 for Big-Endian 00019 int bitStream; 00020 long bytes; 00021 char *array; 00022 vector <char> data; 00023 FILE *f; 00024 ALenum format; 00025 ALsizei freq; 00026 00027 vorbis_info *pInfo; 00028 OggVorbis_File oggFile; 00029 00030 // Open for binary reading 00031 f = fopen(fileName, "rb"); 00032 if (!f) { 00033 return false; 00034 } 00035 00036 ov_open(f, &oggFile, NULL, 0); 00037 00038 // Get some information about the OGG file 00039 pInfo = ov_info(&oggFile, -1); 00040 00041 // Check the number of channels... always use 16-bit samples 00042 if (pInfo->channels == 1) 00043 format = AL_FORMAT_MONO16; 00044 else 00045 format = AL_FORMAT_STEREO16; 00046 00047 // The frequency of the sampling rate 00048 freq = pInfo->rate; 00049 00050 array = new char[BUFFER_SIZE]; 00051 00052 do { 00053 // Read up to a buffer's worth of decoded sound data 00054 bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream); 00055 // Append to end of buffer 00056 data.insert(data.end(), array, array + bytes); 00057 } while (bytes > 0); 00058 00059 delete []array; 00060 00061 ov_clear(&oggFile); 00062 00063 // Don't call fclose(f), ogg vorbis does it 00064 alGenBuffers(1, buffer); 00065 if (alGetError() != AL_NO_ERROR) { 00066 return false; 00067 } 00068 alBufferData(*buffer, format, &data[0], data.size(), freq); 00069 00070 return true; 00071 }
1.4.7