From 9a090e8df84e8b83474d02bc1db8ec2d8b75e88d Mon Sep 17 00:00:00 2001 From: Raidho Date: Sun, 23 Oct 2016 18:53:02 +0300 Subject: [PATCH] made RecordingDevice create new SoundData every time captured samples are aquired --HG-- branch : minor-mic-input --- src/modules/audio/openal/RecordingDevice.cpp | 5 +-- src/modules/audio/wrap_RecordingDevice.cpp | 38 +++----------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/modules/audio/openal/RecordingDevice.cpp b/src/modules/audio/openal/RecordingDevice.cpp index afe06ef69..5eb77f648 100644 --- a/src/modules/audio/openal/RecordingDevice.cpp +++ b/src/modules/audio/openal/RecordingDevice.cpp @@ -102,8 +102,9 @@ int RecordingDevice::getData(love::sound::SoundData *soundData) if (samples == 0) return 0; - //resize internal buffer to proper size - if (samples != soundData->getSampleCount()) + //reinitialize soundData if necessary + if (samples != soundData->getSampleCount() || sampleRate != soundData->getSampleRate() || + bitDepth != soundData->getBitDepth() || channels != soundData->getChannels()) soundData->load(samples, sampleRate, bitDepth, channels); alcCaptureSamples(device, soundData->getData(), samples); diff --git a/src/modules/audio/wrap_RecordingDevice.cpp b/src/modules/audio/wrap_RecordingDevice.cpp index fbb5c3016..b78dc3bc1 100644 --- a/src/modules/audio/wrap_RecordingDevice.cpp +++ b/src/modules/audio/wrap_RecordingDevice.cpp @@ -67,23 +67,8 @@ int w_RecordingDevice_stopRecording(lua_State *L) } love::sound::SoundData *s = nullptr; - if (lua_gettop(L) > 1) - { - if (luax_istype(L, 2, SOUND_SOUND_DATA_ID)) - s = luax_totype(L, 2, SOUND_SOUND_DATA_ID); - else - return luaL_typerror(L, 2, "SoundData"); - - s->retain(); - } - else - { - luax_catchexcept(L, [&](){ - s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels()); - }); - } - luax_catchexcept(L, [&](){ + s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels()); d->getData(s); d->stopRecording(); }); @@ -104,23 +89,10 @@ int w_RecordingDevice_getData(lua_State *L) } love::sound::SoundData *s = nullptr; - if (lua_gettop(L) > 1) - { - if (luax_istype(L, 2, SOUND_SOUND_DATA_ID)) - s = luax_totype(L, 2, SOUND_SOUND_DATA_ID); - else - return luaL_typerror(L, 2, "SoundData"); - - s->retain(); - } - else - { - luax_catchexcept(L, [&](){ - s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels()); - }); - } - - luax_catchexcept(L, [&](){ d->getData(s); }); + luax_catchexcept(L, [&](){ + s = soundInstance()->newSoundData(samples, d->getSampleRate(), d->getBitDepth(), d->getChannels()); + d->getData(s); + }); luax_pushtype(L, SOUND_SOUND_DATA_ID, s); s->release();