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