mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
RecordingDevice:start has default arguments (resolves issue #1296).
--HG-- branch : minor
This commit is contained in:
@@ -37,15 +37,14 @@ public:
|
||||
|
||||
static love::Type type;
|
||||
|
||||
static const int DEFAULT_SAMPLES = 8192;
|
||||
static const int DEFAULT_SAMPLE_RATE = 8000;
|
||||
static const int DEFAULT_BIT_DEPTH = 16;
|
||||
static const int DEFAULT_CHANNELS = 1;
|
||||
|
||||
RecordingDevice();
|
||||
virtual ~RecordingDevice();
|
||||
|
||||
/**
|
||||
* Begins audio input recording process. using default (previous) parameters.
|
||||
* @return True if recording started successfully.
|
||||
**/
|
||||
virtual bool start() = 0;
|
||||
|
||||
/**
|
||||
* Begins audio input recording process.
|
||||
* @param samples Number of samples to buffer.
|
||||
@@ -96,6 +95,7 @@ public:
|
||||
* @return True if currently recording.
|
||||
**/
|
||||
virtual bool isRecording() const = 0;
|
||||
|
||||
}; //RecordingDevice
|
||||
|
||||
} //audio
|
||||
|
||||
@@ -38,11 +38,6 @@ RecordingDevice::~RecordingDevice()
|
||||
{
|
||||
}
|
||||
|
||||
bool RecordingDevice::start()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RecordingDevice::start(int, int, int, int)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -36,7 +36,6 @@ class RecordingDevice : public love::audio::RecordingDevice
|
||||
public:
|
||||
RecordingDevice(const char *name);
|
||||
virtual ~RecordingDevice();
|
||||
virtual bool start();
|
||||
virtual bool start(int samples, int sampleRate, int bitDepth, int channels);
|
||||
virtual void stop();
|
||||
virtual love::sound::SoundData *getData();
|
||||
|
||||
@@ -56,19 +56,8 @@ RecordingDevice::~RecordingDevice()
|
||||
alcCaptureCloseDevice(device);
|
||||
}
|
||||
|
||||
bool RecordingDevice::start()
|
||||
{
|
||||
return start(samples, sampleRate, bitDepth, channels);
|
||||
}
|
||||
|
||||
bool RecordingDevice::start(int samples, int sampleRate, int bitDepth, int channels)
|
||||
{
|
||||
if (isRecording())
|
||||
{
|
||||
alcCaptureStop(device);
|
||||
alcCaptureCloseDevice(device);
|
||||
}
|
||||
|
||||
ALenum format = Audio::getFormat(bitDepth, channels);
|
||||
if (format == AL_NONE)
|
||||
throw InvalidFormatException(channels, bitDepth);
|
||||
@@ -79,15 +68,20 @@ bool RecordingDevice::start(int samples, int sampleRate, int bitDepth, int chann
|
||||
if (sampleRate <= 0)
|
||||
throw love::Exception("Invalid sample rate.");
|
||||
|
||||
if (isRecording())
|
||||
stop();
|
||||
|
||||
device = alcCaptureOpenDevice(name.c_str(), sampleRate, format, samples);
|
||||
if (device == nullptr)
|
||||
return false;
|
||||
|
||||
alcCaptureStart(device);
|
||||
|
||||
this->samples = samples;
|
||||
this->sampleRate = sampleRate;
|
||||
this->bitDepth = bitDepth;
|
||||
this->channels = channels;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace openal
|
||||
class RecordingDevice : public love::audio::RecordingDevice
|
||||
{
|
||||
public:
|
||||
|
||||
RecordingDevice(const char *name);
|
||||
virtual ~RecordingDevice();
|
||||
virtual bool start();
|
||||
virtual bool start(int samples, int sampleRate, int bitDepth, int channels);
|
||||
virtual void stop();
|
||||
virtual love::sound::SoundData *getData();
|
||||
@@ -63,12 +63,15 @@ public:
|
||||
virtual bool isRecording() const;
|
||||
|
||||
private:
|
||||
int samples = 8192;
|
||||
int sampleRate = 8000;
|
||||
int bitDepth = 16;
|
||||
int channels = 1;
|
||||
|
||||
int samples = 0;
|
||||
int sampleRate = 0;
|
||||
int bitDepth = 0;
|
||||
int channels = 0;
|
||||
|
||||
std::string name;
|
||||
ALCdevice *device = nullptr;
|
||||
|
||||
}; //RecordingDevice
|
||||
|
||||
} //openal
|
||||
|
||||
@@ -35,18 +35,15 @@ RecordingDevice *luax_checkrecordingdevice(lua_State *L, int idx)
|
||||
int w_RecordingDevice_start(lua_State *L)
|
||||
{
|
||||
RecordingDevice *d = luax_checkrecordingdevice(L, 1);
|
||||
if (lua_gettop(L) > 1)
|
||||
{
|
||||
int samples = (int) luaL_checkinteger(L, 2);
|
||||
int sampleRate = (int) luaL_checkinteger(L, 3);
|
||||
int bitDepth = (int) luaL_checkinteger(L, 4);
|
||||
int channels = (int) luaL_checkinteger(L, 5);
|
||||
luax_catchexcept(L, [&](){
|
||||
lua_pushboolean(L, d->start(samples, sampleRate, bitDepth, channels));
|
||||
});
|
||||
}
|
||||
else
|
||||
luax_catchexcept(L, [&](){ lua_pushboolean(L, d->start()); });
|
||||
|
||||
int samples = (int) luaL_optinteger(L, 2, RecordingDevice::DEFAULT_SAMPLES);
|
||||
int sampleRate = (int) luaL_optinteger(L, 3, RecordingDevice::DEFAULT_SAMPLE_RATE);
|
||||
int bitDepth = (int) luaL_optinteger(L, 4, RecordingDevice::DEFAULT_BIT_DEPTH);
|
||||
int channels = (int) (int) luaL_optinteger(L, 5, RecordingDevice::DEFAULT_CHANNELS);
|
||||
|
||||
luax_catchexcept(L, [&](){
|
||||
lua_pushboolean(L, d->start(samples, sampleRate, bitDepth, channels));
|
||||
});
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user