start 380 project5

changes to 380 project 4
changes to 350 project 2

Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
Amrit Panesar committed 2015-05-06 10:18:39 -07:00
1 parent 40ac78074b
commit 39ee821f54
174 files changed
+13356 -80

No files matched your search

@@ -0,0 +1,67 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkSoundDevice.h"
#include <AL\alut.h>
#include <AL\al.h>
void GkSoundDevice::Initialize()
{
alutInit(0, 0);
}
void GkSoundDevice::Close()
{
alutExit();
}
GkSoundDevice::GkSoundDevice(int volume)
{
this->volume = volume;
}
GkSoundDevice::~GkSoundDevice(void)
{
}
bool GkSoundDevice::IsPlaying(GkSoundSource *soundSource)
{
ALenum state;
alGetSourcei(soundSource->handle, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
}
void GkSoundDevice::PlaySource(GkSoundSource *soundSource)
{
alSourcei (soundSource->handle, AL_LOOPING, AL_FALSE);
alSourcef (soundSource->handle, AL_GAIN, this->volume / 10.0f);
alSourcePlay(soundSource->handle);
}
void GkSoundDevice::PlaySourceLooping(GkSoundSource *soundSource)
{
alSourcei (soundSource->handle, AL_LOOPING, AL_TRUE);
alSourcePlay(soundSource->handle);
}
void GkSoundDevice::PauseSource(GkSoundSource *soundSource)
{
alSourcePause(soundSource->handle);
}
void GkSoundDevice::StopSource(GkSoundSource *soundSource)
{
alSourceStop(soundSource->handle);
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkSoundSource.h"
class GKDLLCLASS GkSoundDevice
{
public:
int volume;
static void Initialize();
static void Close();
GkSoundDevice(int volume = 100);
~GkSoundDevice(void);
bool IsPlaying(GkSoundSource *soundSource);
void PlaySource(GkSoundSource *soundSource);
void PlaySourceLooping(GkSoundSource *soundSource);
void PauseSource(GkSoundSource *soundSource);
void StopSource(GkSoundSource *soundSource);
};
@@ -0,0 +1,87 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkSoundSource.h"
#include <string>
#include <AL\alut.h>
#pragma pack(1)
struct WAVFileHeader
{
char chunkID[4]; // "RIFF"
unsigned int chunkSize;
char format[4]; // "WAVE"
char subchunk1Id[4]; // "fmt "
unsigned int subchunk1Size;
unsigned short audioFormat; // 1 - PCM
unsigned short numChannels; // 1 - mono, 2 - stereo
unsigned int sampleRate; // 22050, 44100, etc.
unsigned int byteRate; // == SampleRate * NumChannels * BitsPerSample / 8
unsigned short blockAlign; // == NumChannels * BitsPerSample / 8. The number of bytes for one sample including
unsigned short bitsPerSample; // 8, 16, etc.
//unsigned short extraParamsSize; //if PCM does not exist
//extraParams; //variable format
//char subchunk2Id[4]; // "data"
//unsigned int subchunk2Size;
};
GkSoundSource::GkSoundSource(void)
{
alGenSources(1, &this->handle);
this->buffer = 0;
}
GkSoundSource::~GkSoundSource(void)
{
this->UnloadBuffer();
alDeleteSources(1, &this->handle);
}
void GkSoundSource::LoadFromMemory(void *wavData)
{
ALenum format;
ALvoid *data;
ALsizei size, frequency;
WAVFileHeader *header = (WAVFileHeader*)wavData;
int dataOffset = 20 + header->subchunk1Size;
while (memcmp((char*)&((char*)wavData)[dataOffset], &"data", 4) != 0)
{
dataOffset += *((int*)&(((char*)wavData)[dataOffset + 4])) + 8;
}
size = *((int*)&(((char*)wavData)[dataOffset + 4]));
data = (ALvoid*)&(((char*)wavData)[dataOffset + 8]);
format = header->numChannels == 1 ? header->bitsPerSample == 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16 : header->bitsPerSample == 8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
frequency = header->sampleRate;
this->UnloadBuffer();
alGenBuffers(1, &this->buffer);
alBufferData(this->buffer, format, data, size, frequency);
alSourcei(this->handle, AL_BUFFER, this->buffer);
}
void GkSoundSource::UnloadBuffer()
{
if (this->buffer == 0)
return;
alDeleteBuffers(1, &this->buffer);
this->buffer = 0;
}
@@ -0,0 +1,20 @@
#pragma once
#include "..\GkDefinitions.h"
#include <AL\al.h>
#include "..\Base\GkBase.h"
class GKDLLCLASS GkSoundSource
: public GkBase
{
public:
ALuint handle, buffer;
GkSoundSource::GkSoundSource(void);
GkSoundSource::~GkSoundSource(void);
void GkSoundSource::LoadFromMemory(void *data);
void GkSoundSource::UnloadBuffer();
};