{"id":74,"date":"2018-01-06T05:20:55","date_gmt":"2018-01-05T20:20:55","guid":{"rendered":"http:\/\/mell0w-5phere.net\/jaded5phere\/2018\/01\/06\/2018-01-06-052055\/"},"modified":"2018-03-23T04:22:16","modified_gmt":"2018-03-22T19:22:16","slug":"java-sound","status":"publish","type":"post","link":"https:\/\/mell0w-5phere.net\/jaded5phere\/2018\/01\/06\/java-sound\/","title":{"rendered":"\u3010Processing\u3011\u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/mell0w-5phere.net\/jaded5phere\/2017\/12\/28\/speana-fft\/\">\u524d\u56de<\/a>\u306e\u4e88\u544a\u901a\u308a\u3001\u30b9\u30da\u30a2\u30ca\u3068\u9023\u52d5\u3057\u3066wave\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<h3>\u30fbddf.minim\u306e\u843d\u3068\u3057\u7a74<\/h3>\n<p>Processing\u3067\u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f\u3068\u8a00\u3063\u305f\u3089\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u983c\u308b\u306e\u304c\u624b\u3063\u53d6\u308a\u65e9\u3044\u3002ddf.minim\u306a\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3064\u3044\u3066\u8abf\u3079\u3066\u307f\u305f\u3068\u3053\u308d\u3001\u97f3\u58f0\u306e\u518d\u751f\u3069\u3053\u308d\u304bFFT\u307e\u3067\u3067\u304d\u308b\u3089\u3057\u3044(\u524d\u56de\u306e\u52b4\u529b\u306f\u7121\u99c4\u3060\u3063\u305f\u306e\u304b?)\u3002<br \/>\n\u304c\u3001\u5b9f\u969b\u306b\u97f3\u58f0\u3092\u518d\u751f\u3057\u3066\u307f\u3088\u3046\u3068\u3057\u305f\u3068\u3053\u308d\u3001\"couldn't load the file\u201d\u306a\u3069\u3068\u306e\u305f\u307e\u3063\u3066\u518d\u751f\u3067\u304d\u306a\u3044\u3002\u5225\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u8a66\u3057\u305f\u3068\u3053\u308d\u518d\u751f\u3067\u304d\u308b\u3082\u306e\u3082\u3042\u308b\u3002\u610f\u5473\u304c\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30bd\u30fc\u30b9\u3092\u8997\u3044\u3066\u307f\u305f\u3002<\/p>\n<p>\u7d50\u5c40\u3001\u3069\u3046\u3082minim\u3067\u306f8bit\u304b16bit\u3057\u304b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u3088\u3046\u3060\u3068\u3044\u3046\u3053\u3068\u304c\u5224\u660e\u3057\u305f\u3002\u307e\u3042CD\u898f\u683c\u306716bit\/44.1kHz\u304c\u4e00\u822c\u7684\u3060\u3057\u81f4\u3057\u65b9\u3042\u308b\u307e\u3044\u3002<\/p>\n<h3>\u30fb\u306a\u3089\u3070java\u306eAPI\u3092\u4f7f\u3063\u3066\u3084\u308d\u3046\u3068\u601d\u3063\u305f\u304c<\/h3>\n<p>minim\u304c\u4f7f\u3048\u306a\u3044\u306a\u3089java\u306e\u30b5\u30a6\u30f3\u30c9API ( javax.sound.sampled )\u3067\u3082\u4f7f\u3063\u3066\u3084\u308c\u3068\u601d\u3063\u305f\u304c\u3084\u3063\u3071\u308a\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002\u3069\u3046\u3082\u30d1\u30bd\u30b3\u30f3\u306e\u30df\u30ad\u30b5\u30fc\u81ea\u4f53\u304c16bit\u307e\u3067\u3057\u304b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u3063\u307d\u3044\u306e\u3067\u3042\u308b\u3002<br \/>\n<img loading=\"lazy\" src=\"http:\/\/mell0w-5phere.net\/jaded5phere\/wp-content\/uploads\/2017\/07\/formats.png\" alt=\"\" width=\"665\" height=\"397\" class=\"alignnone size-full wp-image-115\" srcset=\"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-content\/uploads\/2017\/07\/formats.png 665w, https:\/\/mell0w-5phere.net\/jaded5phere\/wp-content\/uploads\/2017\/07\/formats-300x179.png 300w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><br \/>\n\u3068\u3044\u3046\u3053\u3068\u3067\u3001API\u3067\u306f\u975e\u5bfe\u5fdc\u5f62\u5f0f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u76f4\u63a5\u8aad\u307f\u8fbc\u307e\u305b\u3066\u518d\u751f\u3067\u304d\u306a\u3044\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002<\/p>\n<h3>\u30fb\u8aad\u307f\u8fbc\u3081\u306a\u3044\u306a\u3089\u30c7\u30fc\u30bf\u306e\u65b9\u3092\u5909\u3048\u308c\u3070\u3044\u3044\u3058\u3083\u306a\u3044<\/h3>\n<p>\u3053\u3053\u3067\u3001\u6298\u89d2wav\u30c7\u30fc\u30bf\u3092\u65e2\u306b\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u306e\u3060\u304b\u3089\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u76f4\u63a5\u8aad\u307e\u305b\u3089\u308c\u306a\u3044\u306a\u3089\u5909\u63db\u3059\u308c\u3070\u3044\u3044\u3058\u3083\u306a\u3044\u304b\u3068\u3044\u3046\u767a\u60f3\u306b\u81f3\u308b\u3002<br \/>\n\u3068\u3044\u3046\u308f\u3051\u3067<a href=\"http:\/\/mell0w-5phere.net\/jaded5phere\/2017\/12\/26\/display-waveform\/\">\u524d\u3005\u56de<\/a>\u306e\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u306e\u30b3\u30fc\u30c9\u306b\u3044\u304f\u3089\u304b\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-java\">sampleNum=chunkSize\/(ch*sampleByte);\r\nwaveData=new float[ch][sampleNum];\r\ncopy=new byte[sampleNum*2*ch]; \/\/\u5909\u63db\u5f8c\u306e\u30d0\u30a4\u30c8\u914d\u5217\r\nint copyBytePos=0;\r\n\r\nif(fmtCode==1){\r\n\tint maxLv=(1&lt;&lt;sampleByte*8-1)-1;\r\n\t\r\n\tfor(int i=0;i&lt;sampleNum;i++){\r\n\t\tfor(int c=0;c&lt;ch;c++){\r\n\t\t\tfloat val=(float)ReadLittleEnd(sampleByte,true)\/maxLv;\r\n\t\t\twaveData[c][i]=val;\r\n\t\t\t\/\/\u4ee5\u4e0b\u8ffd\u52a0\r\n\t\t\tint copyVal=(int)(val*0x7fff); \/\/...(1)\r\n\t\t\tcopy[copyBytePos++]=(byte)(copyVal&amp;0xff);\r\n\t\t\tcopy[copyBytePos++]=(byte)(copyVal&gt;&gt;8&amp;0xff); \/\/...(2)\r\n\t\t}\r\n\t}\r\n}else if(fmtCode==3){\r\n\tfor(int i=0;i&lt;sampleNum;i++){\r\n\t\tfor(int c=0;c&lt;ch;c++){\r\n\t\t\tfloat val=ReadLittleEnd();\r\n\t\t\twaveData[c][i]=val;\r\n\t\t\t\/\/\r\n\t\t\tint copyVal=(int)(val*0x7fff);\r\n\t\t\tcopy[copyBytePos++]=(byte)(copyVal&amp;0xff);\r\n\t\t\tcopy[copyBytePos++]=(byte)(copyVal&gt;&gt;8&amp;0xff);\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<\/p>\n<p>\u4eca\u56de\u306f\u97f3\u58f0\u30c7\u30fc\u30bf\u309216bit signed int\u3001\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306b\u5909\u63db\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3046\u306e\u3067\u3001\u307e\u305a-1\u304b\u30891\u306e\u5024\u3092\u53d6\u3063\u3066\u3044\u308b\u6ce2\u5f62\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3001\u7b26\u53f7\u4ed816bit\u6574\u6570\u306e\u6700\u5927\u50240x7fff\u3092\u639b\u3051\u308b...(1)\u3002<br \/>\n\u6b21\u306b\u3053\u308c\u3092\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306e\u30d0\u30a4\u30c8\u914d\u5217\u306b\u3059\u308b\u306e\u3067\u3001\u307e\u305a\u305d\u306e\u307e\u307e0xff\u3067\u30de\u30b9\u30af\u3057\u3066\u683c\u7d0d\u3057\u3001\u6b21\u306b8\u30d3\u30c3\u30c8\u30b7\u30d5\u30c8\u3057\u3066\u307e\u305f\u30de\u30b9\u30af\u3057\u3066\u683c\u7d0d\u3059\u308b...(2)\u3002<\/p>\n<p>\u3053\u308c\u306716bit signed int\u3001\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306e\u97f3\u58f0\u30c7\u30fc\u30bf\u304c\u51fa\u6765\u4e0a\u304c\u3063\u305f\u306e\u3067\u3001\u5b9f\u969b\u306b\u8aad\u307f\u8fbc\u307e\u305b\u3066\u307f\u308b\u3002\u4eca\u56de\u306f\u518d\u751f\u524d\u306b\u5168\u90e8\u30ed\u30fc\u30c9\u3057\u3066\u3042\u308b\u306e\u3067Clip\u3092\u4f7f\u3046\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-java\">try{\r\n\tc=AudioSystem.getClip();\r\n\tAudioFormat auf=new AudioFormat(sampleRate,16,ch,true,false);\r\n\t\t\/\/...(3)\r\n\tc.open(auf,copy,0,copy.length); \/\/...(4)\r\n}catch(LineUnavailableException e){\r\n\te.printStackTrace();\r\n}\r\n<\/code><\/pre>\n<\/p>\n<p>AudioFormat\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u306f\u3044\u304f\u3064\u304b\u3042\u308b<a href=\"https:\/\/docs.oracle.com\/javase\/6\/docs\/api\/javax\/sound\/sampled\/AudioFormat.html\">*1<\/a>\u304c\u3001\u3053\u308c\u306fPCM\u306a\u306e\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u30ec\u30fc\u30c8\u3001\u30b5\u30f3\u30d7\u30eb\u30b5\u30a4\u30ba\u3001\u30c1\u30e3\u30f3\u30cd\u30eb\u6570\u3001\u7b26\u53f7\u306e\u6709\u7121\u3001\u30d3\u30c3\u30b0\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u304b\u3069\u3046\u304b\u3060\u3051\u6307\u5b9a\u3059\u308b...(3)\u3002\u305d\u3057\u3066\u305d\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3068\u97f3\u58f0\u30c7\u30fc\u30bf\u3092Clip.open\u306b\u3076\u3061\u3053\u3081\u3070Clip\u306e\u5b8c\u6210\u3067\u3042\u308b...(4)\u3002<\/p>\n<p>\u3042\u3068\u306fClip.start()\u3092\u547c\u3073\u51fa\u305b\u3070\u518d\u751f\u3057\u3066\u304f\u308c\u3066\u3001Clip.stop()\u3067\u505c\u6b62\u3067\u304d\u308b\u3002\u4eca\u56de\u306e\u30b9\u30da\u30a2\u30ca\u306f\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u8868\u793a\u304c\u4e00\u6642\u505c\u6b62\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u306e\u3067\u3061\u3083\u3093\u3068\u97f3\u58f0\u3082\u6b62\u3081\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f...(5)\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-processing\">void mousePressed(){\r\n\tif(!setUp){\r\n\t\tif(running){\r\n\t\t\trunning=false;\r\n\t\t\tif(c!=null)c.stop(); \/\/...(5)\r\n\t\t\tnoLoop();\r\n\t\t}else{\r\n\t\t\trunning=true;\r\n\t\t\tif(c!=null)c.start();\r\n\t\t\tprevMillis=millis();\r\n\t\t\tloop();\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<\/p>\n<hr>\n<p>\u3068\u3044\u3046\u308f\u3051\u3067\u30b9\u30da\u30a2\u30ca\u5236\u4f5c\u7de8\u306f\u591a\u5206\u7d42\u308f\u308a\u3067\u3042\u308b\u3002\u5b9f\u306fControlP5\u3092\u4f7f\u3063\u3066GUI\u3092\u3064\u3051\u3066\u307f\u305f\u308a\u3057\u305f\u304c\u3001\u7d39\u4ecb\u3059\u308b\u307b\u3069\u306e\u5185\u5bb9\u306f\u306a\u3044<s>\u3088\u3046<\/s>\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3053\u308c\u3067\u7d42\u308f\u308a\u306b\u3057\u3088\u3046\u3068\u601d\u3046\u3002<\/p>\n<p>\u6c17\u304c\u5411\u3044\u305f\u3089\u30b9\u30da\u30a2\u30ca\u306e\u7d39\u4ecb\u52d5\u753b\u3067\u3082\u51fa\u305d\u3046\u304b\u306a\u3068\u601d\u3046\u3002\u9762\u5012\u306a\u306e\u3067\u51fa\u3055\u306a\u3044\u6c17\u3082\u3059\u308b\u3002<\/p>\n<p>\u4ee5\u4e0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u4e88\u544a\u901a\u308a\u3001\u30b9\u30da\u30a2\u30ca\u3068\u9023\u52d5\u3057\u3066wave\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u751f\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3002 &nbsp; \u30fbddf.minim\u306e\u843d\u3068\u3057\u7a74 Processing\u3067\u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u306e\u518d\u751f\u3068\u8a00\u3063\u305f\u3089\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u983c\u308b\u306e\u304c\u624b\u3063\u53d6\u308a\u65e9\u3044\u3002ddf.mi<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[15,27,31],"_links":{"self":[{"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/posts\/74"}],"collection":[{"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":2,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/posts\/74\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mell0w-5phere.net\/jaded5phere\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}