LoginSignup
0

More than 1 year has passed since last update.

posted at

updated at

OpenSiv3Dを使ってサウンドビジュアライズ

OpenSiv3Dを使ってサウンドビジュアライザーの開発

この記事はSiv3D Advent Calendar 2020 24日めの記事です。

OpenSiv3Dを使ってサウンドビジュアライズをしました。
ソースコード(Github)

動画
ColorFull Snow

Code

Sound.cpp

#include "Sound.h"
const int SnowMax = 300;

Sound::Sound(Audio init_audio) {
    audio_data = init_audio;
}

void Sound::audioPlay()
{

    //デフォルトでは1.0
    double volume = 1.0;

    double speed = 1.0;

    audio_data.setLoop(true);

    if (audio_data.isLoop() == true) {

        std::vector<SnowParticle> snow_data;
        for (int count = 0; count < SnowMax; count++) {
            SnowParticle data;
            snow_data.push_back(data);
        }

        while (System::Update())
        {   

            //playボタンの追加
            if (SimpleGUI::Button(U"Play", Vec2(20, 200), 100)) {
                audio_data.play();
            }

            //pauseボタンの追加
            if (SimpleGUI::Button(U"Pause", Vec2(120, 200), 100)) {
                audio_data.pause();
            }

            //stopボタンの追加
            if (SimpleGUI::Button(U"Stop", Vec2(220, 200), 100)) {
                audio_data.stop();

            }

            //音量のボリュームを変える
            if (SimpleGUI::Slider(volume, Vec2(330, 200))) {
                audio_data.setVolume(volume);
            }

            //再生スピードを変える
            if (SimpleGUI::Slider(U"{:.2f}"_fmt(speed), speed, 0.1, 2.0, Vec2(460, 200))) {
                audio_data.setSpeed(speed);
            }

            //再生位置の変更  .setPosSample() or .setPosSec()
            //再生位置の変更 0に設定
            if (SimpleGUI::Button(U"再生位置を0に変更", Vec2(20, 300))) {
                audio_data.setPosSample(0);
            }



            for (auto count : step(SnowMax)) {
                snow_data[count].snow_render(abs(sin(audio_data.posSec())), abs(cos(audio_data.posSec())), volume, 1.0);
                snow_data[count].snow_step();
            }

        }


    }
}

Sound.h

#pragma once
#include <Siv3D.hpp> 
#include "SnowParticle.h"
class Sound
{
private:
    Audio audio_data;
public:
    Sound(Audio init_audio);
    void audioPlay();

};

まとめ

全体としてあまり出来が良いとは言えないと思います。問題点を適時改良していきたいと思います:blush:

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0