Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring

HelloOpenAL folder moved to HelloOpenALOggVorbis for clarity.
Changing code style to suit cascades samples.
removed libasound.a from .pro file.
  • Loading branch information...
commit b238ad4fc75b7c64ea16881ef09450b1f14f7bfb 1 parent 7dc4b0f
Ramprasad Madhavan authored
Showing with 46 additions and 82 deletions.
  1. 0  {HelloOpenAL → HelloOpenALOggVorbis}/.cproject
  2. 0  {HelloOpenAL → HelloOpenALOggVorbis}/.project
  3. +2 −2 HelloOpenAL/HelloOpenAL.pro → HelloOpenALOggVorbis/HelloOpenALOggVorbis.pro
  4. 0  {HelloOpenAL → HelloOpenALOggVorbis}/LICENSE
  5. +1 −1  {HelloOpenAL → HelloOpenALOggVorbis}/Makefile
  6. 0  {HelloOpenAL → HelloOpenALOggVorbis}/Notice
  7. 0  {HelloOpenAL → HelloOpenALOggVorbis}/README.md
  8. 0  {HelloOpenAL → HelloOpenALOggVorbis}/assets/cowbell.qml
  9. 0  {HelloOpenAL → HelloOpenALOggVorbis}/assets/images/background.png
  10. 0  {HelloOpenAL → HelloOpenALOggVorbis}/assets/images/bell.png
  11. 0  {HelloOpenAL → HelloOpenALOggVorbis}/assets/sounds/cowbell.wav
  12. 0  {HelloOpenAL → HelloOpenALOggVorbis}/assets/sounds/moo.ogg
  13. +3 −4 {HelloOpenAL → HelloOpenALOggVorbis}/bar-descriptor.xml
  14. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/include/ogg/ogg.h
  15. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/include/ogg/os_types.h
  16. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/include/vorbis/codec.h
  17. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/include/vorbis/vorbisenc.h
  18. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/include/vorbis/vorbisfile.h
  19. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/lib/qnx/arm/libvorbis.a
  20. 0  {HelloOpenAL → HelloOpenALOggVorbis}/external-lib/oggvorbis/lib/qnx/x86/libvorbis.a
  21. 0  {HelloOpenAL → HelloOpenALOggVorbis}/icon.png
  22. 0  {HelloOpenAL → HelloOpenALOggVorbis}/src/cowbellapp.cpp
  23. 0  {HelloOpenAL → HelloOpenALOggVorbis}/src/cowbellapp.h
  24. 0  {HelloOpenAL → HelloOpenALOggVorbis}/src/main.cpp
  25. +40 −75 {HelloOpenAL → HelloOpenALOggVorbis}/src/soundmanager.cpp
  26. 0  {HelloOpenAL → HelloOpenALOggVorbis}/src/soundmanager.h
View
0  HelloOpenAL/.cproject → HelloOpenALOggVorbis/.cproject
File renamed without changes
View
0  HelloOpenAL/.project → HelloOpenALOggVorbis/.project
File renamed without changes
View
4 HelloOpenAL/HelloOpenAL.pro → ...oOpenALOggVorbis/HelloOpenALOggVorbis.pro
@@ -2,11 +2,11 @@ TEMPLATE = app
TARGET = cowbell
CONFIG += qt warn_on debug_and_release cascades
-LIBS += -lOpenAL -lalut -lasound -L../external-lib/oggvorbis/lib/qnx/arm/ -L../external-lib/oggvorbis/lib/qnx/x86/ -lvorbis
+LIBS += -lOpenAL -lalut -L../external-lib/oggvorbis/lib/qnx/arm/ -L../external-lib/oggvorbis/lib/qnx/x86/ -lvorbis
INCLUDEPATH += ../src ../external-lib/oggvorbis/include
SOURCES += ../src/*.cpp
-HEADERS += ../src/*.h ../external-lib/oggvorbis/include/vorbis/*.h ../external-lib/oggvorbis/include/ogg/*.h
+HEADERS += ../src/*.h
device {
CONFIG(release, debug|release) {
View
0  HelloOpenAL/LICENSE → HelloOpenALOggVorbis/LICENSE
File renamed without changes
View
2  HelloOpenAL/Makefile → HelloOpenALOggVorbis/Makefile
@@ -1,4 +1,4 @@
-QMAKE_TARGET = HelloOpenAL
+QMAKE_TARGET = HelloOpenALOggVorbis
QMAKE = $(QNX_HOST)/usr/bin/qmake
TARGET = $(QMAKE_TARGET)
View
0  HelloOpenAL/Notice → HelloOpenALOggVorbis/Notice
File renamed without changes
View
0  HelloOpenAL/README.md → HelloOpenALOggVorbis/README.md
File renamed without changes
View
0  HelloOpenAL/assets/cowbell.qml → HelloOpenALOggVorbis/assets/cowbell.qml
File renamed without changes
View
0  HelloOpenAL/assets/images/background.png → ...nALOggVorbis/assets/images/background.png
File renamed without changes
View
0  HelloOpenAL/assets/images/bell.png → HelloOpenALOggVorbis/assets/images/bell.png
File renamed without changes
View
0  HelloOpenAL/assets/sounds/cowbell.wav → ...OpenALOggVorbis/assets/sounds/cowbell.wav
File renamed without changes
View
0  HelloOpenAL/assets/sounds/moo.ogg → HelloOpenALOggVorbis/assets/sounds/moo.ogg
File renamed without changes
View
7 HelloOpenAL/bar-descriptor.xml → HelloOpenALOggVorbis/bar-descriptor.xml
@@ -9,11 +9,11 @@
<!-- A universally unique application identifier. Must be unique across all BlackBerry 10 applications.
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
- <id>com.example.helloopenal</id>
+ <id>com.example.openALOggVorbis</id>
<!-- The name that is displayed in the BlackBerry 10 application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
- <name>HelloOpenAL</name>
+ <name>HelloOpenALOggVorbis</name>
<!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade.
Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
@@ -26,8 +26,7 @@
<!-- Description, displayed in the BlackBerry 10 application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
- <description>The modified &quot;Cascades Cowbell&quot; application that shows how to use OpenAL API and OggVorbis library to
-load compressed audio data.</description>
+ <description>The modified &quot;Cascades Cowbell&quot; application that shows how to use OpenAL API and OggVorbis library to load compressed audio data.</description>
<!-- Name of author which is used for signing. Must match the developer name of your development certificate. -->
<author>Example Inc.</author>
View
0  .../external-lib/oggvorbis/include/ogg/ogg.h → .../external-lib/oggvorbis/include/ogg/ogg.h
File renamed without changes
View
0  ...rnal-lib/oggvorbis/include/ogg/os_types.h → ...rnal-lib/oggvorbis/include/ogg/os_types.h
File renamed without changes
View
0  ...rnal-lib/oggvorbis/include/vorbis/codec.h → ...rnal-lib/oggvorbis/include/vorbis/codec.h
File renamed without changes
View
0  ...-lib/oggvorbis/include/vorbis/vorbisenc.h → ...-lib/oggvorbis/include/vorbis/vorbisenc.h
File renamed without changes
View
0  ...lib/oggvorbis/include/vorbis/vorbisfile.h → ...lib/oggvorbis/include/vorbis/vorbisfile.h
File renamed without changes
View
0  ...nal-lib/oggvorbis/lib/qnx/arm/libvorbis.a → ...nal-lib/oggvorbis/lib/qnx/arm/libvorbis.a
File renamed without changes
View
0  ...nal-lib/oggvorbis/lib/qnx/x86/libvorbis.a → ...nal-lib/oggvorbis/lib/qnx/x86/libvorbis.a
File renamed without changes
View
0  HelloOpenAL/icon.png → HelloOpenALOggVorbis/icon.png
File renamed without changes
View
0  HelloOpenAL/src/cowbellapp.cpp → HelloOpenALOggVorbis/src/cowbellapp.cpp
File renamed without changes
View
0  HelloOpenAL/src/cowbellapp.h → HelloOpenALOggVorbis/src/cowbellapp.h
File renamed without changes
View
0  HelloOpenAL/src/main.cpp → HelloOpenALOggVorbis/src/main.cpp
File renamed without changes
View
115 HelloOpenAL/src/soundmanager.cpp → HelloOpenALOggVorbis/src/soundmanager.cpp
@@ -82,57 +82,49 @@ SoundManager::SoundManager(QString soundDirectory)
alGenBuffers(1, &mSoundBuffers[fileInfo.fileName()]);
error = alGetError();
- if (error != AL_NO_ERROR)
- {
+ if (error != AL_NO_ERROR) {
reportOpenALError(error);
break;
}
// Load sound file.
FILE* file = fopen(path, "rb");
- if (!file)
- {
+ if (!file) {
qDebug() << "Failed to load audio file " << path;
break;
}
// Read the file header
char header[12];
- if (fread(header, 1, 12, file) != 12)
- {
+ ALuint bufferId = mSoundBuffers[fileInfo.fileName()];
+ if (fread(header, 1, 12, file) != 12) {
qDebug() << "Invalid header for audio file " << path;
- alDeleteBuffers(1, &mSoundBuffers[fileInfo.fileName()]);
+ alDeleteBuffers(1, &bufferId);
goto cleanup;
}
// Check the file format & load the buffer with audio data.
- if (memcmp(header, "RIFF", 4) == 0)
- {
- if (!loadWav(file, mSoundBuffers[fileInfo.fileName()]))
- {
+ if (memcmp(header, "RIFF", 4) == 0) {
+ if (!loadWav(file, bufferId)) {
qDebug() << "Invalid wav file: " << path;
- alDeleteBuffers(1, &mSoundBuffers[fileInfo.fileName()]);
+ alDeleteBuffers(1, &bufferId);
goto cleanup;
}
}
- else if (memcmp(header, "OggS", 4) == 0)
- {
- if (!loadOgg(file, mSoundBuffers[fileInfo.fileName()]))
- {
+ else if (memcmp(header, "OggS", 4) == 0) {
+ if (!loadOgg(file, bufferId)) {
qDebug() << "Invalid ogg file: " << path;
- alDeleteBuffers(1, &mSoundBuffers[fileInfo.fileName()]);
+ alDeleteBuffers(1, &bufferId);
goto cleanup;
}
}
- else
- {
+ else {
qDebug() << "Unsupported audio file: " << path;
goto cleanup;
}
cleanup:
- if (file)
- {
+ if (file) {
fclose(file);
}
}
@@ -194,8 +186,7 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
unsigned char stream[12];
// Verify the wave fmt magic value meaning format.
- if (fread(stream, 1, 8, file) != 8 || memcmp(stream, "fmt ", 4) != 0 )
- {
+ if (fread(stream, 1, 8, file) != 8 || memcmp(stream, "fmt ", 4) != 0 ) {
qDebug() << "Failed to verify the magic value for the wave file format.";
return false;
}
@@ -207,16 +198,14 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
section_size |= stream[4];
// Check for a valid pcm format.
- if (fread(stream, 1, 2, file) != 2 || stream[1] != 0 || stream[0] != 1)
- {
+ if (fread(stream, 1, 2, file) != 2 || stream[1] != 0 || stream[0] != 1) {
qDebug() << "Unsupported audio file format (must be a valid PCM format).";
return false;
}
// Get the channel count (16-bit little-endian).
int channels;
- if (fread(stream, 1, 2, file) != 2)
- {
+ if (fread(stream, 1, 2, file) != 2) {
qDebug() << "Failed to read the wave file's channel count.";
return false;
}
@@ -225,8 +214,7 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
// Get the sample frequency (32-bit little-endian).
ALuint frequency;
- if (fread(stream, 1, 4, file) != 4)
- {
+ if (fread(stream, 1, 4, file) != 4) {
qDebug() << "Failed to read the wave file's sample frequency.";
return false;
}
@@ -239,16 +227,14 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
// The next 6 bytes hold the block size and bytes-per-second.
// We don't need that info, so just read and ignore it.
// We could use this later if we need to know the duration.
- if (fread(stream, 1, 6, file) != 6)
- {
+ if (fread(stream, 1, 6, file) != 6) {
qDebug() << "Failed to read past the wave file's block size and bytes-per-second.";
return false;
}
// Get the bit depth (16-bit little-endian).
int bits;
- if (fread(stream, 1, 2, file) != 2)
- {
+ if (fread(stream, 1, 2, file) != 2) {
qDebug() << "Failed to read the wave file's bit depth.";
return false;
}
@@ -257,70 +243,59 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
// Now convert the given channel count and bit depth into an OpenAL format.
ALuint format = 0;
- if (bits == 8)
- {
+ if (bits == 8) {
if (channels == 1)
format = AL_FORMAT_MONO8;
else if (channels == 2)
format = AL_FORMAT_STEREO8;
}
- else if (bits == 16)
- {
+ else if (bits == 16) {
if (channels == 1)
format = AL_FORMAT_MONO16;
else if (channels == 2)
format = AL_FORMAT_STEREO16;
}
- else
- {
+ else {
qDebug() << "Incompatible wave file format: ( " << channels << ", " << bits << ")";
return false;
}
// Check against the size of the format header as there may be more data that we need to read.
- if (section_size > 16)
- {
+ if (section_size > 16) {
unsigned int length = section_size - 16;
// Extension size is 2 bytes.
- if (fread(stream, 1, length, file) != length)
- {
+ if (fread(stream, 1, length, file) != length) {
qDebug() << "Failed to read extension size from wave file.";
return false;
}
}
// Read in the rest of the file a chunk (section) at a time.
- while (true)
- {
+ while (true) {
// Check if we are at the end of the file without reading the data.
- if (feof(file))
- {
+ if (feof(file)) {
qDebug() << "Failed to load wave file; file appears to have no data.";
return false;
}
// Read in the type of the next section of the file.
- if (fread(stream, 1, 4, file) != 4)
- {
+ if (fread(stream, 1, 4, file) != 4) {
qDebug() << "Failed to read next section type from wave file.";
return false;
}
// Data chunk.
- if (memcmp(stream, "data", 4) == 0)
- {
+ if (memcmp(stream, "data", 4) == 0) {
// Read how much data is remaining and buffer it up.
unsigned int dataSize;
- if (fread(&dataSize, sizeof(int), 1, file) != 1)
- {
+ if (fread(&dataSize, sizeof(int), 1, file) != 1) {
qDebug() << "Failed to read size of data section from wave file.";
return false;
}
char* data = new char[dataSize];
- if (fread(data, sizeof(char), dataSize, file) != dataSize)
- {
+ if (fread(data, sizeof(char), dataSize, file) != dataSize) {
qDebug() << "Failed to load wave file; file is missing data.";
delete data;
return false;
@@ -348,15 +323,13 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
// - Labeled Text ("ltxt")
// - Sampler ("smpl")
// - Instrument ("inst")
- else
- {
+ else {
// Store the name of the chunk so we can report errors informatively.
char chunk[5] = { 0 };
memcpy(chunk, stream, 4);
// Read the chunk size.
- if (fread(stream, 1, 4, file) != 4)
- {
+ if (fread(stream, 1, 4, file) != 4) {
qDebug() << "Failed to read size of " << chunk << "chunk from wave file.";
return false;
}
@@ -367,8 +340,7 @@ bool SoundManager::loadWav(FILE* file, ALuint buffer)
section_size |= stream[0];
// Seek past the chunk.
- if (fseek(file, section_size, SEEK_CUR) != 0)
- {
+ if (fseek(file, section_size, SEEK_CUR) != 0) {
qDebug() << "Failed to seek past " << chunk << "in wave file.";
return false;
}
@@ -389,8 +361,7 @@ bool SoundManager::loadOgg(FILE* file, ALuint buffer)
rewind(file);
- if ((result = ov_open(file, &ogg_file, NULL, 0)) < 0)
- {
+ if ((result = ov_open(file, &ogg_file, NULL, 0)) < 0) {
fclose(file);
qDebug() << "Failed to open ogg file.";
return false;
@@ -407,27 +378,22 @@ bool SoundManager::loadOgg(FILE* file, ALuint buffer)
unsigned int data_size = ov_pcm_total(&ogg_file, -1) * info->channels * 2;
char* data = new char[data_size];
- while (size < data_size)
- {
+ while (size < data_size) {
result = ov_read(&ogg_file, data + size, data_size - size, 0, 2, 1, &section);
- if (result > 0)
- {
+ if (result > 0) {
size += result;
}
- else if (result < 0)
- {
+ else if (result < 0) {
delete data;
qDebug() << "Failed to read ogg file; file is missing data.";
return false;
}
- else
- {
+ else {
break;
}
}
- if (size == 0)
- {
+ if (size == 0) {
delete data;
qDebug() << "Filed to read ogg file; unable to read any data.";
return false;
@@ -436,8 +402,7 @@ bool SoundManager::loadOgg(FILE* file, ALuint buffer)
alBufferData(buffer, format, data, data_size, info->rate);
ALenum error = alGetError();
- if (error != AL_NO_ERROR)
- {
+ if (error != AL_NO_ERROR) {
reportOpenALError(error);
}
View
0  HelloOpenAL/src/soundmanager.h → HelloOpenALOggVorbis/src/soundmanager.h
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.