{"id":564,"date":"2009-10-22T16:26:52","date_gmt":"2009-10-22T08:26:52","guid":{"rendered":"http:\/\/test999.eblhost.com\/blog\/?p=564"},"modified":"2010-02-26T20:48:16","modified_gmt":"2010-02-26T12:48:16","slug":"minim%ef%bc%9aminim","status":"publish","type":"post","link":"https:\/\/learn.travelchinawith.me\/?p=564","title":{"rendered":"Minim\uff1aMinim"},"content":{"rendered":"<p>[ <a href=\"http:\/\/code.compartmental.net\/minim\/javadoc\/ddf\/minim\/Minim.html\" target=\"_blank\">javadoc<\/a> | <a href=\"http:\/\/code.compartmental.net\/minim\/examples\/Minim\/\" target=\"_blank\">\u8303\u4f8b<\/a> ]<\/p>\n<p>Minim\u662f\u4f60\u6b63\u5728\u9605\u8bfb\u7684\u97f3\u9891\u5e93\u7684\u540d\u5b57\u3002Minim\u662f\u5728\u80fd\u63d0\u4f9b\u4e00\u5806\u65b9\u6cd5\uff08method\uff09\u7ed9\u4f60\u83b7\u53d6\u7cfb\u7edf\u97f3\u9891\u8d44\u6e90\u7684\u5e93\u91cc\u7684\u4e00\u4e2a\u7c7b\u3002\u8981\u4f7f\u7528\u5b83\uff0c\u4f60\u5fc5\u987b\u5728setup()\u4e4b\u524d\u7533\u660e\u4e00\u4e2aMinm\u7684\u53d8\u91cf\uff0c\u800c\u540e\u4f8b\u793a\u4e00\u4e2aMinim\u5bf9\u8c61\u3002\u4e3a\u4e86\u4f7fMinm\u80fd\u591f\u8fa8\u8bc6\u4e00\u4e9b\u4e1c\u897f\u5e76\u80fd\u591f\u8fdb\u5165\u4f60sketch\u7684data\u6587\u4ef6\u5939\uff0c\u4f60\u5fc5\u987b\u8fd9\u4e48\u505a\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong><\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\n\r\nMinim minim;\r\n\r\nvoid setup()\r\n{\r\n  size(100, 100);\r\n\r\n  minim = new Minim(this);\r\n}\r\n\r\nvoid draw()\r\n{\r\n}<\/pre>\n<p><strong>\u83b7\u53d6Minim\u7684\u97f3\u9891\u8d44\u6e90<\/strong><\/p>\n<p>\u4f60\u53ef\u4ee5\u7528Minim\u505a\u56db\u4ef6\u4e8b\uff1a\u64ad\u653e\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6\uff0c\u64ad\u653e\u5408\u6210\u97f3\u9891\uff0c\u76d1\u542c\u97f3\u9891\u8f93\u5165\uff0c\u5411\u786c\u76d8\u5185\u5f55\u5236\u97f3\u9891\u3002\u6240\u6709\u8fd9\u4e9b\u90fd\u662f\u7531\u5e93\u5185\u4e0d\u540c\u7684\u7c7b\u64cd\u4f5c\u7684\uff0c\u8fd9\u4e9b\u7c7b\u7684\u8303\u4f8b\u901a\u8fc7\u547c\u53ebMinim\u9002\u5f53\u7684\u65b9\u6cd5\u800c\u83b7\u5f97\u3002<\/p>\n<p><strong>\u8f7d\u5165\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6<\/strong><\/p>\n<p>\u6709\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u53ef\u7528\u6765\u64ad\u653e\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6\uff0c\u6bcf\u79cd\u90fd\u7528\u6765\u914d\u5408\u7279\u5b9a\u7684\u56de\u653e\u7c7b\u578b\u3002\u63a5\u4e0b\u6765\u7684\u8bfe\u7a0b\u4f1a\u8be6\u5c3d\u7684\u8bb2\u89e3\u6bcf\u4e2a\u7c7b\uff0c\u73b0\u5728\u4f60\u53ea\u9700\u8981\u77e5\u9053\u4ed6\u4eec\u662f\uff1aAudioSnippet, AudioSample, \u548c AudioPlayer\u3002\u4f60\u901a\u8fc7\u547c\u53eb\u5982\u4e0bMinim\u65b9\u6cd5\u521b\u5efa\u5b83\u4eec\uff1a<\/p>\n<pre class=\"brush:processing\">loadSnippet(String filename)\r\nloadSample(String filename)\r\nloadSample(String filename, int bufferSize)\r\nloadFile(String filename)\r\nloadFile(String filename, int bufferSize)<\/pre>\n<p>loadSnippet \u8fd4\u56de AudioSnippet\uff0cloadSample \u8fd4\u56de AudioSample, loadFile \u8fd4\u56de AudioPlayer\u3002\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\uff0cfilename\uff08\u6587\u4ef6\u540d\uff09\u53ef\u4ee5\u662f\u4f60sketch\u91ccdata\u6587\u4ef6\u5939\u4e0b\u7684\u97f3\u9891\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u4e5f\u53ef\u4ee5\u662f\u7f51\u8def\u4e0a\u7684\u97f3\u9891\u6587\u4ef6\u94fe\u63a5\u3002bufferSize\u662f\u4f60\u5e0c\u671b\u7684\u7f13\u51b2\u5668\u5927\u5c0f\uff0c\u8fd9\u4e2a\u6570\u5b57\u8d8a\u5c0f\uff0c\u97f3\u9891\u7684\u5ef6\u8fdf\u8d8a\u5c11\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong><\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\n\r\nMinim minim;\r\nAudioPlayer in;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 200);\r\n  \/\/ \u4f8b\u793a\u4e00\u4e2aMinim\u5bf9\u8c61\r\n  minim = new Minim(this);\r\n  \/\/ \u8f7d\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u9ed8\u8ba4\u91c7\u6837\u7387\u4e3a1024\r\n  in = minim.loadFile(\"music.mp3\");\r\n  \/\/ \u64ad\u653e\u8fd9\u4e2a\u6587\u4ef6\r\n  in.play();\r\n}\r\n\r\nvoid draw()\r\n{\r\n  \/\/ \u505a\u7231\u505a\u7684\u4e8b\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ \u522b\u5fd8\u8bb0\u5173\u95ed\u97f3\u9891\u8f93\u5165\u8f93\u51fa\u7c7b\r\n  in.close();\r\n  \/\/ \u522b\u5fd8\u8bb0\u505c\u6b62\u4f60\u7684Minim\u5bf9\u8c61\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n<p><strong>\u83b7\u5f97\u4e00\u4e2aAudioOutput\uff08\u97f3\u9891\u8f93\u51fa\uff09<\/strong><\/p>\n<p>Minim\u4e3a\u56de\u653e\u5408\u6210\u97f3\u9891\u63d0\u4f9bAudioOutput\u7c7b\u3002\u8fd9\u662f\u5b9e\u65f6\u7ecf\u7531\u4f60\u7a0b\u5e8f\u521b\u5efa\u5e76\u53cd\u9988\u5230\u626c\u58f0\u5668\u7684\u97f3\u9891\u3002AudioOutput\u652f\u6301\u5355\u58f0\u9053\u53ca\u7acb\u4f53\u58f0\uff0c\u5e76\u4e14\u53ef\u6307\u5b9a\u4f60\u9700\u8981\u7684\u5408\u6210\u7c7b\u578b\u3002\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:processing\">getLineOut()\r\ngetLineOut(int type)\r\ngetLineOut(int type, int bufferSize)\r\ngetLineOut(int type, int bufferSize, float sampleRate)\r\ngetLineOut(int type, int bufferSize, float sampleRate, int bitDepth)<\/pre>\n<p>type\u6307\u51fa\u4f60\u60f3\u8981\u5355\u58f0\u9053\u8fd8\u662f\u7acb\u4f53\u58f0\u3002\u4f60\u5e94\u5f53\u4f7f\u7528Minim.MONO\u6216Minim.STEREO\u4f5c\u4e3a\u8fd9\u4e2a\u5f15\u6570\u7684\u503c\uff0c\u8fd9\u4e2a\u5f15\u6570\u7684\u9ed8\u8ba4\u503c\u4e3aMinim.STEREO\u3002bufferSize\u5982\u4e0a\uff0c\u5373\u4f60\u7f13\u51b2\u5668\u7684\u5927\u5c0f\u3002sampleRate\u662f\u4f60\u5408\u6210\u97f3\u9891\u7684\u91c7\u6837\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a44100\uff08CD\u97f3\u9891\u8d28\u91cf\uff09\u3002bitDepth\u662f\u4f60\u5408\u6210\u97f3\u9891\u7684\u6bd4\u7279\u7387\uff0c\u76ee\u524d\u4ec5\u652f\u63018\u548c16\u4e24\u4e2a\u503c\uff0c\u9ed8\u8ba4\u503c\u4e3a16\uff08CD\u97f3\u9891\u8d28\u91cf\uff09\u3002\u6ce8\u610f\u6709\u65f6\u4f60\u586b\u5165\u7684\u503c\u5c06\u8d85\u51fa\u4f60\u7684\u8bbe\u5907\u5141\u8bb8\u8303\u56f4\uff0c\u8fd9\u65f6\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5c06\u4f1a\u8fd4\u56denull\uff0c\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u5e76\u4e0d\u610f\u5473\u7740\u4f60\u5b8c\u5168\u65e0\u6cd5\u83b7\u5f97\u4e00\u4e2a\u8f93\u51fa\uff0c\u800c\u53ea\u662f\u8868\u660e\u4f60\u60f3\u8981\u7684\u662f\u4e00\u4e2a\u65e0\u6cd5\u5b9e\u73b0\u7684\u914d\u7f6e\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong><\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\nimport ddf.minim.signals.*;\r\n\r\nMinim minim;\r\nAudioOutput out;\r\nSineWave sine;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 200);\r\n  \/\/ \u4f8b\u793a\u4e00\u4e2aMinim\u5bf9\u8c61\r\n  minim = new Minim(this);\r\n  \/\/ \u901a\u8fc7Minim\u83b7\u5f97\u4e00\u4e2a\u7ebf\u6027\u8f93\u51fa, \r\n  \/\/ \u9ed8\u8ba4\u91c7\u6837\u7387\u4e3a44100\uff0c\u91c7\u6837\u6df1\u5ea616\r\n  out = minim.getLineOut(Minim.STEREO, 512);\r\n  \/\/ \u521b\u5efa\u4e00\u4e2a\u632f\u8361\u5668, \u9891\u7387440 Hz, \u632f\u5e450.5, \r\n  \/\/ \u91c7\u6837\u738744100\u4ee5\u7b26\u5408\u7ebf\u6027\u8f93\u51fa\r\n  sine = new SineWave(440, 0.5, 44100);\r\n  \/\/ \u5c06\u632f\u8361\u5668\u52a0\u5230\u8f93\u51fa\u4e0a\r\n  out.addSignal(sine);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  \/\/ \u505a\u7231\u505a\u7684\u4e8b\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ always closes audio I\/O classes\r\n  out.close();\r\n  \/\/ always stop your Minim object\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n<p><strong>\u83b7\u5f97\u4e00\u4e2aAudioInput\uff08\u97f3\u9891\u8f93\u5165\uff09<\/strong><\/p>\n<p>Minim\u4e3a\u76d1\u542c\u7528\u6237\u5f53\u524d\u5f55\u97f3\u6e90\u63d0\u4f9b\u4e86AudioInput\u7c7b\u3002\u76ee\u524d\u6211\u4eec\u65e0\u6cd5\u6307\u5b9a\u8fd9\u4e2a\u8f93\u5165\u7684\u6765\u6e90\uff0c\u6bd4\u5982\u9ea6\u514b\u6216\u7ebf\u6027\u8f93\u5165\u3002<\/p>\n<pre class=\"brush:processing\">getLineIn()\r\ngetLineIn(int type)\r\ngetLineIn(int type, int bufferSize)\r\ngetLineIn(int type, int bufferSize, float sampleRate)\r\ngetLineIn(int type, int bufferSize, float sampleRate, int bitDepth)<\/pre>\n<p>type\u6307\u51fa\u4f60\u60f3\u8981\u5355\u58f0\u9053\u8fd8\u662f\u7acb\u4f53\u58f0\u3002\u4f60\u5e94\u5f53\u4f7f\u7528Minim.MONO\u6216Minim.STEREO\u4f5c\u4e3a\u8fd9\u4e2a\u5f15\u6570\u7684\u503c\uff0c\u8fd9\u4e2a\u5f15\u6570\u7684\u9ed8\u8ba4\u503c\u4e3a Minim.STEREO\u3002bufferSize\u5982\u4e0a\uff0c\u5373\u4f60\u7f13\u51b2\u5668\u7684\u5927\u5c0f\u3002sampleRate\u662f\u4f60\u5408\u6210\u97f3\u9891\u7684\u91c7\u6837\u7387\uff0c\u9ed8\u8ba4\u503c\u4e3a44100\uff08CD\u97f3\u9891\u8d28 \u91cf\uff09\u3002bitDepth\u662f\u4f60\u5408\u6210\u97f3\u9891\u7684\u6bd4\u7279\u7387\uff0c\u76ee\u524d\u4ec5\u652f\u63018\u548c16\u4e24\u4e2a\u503c\uff0c\u9ed8\u8ba4\u503c\u4e3a16\uff08CD\u97f3\u9891\u8d28\u91cf\uff09\u3002\u6ce8\u610f\u6709\u65f6\u4f60\u586b\u5165\u7684\u503c\u5c06\u8d85\u51fa\u4f60\u7684\u8bbe\u5907\u5141\u8bb8\u8303\u56f4\uff0c\u8fd9 \u65f6\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u5c06\u4f1a\u8fd4\u56denull\uff0c\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u5e76\u4e0d\u610f\u5473\u7740\u4f60\u5b8c\u5168\u65e0\u6cd5\u83b7\u5f97\u4e00\u4e2a\u8f93\u51fa\uff0c\u800c\u53ea\u662f\u8868\u660e\u4f60\u60f3\u8981\u7684\u662f\u4e00\u4e2a\u65e0\u6cd5\u5b9e\u73b0\u7684\u914d\u7f6e\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong><\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\n\r\nMinim minim;\r\nAudioInput in;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 200);\r\n  \/\/ instatiate a Minim object\r\n  minim = new Minim(this);\r\n  \/\/ get a line out from Minim, \r\n  \/\/ default sample rate is 44100, bit depth is 16\r\n  in = minim.getLineIn(Minim.STEREO, 512);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  \/\/ do whatever you are going to do\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ \u522b\u5fd8\u8bb0\u5173\u95ed\u97f3\u9891I\/O\u7c7b\r\n  in.close();\r\n  \/\/ \u522b\u5fd8\u8bb0\u505c\u6b62\u4f60\u7684Minim\u5bf9\u8c61\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n<p><strong>\u521b\u5efa\u4e00\u4e2aAudioRecorder\uff08\u97f3\u9891\u5f55\u5236\u673a\uff09<\/strong><\/p>\n<p>Minim\u4e3a\u5f55\u5236\u97f3\u9891\u6570\u636e\u5230\u786c\u76d8\u63d0\u4f9bAudioRecorder\u7c7b\u3002\u7ec6\u8282\u7684\u8ba8\u8bba\u5c06\u540e\u7eed\u8bf4\u660e\uff0c\u4ee5\u4e0b\u662f\u83b7\u53d6\u4e00\u4e2aAudioRecorder\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush:processing\">createRecorder(Recordable source, String filename, boolean buffered)<\/pre>\n<p>source\u662f\u4e00\u4e2a\u4f60\u5e0c\u671b\u4f5c\u4e3a\u5f55\u97f3\u6e90\u7684\u53ef\u8bb0\u5f55\u5bf9\u8c61\u3002filename\u662f\u8981\u4fdd\u5b58\u7684\u97f3\u9891\u6587\u4ef6\u7684\u540d\u5b57\uff0c\u5305\u62ec\u6269\u5c55\u540d\u3002buffered\u8868\u660e\u4f60\u5e0c\u671b\u6216\u4e0d\u5e0c\u671b\u5728\u5f55\u97f3\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7f13\u51b2\u5668\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong><\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\n\r\nMinim minim;\r\nAudioInput in;\r\nAudioRecorder fout;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 400);\r\n\r\n  minim = new Minim(this);\r\n\r\n  \/\/ \u83b7\u5f97\u4e00\u4e2a\u7acb\u4f53\u58f0\u7ebf\u6027\u8f93\u5165: \u7f13\u51b2\u5668512\r\n  in = minim.getLineIn(Minim.STEREO, 512);\r\n  \/\/ \u83b7\u53d6\u4e00\u4e2a\u5f55\u97f3\u673a \r\n  \/\/ \u5e76\u4f7f\u7528\u7f13\u51b2\u5f55\u97f3\u7684\u65b9\u5f0f\u5c06\u58f0\u97f3\u5f55\u5165\u6307\u5b9a\u6587\u4ef6\u540d\u53ca\u7c7b\u578b\u7684\u6587\u4ef6\r\n  fout = minim.createRecorder(in, \"myrecording.wav\", true);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  \/\/ \u505a\u7231\u505a\u7684\u4e8b\r\n}\r\n\r\nvoid keyReleased()\r\n{\r\n  \/\/ \u53ef\u4ee5\u8bbe\u7f6e\u63a7\u5236\u5f55\u97f3\u8d77\u59cb\u7684\u952e\u76d8\u6309\u952e\r\n  \/\/ \u7136\u540e\u5b58\u81f3\u786c\u76d8\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ always close audio I\/O classes\r\n  in.close();\r\n  \/\/ always stop your Minim object\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n<p><strong>\u8bbe\u7f6e\u7cfb\u7edf\u6df7\u97f3\u5668\uff08Mixer\uff09<\/strong><\/p>\n<p>Javasound\uff08Java\u58f0\u97f3\uff09\u901a\u8fc7\u4f7f\u7528\u4e00\u4e2a\u53eb\u505aMixer\uff08\u6df7\u97f3\u5668\uff09\u7684\u5bf9\u8c61\u63d0\u4f9b\u8fdb\u5165\u7535\u8111\u7cfb\u7edf\u7279\u5b9a\u8f93\u5165\u3001\u8f93\u51fa\u53e3\u7684\u80fd\u529b\u3002\u4f60\u53ef\u4ee5\u5728\u521b\u5efa\u8d44\u6e90\u4e4b\u524d\u8bbe\u7f6e\u8f93\u5165\u8f93\u51fa\u6df7\u97f3\u5668\u6765\u6307\u5b9a\u7279\u5b9a\u7684\u8f93\u5165\u6216\u8f93\u51fa\u3002AudioPlayer, AudioSnippet, AudioSample, \u548c AudioOuput\u90fd\u4f7f\u7528\u8f93\u51fa\u6df7\u97f3\u5668\u6765\u83b7\u5f97\u97f3\u9891\u8f93\u51fa\u3002AudioInput\u5219\u4f7f\u7528\u8f93\u5165\u6df7\u97f3\u5668\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u5757\u591a\u901a\u9053\u58f0\u5361\uff0c\u4f60\u53ef\u4ee5\u4e3a\u4f60\u7684\u97f3\u9891\u8f93\u51fa\u6307\u5b9a\u5b83\u7279\u5b9a\u7684\u8f93\u51fa\u53e3\u3002<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong>\uff08<a href=\"http:\/\/code.compartmental.net\/minim\/examples\/Minim\/setOutputMixer\/\" target=\"_blank\">\u5728\u7ebf\u793a\u4f8b<\/a>\uff09<\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\n\/\/ \u9700\u8981SineWave\u4fe1\u53f7\u5305\r\nimport ddf.minim.signals.*;\r\nimport controlP5.*;\r\n\/\/ \u4e3a\u4f7f\u7528Mixer \u548c Mixer.Info\u5bf9\u8c61\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u8fd9\u4e2a\r\nimport javax.sound.sampled.*;\r\n\r\nMinim minim;\r\nAudioOutput out;\r\n\/\/ \u4e00\u4e2a\u5c55\u793a\u6574\u4e2a\u97f3\u9891\u7cfb\u7edf\u6df7\u97f3\u5668\u7684info\u5bf9\u8c61\u7684\u6570\u7ec4\u3002\r\n\/\/ \u6211\u4eec\u7528\u5b83\u7ec4\u88c5\u6211\u4eec\u7684\u6df7\u97f3\u5668\u4e0b\u62c9\u83dc\u5355\uff0c\u5e76\u8ba9\u7528\u6237\u9009\u62e9\u60f3\u8981\u7684\u6df7\u97f3\u5668\u3002\r\nMixer.Info[] mixerInfo;\r\n\r\n\/\/ \u7ed9\u6211\u4eec\u8f93\u51fa\u7684\u4e00\u4e2a\u4fe1\u53f7\r\nSineWave sine;\r\n\r\nControlP5 gui;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 275);\r\n\r\n  minim = new Minim(this);\r\n  gui = new ControlP5(this);\r\n\r\n  ScrollList mixers = gui.addScrollList(\"Mixers\", 10, 10, 475, 280);\r\n  mixers.setLabel(\"Choose A Mixer\");\r\n\r\n  mixerInfo = AudioSystem.getMixerInfo();\r\n\r\n  for(int i = 0; i &lt; mixerInfo.length; i++)\r\n  {\r\n    controlP5.Button b = mixers.addItem(\"item\"+i, i);\r\n    b.setLabel(mixerInfo[i].getName());\r\n  }\r\n\r\n  sine = new SineWave(220, 0.3, 44100);\r\n\r\n}\r\n\r\nvoid draw()\r\n{\r\n  background(0);\r\n\r\n  \/\/gui.draw();\r\n\r\n  if ( out != null )\r\n  {\r\n    stroke(255);\r\n    \/\/ \u7ed8\u5236\u6ce2\u5f62\r\n    for(int i = 0; i &lt; out.bufferSize() - 1; i++)\r\n    {\r\n      line(i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50);\r\n      line(i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50);\r\n    }\r\n  }\r\n}\r\n\r\npublic void controlEvent(ControlEvent theEvent)\r\n{\r\n  int mixerIndex = (int)theEvent.controller().value();\r\n\r\n  println(\"User chose \" + theEvent.controller().label());\r\n  println(\"Using mixer info \" + mixerInfo[mixerIndex].getName());\r\n\r\n  Mixer mixer = AudioSystem.getMixer(mixerInfo[mixerIndex]);\r\n\r\n  minim.setOutputMixer(mixer);\r\n\r\n  if ( out != null )\r\n  {\r\n    out.close();\r\n  }\r\n\r\n  out = minim.getLineOut(Minim.STEREO);\r\n\r\n  if ( out != null )\r\n  {\r\n    out.addSignal(sine);\r\n  }\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ \u5b8c\u4e8b\u540e\u8bb0\u5f97\u5173\u95edMinim\u97f3\u9891\u7c7b\r\n  if ( out != null )\r\n  {\r\n    out.close();\r\n  }\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n<p>\u540c\u6837\u7684\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u4f60\u58f0\u5361\u7279\u5b9a\u7684\u8f93\u5165\uff1a<\/p>\n<p><strong>\u793a\u8303\u4ee3\u7801<\/strong>\uff08<a href=\"http:\/\/code.compartmental.net\/minim\/examples\/Minim\/setInputMixer\/\" target=\"_blank\">\u5728\u7ebf\u793a\u4f8b<\/a>\uff09<\/p>\n<pre class=\"brush:processing\">import ddf.minim.*;\r\nimport controlP5.*;\r\n\/\/ need to import this so we can use Mixer and Mixer.Info objects\r\nimport javax.sound.sampled.*;\r\n\r\nMinim minim;\r\nAudioInput in;\r\n\/\/ an array of info objects describing all of \r\n\/\/ the mixers the AudioSystem has. we'll use\r\n\/\/ this to populate our gui scroll list and\r\n\/\/ also to obtain an actual Mixer when the\r\n\/\/ user clicks on an item in the list.\r\nMixer.Info[] mixerInfo;\r\n\r\nControlP5 gui;\r\n\r\nvoid setup()\r\n{\r\n  size(512, 275);\r\n\r\n  minim = new Minim(this);\r\n  gui = new ControlP5(this);\r\n\r\n  ScrollList mixers = gui.addScrollList(\"Mixers\", 10, 10, 475, 280);\r\n  mixers.setLabel(\"Choose A Mixer\");\r\n\r\n  mixerInfo = AudioSystem.getMixerInfo();\r\n\r\n  for(int i = 0; i &lt; mixerInfo.length; i++)\r\n  {\r\n    controlP5.Button b = mixers.addItem(\"item\"+i, i);\r\n    b.setLabel(mixerInfo[i].getName());\r\n  }\r\n\r\n}\r\n\r\nvoid draw()\r\n{\r\n  background(0);\r\n\r\n  \/\/gui.draw();\r\n\r\n  if ( in != null )\r\n  {\r\n    stroke(255);\r\n    \/\/ draw the waveforms\r\n    for(int i = 0; i &lt; in.bufferSize() - 1; i++)\r\n    {\r\n      line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);\r\n      line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);\r\n    }\r\n  }\r\n}\r\n\r\npublic void controlEvent(ControlEvent theEvent)\r\n{\r\n  int mixerIndex = (int)theEvent.controller().value();\r\n\r\n  println(\"User chose \" + theEvent.controller().label());\r\n  println(\"Using mixer info \" + mixerInfo[mixerIndex].getName());\r\n\r\n  Mixer mixer = AudioSystem.getMixer(mixerInfo[mixerIndex]);\r\n\r\n  if ( in != null )\r\n  {\r\n    in.close();\r\n  }\r\n\r\n  minim.setInputMixer(mixer);\r\n\r\n  in = minim.getLineIn(Minim.STEREO);\r\n\r\n}\r\n\r\nvoid stop()\r\n{\r\n  \/\/ always close Minim audio classes when you are done with them\r\n  if ( in != null )\r\n  {\r\n    in.close();\r\n  }\r\n  minim.stop();\r\n\r\n  super.stop();\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>[ javadoc | \u8303\u4f8b ] Minim\u662f\u4f60\u6b63\u5728\u9605\u8bfb\u7684\u97f3\u9891\u5e93\u7684\u540d\u5b57\u3002Minim\u662f\u5728\u80fd\u63d0\u4f9b\u4e00\u5806\u65b9\u6cd5\uff08method\uff09\u7ed9\u4f60\u83b7\u53d6\u7cfb\u7edf\u97f3\u9891\u8d44\u6e90\u7684\u5e93\u91cc\u7684\u4e00\u4e2a\u7c7b\u3002\u8981\u4f7f\u7528\u5b83\uff0c\u4f60\u5fc5\u987b\u5728setup()\u4e4b\u524d\u7533\u660e\u4e00\u4e2aMinm\u7684\u53d8\u91cf\uff0c\u800c\u540e\u4f8b\u793a\u4e00\u4e2aMinim\u5bf9\u8c61\u3002\u4e3a\u4e86\u4f7fMinm\u80fd\u591f\u8fa8\u8bc6\u4e00\u4e9b\u4e1c\u897f\u5e76\u80fd\u591f\u8fdb\u5165\u4f60sketch\u7684data\u6587\u4ef6\u5939\uff0c\u4f60\u5fc5\u987b\u8fd9\u4e48\u505a\u3002 \u793a\u8303\u4ee3\u7801 import ddf.minim.*; Minim minim; void setup() { size(100, 100); minim = new Minim(this); } void draw() { } \u83b7\u53d6Minim\u7684\u97f3\u9891\u8d44\u6e90 \u4f60\u53ef\u4ee5\u7528Minim\u505a\u56db\u4ef6\u4e8b\uff1a\u64ad\u653e\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6\uff0c\u64ad\u653e\u5408\u6210\u97f3\u9891\uff0c\u76d1\u542c\u97f3\u9891\u8f93\u5165\uff0c\u5411\u786c\u76d8\u5185\u5f55\u5236\u97f3\u9891\u3002\u6240\u6709\u8fd9\u4e9b\u90fd\u662f\u7531\u5e93\u5185\u4e0d\u540c\u7684\u7c7b\u64cd\u4f5c\u7684\uff0c\u8fd9\u4e9b\u7c7b\u7684\u8303\u4f8b\u901a\u8fc7\u547c\u53ebMinim\u9002\u5f53\u7684\u65b9\u6cd5\u800c\u83b7\u5f97\u3002 \u8f7d\u5165\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6 \u6709\u4e09\u4e2a\u4e0d\u540c\u7684\u7c7b\u53ef\u7528\u6765\u64ad\u653e\u4e00\u4e2a\u97f3\u9891\u6587\u4ef6\uff0c\u6bcf\u79cd\u90fd\u7528\u6765\u914d\u5408\u7279\u5b9a\u7684\u56de\u653e\u7c7b\u578b\u3002\u63a5\u4e0b\u6765\u7684\u8bfe\u7a0b\u4f1a\u8be6\u5c3d\u7684\u8bb2\u89e3\u6bcf\u4e2a\u7c7b\uff0c\u73b0\u5728\u4f60\u53ea\u9700\u8981\u77e5\u9053\u4ed6\u4eec\u662f\uff1aAudioSnippet, AudioSample, \u548c AudioPlayer\u3002\u4f60\u901a\u8fc7\u547c\u53eb\u5982\u4e0bMinim\u65b9\u6cd5\u521b\u5efa\u5b83\u4eec\uff1a loadSnippet(String filename) loadSample(String filename) loadSample(String filename, int bufferSize) loadFile(String filename) loadFile(String filename, int bufferSize) loadSnippet \u8fd4\u56de AudioSnippet\uff0cloadSample \u8fd4\u56de AudioSample, loadFile \u8fd4\u56de AudioPlayer\u3002\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\uff0cfilename\uff08\u6587\u4ef6\u540d\uff09\u53ef\u4ee5\u662f\u4f60sketch\u91ccdata\u6587\u4ef6\u5939\u4e0b\u7684\u97f3\u9891\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u4e5f\u53ef\u4ee5\u662f\u7f51\u8def\u4e0a\u7684\u97f3\u9891\u6587\u4ef6\u94fe\u63a5\u3002bufferSize\u662f\u4f60\u5e0c\u671b\u7684\u7f13\u51b2\u5668\u5927\u5c0f\uff0c\u8fd9\u4e2a\u6570\u5b57\u8d8a\u5c0f\uff0c\u97f3\u9891\u7684\u5ef6\u8fdf\u8d8a\u5c11\u3002 \u793a\u8303\u4ee3\u7801 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[61],"class_list":["post-564","post","type-post","status-publish","format-standard","hentry","category-minim","tag-minim"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=564"}],"version-history":[{"count":6,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":1043,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions\/1043"}],"wp:attachment":[{"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.travelchinawith.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}