{"id":553,"date":"2020-09-30T03:12:39","date_gmt":"2020-09-29T18:12:39","guid":{"rendered":"https:\/\/machiaworx.net\/?p=553"},"modified":"2020-09-30T03:12:39","modified_gmt":"2020-09-29T18:12:39","slug":"love-%e3%82%a8%e3%83%b3%e3%82%b8%e3%83%b3%e3%81%a7%e3%81%ae%e3%82%b7%e3%83%b3%e3%82%bb%e3%82%b5%e3%82%a4%e3%82%ba%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%80%82","status":"publish","type":"post","link":"https:\/\/machiaworx.net\/?p=553","title":{"rendered":"L\u00d6VE \u30a8\u30f3\u30b8\u30f3\u3067\u306e\u30b7\u30f3\u30bb\u30b5\u30a4\u30ba\u30b5\u30f3\u30d7\u30eb\u3002"},"content":{"rendered":"<p>\u53c2\u8003\u8cc7\u6599<br \/>\nhttps:\/\/pastebin.com\/uu0hBkfW<\/p>\n<p>\u3053\u308c\u304c\u306a\u304f\u306a\u308b\u306e\u3082\u8f9b\u3044\u306e\u3067\u3001\u81ea\u5206\u3067\u3082\u307e\u3068\u3081\u3066\u304a\u304f\u3002<br \/>\n\u3061\u306a\u307f\u306bLua\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n-- source\r\n-- https:\/\/pastebin.com\/uu0hBkfW\r\n\r\nlocal SD -- SoundData, used as a short buffer\r\nlocal QS -- Queueable Source\r\nlocal phaseAccum\r\nlocal samplerate\r\nlocal frequency\r\n\r\nlocal lfo_on=false\r\nlocal note_on=false\r\n \r\n -- \u6e96\u5099\r\nfunction love.load()\r\n    phaseAccum = 0.0\r\n    samplerate = 44100\r\n    frequency = 490.0\r\n    buf =512\r\n    SD = love.sound.newSoundData(buf, samplerate, 16, 1) -- 2048 samplepoints, at a sampling rate of 44.1kHz, that's 46.44 milliseconds\r\n    QS = love.audio.newQueueableSource(SD:getSampleRate(), SD:getBitDepth(), SD:getChannelCount()) -- one is enough to push data into it\r\n    QS:play() -- start it up\r\nend\r\n\r\nlocal smp=0\r\n\r\n-- \u6ce2\u5f62\u751f\u6210\r\nfunction generate(buffer)\r\n\r\n\t-- 0-\u30b5\u30f3\u30d7\u30eb\u30d0\u30c3\u30d5\u30a1\u306e\u6570\u5024\r\n    for i=0, buffer:getSampleCount()-1 do\r\n    \r\n    \t-- \u5468\u6ce2\u6570\u4fee\u6b63\r\n    \tif lfo_on == true then\r\n\t        frequency = frequency + math.sin(phaseAccum\/75) * 0.001\r\n        end\r\n        \r\n        -- if you want to modify the frequency in realtime\r\n        \r\n        -- \u4f4d\u76f8\u306e\u5b9a\u7fa9\uff08\u66f8\u304d\u8fbc\u3080\u30b9\u30c6\u30c3\u30d7\u30b5\u30a4\u30ba\uff09\r\n        local phaseDelta = frequency \/ samplerate -- step size\r\n        \r\n        -- \u6700\u7d42\u7684\u306a\u6ce2\u5f62\u306e\u4f4d\u7f6e\u3092\u5b9a\u7fa9\r\n        if note_on == true then\r\n\t        phaseAccum = phaseAccum + phaseDelta\r\n\r\n        \t-- \u30b5\u30a4\u30f3\u6ce2\u3092\u751f\u6210\u3059\u308b\r\n        \t-- make a sine wave\r\n        \tsmp = math.sin(2.0 * math.pi * phaseAccum)\r\n        \t\r\n\r\n        else\r\n        \t-- \u7121\u97f3\u3092\u66f8\u304d\u8fbc\u3080\r\n        \tsmp=0\r\n        end\r\n        -- \u30b5\u30f3\u30d7\u30eb\u3092\u914d\u7f6e\u3059\u308b\r\n        buffer:setSample(i, smp)\r\n    end\r\nend\r\n\r\nfunction love.keypressed( key )\r\n\tif love.keyboard.isDown(&quot;space&quot;) then\r\n\t   note_on=true\r\n\t   print(&quot;key on&quot;)\r\n\tend\r\nend\r\n\r\nfunction love.keyreleased( key )\r\n\tif key == &quot;space&quot; then\r\n\t\tnote_on= false\r\n\t   print(&quot;key off&quot;)\r\n\t   phaseAccum=0\r\n\tend\r\nend\r\n \r\nfunction love.update(dt)\r\n    while QS:getFreeBufferCount() &gt; 0 do -- timing\r\n        generate(SD) -- make one buffer's worth of samplepoints\r\n        QS:queue(SD) -- push buffer\r\n    end\r\n    QS:play() -- doesn't hurt to have, but kinda pointless\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u8cc7\u6599 https:\/\/pastebin.com\/uu0hBkfW \u3053\u308c\u304c\u306a\u304f\u306a\u308b\u306e\u3082\u8f9b\u3044\u306e\u3067\u3001\u81ea\u5206\u3067\u3082\u307e\u3068\u3081\u3066\u304a\u304f\u3002 \u3061\u306a\u307f\u306bLua\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11,4],"tags":[],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-zatta","category-synth-dev","category-pgm"],"_links":{"self":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553"}],"version-history":[{"count":3,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":766,"href":"https:\/\/machiaworx.net\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions\/766"}],"wp:attachment":[{"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machiaworx.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}