Project1

标题: 有没有办法在Ruby上使用fmod呢 [打印本页]

作者: 你欠抽吧    时间: 2016-7-16 19:55
标题: 有没有办法在Ruby上使用fmod呢
本帖最后由 你欠抽吧 于 2016-7-17 20:03 编辑

官方提供的api仅限于C/C++/C#


===============================

这个win32api用得我一脸懵逼
官方的范例工程比较复杂,貌似仅靠win32api搞不定

CPP 代码复制下载
  1. /*===============================================================================================
  2.  PlaySound Example
  3.  Copyright (c), Firelight Technologies Pty, Ltd 2004-2016.
  4.  
  5.  This example shows how to simply load and play multiple sounds.  This is about the simplest
  6.  use of FMOD.
  7.  This makes FMOD decode the into memory when it loads.  If the sounds are big and possibly take
  8.  up a lot of ram, then it would be better to use the FMOD_CREATESTREAM flag so that it is
  9.  streamed in realtime as it plays.
  10. ===============================================================================================*/
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <conio.h>
  14.  
  15. #include "../../api/inc/fmod.hpp"
  16. #include "../../api/inc/fmod_errors.h"
  17.  
  18. void ERRCHECK(FMOD_RESULT result)
  19. {
  20.     if (result != FMOD_OK)
  21.     {
  22.         printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
  23.         exit(-1);
  24.     }
  25. }
  26.  
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.     FMOD::System     *system;
  31.     FMOD::Sound      *sound1, *sound2, *sound3;
  32.     FMOD::Channel    *channel = 0;
  33.     FMOD_RESULT       result;
  34.     int               key;
  35.     unsigned int      version;
  36.  
  37.     /*
  38.         Create a System object and initialize.
  39.     */
  40.     result = FMOD::System_Create(&system);
  41.     ERRCHECK(result);
  42.  
  43.     result = system->getVersion(&version);
  44.     ERRCHECK(result);
  45.  
  46.     if (version < FMOD_VERSION)
  47.     {
  48.         printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
  49.         return 0;
  50.     }
  51.  
  52.     result = system->init(32, FMOD_INIT_NORMAL, 0);
  53.     ERRCHECK(result);
  54.  
  55.     result = system->createSound("../media/drumloop.wav", FMOD_HARDWARE, 0, &sound1);
  56.     ERRCHECK(result);
  57.  
  58.     result = sound1->setMode(FMOD_LOOP_OFF);    /* drumloop.wav has embedded loop points which automatically makes looping turn on, */
  59.     ERRCHECK(result);                           /* so turn it off here.  We could have also just put FMOD_LOOP_OFF in the above CreateSound call. */
  60.  
  61.     result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2);
  62.     ERRCHECK(result);
  63.  
  64.     result = system->createSound("../media/swish.wav", FMOD_HARDWARE, 0, &sound3);
  65.     ERRCHECK(result);
  66.  
  67.     printf("===================================================================\n");
  68.     printf("PlaySound Example.  Copyright (c) Firelight Technologies 2004-2016.\n");
  69.     printf("===================================================================\n");
  70.     printf("\n");
  71.     printf("Press '1' to play a mono sound using hardware mixing\n");
  72.     printf("Press '2' to play a mono sound using software mixing\n");
  73.     printf("Press '3' to play a stereo sound using hardware mixing\n");
  74.     printf("Press 'Esc' to quit\n");
  75.     printf("\n");
  76.  
  77.     /*
  78.         Main loop.
  79.     */
  80.     do
  81.     {
  82.         if (_kbhit())
  83.         {
  84.             key = _getch();
  85.  
  86.             switch (key)
  87.             {
  88.                 case '1' :
  89.                 {
  90.                     result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
  91.                     ERRCHECK(result);
  92.                     break;
  93.                 }
  94.                 case '2' :
  95.                 {
  96.                     result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
  97.                     ERRCHECK(result);
  98.                     break;
  99.                 }
  100.                 case '3' :
  101.                 {
  102.                     result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel);
  103.                     ERRCHECK(result);
  104.                     break;
  105.                 }
  106.             }
  107.         }
  108.  
  109.         system->update();
  110.  
  111.         {
  112.             unsigned int ms = 0;
  113.             unsigned int lenms = 0;
  114.             bool         playing = 0;
  115.             bool         paused = 0;
  116.             int          channelsplaying = 0;
  117.  
  118.             if (channel)
  119.             {
  120.                 FMOD::Sound *currentsound = 0;
  121.  
  122.                 result = channel->isPlaying(&playing);
  123.                 if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
  124.                 {
  125.                     ERRCHECK(result);
  126.                 }
  127.  
  128.                 result = channel->getPaused(&paused);
  129.                 if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
  130.                 {
  131.                     ERRCHECK(result);
  132.                 }
  133.  
  134.                 result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
  135.                 if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
  136.                 {
  137.                     ERRCHECK(result);
  138.                 }
  139.  
  140.                 channel->getCurrentSound(&currentsound);
  141.                 if (currentsound)
  142.                 {
  143.                     result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
  144.                     if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
  145.                     {
  146.                         ERRCHECK(result);
  147.                     }
  148.                 }
  149.             }
  150.  
  151.             system->getChannelsPlaying(&channelsplaying);
  152.  
  153.             printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
  154.         }
  155.  
  156.         Sleep(10);
  157.  
  158.     } while (key != 27);
  159.  
  160.     printf("\n");
  161.  
  162.     /*
  163.         Shut down
  164.     */
  165.     result = sound1->release();
  166.     ERRCHECK(result);
  167.     result = sound2->release();
  168.     ERRCHECK(result);
  169.     result = sound3->release();
  170.     ERRCHECK(result);
  171.     result = system->close();
  172.     ERRCHECK(result);
  173.     result = system->release();
  174.     ERRCHECK(result);
  175.  
  176.     return 0;
  177. }

作者: 喵呜喵5    时间: 2016-7-16 23:51
编译成 dll ,然后在Ruby 里 Win32API.new ?(我乱说的,并且我不会

作者: 你欠抽吧    时间: 2016-7-17 01:04
喵呜喵5 发表于 2016-7-16 23:51
编译成 dll ,然后在Ruby 里 Win32API.new ?(我乱说的,并且我不会

哦api提供了dll的= =
看来可以




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1