{"id":377,"date":"2010-08-16T08:40:27","date_gmt":"2010-08-15T23:40:27","guid":{"rendered":"http:\/\/helloidea.org\/?p=377"},"modified":"2016-06-30T01:10:26","modified_gmt":"2016-06-29T16:10:26","slug":"windows%e3%81%a7%e9%8c%b2%e9%9f%b3-%e5%86%8d%e7%94%9f","status":"publish","type":"post","link":"https:\/\/helloidea.org\/index.php\/archives\/377.html","title":{"rendered":"Windows\u3067\u9332\u97f3 \u518d\u751f"},"content":{"rendered":"<p>\u30e1\u30e2\u30e1\u30e2\u3002 \u97f3\u58f0\u3092\u9332\u97f3\u3057\u3066\u518d\u751f\u3059\u308b\u3060\u3051\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059<\/p>\n<p>MMSystem.h \u3060\u3051\u3060\u3068 \u52d5\u304b\u306a\u3044\u3051\u3069\u3001Windows.h\u3067\u3001 \u3046\u3054\u304f\u3002\u3002\u3002\u4e0d\u601d\u8b70<br \/>\nWindows\u30de\u30eb\u30c1\u30e1\u30c7\u30a3\u30a2\u7cfb\u306eAPI\u306f\u3053\u3053\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3000<a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/cc428426.aspx\">msdn WIN32API<\/a><\/p>\n<p>\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8\u4e00\u89a7<br \/>\n<a href=\"http:\/\/www13.plala.or.jp\/kymats\/study\/MULTIMEDIA\/waveOut_create.html\">WAVE\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u3068\u518d\u751f<\/a><br \/>\n<a href=\"http:\/\/eternalwindows.jp\/winmm\/wave\/wave00.html\">WAVE<\/a><br \/>\n<a href=\"http:\/\/codezine.jp\/article\/detail\/368\">WAVE\u30d5\u30a1\u30a4\u30eb\u306b\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u52a0\u5de5\u3092\u65bd\u3057\u518d\u751f\u3059\u308b<\/a><\/p>\n<p>\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306b\u97f3\u58f0\u3092\u9332\u97f3\u3057\u7d9a\u3051\u305f\u3044\u306a\u3089\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3092\u5229\u7528\u3057\u3066\u3001\u8907\u6570\u306e\u30d0\u30d5\u30a1\u3092\u5207\u308a\u66ff\u3048\u306a\u304c\u3089\u3001waveInAddBuffer \u3067\u304a\uff4b\u3002<br \/>\n\u9332\u97f3\u3068\u518d\u751f\u306e\u30ec\u30a4\u30c6\u30f3\u30b7\u3092\u5c0f\u3055\u304f\u3057\u305f\u3044\u306a\u3089\u3001\u30d0\u30c3\u30d5\u30a1\u306e\u5927\u304d\u3055\u3092\u5c0f\u3055\u304f\u3059\u308c\u3070o\uff4b\uff1f<br \/>\n\u3069\u3061\u3089\u306b\u305b\u3088\u3001\u518d\u751f\u4e2d\u306e\u30dd\u30a4\u30f3\u30bf\u3068\u9332\u97f3\u4e2d\u306e\u30dd\u30a4\u30f3\u30bf\u306e\u8ddd\u96e2\u304c\u8fd1\u3044\u307b\u3069\u30ec\u30a4\u30c6\u30f3\u30b7\u306f\u6291\u3048\u3089\u308c\u305d\u3046\u3002<\/p>\n<p>\u30dd\u30a4\u30f3\u30bf\u304c\u91cd\u306a\u3063\u305f\u308a\u3057\u305f\u3089\u3001\u3048\u3089\u3044\u96d1\u97f3\u304c\u5165\u308a\u305d\u3046\u3060\u306a\uff20\uff20<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;Windows.h&gt;\r\n\/\/#include &lt;MMSystem.h&gt;\r\n\/\/#pragma comment (lib, &quot;winmm.lib&quot;)\r\n\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n\/\/ waveInOpen\u304c\u5229\u7528\u3059\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\r\nvoid CALLBACK waveInProc(\r\n\tHWAVEIN hwi,      \r\n\tUINT uMsg,        \r\n\tDWORD dwInstance, \r\n\tDWORD dwParam1,   \r\n\tDWORD dwParam2    \r\n\t)\r\n{\r\n\tswitch(uMsg)\r\n\t{\r\n\tcase WIM_OPEN:\r\n\t\tcout &lt;&lt; &quot;waveInOpen&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\tcase WIM_CLOSE:\r\n\t\tcout &lt;&lt; &quot;waveInClose&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\tcase WIM_DATA:\r\n\t\tcout &lt;&lt; &quot;\u30d0\u30c3\u30d5\u30a1\u304c\u3044\u3063\u3071\u3044\u306b\u306a\u308a\u307e\u3057\u305f&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\t}\r\n}\r\n\r\n\/\/ waveOutOpen\u304c\u5229\u7528\u3059\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\r\nvoid CALLBACK waveOutProc(\r\n\tHWAVEOUT hwo,\r\n\tUINT uMsg,        \r\n\tDWORD dwInstance, \r\n\tDWORD dwParam1,   \r\n\tDWORD dwParam2    \r\n\t)\r\n{\r\n\tswitch(uMsg)\r\n\t{\r\n\tcase WOM_OPEN:\r\n\t\tcout &lt;&lt; &quot;waveOutOpen&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\tcase WOM_CLOSE:\r\n\t\tcout &lt;&lt; &quot;waveOutClose&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\tcase WOM_DONE:\r\n\t\tcout &lt;&lt; &quot;\u30d0\u30c3\u30d5\u30a1\u3092\u3059\u3079\u3066\u518d\u751f\u3057\u307e\u3057\u305f&quot; &lt;&lt; endl;\r\n\t\tbreak;\r\n\t}\r\n}\r\n\r\nint main()\r\n{\r\n\t\/*******************************************************************************\r\n\t\t\u9332\u97f3\r\n\t********************************************************************************\/\r\n\tHWAVEIN      hwi = NULL;\t\t\t\t\/\/ WAVE\u30cf\u30f3\u30c9\u30eb\r\n\tLPBYTE       lpWaveData = NULL;\t\t\t\/\/ \u30d0\u30c3\u30d5\u30a1\u672c\u4f53\u306e\u30dd\u30a4\u30f3\u30bf&#x5B;\u30d2\u30fc\u30d7\u9818\u57df]\r\n\tWAVEFORMATEX wf = {0};\t\t\t\t\t\/\/ \u30c7\u30d0\u30a4\u30b9\u30aa\u30fc\u30d7\u30f3\u6642\u306b\u4f7f\u3046\u3001\u8a2d\u5b9a\u69cb\u9020\u4f53\r\n\tWAVEHDR      wh = {0};\t\t\t\t\t\/\/ \u30c7\u30d0\u30a4\u30b9\u306b\u4e0e\u3048\u308b\u30d0\u30c3\u30d5\u30a1\u306e\u8a2d\u5b9a\u69cb\u9020\u4f53\r\n\r\n\t\/\/ \u30c7\u30d0\u30a4\u30b9\u30aa\u30fc\u30d7\u30f3\u6642\u306e\u8a2d\u5b9a\r\n\twf.wFormatTag      = WAVE_FORMAT_PCM;\t\/\/ PCM\u5f62\u5f0f\r\n\twf.nChannels       = 1;\t\t\t\t\t\/\/ \u30b9\u30c6\u30ec\u30aa\u304b\u30e2\u30ce\u30e9\u30eb\u304b\r\n\twf.nSamplesPerSec  = 22050;\t\t\t\t\/\/ \u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u30ec\u30fc\u30c8 22.05KHz\r\n\twf.wBitsPerSample  = 8;\t\t\t\t\t\/\/ \u91cf\u5b50\u5316\u30ec\u30d9\u30eb\r\n\twf.nBlockAlign     = wf.wBitsPerSample * wf.nChannels \/ 8;\t\/\/ \u30d0\u30a4\u30c8\u3042\u305f\u308a\u306e\u30d3\u30c3\u30c8\u6570&#x5B;PCM\u306e\u4ed5\u69d8]\r\n\twf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;\t\/\/ 1 \u79d2\u3042\u305f\u308a\u306e\u30d0\u30a4\u30c8\u6570\r\n\t\/\/ \u30e2\u30ce\u30e9\u30eb+\u30b5\u30f3\u30d7\u30eb22050+\u91cf\u5b50\u53168bit\u306a\u306e\u3067 \u4e00\u79d2\u9593\u306b22050byte\u306e\u30c7\u30fc\u30bf\u304c\u767a\u751f\u3059\u308b\r\n\t\/\/ \u30b5\u30f3\u30d7\u30eb x nBlockAlign = \u4e00\u79d2\u9593\u306e\u30c7\u30fc\u30bf\u91cf\u306a\u306e\u3067 nBlockAlign\u306f\uff11\r\n\r\n\t\/\/ \u30c7\u30d0\u30a4\u30b9\u30aa\u30fc\u30d7\u30f3\r\n\tif(waveInOpen(\r\n\t\t&amp;hwi,\t\t\t\t\/\/ \u30cf\u30f3\u30c9\u30eb\r\n\t\tWAVE_MAPPER,\t\t\/\/ \u30c7\u30d0\u30a4\u30b9ID\u3002 WAVE_MAPPER\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30c7\u30d0\u30a4\u30b9\u3092\u6307\u5b9a\r\n\t\t&amp;wf,\t\t\t\t\/\/ \u30aa\u30fc\u30d7\u30f3\u6642\u306e\u8a2d\u5b9a\r\n\t\t(DWORD)waveInProc,\t\/\/ \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\r\n\t\t0,\t\t\t\t\t\/\/ \u3057\u3089\u3093\r\n\t\tCALLBACK_FUNCTION\t\/\/ \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306e\u5c5e\u6027\r\n\t\t) != MMSYSERR_NOERROR)\r\n\t\tcout &lt;&lt; &quot;\u30c7\u30d0\u30a4\u30b9\u306e\u30aa\u30fc\u30d7\u30f3\u306b\u5931\u6557\u3057\u307e\u3057\u305f&quot; &lt;&lt; endl;\r\n\r\n\tDWORD dwRecordSecond = 10;\t\t\/\/ 10\u79d2\r\n\tDWORD dwDataSize;\r\n\r\n\tdwDataSize = wf.nAvgBytesPerSec * dwRecordSecond;\t\/\/ \u4e00\u79d2\u9593\u306e\u30c7\u30fc\u30bf\u91cf x \u79d2\u6570\r\n\tlpWaveData = (LPBYTE)new BYTE&#x5B;dwDataSize];\r\n\r\n\t\/\/ \u30d0\u30c3\u30d5\u30a1\u60c5\u5831\u30bb\u30c3\u30c8\r\n\twh.lpData         = (LPSTR)lpWaveData;\r\n\twh.dwBufferLength = dwDataSize;\r\n\twh.dwFlags        = 0;\r\n\r\n\t\/\/ \u30d0\u30c3\u30d5\u30a1\u306e\u521d\u671f\u5316\r\n\twaveInPrepareHeader(hwi, &amp;wh, sizeof(WAVEHDR));\r\n\r\n\t\/\/ \u30d0\u30c3\u30d5\u30a1\u306e\u95a2\u9023\u4ed8\u3051\r\n\twaveInAddBuffer(hwi, &amp;wh, sizeof(WAVEHDR));\r\n\r\n\t\/\/ \u9332\u97f3\u958b\u59cb\r\n\twaveInStart(hwi);\r\n\r\n\trewind(stdin);\r\n\tgetchar(); \/\/ 10\u79d2\u5f85\u6a5f\u3059\u308b\u3068\u3001 &quot;\u30d0\u30c3\u30d5\u30a1\u304c\u3044\u3063\u3071\u3044\u306b\u306a\u3063\u305f&quot; \u304c\u8868\u793a\u3055\u308c\u308b\u306f\u305a\r\n\r\n\t\/\/ \u9332\u97f3\u7d42\u4e86\r\n\twaveInReset(hwi);\r\n\twaveInUnprepareHeader(hwi, &amp;wh, sizeof(WAVEHDR));\r\n\twaveInClose(hwi);\r\n\r\n\r\n\t\/*******************************************************************************\r\n\t\t\u518d\u751f\r\n\t********************************************************************************\/\r\n\t\r\n\tHWAVEOUT hwo;\t\/\/ \u30cf\u30f3\u30c9\u30eb\r\n\tWAVEHDR whdr;\t\t\/\/ \r\n\r\n\t\/\/ \u30c7\u30d0\u30a4\u30b9\u3092\u958b\u304f\r\n\tif(waveOutOpen(\r\n\t\t&amp;hwo,\t\t\t\/\/ \u30cf\u30f3\u30c9\u30eb\r\n\t\tWAVE_MAPPER,\t\t\/\/ \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30c7\u30d0\u30a4\u30b9\u3092\u6307\u5b9a\r\n\t\t&amp;wf,\t\t\t\t\/\/ waveInOpen\u306e\u3068\u304a\u306a\u3058\u3067\u304a\uff4b\r\n\t\t(DWORD)waveOutProc,\t\/\/ \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\r\n\t\t0,\t\t\t\t\t\/\/ \u3057\u3089\u3093\r\n\t\tCALLBACK_FUNCTION\t\/\/ \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306e\u5c5e\u6027\r\n\t\t)\r\n\t\t!= MMSYSERR_NOERROR )\r\n\t\tcout &lt;&lt; &quot;Erroe&quot; &lt;&lt; endl;\r\n\r\n\r\n\t\/\/ \u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8a2d\u5b9a\r\n\twhdr.lpData =\t\t\t(LPSTR)lpWaveData;\t\t\t\/\/ \u97f3\u58f0\u30c7\u30fc\u30bf\u306e\u5165\u3063\u3066\u308b\u30dd\u30a4\u30f3\u30bf\r\n\twhdr.dwBufferLength =\tdwDataSize;\t\t\t\t\t\t\/\/ \u97f3\u58f0\u30c7\u30fc\u30bf\u306e\u30b5\u30a4\u30ba\r\n\twhdr.dwFlags =\t\t\tWHDR_BEGINLOOP | WHDR_ENDLOOP;\t\/\/ \u518d\u751f\u30aa\u30d7\u30b7\u30e7\u30f3\r\n\twhdr.dwLoops =\t\t\t1;\t\t\t\t\t\t\t\t\/\/ \u30eb\u30fc\u30d7\u56de\u6570\r\n\r\n\t\/\/ \u521d\u671f\u5316\r\n\twaveOutPrepareHeader(hwo,&amp;whdr,sizeof(WAVEHDR));\r\n\r\n\t\/\/ \u97f3\u58f0\u30c7\u30fc\u30bf\u30d6\u30ed\u30c3\u30af\u306e\u66f8\u304d\u8fbc\u307f\r\n\twaveOutWrite(hwo,&amp;whdr,whdr.dwBufferLength);\r\n\r\n\trewind(stdin);\r\n\tgetchar();\t\/\/ \u518d\u751f\u4e2d\u5f85\u6a5f\r\n\r\n\twaveOutReset(hwo);\r\n\twaveOutUnprepareHeader(hwo, &amp;whdr, sizeof(whdr));\r\n\twaveOutClose(hwo);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30e1\u30e2\u30e1\u30e2\u3002 \u97f3\u58f0\u3092\u9332\u97f3\u3057\u3066\u518d\u751f\u3059\u308b\u3060\u3051\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059 MMSystem.h \u3060\u3051\u3060\u3068 \u52d5\u304b\u306a\u3044\u3051\u3069\u3001Windows.h\u3067\u3001 \u3046\u3054\u304f\u3002\u3002\u3002\u4e0d\u601d\u8b70 Windows\u30de\u30eb\u30c1\u30e1\u30c7\u30a3\u30a2\u7cfb\u306eAPI\u306f\u3053\u3053\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3000msdn  \u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[86,82,81,85,84,83],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-memo","tag-waveinaddbuffer","tag-waveinopen","tag-waveoutopen","tag-win32api","tag-reproduction","tag-recording"],"_links":{"self":[{"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":12,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":1642,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/posts\/377\/revisions\/1642"}],"wp:attachment":[{"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/helloidea.org\/index.php\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}