Cマイクから音を拾ってグラフにする。
モールス信号の音声入力を作ろうと思っている。思っているだけ
そこで音の大きさを取得しないといけない。
やってみることに。
NAudioとOxyPlotを入れるには
ここからインストールできる。簡単。
これ肝心プレリリースを含める。
NAudio
はい。インストールできましたね。
では次。
OxyPlot
これは色あって迷うねぇ。画像みて確認してくれ。
で使いたいからそれね。
準備完了。ではソース。コピペしてまとめていないから宣言が下にあったり見づらいけどこれ以上まとめる気はない。
そのままコピペ。
usingSystem;
usingSystemGeneric;
usingSystem;
usingSystemData;
usingSystemDrawing;
usingSystemLinq;
usingSystemText;
usingSystemThreadingTasks;
usingSystemWindowsForms;
usingNAudio;
usingOxyPlot;
namespaceマイク入力レベル
publicpartialclassForm1:Form
Labellabel1;
NAudioWaveWaveInwaveIn;
publicForm1()
();
label1newLabel();
thisControlsAdd(label1);
label1Textaaaa;
InitPlot();
waveInnewNAudioWaveWaveIn()0;
waveInWaveIn;
waveInnewNAudioWave(:8000channels:1);
waveIn();
privatevoidWaveIn(objectsenderNAudioWavee)
for(intindex0;index<e;index2)
shortsample(short)((eBufferindex1<<8)eBufferindex);
floatsample32sample/32768f;
(sample32);
OxyPlotPlotViewplotView1newOxyPlotPlotView();
privatePlotModelplotmodelnewPlotModel();
privateOxyPlotAxesnewOxyPlotAxes
PositionOxyPlotAxesBottom
;
privateOxyPlotAxesnewOxyPlotAxes
Minimum-10
Maximum10
PositionOxyPlotAxesLeft
;
privateOxyPlotSeriesnewOxyPlotSeries();
List<float>recordednewList<float>();//音声データ
privatevoidInitPlot()
plotmodelAxesAdd();
plotmodelAxesAdd();
plotmodelSeriesAdd();
thisplotView1Modelplotmodel;
thisControlsAdd(plotView1);
plotView1WidththisWidth;
plotView1HeightthisHeight;
plotView1BackColorColorBeige;
privatevoid(floatsample)
recordedAdd(sample);
if(recordedCount1024)
varpointsrecordedSelect((vindex)>
newDataPoint((double)indexv)
)ToList();
PointsClear();
PointsAddRange(points);
thisplotView1(true);
recordedClear();
privatevoidForm1Load(objectsenderEventArgse)
for(inti0;i<NAudioWaveWaveIn;i)
varNAudioWaveWaveIn(i);
label1TextStringFormat(Device0:1cannelsiChannels);