设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1545|回复: 2
打印 上一主题 下一主题

[讨论] 有没有办法在Ruby上使用fmod呢

[复制链接]

Lv1.梦旅人

梦石
0
星屑
75
在线时间
241 小时
注册时间
2013-3-28
帖子
67
跳转到指定楼层
1
发表于 2016-7-16 19:55:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 你欠抽吧 于 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. }

Lv5.捕梦者 (暗夜天使)

只有笨蛋才会看到

梦石
1
星屑
20945
在线时间
9332 小时
注册时间
2012-6-19
帖子
7106

开拓者短篇九导演组冠军

2
发表于 2016-7-16 23:51:28 | 只看该作者
编译成 dll ,然后在Ruby 里 Win32API.new ?(我乱说的,并且我不会
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
75
在线时间
241 小时
注册时间
2013-3-28
帖子
67
3
 楼主| 发表于 2016-7-17 01:04:57 | 只看该作者
喵呜喵5 发表于 2016-7-16 23:51
编译成 dll ,然后在Ruby 里 Win32API.new ?(我乱说的,并且我不会

哦api提供了dll的= =
看来可以
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 05:13

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表