made :getData produce SoundData directly

moved SoundData::load back to private

--HG--
branch : minor-mic-input
This commit is contained in:
Raidho
2016-10-25 02:39:39 +03:00
parent 3de68707d1
commit a99c757652
7 changed files with 36 additions and 42 deletions
+2 -3
View File
@@ -60,10 +60,9 @@ public:
/**
* Retreives recorded data.
* @param soundData Reference to a SoundData to fill.
* @return number of samples obtained from device.
* @return SoundData containing data obtained from recording device.
**/
virtual int getData(love::sound::SoundData *soundData) = 0;
virtual love::sound::SoundData *getData() = 0;
/**
* @return C string device name.
+2 -2
View File
@@ -52,9 +52,9 @@ void RecordingDevice::stopRecording()
{
}
int RecordingDevice::getData(love::sound::SoundData*)
love::sound::SoundData *RecordingDevice::getData()
{
return 0;
return nullptr;
}
int RecordingDevice::getSampleCount() const
+1 -1
View File
@@ -39,7 +39,7 @@ public:
virtual bool startRecording();
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
virtual void stopRecording();
virtual int getData(love::sound::SoundData *soundData);
virtual love::sound::SoundData *getData();
virtual const char *getName() const;
virtual int getID() const;
virtual int getSampleCount() const;
+8 -8
View File
@@ -20,6 +20,7 @@
#include "RecordingDevice.h"
#include "Audio.h"
#include "sound/Sound.h"
namespace love
{
@@ -28,6 +29,8 @@ namespace audio
namespace openal
{
#define soundInstance() (Module::getInstance<love::sound::Sound>(Module::M_SOUND))
class InvalidFormatException : public love::Exception
{
public:
@@ -99,23 +102,20 @@ void RecordingDevice::stopRecording()
device = nullptr;
}
int RecordingDevice::getData(love::sound::SoundData *soundData)
love::sound::SoundData *RecordingDevice::getData()
{
if (!isRecording())
return 0;
return nullptr;
int samples = getSampleCount();
if (samples == 0)
return 0;
return nullptr;
//reinitialize soundData if necessary
if (samples != soundData->getSampleCount() || sampleRate != soundData->getSampleRate() ||
bitDepth != soundData->getBitDepth() || channels != soundData->getChannels())
soundData->load(samples, sampleRate, bitDepth, channels);
love::sound::SoundData *soundData = soundInstance()->newSoundData(samples, sampleRate, bitDepth, channels);
alcCaptureSamples(device, soundData->getData(), samples);
return samples;
return soundData;
}
int RecordingDevice::getSampleCount() const
+1 -1
View File
@@ -52,7 +52,7 @@ public:
virtual bool startRecording();
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
virtual void stopRecording();
virtual int getData(love::sound::SoundData *soundData);
virtual love::sound::SoundData *getData();
virtual const char *getName() const;
virtual int getID() const;
virtual int getSampleCount() const;
+20 -26
View File
@@ -22,10 +22,6 @@
#include "wrap_Audio.h"
#include "sound/SoundData.h"
#include "sound/Sound.h"
#define soundInstance() (Module::getInstance<love::sound::Sound>(Module::M_SOUND))
namespace love
{
namespace audio
@@ -59,43 +55,41 @@ int w_RecordingDevice_startRecording(lua_State *L)
int w_RecordingDevice_stopRecording(lua_State *L)
{
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
int samples = d->getSampleCount();
if (samples == 0)
{
lua_pushnil(L);
return 1;
}
love::sound::SoundData *s = nullptr;
luax_catchexcept(L, [&](){
s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels());
d->getData(s);
s = d->getData();
d->stopRecording();
});
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
s->release();
if (s != nullptr)
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
s->release();
}
else
lua_pushnil(L);
return 1;
}
int w_RecordingDevice_getData(lua_State *L)
{
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
int samples = d->getSampleCount();
if (samples == 0)
{
lua_pushnil(L);
return 1;
}
love::sound::SoundData *s = nullptr;
luax_catchexcept(L, [&](){
s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels());
d->getData(s);
s = d->getData();
});
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
s->release();
if (s != nullptr)
{
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
s->release();
}
else
lua_pushnil(L);
return 1;
}
+2 -1
View File
@@ -54,10 +54,11 @@ public:
void setSample(int i, float sample);
float getSample(int i) const;
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
private:
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
uint8 *data;
size_t size;