mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
made :getData produce SoundData directly
moved SoundData::load back to private --HG-- branch : minor-mic-input
This commit is contained in:
@@ -60,10 +60,9 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retreives recorded data.
|
* Retreives recorded data.
|
||||||
* @param soundData Reference to a SoundData to fill.
|
* @return SoundData containing data obtained from recording device.
|
||||||
* @return number of samples obtained from device.
|
|
||||||
**/
|
**/
|
||||||
virtual int getData(love::sound::SoundData *soundData) = 0;
|
virtual love::sound::SoundData *getData() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return C string device name.
|
* @return C string device name.
|
||||||
|
|||||||
@@ -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
|
int RecordingDevice::getSampleCount() const
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
virtual bool startRecording();
|
virtual bool startRecording();
|
||||||
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
|
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
|
||||||
virtual void stopRecording();
|
virtual void stopRecording();
|
||||||
virtual int getData(love::sound::SoundData *soundData);
|
virtual love::sound::SoundData *getData();
|
||||||
virtual const char *getName() const;
|
virtual const char *getName() const;
|
||||||
virtual int getID() const;
|
virtual int getID() const;
|
||||||
virtual int getSampleCount() const;
|
virtual int getSampleCount() const;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "RecordingDevice.h"
|
#include "RecordingDevice.h"
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
|
#include "sound/Sound.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,8 @@ namespace audio
|
|||||||
namespace openal
|
namespace openal
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#define soundInstance() (Module::getInstance<love::sound::Sound>(Module::M_SOUND))
|
||||||
|
|
||||||
class InvalidFormatException : public love::Exception
|
class InvalidFormatException : public love::Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -99,23 +102,20 @@ void RecordingDevice::stopRecording()
|
|||||||
device = nullptr;
|
device = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RecordingDevice::getData(love::sound::SoundData *soundData)
|
love::sound::SoundData *RecordingDevice::getData()
|
||||||
{
|
{
|
||||||
if (!isRecording())
|
if (!isRecording())
|
||||||
return 0;
|
return nullptr;
|
||||||
|
|
||||||
int samples = getSampleCount();
|
int samples = getSampleCount();
|
||||||
if (samples == 0)
|
if (samples == 0)
|
||||||
return 0;
|
return nullptr;
|
||||||
|
|
||||||
//reinitialize soundData if necessary
|
love::sound::SoundData *soundData = soundInstance()->newSoundData(samples, sampleRate, bitDepth, channels);
|
||||||
if (samples != soundData->getSampleCount() || sampleRate != soundData->getSampleRate() ||
|
|
||||||
bitDepth != soundData->getBitDepth() || channels != soundData->getChannels())
|
|
||||||
soundData->load(samples, sampleRate, bitDepth, channels);
|
|
||||||
|
|
||||||
alcCaptureSamples(device, soundData->getData(), samples);
|
alcCaptureSamples(device, soundData->getData(), samples);
|
||||||
|
|
||||||
return samples;
|
return soundData;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RecordingDevice::getSampleCount() const
|
int RecordingDevice::getSampleCount() const
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
virtual bool startRecording();
|
virtual bool startRecording();
|
||||||
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
|
virtual bool startRecording(int samples, int sampleRate, int bitDepth, int channels);
|
||||||
virtual void stopRecording();
|
virtual void stopRecording();
|
||||||
virtual int getData(love::sound::SoundData *soundData);
|
virtual love::sound::SoundData *getData();
|
||||||
virtual const char *getName() const;
|
virtual const char *getName() const;
|
||||||
virtual int getID() const;
|
virtual int getID() const;
|
||||||
virtual int getSampleCount() const;
|
virtual int getSampleCount() const;
|
||||||
|
|||||||
@@ -22,10 +22,6 @@
|
|||||||
#include "wrap_Audio.h"
|
#include "wrap_Audio.h"
|
||||||
|
|
||||||
#include "sound/SoundData.h"
|
#include "sound/SoundData.h"
|
||||||
#include "sound/Sound.h"
|
|
||||||
|
|
||||||
#define soundInstance() (Module::getInstance<love::sound::Sound>(Module::M_SOUND))
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace audio
|
namespace audio
|
||||||
@@ -59,43 +55,41 @@ int w_RecordingDevice_startRecording(lua_State *L)
|
|||||||
int w_RecordingDevice_stopRecording(lua_State *L)
|
int w_RecordingDevice_stopRecording(lua_State *L)
|
||||||
{
|
{
|
||||||
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
|
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
|
||||||
int samples = d->getSampleCount();
|
|
||||||
if (samples == 0)
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
love::sound::SoundData *s = nullptr;
|
love::sound::SoundData *s = nullptr;
|
||||||
|
|
||||||
luax_catchexcept(L, [&](){
|
luax_catchexcept(L, [&](){
|
||||||
s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels());
|
s = d->getData();
|
||||||
d->getData(s);
|
|
||||||
d->stopRecording();
|
d->stopRecording();
|
||||||
});
|
});
|
||||||
|
|
||||||
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
|
if (s != nullptr)
|
||||||
s->release();
|
{
|
||||||
|
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
|
||||||
|
s->release();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_RecordingDevice_getData(lua_State *L)
|
int w_RecordingDevice_getData(lua_State *L)
|
||||||
{
|
{
|
||||||
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
|
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
|
||||||
int samples = d->getSampleCount();
|
|
||||||
if (samples == 0)
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
love::sound::SoundData *s = nullptr;
|
love::sound::SoundData *s = nullptr;
|
||||||
|
|
||||||
luax_catchexcept(L, [&](){
|
luax_catchexcept(L, [&](){
|
||||||
s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels());
|
s = d->getData();
|
||||||
d->getData(s);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
|
if (s != nullptr)
|
||||||
s->release();
|
{
|
||||||
|
luax_pushtype(L, SOUND_SOUND_DATA_ID, s);
|
||||||
|
s->release();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,10 +54,11 @@ public:
|
|||||||
|
|
||||||
void setSample(int i, float sample);
|
void setSample(int i, float sample);
|
||||||
float getSample(int i) const;
|
float getSample(int i) const;
|
||||||
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
|
||||||
|
|
||||||
uint8 *data;
|
uint8 *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user