Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unity_VolumeEffect

 Unity_VolumeEffect

Unityオーディオ完全に理解した勉強会での登壇資料です

Cova8bitdots

January 29, 2019
Tweet

More Decks by Cova8bitdots

Other Decks in Programming

Transcript

  1. Իྔͷجૅˍ
 ɹɹUNITY্ͰͷԻྔԋग़ UNITYΦʔσΟΦ׬શʹཧղͨ͠

  2. ͸͡Ίʹ ొஃऀ৘ใ Twitter: @8bitdots ήʔϜͱα΢ϯυେ޷͖UnityΤϯδχΞ
 ʢ≠α΢ϯυΤϯδχΞʣ

  3. Իྔͷجૅ Իྔʹ͍ͭͯ < ͜͜ͷSEͪΐͬͱ͏Δ͍͞Ͱ͢Ͷ ͦ͏ͨ͠ΒͱΓ͋͑ͣ3dB ఔԼ͛ͯ΋Β͑·͔͢ʁ> < (AudioSource.volume ͬͯ0.0~1.0 ͳΜ͚ͩͲͳ͊ɻ


    ԿݴͬͯΔΜͩʁ) Έ͍ͨͳ΍ΓͱΓͷܦݧ͸ͳ͍Ͱ͠ΐ͏͔ʁ
  4. Իྔͷجૅ Իྔʹ͍ͭͯ ▸ Իڹֶత؍఺ ▸ ʮԻྔʯͱ͍͏ݴ༿͸ͳ͘ʮԻѹʯʮԻͷڧ͞ʯʮԻڹύϫʔʯͳͲͷ
 ෺ཧྔΛఆٛ ▸ Իѹ p[Pa]

    ͷԻѹϨϕϧ(SoundPressureLevel) Lp [dB]
 
 
 
 p0 ɿج४Իѹ஋(1kHz ͷ࠷খՄௌԻ) = 2.0x10-5[Pa]
 ▸ σδλϧ৴߸ॲཧ
 [0.0 1.0] Ͱਖ਼نԽ͞Ε͍ͯΔͷͰͦͷର਺Λͱͬͯ͋͛Δ
 ˠ[-∞ 0.0] ʹม׵
  5. Իྔͷجૅ Իྔʹ͍ͭͯ ▸ Ұൠతʹਓؒͷײ֮ྔ͸
 ෺ཧྔͷର਺ʹ΄΅ൺྫɹɹɹɹɹɹɹ ▸ ਓؒͷײ֮ʹ߹ΘͤͨԻྔ
 ˠϥ΢υωε ౳ϥ΢υωεۂઢ(ISO226:2003)
 ʰԻڹֶೖ໳ʱΑΓҾ༻

    ʰԻڹֶೖ໳ʱΑΓҾ༻
  6. Իྔͷجૅ ϥ΢υωεͷݱ࣮ ▸ ςϨϏͳͲͷ์ૹۀք
 ຽ์࿈ɿhttps://j-ba.or.jp/category/t032
 ฏۉ: -24LKFS (Loudness K-weight Full

    Scale)Ͱ౷Ұ ▸ ήʔϜۀքͰ͸ ▸ ίϯγϡʔϚʔɿ2012೥ʹCEDECͰηογϣϯ͕͋ͬͨ΋ͷͷ…
 https://www.slideshare.net/IGDAJ_SigAudio/sigaudio1-cedec2012 ▸ ϞόΠϧɿTencent Ͱ͸େମ-16LKFS ఔ౓ʹἧ͑ͨͱͷ͜ͱ
 https://cedil.cesa.or.jp/cedil_sessions/view/1806 ▸ UnityͰ͸ ▸ AudioMixerʹVUϝʔλ͸͋Δ΋ͷͷ…
  7. Իྔͷجૅ ԻׂΕ ▸ ԻྔΛ্͛ΔͱԻׂΕ͢Δ
 ˠԻ͕Ճ޻͞Εͨײ͡ʹฉ͑͜Δ ▸ ݪҼɿ
 Mathf.Clamp( ೾ܗ, -1,

    1 ) ͕ߦΘΕΔͨΊ
  8. Իྔͷجૅ ԻׂΕ ▸ ݩ೾ܗ
 
 
 
 
 ▸ ԻׂΕ


    
 
 
 
 ݩ೾ܗΛ4ഒʹ૿෯
 ˠ೾ܗαΠζௐ੔
 ˠ0.5 Ҏ্,-0.5ҎԼ͕ਅͬฏΒʹ εϖΫτϥϜ εϖΫτϥϜ ೾ܗ ೾ܗ ԻׂΕ͕ى͖Δˠۣܗ೾Έ͍ͨʹ೾ܗ͕มԽ͍ͯ͠Δ
  9. Իྔͷجૅ ԻׂΕ ԻׂΕͰ೾ܗ͕ۣܗ೾ͬΆ͘ͳͬͨ
 ˠۣܗ೾ʹ͍ͭͯߟ͑ͯΈΔ ▸ ϑʔϦΤڃ਺ల։ ▸ ͬ͘͟Γͱͨ͠આ໌ɿ
 पظؔ਺Λsinͱcos ͦΕͧΕͷഒԻΛͲΜͲΜ଍͠߹Θͤͯۙࣅ͢Δදݱ


    ▸ ஸೡͳઆ໌ɿ
 पظTͷؔ਺f(t) Λۮؔ਺ͱحؔ਺ͷ࿨Ͱදݱ εϖΫτϥϜ εϖΫτϥϜ ೾ܗ
  10. Իྔͷجૅ ೾ܗͱϑʔϦΤڃ਺ల։ ▸ ۣܗ೾ΛϑʔϦΤڃ਺ల։Λ࢖ͬͯදݱͯ͠ΈΔ
 حؔ਺ͳͷͰۮؔ਺੒෼(an )͸શͯ0
 
 حؔ਺੒෼

  11. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(t) ͷΈ

  12. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(3t) ·Ͱͷ࿨

  13. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(5t) ·Ͱͷ࿨

  14. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(11t) ·Ͱͷ࿨

  15. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(21t) ·Ͱͷ࿨

  16. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(41t) ·Ͱͷ࿨ ͍ͩͿۣܗ೾ʹ͍ۙͮͯ͸͍Δ΋ͷͷ
 ೾͕·ͩݟ͑Δ

  17. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(101t) ·Ͱͷ࿨ ୺఺͸·ͩߥͿ͍ͬͯΔ͕
 தԝ෇ۙ͸͍ͩͿ೾͕ࡉ͔͘ͳ͖͍ͬͯͯΔ

  18. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ Sin(201t) ·Ͱͷ࿨ ͔ͳΓݟͨ໨΋ۣܗ೾ͬΆ͘ͳ͖͍ͬͯͯΔ

  19. Իྔͷجૅ ۣܗ೾ΛϑʔϦΤڃ਺ల։Ͱදݱ ۣܗ೾Λࡾ֯ؔ਺Ͱදݱ͢Δʹ͸ߴ࣍ഒԻͷॏͶ߹Θ͕ͤඞཁ
 https://github.com/Cova8bitdots/FourieSample

  20. Իྔͷجૅ ԻׂΕʢ·ͱΊʣ ▸ ۣܗ೾ɿSin೾ͷߴ࣍ഒԻ·ͰͷॏͶ߹ΘͤͰදݱ ▸ ԻׂΕঢ়ଶˠ೾ܗ͕ۣܗ೾νοΫʹՃ޻͞ΕΔ
 ɹɹɹɹɹˠߴ࣍ഒԻ͕উखʹ଍͞Εͯ͠·͏
 ɹɹɹɹɹˠԻ৭͕มΘΔ ▸ ԻΛॏͶͯ໐Β࣌͢͸ؾΛ͚ͭΑ͏

  21. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ • ϑΟϧλ/ΤϑΣΫτʹΑΔ੍ޚ • ScriptʹΑΔ੍ޚ

  22. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ • ϑΟϧλ/ΤϑΣΫτʹΑΔ੍ޚ • ScriptʹΑΔ੍ޚ

  23. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ ▸ UnityͰ࢖༻ՄೳͳϑΟϧλ ▸ LowPassFilter
 ߴԻҬΛΧοτɻ
 ήʔϜͷϙʔζதͳͲʹ࢖༻͞ΕΔ͜ͱ͕ଟ͍ ▸

    HighPassFilter
 ௿ԻҬΛΧοτɻ
 LPFͱ૊Έ߹ΘͤͯBandPassFilterͱͯ͠ར༻΋
 BPFͳΒதҬͷΈ௨աͰϥδΦͬΆ͍ԋग़΋ [༻ޠઆ໌] ΧοτΦϑप೾਺fc ɿ ύϫʔ͕6dB ௿Լ͢Δ఺ͷप೾਺ Q஋:
 
 
 ɹQ஋͕ߴ͍ͱϑϥοτͳ෦෼͕ଟ͍
 ɹ௿͍ͱ࠷ॳ͔ΒΏͬͨΓͱ௿Լ͢Δ(LPF) ڞৼप೾਺ όϯυ෯ ʰԻڹֶೖ໳ʱΑΓҾ༻
  24. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ ▸ AudioMixerΛ࢖ͬͯͷදݱ ▸ LowPassEffect
 ▸ HighPassEffect
 ▸

    FadeIn/FadeOut
 SnapShotͷ੾Γସ͑ʹΑΓࣗಈͰϑΣʔυ͕͔͔Δ ▸ μοΩϯά
 ϘΫγϯάͷ͔͕Ήಈ࡞͔Βདྷ͍ͯΔ༻ޠ
 ଞͷԻ͕໐Δͱ͖ʹࣗ਎ʢେ఍͸BGMʣͷԻྔΛԼ͛໐ΓऴΘΔͱಉ࣌ʹԻྔΛݩʹ໭͢ԋग़
 ▸ αΠυνΣʔϯೖྗʹΑΔμοΩϯά
 ଞͷԻ(ϕʔεԻ, υϥϜͷΩοΫԻͳͲ)ͷେ͖͞ʹ࿈ಈͯ͠ಈతʹԻྔΛมԽͤ͞Δํ๏

  25. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ • ϑΟϧλʹΑΔ੍ޚ • ScriptʹΑΔ੍ޚ

  26. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ ▸ ScriptʹΑΔ੍ޚ ▸ FadeIn/FadeOut →ίϧʔνϯ ͳΓͰ࣮૷Մೳ ▸

    μοΩϯά ▸ Πϯτϩ෇BGM࠶ੜ ▸ ΠϯλϥΫςΟϒϛϡʔδοΫ
  27. UNITY ্ͰͷԻྔԋग़ ϑΣʔυ࣮૷ͷςΫχοΫ ▸ Scriptࣗମ͸ඇৗʹ୯७ FadeIn/Out ͦΕͧΕಉ͡ίʔυͰදݱՄೳʢStartͱEndͷઃఆ࣍ୈʣ

  28. UNITY ্ͰͷԻྔԋग़ ϑΣʔυ࣮૷ͷςΫχοΫ ▸ ΫϩεϑΣʔυͷ஫ҙ఺ ▸ ϑΣʔυΧʔϒ͕௚ઢͩͱશମͷԻྔ͕Լ͕Δॠ͕ؒੜ·ΕΔ ▸ 
 ▸

    ղܾखஈͱͯ͠͸ɺϑΣʔυΧʔϒͱͯ͠ࡾ֯ؔ਺Λ༻͍Δ
  29. UNITY ্ͰͷԻྔԋग़ ϑΣʔυ࣮૷ͷςΫχοΫ ▸ ͬ͘͟Γͱͨ͠આ໌ ▸ ೾ͷΤωϧΪʔ͸ઈର஋ͷ2৐ ▸ A(t), B(t)

    ʹ t, 1-t Λ୅ೖ ▸ ৴߸S1 (t), S2 (t) ͷΤωϧΪʔΛҰఆͱԾఆ
 
 
 ▸ 2৐ͨ͠ͱ͖ʹҰఆˠsin2+cos2 ▸ ࡾ֯ؔ਺ͰϑΣʔυΧʔϒΛදݱͯ͋͛͠Ε͹͍͍ ▸ ৄࡉɿhttps://speakerdeck.com/cova8bitdots/unitydeintarakuteibumiyuzitukuyatutemita
  30. UNITY ্ͰͷԻྔԋग़ Իྔʹؔ͢Δԋग़ྫ ▸ ScriptʹΑΔ੍ޚ ▸ FadeIn/FadeOut →ίϧʔνϯ ͳΓͰ࣮૷Մೳ ▸

    μοΩϯά
 ԻݯBΛ࠶ੜ͢ΔલʹԻݯAΛFadeͰԻྔམͱ͢ˠԻݯB࠶ੜޙʹԻݯAΛFadeͰݩͷԻྔ΁
 ▸ Πϯτϩ෇BGM࠶ੜ
 ΠϯτϩͷԻݯͷऴΘΓ͔͚ͱϧʔϓ෦෼ΛΫϩεϑΣʔυͰಉظͤͯ͞࠶ੜ
 ▸ ΠϯλϥΫςΟϒϛϡʔδοΫ ▸ ݱࡏͷBGMͷϏʔτʹ߹ΘͤͯΫϩεϑΣʔυΛελʔτͤͯ͋͛͞Δ ▸ ݱࡏͷBGMͷ࠶ੜҐஔΛಉظͯ͠ΫϩεϑΣʔυΛߦ͏
  31. ಺༰ͷ૯෮श ·ͱΊ ▸ Իྔʹ͍ͭͯ ▸ ର਺Λͱͬͯදݱ[dB] ▸ ײ֮ྔʹΑΓͦ͏ͳΒϥ΢υωε
 ▸ ԻׂΕ

    ▸ ԻׂΕ͢ΔͱԻ͕࿪Ή ▸ ഒԻ੒෼ʹΑͬͯԻ৭͕มΘΔ ▸ α΢ϯυԋग़ ▸ FadeΛ੍͢Ε͹৭ʑग़དྷΔ ▸ μοΩϯά ▸ Πϯτϩ෇BGM࠶ੜ ▸ ΠϯλϥΫςΟϒϛϡʔδοΫ
  32. ͓ΘΓʹ એ఻ ▸ ϛυϧ΢ΣΞʹཔΒͳ͍ͰؤுΔα΢ϯυΤϯδϯӶҙ੡࡞த ▸ https://github.com/UnityLibrary/UniSound
 ▸ ػೳ ▸ Πϯτϩ෇͖BGM࠶ੜ

    ▸ FadeIn/FadeOut/ CrossFade ▸ ΠϕϯτͷϏʔτಉظ ▸ Մมςϯϙ৘ใઃఆ ▸ ಉ࣌ൃԻ੍ޚ ▸ ൃԻ਺੍໿ ▸ ൃԻͷΠϯλʔόϧ੍໿ ▸ ઌண/ޙண༏ઌઃఆ ▸ etc.