• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

test


Commit MetaInfo

Revision62d57e3eadfd1eb7e8eb1593eb89baa6e7e786b6 (tree)
Time2012-04-23 19:26:46
Authortyiki badwell <miria@user...>
Commitertyiki badwell

Log Message

送信元バッファに使用サイズの指定をできるようにした(インタフェースは後でまとめる)

Change Summary

Incremental Difference

--- a/Core/Momiji.Core.Buffer.cpp
+++ b/Core/Momiji.Core.Buffer.cpp
@@ -101,17 +101,27 @@ namespace Buffer {
101101 }
102102
103103 generic<typename HEADER_TYPE, typename DATA_TYPE>
104- void HeaderPool<HEADER_TYPE, DATA_TYPE>::Header::Reset(array<DATA_TYPE>^ data)
104+ void HeaderPool<HEADER_TYPE, DATA_TYPE>::Header::Reset(array<DATA_TYPE>^ data, System::UInt32 useSize)
105105 {
106- #ifdef _DEBUG
107- System::Console::WriteLine("[{0}][this length:{1}][data length:{2}]",__FUNCTION__, this->_buffer->Length, data->Length);
108- #endif
106+ // #ifdef _DEBUG
107+ // System::Console::WriteLine("[{0}][this length:{1}][data length:{2}][use length:{3}]",__FUNCTION__, this->_buffer->Length, data->Length, useSize);
108+ // #endif
109+
110+ if (useSize > data->Length) {
111+ throw gcnew HeaderException("データバッファサイズと使用サイズの関係がおかしい [データバッファサイズ:" + data->Length.ToString("D") + "][使用サイズ:" + useSize.ToString("D") + "]");
112+ }
113+
114+ //確保していたバッファを超えていたら、後半は打ち切り
115+ if (useSize > this->_buffer->Length) {
116+ System::Console::WriteLine("[{0}] drop size[{1}]",__FUNCTION__, useSize - this->_buffer->Length);
117+ useSize = this->_buffer->Length;
118+ }
109119
110- System::Array::Copy(data, this->_buffer, data->Length); //確保していたバッファを超えていたら、ココでエラーになることを期待して、長さチェックはしないことにしておく
120+ System::Array::Copy(data, this->_buffer, useSize);
111121
112122 System::Object^ header =
113123 this->_headerInitializer(
114- InteropServices::Marshal::SizeOf(DATA_TYPE::typeid) * data->Length,
124+ InteropServices::Marshal::SizeOf(DATA_TYPE::typeid) * useSize,
115125 this->_bufferHandle.AddrOfPinnedObject()
116126 );
117127
--- a/Core/Momiji.Core.Buffer.h
+++ b/Core/Momiji.Core.Buffer.h
@@ -62,7 +62,7 @@ namespace Buffer {
6262
6363 public:
6464 System::IntPtr GetHeaderIntPtr();
65- void Reset(array<DATA_TYPE>^ data);
65+ void Reset(array<DATA_TYPE>^ data, System::UInt32 useSize);
6666
6767 HEADER_TYPE ToHeader();
6868
@@ -99,6 +99,15 @@ namespace Buffer {
9999
100100 };
101101
102+ public ref class HeaderException
103+ : public System::Exception
104+ {
105+ public:
106+ HeaderException(System::String^ v): System::Exception(v){};
107+ virtual ~HeaderException(void){};
108+ };
109+
110+
102111 }
103112 }
104113 }
--- a/Core/Momiji.Core.Midi.Data.h
+++ b/Core/Momiji.Core.Midi.Data.h
@@ -103,15 +103,18 @@ namespace Midi {
103103 {
104104 private:
105105 initonly array<System::Byte>^ _longData;
106+ initonly System::UInt32 _useSize;
106107
107108 public:
108109 LongData(
109110 System::UInt64 tick,
110111 System::UInt16 port,
111- array<System::Byte>^ longData
112- ): MidiData(tick, port), _longData(longData) {}
112+ array<System::Byte>^ longData,
113+ System::UInt32 useSize
114+ ): MidiData(tick, port), _longData(longData), _useSize(useSize) {}
113115
114116 property array<System::Byte>^ longData { array<System::Byte>^ get() {return this->_longData;} }
117+ property System::UInt32 useSize { System::UInt32 get() { return this->_useSize; } }
115118 };
116119
117120 }
--- a/Core/Momiji.Core.Midi.Out.cpp
+++ b/Core/Momiji.Core.Midi.Out.cpp
@@ -272,7 +272,7 @@ namespace Out {
272272 }
273273
274274 void Device::SendLong(
275- array<System::Byte>^ data
275+ array<System::Byte>^ data, System::UInt32 useSize
276276 )
277277 {
278278 #ifdef _DEBUG
@@ -298,7 +298,7 @@ namespace Out {
298298 return;
299299 }
300300
301- System::IntPtr headerPtr = this->Prepare(data);
301+ System::IntPtr headerPtr = this->Prepare(data, useSize);
302302
303303 auto mmResult =
304304 Interop::Winmm::Function::midiOutLongMsg(
@@ -313,7 +313,7 @@ namespace Out {
313313 }
314314 }
315315
316- System::IntPtr Device::Prepare(array<System::Byte>^ data)
316+ System::IntPtr Device::Prepare(array<System::Byte>^ data, System::UInt32 useSize)
317317 {
318318 #ifdef _DEBUG
319319 System::Console::WriteLine("[{0}]",__FUNCTION__);
@@ -322,7 +322,7 @@ namespace Out {
322322 Core::Buffer::HeaderPool<Interop::Winmm::MidiHeader, System::Byte>::Header^ header =
323323 this->_headerPool->Get();
324324
325- header->Reset(data);
325+ header->Reset(data, useSize);
326326
327327 auto mmResult =
328328 Interop::Winmm::Function::midiOutPrepareHeader(
@@ -489,7 +489,7 @@ namespace Out {
489489 Core::Midi::LongData^ longData = dynamic_cast<Core::Midi::LongData^>(midiData);
490490 if (longData != nullptr)
491491 {
492- d->SendLong(longData->longData);
492+ d->SendLong(longData->longData, longData->longData->Length);
493493 return;
494494 }
495495
--- a/Core/Momiji.Core.Midi.Out.h
+++ b/Core/Momiji.Core.Midi.Out.h
@@ -49,7 +49,7 @@ namespace Out {
4949 !Device();
5050
5151 private:
52- System::IntPtr Prepare(array<System::Byte>^ data);
52+ System::IntPtr Prepare(array<System::Byte>^ data, System::UInt32 useSize);
5353 void Unprepare(System::IntPtr headerPtr);
5454
5555 Interop::Winmm::MidiHeader InitializeHeader(System::UInt32 bufferLength, System::IntPtr bufferPtr);
@@ -65,7 +65,7 @@ namespace Out {
6565
6666 public:
6767 void SendShort(System::UInt32 dwMsg);
68- void SendLong(array<System::Byte>^ data);
68+ void SendLong(array<System::Byte>^ data, System::UInt32 useSize);
6969
7070 public:
7171 event System::EventHandler<System::EventArgs^>^ OnOpen;
--- a/Core/Momiji.Core.Wave.Data.h
+++ b/Core/Momiji.Core.Wave.Data.h
@@ -37,20 +37,24 @@ namespace Wave {
3737 : public Core::IData
3838 {
3939 private:
40- System::UInt16 _port;
41- array<T>^ _data;
40+ initonly System::UInt16 _port;
41+ initonly array<T>^ _data;
42+ initonly System::UInt32 _useSize;
4243
4344 public:
4445 WaveData(
4546 System::UInt16 port,
46- array<T>^ data
47- ): _port(port), _data(data) {}
47+ array<T>^ data,
48+ System::UInt32 useSize
49+ ): _port(port), _data(data), _useSize(useSize) {}
4850
4951 public:
5052 property System::UInt16 port { System::UInt16 get() {return this->_port;} }
5153 property array<T>^ data { array<T>^ get() {return this->_data;} }
54+ property System::UInt32 useSize { System::UInt32 get() { return this->_useSize; } }
5255 };
5356
57+
5458 }
5559 }
5660 }
--- a/Core/Momiji.Core.Wave.Out.cpp
+++ b/Core/Momiji.Core.Wave.Out.cpp
@@ -299,7 +299,7 @@ namespace Out {
299299
300300 //TODO 要同期
301301 generic<typename T>
302- System::IntPtr Device<T>::Prepare(array<T>^ data)
302+ System::IntPtr Device<T>::Prepare(array<T>^ data, System::UInt32 useSize)
303303 {
304304 #ifdef _DEBUG
305305 System::Console::WriteLine("[{0}]",__FUNCTION__);
@@ -308,7 +308,7 @@ namespace Out {
308308 Core::Buffer::HeaderPool<Interop::Winmm::WaveHeader, T>::Header^ header =
309309 this->_headerPool->Get();
310310
311- header->Reset(data);
311+ header->Reset(data, useSize);
312312
313313 auto mmResult =
314314 Interop::Winmm::Function::waveOutPrepareHeader(
@@ -376,7 +376,7 @@ namespace Out {
376376
377377 generic<typename T>
378378 void Device<T>::Send(
379- array<T>^ data
379+ array<T>^ data, System::UInt32 useSize
380380 )
381381 {
382382 #ifdef _DEBUG
@@ -396,7 +396,7 @@ namespace Out {
396396
397397 //TODO 長かったら分割して送信する
398398
399- System::IntPtr headerPtr = this->Prepare(data);
399+ System::IntPtr headerPtr = this->Prepare(data, useSize);
400400
401401 auto mmResult =
402402 Interop::Winmm::Function::waveOutWrite(
@@ -528,7 +528,7 @@ namespace Out {
528528 }
529529
530530 Device<T>^ d = this->_outs[p];
531- d->Send(waveData->data);
531+ d->Send(waveData->data, waveData->useSize);
532532 }
533533
534534 }
--- a/Core/Momiji.Core.Wave.Out.h
+++ b/Core/Momiji.Core.Wave.Out.h
@@ -66,7 +66,7 @@ namespace Out {
6666 !Device();
6767
6868 private:
69- System::IntPtr Prepare(array<T>^ data);
69+ System::IntPtr Prepare(array<T>^ data, System::UInt32 useSize);
7070 void Unprepare(System::IntPtr headerPtr);
7171
7272 Interop::Winmm::WaveHeader InitializeHeader(System::UInt32 bufferLength, System::IntPtr bufferPtr);
@@ -81,7 +81,7 @@ namespace Out {
8181 void Close();
8282
8383 public:
84- void Send(array<T>^ data);
84+ void Send(array<T>^ data, System::UInt32 useSize);
8585
8686 public:
8787 event System::EventHandler<System::EventArgs^>^ OnOpen;
--- a/Core/Momiji.Sequencer.Midi.Smf.cpp
+++ b/Core/Momiji.Sequencer.Midi.Smf.cpp
@@ -159,6 +159,13 @@ namespace Smf {
159159 }
160160 }
161161
162+ //TODO: packetにIComparerを実装してもSortで反応してくれなかったので、仕方なくコレで。
163+ int IStreamPacketCompare(Core::IStreamPacket^ a, Core::IStreamPacket^ b)
164+ {
165+ //TODO: RPN・NRPNの塊は維持したままソートしないとダメだった
166+ return a->tick.CompareTo(b->tick);
167+ }
168+
162169 array<Core::IStreamPacket^>^ SmfStream::GetStreamPacket(System::Double deltaTime)
163170 {
164171 #ifdef _DEBUG
@@ -173,6 +180,8 @@ namespace Smf {
173180 result->AddRange(data);
174181 }
175182
183+ // result->Sort(gcnew System::Comparison<Core::IStreamPacket^>(IStreamPacketCompare));
184+
176185 return result->ToArray();
177186 }
178187
@@ -355,7 +364,8 @@ namespace Smf {
355364 gcnew Core::Midi::LongData(
356365 this->_tick,
357366 metaPort->number,
358- longData
367+ longData,
368+ longData->Length
359369 );
360370 break;
361371 }
--- a/Test/Momiji.Test.Sequencer.Wave/Form1.h
+++ b/Test/Momiji.Test.Sequencer.Wave/Form1.h
@@ -141,7 +141,8 @@ namespace MomijiTestSequencerWave {
141141 private:
142142 void OnDone(System::Object^ sender, System::EventArgs^ args)
143143 {
144- o->Send(s->Read(this->_samplesPerBuffer));
144+ auto data = s->Read(this->_samplesPerBuffer);
145+ o->Send(data, data->Length);
145146 }
146147
147148 public:
@@ -170,9 +171,11 @@ namespace MomijiTestSequencerWave {
170171
171172 o->OnDone += gcnew System::EventHandler<System::EventArgs^>(this, &TestWave::OnDone);
172173
174+ //このやり方は、周ってる間にOnDoneが発生して順番が崩れるかも?
173175 for (auto i = 0; i < count; i++)
174176 {
175- o->Send(s->Read(this->_samplesPerBuffer));
177+ auto data = s->Read(this->_samplesPerBuffer);
178+ o->Send(data, data->Length);
176179 }
177180
178181 }
--- a/Test/Momiji.Test.Vst.Controller/Momiji.Test.Vst.Controller.cpp
+++ b/Test/Momiji.Test.Vst.Controller/Momiji.Test.Vst.Controller.cpp
@@ -13,8 +13,76 @@ private:
1313 Momiji::Core::IStream^ _stream;
1414 Momiji::Core::IOut^ _out;
1515
16- Momiji::Core::Vst::Host::Master^ _host;
16+ //Momiji::Core::Vst::Host::Master^ _host;
1717
18+ Collections::Generic::List<Momiji::Core::Vst::Host::Master^>^ _hosts;
19+
20+ int _interval;
21+ int _sampleMax;
22+ int _ch;
23+ array<System::Single>^ _data;
24+ Momiji::Core::Vst::Buffer::VstBuffer<System::Single>^ _inBuffer;
25+ Momiji::Core::Vst::Buffer::VstBuffer<System::Single>^ _outBuffer;
26+
27+
28+public:
29+ Controller()
30+ {
31+ #ifdef _DEBUG
32+ System::Console::WriteLine("[{0}]",__FUNCTION__);
33+ #endif
34+
35+ this->_interval = 10;
36+ this->_sampleMax = 48000.0 * this->_interval * 2 / 1000.0;
37+
38+ this->_ch = 1;
39+ this->_data = gcnew array<System::Single>(this->_sampleMax * 2);
40+ this->_inBuffer = gcnew Momiji::Core::Vst::Buffer::VstBuffer<System::Single>(2,this->_sampleMax);
41+ this->_outBuffer = gcnew Momiji::Core::Vst::Buffer::VstBuffer<System::Single>(2,this->_sampleMax);
42+
43+ this->_hosts = gcnew Collections::Generic::List<Momiji::Core::Vst::Host::Master^>;
44+ }
45+
46+ ~Controller()
47+ {
48+ #ifdef _DEBUG
49+ System::Console::WriteLine("[{0}]",__FUNCTION__);
50+ #endif
51+ this->!Controller();
52+ }
53+
54+ void Start()
55+ {
56+ #ifdef _DEBUG
57+ System::Console::WriteLine("[{0}]",__FUNCTION__);
58+ #endif
59+ if (this->_timer != nullptr)
60+ {
61+ this->_timer->Start(this->_interval);
62+ }
63+ }
64+
65+ void Stop()
66+ {
67+ #ifdef _DEBUG
68+ System::Console::WriteLine("[{0}]",__FUNCTION__);
69+ #endif
70+ if (this->_timer != nullptr)
71+ {
72+ this->_timer->Stop();
73+ }
74+ }
75+
76+protected:
77+ !Controller()
78+ {
79+ #ifdef _DEBUG
80+ System::Console::WriteLine("[{0}]",__FUNCTION__);
81+ #endif
82+ this->Stop();
83+ }
84+
85+private:
1886 void OnInterval(System::Double deltaTime)
1987 {
2088 #ifdef _DEBUG
@@ -22,7 +90,7 @@ private:
2290 #endif
2391 auto stream = this->_stream;
2492 auto out = this->_out;
25- auto host = this->_host;
93+ auto hosts = this->_hosts;
2694
2795 if (stream == nullptr)
2896 {
@@ -38,7 +106,7 @@ private:
38106 #endif
39107 return;
40108 }
41- if (host == nullptr)
109+ if (hosts == nullptr)
42110 {
43111 #ifdef _DEBUG
44112 System::Console::WriteLine("[{0}]VSTが無いので何もしません",__FUNCTION__);
@@ -46,10 +114,19 @@ private:
46114 return;
47115 }
48116
49- int sample = 44100.0 * deltaTime / 1000.0;
50-// System::Console::WriteLine("[{0}][{1}][{2}]",__FUNCTION__, sample, deltaTime);
117+ int sample = 48000.0 * deltaTime / 1000.0;
118+ //System::Console::WriteLine("[{0}][{1}][{2}][{3}]",__FUNCTION__, this->_sampleMax, sample, deltaTime);
119+
120+ if (sample > this->_sampleMax) {
121+ sample = this->_sampleMax;
122+ }
123+
124+ auto events = gcnew Collections::Generic::List< Collections::Generic::List<Momiji::Interop::Vst::VstEvent>^ >;
125+ for (int i = 0; i < this->_ch; i++)
126+ {
127+ events->Add(gcnew Collections::Generic::List<Momiji::Interop::Vst::VstEvent>);
128+ }
51129
52- auto events = gcnew Collections::Generic::List<Momiji::Interop::Vst::VstEvent>;
53130 auto packets = stream->GetStreamPacket(deltaTime);
54131 auto startTick = 0;
55132 for each(auto packet in packets)
@@ -66,83 +143,46 @@ private:
66143 auto e = Momiji::Interop::Vst::VstEvent();
67144 e.type = Momiji::Interop::Vst::VstEvent::VstEventTypes::kVstMidiType;
68145 e.flags = Momiji::Interop::Vst::VstEvent::VstMidiEventFlags::kVstMidiEventIsRealtime;
69- e.deltaFrames = 0;//((sample < delta) ? sample : delta) * 10000;
146+ e.deltaFrames = ((sample < delta) ? sample : delta) * 10000; //これはちゃんと求めるようにする
70147 e.midiData = midi->shortData;
71- events->Add(e);
148+ events[0/*midi->port*/]->Add(e);
72149 }
73- host->ProcessEvents(events->ToArray());
74- delete events;
75-
76- auto inBuffer = gcnew Momiji::Core::Vst::Buffer::VstBuffer<System::Single>(2,sample);
77- auto outBuffer = gcnew Momiji::Core::Vst::Buffer::VstBuffer<System::Single>(2,sample);
78150
79- host->Process(inBuffer, outBuffer, outBuffer->Length());
80-
81- delete inBuffer;
82-
83- auto data = gcnew array<System::Single>(sample * 2);
84151 auto pos = 0;
85- for (int idx = 0; idx < sample; idx++)
152+ for (int i = 0; i < this->_ch; i++)
86153 {
87- data[pos++] = outBuffer->GetBuffer()[0][idx];
88- data[pos++] = outBuffer->GetBuffer()[1][idx];
89- }
90- delete outBuffer;
154+ auto host = hosts[i];
91155
92- auto buffer = gcnew Momiji::Core::Wave::WaveData<System::Single>(0, data);
93- delete data;
156+ host->ProcessEvents(events[i]->ToArray());
157+ host->Process(this->_inBuffer, this->_outBuffer, sample/*this->_outBuffer->Length()/**/);
94158
95- out->Send(buffer);
96- buffer = nullptr;
97- }
159+ for (int idx = 0; idx < sample; idx++)
160+ {
161+ this->_data[pos++] += this->_outBuffer->GetBuffer()[0][idx];
162+ this->_data[pos++] += this->_outBuffer->GetBuffer()[1][idx];
163+ }
164+ }
98165
99-public:
100- Controller()
101- {
102- #ifdef _DEBUG
103- System::Console::WriteLine("[{0}]",__FUNCTION__);
104- #endif
105- }
166+ delete events;
106167
107- ~Controller()
108- {
109- #ifdef _DEBUG
110- System::Console::WriteLine("[{0}]",__FUNCTION__);
111- #endif
112- this->!Controller();
113- }
168+ auto buffer = gcnew Momiji::Core::Wave::WaveData<System::Single>(0, this->_data, pos);
114169
115- void Start()
116- {
117- #ifdef _DEBUG
118- System::Console::WriteLine("[{0}]",__FUNCTION__);
119- #endif
120- if (this->_timer != nullptr)
121- {
122- this->_timer->Start(10);
123- }
124- }
170+ out->Send(buffer);
125171
126- void Stop()
127- {
128- #ifdef _DEBUG
129- System::Console::WriteLine("[{0}]",__FUNCTION__);
130- #endif
131- if (this->_timer != nullptr)
172+ pos = 0;
173+ for (int i = 0; i < this->_ch; i++)
132174 {
133- this->_timer->Stop();
175+ for (int idx = 0; idx < sample; idx++)
176+ {
177+ this->_data[pos++] = 0;
178+ this->_data[pos++] = 0;
179+ }
134180 }
135- }
136181
137-protected:
138- !Controller()
139- {
140- #ifdef _DEBUG
141- System::Console::WriteLine("[{0}]",__FUNCTION__);
142- #endif
143- this->Stop();
182+ buffer = nullptr;
144183 }
145184
185+
146186 public:
147187 void Assign(Momiji::Core::ITimer^ timer)
148188 {
@@ -166,9 +206,9 @@ public:
166206 this->_out = out;
167207 }
168208
169- void Assign(Momiji::Core::Vst::Host::Master^ host)
209+ void Add(Momiji::Core::Vst::Host::Master^ host)
170210 {
171- this->_host = host;
211+ this->_hosts->Add(host);
172212 }
173213
174214 };
@@ -231,30 +271,32 @@ void test0()
231271 o->AddPort(
232272 0,
233273 2,
234- 44110,
274+ 48000,
235275 System::Runtime::InteropServices::Marshal::SizeOf(System::Single::typeid) * 8,
236276 (
237277 Momiji::Interop::Winmm::WaveFormatExtensiblePart::SPEAKER::FRONT_LEFT
238278 | Momiji::Interop::Winmm::WaveFormatExtensiblePart::SPEAKER::FRONT_RIGHT
239279 ),
240280 Momiji::Interop::Ks::StaticKs::SUBTYPE_IEEE_FLOAT,
241- 44110
281+ 48000
242282 );
243283
244- h = gcnew Momiji::Core::Vst::Host::Master(vstFileName);
245- h->SetSampleRate(44100);
246- h->SetBlockSize(512);
247- h->Resume();
248- h->Suspend();
249- h->StartProcess();
250-
251284 c = gcnew Controller();
252285 c->Assign(t);
253286 c->Assign(s);
254287 c->Assign(o);
255- c->Assign(h);
256288
257- h->Resume();
289+ for (int i = 0; i < 1/*16*/; i++) {
290+ h = gcnew Momiji::Core::Vst::Host::Master(vstFileName);
291+ h->SetSampleRate(48000);
292+ h->SetBlockSize(48000);
293+ h->Resume();
294+ h->Suspend();
295+ h->StartProcess();
296+ h->Resume();
297+
298+ c->Add(h);
299+ }
258300
259301 c->Start();
260302 Console::WriteLine("============ enter でstop");