1 //// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
2 //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
3 //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
4 //// PARTICULAR PURPOSE.
6 //// Copyright (c) Microsoft Corporation. All rights reserved
9 #include "SoundDriver.h"
11 #include "BasicLoader.h"
12 #include "windows.ui.xaml.media.dxinterop.h"
14 using namespace Microsoft::WRL;
15 using namespace Windows::Foundation;
16 using namespace Windows::Foundation::Collections;
17 using namespace Windows::UI::Core;
18 using namespace Windows::UI::ViewManagement;
20 using namespace Windows::UI::ApplicationSettings;
21 using namespace Windows::UI::Popups;
22 using namespace Windows::UI::Xaml::Controls;
23 using namespace Windows::Graphics::Display;
24 using namespace DirectX;
26 using namespace concurrency;
29 using namespace BasicSprites;
31 const float GameMain::BACKBUFFER_WIDTH = 320.0f;
32 const float GameMain::BACKBUFFER_HEIGHT = 240.0f;
35 GameMain::GameMain() : backBufferViewPort_(0.0f,0.0f,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT) , isDestroy_(false)
37 soundDriver_.reset(new sf::SoundDriver());
38 soundManager_.reset(new sf::SoundManager(*soundDriver_.get()));
39 //
\83T
\83E
\83\93\83h
\8dÄ
\90¶
\83X
\83\8c\83b
\83h
\82Ì
\8aJ
\8en
40 soundTask_ = task<void>(create_async([this]()
45 //soundThread_ = std::thread(
48 // ExecuteSoundThread();
55 //
\83T
\83E
\83\93\83h
\8dÄ
\90¶
\83X
\83\8c\83b
\83h
\82Ì
\92â
\8e~
59 //if(soundThread_.joinable())
61 // soundThread_.join();
65 void GameMain::CreateDeviceIndependentResources()
67 DirectXBase::CreateDeviceIndependentResources();
69 // Create the performance throttler.
71 autoThrottle_ = ref new AutoThrottle(1.0f / 60.0f);
74 void GameMain::Initialize(
75 _In_ Windows::UI::Core::CoreWindow^ window,
76 _In_ Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
80 panel_ = swapChainPanel;
81 Initialize(window,dpi);
84 void GameMain::CreateDeviceResources()
86 DirectXBase::CreateDeviceResources();
88 // Create the sprite batch.
90 spriteBatch_ = ref new SpriteBatch();
91 unsigned int capacity = 1024;
92 if (m_featureLevel < D3D_FEATURE_LEVEL_9_3)
94 capacity = min(Parameters::MaximumCapacityCompatible, capacity);
96 spriteBatch_->Initialize(
101 // Load the sprite textures.
103 BasicLoader^ loader = ref new BasicLoader(m_d3dDevice.Get(), m_wicFactory.Get());
111 spriteBatch_->AddTexture(test_.Get(),float2(64.0,64.0));
113 // Create the Sample Overlay.
115 sampleOverlay_ = ref new SampleOverlay();
117 sampleOverlay_->Initialize(
121 m_dwriteFactory.Get(),
122 L"
\83V
\83\85\81[
\83e
\83B
\83\93\83O
\83Q
\81[
\83\80"
129 void GameMain::CreateWindowSizeDependentResources()
131 // DirectXBase::CreateWindowSizeDependentResources();
132 // Store the window bounds so the next time we get a SizeChanged event we can
133 // avoid rebuilding everything if the size is identical.
134 m_windowBounds = m_window->Bounds;
136 // If the swap chain already exists, resize it.
137 if(m_swapChain != nullptr)
140 m_swapChain->ResizeBuffers(2, 0, 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0)
143 // Otherwise, create a new one.
146 // Allocate a descriptor.
147 DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
148 scale_ = floorf(m_window->Bounds.Width * m_dpi / ( 96.0f * BACKBUFFER_WIDTH));
149 swapChainDesc.Width = static_cast<UINT>(m_window->Bounds.Width * m_dpi / 96.0f); // Can not use 0 to get the default on Composition SwapChain
150 swapChainDesc.Height = static_cast<UINT>(m_window->Bounds.Height * m_dpi / 96.0f);
151 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format
152 swapChainDesc.Stereo = false;
153 swapChainDesc.SampleDesc.Count = 1; // don't use multi-sampling
154 swapChainDesc.SampleDesc.Quality = 0;
155 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
156 swapChainDesc.BufferCount = 2; // use double buffering to enable flip
157 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
158 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // all Metro style apps must use this SwapEffect
159 swapChainDesc.Flags = 0;
161 // Once the desired swap chain description is configured, it must be created on the same adapter as our D3D Device
163 // First, retrieve the underlying DXGI Device from the D3D Device.
164 ComPtr<IDXGIDevice1> dxgiDevice;
166 m_d3dDevice.As(&dxgiDevice)
169 // Identify the physical adapter (GPU or card) this device is running on.
170 ComPtr<IDXGIAdapter> dxgiAdapter;
172 dxgiDevice->GetAdapter(&dxgiAdapter)
175 // And obtain the factory object that created it.
176 ComPtr<IDXGIFactory2> dxgiFactory;
178 dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory))
181 // Obtain the final swap chain for this window from the DXGI factory.
183 dxgiFactory->CreateSwapChainForComposition(
186 nullptr, // allow on all displays
191 ComPtr<ISwapChainBackgroundPanelNative> dxRootPanelAsNative;
193 // set the swap chain on the SwapChainBackgroundPanel
194 reinterpret_cast<IUnknown*>(panel_)->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void**)&dxRootPanelAsNative);
197 dxRootPanelAsNative->SetSwapChain(m_swapChain.Get())
200 // Ensure that DXGI does not queue more than one frame at a time. This both reduces
201 // latency and ensures that the application will only render after each VSync, minimizing
202 // power consumption.
204 dxgiDevice->SetMaximumFrameLatency(1)
209 // Obtain the backbuffer for this window which will be the final 3D rendertarget.
210 ComPtr<ID3D11Texture2D> backBuffer;
212 m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer))
215 // Create a view interface on the rendertarget to use on bind.
217 m_d3dDevice->CreateRenderTargetView(
224 // Cache the rendertarget dimensions in our helper class for convenient use.
225 D3D11_TEXTURE2D_DESC backBufferDesc = {0};
226 backBuffer->GetDesc(&backBufferDesc);
227 m_renderTargetSize.Width = static_cast<float>(backBufferDesc.Width);
228 m_renderTargetSize.Height = static_cast<float>(backBufferDesc.Height);
230 // Create a descriptor for the depth/stencil buffer.
231 CD3D11_TEXTURE2D_DESC depthStencilDesc(
232 DXGI_FORMAT_D24_UNORM_S8_UINT,
233 backBufferDesc.Width,
234 backBufferDesc.Height,
237 D3D11_BIND_DEPTH_STENCIL
240 // Allocate a 2-D surface as the depth/stencil buffer.
241 ComPtr<ID3D11Texture2D> depthStencil;
243 m_d3dDevice->CreateTexture2D(
250 // Create a DepthStencil view on this surface to use on bind.
252 m_d3dDevice->CreateDepthStencilView(
254 &CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D),
259 // Create a viewport descriptor of the full window size.
260 swapChainViewPort_.Width = static_cast<float>(backBufferDesc.Width);
261 swapChainViewPort_.Height = static_cast<float>(backBufferDesc.Height);
263 // Set the current viewport using the descriptor.
264 m_d3dContext->RSSetViewports(1, &swapChainViewPort_);
266 // Now we set up the Direct2D render target bitmap linked to the swapchain.
267 // Whenever we render to this bitmap, it will be directly rendered to the
268 // swapchain associated with the window.
269 D2D1_BITMAP_PROPERTIES1 bitmapProperties =
271 D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
272 PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
277 // Direct2D needs the dxgi version of the backbuffer surface pointer.
278 ComPtr<IDXGISurface> dxgiBackBuffer;
280 m_swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer))
283 // Get a D2D surface from the DXGI back buffer to use as the D2D render target.
285 m_d2dContext->CreateBitmapFromDxgiSurface(
286 dxgiBackBuffer.Get(),
292 // So now we can set the Direct2D render target.
293 m_d2dContext->SetTarget(m_d2dTargetBitmap.Get());
295 // Set D2D text anti-alias mode to Grayscale to ensure proper rendering of text on intermediate surfaces.
296 m_d2dContext->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
298 // Randomly generate some non-interactive asteroids to fit the screen.
300 sampleOverlay_->UpdateForWindowSizeChange();
301 //
\83o
\83b
\83N
\83o
\83b
\83t
\83@
\82Ì
\8dì
\90¬
302 //ComPtr<ID3D11Texture2D> backBuffer;
304 // m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer))
306 //D3D11_TEXTURE2D_DESC backBufferDesc = {0};
307 //backBuffer->GetDesc(&backBufferDesc);
309 D3D11_TEXTURE2D_DESC desc = {0};
312 desc.Format = backBufferDesc.Format;
314 desc.SampleDesc.Count = 1;
315 desc.SampleDesc.Quality = 0;
317 desc.Usage = D3D11_USAGE_DEFAULT;
318 desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
319 // desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
321 DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D(&desc,NULL,&backBuffer_));
323 DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView(backBuffer_.Get(),0,&backBufferRenderTargetView_));
325 // //
\90[
\93x
\83o
\83b
\83t
\83@
\82Ì
\8dì
\90¬
326 // D3D11_TEXTURE2D_DESC depth = {} ;
327 // depth.Width = desc.Width;//rc.right - rc.left;client_width_;
328 // depth.Height = desc.Height;//rc.bottom - rc.top;client_height_;
329 // depth.MipLevels = 1;
330 // depth.ArraySize = 1;
331 // depth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
332 // depth.SampleDesc.Count = 1;
333 // depth.SampleDesc.Quality = 0;
334 // depth.Usage = D3D11_USAGE_DEFAULT;
335 // depth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
336 // depth.CPUAccessFlags = 0;
337 // depth.MiscFlags = 0;
338 // ComPtr<ID3D11Texture2D> depthT;
339 //DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D( &depth, NULL, &depthT ));
341 // D3D11_DEPTH_STENCIL_VIEW_DESC dsv = {};
342 // dsv.Format = depth.Format;
343 // dsv.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
344 // dsv.Texture2D.MipSlice = 0;
346 //DX::ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( depthT.Get(), &dsv, &backBufferDepthStencilView_ ));
348 spriteBatch_->AddTexture(backBuffer_.Get(),float2());
350 //
\90[
\93x
\83X
\83e
\83\93\83V
\83\8b\83X
\83e
\81[
\83g
\82ð
\8dì
\90¬
\82·
\82é
351 //D3D11_DEPTH_STENCIL_DESC ddsDesc;
352 //::ZeroMemory( &ddsDesc, sizeof( ddsDesc ) );
353 //ddsDesc.DepthEnable = TRUE; //
\90[
\93x
\83e
\83X
\83g
\82ð
\8eg
\97p
\82·
\82é
354 //ddsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
355 //ddsDesc.DepthFunc = D3D11_COMPARISON_LESS;
356 //ddsDesc.StencilEnable = FALSE;
357 //DX::ThrowIfFailed(m_d3dDevice->CreateDepthStencilState( &ddsDesc, &backBufferDepthStencilState_ ));
361 void GameMain::Update(float timeTotal, float timeDelta)
363 // Update the performance throttler.
365 auto control = autoThrottle_->Update(timeDelta);
367 //if (control == FrameWorkload::Increase)
369 // m_numParticlesToDraw += SampleSettings::Performance::ParticleCountDelta;
371 //if (control == FrameWorkload::Decrease)
373 // m_numParticlesToDraw -= SampleSettings::Performance::ParticleCountDelta;
375 //if (control != FrameWorkload::Maintain)
377 // m_numParticlesToDraw = max(SampleSettings::Performance::ParticleCountMin, min(SampleSettings::Performance::ParticleCountMax, m_numParticlesToDraw));
378 // if (m_featureLevel < D3D_FEATURE_LEVEL_9_3)
380 // m_numParticlesToDraw = min(static_cast<int>(Parameters::MaximumCapacityCompatible - SampleSettings::NumAsteroids - 1), m_numParticlesToDraw);
384 // Update the non-interactive asteroids.
385 // Their behavior is to drift across the window with a fixed translational and rotational
386 // velocity. Upon crossing a boundary outside the window, their position wraps.
388 //for (auto asteroid = m_asteroidData.begin(); asteroid != m_asteroidData.end(); asteroid++)
390 // static const float border = 100.0f;
391 // asteroid->pos = asteroid->pos + asteroid->vel * timeDelta;
392 // if (asteroid->vel.x < 0)
394 // if (asteroid->pos.x < -border)
396 // asteroid->pos.x = m_windowBounds.Width + border;
401 // if (asteroid->pos.x > m_windowBounds.Width + border)
403 // asteroid->pos.x = -border;
406 // if (asteroid->vel.y < 0)
408 // if (asteroid->pos.y < -border)
410 // asteroid->pos.y = m_windowBounds.Height + border;
415 // if (asteroid->pos.y > m_windowBounds.Height + border)
417 // asteroid->pos.y = -border;
421 // asteroid->rot += asteroid->rotVel * timeDelta;
422 // if (asteroid->rot > static_cast<float>(M_PI))
424 // asteroid->rot -= 2.0f * static_cast<float>(M_PI);
426 // if (asteroid->rot < static_cast<float>(-M_PI))
428 // asteroid->rot += 2.0f * static_cast<float>(M_PI);
432 //// Update the interactive particles.
433 //// Their behavior is to be gravitationally attracted to two oscillating gravity
434 //// wells and repelled by any pressed pointer points. Upon reaching the edge of
435 //// the window, the particles bounce.
437 //// Add two gravity wells that move throughout the window.
438 //float2 wellPositions[] =
441 // (1.0f + 0.8f * cosf(timeTotal / (2.0f * static_cast<float>(M_PI)) + 3.0f)) * m_windowBounds.Width / 2.0f,
442 // (1.0f + 0.8f * sinf(timeTotal / 5.0f)) * m_windowBounds.Height / 2.0f
445 // (1.0f + 0.8f * cosf(timeTotal / static_cast<float>(M_PI * M_PI) + 1.0f)) * m_windowBounds.Width / 2.0f,
446 // (1.0f + 0.8f * sinf(timeTotal / static_cast<float>(M_PI))) * m_windowBounds.Height / 2.0f
450 //for (auto particle = m_particleData.begin(); particle != m_particleData.begin() + m_numParticlesToDraw; particle++)
452 // if (particle->pos.x < 0)
454 // particle->vel.x = abs(particle->vel.x);
456 // if (particle->pos.x > m_windowBounds.Width)
458 // particle->vel.x = -abs(particle->vel.x);
460 // if (particle->pos.y < 0)
462 // particle->vel.y = abs(particle->vel.y);
464 // if (particle->pos.y > m_windowBounds.Height)
466 // particle->vel.y = -abs(particle->vel.y);
469 // for (auto repulsor = m_repulsors.begin(); repulsor != m_repulsors.end(); repulsor++)
471 // float2 delta = particle->pos - repulsor->second;
472 // float deltaLength = length(delta) + 24.0f; // Offset length to avoid division by zero.
473 // float deltaLengthCubed = deltaLength * deltaLength * deltaLength;
474 // particle->vel = particle->vel + SampleSettings::Physics::Gravity * timeDelta * delta / deltaLengthCubed;
477 // for (int i = 0; i < ARRAYSIZE(wellPositions); i++)
479 // float gravitySign = 1.0f;
480 // if ((static_cast<int>(timeTotal / 2.0f) + 1) % 10 == 0)
482 // // Every 20 seconds, "explode" the gravity wells for 2 seconds.
483 // gravitySign = -1.0f;
485 // float2 delta = wellPositions[i] - particle->pos;
486 // float deltaLength = length(delta) + 24.0f;
487 // float deltaLengthCubed = deltaLength * deltaLength * deltaLength;
488 // particle->vel = particle->vel + gravitySign * 0.2f * SampleSettings::Physics::Gravity * timeDelta * delta / deltaLengthCubed;
491 // particle->vel = particle->vel * (1.0f - SampleSettings::Physics::Damping);
493 // // Add random noise to the velocity to prevent particles from locking together.
495 // particle->vel.x += RandFloat(-0.5f, 0.5f);
496 // particle->vel.y += RandFloat(-0.5f, 0.5f);
498 // particle->pos = particle->pos + particle->vel * timeDelta;
502 void GameMain::Render()
504 static int frame_count = 0;
506 m_d3dContext->OMSetRenderTargets(
508 backBufferRenderTargetView_.GetAddressOf(),
509 nullptr//backBufferDepthStencilView_.Get()
511 // m_d3dContext->OMSetDepthStencilState(backBufferDepthStencilState_.Get(),0);
512 m_d3dContext->RSSetViewports(1, &backBufferViewPort_);
513 //m_d3dContext->RSSetState(
516 m_d3dContext->ClearRenderTargetView(
517 backBufferRenderTargetView_.Get(),
518 reinterpret_cast<float*>(&D2D1::ColorF(D2D1::ColorF::Black))
521 //m_d3dContext->ClearDepthStencilView(backBufferDepthStencilView_.Get(),D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,1.0f,0);
524 spriteBatch_->Begin();
526 // Draw the background.
530 float4(160.0f, 120.0f,0.7f,1.0f),
531 PositionUnits::Pixels,
532 float2(64.0f, 64.0f),
534 float4(1.0f, 1.0f, 1.0f, 1.0f),
537 float2((float)((frame_count >> 3) % 4) * 64.0f,(float)((frame_count >> 3) / 4) * 64.0f)
542 float4(128.0f, 100.0f,0.7f,1.0f),
543 PositionUnits::Pixels,
544 float2(32.0f, 32.0f),
546 float4(1.0f, 1.0f, 1.0f, 1.0f),
549 float2((float)((frame_count >> 3) % 4) * 64.0f,(float)((frame_count >> 3) / 4) * 64.0f)
554 float4(128.0f, 50.0f,0.7f,1.0f),
555 PositionUnits::Pixels,
556 float2(96.0f, 96.0f),
558 float4(1.0f, 1.0f, 1.0f, 1.0f),
561 float2((float)((frame_count >> 3) % 4) * 64.0f,(float)((frame_count >> 3) / 4) * 64.0f)
564 frame_count = (frame_count + 1) & (0x7f);
566 //// Draw the non-interactive asteroids.
568 //for (auto asteroid = m_asteroidData.begin(); asteroid != m_asteroidData.end(); asteroid++)
570 // spriteBatch_->Draw(
573 // PositionUnits::DIPs,
574 // float2(1.0f, 1.0f) * asteroid->scale,
575 // SizeUnits::Normalized,
576 // float4(0.8f, 0.8f, 1.0f, 1.0f),
581 //// Draw the interactive particles.
583 //for (auto particle = m_particleData.begin(); particle != m_particleData.begin() + m_numParticlesToDraw; particle++)
585 // float alpha = length(particle->vel) / 200.0f;
586 // spriteBatch_->Draw(
589 // PositionUnits::DIPs,
590 // float2(32.0f, 32.0f),
592 // float4(0.1f, 0.02f, 0.0f, alpha),
594 // BlendMode::Additive
600 m_d3dContext->OMSetRenderTargets(
602 m_renderTargetView.GetAddressOf(),
603 nullptr/*m_depthStencilView.Get()*/
606 m_d3dContext->RSSetViewports(1, &swapChainViewPort_);
609 m_d3dContext->ClearRenderTargetView(
610 m_renderTargetView.Get(),
611 reinterpret_cast<float*>(&D2D1::ColorF(D2D1::ColorF::MidnightBlue))
614 //m_d3dContext->ClearDepthStencilView(m_depthStencilView.Get(),D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,1.0f,0);
616 spriteBatch_->Begin();
620 float4(m_window->Bounds.Width / 2.0f,m_window->Bounds.Height / 2.0f,0.0f,1.0f),
622 float2(1.0f, 1.0f) * scale_,
623 SizeUnits::Normalized,
624 float4(1.0f, 1.0f, 1.0f, 1.0f),
631 // Render the Sample Overlay.
632 sampleOverlay_->Render();
637 float GameMain::RandFloat(float min, float max)
639 return (static_cast<float>(rand() % RAND_MAX) / static_cast<float>(RAND_MAX)) * (max - min) + min;
642 //
\83T
\83E
\83\93\83h
\8dÄ
\90¶
\83X
\83\8c\83b
\83h
643 void GameMain::ExecuteSoundThread()
645 //sf::com_init comInit;
647 soundManager_->Sequencer().Play();
650 soundDriver_->Render();
651 // Concurrency::wait(800);
652 // soundDriver_->Update();
653 // soundDriver_->Render();
657 void GameMain::InitSound()
659 //
\8b\98\94g
\83e
\81[
\83u
\83\8b\82ð
\8dì
\82é
661 sf::Synthesizer::WaveTable sawtbl;
662 sawtbl.sampleRate = 440.0f;
663 sawtbl.basePitch = 0.0f;
664 sawtbl.stereo = false;
666 float v = -1.0f,d = 2.0f / 1024.0f;
667 for(int i = 0;i < 1024;++i)
669 // if(i < 15) v = -1.0f; else v = 1.0f;
670 sawtbl.waveData.push_back(v) ;
673 soundManager_->Synthesizer().WaveTables().push_back(std::move(sawtbl));
676 //
\8bé
\8c`
\94g
\83e
\81[
\83u
\83\8b\82ð
\8dì
\82é
678 sf::Synthesizer::WaveTable squaretbl;
679 squaretbl.sampleRate = 440.0f;
680 squaretbl.basePitch = 0.0f;
681 squaretbl.stereo = false;
684 for(int i = 0;i < 32;++i)
686 if(i < 15) v = -1.0f; else v = 1.0f;
687 squaretbl.waveData.push_back(v) ;
689 soundManager_->Synthesizer().WaveTables().push_back(std::move(squaretbl));
692 //
\8eO
\8ap
\94g
\83e
\81[
\83u
\83\8b
694 sf::Synthesizer::WaveTable tritbl;
695 tritbl.sampleRate = 440.0f;
696 tritbl.basePitch = 0.0f;
697 tritbl.stereo = false;
699 float v = -1.0f,d = 2.0f / 16.0f;
700 for(int i = 0;i < 32;++i)
703 tritbl.waveData.push_back(v) ;
706 soundManager_->Synthesizer().WaveTables().push_back(std::move(tritbl));
709 // sin
\83e
\81[
\83u
\83\8b
711 sf::Synthesizer::WaveTable sintbl;
712 sintbl.sampleRate = 440.0f;
713 sintbl.basePitch = 0.0f;
714 sintbl.stereo = false;
716 float v = 0.0f,d = 2.0f * M_PI / 128.0f;
717 for(int i = 0;i < 128;++i)
719 sintbl.waveData.push_back(sinf(v));
722 soundManager_->Synthesizer().WaveTables().push_back(std::move(sintbl));
725 // LFO
\97p Sin
\83e
\81[
\83u
\83\8b
727 sf::Synthesizer::WaveTable sintbl;
728 sintbl.sampleRate = 440.0f;
729 sintbl.basePitch = 0.0f;
730 sintbl.stereo = false;
732 float v = 0.0f,d = 2.0f * M_PI / 128.0f;
733 for(int i = 0;i < 128;++i)
735 sintbl.waveData.push_back(sinf(v) / 2.0f + 0.5f);
738 soundManager_->Synthesizer().WaveTables().push_back(std::move(sintbl));
744 // ::OutputDebugStringW((boost::wformat(L"waveTable size: %d") % osc_[0].WaveData().size()).str().c_str());
746 // timber
\82Ì
\83Z
\83b
\83g
\83A
\83b
\83v
747 for(int i = 0; i < 4;++i){
749 sf::Synthesizer::Timber timber;
750 timber.oscillator.reset(new sf::Synthesizer::WaveTableOscillator(&soundManager_->Synthesizer().WaveTables().at(0)));
751 timber.amplitude.gain = 1.0f;
752 timber.amplitude.envelope.releaseNoteOff = true;
753 timber.amplitude.envelope.attackTime = 0.01f;
754 timber.amplitude.envelope.decayTime = 0.02f;
755 timber.amplitude.envelope.sustainLevel = 0.5f;
756 timber.amplitude.envelope.releaseTime = 0.2f;
757 timber.amplitude.envelope.gain = 1.0f;
758 timber.amplitude.lfo.waveForm = &(soundManager_->Synthesizer().WaveTables()[4]);
759 timber.amplitude.lfo.freq = 5.0f;
760 timber.amplitude.lfo.gain = 0.0f;
762 timber.pitch.lfo.freq = 10.0f;
763 timber.pitch.lfo.gain = 0.000f;
764 timber.pitch.lfo.waveForm = &(soundManager_->Synthesizer().WaveTables()[4]);
765 timber.pitch.lfo.startNoteOn = true;
766 timber.pitch.envelope.attackTime = 0.0f;
767 timber.pitch.envelope.decayTime = 0.02f;
768 timber.pitch.envelope.sustainLevel = 0.5f;
769 timber.pitch.envelope.gain =0.0f;
770 timber.pitch.pitch = 0.0f;
772 timber.pan.lfo.freq = 2.0f;
773 timber.pan.lfo.gain = 1.0f;
774 timber.pan.lfo.waveForm = &(soundManager_->Synthesizer().WaveTables()[3]);
775 timber.pan.lfo.startNoteOn = true;
776 timber.pan.envelope.enable = false;
777 timber.pan.lfo.envelope.enable = false;
778 timber.pan.pan = 0.0f;
780 timber.filter.lfo.freq = 5.0f;
781 timber.filter.lfo.gain = 1.0f;
782 timber.filter.lfo.waveForm = &(soundManager_->Synthesizer().WaveTables()[3]);
783 timber.filter.lfo.startNoteOn = true;
784 timber.filter.cutoff = 10000.0f;
785 timber.filter.resonance = 0.0f;
786 timber.filter.envelope.attackTime = 0.01f;
787 timber.filter.envelope.decayTime = 0.03f;
788 timber.filter.envelope.sustainLevel = 0.05f;
789 timber.filter.envelope.releaseTime = 0.2f;
790 timber.filter.envelope.gain = 10000.0f;
792 soundManager_->Synthesizer().AddProgram(sf::Synthesizer::Program(std::move((boost::wformat(L"Program No.%d") % i).str()),std::move(timber)));
793 // timbers_.push_back(std::move(timber));
796 for(int i = 0,end = soundManager_->Synthesizer().Voices();i < end;++i)
798 soundManager_->Synthesizer().AssignProgramToVoice(0,i);
801 soundManager_->Synthesizer().isEnable(true);