kopia lustrzana https://github.com/backface/turtlestitch
added microphone "resolution" concept governing "bins" (buffer / bin sizes)
rodzic
c4e9518da2
commit
af1397d7d3
|
@ -53,6 +53,7 @@
|
||||||
* ported multiline library to new (custom input slot) format
|
* ported multiline library to new (custom input slot) format
|
||||||
* new "text costumes" library for generating costumes from letters or words of text
|
* new "text costumes" library for generating costumes from letters or words of text
|
||||||
* took out "b block" costume from catalog
|
* took out "b block" costume from catalog
|
||||||
|
* added microphone "resolution" concept governing "bins" (buffer / bin sizes)
|
||||||
|
|
||||||
### 2019-03-10
|
### 2019-03-10
|
||||||
* Objects, Blocks, Threads: added microphone note and pitch detection
|
* Objects, Blocks, Threads: added microphone note and pitch detection
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
<link rel="shortcut icon" href="src/favicon.ico">
|
<link rel="shortcut icon" href="src/favicon.ico">
|
||||||
<script type="text/javascript" src="src/morphic.js?version=2019-02-07"></script>
|
<script type="text/javascript" src="src/morphic.js?version=2019-02-07"></script>
|
||||||
<script type="text/javascript" src="src/widgets.js?version=2018-10-02"></script>
|
<script type="text/javascript" src="src/widgets.js?version=2018-10-02"></script>
|
||||||
<script type="text/javascript" src="src/blocks.js?version=2019-03-10"></script>
|
<script type="text/javascript" src="src/blocks.js?version=2019-03-11"></script>
|
||||||
<script type="text/javascript" src="src/threads.js?version=2019-03-10"></script>
|
<script type="text/javascript" src="src/threads.js?version=2019-03-11"></script>
|
||||||
<script type="text/javascript" src="src/objects.js?version=2019-03-10"></script>
|
<script type="text/javascript" src="src/objects.js?version=2019-03-11"></script>
|
||||||
<script type="text/javascript" src="src/gui.js?version=2019-03-06"></script>
|
<script type="text/javascript" src="src/gui.js?version=2019-03-06"></script>
|
||||||
<script type="text/javascript" src="src/paint.js?version=2019-02-22"></script>
|
<script type="text/javascript" src="src/paint.js?version=2019-02-22"></script>
|
||||||
<script type="text/javascript" src="src/lists.js?version=2019-02-07"></script>
|
<script type="text/javascript" src="src/lists.js?version=2019-02-07"></script>
|
||||||
|
|
|
@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph, DialMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2019-March-10';
|
modules.blocks = '2019-March-11';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -992,7 +992,9 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
|
||||||
'note' : ['note'],
|
'note' : ['note'],
|
||||||
'pitch' : ['pitch'],
|
'pitch' : ['pitch'],
|
||||||
'signals' : ['signals'],
|
'signals' : ['signals'],
|
||||||
'frequencies' : ['frequencies']
|
'frequencies' : ['frequencies'],
|
||||||
|
'~' : null,
|
||||||
|
'bins' : ['bins']
|
||||||
},
|
},
|
||||||
true // read-only
|
true // read-only
|
||||||
);
|
);
|
||||||
|
|
|
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
||||||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
|
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
|
||||||
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/
|
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/
|
||||||
|
|
||||||
modules.objects = '2019-March-10';
|
modules.objects = '2019-March-11';
|
||||||
|
|
||||||
var SpriteMorph;
|
var SpriteMorph;
|
||||||
var StageMorph;
|
var StageMorph;
|
||||||
|
@ -8871,8 +8871,7 @@ function Microphone() {
|
||||||
this.analyser = null;
|
this.analyser = null;
|
||||||
|
|
||||||
// parameters:
|
// parameters:
|
||||||
this.signalBufferSize = 512; // should probably be 1024 by default
|
this.resolution = 2;
|
||||||
this.fftSize = 1024; // should probably be 2048 by default
|
|
||||||
this.MIN_SAMPLES = 0; // will be initialized when AudioContext is created.
|
this.MIN_SAMPLES = 0; // will be initialized when AudioContext is created.
|
||||||
this.GOOD_ENOUGH_CORRELATION = 0.9;
|
this.GOOD_ENOUGH_CORRELATION = 0.9;
|
||||||
|
|
||||||
|
@ -8904,6 +8903,27 @@ Microphone.prototype.isOn = function () {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Microphone shared properties
|
||||||
|
|
||||||
|
Microphone.prototype.binSizes = [256, 512, 1024, 2048, 4096];
|
||||||
|
|
||||||
|
// Microphone resolution
|
||||||
|
|
||||||
|
Microphone.prototype.binSize = function () {
|
||||||
|
return this.binSizes[this.resolution - 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
Microphone.prototype.setResolution = function (num) {
|
||||||
|
if (contains([1, 2, 3, 4], num)) {
|
||||||
|
if (this.isReady) {
|
||||||
|
this.stop();
|
||||||
|
this.resolution = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Microphone ops
|
||||||
|
|
||||||
Microphone.prototype.start = function () {
|
Microphone.prototype.start = function () {
|
||||||
var AudioContext = window.AudioContext || window.webkitAudioContext,
|
var AudioContext = window.AudioContext || window.webkitAudioContext,
|
||||||
myself = this;
|
myself = this;
|
||||||
|
@ -8964,7 +8984,7 @@ Microphone.prototype.setupNodes = function (stream) {
|
||||||
Microphone.prototype.createAnalyser = function () {
|
Microphone.prototype.createAnalyser = function () {
|
||||||
var freqBufLength;
|
var freqBufLength;
|
||||||
this.analyser = this.audioContext.createAnalyser();
|
this.analyser = this.audioContext.createAnalyser();
|
||||||
this.analyser.fftSize = this.fftSize;
|
this.analyser.fftSize = this.binSizes[this.resolution];
|
||||||
freqBufLength = this.analyser.frequencyBinCount;
|
freqBufLength = this.analyser.frequencyBinCount;
|
||||||
this.freqBuffer = new Uint8Array(freqBufLength);
|
this.freqBuffer = new Uint8Array(freqBufLength);
|
||||||
this.pitchBuffer = new Float32Array(freqBufLength);
|
this.pitchBuffer = new Float32Array(freqBufLength);
|
||||||
|
@ -8973,7 +8993,7 @@ Microphone.prototype.createAnalyser = function () {
|
||||||
Microphone.prototype.createProcessor = function () {
|
Microphone.prototype.createProcessor = function () {
|
||||||
var myself = this;
|
var myself = this;
|
||||||
this.processor = this.audioContext.createScriptProcessor(
|
this.processor = this.audioContext.createScriptProcessor(
|
||||||
this.signalBufferSize
|
this.binSizes[this.resolution - 1]
|
||||||
);
|
);
|
||||||
|
|
||||||
this.processor.onaudioprocess = function (event) {
|
this.processor.onaudioprocess = function (event) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
|
||||||
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
|
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
|
||||||
TableFrameMorph, ColorSlotMorph, isSnapObject, Map*/
|
TableFrameMorph, ColorSlotMorph, isSnapObject, Map*/
|
||||||
|
|
||||||
modules.threads = '2019-March-10';
|
modules.threads = '2019-March-11';
|
||||||
|
|
||||||
var ThreadManager;
|
var ThreadManager;
|
||||||
var Process;
|
var Process;
|
||||||
|
@ -2252,9 +2252,13 @@ Process.prototype.doStopAllSounds = function () {
|
||||||
// Process audio input (interpolated)
|
// Process audio input (interpolated)
|
||||||
|
|
||||||
Process.prototype.reportAudio = function (choice) {
|
Process.prototype.reportAudio = function (choice) {
|
||||||
var stage = this.blockReceiver().parentThatIsA(StageMorph);
|
var stage = this.blockReceiver().parentThatIsA(StageMorph),
|
||||||
|
selection = this.inputOption(choice);
|
||||||
|
if (selection === 'bins') {
|
||||||
|
return stage.microphone.binSize();
|
||||||
|
}
|
||||||
if (stage.microphone.isOn()) {
|
if (stage.microphone.isOn()) {
|
||||||
switch (this.inputOption(choice)) {
|
switch (selection) {
|
||||||
case 'volume':
|
case 'volume':
|
||||||
return stage.microphone.volume;
|
return stage.microphone.volume;
|
||||||
case 'pitch':
|
case 'pitch':
|
||||||
|
|
Ładowanie…
Reference in New Issue