Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <windows.h>
- #include <iostream>
- #include "inc\fmod.hpp"
- #include "inc\fmod.h"
- #include "inc\fmod_errors.h"
- #pragma comment(lib, "fmodex_vc.lib")
- void ERRCHECK(FMOD_RESULT result)
- {
- if (result != FMOD_OK)
- {
- printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
- exit(-1);
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- // Создаём главный системный объект
- FMOD::System *system = nullptr;
- FMOD_RESULT result = FMOD::System_Create(&system);
- ERRCHECK(result);
- result = system->init(16, FMOD_INIT_NORMAL, 0);
- ERRCHECK(result);
- FMOD::Sound *sound = nullptr; // Звук
- result = system->createStream("Кино - Кончится лето.mp3", FMOD_3D | FMOD_LOOP_OFF, 0, &sound); // Создаём звук с параметрами 3D звучания без зацикливания
- ERRCHECK(result);
- std::cout << "Playing at 10% volume" << '\n';
- // --------------------- Начинаем проигрывание
- FMOD::Channel *channel = nullptr; // Звуковой канал
- result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel); // Проигрываем звук (направляем его в канал)
- channel->setVolume(0.1f);
- // --------------------- Меняем громкость
- for (int i = 2; i <= 10; i++)
- {
- _getch();
- channel->setVolume(0.1f * i);
- std::cout << "Volume increased to " << i << "0%" << '\n';
- }
- std::cout << "\n";
- for (int i = 9; i >= 3; i--)
- {
- _getch();
- channel->setVolume(0.1f * i);
- std::cout << "Volume decreased to " << i << "0%" << '\n';
- }
- // --------------------- Пауза/проигрывание
- std::cout << "\nPress any key to pause...\n";
- _getch();
- channel->setPaused(true);
- ERRCHECK(result);
- std::cout << "\nPress any key to unpause...\n";
- _getch();
- channel->setPaused(false);
- // --------------------- Проигрывание с 3D эффектом
- std::cout << "\nPress any key to enable 3D...\n";
- _getch();
- channel->setVolume(10);
- // Назначаем минимальное и максимальное слышимое расстояние источника звука
- result = sound->set3DMinMaxDistance(1.0f, 100.0f);
- result = system->update();
- // Настраиваем параметры слушателя
- result = system->set3DListenerAttributes(0, new FMOD_VECTOR{ -10.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 1.0f, 1.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 1.0f });
- ERRCHECK(result);
- result = system->update();
- for (int c = 0; c < 2; c++) {
- int i = 0;
- for (; i < 20; i++) {
- Sleep(200);
- result = channel->set3DAttributes(new FMOD_VECTOR{ 1.0f * -i, 0.0f, -5.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f });
- ERRCHECK(result);
- result = system->update();
- }
- for (; i > 0; i--) {
- Sleep(200);
- result = channel->set3DAttributes(new FMOD_VECTOR{ 1.0f * -i, 0.0f, -5.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f });
- ERRCHECK(result);
- result = system->update();
- }
- Sleep(1000);
- }
- result = system->set3DListenerAttributes(0, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 1.0f, 1.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 1.0f });
- ERRCHECK(result);
- result = system->update();
- // --------------------- Проигрываем в одном ухе
- std::cout << "\nPress any key to play music in right ear only...\n";
- _getch();
- result = system->set3DListenerAttributes(0, new FMOD_VECTOR{ 20.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 1.0f, 1.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 1.0f });
- ERRCHECK(result);
- result = system->update();
- std::cout << "\nPress any key to play music in left ear only...\n";
- _getch();
- result = system->set3DListenerAttributes(0, new FMOD_VECTOR{ -20.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 1.0f, 1.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 1.0f });
- ERRCHECK(result);
- result = system->update();
- // --------------------- Добавляем эффект Допплера путём увеличения скорости источника
- std::cout << "\nPress any key to begin changing velocity...\n";
- _getch();
- result = channel->set3DSpread(180);
- ERRCHECK(result);
- result = system->update();
- result = channel->set3DAttributes(new FMOD_VECTOR{ -2.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 100.0f, 0.0f, 0.0f });
- ERRCHECK(result);
- result = system->update();
- std::cout << "\nVelocity is set to -100%...\n";
- for (int i = 9; i >= -10; i--)
- {
- _getch();
- result = channel->set3DAttributes(new FMOD_VECTOR{ -2.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 10.0f * i, 0.0f, 0.0f });
- ERRCHECK(result);
- result = system->update();
- std::cout << "Velocity increased to " << -i << "0%\n";
- }
- std::cout << "\nPress any key to return velocity to normal...\n";
- _getch();
- result = channel->set3DAttributes(new FMOD_VECTOR{ -2.0f, 0.0f, 0.0f }, new FMOD_VECTOR{ 0.0f, 0.0f, 0.0f });
- ERRCHECK(result);
- result = system->update();
- std::cout << "\nPress any key to stop playing...";
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement