Merge branch 'master' of https://github.com/cocos2d/cocos2d-x into linux_port1

This commit is contained in:
laschweinski 2011-10-22 19:27:35 +08:00
commit 5589335d3a
329 changed files with 4397 additions and 18305 deletions

3
.gitignore vendored
View File

@ -37,6 +37,9 @@ assets/
.project
.cproject
# Ignore files build by linux
*.o
# Ignore files build by airplay
build_*_xcode/

24
AUTHORS
View File

@ -3,13 +3,30 @@ cocos2d-x authors
(ordered by the join in time)
Core Developers:
Walzer Wang
Minggo Zhang
Zhe Wang (Walzer)
XiaoMing Zhang (Minggo)
WenSheng Yang
Bin Zhang
RongHong Huang
JianHua Chen (Dumganhar)
Developers:
HuaXu Cai (laschweinski)
author of linux port
ciaranj
add a build file that correctly generates LuaCocos2d.cpp
add a lua template
add particle systems to lua bindings
use ant to generate LuaCocos2d.cpp and lua projects
Marat Yakupov (moadib)
add ability of simulating android enter/resume background on win32
add ability of simulating android back/menu key on win32
reflog
add a helper method to draw filled polygons
ZhuoShi Shun
contribute the lua binding of CocosDenshion
@ -28,9 +45,10 @@ Developers:
Carlos Sessa
implement the accelerometer module onto Android
Dumganhar
JianHua Chen (Dumganhar)
author of Bada port
Cocos2d-x can not grow so fast without the active community.
Thanks to all developers who report & trace bugs, dicuss the engine usage in forum & QQ groups!
Special thanks to Ricardo Quesada for giving us lots of guidances & suggestions.

View File

@ -926,6 +926,9 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
m_debugDraw->DrawSolidPolygon(vertices, vertexCount, color);
}
break;
default:
break;
}
}

View File

@ -5,6 +5,9 @@
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.config.gnu.lib.debug.1073463358">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.lib.debug.1073463358" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<macros>
<stringMacro name="cocos2dx_loc" type="VALUE_TEXT" value="../../.."/>
</macros>
<externalSettings>
<externalSetting>
<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/libBox2D"/>
@ -30,6 +33,9 @@
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.lib.debug.1715832133" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.lib.debug">
<option id="gnu.cpp.compiler.lib.debug.option.optimization.level.1279009838" name="Optimization Level" superClass="gnu.cpp.compiler.lib.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.lib.debug.option.debugging.level.1137403177" name="Debug Level" superClass="gnu.cpp.compiler.lib.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1388652374" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="${cocos2dx_loc}"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1768946738" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.lib.debug.1183450462" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.lib.debug">
@ -38,6 +44,9 @@
<option id="gnu.c.compiler.option.preprocessor.def.symbols.638003594" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="LINUX"/>
</option>
<option id="gnu.c.compiler.option.include.paths.29808765" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="${cocos2dx_loc}"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1136434176" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1824882157" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
@ -50,6 +59,7 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.lib.release.1696709029">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.lib.release.1696709029" moduleId="org.eclipse.cdt.core.settings" name="Release">
@ -78,6 +88,9 @@
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.lib.release.580850844" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.lib.release">
<option id="gnu.cpp.compiler.lib.release.option.optimization.level.401070766" name="Optimization Level" superClass="gnu.cpp.compiler.lib.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.lib.release.option.debugging.level.1515853804" name="Debug Level" superClass="gnu.cpp.compiler.lib.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.315343143" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="../../.."/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.811835144" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.lib.release.1831021578" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.lib.release">
@ -86,6 +99,9 @@
<option id="gnu.c.compiler.option.preprocessor.def.symbols.514457469" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="LINUX"/>
</option>
<option id="gnu.c.compiler.option.include.paths.1198096657" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="../../.."/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.624842426" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1478061636" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
@ -98,6 +114,140 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.lib.debug.1073463358.641376812">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.lib.debug.1073463358.641376812" moduleId="org.eclipse.cdt.core.settings" name="AndroidDebug">
<macros>
<stringMacro name="cocos2dx_loc" type="VALUE_TEXT" value="../../.."/>
</macros>
<externalSettings>
<externalSetting>
<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/libBox2D"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libBox2D/Debug"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libBox2D/AndroidDebug"/>
<entry flags="RESOLVED" kind="libraryFile" name="box2d"/>
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="so" artifactName="box2d" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.lib.debug.1073463358.641376812" name="AndroidDebug" parent="cdt.managedbuild.config.gnu.lib.debug">
<folderInfo id="cdt.managedbuild.config.gnu.lib.debug.1073463358.641376812." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.lib.debug.1024983557" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.lib.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.lib.debug.1333683445" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.lib.debug"/>
<builder buildPath="${workspace_loc:/libBox2D/Debug}" id="cdt.managedbuild.target.gnu.builder.lib.debug.261427228" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.lib.debug"/>
<tool command="ar" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.archiver.lib.debug.283269200" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.lib.debug"/>
<tool command="arm-linux-androideabi-g++" id="cdt.managedbuild.tool.gnu.cpp.compiler.lib.debug.1668352314" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.lib.debug">
<option id="gnu.cpp.compiler.lib.debug.option.optimization.level.580003835" name="Optimization Level" superClass="gnu.cpp.compiler.lib.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.lib.debug.option.debugging.level.855585604" name="Debug Level" superClass="gnu.cpp.compiler.lib.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1142759011" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="${cocos2dx_loc}"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.548864496" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool command="arm-linux-androideabi-gcc" id="cdt.managedbuild.tool.gnu.c.compiler.lib.debug.1142359846" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.lib.debug">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.lib.debug.option.optimization.level.1452717285" name="Optimization Level" superClass="gnu.c.compiler.lib.debug.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.lib.debug.option.debugging.level.306675075" name="Debug Level" superClass="gnu.c.compiler.lib.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.1388759160" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="LINUX"/>
</option>
<option id="gnu.c.compiler.option.include.paths.353564209" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="${cocos2dx_loc}"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1809004285" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.384024277" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base">
<option defaultValue="true" id="gnu.c.link.option.shared.393965362" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
</tool>
<tool command="arm-linux-androideabi-g++" id="cdt.managedbuild.tool.gnu.cpp.linker.base.722562264" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<option defaultValue="true" id="gnu.cpp.link.option.shared.192282494" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1175254266" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.lib.debug.1596429560" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.lib.debug">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1043944519" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.lib.release.1696709029.1026841372">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.lib.release.1696709029.1026841372" moduleId="org.eclipse.cdt.core.settings" name="AndroidRelease">
<externalSettings>
<externalSetting>
<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/libBox2D"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libBox2D/Release"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libBox2D/AndroidRelease"/>
<entry flags="RESOLVED" kind="libraryFile" name="bos2d"/>
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="so" artifactName="bos2d" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.lib.release.1696709029.1026841372" name="AndroidRelease" parent="cdt.managedbuild.config.gnu.lib.release">
<folderInfo id="cdt.managedbuild.config.gnu.lib.release.1696709029.1026841372." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.lib.release.211833502" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.lib.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.lib.release.1572331042" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.lib.release"/>
<builder buildPath="${workspace_loc:/libBox2D/Release}" id="cdt.managedbuild.target.gnu.builder.lib.release.865861653" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.lib.release"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.lib.release.167980001" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.lib.release"/>
<tool command="arm-linux-androideabi-g++" id="cdt.managedbuild.tool.gnu.cpp.compiler.lib.release.163158835" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.lib.release">
<option id="gnu.cpp.compiler.lib.release.option.optimization.level.1801923322" name="Optimization Level" superClass="gnu.cpp.compiler.lib.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.lib.release.option.debugging.level.1656716619" name="Debug Level" superClass="gnu.cpp.compiler.lib.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1700037376" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="../../.."/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1464808170" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool command="arm-linux-androideabi-gcc" id="cdt.managedbuild.tool.gnu.c.compiler.lib.release.485899141" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.lib.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.lib.release.option.optimization.level.1038296098" name="Optimization Level" superClass="gnu.c.compiler.lib.release.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.lib.release.option.debugging.level.187067668" name="Debug Level" superClass="gnu.c.compiler.lib.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.157754591" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="LINUX"/>
</option>
<option id="gnu.c.compiler.option.include.paths.461957057" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="../../.."/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1782492850" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.434986368" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base">
<option defaultValue="true" id="gnu.c.link.option.shared.1799562846" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
</tool>
<tool command="arm-linux-androideabi-g++" id="cdt.managedbuild.tool.gnu.cpp.linker.base.63275203" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<option defaultValue="true" id="gnu.cpp.link.option.shared.371676063" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.156686569" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.lib.release.1122871727" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.lib.release">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1098079290" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">

View File

@ -1,7 +1,7 @@
CC = gcc
CXX = g++
AR = ar
TARGET = libBox2D.a
TARGET = libbox2d.a
CCFLAGS = -Wall -g -O2
CXXFLAGS = -Wall -g -O2
ARFLAGS = cr

View File

@ -1,3 +1,63 @@
cocos2d-1.0.1-x-0.9.2 @ Oct.20,2011
[linux]
Feature #728 Linux port is born! http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_run_HelloWorld_and_tests_on_linux
[all platforms]
Feature #672 Implements copyWithZone() for CCShow & CCHide
Feature #676 add more languages into CCApplication::getCurrentLanguage()
Feature #678 add private constructor for CCArray
Feature #684 add test case for CCApplication::getCurrentLanguage()
Feature #685 add test case in LabelTest to display Chinese charactors
Bug #675 Fix memory leak in CCLayer when using accelerometer
Bug #686 CCTMXLayer::appendTileForGID() not setting Z index tag causes the first screen of tiles to be re-created
Bug #689 CCRect should assert the width and height is positive
Bug #698 CCSprite::init() is excited twice in all CCSprite's static methods
Bug #700 CC_SWAP32 marco has a typo with leads to error swap result
Bug #701 CCZHeader.version should be unsigned short
Bug #715 CCFadeOut causes a crash when applied to CCMenuItem and m_pSelectedImage is NULL
Bug #718 fix a typo in method CCMenu::alignItemsInRows
Bug #749 CCSpriteTest crashes at the test case SpriteNilTexture
Bug #750 CCTextureCache::textureForKey() can't find textures added by function addUIImage()
Refactor #677 Pass arguments by reference instead of pointer if possible
Refactor #703 Refactor Accelerometer. Because it only sends data to one delegate, so it needs only one setDelegate()
Document #692 Describe the usage of view orientation http://www.cocos2d-x.org/projects/cocos2d-x/wiki/About_device_orientation
[android]
Feature #670 Pause & resume effect playing when activity is paused & resumed
Feature #687 Implement preloadBackgroundMusic to android
Feature #688 Support reading resources not only from apk
Feature #726 use external storage on android
Feature #746 add a helper method to draw filled polygons
Bug #683 getPackagenameJNI() and getCurrentLanguageJNI() mustn't return invalid pointer
Bug #696 Some android devices may crash at CCRenderTexture::end(bool)
Bug #719 CocosDenshionTest crashes when start the test case on android
Bug #714 CCLabelTTF has different visual result between Android & Windows
Bug #727 Memory leak of NewStringUTF
Bug #736 Remove android:installLocation in AndroidManifest.xml
Bug #743 nativeInit is called with wrong screen size when running on device with software android buttons
Bug #744 CCUserDefault crashes in v0.9.1
Bug #755 Multi-touch causes crash on sum sung devices
[ios]
Bug #660 CCLabelBMFont image error in retina display
Bug #693 CCLabelTTF can not break line by '\n' on iOS
Bug #716 subbing & adding volume of sound effects don't change volume little by little on iOS
Bug #738 Passing CCSize(width,0) to CCLabelTTF causes the label invisible
Bug #753 visual orientation is wrong on ios5 simulator
Bug #754 Missing png file for CCLabelAtlas cause crashes on iOS 4.3.3 & 5.0
[win32]
Feature #731 add ability of simulating android back/menu key on win32
Feature #735 add ability of simulating android enter/resume background on win32. Shift+F1=android Back, Shift+F2 =android Menu
Feature #745 export CCTime to all
Bug #747 Win32 templates should put all resources into "Resources" folder
Bug #748 build error in win32 release version
[wophone]
Bug #702 tests crash at the start on wophone devices
[lua]
Feature #704 Print error descriptions ad pop error code in CCLuaScriptModule::executeString & CCLuaScriptModule::executeScriptFile
Feature #707 Support 'require' for lua on android
Feature #732 Add particle systems to lua bindings
Feature #733 Use ant to generate a lua project, refer to http://www.cocos2d-x.org/boards/11/topics/3957
Feature #734 Use ant to generate LuaCocos2d.cpp
cocos2d-1.0.1-x-0.9.1 @ Aug.17,2011
[all platforms]
Feature #347 Support custom TTF fonts

View File

@ -45,6 +45,7 @@ extern "C"
if (env != 0 && classOfCocos2dxActivity != 0)
{
ret = env->GetStaticMethodID(classOfCocos2dxActivity, methodName, paramCode);
env->DeleteLocalRef(classOfCocos2dxActivity);
}
if (! ret)
@ -62,8 +63,9 @@ extern "C"
if (preloadBackgroundMusicMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadBackgroundMusicMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadBackgroundMusicMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
@ -74,9 +76,9 @@ extern "C"
if (playBackgroundMusicMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, playBackgroundMusicMethodID, StringArg, isLoop);
//env->ReleaseStringUTFChars(StringArg, path);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, playBackgroundMusicMethodID, stringArg, isLoop);
env->DeleteLocalRef(stringArg);
}
}
@ -172,8 +174,9 @@ extern "C"
if (playEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, StringArg, bLoop);
jstring stringArg = env->NewStringUTF(path);
ret = env->CallStaticIntMethod(classOfCocos2dxActivity, playEffectMethodID, stringArg, bLoop);
env->DeleteLocalRef(stringArg);
}
return (unsigned int)ret;
@ -233,8 +236,9 @@ extern "C"
if (preloadEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadEffectMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, preloadEffectMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
@ -245,8 +249,9 @@ extern "C"
if (unloadEffectMethodID)
{
jstring StringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, unloadEffectMethodID, StringArg);
jstring stringArg = env->NewStringUTF(path);
env->CallStaticVoidMethod(classOfCocos2dxActivity, unloadEffectMethodID, stringArg);
env->DeleteLocalRef(stringArg);
}
}
}

View File

@ -54,6 +54,9 @@
<listOptionValue builtIn="false" value="fmodex"/>
</option>
<option defaultValue="true" id="gnu.cpp.link.option.shared.430688089" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" valueType="boolean"/>
<option id="gnu.cpp.link.option.paths.1630974641" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/third_party/fmod/api/lib}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1207468004" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@ -70,6 +73,8 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.509246766">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.509246766" moduleId="org.eclipse.cdt.core.settings" name="Release">
@ -122,6 +127,9 @@
<listOptionValue builtIn="false" value="fmodex"/>
</option>
<option defaultValue="true" id="gnu.cpp.link.option.shared.1840009551" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" valueType="boolean"/>
<option id="gnu.cpp.link.option.paths.1502506408" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/third_party/fmod/api/lib}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1952243970" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@ -138,6 +146,8 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1982681102.1621062209">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1982681102.1621062209" moduleId="org.eclipse.cdt.core.settings" name="AndroidDebug">
@ -204,6 +214,8 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.509246766.1769340575">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.509246766.1769340575" moduleId="org.eclipse.cdt.core.settings" name="AndroidRelease">
@ -270,6 +282,8 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="scannerConfiguration"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">

View File

@ -1,6 +1,6 @@
CC = gcc
CXX = g++
TARGET = libCocosDenshion.so
TARGET = libcocosdenshion.so
CCFLAGS = -Wall -g -O2
CXXFLAGS = -Wall -g -O2
VISIBILITY =
@ -14,9 +14,9 @@ DEFINES = -DLINUX
OBJECTS = ../Linux/FmodAudioPlayer.o \
../Linux/SimpleAudioEngine.o \
STATICLIBS =
SHAREDLIBS = -lfmodex
SHAREDLIBS_DIR = ../third_party/fmod/api/lib
SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex
####### Build rules
$(TARGET): $(OBJECTS)

View File

@ -1 +0,0 @@
fe25757fdb0cc2e48002bf130522902794158965

View File

@ -1 +0,0 @@
2b6d571d132326e599c4790cc0a24aaaa940f721

View File

@ -1,85 +0,0 @@
FMOD Ex SoundSystem Copyright © 2005-2011 Firelight Technologies Pty, Ltd.
FMOD NON-COMMERCIAL LICENSE
------------------------------------
IF YOUR PRODUCT IS NOT INTENDED FOR COMMERCIAL GAIN AND DOES NOT
INCLUDE THE FMOD LIBRARY FOR RESALE, LICENSE OR OTHER COMMERCIAL
DISTRIBUTION, THEN USE OF FMOD IS FREE OF CHARGE. THERE ARE NO
LICENSE FEES FOR NON-COMMERCIAL APPLICATIONS.
CONDITIONS/LIMITATIONS:
- WHEN USING THIS LICENSE, THE FMOD LIBRARY CANNOT BE USED FOR
RESALE OR OTHER COMMERCIAL DISTRIBUTION
- THIS LICENSE CANNOT BE USED FOR PRODUCTS WHICH DO NOT MAKE
PROFIT BUT ARE STILL COMMERCIALLY RELEASED
- THIS LICENSE CANNOT BE USED FOR COMMERCIAL SERVICES, WHERE THE
EXECUTABLE CONTAINING FMOD IS NOT SOLD, BUT THE DATA IS.
- WHEN USING FMOD, A CREDIT LINE IS REQUIRED IN EITHER DOCUMENTATION,
OR 'ON SCREEN' FORMAT (IF POSSIBLE). IT SHOULD CONTAIN AT LEAST
THE WORDS FMOD SOUND SYSTEM AND FIRELIGHT TECHNOLOGIES.
LOGOS ARE AVAILABLE FOR BOX OR MANUAL ART, BUT ARE NOT MANDANTORY.
AN EXAMPLE CREDIT COULD BE:
FMOD Sound System, copyright © Firelight Technologies Pty, Ltd., 1994-2011.
NOTE THIS IN ADVANCE, AS IT MUST BE DONE BEFORE SHIPPING YOUR
PRODUCT WITH FMOD.
Uses Ogg Vorbis codec. BSD license.
------------------------------------
Copyright (c) 2002, Xiph.org Foundation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For Android platform code.
--------------------------
Copyright (C) 2010 The Android Open Source Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

View File

@ -1 +0,0 @@
fe3d4e47687a4bc181a1b3e1d71459b13f8d1ebc

View File

@ -1 +0,0 @@
ea6ff436eda933873fe871fb22523eebdfcccbca

View File

@ -1 +0,0 @@
2e5bd5bfc4d59acfe03fe0d7fd67187dd7281171

View File

@ -1,11 +0,0 @@
3d_cpp: main.cpp
g++ -O3 -o 3d main.cpp ../../api/lib/libfmodex.so -pthread
3d_c: main.c
g++ -O3 -o 3d main.c ../../api/lib/libfmodex.so -pthread
run:
./3d
clean:
rm -f 3d

View File

@ -1,254 +0,0 @@
/*===============================================================================================
3d Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to basic 3d positioning
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <math.h>
const int INTERFACE_UPDATETIME = 50; // 50ms update for interface
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1, *sound2, *sound3;
FMOD_CHANNEL *channel1 = 0, *channel2 = 0, *channel3 = 0;
FMOD_RESULT result;
int key;
int listenerflag = TRUE;
FMOD_VECTOR listenerpos = { 0.0f, 0.0f, 0.0f };
unsigned int version;
printf("===============================================================\n");
printf("3d Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===============================================================\n");
printf("This example plays 2 3D sounds in software. Optionally you can\n");
printf("play a 2D software sound as well.\n");
printf("Hardware sounds are not supported on Linux\n");
printf("===============================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_Init(system, 10, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Load some sounds
*/
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_3D, 0, &sound1);
ERRCHECK(result);
result = FMOD_Sound_Set3DMinMaxDistance(sound1, 4.0f, 10000.0f);
ERRCHECK(result);
result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_SOFTWARE | FMOD_3D, 0, &sound2);
ERRCHECK(result);
result = FMOD_Sound_Set3DMinMaxDistance(sound2, 4.0f, 10000.0f);
ERRCHECK(result);
result = FMOD_Sound_SetMode(sound2, FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound3);
ERRCHECK(result);
/*
Play sounds at certain positions
*/
{
FMOD_VECTOR pos = { -10.0f, -0.0f, 0.0f };
FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel1);
ERRCHECK(result);
result = FMOD_Channel_Set3DAttributes(channel1, &pos, &vel);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel1, FALSE);
ERRCHECK(result);
}
{
FMOD_VECTOR pos = { 15.0f, -0.0f, -0.0f };
FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel2);
ERRCHECK(result);
result = FMOD_Channel_Set3DAttributes(channel2, &pos, &vel);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel2, FALSE);
ERRCHECK(result);
}
/*
Display help
*/
{
int numchannels;
result = FMOD_System_GetHardwareChannels(system, &numchannels);
ERRCHECK(result);
printf("Hardware channels : %d\n", numchannels);
}
printf("=========================================================================\n");
printf("Press 1 Pause/Unpause 16bit 3D sound at any time\n");
printf(" 2 Pause/Unpause 8bit 3D sound at any time\n");
printf(" 3 Play 16bit STEREO 2D sound at any time\n");
printf(" < Move listener left (in still mode)\n");
printf(" > Move listener right (in still mode)\n");
printf(" SPACE Stop/Start listener automatic movement\n");
printf(" ESC Quit\n");
printf("=========================================================================\n");
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
if (key == '1')
{
int paused;
FMOD_Channel_GetPaused(channel1, &paused);
FMOD_Channel_SetPaused(channel1, !paused);
}
if (key == '2')
{
int paused;
FMOD_Channel_GetPaused(channel2, &paused);
FMOD_Channel_SetPaused(channel2, !paused);
}
if (key == '3')
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, FALSE, &channel3);
ERRCHECK(result);
}
if (key == ' ')
{
listenerflag = !listenerflag;
}
if (!listenerflag)
{
if (key == '<')
{
listenerpos.x -= 1.0f;
if (listenerpos.x < -35)
{
listenerpos.x = -35;
}
}
if (key == '>')
{
listenerpos.x += 1.0f;
if (listenerpos.x > 30)
{
listenerpos.x = 30;
}
}
}
}
// ==========================================================================================
// UPDATE THE LISTENER
// ==========================================================================================
{
static float t = 0;
static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f };
FMOD_VECTOR vel;
if (listenerflag)
{
listenerpos.x = ((float)sin(t * 0.05f) * 33.0f); // left right pingpong
}
// ********* NOTE ******* READ NEXT COMMENT!!!!!
// vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);
// store pos for next time
lastpos = listenerpos;
result = FMOD_System_Set3DListenerAttributes(system, 0, &listenerpos, &vel, &forward, &up);
ERRCHECK(result);
t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example
// print out a small visual display
{
char s[80];
sprintf(s, "|.......................<1>......................<2>....................|");
s[(int)(listenerpos.x) + 35] = 'L';
printf("%s\r", s);
fflush(stdout);
}
}
FMOD_System_Update(system);
Sleep(INTERFACE_UPDATETIME - 1);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound1);
ERRCHECK(result);
result = FMOD_Sound_Release(sound2);
ERRCHECK(result);
result = FMOD_Sound_Release(sound3);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,255 +0,0 @@
/*===============================================================================================
3d Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to basic 3d positioning
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <math.h>
const int INTERFACE_UPDATETIME = 50; // 50ms update for interface
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2, *sound3;
FMOD::Channel *channel1 = 0, *channel2 = 0, *channel3 = 0;
FMOD_RESULT result;
int key;
bool listenerflag = true;
FMOD_VECTOR listenerpos = { 0.0f, 0.0f, 0.0f };
unsigned int version;
printf("===============================================================\n");
printf("3d Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===============================================================\n\n");
printf("This example plays 2 3D sounds in software. Optionally you can\n");
printf("play a 2D software sound as well.\n");
printf("Hardware sounds are not supported on Linux\n");
printf("===============================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = system->init(10, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Load some sounds
*/
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_3D, 0, &sound1);
ERRCHECK(result);
result = sound1->set3DMinMaxDistance(4.0f, 10000.0f);
ERRCHECK(result);
result = sound1->setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE | FMOD_3D, 0, &sound2);
ERRCHECK(result);
result = sound2->set3DMinMaxDistance(4.0f, 10000.0f);
ERRCHECK(result);
result = sound2->setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = system->createSound("../media/swish.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound3);
ERRCHECK(result);
/*
Play sounds at certain positions
*/
{
FMOD_VECTOR pos = { -10.0f, -0.0f, 0.0f };
FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel1);
ERRCHECK(result);
result = channel1->set3DAttributes(&pos, &vel);
ERRCHECK(result);
result = channel1->setPaused(false);
ERRCHECK(result);
}
{
FMOD_VECTOR pos = { 15.0f, -0.0f, -0.0f };
FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };
result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel2);
ERRCHECK(result);
result = channel2->set3DAttributes(&pos, &vel);
ERRCHECK(result);
result = channel2->setPaused(false);
ERRCHECK(result);
}
/*
Display help
*/
{
int numchannels = 0;
result = system->getHardwareChannels(&numchannels);
ERRCHECK(result);
printf("Hardware channels : %d\n", numchannels);
}
printf("=========================================================================\n");
printf("Press 1 Pause/Unpause 16bit 3D sound at any time\n");
printf(" 2 Pause/Unpause 8bit 3D sound at any time\n");
printf(" 3 Play 16bit STEREO 2D sound at any time\n");
printf(" < Move listener left (in still mode)\n");
printf(" > Move listener right (in still mode)\n");
printf(" SPACE Stop/Start listener automatic movement\n");
printf(" ESC Quit\n");
printf("=========================================================================\n");
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
if (key == '1')
{
bool paused;
channel1->getPaused(&paused);
channel1->setPaused(!paused);
}
if (key == '2')
{
bool paused;
channel2->getPaused(&paused);
channel2->setPaused(!paused);
}
if (key == '3')
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3);
ERRCHECK(result);
}
if (key == ' ')
{
listenerflag = !listenerflag;
}
if (!listenerflag)
{
if (key == '<')
{
listenerpos.x -= 1.0f;
if (listenerpos.x < -35)
{
listenerpos.x = -35;
}
}
if (key == '>')
{
listenerpos.x += 1.0f;
if (listenerpos.x > 30)
{
listenerpos.x = 30;
}
}
}
}
// ==========================================================================================
// UPDATE THE LISTENER
// ==========================================================================================
{
static float t = 0;
static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f };
FMOD_VECTOR vel;
if (listenerflag)
{
listenerpos.x = ((float)sin(t * 0.05f) * 33.0f); // left right pingpong
}
// ********* NOTE ******* READ NEXT COMMENT!!!!!
// vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);
// store pos for next time
lastpos = listenerpos;
result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up);
ERRCHECK(result);
t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example
// print out a small visual display
{
char s[80];
sprintf(s, "|.......................<1>......................<2>....................|");
s[(int)(listenerpos.x) + 35] = 'L';
printf("%s\r", s);
fflush(stdout);
}
}
system->update();
Sleep(INTERFACE_UPDATETIME - 1);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
cdplayer_cpp: main.cpp
g++ -O3 -o cdplayer main.cpp ../../api/lib/libfmodex.so -pthread
cdplayer_c: main.c
g++ -O3 -o cdplayer main.c ../../api/lib/libfmodex.so -pthread
run:
./cdplayer
clean:
rm -f cdplayer

View File

@ -1,236 +0,0 @@
/*===============================================================================================
CDPlayer Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play CD tracks digitally and generate a CDDB query
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int cddb_sum(int n)
{
int ret = 0;
while (n > 0)
{
ret += (n % 10);
n /= 10;
}
return ret;
}
unsigned long cddb_discid(FMOD_CDTOC *toc)
{
int i, t, n = 0;
for (i = 0; i < toc->numtracks; i++)
{
n += cddb_sum((toc->min[i] * 60) + toc->sec[i]);
}
t = ((toc->min[toc->numtracks] * 60) + toc->sec[toc->numtracks]) - ((toc->min[0] * 60) + toc->sec[0]);
return ((n % 0xff) << 24 | t << 8 | toc->numtracks);
}
void dump_cddb_query(FMOD_CDTOC *toc)
{
int i;
printf("cddb query %08x %d", cddb_discid(toc), toc->numtracks);
for (i = 0; i < toc->numtracks; i++)
{
printf(" %d", (toc->min[i] * (60 * 75)) + (toc->sec[i] * 75) + toc->frame[i]);
}
printf(" %d\n", (toc->min[toc->numtracks] * 60) + toc->sec[toc->numtracks]);
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *cdsound;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key, numtracks, currenttrack = 0;
unsigned int version;
if (argc < 2)
{
printf("Usage: cdplayer <drivepath>\n");
printf("Example: cdplayer /dev/cdrom\n");
exit(-1);
}
printf("==================================================================\n");
printf("CDPlayer Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==================================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium.
*/
result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = FMOD_System_CreateStream(system, argv[1], FMOD_OPENONLY, 0, &cdsound);
ERRCHECK(result);
result = FMOD_Sound_GetNumSubSounds(cdsound, &numtracks);
ERRCHECK(result);
result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound);
ERRCHECK(result);
for (;;)
{
FMOD_TAG tag;
if (FMOD_Sound_GetTag(cdsound, 0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_CDTOC)
{
dump_cddb_query((FMOD_CDTOC *)tag.data);
}
}
printf("\n========================================\n");
printf("Press SPACE to pause\n");
printf(" n to skip to next track\n");
printf(" ESC to exit\n");
printf("========================================\n\n");
/*
Print out length of entire CD. Did you know you can also play 'cdsound' and it will play the whole CD without gaps?
*/
{
unsigned int lenms;
result = FMOD_Sound_GetLength(cdsound, &lenms, FMOD_TIMEUNIT_MS);
ERRCHECK(result);
printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100);
}
/*
Play a CD track
*/
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
break;
}
case 'n' :
{
currenttrack++;
if (currenttrack >= numtracks)
{
currenttrack = 0;
}
result = FMOD_Sound_GetSubSound(cdsound, currenttrack, &sound);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
unsigned int ms, lenms, percent = 0;
FMOD_BOOL playing;
FMOD_BOOL paused;
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,238 +0,0 @@
/*===============================================================================================
CDPlayer Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play CD tracks digitally and generate a CDDB query
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int cddb_sum(int n)
{
int ret = 0;
while (n > 0)
{
ret += (n % 10);
n /= 10;
}
return ret;
}
unsigned long cddb_discid(FMOD_CDTOC *toc)
{
int i, t, n = 0;
for (i = 0; i < toc->numtracks; i++)
{
n += cddb_sum((toc->min[i] * 60) + toc->sec[i]);
}
t = ((toc->min[toc->numtracks] * 60) + toc->sec[toc->numtracks]) - ((toc->min[0] * 60) + toc->sec[0]);
return ((n % 0xff) << 24 | t << 8 | toc->numtracks);
}
void dump_cddb_query(FMOD_CDTOC *toc)
{
int i;
printf("cddb query %08x %d", cddb_discid(toc), toc->numtracks);
for (i = 0; i < toc->numtracks; i++)
{
printf(" %d", (toc->min[i] * (60 * 75)) + (toc->sec[i] * 75) + toc->frame[i]);
}
printf(" %d\n", (toc->min[toc->numtracks] * 60) + toc->sec[toc->numtracks]);
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *cdsound;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key, numtracks, currenttrack = 0;
unsigned int version;
if (argc < 2)
{
printf("Usage: cdplayer <drivepath>\n");
printf("Example: cdplayer /dev/cdrom\n");
exit(-1);
}
printf("==================================================================\n");
printf("CDPlayer Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==================================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Bump up the file buffer size a bit from the 16k default for CDDA, because it is a slower medium.
*/
result = system->setStreamBufferSize(64*1024, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = system->createStream(argv[1], FMOD_OPENONLY, 0, &cdsound);
ERRCHECK(result);
result = cdsound->getNumSubSounds(&numtracks);
ERRCHECK(result);
result = cdsound->getSubSound(currenttrack, &sound);
ERRCHECK(result);
for (;;)
{
FMOD_TAG tag;
if (cdsound->getTag(0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_CDTOC)
{
dump_cddb_query((FMOD_CDTOC *)tag.data);
}
}
printf("\n========================================\n");
printf("Press SPACE to pause\n");
printf(" n to skip to next track\n");
printf(" ESC to exit\n");
printf("========================================\n\n");
/*
Print out length of entire CD. Did you know you can also play 'cdsound' and it will play the whole CD without gaps?
*/
{
unsigned int lenms;
result = cdsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
ERRCHECK(result);
printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100);
}
/*
Play a CD track
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
case 'n' :
{
currenttrack++;
if (currenttrack >= numtracks)
{
currenttrack = 0;
}
result = cdsound->getSubSound(currenttrack, &sound);
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
channelgroups_cpp: main.cpp
g++ -O3 -o channelgroups main.cpp ../../api/lib/libfmodex.so -pthread
channelgroups_c: main.c
g++ -O3 -o channelgroups main.c ../../api/lib/libfmodex.so -pthread
run:
./channelgroups
clean:
rm -f channelgroups

View File

@ -1,226 +0,0 @@
/*===============================================================================================
ChannelGroups Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to put channels into channel groups, so that you can affect a group
of channels at a time instead of just one channel at a time.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound[6];
FMOD_CHANNEL *channel[6];
FMOD_CHANNELGROUP *groupA, *groupB, *masterGroup;
FMOD_RESULT result;
int key, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_LOOP_NORMAL, 0, &sound[0]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_LOOP_NORMAL, 0, &sound[1]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_LOOP_NORMAL, 0, &sound[2]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/c.ogg", FMOD_LOOP_NORMAL, 0, &sound[3]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/d.ogg", FMOD_LOOP_NORMAL, 0, &sound[4]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/e.ogg", FMOD_LOOP_NORMAL, 0, &sound[5]);
ERRCHECK(result);
result = FMOD_System_CreateChannelGroup(system, "Group A", &groupA);
ERRCHECK(result);
result = FMOD_System_CreateChannelGroup(system, "Group B", &groupB);
ERRCHECK(result);
result = FMOD_System_GetMasterChannelGroup(system, &masterGroup);
ERRCHECK(result);
printf("=======================================================================\n");
printf("ChannelGroups Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=======================================================================\n");
printf("\n");
printf("Group A : drumloop.wav, jaguar.wav, swish.wav\n");
printf("Group B : c.ogg, d.ogg, e.ogg\n");
printf("\n");
printf("Press 'A' to mute/unmute group A\n");
printf("Press 'B' to mute/unmute group B\n");
printf("Press 'C' to mute/unmute group A and B (master group)\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Instead of being independent, set the group A and B to be children of the master group.
*/
result = FMOD_ChannelGroup_AddGroup(masterGroup, groupA);
ERRCHECK(result);
result = FMOD_ChannelGroup_AddGroup(masterGroup, groupB);
ERRCHECK(result);
/*
Start all the sounds!
*/
for (count = 0; count < 6; count++)
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound[count], TRUE, &channel[count]);
ERRCHECK(result);
if (count < 3)
{
result = FMOD_Channel_SetChannelGroup(channel[count], groupA);
}
else
{
result = FMOD_Channel_SetChannelGroup(channel[count], groupB);
}
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel[count], FALSE);
ERRCHECK(result);
}
/*
Change the volume of each group, just because we can! (And makes it less of a loud noise).
*/
result = FMOD_ChannelGroup_SetVolume(groupA, 0.5f);
ERRCHECK(result);
result = FMOD_ChannelGroup_SetVolume(groupB, 0.5f);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'a' :
case 'A' :
{
static int mute = TRUE;
FMOD_ChannelGroup_SetMute(groupA, mute);
mute = !mute;
break;
}
case 'b' :
case 'B' :
{
static int mute = TRUE;
FMOD_ChannelGroup_SetMute(groupB, mute);
mute = !mute;
break;
}
case 'c' :
case 'C' :
{
static int mute = TRUE;
FMOD_ChannelGroup_SetMute(masterGroup, mute);
mute = !mute;
break;
}
}
}
FMOD_System_Update(system);
{
int channelsplaying = 0;
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
printf("Channels Playing %2d\r", channelsplaying);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
A little fade out. (over 2 seconds)
*/
printf("Goodbye!\n");
{
float pitch = 1.0f;
float vol = 1.0f;
for (count = 0; count < 200; count++)
{
FMOD_ChannelGroup_SetPitch(masterGroup, pitch);
FMOD_ChannelGroup_SetVolume(masterGroup, vol);
vol -= (1.0f / 200.0f);
pitch -= (0.5f / 200.0f);
Sleep(10);
}
}
/*
Shut down
*/
for (count = 0; count < 6; count++)
{
result = FMOD_Sound_Release(sound[count]);
ERRCHECK(result);
}
result = FMOD_ChannelGroup_Release(groupA);
ERRCHECK(result);
result = FMOD_ChannelGroup_Release(groupB);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,226 +0,0 @@
/*===============================================================================================
ChannelGroups Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to put channels into channel groups, so that you can affect a group
of channels at a time instead of just one channel at a time.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound[6];
FMOD::Channel *channel[6];
FMOD::ChannelGroup *groupA, *groupB, *masterGroup;
FMOD_RESULT result;
int key, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_LOOP_NORMAL, 0, &sound[0]);
ERRCHECK(result);
result = system->createSound("../media/jaguar.wav", FMOD_LOOP_NORMAL, 0, &sound[1]);
ERRCHECK(result);
result = system->createSound("../media/swish.wav", FMOD_LOOP_NORMAL, 0, &sound[2]);
ERRCHECK(result);
result = system->createSound("../media/c.ogg", FMOD_LOOP_NORMAL, 0, &sound[3]);
ERRCHECK(result);
result = system->createSound("../media/d.ogg", FMOD_LOOP_NORMAL, 0, &sound[4]);
ERRCHECK(result);
result = system->createSound("../media/e.ogg", FMOD_LOOP_NORMAL, 0, &sound[5]);
ERRCHECK(result);
result = system->createChannelGroup("Group A", &groupA);
ERRCHECK(result);
result = system->createChannelGroup("Group B", &groupB);
ERRCHECK(result);
result = system->getMasterChannelGroup(&masterGroup);
ERRCHECK(result);
printf("=======================================================================\n");
printf("ChannelGroups Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=======================================================================\n");
printf("\n");
printf("Group A : drumloop.wav, jaguar.wav, swish.wav\n");
printf("Group B : c.ogg, d.ogg, e.ogg\n");
printf("\n");
printf("Press 'A' to mute/unmute group A\n");
printf("Press 'B' to mute/unmute group B\n");
printf("Press 'C' to mute/unmute group A and B (master group)\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Instead of being independent, set the group A and B to be children of the master group.
*/
result = masterGroup->addGroup(groupA);
ERRCHECK(result);
result = masterGroup->addGroup(groupB);
ERRCHECK(result);
/*
Start all the sounds!
*/
for (count = 0; count < 6; count++)
{
result = system->playSound(FMOD_CHANNEL_FREE, sound[count], true, &channel[count]);
ERRCHECK(result);
if (count < 3)
{
result = channel[count]->setChannelGroup(groupA);
}
else
{
result = channel[count]->setChannelGroup(groupB);
}
ERRCHECK(result);
result = channel[count]->setPaused(false);
ERRCHECK(result);
}
/*
Change the volume of each group, just because we can! (And makes it less noise).
*/
result = groupA->setVolume(0.5f);
ERRCHECK(result);
result = groupB->setVolume(0.5f);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'a' :
case 'A' :
{
static bool mute = true;
groupA->setMute(mute);
mute = !mute;
break;
}
case 'b' :
case 'B' :
{
static bool mute = true;
groupB->setMute(mute);
mute = !mute;
break;
}
case 'c' :
case 'C' :
{
static bool mute = true;
masterGroup->setMute(mute);
mute = !mute;
break;
}
}
}
system->update();
{
int channelsplaying = 0;
system->getChannelsPlaying(&channelsplaying);
printf("Channels Playing %2d\r", channelsplaying);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
A little fade out. (over 2 seconds)
*/
printf("Goodbye!\n");
{
float pitch = 1.0f;
float vol = 1.0f;
for (count = 0; count < 200; count++)
{
masterGroup->setPitch(pitch);
masterGroup->setVolume(vol);
vol -= (1.0f / 200.0f);
pitch -= (0.5f / 200.0f);
Sleep(10);
}
}
/*
Shut down
*/
for (count = 0; count < 6; count++)
{
result = sound[count]->release();
ERRCHECK(result);
}
result = groupA->release();
ERRCHECK(result);
result = groupB->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,84 +0,0 @@
#if !defined(WINCOMPAT_INCLUDED) && !defined(PLATFORM_WINDOWS) && !defined(WIN32) && !defined(WINDOWS) && !defined(__WIN32__)
#define WINCOMPAT_INCLUDED
/**
*
* Author: Magnus Naeslund (mag@fbab.net, mag@bahnhof.se)
* (c) 2000 Magnus Naeslund, all rights reserved
*
*/
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define _kbhit kbhit
#define _getch getch
#define stricmp strcasecmp
#define strnicmp strncasecmp
#define Sleep(x) usleep((x)*1000)
static int inited=0;
static struct termios ori;
static void tcatexit(){
tcsetattr(0,TCSANOW,&ori);
}
static void init_terminal(){
struct termios t;
tcgetattr(0,&t);
tcgetattr(0,&ori);
t.c_lflag &= ~(ICANON);
t.c_lflag &= ~(ECHO);
tcsetattr(0,TCSANOW,&t);
atexit(tcatexit);
}
static inline int kbhit(){
fd_set rfds;
struct timeval tv;
if (!inited){
inited=1;
init_terminal();
}
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 10*1000;
return select(1, &rfds, NULL, NULL, &tv)>0;
}
static inline int getch(){
fd_set rfds;
if (!inited){
inited=1;
init_terminal();
}
FD_ZERO(&rfds);
FD_SET(0, &rfds);
if (select(1, &rfds, NULL, NULL, NULL)>0)
return getchar();
else{
printf("wincompat.h: select() on fd 0 failed\n");
return 0xDeadBeef;
}
}
#endif

View File

@ -1,11 +0,0 @@
dsp_custom_cpp: main.cpp
g++ -O3 -o dsp_custom main.cpp ../../api/lib/libfmodex.so -pthread
dsp_custom_c: main.c
g++ -O3 -o dsp_custom main.c ../../api/lib/libfmodex.so -pthread
run:
./dsp_custom
clean:
rm -f dsp_custom

View File

@ -1,185 +0,0 @@
/*===============================================================================================
Custom DSP Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to add a user created DSP callback to process audio data.
A read callback is generated at runtime, and can be added anywhere in the DSP network.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
unsigned int count, userdata;
int count2;
char name[256];
FMOD_DSP *thisdsp = dsp_state->instance;
/*
This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to
call a DSP information function.
*/
FMOD_DSP_GetInfo(thisdsp, name, 0, 0, 0, 0);
FMOD_DSP_GetUserData(thisdsp, (void **)&userdata);
/*
This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0'
as the number of channels in FMOD_DSP_DESCRIPTION.
Specifying an actual channel count will mean you have to take care of any number of channels coming in,
but outputting the number of channels specified. Generally it is best to keep the channel
count at 0 for maximum compatibility.
*/
for (count = 0; count < length; count++)
{
/*
Feel free to unroll this.
*/
for (count2 = 0; count2 < outchannels; count2++)
{
/*
This DSP filter just halves the volume!
Input is modified, and sent to output.
*/
outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2] * 0.2f;
}
}
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel;
FMOD_DSP *mydsp;
FMOD_RESULT result;
int key;
unsigned int version;
float pan = 0;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
ERRCHECK(result);
printf("===============================================================================\n");
printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===============================================================================\n");
printf("Press 'f' to activate, deactivate user filter\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);
/*
Create the DSP effects.
*/
{
FMOD_DSP_DESCRIPTION dspdesc;
memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "My first DSP unit");
dspdesc.channels = 0; // 0 = whatever comes in, else specify.
dspdesc.read = myDSPCallback;
dspdesc.userdata = (void *)0x12345678;
result = FMOD_System_CreateDSP(system, &dspdesc, &mydsp);
ERRCHECK(result);
}
/*
Inactive by default.
*/
FMOD_DSP_SetBypass(mydsp, TRUE);
/*
Main loop.
*/
result = FMOD_System_AddDSP(system, mydsp, 0);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'f' :
case 'F' :
{
static int active = FALSE;
FMOD_DSP_SetBypass(mydsp, active);
active = !active;
break;
}
}
}
FMOD_System_Update(system);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_DSP_Release(mydsp);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,185 +0,0 @@
/*===============================================================================================
Custom DSP Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to add a user created DSP callback to process audio data.
A read callback is generated at runtime, and can be added anywhere in the DSP network.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
unsigned int count, userdata;
int count2;
char name[256];
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
/*
This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to
call a DSP information function.
*/
thisdsp->getInfo(name, 0, 0, 0, 0);
thisdsp->getUserData((void **)&userdata);
/*
This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0'
as the number of channels in FMOD_DSP_DESCRIPTION.
Specifying an actual channel count will mean you have to take care of any number of channels coming in,
but outputting the number of channels specified. Generally it is best to keep the channel
count at 0 for maximum compatibility.
*/
for (count = 0; count < length; count++)
{
/*
Feel free to unroll this.
*/
for (count2 = 0; count2 < outchannels; count2++)
{
/*
This DSP filter just halves the volume!
Input is modified, and sent to output.
*/
outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2] * 0.2f;
}
}
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel;
FMOD::DSP *mydsp;
FMOD_RESULT result;
int key;
unsigned int version;
float pan = 0;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
ERRCHECK(result);
printf("===================================================================\n");
printf("Custom DSP example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("Press 'f' to activate, deactivate user filter\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Create the DSP effects.
*/
{
FMOD_DSP_DESCRIPTION dspdesc;
memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION));
strcpy(dspdesc.name, "My first DSP unit");
dspdesc.channels = 0; // 0 = whatever comes in, else specify.
dspdesc.read = myDSPCallback;
dspdesc.userdata = (void *)0x12345678;
result = system->createDSP(&dspdesc, &mydsp);
ERRCHECK(result);
}
/*
Inactive by default.
*/
mydsp->setBypass(true);
/*
Main loop.
*/
result = system->addDSP(mydsp, 0);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'f' :
case 'F' :
{
static bool active = false;
mydsp->setBypass(active);
active = !active;
break;
}
}
}
system->update();
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = mydsp->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
dsp_effectperspeaker_cpp: main.cpp
g++ -O3 -o dsp_effectperspeaker main.cpp ../../api/lib/libfmodex.so -pthread
dsp_effectperspeaker_c: main.c
g++ -O3 -o dsp_effectperspeaker main.c ../../api/lib/libfmodex.so -pthread
run:
./dsp_effectperspeaker
clean:
rm -f dsp_effectperspeaker

View File

@ -1,268 +0,0 @@
/*===============================================================================================
DSP Effect per speaker Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to manipulate a DSP network and as an example, creates 2 dsp effects,
and splits a single sound into 2 audio paths, which it then filters seperately.
To only have each audio path come out of one speaker each, FMOD_DSPConnection_setLevels is used just
before the 2 branches merge back together again.
For more speakers:
1. Use FMOD_System_SetSpeakerMode or FMOD_System_SetOutputFormat.
2. Create more effects, currently 2 for stereo (reverb and chorus), create one per speaker.
3. Under the 'Now connect the 2 effects to channeldsp head.' section, connect the extra effects
by duplicating the code more times.
4. Filter each effect to each speaker by calling FMOD_DSP_SetInputLevels. Expand the existing code
by extending the level arrays from 2 to the number of speakers you require, and change the
numlevels parameter in FMOD_DSP_SetInputLevels from 2 to the correct number accordingly.
===============================================================================================*/
#include "../common/wincompat.h"
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel;
FMOD_DSP *dsplowpass, *dspchorus, *dsphead, *dspchannelmixer;
FMOD_DSPCONNECTION *dsplowpassconnection, *dspchorusconnection;
FMOD_RESULT result;
int key;
unsigned int version;
float pan = 0;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
ERRCHECK(result);
printf("===============================================================================\n");
printf("DSP Effect per speaker example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===============================================================================\n");
printf("Press 'L' to toggle reverb on/off on left speaker only\n");
printf("Press 'R' to toggle chorus on/off on right speaker only\n");
printf("Press '[' to pan sound left\n");
printf("Press ']' to pan sound right\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);
/*
Create the DSP effects.
*/
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_REVERB, &dsplowpass);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_CHORUS, &dspchorus);
ERRCHECK(result);
/*
Connect up the DSP network
*/
/*
When a sound is played, a subnetwork is set up in the DSP network which looks like this.
Wavetable is the drumloop sound, and it feeds its data from right to left.
[DSPHEAD]<------------[DSPCHANNELMIXER]
*/
result = FMOD_System_GetDSPHead(system, &dsphead);
ERRCHECK(result);
result = FMOD_DSP_GetInput(dsphead, 0, &dspchannelmixer, 0);
ERRCHECK(result);
/*
Now disconnect channeldsp head from wavetable to look like this.
[DSPHEAD] [DSPCHANNELMIXER]
*/
result = FMOD_DSP_DisconnectFrom(dsphead, dspchannelmixer);
ERRCHECK(result);
/*
Now connect the 2 effects to channeldsp head.
Store the 2 connections this makes so we can set their speakerlevels later.
[DSPLOWPASS]
/x
[DSPHEAD] [DSPCHANNELMIXER]
\y
[DSPCHORUS]
*/
result = FMOD_DSP_AddInput(dsphead, dsplowpass, &dsplowpassconnection); /* x = dsplowpassconnection */
ERRCHECK(result);
result = FMOD_DSP_AddInput(dsphead, dspchorus, &dspchorusconnection); /* y = dspchorusconnection */
ERRCHECK(result);
/*
Now connect the wavetable to the 2 effects
[DSPLOWPASS]
/x \
[DSPHEAD] [DSPCHANNELMIXER]
\y /
[DSPCHORUS]
*/
result = FMOD_DSP_AddInput(dsplowpass, dspchannelmixer, NULL); /* Null for connection - we dont care about it. */
ERRCHECK(result);
result = FMOD_DSP_AddInput(dspchorus, dspchannelmixer, NULL); /* Null for connection - we dont care about it. */
ERRCHECK(result);
/*
Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and
dspchannelmixer->dspchorus to the right speaker.
We can do that simply by setting the pan, or speaker levels of the connections.
[DSPLOWPASS]
/x=1,0 \
[DSPHEAD] [DSPCHANNELMIXER]
\y=0,1 /
[DSPCHORUS]
*/
{
float leftinputon[2] = { 1.0f, 0.0f };
float rightinputon[2] = { 0.0f, 1.0f };
float inputsoff[2] = { 0.0f, 0.0f };
result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2);
ERRCHECK(result);
result = FMOD_DSPConnection_SetLevels(dsplowpassconnection, FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2);
ERRCHECK(result);
result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2);
ERRCHECK(result);
result = FMOD_DSPConnection_SetLevels(dspchorusconnection, FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2);
ERRCHECK(result);
}
result = FMOD_DSP_SetBypass(dsplowpass, TRUE);
result = FMOD_DSP_SetBypass(dspchorus, TRUE);
result = FMOD_DSP_SetActive(dsplowpass, TRUE);
result = FMOD_DSP_SetActive(dspchorus, TRUE);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'l' :
case 'L' :
{
static int reverb = FALSE;
FMOD_DSP_SetBypass(dsplowpass, reverb);
reverb = !reverb;
break;
}
case 'r' :
case 'R' :
{
static int chorus = FALSE;
FMOD_DSP_SetBypass(dspchorus, chorus);
chorus = !chorus;
break;
}
case '[' :
{
FMOD_Channel_GetPan(channel, &pan);
pan -= 0.1f;
if (pan < -1)
{
pan = -1;
}
FMOD_Channel_SetPan(channel, pan);
break;
}
case ']' :
{
FMOD_Channel_GetPan(channel, &pan);
pan += 0.1f;
if (pan > 1)
{
pan = 1;
}
FMOD_Channel_SetPan(channel, pan);
break;
}
}
}
FMOD_System_Update(system);
{
int channelsplaying = 0;
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan);
}
fflush(stdout);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_DSP_Release(dsplowpass);
ERRCHECK(result);
result = FMOD_DSP_Release(dspchorus);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,268 +0,0 @@
/*===============================================================================================
DSP Effect per speaker Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to manipulate a DSP network and as an example, creates 2 dsp effects,
and splits a single sound into 2 audio paths, which it then filters seperately.
To only have each audio path come out of one speaker each, DSPConnection::setLevels is used just
before the 2 branches merge back together again.
For more speakers:
1. Use System::setSpeakerMode or System::setOutputFormat.
2. Create more effects, currently 2 for stereo (lowpass and chorus), create one per speaker.
3. Under the 'Now connect the 2 effects to channeldsp head.' section, connect the extra effects
by duplicating the code more times.
4. Filter each effect to each speaker by calling DSP::setInputLevels. Expand the existing code
by extending the level arrays from 2 to the number of speakers you require, and change the
numlevels parameter in DSP::setInputLevels from 2 to the correct number accordingly.
===============================================================================================*/
#include "../common/wincompat.h"
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel;
FMOD::DSP *dsplowpass, *dspchorus, *dsphead, *dspchannelmixer;
FMOD::DSPConnection *dsplowpassconnection, *dspchorusconnection;
FMOD_RESULT result;
int key;
unsigned int version;
float pan = 0;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound);
ERRCHECK(result);
printf("===============================================================================\n");
printf("DSP effect per speaker example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===============================================================================\n");
printf("Press 'L' to toggle lowpass on/off on left speaker only\n");
printf("Press 'R' to toggle chorus on/off on right speaker only\n");
printf("Press '[' to pan sound left\n");
printf("Press ']' to pan sound right\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Create the DSP effects.
*/
result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_CHORUS, &dspchorus);
ERRCHECK(result);
/*
Connect up the DSP network
*/
/*
When a sound is played, a subnetwork is set up in the DSP network which looks like this.
Wavetable is the drumloop sound, and it feeds its data from right to left.
[DSPHEAD]<------------[DSPCHANNELMIXER]
*/
result = system->getDSPHead(&dsphead);
ERRCHECK(result);
result = dsphead->getInput(0, &dspchannelmixer, 0);
ERRCHECK(result);
/*
Now disconnect channeldsp head from wavetable to look like this.
[DSPHEAD] [DSPCHANNELMIXER]
*/
result = dsphead->disconnectFrom(dspchannelmixer);
ERRCHECK(result);
/*
Now connect the 2 effects to channeldsp head.
Store the 2 connections this makes so we can set their speakerlevels later.
[DSPLOWPASS]
/x
[DSPHEAD] [DSPCHANNELMIXER]
\y
[DSPCHORUS]
*/
result = dsphead->addInput(dsplowpass, &dsplowpassconnection); /* x = dsplowpassconnection */
ERRCHECK(result);
result = dsphead->addInput(dspchorus, &dspchorusconnection); /* y = dspchorusconnection */
ERRCHECK(result);
/*
Now connect the wavetable to the 2 effects
[DSPLOWPASS]
/x \
[DSPHEAD] [DSPCHANNELMIXER]
\y /
[DSPCHORUS]
*/
result = dsplowpass->addInput(dspchannelmixer, 0); /* Null for connection - we dont care about it. */
ERRCHECK(result);
result = dspchorus->addInput(dspchannelmixer, 0); /* Null for connection - we dont care about it. */
ERRCHECK(result);
/*
Now the drumloop will be twice as loud, because it is being split into 2, then recombined at the end.
What we really want is to only feed the dspchannelmixer->dsplowpass through the left speaker, and
dspchannelmixer->dspchorus to the right speaker.
We can do that simply by setting the pan, or speaker levels of the connections.
[DSPLOWPASS]
/x=1,0 \
[DSPHEAD] [DSPCHANNELMIXER]
\y=0,1 /
[DSPCHORUS]
*/
{
float leftinputon[2] = { 1.0f, 0.0f };
float rightinputon[2] = { 0.0f, 1.0f };
float inputsoff[2] = { 0.0f, 0.0f };
result = dsplowpassconnection->setLevels(FMOD_SPEAKER_FRONT_LEFT, leftinputon, 2);
ERRCHECK(result);
result = dsplowpassconnection->setLevels(FMOD_SPEAKER_FRONT_RIGHT, inputsoff, 2);
ERRCHECK(result);
result = dspchorusconnection->setLevels(FMOD_SPEAKER_FRONT_LEFT, inputsoff, 2);
ERRCHECK(result);
result = dspchorusconnection->setLevels(FMOD_SPEAKER_FRONT_RIGHT, rightinputon, 2);
ERRCHECK(result);
}
result = dsplowpass->setBypass(true);
result = dspchorus->setBypass(true);
result = dsplowpass->setActive(true);
result = dspchorus->setActive(true);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'l' :
case 'L' :
{
static bool lowpass = false;
dsplowpass->setBypass(lowpass);
lowpass = !lowpass;
break;
}
case 'r' :
case 'R' :
{
static bool chorus = false;
dspchorus->setBypass(chorus);
chorus = !chorus;
break;
}
case '[' :
{
channel->getPan(&pan);
pan -= 0.1f;
if (pan < -1)
{
pan = -1;
}
channel->setPan(pan);
break;
}
case ']' :
{
channel->getPan(&pan);
pan += 0.1f;
if (pan > 1)
{
pan = 1;
}
channel->setPan(pan);
break;
}
}
}
system->update();
{
int channelsplaying = 0;
system->getChannelsPlaying(&channelsplaying);
printf("Channels Playing %2d : Pan = %.02f\r", channelsplaying, pan);
}
fflush(stdout);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = dsplowpass->release();
ERRCHECK(result);
result = dspchorus->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
effects_cpp: main.cpp
g++ -O3 -o effects main.cpp ../../api/lib/libfmodex.so -pthread
effects_c: main.c
g++ -O3 -o effects main.c ../../api/lib/libfmodex.so -pthread
run:
./effects
clean:
rm -f effects

View File

@ -1,333 +0,0 @@
/*===============================================================================================
Effects Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to apply some of the built in software effects to sounds.
This example filters the global mix. All software sounds played here would be filtered in the
same way.
To filter per channel, and not have other channels affected, simply replace FMOD_System_AddDSP with
FMOD_Channel_AddDSP.
Note in this example you don't have to add and remove units each time, you could simply add them
all at the start then use FMOD_DSP_SetActive to toggle them on and off.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_dsp.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *sound = 0;
FMOD_CHANNEL *channel = 0;
FMOD_DSP *dsplowpass = 0;
FMOD_DSP *dsphighpass = 0;
FMOD_DSP *dspecho = 0;
FMOD_DSP *dspflange = 0;
FMOD_DSP *dspdistortion = 0;
FMOD_DSP *dspchorus = 0;
FMOD_DSP *dspparameq = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound);
ERRCHECK(result);
printf("=================================================================\n");
printf("Effects Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=================================================================\n");
printf("\n");
printf("Press SPACE to paused/unpause sound.\n");
printf("Press 1 to toggle dsplowpass effect.\n");
printf("Press 2 to toggle dsphighpass effect.\n");
printf("Press 3 to toggle dspecho effect.\n");
printf("Press 4 to toggle dspflange effect.\n");
printf("Press 5 to toggle dspdistortion effect.\n");
printf("Press 6 to toggle dspchorus effect.\n");
printf("Press 7 to toggle dspparameq effect.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Create some effects to play with.
*/
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_HIGHPASS, &dsphighpass);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_ECHO, &dspecho);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_FLANGE, &dspflange);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_DISTORTION, &dspdistortion);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_CHORUS, &dspchorus);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_PARAMEQ, &dspparameq);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
ERRCHECK(result);
paused = !paused;
result = FMOD_Channel_SetPaused(channel, paused);
ERRCHECK(result);
break;
}
case '1' :
{
int active;
result = FMOD_DSP_GetActive(dsplowpass, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dsplowpass);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dsplowpass, 0);
ERRCHECK(result);
}
break;
}
case '2' :
{
int active;
result = FMOD_DSP_GetActive(dsphighpass, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dsphighpass);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dsphighpass, 0);
ERRCHECK(result);
}
break;
}
case '3' :
{
int active;
result = FMOD_DSP_GetActive(dspecho, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dspecho);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dspecho, 0);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dspecho, FMOD_DSP_ECHO_DELAY, 50.0f);
ERRCHECK(result);
}
break;
}
case '4' :
{
int active;
result = FMOD_DSP_GetActive(dspflange, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dspflange);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dspflange, 0);
ERRCHECK(result);
}
break;
}
case '5' :
{
int active;
result = FMOD_DSP_GetActive(dspdistortion, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dspdistortion);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dspdistortion, 0);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dspdistortion, FMOD_DSP_DISTORTION_LEVEL, 0.8f);
ERRCHECK(result);
}
break;
}
case '6' :
{
int active;
result = FMOD_DSP_GetActive(dspchorus, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dspchorus);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dspchorus, 0);
ERRCHECK(result);
}
break;
}
case '7' :
{
int active;
result = FMOD_DSP_GetActive(dspparameq, &active);
ERRCHECK(result);
if (active)
{
result = FMOD_DSP_Remove(dspparameq);
ERRCHECK(result);
}
else
{
result = FMOD_System_AddDSP(system, dspparameq, 0);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dspparameq, FMOD_DSP_PARAMEQ_CENTER, 5000.0f);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dspparameq, FMOD_DSP_PARAMEQ_GAIN, 0.0f);
ERRCHECK(result);
}
break;
}
}
}
FMOD_System_Update(system);
{
int paused = 0;
int dsplowpass_active;
int dsphighpass_active;
int dspecho_active;
int dspflange_active;
int dspdistortion_active;
int dspchorus_active;
int dspparameq_active;
FMOD_DSP_GetActive(dsplowpass , &dsplowpass_active);
FMOD_DSP_GetActive(dsphighpass , &dsphighpass_active);
FMOD_DSP_GetActive(dspecho , &dspecho_active);
FMOD_DSP_GetActive(dspflange , &dspflange_active);
FMOD_DSP_GetActive(dspdistortion, &dspdistortion_active);
FMOD_DSP_GetActive(dspchorus , &dspchorus_active);
FMOD_DSP_GetActive(dspparameq , &dspparameq_active);
if (channel)
{
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
printf("%s : lowpass[%c] highpass[%c] echo[%c] flange[%c] dist[%c] chorus[%c] parameq[%c]\r",
paused ? "Paused " : "Playing",
dsplowpass_active ? 'x' : ' ',
dsphighpass_active ? 'x' : ' ',
dspecho_active ? 'x' : ' ',
dspflange_active ? 'x' : ' ',
dspdistortion_active ? 'x' : ' ',
dspchorus_active ? 'x' : ' ',
dspparameq_active ? 'x' : ' ');
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,333 +0,0 @@
/*===============================================================================================
Effects Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to apply some of the built in software effects to sounds.
This example filters the global mix. All software sounds played here would be filtered in the
same way.
To filter per channel, and not have other channels affected, simply replace system->addDSP with
channel->addDSP.
Note in this example you don't have to add and remove units each time, you could simply add them
all at the start then use DSP::setActive to toggle them on and off.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_dsp.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD::DSP *dsplowpass = 0;
FMOD::DSP *dsphighpass = 0;
FMOD::DSP *dspecho = 0;
FMOD::DSP *dspflange = 0;
FMOD::DSP *dspdistortion = 0;
FMOD::DSP *dspchorus = 0;
FMOD::DSP *dspparameq = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound);
ERRCHECK(result);
printf("=================================================================\n");
printf("Effects Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=================================================================\n");
printf("\n");
printf("Press SPACE to paused/unpause sound.\n");
printf("Press 1 to toggle dsplowpass effect.\n");
printf("Press 2 to toggle dsphighpass effect.\n");
printf("Press 3 to toggle dspecho effect.\n");
printf("Press 4 to toggle dspflange effect.\n");
printf("Press 5 to toggle dspdistortion effect.\n");
printf("Press 6 to toggle dspchorus effect.\n");
printf("Press 7 to toggle dspparameq effect.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Create some effects to play with.
*/
result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_HIGHPASS, &dsphighpass);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_DISTORTION, &dspdistortion);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_CHORUS, &dspchorus);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_PARAMEQ, &dspparameq);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
ERRCHECK(result);
paused = !paused;
result = channel->setPaused(paused);
ERRCHECK(result);
break;
}
case '1' :
{
bool active;
result = dsplowpass->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dsplowpass->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dsplowpass, 0);
ERRCHECK(result);
}
break;
}
case '2' :
{
bool active;
result = dsphighpass->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dsphighpass->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dsphighpass, 0);
ERRCHECK(result);
}
break;
}
case '3' :
{
bool active;
result = dspecho->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dspecho->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dspecho, 0);
ERRCHECK(result);
result = dspecho->setParameter(FMOD_DSP_ECHO_DELAY, 50.0f);
ERRCHECK(result);
}
break;
}
case '4' :
{
bool active;
result = dspflange->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dspflange->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dspflange, 0);
ERRCHECK(result);
}
break;
}
case '5' :
{
bool active;
result = dspdistortion->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dspdistortion->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dspdistortion, 0);
ERRCHECK(result);
result = dspdistortion->setParameter(FMOD_DSP_DISTORTION_LEVEL, 0.8f);
ERRCHECK(result);
}
break;
}
case '6' :
{
bool active;
result = dspchorus->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dspchorus->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dspchorus, 0);
ERRCHECK(result);
}
break;
}
case '7' :
{
bool active;
result = dspparameq->getActive(&active);
ERRCHECK(result);
if (active)
{
result = dspparameq->remove();
ERRCHECK(result);
}
else
{
result = system->addDSP(dspparameq, 0);
ERRCHECK(result);
result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_CENTER, 5000.0f);
ERRCHECK(result);
result = dspparameq->setParameter(FMOD_DSP_PARAMEQ_GAIN, 0.0f);
ERRCHECK(result);
}
break;
}
}
}
system->update();
{
bool paused = 0;
bool dsplowpass_active;
bool dsphighpass_active;
bool dspecho_active;
bool dspflange_active;
bool dspdistortion_active;
bool dspchorus_active;
bool dspparameq_active;
dsplowpass ->getActive(&dsplowpass_active);
dsphighpass ->getActive(&dsphighpass_active);
dspecho ->getActive(&dspecho_active);
dspflange ->getActive(&dspflange_active);
dspdistortion->getActive(&dspdistortion_active);
dspchorus ->getActive(&dspchorus_active);
dspparameq ->getActive(&dspparameq_active);
if (channel)
{
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
printf("%s : lowpass[%c] highpass[%c] echo[%c] flange[%c] dist[%c] chorus[%c] parameq[%c]\r",
paused ? "Paused " : "Playing",
dsplowpass_active ? 'x' : ' ',
dsphighpass_active ? 'x' : ' ',
dspecho_active ? 'x' : ' ',
dspflange_active ? 'x' : ' ',
dspdistortion_active ? 'x' : ' ',
dspchorus_active ? 'x' : ' ',
dspparameq_active ? 'x' : ' ');
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
filecallbacks_cpp: main.cpp
g++ -O3 -o filecallbacks main.cpp ../../api/lib/libfmodex.so -pthread
filecallbacks_c: main.c
g++ -O3 -o filecallbacks main.c ../../api/lib/libfmodex.so -pthread
run:
./filecallbacks
clean:
rm -f filecallbacks

View File

@ -1,230 +0,0 @@
/*===============================================================================================
File Callbacks Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example is a modified version of the playstream example.
It shows the correct way declare and handle fmod file callbacks with System::setFileSystem.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
/*
TIPS:
1. use F_CALLBACK. Do NOT force cast your own function to fmod's callback type.
2. return FMOD_ERR_FILE_NOTFOUND in open as required.
3. return number of bytes read in read callback. Do not get the size and count
around the wrong way in fread for example, this would return 1 instead of the number of bytes read.
QUESTIONS:
1. Why does fmod seek to the end and read? Because it is looking for ID3V1 tags.
Use FMOD_IGNORETAGS in FMOD_System_CreateSound / FMOD_System_CreateStream if you don't like this behaviour.
*/
FMOD_RESULT F_CALLBACK myopen(const char *name, int unicode, unsigned int *filesize, void **handle, void **userdata)
{
if (name)
{
FILE *fp;
fp = fopen(name, "rb");
if (!fp)
{
return FMOD_ERR_FILE_NOTFOUND;
}
fseek(fp, 0, SEEK_END);
*filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
*userdata = (void *)0x12345678;
*handle = fp;
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myclose(void *handle, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
fclose((FILE *)handle);
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myread(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
if (bytesread)
{
*bytesread = (int)fread(buffer, 1, sizebytes, (FILE *)handle);
if (*bytesread < sizebytes)
{
return FMOD_ERR_FILE_EOF;
}
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myseek(void *handle, unsigned int pos, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
fseek((FILE *)handle, pos, SEEK_SET);
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_SetFileSystem(system, myopen, myclose, myread, myseek, 0, 0, 2048);
ERRCHECK(result);
result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
ERRCHECK(result);
printf("====================================================================\n");
printf("PlayStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("====================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
unsigned int ms;
unsigned int lenms;
int playing;
int paused;
FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,229 +0,0 @@
/*===============================================================================================
File Callbacks Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example is a modified version of the playstream example.
It shows the correct way declare and handle fmod file callbacks with System::setFileSystem.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
/*
TIPS:
1. use F_CALLBACK. Do NOT force cast your own function to fmod's callback type.
2. return FMOD_ERR_FILE_NOTFOUND in open as required.
3. return number of bytes read in read callback. Do not get the size and count
around the wrong way in fread for example, this would return 1 instead of the number of bytes read.
QUESTIONS:
1. Why does fmod seek to the end and read? Because it is looking for ID3V1 tags.
Use FMOD_IGNORETAGS in System::createSound / System::createStream if you don't like this behaviour.
*/
FMOD_RESULT F_CALLBACK myopen(const char *name, int unicode, unsigned int *filesize, void **handle, void **userdata)
{
if (name)
{
FILE *fp;
fp = fopen(name, "rb");
if (!fp)
{
return FMOD_ERR_FILE_NOTFOUND;
}
fseek(fp, 0, SEEK_END);
*filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
*userdata = (void *)0x12345678;
*handle = fp;
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myclose(void *handle, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
fclose((FILE *)handle);
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myread(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
if (bytesread)
{
*bytesread = (int)fread(buffer, 1, sizebytes, (FILE *)handle);
if (*bytesread < sizebytes)
{
return FMOD_ERR_FILE_EOF;
}
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myseek(void *handle, unsigned int pos, void *userdata)
{
if (!handle)
{
return FMOD_ERR_INVALID_PARAM;
}
fseek((FILE *)handle, pos, SEEK_SET);
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->setFileSystem(myopen, myclose, myread, myseek, 0, 0, 2048);
ERRCHECK(result);
result = system->createStream("../media/wave.mp3", FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
ERRCHECK(result);
printf("========================================================================\n");
printf("File Callbacks Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("========================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
generatetone_cpp: main.cpp
g++ -O3 -o generatetone main.cpp ../../api/lib/libfmodex.so
generatetone_c: main.c
g++ -O3 -o generatetone main.c ../../api/lib/libfmodex.so
run:
./generatetone
clean:
rm -f generatetone

View File

@ -1,230 +0,0 @@
/*===============================================================================================
GenerateTone Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how simply play generated tones using FMOD_System_PlayDSP instead of
manually connecting and disconnecting DSP units.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_CHANNEL *channel = 0;
FMOD_DSP *dsp = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Create DSP units for each type of noise we want.
*/
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_OSCILLATOR, &dsp);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_RATE, 440.0f);
ERRCHECK(result);
printf("======================================================================\n");
printf("GenerateTone Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n\n");
printf("\n");
printf("Press '1' to play a sine wave\n");
printf("Press '2' to play a square wave\n");
printf("Press '3' to play a triangle wave\n");
printf("Press '4' to play a saw wave\n");
printf("Press '5' to play a white noise\n");
printf("Press 's' to stop channel\n");
printf("\n");
printf("Press 'v'/'V' to change channel volume\n");
printf("Press 'f'/'F' to change channel frequency\n");
printf("Press '['/']' to change channel pan\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
FMOD_Channel_SetVolume(channel, 0.5f);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 0);
ERRCHECK(result);
FMOD_Channel_SetPaused(channel, FALSE);
break;
}
case '2' :
{
result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
FMOD_Channel_SetVolume(channel, 0.125f);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 1);
ERRCHECK(result);
FMOD_Channel_SetPaused(channel, FALSE);
break;
}
case '3' :
{
result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
FMOD_Channel_SetVolume(channel, 0.5f);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 2);
ERRCHECK(result);
FMOD_Channel_SetPaused(channel, FALSE);
break;
}
case '4' :
{
result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
FMOD_Channel_SetVolume(channel, 0.125f);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 4);
ERRCHECK(result);
FMOD_Channel_SetPaused(channel, FALSE);
break;
}
case '5' :
{
result = FMOD_System_PlayDSP(system, FMOD_CHANNEL_REUSE, dsp, TRUE, &channel);
FMOD_Channel_SetVolume(channel, 0.25f);
result = FMOD_DSP_SetParameter(dsp, FMOD_DSP_OSCILLATOR_TYPE, 5);
ERRCHECK(result);
FMOD_Channel_SetPaused(channel, FALSE);
break;
}
case 's' :
{
FMOD_Channel_Stop(channel);
break;
}
case 'v' :
{
float volume;
FMOD_Channel_GetVolume(channel, &volume);
volume -= 0.1f;
FMOD_Channel_SetVolume(channel, volume);
break;
}
case 'V' :
{
float volume;
FMOD_Channel_GetVolume(channel, &volume);
volume += 0.1f;
FMOD_Channel_SetVolume(channel, volume);
break;
}
case 'f' :
{
float frequency;
FMOD_Channel_GetFrequency(channel, &frequency);
frequency -= 500.0f;
FMOD_Channel_SetFrequency(channel, frequency);
break;
}
case 'F' :
{
float frequency;
FMOD_Channel_GetFrequency(channel, &frequency);
frequency += 500.0f;
FMOD_Channel_SetFrequency(channel, frequency);
break;
}
case '[' :
{
float pan;
FMOD_Channel_GetPan(channel, &pan);
pan -= 0.1f;
FMOD_Channel_SetPan(channel, pan);
break;
}
case ']' :
{
float pan;
FMOD_Channel_GetPan(channel, &pan);
pan += 0.1f;
FMOD_Channel_SetPan(channel, pan);
break;
}
}
}
FMOD_System_Update(system);
{
float frequency = 0, volume = 0, pan = 0;
int playing = FALSE;
if (channel)
{
FMOD_Channel_GetFrequency(channel, &frequency);
FMOD_Channel_GetVolume(channel, &volume);
FMOD_Channel_GetPan(channel, &pan);
FMOD_Channel_IsPlaying(channel, &playing);
}
printf("Channel %s : Frequency %.1f Volume %.1f Pan %.1f \r", playing ? "playing" : "stopped", frequency, volume, pan);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_DSP_Release(dsp);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,234 +0,0 @@
/*===============================================================================================
GenerateTone Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how simply play generated tones using FMOD::System::payDSP instead of
manually connecting and disconnecting DSP units.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Channel *channel = 0;
FMOD::DSP *dsp = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Create an oscillator DSP unit for the tone.
*/
result = system->createDSPByType(FMOD_DSP_TYPE_OSCILLATOR, &dsp);
ERRCHECK(result);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_RATE, 440.0f);
ERRCHECK(result);
printf("======================================================================\n");
printf("GenerateTone Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n\n");
printf("\n");
printf("Press '1' to play a sine wave\n");
printf("Press '2' to play a square wave\n");
printf("Press '3' to play a triangle wave\n");
printf("Press '4' to play a saw wave\n");
printf("Press '5' to play a white noise\n");
printf("Press 's' to stop channel\n");
printf("\n");
printf("Press 'v'/'V' to change channel volume\n");
printf("Press 'f'/'F' to change channel frequency\n");
printf("Press '['/']' to change channel pan\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = system->playDSP(FMOD_CHANNEL_REUSE, dsp, true, &channel);
channel->setVolume(0.5f);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 0);
ERRCHECK(result);
channel->setPaused(false);
break;
}
case '2' :
{
result = system->playDSP(FMOD_CHANNEL_REUSE, dsp, true, &channel);
channel->setVolume(0.125f);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 1);
ERRCHECK(result);
channel->setPaused(false);
break;
}
case '3' :
{
result = system->playDSP(FMOD_CHANNEL_REUSE, dsp, true, &channel);
channel->setVolume(0.5f);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 2);
ERRCHECK(result);
channel->setPaused(false);
break;
}
case '4' :
{
result = system->playDSP(FMOD_CHANNEL_REUSE, dsp, true, &channel);
channel->setVolume(0.125f);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 4);
ERRCHECK(result);
channel->setPaused(false);
break;
}
case '5' :
{
result = system->playDSP(FMOD_CHANNEL_REUSE, dsp, true, &channel);
channel->setVolume(0.25f);
result = dsp->setParameter(FMOD_DSP_OSCILLATOR_TYPE, 5);
ERRCHECK(result);
channel->setPaused(false);
break;
}
case 's' :
{
channel->stop();
break;
}
case 'v' :
{
float volume;
channel->getVolume(&volume);
volume -= 0.1f;
channel->setVolume(volume);
break;
}
case 'V' :
{
float volume;
channel->getVolume(&volume);
volume += 0.1f;
channel->setVolume(volume);
break;
}
case 'f' :
{
float frequency;
channel->getFrequency(&frequency);
frequency -= 500.0f;
channel->setFrequency(frequency);
break;
}
case 'F' :
{
float frequency;
channel->getFrequency(&frequency);
frequency += 500.0f;
channel->setFrequency(frequency);
break;
}
case '[' :
{
float pan;
channel->getPan(&pan);
pan -= 0.1f;
channel->setPan(pan);
break;
}
case ']' :
{
float pan;
channel->getPan(&pan);
pan += 0.1f;
channel->setPan(pan);
break;
}
}
}
system->update();
{
float frequency = 0, volume = 0, pan = 0;
bool playing = false;
if (channel)
{
channel->getFrequency(&frequency);
channel->getVolume(&volume);
channel->getPan(&pan);
channel->isPlaying(&playing);
}
printf("Channel %s : Frequency %.1f Volume %.1f Pan %.1f \r", playing ? "playing" : "stopped", frequency, volume, pan);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = dsp->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
loadfrommemory_cpp: main.cpp
g++ -O3 -o loadfrommemory main.cpp ../../api/lib/libfmodex.so -pthread
loadfrommemory_c: main.c
g++ -O3 -o loadfrommemory main.c ../../api/lib/libfmodex.so -pthread
run:
./loadfrommemory
clean:
rm -f loadfrommemory

View File

@ -1,219 +0,0 @@
/*===============================================================================================
Load from memory example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example is simply a variant of the play sound example, but it loads the data into memory
then uses the 'load from memory' feature of System::createSound.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
void LoadFileIntoMemory(const char *name, void **buff, int *length)
{
FILE *fp = fopen(name, "rb");
fseek(fp, 0, SEEK_END);
*length = ftell(fp);
fseek(fp, 0, SEEK_SET);
*buff = malloc(*length);
fread(*buff, *length, 1, fp);
fclose(fp);
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1, *sound2, *sound3;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
void *buff = 0;
int length = 0;
FMOD_CREATESOUNDEXINFO exinfo;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
LoadFileIntoMemory("../media/drumloop.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound1);
ERRCHECK(result);
result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
LoadFileIntoMemory("../media/jaguar.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
LoadFileIntoMemory("../media/swish.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
printf("==========================================================================\n");
printf("Load from memory example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==========================================================================\n");
printf("\n");
printf("Press '1' to play a mono sound using hardware mixing\n");
printf("Press '2' to play a mono sound using software mixing\n");
printf("Press '3' to play a stereo sound using hardware mixing\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
ERRCHECK(result);
break;
}
case '2' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, 0, &channel);
ERRCHECK(result);
break;
}
case '3' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, 0, &channel);
ERRCHECK(result);
break;
}
}
}
FMOD_System_Update(system);
{
unsigned int ms = 0;
unsigned int lenms = 0;
int playing = 0;
int paused = 0;
int channelsplaying = 0;
if (channel)
{
FMOD_SOUND *currentsound = 0;
result = FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_Channel_GetCurrentSound(channel, &currentsound);
if (currentsound)
{
result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
result = FMOD_Sound_GetLength(sound1, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
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);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound1);
ERRCHECK(result);
result = FMOD_Sound_Release(sound2);
ERRCHECK(result);
result = FMOD_Sound_Release(sound3);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,213 +0,0 @@
/*===============================================================================================
Load from memory example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example is simply a variant of the play sound example, but it loads the data into memory
then uses the 'load from memory' feature of System::createSound.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
void LoadFileIntoMemory(const char *name, void **buff, int *length)
{
FILE *fp = fopen(name, "rb");
fseek(fp, 0, SEEK_END);
*length = ftell(fp);
fseek(fp, 0, SEEK_SET);
*buff = malloc(*length);
fread(*buff, *length, 1, fp);
fclose(fp);
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2, *sound3;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
void *buff = 0;
int length = 0;
FMOD_CREATESOUNDEXINFO exinfo;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
LoadFileIntoMemory("../media/drumloop.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound1);
ERRCHECK(result);
result = sound1->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
LoadFileIntoMemory("../media/jaguar.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = system->createSound((const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound2);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
LoadFileIntoMemory("../media/swish.wav", &buff, &length);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = length;
result = system->createSound((const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound3);
ERRCHECK(result);
free(buff); // don't need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!
printf("==========================================================================\n");
printf("Load from memory example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==========================================================================\n");
printf("\n");
printf("Press '1' to play a mono sound using hardware mixing\n");
printf("Press '2' to play a mono sound using software mixing\n");
printf("Press '3' to play a stereo sound using hardware mixing\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
ERRCHECK(result);
break;
}
case '2' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
ERRCHECK(result);
break;
}
case '3' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel);
ERRCHECK(result);
break;
}
}
}
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;
if (channel)
{
FMOD::Sound *currentsound = 0;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
channel->getCurrentSound(&currentsound);
if (currentsound)
{
result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
system->getChannelsPlaying(&channelsplaying);
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);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
#EXTM3U
#EXTINF:11,Unknown - FMOD example wave
wave.mp3
#EXTINF:1,swish
swish.wav
#EXTINF:2,stereo
stereo.ogg
#EXTINF:1,jaguar
jaguar.wav
#EXTINF:0,drumloop
drumloop.wav

View File

@ -1 +0,0 @@
400b6a591c4687406c5b5943181e083952872de7

View File

@ -1,11 +0,0 @@
multiplesoundcard_cpp: main.cpp
g++ -O3 -o multiplesoundcard main.cpp ../../api/lib/libfmodex.so -pthread
multiplesoundcard_c: main.c
g++ -O3 -o multiplesoundcard main.c ../../api/lib/libfmodex.so -pthread
run:
./multiplesoundcard
clean:
rm -f multiplesoundcard

View File

@ -1,226 +0,0 @@
/*===============================================================================================
MultipleSoundCard Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to simply load and play multiple sounds. This is about the simplest
use of FMOD.
This makes FMOD decode the into memory when it loads. If the sounds are big and possibly take
up a lot of ram, then it would be better to use the FMOD_CREATESTREAM flag so that it is
streamed in realtime as it plays.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *systemA, *systemB;
FMOD_SOUND *soundA, *soundB;
FMOD_CHANNEL *channelA = 0, *channelB = 0;
FMOD_RESULT result;
int key, count, numdrivers, driver;
unsigned int version;
/*
Create Sound Card A
*/
result = FMOD_System_Create(&systemA);
ERRCHECK(result);
result = FMOD_System_GetVersion(systemA, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_GetNumDrivers(systemA, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Select soundcard A\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetDriverInfo(systemA, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
printf("\n");
result = FMOD_System_SetDriver(systemA, driver);
ERRCHECK(result);
result = FMOD_System_Init(systemA, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Create Sound Card B
*/
result = FMOD_System_Create(&systemB);
ERRCHECK(result);
result = FMOD_System_GetVersion(systemB, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_GetNumDrivers(systemB, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Select soundcard B\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetDriverInfo(systemB, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
printf("\n");
result = FMOD_System_SetDriver(systemB, driver);
ERRCHECK(result);
result = FMOD_System_Init(systemB, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Load 1 sample into each soundcard.
*/
result = FMOD_System_CreateSound(systemA, "../media/drumloop.wav", FMOD_HARDWARE, 0, &soundA);
ERRCHECK(result);
result = FMOD_Sound_SetMode(soundA, FMOD_LOOP_OFF);
ERRCHECK(result);
result = FMOD_System_CreateSound(systemB, "../media/jaguar.wav", FMOD_HARDWARE, 0,&soundB);
ERRCHECK(result);
printf("======================================================================\n");
printf("MultipleSoundCard Example. Copyright (c) Firelight Technologies 2004.\n");
printf("======================================================================\n");
printf("\n");
printf("Press '1' to play a sound on soundcard A\n");
printf("Press '2' to play a sound on soundcard B\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
int channelsplayingA = 0;
int channelsplayingB = 0;
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = FMOD_System_PlaySound(systemA, FMOD_CHANNEL_FREE, soundA, 0, &channelA);
ERRCHECK(result);
break;
}
case '2' :
{
result = FMOD_System_PlaySound(systemB, FMOD_CHANNEL_FREE, soundB, 0, &channelB);
ERRCHECK(result);
break;
}
}
}
FMOD_System_Update(systemA);
FMOD_System_Update(systemB);
FMOD_System_GetChannelsPlaying(systemA, &channelsplayingA);
FMOD_System_GetChannelsPlaying(systemB, &channelsplayingB);
printf("Channels Playing on A %2d. Channels Playing on B %2d.\r", channelsplayingA, channelsplayingB);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(soundA);
ERRCHECK(result);
result = FMOD_System_Close(systemA);
ERRCHECK(result);
result = FMOD_System_Release(systemA);
ERRCHECK(result);
result = FMOD_Sound_Release(soundB);
ERRCHECK(result);
result = FMOD_System_Close(systemB);
ERRCHECK(result);
result = FMOD_System_Release(systemB);
ERRCHECK(result);
return 0;
}

View File

@ -1,228 +0,0 @@
/*===============================================================================================
MultipleSoundCard Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play sounds on 2 different sound cards from the same application.
It creates 2 FMOD::System objects, selects a different sound device for each, then allows
the user to play 1 sound on 1 soundcard and another sound on another soundcard.
Note that sounds created on device A cannot be played on device B and vice versa.
You will have to each sound separately for each sound card. Device A might load the sound
into its own memory so obviously device B wouldnt be able to play it.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *systemA, *systemB;
FMOD::Sound *soundA, *soundB;
FMOD::Channel *channelA = 0, *channelB = 0;;
FMOD_RESULT result;
int key, count, numdrivers, driver;
unsigned int version;
/*
Create Sound Card A
*/
result = FMOD::System_Create(&systemA);
ERRCHECK(result);
result = systemA->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = systemA->getNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Select soundcard A\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = systemA->getDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
printf("\n");
result = systemA->setDriver(driver);
ERRCHECK(result);
result = systemA->init(32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Create Sound Card B
*/
result = FMOD::System_Create(&systemB);
ERRCHECK(result);
result = systemB->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = systemB->getNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Select soundcard B\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = systemB->getDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
printf("\n");
result = systemB->setDriver(driver);
ERRCHECK(result);
result = systemB->init(32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Load 1 sample into each soundcard.
*/
result = systemA->createSound("../media/drumloop.wav", FMOD_HARDWARE, 0, &soundA);
ERRCHECK(result);
result = soundA->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);
result = systemB->createSound("../media/jaguar.wav", FMOD_HARDWARE, 0, &soundB);
ERRCHECK(result);
printf("======================================================================\n");
printf("MultipleSoundCard Example. Copyright (c) Firelight Technologies 2004.\n");
printf("======================================================================\n");
printf("\n");
printf("Press '1' to play a sound on soundcard A\n");
printf("Press '2' to play a sound on soundcard B\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
int channelsplayingA = 0;
int channelsplayingB = 0;
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = systemA->playSound(FMOD_CHANNEL_FREE, soundA, 0, &channelA);
ERRCHECK(result);
break;
}
case '2' :
{
result = systemB->playSound(FMOD_CHANNEL_FREE, soundB, 0, &channelB);
ERRCHECK(result);
break;
}
}
}
systemA->update();
systemB->update();
systemA->getChannelsPlaying(&channelsplayingA);
systemB->getChannelsPlaying(&channelsplayingB);
printf("Channels Playing on A %2d. Channels Playing on B %2d.\r", channelsplayingA, channelsplayingB);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = soundA->release();
ERRCHECK(result);
result = systemA->close();
ERRCHECK(result);
result = systemA->release();
ERRCHECK(result);
result = soundB->release();
ERRCHECK(result);
result = systemB->close();
ERRCHECK(result);
result = systemB->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
multispeakeroutput_cpp: main.cpp
g++ -O3 -o multispeakeroutput main.cpp ../../api/lib/libfmodex.so -pthread
multispeakeroutput_c: main.c
g++ -O3 -o multispeakeroutput main.c ../../api/lib/libfmodex.so -pthread
run:
./multispeakeroutput
clean:
rm -f multispeakeroutput

View File

@ -1,335 +0,0 @@
/*===============================================================================================
Multi Speaker Output Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play sounds in multiple speakers, and also how to even assign
sound subchannels, such as those in a stereo sound to different individual speakers.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1, *sound2;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
/*
Multichannel only supported in ALSA mode in 5.1 and 7.1.
If the user doesn't have 5.1 speakers then only the speakers
they have will be audible.
*/
result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ALSA);
ERRCHECK(result);
FMOD_System_SetSpeakerMode(system, FMOD_SPEAKERMODE_5POINT1);
ERRCHECK(result);
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound1);
ERRCHECK(result);
result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
result = FMOD_System_CreateSound(system, "../media/stereo.ogg", FMOD_SOFTWARE | FMOD_2D, 0, &sound2);
ERRCHECK(result);
printf("==============================================================================\n");
printf("Multi Speaker Output Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==============================================================================\n");
printf("\n");
printf("Note! You must have your speaker configuration set up correctly\n");
printf(" in the windows control panel for this to work properly.\n");
printf("\n");
printf("Press '1' to play a mono sound on the FRONT LEFT speaker.\n");
printf("Press '2' to play a mono sound on the FRONT RIGHT speaker.\n");
printf("Press '3' to play a mono sound on the CENTER speaker.\n");
printf("Press '4' to play a mono sound on the REAR LEFT speaker.\n");
printf("Press '5' to play a mono sound on the REAR RIGHT speaker.\n");
printf("Press '6' to play a mono sound on the SIDE LEFT speaker.\n");
printf("Press '7' to play a mono sound on the SIDE RIGHT speaker.\n");
printf("Press '8' to play a stereo sound on the front speakers.\n");
printf("Press '9' to play a stereo sound on the front speakers but channel swapped.\n");
printf("Press '0' to play the right part of a stereo sound on the CENTER speaker.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 1.0f, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '2' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 1.0f, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '3' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 1.0f, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '4' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 1.0f, 0, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '5' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 1.0f, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '6' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 1.0f, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '7' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, TRUE, &channel);
ERRCHECK(result);
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 1.0f);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '8' :
{
float levels[2] = { 0, 1.0f };
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
ERRCHECK(result);
/*
By default a stereo sound would play in all right and all left speakers, so this forces it to just the front.
*/
result = FMOD_Channel_SetSpeakerMix(channel, 1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '9' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
ERRCHECK(result);
/*
Clear out all speakers first.
*/
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Put the left channel of the sound in the right speaker.
*/
{
float levels[2] = { 0, 1.0f }; /* This array represents the source stereo sound. l/r */
result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_LEFT, levels, 2);
ERRCHECK(result);
}
/*
Put the right channel of the sound in the left speaker.
*/
{
float levels[2] = { 1.0f, 0 }; /* This array represents the source stereo sound. l/r */
result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_RIGHT, levels, 2);
ERRCHECK(result);
}
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
case '0' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, TRUE, &channel);
ERRCHECK(result);
/*
Clear out all speakers first.
*/
result = FMOD_Channel_SetSpeakerMix(channel, 0, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Put the left channel of the sound in the right speaker.
*/
{
float levels[2] = { 0, 1.0f }; /* This array represents the source stereo sound. l/r */
result = FMOD_Channel_SetSpeakerLevels(channel, FMOD_SPEAKER_FRONT_CENTER, levels, 2);
ERRCHECK(result);
}
result = FMOD_Channel_SetPaused(channel, FALSE);
ERRCHECK(result);
break;
}
}
}
FMOD_System_Update(system);
{
unsigned int ms = 0;
unsigned int lenms = 0;
int playing = FALSE;
int paused = FALSE;
int channelsplaying = 0;
if (channel)
{
FMOD_SOUND *currentsound = 0;
result = FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_Channel_GetCurrentSound(channel, &currentsound);
if (currentsound)
{
result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
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);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound1);
ERRCHECK(result);
result = FMOD_Sound_Release(sound2);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,337 +0,0 @@
/*===============================================================================================
Multi Speaker Output Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play sounds in multiple speakers, and also how to even assign
sound subchannels, such as those in a stereo sound to different individual speakers.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
/*
Multichannel only supported in ALSA mode in 5.1 and 7.1.
If the user doesn't have 5.1 speakers then only the speakers
they have will be audible.
*/
result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
ERRCHECK(result);
result = system->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_2D, 0, &sound1);
ERRCHECK(result);
result = sound1->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);
result = system->createSound("../media/stereo.ogg", FMOD_SOFTWARE | FMOD_2D, 0, &sound2);
ERRCHECK(result);
printf("==============================================================================\n");
printf("Multi Speaker Output Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==============================================================================\n");
printf("\n");
printf("Note! You must have your speaker configuration set up correctly\n");
printf(" in the windows control panel for this to work properly.\n");
printf("\n");
printf("Press '1' to play a mono sound on the FRONT LEFT speaker.\n");
printf("Press '2' to play a mono sound on the FRONT RIGHT speaker.\n");
printf("Press '3' to play a mono sound on the CENTER speaker.\n");
printf("Press '4' to play a mono sound on the REAR LEFT speaker.\n");
printf("Press '5' to play a mono sound on the REAR RIGHT speaker.\n");
printf("Press '6' to play a mono sound on the SIDE LEFT speaker.\n");
printf("Press '7' to play a mono sound on the SIDE RIGHT speaker.\n");
printf("Press '8' to play a stereo sound on the front speakers.\n");
printf("Press '9' to play a stereo sound on the front speakers but channel swapped.\n");
printf("Press '0' to play the right part of a stereo sound on the CENTER speaker.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(1.0f, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '2' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 1.0f, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '3' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 0, 1.0f, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '4' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 0, 0, 0, 1.0f, 0, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '5' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 0, 0, 0, 0, 1.0f, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '6' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 1.0f, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '7' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, true, &channel);
ERRCHECK(result);
result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 1.0f);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '8' :
{
float levels[2] = { 0, 1.0f };
result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
ERRCHECK(result);
/*
By default a stereo sound would play in all right and all left speakers, so this forces it to just the front.
*/
result = channel->setSpeakerMix(1.0f, 1.0f, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '9' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
ERRCHECK(result);
/*
Clear out all speakers first.
*/
result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Put the left channel of the sound in the right speaker.
*/
{
float levels[2] = { 0, 1.0f }; /* This array represents the source stereo sound. l/r */
result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_LEFT, levels, 2);
ERRCHECK(result);
}
/*
Put the right channel of the sound in the left speaker.
*/
{
float levels[2] = { 1.0f, 0 }; /* This array represents the source stereo sound. l/r */
result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_RIGHT, levels, 2);
ERRCHECK(result);
}
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
case '0' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound2, true, &channel);
ERRCHECK(result);
/*
Clear out all speakers first.
*/
result = channel->setSpeakerMix(0, 0, 0, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Put the left channel of the sound in the right speaker.
*/
{
float levels[2] = { 0, 1.0f }; /* This array represents the source stereo sound. l/r */
result = channel->setSpeakerLevels(FMOD_SPEAKER_FRONT_CENTER, levels, 2);
ERRCHECK(result);
}
result = channel->setPaused(false);
ERRCHECK(result);
break;
}
}
}
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = false;
bool paused = false;
int channelsplaying = 0;
if (channel)
{
FMOD::Sound *currentsound = 0;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
channel->getCurrentSound(&currentsound);
if (currentsound)
{
result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
system->getChannelsPlaying(&channelsplaying);
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);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
netstream_cpp: main.cpp
g++ -O3 -o netstream main.cpp ../../api/lib/libfmodex.so -pthread
netstream_c: main.c
g++ -O3 -o netstream main.c ../../api/lib/libfmodex.so -pthread
run:
./netstream
clean:
rm -f netstream

View File

@ -1,174 +0,0 @@
/*===============================================================================================
NetStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play streaming audio from the internet
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
printf("===================================================================\n");
printf("NetStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n\n");
if (argc < 2)
{
printf("Usage: netstream <url>\n");
printf("Example: netstream http://www.fmod.org/stream.mp3\n\n");
return -1;
}
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system,&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Bump up the file buffer size a little bit for netstreams (to account for lag). Decode buffer is left at default.
*/
result = FMOD_System_SetStreamBufferSize(system, 64*1024, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
printf("Press space to pause, Esc to quit\n\n");
/*
Main loop
*/
do
{
unsigned int ms = 0, percent = 0;
int playing = FALSE;
int paused = FALSE;
int starving = FALSE;
FMOD_OPENSTATE openstate;
if (!channel)
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
}
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
if (channel)
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
}
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
for (;;)
{
FMOD_TAG tag;
if (FMOD_Sound_GetTag(sound, 0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
}
}
result = FMOD_Channel_GetPaused(channel, &paused);
ERRCHECK(result);
result = FMOD_Channel_IsPlaying(channel, &playing);
ERRCHECK(result);
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
ERRCHECK(result);
}
result = FMOD_Sound_GetOpenState(sound, &openstate, &percent, &starving, 0);
ERRCHECK(result);
printf("Time %02d:%02d:%02d : %s : (%3d%%%) %s \r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, openstate == FMOD_OPENSTATE_BUFFERING ? "Buffering..." : openstate == FMOD_OPENSTATE_CONNECTING ? "Connecting..." : paused ? "Paused " : playing ? "Playing " : "Stopped ", percent, starving ? "STARVING" : " ");
Sleep(10);
} while (key != 27);
printf("\n");
printf("Shutting down.\n");
/*
If we pressed escape before it is ready, wait for it to finish opening before we release it.
*/
do
{
FMOD_OPENSTATE openstate;
result = FMOD_Sound_GetOpenState(sound, &openstate, 0, 0, 0);
ERRCHECK(result);
if (openstate == FMOD_OPENSTATE_READY)
{
break;
}
printf("Waiting for sound to finish opening before trying to release it....\r");
Sleep(10);
} while (1);
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,186 +0,0 @@
/*===============================================================================================
NetStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to play streaming audio from the internet
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
printf("===================================================================\n");
printf("NetStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n\n");
if (argc < 2)
{
printf("Usage: netstream <url>\n");
printf("Example: netstream http://www.fmod.org/stream.mp3\n\n");
return -1;
}
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Bump up the file buffer size a little bit for netstreams (to account for lag). Decode buffer is left at default.
*/
result = system->setStreamBufferSize(64*1024, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
printf("Press space to pause, Esc to quit\n\n");
/*
Main loop
*/
do
{
unsigned int ms = 0, percent = 0;
bool playing = false;
bool paused = false;
bool starving = false;
FMOD_OPENSTATE openstate;
if (!channel)
{
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
}
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
if (channel)
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
}
break;
}
}
}
system->update();
if (channel)
{
for (;;)
{
FMOD_TAG tag;
if (sound->getTag(0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, (char *)tag.data, tag.datalen);
}
}
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->isPlaying(&playing);
ERRCHECK(result);
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
ERRCHECK(result);
}
result = sound->getOpenState(&openstate, &percent, &starving, 0);
ERRCHECK(result);
channel->setMute(starving);
ERRCHECK(result);
printf("Time %02d:%02d:%02d : %s : (%3d%%) %s \r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, openstate == FMOD_OPENSTATE_BUFFERING ? "Buffering..." : openstate == FMOD_OPENSTATE_CONNECTING ? "Connecting..." : paused ? "Paused " : playing ? "Playing " : "Stopped ", percent, starving ? "STARVING" : " ");
fflush(stdout);
Sleep(10);
} while (key != 27);
printf("\n");
printf("Shutting down.\n");
if (channel)
{
result = channel->stop();
ERRCHECK(result);
}
/*
If we pressed escape before it is ready, wait for it to finish opening before we release it.
*/
do
{
FMOD_OPENSTATE openstate;
result = sound->getOpenState(&openstate, 0, 0, 0);
ERRCHECK(result);
if (openstate == FMOD_OPENSTATE_READY)
{
break;
}
printf("Waiting for sound to finish opening before trying to release it....\r");
fflush(stdout);
Sleep(10);
} while (1);
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
offlinedecoding_cpp: main.cpp
g++ -O3 -o offlinedecoding main.cpp ../../api/lib/libfmodex.so -pthread
offlinedecoding_c: main.c
g++ -O3 -o offlinedecoding main.c ../../api/lib/libfmodex.so -pthread
run:
./offlinedecoding
clean:
rm -f offlinedecoding

View File

@ -1,137 +0,0 @@
/*===============================================================================================
Offline Decoding Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how decode a file to PCM, without playing it.
It writes out the data as a raw data file.
The FMOD_System_CreateSound function uses FMOD_OPENONLY so that FMOD does not read any data
itself.
If this is uses then it is up to the user to use FMOD_Sound_ReadData to get the data out of
the file and into the destination buffer.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_RESULT result;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateStream(system, "../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
ERRCHECK(result);
printf("==========================================================================\n");
printf("Offline Decoding Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==========================================================================\n");
printf("\n");
printf("This program will open wave.mp3 and decode it into wave.raw using the\n");
printf("FMOD_Sound_ReadData function.\n");
printf("\n");
/*
Decode the sound and write it to a .raw file.
*/
{
void *data;
unsigned int length = 0, read;
unsigned int bytesread;
FILE *outfp;
#define CHUNKSIZE 4096
result = FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCMBYTES);
ERRCHECK(result);
outfp = fopen("output.raw", "wb");
if (!outfp)
{
printf("Error! Could not open output.raw output file.\n");
return 0;
}
data = malloc(CHUNKSIZE);
if (!data)
{
printf("Error! Failed to allocate %d bytes.\n", CHUNKSIZE);
return 0;
}
bytesread = 0;
do
{
result = FMOD_Sound_ReadData(sound, (char *)data, CHUNKSIZE, &read);
fwrite((char *)data, read, 1, outfp);
bytesread += read;
printf("writing %d bytes of %d to output.raw\r", bytesread, length);
}
while (result == FMOD_OK && read == CHUNKSIZE);
/*
Loop terminates when either
1. the read function returns an error. (ie FMOD_ERR_FILE_EOF etc).
2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
but this will not usually happen if FMOD_ACCURATETIME is used. (this will give the correct length for VBR formats)
*/
printf("\n");
if (outfp)
{
fclose(outfp);
}
}
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,135 +0,0 @@
/*===============================================================================================
Offline Decoding Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how decode a file to PCM, without playing it.
It writes out the data as a raw data file.
The System::createSound function uses FMOD_OPENONLY so that FMOD does not read any data
itself.
If this is uses then it is up to the user to use Sound::readData to get the data out of
the file and into the destination buffer.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD_RESULT result;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createStream("../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
ERRCHECK(result);
printf("==========================================================================\n");
printf("Offline Decoding Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==========================================================================\n");
printf("\n");
printf("This program will open wave.mp3 and decode it into wave.raw using the\n");
printf("Sound::readData function.\n");
printf("\n");
/*
Decode the sound and write it to a .raw file.
*/
{
void *data;
unsigned int length = 0, read;
unsigned int bytesread;
FILE *outfp;
#define CHUNKSIZE 4096
result = sound->getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
ERRCHECK(result);
outfp = fopen("output.raw", "wb");
if (!outfp)
{
printf("Error! Could not open output.raw output file.\n");
return 0;
}
data = malloc(CHUNKSIZE);
if (!data)
{
printf("Error! Failed to allocate %d bytes.\n", CHUNKSIZE);
return 0;
}
bytesread = 0;
do
{
result = sound->readData((char *)data, CHUNKSIZE, &read);
fwrite((char *)data, read, 1, outfp);
bytesread += read;
printf("writing %d bytes of %d to output.raw\r", bytesread, length);
}
while (result == FMOD_OK && read == CHUNKSIZE);
/*
Loop terminates when either
1. the read function returns an error. (ie FMOD_ERR_FILE_EOF etc).
2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
but this will not usually happen if FMOD_ACCURATETIME is used. (this will give the correct length for VBR formats)
*/
printf("\n");
if (outfp)
{
fclose(outfp);
}
}
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
pitchdetection_cpp: main.cpp
g++ -O3 -o pitchdetection main.cpp ../../api/lib/libfmodex.so -pthread
pitchdetection_c: main.c
g++ -O3 -o pitchdetection main.c ../../api/lib/libfmodex.so -pthread
run:
./pitchdetection
clean:
rm -f pitchdetection

View File

@ -1,309 +0,0 @@
/*===============================================================================================
Pitch detection example.
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example combines recording with spectrum analysis to determine the pitch of the sound
being recorded.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <math.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
static const char *note[120] =
{
"C 0", "C#0", "D 0", "D#0", "E 0", "F 0", "F#0", "G 0", "G#0", "A 0", "A#0", "B 0",
"C 1", "C#1", "D 1", "D#1", "E 1", "F 1", "F#1", "G 1", "G#1", "A 1", "A#1", "B 1",
"C 2", "C#2", "D 2", "D#2", "E 2", "F 2", "F#2", "G 2", "G#2", "A 2", "A#2", "B 2",
"C 3", "C#3", "D 3", "D#3", "E 3", "F 3", "F#3", "G 3", "G#3", "A 3", "A#3", "B 3",
"C 4", "C#4", "D 4", "D#4", "E 4", "F 4", "F#4", "G 4", "G#4", "A 4", "A#4", "B 4",
"C 5", "C#5", "D 5", "D#5", "E 5", "F 5", "F#5", "G 5", "G#5", "A 5", "A#5", "B 5",
"C 6", "C#6", "D 6", "D#6", "E 6", "F 6", "F#6", "G 6", "G#6", "A 6", "A#6", "B 6",
"C 7", "C#7", "D 7", "D#7", "E 7", "F 7", "F#7", "G 7", "G#7", "A 7", "A#7", "B 7",
"C 8", "C#8", "D 8", "D#8", "E 8", "F 8", "F#8", "G 8", "G#8", "A 8", "A#8", "B 8",
"C 9", "C#9", "D 9", "D#9", "E 9", "F 9", "F#9", "G 9", "G#9", "A 9", "A#9", "B 9"
};
static const float notefreq[120] =
{
16.35f, 17.32f, 18.35f, 19.45f, 20.60f, 21.83f, 23.12f, 24.50f, 25.96f, 27.50f, 29.14f, 30.87f,
32.70f, 34.65f, 36.71f, 38.89f, 41.20f, 43.65f, 46.25f, 49.00f, 51.91f, 55.00f, 58.27f, 61.74f,
65.41f, 69.30f, 73.42f, 77.78f, 82.41f, 87.31f, 92.50f, 98.00f, 103.83f, 110.00f, 116.54f, 123.47f,
130.81f, 138.59f, 146.83f, 155.56f, 164.81f, 174.61f, 185.00f, 196.00f, 207.65f, 220.00f, 233.08f, 246.94f,
261.63f, 277.18f, 293.66f, 311.13f, 329.63f, 349.23f, 369.99f, 392.00f, 415.30f, 440.00f, 466.16f, 493.88f,
523.25f, 554.37f, 587.33f, 622.25f, 659.26f, 698.46f, 739.99f, 783.99f, 830.61f, 880.00f, 932.33f, 987.77f,
1046.50f, 1108.73f, 1174.66f, 1244.51f, 1318.51f, 1396.91f, 1479.98f, 1567.98f, 1661.22f, 1760.00f, 1864.66f, 1975.53f,
2093.00f, 2217.46f, 2349.32f, 2489.02f, 2637.02f, 2793.83f, 2959.96f, 3135.96f, 3322.44f, 3520.00f, 3729.31f, 3951.07f,
4186.01f, 4434.92f, 4698.64f, 4978.03f, 5274.04f, 5587.65f, 5919.91f, 6271.92f, 6644.87f, 7040.00f, 7458.62f, 7902.13f,
8372.01f, 8869.84f, 9397.27f, 9956.06f, 10548.08f, 11175.30f, 11839.82f, 12543.85f, 13289.75f, 14080.00f, 14917.24f, 15804.26f
};
#define OUTPUTRATE 48000
#define SPECTRUMSIZE 8192
#define SPECTRUMRANGE ((float)OUTPUTRATE / 2.0f) /* 0 to nyquist */
#define BINSIZE (SPECTRUMRANGE / (float)SPECTRUMSIZE)
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *sound = 0;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, driver, recorddriver, numdrivers, count, outputfreq, bin;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate playback devices
*/
result = FMOD_System_GetNumDrivers(system, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a PLAYBACK driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetDriverInfo(system, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
result = FMOD_System_SetDriver(system, driver);
ERRCHECK(result);
/*
Enumerate record devices
*/
result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = FMOD_System_SetSoftwareFormat(system, OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR);
ERRCHECK(result);
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
FMOD_System_GetSoftwareFormat(system, &outputfreq, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Create a sound to record to.
*/
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 1;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = OUTPUTRATE;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
/*
Start the interface
*/
printf("=========================================================================\n");
printf("Pitch detection example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=========================================================================\n");
printf("\n");
printf("Record something through the selected recording device and FMOD will\n");
printf("Determine the pitch. Sustain the tone for at least a second to get an\n");
printf("accurate reading.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = FMOD_System_RecordStart(system, recorddriver, sound, TRUE);
ERRCHECK(result);
Sleep(200); /* Give it some time to record something */
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, FALSE, &channel);
ERRCHECK(result);
/* Dont hear what is being recorded otherwise it will feedback. Spectrum analysis is done before volume scaling in the DSP chain */
result = FMOD_Channel_SetVolume(channel, 0);
ERRCHECK(result);
bin = 0;
/*
Main loop.
*/
do
{
static float spectrum[SPECTRUMSIZE];
float dominanthz = 0;
float max;
int dominantnote = 0;
float binsize = BINSIZE;
if (kbhit())
{
key = getch();
}
result = FMOD_Channel_GetSpectrum(channel, spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);
ERRCHECK(result);
max = 0;
for (count = 0; count < SPECTRUMSIZE; count++)
{
if (spectrum[count] > 0.01f && spectrum[count] > max)
{
max = spectrum[count];
bin = count;
}
}
dominanthz = (float)bin * BINSIZE; /* dominant frequency min */
dominantnote = 0;
for (count = 0; count < 120; count++)
{
if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1])
{
/* which is it closer to. This note or the next note */
if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1]))
{
dominantnote = count;
}
else
{
dominantnote = count + 1;
}
break;
}
}
printf("Detected rate : %7.1f -> %7.1f hz. Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]);
fflush(stdout);
FMOD_System_Update(system);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,309 +0,0 @@
/*===============================================================================================
Pitch detection example.
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example combines recording with spectrum analysis to determine the pitch of the sound
being recorded.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <math.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
static const char *note[120] =
{
"C 0", "C#0", "D 0", "D#0", "E 0", "F 0", "F#0", "G 0", "G#0", "A 0", "A#0", "B 0",
"C 1", "C#1", "D 1", "D#1", "E 1", "F 1", "F#1", "G 1", "G#1", "A 1", "A#1", "B 1",
"C 2", "C#2", "D 2", "D#2", "E 2", "F 2", "F#2", "G 2", "G#2", "A 2", "A#2", "B 2",
"C 3", "C#3", "D 3", "D#3", "E 3", "F 3", "F#3", "G 3", "G#3", "A 3", "A#3", "B 3",
"C 4", "C#4", "D 4", "D#4", "E 4", "F 4", "F#4", "G 4", "G#4", "A 4", "A#4", "B 4",
"C 5", "C#5", "D 5", "D#5", "E 5", "F 5", "F#5", "G 5", "G#5", "A 5", "A#5", "B 5",
"C 6", "C#6", "D 6", "D#6", "E 6", "F 6", "F#6", "G 6", "G#6", "A 6", "A#6", "B 6",
"C 7", "C#7", "D 7", "D#7", "E 7", "F 7", "F#7", "G 7", "G#7", "A 7", "A#7", "B 7",
"C 8", "C#8", "D 8", "D#8", "E 8", "F 8", "F#8", "G 8", "G#8", "A 8", "A#8", "B 8",
"C 9", "C#9", "D 9", "D#9", "E 9", "F 9", "F#9", "G 9", "G#9", "A 9", "A#9", "B 9"
};
static const float notefreq[120] =
{
16.35f, 17.32f, 18.35f, 19.45f, 20.60f, 21.83f, 23.12f, 24.50f, 25.96f, 27.50f, 29.14f, 30.87f,
32.70f, 34.65f, 36.71f, 38.89f, 41.20f, 43.65f, 46.25f, 49.00f, 51.91f, 55.00f, 58.27f, 61.74f,
65.41f, 69.30f, 73.42f, 77.78f, 82.41f, 87.31f, 92.50f, 98.00f, 103.83f, 110.00f, 116.54f, 123.47f,
130.81f, 138.59f, 146.83f, 155.56f, 164.81f, 174.61f, 185.00f, 196.00f, 207.65f, 220.00f, 233.08f, 246.94f,
261.63f, 277.18f, 293.66f, 311.13f, 329.63f, 349.23f, 369.99f, 392.00f, 415.30f, 440.00f, 466.16f, 493.88f,
523.25f, 554.37f, 587.33f, 622.25f, 659.26f, 698.46f, 739.99f, 783.99f, 830.61f, 880.00f, 932.33f, 987.77f,
1046.50f, 1108.73f, 1174.66f, 1244.51f, 1318.51f, 1396.91f, 1479.98f, 1567.98f, 1661.22f, 1760.00f, 1864.66f, 1975.53f,
2093.00f, 2217.46f, 2349.32f, 2489.02f, 2637.02f, 2793.83f, 2959.96f, 3135.96f, 3322.44f, 3520.00f, 3729.31f, 3951.07f,
4186.01f, 4434.92f, 4698.64f, 4978.03f, 5274.04f, 5587.65f, 5919.91f, 6271.92f, 6644.87f, 7040.00f, 7458.62f, 7902.13f,
8372.01f, 8869.84f, 9397.27f, 9956.06f, 10548.08f, 11175.30f, 11839.82f, 12543.85f, 13289.75f, 14080.00f, 14917.24f, 15804.26f
};
#define OUTPUTRATE 48000
#define SPECTRUMSIZE 8192
#define SPECTRUMRANGE ((float)OUTPUTRATE / 2.0f) /* 0 to nyquist */
#define BINSIZE (SPECTRUMRANGE / (float)SPECTRUMSIZE)
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, driver, recorddriver, numdrivers, count, outputfreq, bin;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate playback devices
*/
result = system->getNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a PLAYBACK driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = system->getDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
result = system->setDriver(driver);
ERRCHECK(result);
/*
Enumerate record devices
*/
result = system->getRecordNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = system->getRecordDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = system->setSoftwareFormat(OUTPUTRATE, FMOD_SOUND_FORMAT_PCM16, 1, 0, FMOD_DSP_RESAMPLER_LINEAR);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
system->getSoftwareFormat(&outputfreq, 0, 0, 0, 0, 0);
ERRCHECK(result);
/*
Create a sound to record to.
*/
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 1;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = OUTPUTRATE;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
/*
Start the interface
*/
printf("=========================================================================\n");
printf("Pitch detection example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=========================================================================\n");
printf("\n");
printf("Record something through the selected recording device and FMOD will\n");
printf("Determine the pitch. Sustain the tone for at least a second to get an\n");
printf("accurate reading.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
result = system->recordStart(recorddriver, sound, true);
ERRCHECK(result);
Sleep(200); /* Give it some time to record something */
result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
ERRCHECK(result);
/* Dont hear what is being recorded otherwise it will feedback. Spectrum analysis is done before volume scaling in the DSP chain */
result = channel->setVolume(0);
ERRCHECK(result);
bin = 0;
/*
Main loop.
*/
do
{
static float spectrum[SPECTRUMSIZE];
float dominanthz = 0;
float max;
int dominantnote = 0;
float binsize = BINSIZE;
if (kbhit())
{
key = getch();
}
result = channel->getSpectrum(spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);
ERRCHECK(result);
max = 0;
for (count = 0; count < SPECTRUMSIZE; count++)
{
if (spectrum[count] > 0.01f && spectrum[count] > max)
{
max = spectrum[count];
bin = count;
}
}
dominanthz = (float)bin * BINSIZE; /* dominant frequency min */
dominantnote = 0;
for (count = 0; count < 120; count++)
{
if (dominanthz >= notefreq[count] && dominanthz < notefreq[count + 1])
{
/* which is it closer to. This note or the next note */
if (fabs(dominanthz - notefreq[count]) < fabs(dominanthz - notefreq[count+1]))
{
dominantnote = count;
}
else
{
dominantnote = count + 1;
}
break;
}
}
printf("Detected rate : %7.1f -> %7.1f hz. Detected musical note. %-3s (%7.1f hz)\r", dominanthz, ((float)bin + 0.99f) * BINSIZE, note[dominantnote], notefreq[dominantnote]);
fflush(stdout);
system->update();
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
playlist_cpp: main.cpp
g++ -O3 -o playlist main.cpp ../../api/lib/libfmodex.so -pthread
playlist_c: main.c
g++ -O3 -o playlist main.c ../../api/lib/libfmodex.so -pthread
run:
./playlist
clean:
rm -f playlist

View File

@ -1,254 +0,0 @@
/*===============================================================================================
PlayList Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to load a playlist and play the sounds in a playlist.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *playlist = 0;
FMOD_SOUND *sound = 0;
FMOD_CHANNEL *channel = 0;
FMOD_TAG tag;
FMOD_RESULT result;
FMOD_SOUND_TYPE soundtype;
FMOD_BOOL isplaylist = 0;
char *title = NULL;
int count = 0;
int key;
unsigned int version;
char file[128];
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/playlist.m3u", FMOD_DEFAULT, 0, &playlist);
ERRCHECK(result);
result = FMOD_Sound_GetFormat(playlist, &soundtype, 0, 0, 0);
ERRCHECK(result);
isplaylist = (soundtype == FMOD_SOUND_TYPE_PLAYLIST);
printf("===================================================================\n");
printf("PlayList Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press 'n' to play next sound in playlist\n");
printf("Press 'space' to pause/unpause current sound\n");
printf("Press 'Esc' to quit\n");
printf("\n");
if (isplaylist)
{
printf("PLAYLIST loaded.\n");
/*
Get the first song in the playlist, create the sound and then play it.
*/
result = FMOD_Sound_GetTag(playlist, "FILE", count, &tag);
ERRCHECK(result);
sprintf(file, "../media/%s", (char *)tag.data);
result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
FMOD_Sound_GetTag(playlist, "TITLE", count, &tag);
title = (char *)tag.data;
count++;
}
else
{
printf("SOUND loaded.\n");
/*
This is just a normal sound, so just play it.
*/
sound = playlist;
result = FMOD_Sound_SetMode(sound, FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
}
printf("\n");
/*
Main loop.
*/
do
{
FMOD_BOOL isplaying = 0;
if (channel && isplaylist)
{
/*
When sound has finished playing, play the next sound in the playlist
*/
FMOD_Channel_IsPlaying(channel, &isplaying);
if (!isplaying)
{
if (sound)
{
FMOD_Sound_Release(sound);
sound = NULL;
}
result = FMOD_Sound_GetTag(playlist, "FILE", count, &tag);
if (result != FMOD_OK)
{
count = 0;
}
else
{
printf("playing next song in playlist...\n");
sprintf(file, "../media/%s", (char *)tag.data);
result = FMOD_System_CreateSound(system, file, FMOD_DEFAULT, 0, &sound);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
FMOD_Sound_GetTag(playlist, "TITLE", count, &tag);
title = (char *)tag.data;
count++;
}
}
}
if (kbhit())
{
key = getch();
switch (key)
{
case 'n' :
{
/*
Play the next song in the playlist
*/
if (channel && isplaylist)
{
FMOD_Channel_Stop(channel);
}
break;
}
case ' ' :
{
if (channel)
{
FMOD_BOOL paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
}
}
}
}
FMOD_System_Update(system);
{
unsigned int ms = 0;
unsigned int lenms = 0;
FMOD_BOOL paused = 0;
if (channel)
{
if (sound)
{
result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : "Playing ", title);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
if (sound)
{
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
}
if (isplaylist)
{
result = FMOD_Sound_Release(playlist);
ERRCHECK(result);
}
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,256 +0,0 @@
/*===============================================================================================
PlayList Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to load a playlist and play the sounds in a playlist.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *playlist = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD_TAG tag;
FMOD_RESULT result;
FMOD_SOUND_TYPE soundtype;
bool isplaylist = false;
char *title = NULL;
int count = 0;
int key;
unsigned int version;
char file[128];
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/playlist.m3u", FMOD_DEFAULT, 0, &playlist);
ERRCHECK(result);
result = playlist->getFormat(&soundtype, 0, 0, 0);
ERRCHECK(result);
isplaylist = (soundtype == FMOD_SOUND_TYPE_PLAYLIST);
printf("===================================================================\n");
printf("PlayList Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press 'n' to play next sound in playlist\n");
printf("Press 'space' to pause/unpause current sound\n");
printf("Press 'Esc' to quit\n");
printf("\n");
if (isplaylist)
{
printf("PLAYLIST loaded.\n");
/*
Get the first song in the playlist, create the sound and then play it.
*/
result = playlist->getTag("FILE", count, &tag);
ERRCHECK(result);
sprintf(file, "../media/%s", (char *)tag.data);
result = system->createSound(file, FMOD_DEFAULT, 0, &sound);
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
playlist->getTag("TITLE", count, &tag);
title = (char *)tag.data;
count++;
}
else
{
printf("SOUND loaded.\n");
/*
This is just a normal sound, so just play it.
*/
sound = playlist;
result = sound->setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
}
printf("\n");
/*
Main loop.
*/
do
{
bool isplaying = false;
if (channel && isplaylist)
{
/*
When sound has finished playing, play the next sound in the playlist
*/
channel->isPlaying(&isplaying);
if (!isplaying)
{
if (sound)
{
sound->release();
sound = NULL;
}
result = playlist->getTag("FILE", count, &tag);
if (result != FMOD_OK)
{
count = 0;
}
else
{
printf("playing next song in playlist...\n");
sprintf(file, "../media/%s", (char *)tag.data);
result = system->createSound(file, FMOD_DEFAULT, 0, &sound);
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
playlist->getTag("TITLE", count, &tag);
title = (char *)tag.data;
count++;
}
}
}
if (kbhit())
{
key = getch();
switch (key)
{
case 'n' :
{
/*
Play the next song in the playlist
*/
if (channel && isplaylist)
{
channel->stop();
}
break;
}
case ' ' :
{
if (channel)
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
}
}
}
}
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool paused = 0;
if (channel)
{
if (sound)
{
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : "Playing ", title);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
if (sound)
{
result = sound->release();
ERRCHECK(result);
}
if (isplaylist)
{
result = playlist->release();
ERRCHECK(result);
}
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
playsound_cpp: main.cpp
g++ -O3 -o playsound main.cpp ../../api/lib/libfmodex.so -pthread
playsound_c: main.c
gcc -O3 -o playsound main.c ../../api/lib/libfmodex.so -pthread
run:
./playsound
clean:
rm -f playsound

View File

@ -1,184 +0,0 @@
/*===============================================================================================
PlaySound Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to simply load and play multiple sounds. This is about the simplest
use of FMOD.
This makes FMOD decode the into memory when it loads. If the sounds are big and possibly take
up a lot of ram, then it would be better to use the FMOD_CREATESTREAM flag so that it is
streamed in realtime as it plays.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1, *sound2, *sound3;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1);
ERRCHECK(result);
result = FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/swish.wav", FMOD_SOFTWARE, 0, &sound3);
ERRCHECK(result);
printf("===================================================================\n");
printf("PlaySound Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press '1' to Play a mono sound using hardware mixing\n");
printf("Press '2' to Play a mono sound using software mixing\n");
printf("Press '3' to Play a stereo sound using hardware mixing\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
ERRCHECK(result);
break;
}
case '2' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, 0, &channel);
ERRCHECK(result);
break;
}
case '3' :
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, 0, &channel);
ERRCHECK(result);
break;
}
}
}
FMOD_System_Update(system);
{
unsigned int ms = 0;
unsigned int lenms = 0;
int playing = 0;
int paused = 0;
int channelsplaying = 0;
if (channel)
{
FMOD_SOUND *currentsound = 0;
result = FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_Channel_GetCurrentSound(channel, &currentsound);
if (currentsound)
{
result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
result = FMOD_Sound_GetLength(sound1, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
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);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound1);
ERRCHECK(result);
result = FMOD_Sound_Release(sound2);
ERRCHECK(result);
result = FMOD_Sound_Release(sound3);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,182 +0,0 @@
/*===============================================================================================
PlaySound Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to simply load and play multiple sounds. This is about the simplest
use of FMOD.
This makes FMOD decode the into memory when it loads. If the sounds are big and possibly take
up a lot of ram, then it would be better to use the FMOD_CREATESTREAM flag so that it is
streamed in realtime as it plays.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2, *sound3;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE, 0, &sound1);
ERRCHECK(result);
result = sound1->setMode(FMOD_LOOP_OFF);
ERRCHECK(result);
result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE, 0, &sound2);
ERRCHECK(result);
result = system->createSound("../media/swish.wav", FMOD_SOFTWARE, 0, &sound3);
ERRCHECK(result);
printf("===================================================================\n");
printf("PlaySound Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press '1' to Play a mono sound using software mixing\n");
printf("Press '2' to Play a mono sound using software mixing\n");
printf("Press '3' to Play a stereo sound using software mixing\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, 0, &channel);
ERRCHECK(result);
break;
}
case '2' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound2, 0, &channel);
ERRCHECK(result);
break;
}
case '3' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, 0, &channel);
ERRCHECK(result);
break;
}
}
}
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;
if (channel)
{
FMOD::Sound *currentsound = 0;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
channel->getCurrentSound(&currentsound);
if (currentsound)
{
result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
system->getChannelsPlaying(&channelsplaying);
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);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
playstream_cpp: main.cpp
g++ -O3 -o playstream main.cpp ../../api/lib/libfmodex.so -pthread
playstream_c: main.c
g++ -O3 -o playstream main.c ../../api/lib/libfmodex.so -pthread
run:
./playstream
clean:
rm -f playstream

View File

@ -1,149 +0,0 @@
/*===============================================================================================
PlayStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to simply play a stream, such as an mp3 or wav.
The stream behaviour is achieved by specifying FMOD_CREATESTREAM in the call to
FMOD_System_CreateSound.
This makes FMOD decode the file in realtime as it plays, instead of loading it all at once.
This uses far less memory, in exchange for a small runtime cpu hit.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &sound);
ERRCHECK(result);
printf("====================================================================\n");
printf("PlayStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("====================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
unsigned int ms;
unsigned int lenms;
int playing;
int paused;
FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,147 +0,0 @@
/*===============================================================================================
PlayStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to simply play a stream, such as an mp3 or wav.
The stream behaviour is achieved by specifying FMOD_CREATESTREAM in the call to
System::createSound.
This makes FMOD decode the file in realtime as it plays, instead of loading it all at once.
This uses far less memory, in exchange for a small runtime cpu hit.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &sound);
ERRCHECK(result);
printf("====================================================================\n");
printf("PlayStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("====================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,5 +0,0 @@
all:
g++ -shared -fPIC -o codec_raw.so main.c
clean:
rm -f codec_raw.so

View File

@ -1,96 +0,0 @@
/*===============================================================================================
CODEC_RAW.SO
Copyright (c), Firelight Technologies Pty, Ltd 2006-2011.
===============================================================================================*/
#include <stdio.h>
#include "../../../api/inc/fmod.h"
#include "../../../api/inc/fmod_errors.h"
FMOD_RESULT F_CALLBACK rawopen(FMOD_CODEC_STATE *codec, FMOD_MODE usermode, FMOD_CREATESOUNDEXINFO *userexinfo);
FMOD_RESULT F_CALLBACK rawclose(FMOD_CODEC_STATE *codec);
FMOD_RESULT F_CALLBACK rawread(FMOD_CODEC_STATE *codec, void *buffer, unsigned int size, unsigned int *read);
FMOD_RESULT F_CALLBACK rawsetposition(FMOD_CODEC_STATE *codec, int subsound, unsigned int position, FMOD_TIMEUNIT postype);
FMOD_CODEC_DESCRIPTION rawcodec =
{
"FMOD Raw player plugin example", // Name.
0x00010000, // Version 0xAAAABBBB A = major, B = minor.
0, // Don't force everything using this codec to be a stream
FMOD_TIMEUNIT_PCMBYTES, // The time format we would like to accept into setposition/getposition.
&rawopen, // Open callback.
&rawclose, // Close callback.
&rawread, // Read callback.
0, // Getlength callback. (If not specified FMOD return the length in FMOD_TIMEUNIT_PCM, FMOD_TIMEUNIT_MS or FMOD_TIMEUNIT_PCMBYTES units based on the lengthpcm member of the FMOD_CODEC structure).
&rawsetposition, // Setposition callback.
0, // Getposition callback. (only used for timeunit types that are not FMOD_TIMEUNIT_PCM, FMOD_TIMEUNIT_MS and FMOD_TIMEUNIT_PCMBYTES).
0 // Sound create callback (don't need it)
};
/*
FMODGetCodecDescription is mandatory for every fmod plugin. This is the symbol the registerplugin function searches for.
Must be declared with F_API to make it export as stdcall.
MUST BE EXTERN'ED AS C! C++ functions will be mangled incorrectly and not load in fmod.
*/
#ifdef __cplusplus
extern "C" {
#endif
F_DECLSPEC F_DLLEXPORT FMOD_CODEC_DESCRIPTION * F_API FMODGetCodecDescription()
{
return &rawcodec;
}
#ifdef __cplusplus
}
#endif
static FMOD_CODEC_WAVEFORMAT rawwaveformat;
/*
The actual codec code.
Note that the callbacks uses FMOD's supplied file system callbacks.
This is important as even though you might want to open the file yourself, you would lose the following benefits.
1. Automatic support of memory files, CDDA based files, and HTTP/TCPIP based files.
2. "fileoffset" / "length" support when user calls System::createSound with FMOD_CREATESOUNDEXINFO structure.
3. Buffered file access.
FMOD files are high level abstracts that support all sorts of 'file', they are not just disk file handles.
If you want FMOD to use your own filesystem (and potentially lose the above benefits) use System::setFileSystem.
*/
FMOD_RESULT F_CALLBACK rawopen(FMOD_CODEC_STATE *codec, FMOD_MODE usermode, FMOD_CREATESOUNDEXINFO *userexinfo)
{
rawwaveformat.channels = 2;
rawwaveformat.format = FMOD_SOUND_FORMAT_PCM16;
rawwaveformat.frequency = 44100;
rawwaveformat.blockalign = rawwaveformat.channels * 2; /* 2 = 16bit pcm */
rawwaveformat.lengthpcm = codec->filesize / rawwaveformat.blockalign; /* bytes converted to PCM samples */;
codec->numsubsounds = 0; /* number of 'subsounds' in this sound. For most codecs this is 0, only multi sound codecs such as FSB or CDDA have subsounds. */
codec->waveformat = &rawwaveformat;
codec->plugindata = 0; /* user data value */
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK rawclose(FMOD_CODEC_STATE *codec)
{
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK rawread(FMOD_CODEC_STATE *codec, void *buffer, unsigned int size, unsigned int *read)
{
return codec->fileread(codec->filehandle, buffer, size, read, 0);
}
FMOD_RESULT F_CALLBACK rawsetposition(FMOD_CODEC_STATE *codec, int subsound, unsigned int position, FMOD_TIMEUNIT postype)
{
return codec->fileseek(codec->filehandle, position, 0);
}

View File

@ -1,5 +0,0 @@
all:
g++ -shared -fPIC -o dsp_gain.so main.c
clean:
rm -f dsp_gain.so

View File

@ -1,181 +0,0 @@
/*===============================================================================================
DSP_GAIN.SO
Copyright (c), Firelight Technologies Pty, Ltd 2006-2011.
===============================================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include "../../../api/inc/fmod.h"
#include "../../../api/inc/fmod_errors.h"
FMOD_RESULT F_CALLBACK dspcreate (FMOD_DSP_STATE *dsp);
FMOD_RESULT F_CALLBACK dsprelease (FMOD_DSP_STATE *dsp);
FMOD_RESULT F_CALLBACK dspreset (FMOD_DSP_STATE *dsp);
FMOD_RESULT F_CALLBACK dspread (FMOD_DSP_STATE *dsp, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels);
FMOD_RESULT F_CALLBACK dspsetparam(FMOD_DSP_STATE *dsp, int index, float value);
FMOD_RESULT F_CALLBACK dspgetparam(FMOD_DSP_STATE *dsp, int index, float *value, char *valuestr);
/*
DSP Parameter list.
*/
FMOD_DSP_PARAMETERDESC dspparam[1] =
{
{ 0.0f, 1.0f, 1.0, "Level", "%", "Gain level" },
};
FMOD_DSP_DESCRIPTION dspgaindesc =
{
"FMOD gain example", // name
0x00010000, // version 0xAAAABBBB A = major, B = minor.
0, // 0 = we can filter whatever you throw at us. To be most user friendly, always write a filter like this.
dspcreate, //
dsprelease, //
dspreset, //
dspread, //
0, // This is for if you want to allow the plugin to seek, which doesnt really make sense in a gain filter so we'll just leave it out.
1, // 1 parameter. "level"
dspparam, // pointer to the parameter list definition.
dspsetparam, //
dspgetparam, //
0, // This is for if you want to pop up a dialog box to configure the plugin. Not doing that here.
0, // This is for if you want to pop up a dialog box to configure the plugin. Not doing that here.
0, // This is for if you want to pop up a dialog box to configure the plugin. Not doing that here.
};
/*
FMODGetDSPDescription is mandantory for every fmod plugin. This is the symbol the registerplugin function searches for.
Must be declared with F_API to make it export as stdcall.
MUST BE EXTERN'ED AS C! C++ functions will be mangled incorrectly and not load in fmod.
*/
#ifdef __cplusplus
extern "C" {
#endif
F_DECLSPEC F_DLLEXPORT FMOD_DSP_DESCRIPTION * F_API FMODGetDSPDescription()
{
return &dspgaindesc;
}
#ifdef __cplusplus
}
#endif
typedef struct dspgain_state
{
float gain;
} dspgain_state;
FMOD_RESULT F_CALLBACK dspcreate(FMOD_DSP_STATE *dsp)
{
dspgain_state *state;
/*
If we were allocating memory for buffers etc, it would be done in this function.
*/
state = (dspgain_state *)malloc(sizeof(dspgain_state));
if (!state)
{
return FMOD_ERR_MEMORY;
}
state->gain = dspparam[0].defaultval;
dsp->plugindata = state;
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK dsprelease(FMOD_DSP_STATE *dsp)
{
dspgain_state *state = (dspgain_state *)dsp->plugindata;
/*
If memory was allocated in create, it would be freed in this function.
*/
free(state);
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK dspreset(FMOD_DSP_STATE *dsp)
{
dspgain_state *state = (dspgain_state *)dsp->plugindata;
/*
This isnt really needed here. It is used to reset a filter back to it's default state.
*/
state->gain = dspparam[0].defaultval;
return FMOD_OK;
}
/*
This callback does the work. Modify data from inbuffer and send it to outbuffer.
*/
FMOD_RESULT F_CALLBACK dspread(FMOD_DSP_STATE *dsp, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
dspgain_state *state = (dspgain_state *)dsp->plugindata;
unsigned int count;
int count2;
int channels = inchannels; // outchannels and inchannels will always be the same because this is a flexible filter.
for (count = 0; count < length; count++)
{
for (count2 = 0; count2 < channels; count2++)
{
outbuffer[(count * channels) + count2] = inbuffer[(count * channels) + count2] * state->gain;
}
}
return FMOD_OK;
}
/*
This callback is for when the user sets a parameter. It is automatically clamped between 0 and 1.
*/
FMOD_RESULT F_CALLBACK dspsetparam(FMOD_DSP_STATE *dsp, int index, float value)
{
dspgain_state *state = (dspgain_state *)dsp->plugindata;
switch (index)
{
case 0:
{
state->gain = value;
break;
}
}
return FMOD_OK;
}
/*
This callback is for when the user gets a parameter. The label for our only parameter is percent,
so when the string is requested print it out as 0 to 100.
*/
FMOD_RESULT F_CALLBACK dspgetparam(FMOD_DSP_STATE *dsp, int index, float *value, char *valuestr)
{
dspgain_state *state = (dspgain_state *)dsp->plugindata;
switch (index)
{
case 0:
{
*value = state->gain;
sprintf(valuestr, "%.02f", state->gain * 100.0f); // our units are '%', so print it out as 0 to 100.
}
}
return FMOD_OK;
}

View File

@ -1,11 +0,0 @@
readtags_cpp: main.cpp
g++ -O3 -o readtags main.cpp ../../api/lib/libfmodex.so
readtags_c: main.c
g++ -O3 -o readtags main.c ../../api/lib/libfmodex.so
run:
./readtags
clean:
rm -f readtags

View File

@ -1,165 +0,0 @@
/*===============================================================================================
ReadTags Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to read tags from sound files
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_RESULT result;
FMOD_TAG tag;
int numtags, numtagsupdated, count;
unsigned int version;
printf("==================================================================\n");
printf("ReadTags Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==================================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Open the specified file. Use FMOD_CREATESTREAM and FMOD_OPENONLY so it opens quickly
*/
result = FMOD_System_CreateSound(system, "../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_OPENONLY, 0, &sound);
ERRCHECK(result);
/*
Read and display all tags associated with this file
*/
for (;;)
{
/*
An index of -1 means "get the first tag that's new or updated".
If no tags are new or updated then getTag will return FMOD_ERR_TAGNOTFOUND.
This is the first time we've read any tags so they'll all be new but after we've read them,
they won't be new any more.
*/
if (FMOD_Sound_GetTag(sound, 0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
}
else
{
printf("%s = <binary> (%d bytes)\n", tag.name, tag.datalen);
}
}
printf("\n");
/*
Read all the tags regardless of whether they're updated or not. Also show the tag type.
*/
result = FMOD_Sound_GetNumTags(sound, &numtags, &numtagsupdated);
ERRCHECK(result);
for (count=0; count < numtags; count++)
{
result = FMOD_Sound_GetTag(sound, 0, count, &tag);
ERRCHECK(result);
switch (tag.type)
{
case FMOD_TAGTYPE_UNKNOWN :
printf("FMOD_TAGTYPE_UNKNOWN ");
break;
case FMOD_TAGTYPE_ID3V1 :
printf("FMOD_TAGTYPE_ID3V1 ");
break;
case FMOD_TAGTYPE_ID3V2 :
printf("FMOD_TAGTYPE_ID3V2 ");
break;
case FMOD_TAGTYPE_VORBISCOMMENT :
printf("FMOD_TAGTYPE_VORBISCOMMENT ");
break;
case FMOD_TAGTYPE_SHOUTCAST :
printf("FMOD_TAGTYPE_SHOUTCAST ");
break;
case FMOD_TAGTYPE_ICECAST :
printf("FMOD_TAGTYPE_ICECAST ");
break;
case FMOD_TAGTYPE_ASF :
printf("FMOD_TAGTYPE_ASF ");
break;
case FMOD_TAGTYPE_FMOD :
printf("FMOD_TAGTYPE_FMOD ");
break;
case FMOD_TAGTYPE_USER :
printf("FMOD_TAGTYPE_USER ");
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
}
else
{
printf("%s = ??? (%d bytes)\n", tag.name, tag.datalen);
}
}
printf("\n");
/*
Find a specific tag by name. Specify an index > 0 to get access to multiple tags of the same name.
*/
result = FMOD_Sound_GetTag(sound, "ARTIST", 0, &tag);
ERRCHECK(result);
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,165 +0,0 @@
/*===============================================================================================
ReadTags Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to read tags from sound files
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD_RESULT result;
FMOD_TAG tag;
int numtags, numtagsupdated, count;
unsigned int version;
printf("==================================================================\n");
printf("ReadTags Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==================================================================\n\n");
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
result = system->init(100, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Open the specified file. Use FMOD_CREATESTREAM and FMOD_OPENONLY so it opens quickly
*/
result = system->createSound("../media/wave.mp3", FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_OPENONLY, 0, &sound);
ERRCHECK(result);
/*
Read and display all tags associated with this file
*/
for (;;)
{
/*
An index of -1 means "get the first tag that's new or updated".
If no tags are new or updated then getTag will return FMOD_ERR_TAGNOTFOUND.
This is the first time we've read any tags so they'll all be new but after we've read them,
they won't be new any more.
*/
if (sound->getTag(0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
}
else
{
printf("%s = <binary> (%d bytes)\n", tag.name, tag.datalen);
}
}
printf("\n");
/*
Read all the tags regardless of whether they're updated or not. Also show the tag type.
*/
result = sound->getNumTags(&numtags, &numtagsupdated);
ERRCHECK(result);
for (count=0; count < numtags; count++)
{
result = sound->getTag(0, count, &tag);
ERRCHECK(result);
switch (tag.type)
{
case FMOD_TAGTYPE_UNKNOWN :
printf("FMOD_TAGTYPE_UNKNOWN ");
break;
case FMOD_TAGTYPE_ID3V1 :
printf("FMOD_TAGTYPE_ID3V1 ");
break;
case FMOD_TAGTYPE_ID3V2 :
printf("FMOD_TAGTYPE_ID3V2 ");
break;
case FMOD_TAGTYPE_VORBISCOMMENT :
printf("FMOD_TAGTYPE_VORBISCOMMENT ");
break;
case FMOD_TAGTYPE_SHOUTCAST :
printf("FMOD_TAGTYPE_SHOUTCAST ");
break;
case FMOD_TAGTYPE_ICECAST :
printf("FMOD_TAGTYPE_ICECAST ");
break;
case FMOD_TAGTYPE_ASF :
printf("FMOD_TAGTYPE_ASF ");
break;
case FMOD_TAGTYPE_FMOD :
printf("FMOD_TAGTYPE_FMOD ");
break;
case FMOD_TAGTYPE_USER :
printf("FMOD_TAGTYPE_USER ");
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
}
else
{
printf("%s = ??? (%d bytes)\n", tag.name, tag.datalen);
}
}
printf("\n");
/*
Find a specific tag by name. Specify an index > 0 to get access to multiple tags of the same name.
*/
result = sound->getTag("ARTIST", 0, &tag);
ERRCHECK(result);
printf("%s = %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
realtimestitching_cpp: main.cpp
g++ -O3 -o realtimestitching main.cpp ../../api/lib/libfmodex.so -pthread
realtimestitching_c: main.c
g++ -O3 -o realtimestitching main.c ../../api/lib/libfmodex.so -pthread
run:
./realtimestitching
clean:
rm -f realtimestitching

View File

@ -1,245 +0,0 @@
/*===============================================================================================
Real-time stitching example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how you can create your own multi-subsound stream, then in realtime replace
each the subsound as it plays them. Using a looping sentence, it will seamlessly stich between
2 subsounds in this example, and each time it switches to a new sound, it will replace the old
one with another sound in our list.
These sounds can go on forever as long as they are the same bitdepth (when decoded) and number
of channels (ie mono / stereo). The reason for this is the hardware channel cannot change
formats mid sentence, and using different hardware channels would mean it wouldn't be gapless.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#define NUMSOUNDS 32
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_SOUND *subsound[2];
FMOD_CREATESOUNDEXINFO exinfo;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int subsoundid, sentenceid;
unsigned int version;
const char *soundname[NUMSOUNDS] =
{
"../media/e.ogg", /* Ma- */
"../media/d.ogg", /* ry */
"../media/c.ogg", /* had */
"../media/d.ogg", /* a */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* ..... */
"../media/d.ogg", /* lit- */
"../media/d.ogg", /* tle */
"../media/d.ogg", /* lamb, */
"../media/d.ogg", /* ..... */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* ..... */
"../media/e.ogg", /* Ma- */
"../media/d.ogg", /* ry */
"../media/c.ogg", /* had */
"../media/d.ogg", /* a */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* its */
"../media/d.ogg", /* fleece */
"../media/d.ogg", /* was */
"../media/e.ogg", /* white */
"../media/d.ogg", /* as */
"../media/c.ogg", /* snow. */
"../media/c.ogg", /* ..... */
"../media/c.ogg", /* ..... */
"../media/c.ogg", /* ..... */
};
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 1, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
/*
Set up the FMOD_CREATESOUNDEXINFO structure for the user stream with room for 2 subsounds. (our subsound double buffer)
*/
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.defaultfrequency = 44100;
exinfo.numsubsounds = 2;
exinfo.numchannels = 1;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
/*
Create the 'parent' stream that contains the substreams. Set it to loop so that it loops between subsound 0 and 1.
*/
result = FMOD_System_CreateStream(system, 0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
/*
Add 2 of our streams as children of the parent. They should be the same format (ie mono/stereo and bitdepth) as the parent sound.
When subsound 0 has finished and it is playing subsound 1, we will swap subsound 0 with a new sound, and the same for when subsound 1 has finished,
causing a continual double buffered flip, which means continuous sound.
*/
result = FMOD_System_CreateStream(system, soundname[0], FMOD_DEFAULT, 0, &subsound[0]);
ERRCHECK(result);
result = FMOD_System_CreateStream(system, soundname[1], FMOD_DEFAULT, 0, &subsound[1]);
ERRCHECK(result);
result = FMOD_Sound_SetSubSound(sound, 0, subsound[0]);
ERRCHECK(result);
result = FMOD_Sound_SetSubSound(sound, 1, subsound[1]);
ERRCHECK(result);
/*
Set up the gapless sentence to contain these first 2 streams.
*/
{
int soundlist[2] = { 0, 1 };
result = FMOD_Sound_SetSubSoundSentence(sound, soundlist, 2);
ERRCHECK(result);
}
subsoundid = 0;
sentenceid = 2; /* The next sound to be appeneded to the stream. */
printf("=============================================================================\n");
printf("Real-time stitching example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=============================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
printf("Inserted subsound %d / 2 with sound %d / %d\n", 0, 0, NUMSOUNDS);
printf("Inserted subsound %d / 2 with sound %d / %d\n", 1, 1, NUMSOUNDS);
/*
Play the sound.
*/
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
unsigned int currentsubsoundid;
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
break;
}
}
}
FMOD_System_Update(system);
/*
Replace the subsound that just finished with a new subsound, to create endless seamless stitching!
Note that this polls the currently playing subsound using the FMOD_TIMEUNIT_BUFFERED flag.
Remember streams are decoded / buffered ahead in advance!
Don't use the 'audible time' which is FMOD_TIMEUNIT_SENTENCE_SUBSOUND by itself. When streaming, sound is
processed ahead of time, and things like stream buffer / sentence manipulation (as done below) is required
to be in 'buffered time', or else there will be synchronization problems and you might end up releasing a
sub-sound that is still playing!
*/
result = FMOD_Channel_GetPosition(channel, &currentsubsoundid, (FMOD_TIMEUNIT)(FMOD_TIMEUNIT_SENTENCE_SUBSOUND | FMOD_TIMEUNIT_BUFFERED));
ERRCHECK(result);
if (currentsubsoundid != subsoundid)
{
/*
Release the sound that isn't playing any more.
*/
result = FMOD_Sound_Release(subsound[subsoundid]);
ERRCHECK(result);
/*
Replace it with a new sound in our list.
*/
result = FMOD_System_CreateStream(system, soundname[sentenceid], FMOD_DEFAULT, 0, &subsound[subsoundid]);
ERRCHECK(result);
result = FMOD_Sound_SetSubSound(sound, subsoundid, subsound[subsoundid]);
ERRCHECK(result);
printf("Replacing subsound %d / 2 with sound %d / %d\n", subsoundid, sentenceid, NUMSOUNDS);
sentenceid++;
if (sentenceid >= NUMSOUNDS)
{
sentenceid = 0;
}
subsoundid = currentsubsoundid;
}
Sleep(50);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound); /* Freeing a parent subsound also frees its children. */
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,245 +0,0 @@
/*===============================================================================================
Real-time stitching example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how you can create your own multi-subsound stream, then in realtime replace
each the subsound as it plays them. Using a looping sentence, it will seamlessly stich between
2 subsounds in this example, and each time it switches to a new sound, it will replace the old
one with another sound in our list.
These sounds can go on forever as long as they are the same bitdepth (when decoded) and number
of channels (ie mono / stereo). The reason for this is the hardware channel cannot change
formats mid sentence, and using different hardware channels would mean it wouldn't be gapless.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#define NUMSOUNDS 32
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Sound *subsound[2];
FMOD_CREATESOUNDEXINFO exinfo;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int subsoundid, sentenceid;
unsigned int version;
const char *soundname[NUMSOUNDS] =
{
"../media/e.ogg", /* Ma- */
"../media/d.ogg", /* ry */
"../media/c.ogg", /* had */
"../media/d.ogg", /* a */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* ..... */
"../media/d.ogg", /* lit- */
"../media/d.ogg", /* tle */
"../media/d.ogg", /* lamb, */
"../media/d.ogg", /* ..... */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* ..... */
"../media/e.ogg", /* Ma- */
"../media/d.ogg", /* ry */
"../media/c.ogg", /* had */
"../media/d.ogg", /* a */
"../media/e.ogg", /* lit- */
"../media/e.ogg", /* tle */
"../media/e.ogg", /* lamb, */
"../media/e.ogg", /* its */
"../media/d.ogg", /* fleece */
"../media/d.ogg", /* was */
"../media/e.ogg", /* white */
"../media/d.ogg", /* as */
"../media/c.ogg", /* snow. */
"../media/c.ogg", /* ..... */
"../media/c.ogg", /* ..... */
"../media/c.ogg", /* ..... */
};
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
/*
Set up the FMOD_CREATESOUNDEXINFO structure for the user stream with room for 2 subsounds. (our subsound double buffer)
*/
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.defaultfrequency = 44100;
exinfo.numsubsounds = 2;
exinfo.numchannels = 1;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
/*
Create the 'parent' stream that contains the substreams. Set it to loop so that it loops between subsound 0 and 1.
*/
result = system->createStream(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
/*
Add 2 of our streams as children of the parent. They should be the same format (ie mono/stereo and bitdepth) as the parent sound.
When subsound 0 has finished and it is playing subsound 1, we will swap subsound 0 with a new sound, and the same for when subsound 1 has finished,
causing a continual double buffered flip, which means continuous sound.
*/
result = system->createStream(soundname[0], FMOD_DEFAULT, 0, &subsound[0]);
ERRCHECK(result);
result = system->createStream(soundname[1], FMOD_DEFAULT, 0, &subsound[1]);
ERRCHECK(result);
result = sound->setSubSound(0, subsound[0]);
ERRCHECK(result);
result = sound->setSubSound(1, subsound[1]);
ERRCHECK(result);
/*
Set up the gapless sentence to contain these first 2 streams.
*/
{
int soundlist[2] = { 0, 1 };
result = sound->setSubSoundSentence(soundlist, 2);
ERRCHECK(result);
}
subsoundid = 0;
sentenceid = 2; /* The next sound to be appeneded to the stream. */
printf("=============================================================================\n");
printf("Real-time stitching example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("=============================================================================\n");
printf("\n");
printf("Press space to pause, Esc to quit\n");
printf("\n");
printf("Inserted subsound %d / 2 with sound %d / %d\n", 0, 0, NUMSOUNDS);
printf("Inserted subsound %d / 2 with sound %d / %d\n", 1, 1, NUMSOUNDS);
/*
Play the sound.
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
unsigned int currentsubsoundid;
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
}
}
system->update();
/*
Replace the subsound that just finished with a new subsound, to create endless seamless stitching!
Note that this polls the currently playing subsound using the FMOD_TIMEUNIT_BUFFERED flag.
Remember streams are decoded / buffered ahead in advance!
Don't use the 'audible time' which is FMOD_TIMEUNIT_SENTENCE_SUBSOUND by itself. When streaming, sound is
processed ahead of time, and things like stream buffer / sentence manipulation (as done below) is required
to be in 'buffered time', or else there will be synchronization problems and you might end up releasing a
sub-sound that is still playing!
*/
result = channel->getPosition(&currentsubsoundid, (FMOD_TIMEUNIT)(FMOD_TIMEUNIT_SENTENCE_SUBSOUND | FMOD_TIMEUNIT_BUFFERED));
ERRCHECK(result);
if (currentsubsoundid != subsoundid)
{
/*
Release the sound that isn't playing any more.
*/
result = subsound[subsoundid]->release();
ERRCHECK(result);
/*
Replace it with a new sound in our list.
*/
result = system->createStream(soundname[sentenceid], FMOD_DEFAULT, 0, &subsound[subsoundid]);
ERRCHECK(result);
result = sound->setSubSound(subsoundid, subsound[subsoundid]);
ERRCHECK(result);
printf("Replacing subsound %d / 2 with sound %d / %d\n", subsoundid, sentenceid, NUMSOUNDS);
sentenceid++;
if (sentenceid >= NUMSOUNDS)
{
sentenceid = 0;
}
subsoundid = currentsubsoundid;
}
Sleep(50);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release(); /* Freeing a parent subsound also frees its children. */
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
recording_cpp: main.cpp
g++ -O3 -o recording main.cpp ../../api/lib/libfmodex.so -pthread
recording_c: main.c
g++ -O3 -o recording main.c ../../api/lib/libfmodex.so -pthread
run:
./recording
clean:
rm -f recording

View File

@ -1,401 +0,0 @@
/*===============================================================================================
Record example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to record a sound, then write it to a wav file.
It then shows how to play a sound while it is being recorded to. Because it is recording, the
sound playback has to be delayed a little bit so that the playback doesn't play part of the
buffer that is still being written to.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#if defined(WIN32) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#define __PACKED /* dummy */
#else
#define __PACKED __attribute__((packed)) /* gcc packed */
#endif
/*
[
[DESCRIPTION]
Writes out the contents of a record buffer to a file.
[PARAMETERS]
[RETURN_VALUE]
void
[REMARKS]
]
*/
void SaveToWav(FMOD_SOUND *sound)
{
FILE *fp;
int channels, bits;
float rate;
void *ptr1, *ptr2;
unsigned int lenbytes, len1, len2;
if (!sound)
{
return;
}
FMOD_Sound_GetFormat (sound, 0, 0, &channels, &bits);
FMOD_Sound_GetDefaults(sound, &rate, 0, 0, 0);
FMOD_Sound_GetLength (sound, &lenbytes, FMOD_TIMEUNIT_PCMBYTES);
{
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack(1)
#endif
/*
WAV Structures
*/
typedef struct
{
signed char id[4];
int size;
} RiffChunk;
struct
{
RiffChunk chunk __PACKED;
unsigned short wFormatTag __PACKED; /* format type */
unsigned short nChannels __PACKED; /* number of channels (i.e. mono, stereo...) */
unsigned int nSamplesPerSec __PACKED; /* sample rate */
unsigned int nAvgBytesPerSec __PACKED; /* for buffer estimation */
unsigned short nBlockAlign __PACKED; /* block size of data */
unsigned short wBitsPerSample __PACKED; /* number of bits per sample of mono data */
} __PACKED FmtChunk = { {{'f','m','t',' '}, sizeof(FmtChunk) - sizeof(RiffChunk) }, 1, channels, (int)rate, (int)rate * channels * bits / 8, 1 * channels * bits / 8, bits };
struct
{
RiffChunk chunk;
} DataChunk = { {{'d','a','t','a'}, lenbytes } };
struct
{
RiffChunk chunk;
signed char rifftype[4];
} WavHeader = { {{'R','I','F','F'}, sizeof(FmtChunk) + sizeof(RiffChunk) + lenbytes }, {'W','A','V','E'} };
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack()
#endif
fp = fopen("record.wav", "wb");
/*
Write out the WAV header.
*/
fwrite(&WavHeader, sizeof(WavHeader), 1, fp);
fwrite(&FmtChunk, sizeof(FmtChunk), 1, fp);
fwrite(&DataChunk, sizeof(DataChunk), 1, fp);
/*
Lock the sound to get access to the raw data.
*/
FMOD_Sound_Lock(sound, 0, lenbytes, &ptr1, &ptr2, &len1, &len2);
/*
Write it to disk.
*/
fwrite(ptr1, len1, 1, fp);
/*
Unlock the sound to allow FMOD to use it again.
*/
FMOD_Sound_Unlock(sound, ptr1, ptr2, len1, len2);
fclose(fp);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *sound = 0;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, driver, recorddriver, numdrivers, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate playback devices
*/
result = FMOD_System_GetNumDrivers(system, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a PLAYBACK driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetDriverInfo(system, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
result = FMOD_System_SetDriver(system, driver);
ERRCHECK(result);
/*
Enumerate record devices
*/
result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = FMOD_System_SetRecordDriver(system, recorddriver, driver);
ERRCHECK(result);
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 2;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 44100;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
printf("===================================================================\n");
printf("Recording example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press 'r' to record a 5 second segment of audio and write it to a wav file.\n");
printf("Press 'p' to play the 5 second segment of audio.\n");
printf("Press 'l' to turn looping on/off.\n");
printf("Press 's' to stop recording and playback.\n");
printf("Press 'w' to save the 5 second segment to a wav file.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
static FMOD_CHANNEL *channel = 0;
static int looping = 0;
int recording = 0;
int playing = 0;
unsigned int recordpos = 0;
unsigned int playpos = 0;
unsigned int length;
if (kbhit())
{
key = getch();
switch (key)
{
case 'r' :
case 'R' :
{
result = FMOD_System_RecordStart(system, recorddriver, sound, looping);
ERRCHECK(result);
break;
}
case 'p' :
case 'P' :
{
if (looping)
{
FMOD_Sound_SetMode(sound, FMOD_LOOP_NORMAL);
}
else
{
FMOD_Sound_SetMode(sound, FMOD_LOOP_OFF);
}
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, 0, &channel);
ERRCHECK(result);
break;
}
case 'l' :
case 'L' :
{
looping = !looping;
break;
}
case 's' :
case 'S' :
{
result = FMOD_System_RecordStop(system, recorddriver);
if (channel)
{
FMOD_Channel_Stop(channel);
channel = 0;
}
break;
}
case 'w' :
case 'W' :
{
printf("Writing to record.wav ... \r");
SaveToWav(sound);
Sleep(500);
break;
}
}
}
FMOD_Sound_GetLength(sound, &length, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
FMOD_System_IsRecording(system, recorddriver, &recording);
ERRCHECK(result);
FMOD_System_GetRecordPosition(system, recorddriver, &recordpos);
ERRCHECK(result);
if (channel)
{
FMOD_Channel_IsPlaying(channel, &playing);
ERRCHECK(result);
FMOD_Channel_GetPosition(channel, &playpos, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
}
printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");
fflush(stdout);
FMOD_System_Update(system);
fflush(stdout);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,395 +0,0 @@
/*===============================================================================================
Record example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to record a sound, then write it to a wav file.
It then shows how to play a sound while it is being recorded to. Because it is recording, the
sound playback has to be delayed a little bit so that the playback doesn't play part of the
buffer that is still being written to.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#if defined(WIN32) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#define __PACKED /* dummy */
#else
#define __PACKED __attribute__((packed)) /* gcc packed */
#endif
/*
[
[DESCRIPTION]
Writes out the contents of a record buffer to a file.
[PARAMETERS]
[RETURN_VALUE]
void
[REMARKS]
]
*/
void SaveToWav(FMOD::Sound *sound)
{
FILE *fp;
int channels, bits;
float rate;
void *ptr1, *ptr2;
unsigned int lenbytes, len1, len2;
if (!sound)
{
return;
}
sound->getFormat (0, 0, &channels, &bits);
sound->getDefaults(&rate, 0, 0, 0);
sound->getLength (&lenbytes, FMOD_TIMEUNIT_PCMBYTES);
{
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack(1)
#endif
/*
WAV Structures
*/
typedef struct
{
signed char id[4];
int size;
} RiffChunk;
struct
{
RiffChunk chunk __PACKED;
unsigned short wFormatTag __PACKED; /* format type */
unsigned short nChannels __PACKED; /* number of channels (i.e. mono, stereo...) */
unsigned int nSamplesPerSec __PACKED; /* sample rate */
unsigned int nAvgBytesPerSec __PACKED; /* for buffer estimation */
unsigned short nBlockAlign __PACKED; /* block size of data */
unsigned short wBitsPerSample __PACKED; /* number of bits per sample of mono data */
} __PACKED FmtChunk = { {{'f','m','t',' '}, sizeof(FmtChunk) - sizeof(RiffChunk) }, 1, channels, (int)rate, (int)rate * channels * bits / 8, 1 * channels * bits / 8, bits };
struct
{
RiffChunk chunk;
} DataChunk = { {{'d','a','t','a'}, lenbytes } };
struct
{
RiffChunk chunk;
signed char rifftype[4];
} WavHeader = { {{'R','I','F','F'}, sizeof(FmtChunk) + sizeof(RiffChunk) + lenbytes }, {'W','A','V','E'} };
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack()
#endif
fp = fopen("record.wav", "wb");
/*
Write out the WAV header.
*/
fwrite(&WavHeader, sizeof(WavHeader), 1, fp);
fwrite(&FmtChunk, sizeof(FmtChunk), 1, fp);
fwrite(&DataChunk, sizeof(DataChunk), 1, fp);
/*
Lock the sound to get access to the raw data.
*/
sound->lock(0, lenbytes, &ptr1, &ptr2, &len1, &len2);
/*
Write it to disk.
*/
fwrite(ptr1, len1, 1, fp);
/*
Unlock the sound to allow FMOD to use it again.
*/
sound->unlock(ptr1, ptr2, len1, len2);
fclose(fp);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, driver, recorddriver, numdrivers, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate playback devices
*/
result = system->getNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a PLAYBACK driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = system->getDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
if (key == 27)
{
return 0;
}
driver = key - '1';
} while (driver < 0 || driver >= numdrivers);
result = system->setDriver(driver);
ERRCHECK(result);
/*
Enumerate record devices
*/
result = system->getRecordNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = system->getRecordDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 2;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 44100;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
printf("===================================================================\n");
printf("Recording example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("===================================================================\n");
printf("\n");
printf("Press 'r' to record a 5 second segment of audio and write it to a wav file.\n");
printf("Press 'p' to play the 5 second segment of audio.\n");
printf("Press 'l' to turn looping on/off.\n");
printf("Press 's' to stop recording and playback.\n");
printf("Press 'w' to save the 5 second segment to a wav file.\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Main loop.
*/
do
{
static FMOD::Channel *channel = 0;
static bool looping = false;
bool recording = false;
bool playing = false;
unsigned int recordpos = 0;
unsigned int playpos = 0;
unsigned int length;
if (kbhit())
{
key = getch();
switch (key)
{
case 'r' :
case 'R' :
{
result = system->recordStart(recorddriver, sound, looping);
ERRCHECK(result);
break;
}
case 'p' :
case 'P' :
{
if (looping)
{
sound->setMode(FMOD_LOOP_NORMAL);
}
else
{
sound->setMode(FMOD_LOOP_OFF);
}
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
ERRCHECK(result);
break;
}
case 'l' :
case 'L' :
{
looping = !looping;
break;
}
case 's' :
case 'S' :
{
result = system->recordStop(recorddriver);
if (channel)
{
channel->stop();
channel = 0;
}
break;
}
case 'w' :
case 'W' :
{
printf("Writing to record.wav ... \r");
SaveToWav(sound);
Sleep(500);
break;
}
}
}
sound->getLength(&length, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
system->isRecording(recorddriver, &recording);
ERRCHECK(result);
system->getRecordPosition(recorddriver, &recordpos);
ERRCHECK(result);
if (channel)
{
channel->isPlaying(&playing);
ERRCHECK(result);
channel->getPosition(&playpos, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
}
printf("State: %-19s. Record pos = %6d : Play pos = %6d : Loop %-3s\r", recording ? playing ? "Recording / playing" : "Recording" : playing ? "Playing" : "Idle", recordpos, playpos, looping ? "On" : "Off");
fflush(stdout);
system->update();
fflush(stdout);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
recordtodisk_cpp: main.cpp
g++ -O3 -o recordtodisk main.cpp ../../api/lib/libfmodex.so -pthread
recordtodisk_c: main.c
g++ -O3 -o recordtodisk main.c ../../api/lib/libfmodex.so -pthread
run:
./recordtodisk
clean:
rm -f recordtodisk

View File

@ -1,326 +0,0 @@
/*===============================================================================================
Record to disk example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to do a streaming record to disk.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#if defined(WIN32) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#define __PACKED /* dummy */
#else
#define __PACKED __attribute__((packed)) /* gcc packed */
#endif
/*
[
[DESCRIPTION]
Writes out the contents of a record buffer to a file.
[PARAMETERS]
[RETURN_VALUE]
void
[REMARKS]
]
*/
void WriteWavHeader(FILE *fp, FMOD_SOUND *sound, int length)
{
int channels, bits;
float rate;
if (!sound)
{
return;
}
fseek(fp, 0, SEEK_SET);
FMOD_Sound_GetFormat (sound, 0, 0, &channels, &bits);
FMOD_Sound_GetDefaults(sound, &rate, 0, 0, 0);
{
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack(1)
#endif
/*
WAV Structures
*/
typedef struct
{
signed char id[4];
int size;
} RiffChunk;
struct
{
RiffChunk chunk __PACKED;
unsigned short wFormatTag __PACKED; /* format type */
unsigned short nChannels __PACKED; /* number of channels (i.e. mono, stereo...) */
unsigned int nSamplesPerSec __PACKED; /* sample rate */
unsigned int nAvgBytesPerSec __PACKED; /* for buffer estimation */
unsigned short nBlockAlign __PACKED; /* block size of data */
unsigned short wBitsPerSample __PACKED; /* number of bits per sample of mono data */
} __PACKED FmtChunk = { {{'f','m','t',' '}, sizeof(FmtChunk) - sizeof(RiffChunk) }, 1, channels, (int)rate, (int)rate * channels * bits / 8, 1 * channels * bits / 8, bits };
struct
{
RiffChunk chunk;
} DataChunk = { {{'d','a','t','a'}, length } };
struct
{
RiffChunk chunk;
signed char rifftype[4];
} WavHeader = { {{'R','I','F','F'}, sizeof(FmtChunk) + sizeof(RiffChunk) + length }, {'W','A','V','E'} };
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack()
#endif
/*
Write out the WAV header.
*/
fwrite(&WavHeader, sizeof(WavHeader), 1, fp);
fwrite(&FmtChunk, sizeof(FmtChunk), 1, fp);
fwrite(&DataChunk, sizeof(DataChunk), 1, fp);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *sound = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, recorddriver, numdrivers, count;
unsigned int version;
FILE *fp;
unsigned int datalength = 0, soundlength;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate record devices
*/
result = FMOD_System_GetRecordNumDrivers(system, &numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = FMOD_System_GetRecordDriverInfo(system, count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 2;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 44100;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2;
result = FMOD_System_CreateSound(system, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
printf("========================================================================\n");
printf("Record to disk example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("========================================================================\n");
printf("\n");
printf("Press a key to start recording to record.wav\n");
printf("\n");
getch();
result = FMOD_System_RecordStart(system, recorddriver, sound, TRUE);
ERRCHECK(result);
printf("Press 'Esc' to quit\n");
printf("\n");
fp = fopen("record.wav", "wb");
if (!fp)
{
printf("ERROR : could not open record.wav for writing.\n");
return 1;
}
/*
Write out the wav header. As we don't know the length yet it will be 0.
*/
WriteWavHeader(fp, sound, datalength);
result = FMOD_Sound_GetLength(sound, &soundlength, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
/*
Main loop.
*/
do
{
static unsigned int lastrecordpos = 0;
unsigned int recordpos = 0;
if (kbhit())
{
key = getch();
}
FMOD_System_GetRecordPosition(system, recorddriver, &recordpos);
ERRCHECK(result);
if (recordpos != lastrecordpos)
{
void *ptr1, *ptr2;
int blocklength;
unsigned int len1, len2;
blocklength = (int)recordpos - (int)lastrecordpos;
if (blocklength < 0)
{
blocklength += soundlength;
}
/*
Lock the sound to get access to the raw data.
*/
FMOD_Sound_Lock(sound, lastrecordpos * 4, blocklength * 4, &ptr1, &ptr2, &len1, &len2); /* *4 = stereo 16bit. 1 sample = 4 bytes. */
/*
Write it to disk.
*/
if (ptr1 && len1)
{
datalength += fwrite(ptr1, 1, len1, fp);
}
if (ptr2 && len2)
{
datalength += fwrite(ptr2, 1, len2, fp);
}
/*
Unlock the sound to allow FMOD to use it again.
*/
FMOD_Sound_Unlock(sound, ptr1, ptr2, len1, len2);
}
lastrecordpos = recordpos;
printf("Record buffer pos = %6d : Record time = %02d:%02d\r", recordpos, datalength / exinfo.defaultfrequency / 4 / 60, (datalength / exinfo.defaultfrequency / 4) % 60);
fflush(stdout);
FMOD_System_Update(system);
Sleep(10);
} while (key != 27);
printf("\n");
/*
Write back the wav header now that we know its length.
*/
WriteWavHeader(fp, sound, datalength);
fclose(fp);
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,326 +0,0 @@
/*===============================================================================================
Record to disk example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to do a streaming record to disk.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
#if defined(WIN32) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#define __PACKED /* dummy */
#else
#define __PACKED __attribute__((packed)) /* gcc packed */
#endif
/*
[
[DESCRIPTION]
Writes out the contents of a record buffer to a file.
[PARAMETERS]
[RETURN_VALUE]
void
[REMARKS]
]
*/
void WriteWavHeader(FILE *fp, FMOD::Sound *sound, int length)
{
int channels, bits;
float rate;
if (!sound)
{
return;
}
fseek(fp, 0, SEEK_SET);
sound->getFormat (0, 0, &channels, &bits);
sound->getDefaults(&rate, 0, 0, 0);
{
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack(1)
#endif
/*
WAV Structures
*/
typedef struct
{
signed char id[4];
int size;
} RiffChunk;
struct
{
RiffChunk chunk __PACKED;
unsigned short wFormatTag __PACKED; /* format type */
unsigned short nChannels __PACKED; /* number of channels (i.e. mono, stereo...) */
unsigned int nSamplesPerSec __PACKED; /* sample rate */
unsigned int nAvgBytesPerSec __PACKED; /* for buffer estimation */
unsigned short nBlockAlign __PACKED; /* block size of data */
unsigned short wBitsPerSample __PACKED; /* number of bits per sample of mono data */
} __PACKED FmtChunk = { {{'f','m','t',' '}, sizeof(FmtChunk) - sizeof(RiffChunk) }, 1, channels, (int)rate, (int)rate * channels * bits / 8, 1 * channels * bits / 8, bits };
struct
{
RiffChunk chunk;
} DataChunk = { {{'d','a','t','a'}, length } };
struct
{
RiffChunk chunk;
signed char rifftype[4];
} WavHeader = { {{'R','I','F','F'}, sizeof(FmtChunk) + sizeof(RiffChunk) + length }, {'W','A','V','E'} };
#if defined(WIN32) || defined(_WIN64) || defined(__WATCOMC__) || defined(_WIN32) || defined(__WIN32__)
#pragma pack()
#endif
/*
Write out the WAV header.
*/
fwrite(&WavHeader, sizeof(WavHeader), 1, fp);
fwrite(&FmtChunk, sizeof(FmtChunk), 1, fp);
fwrite(&DataChunk, sizeof(DataChunk), 1, fp);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *sound = 0;
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO exinfo;
int key, recorddriver, numdrivers, count;
unsigned int version;
FILE *fp;
unsigned int datalength = 0, soundlength;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
/*
System initialization
*/
printf("---------------------------------------------------------\n");
printf("Select OUTPUT type\n");
printf("---------------------------------------------------------\n");
printf("1 : OSS - Open Sound System\n");
printf("2 : ALSA - Advanced Linux Sound Architecture\n");
printf("3 : ESD - Enlightenment Sound Daemon\n");
printf("4 : PULSEAUDIO - Pulse Audio Sound Server\n");
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
do
{
key = getch();
} while (key != 27 && key < '1' && key > '5');
switch (key)
{
case '1' : result = system->setOutput(FMOD_OUTPUTTYPE_OSS);
break;
case '2' : result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);
break;
case '3' : result = system->setOutput(FMOD_OUTPUTTYPE_ESD);
break;
case '4' : result = system->setOutput(FMOD_OUTPUTTYPE_PULSEAUDIO);
break;
default : return 1;
}
ERRCHECK(result);
/*
Enumerate record devices
*/
result = system->getRecordNumDrivers(&numdrivers);
ERRCHECK(result);
printf("---------------------------------------------------------\n");
printf("Choose a RECORD driver\n");
printf("---------------------------------------------------------\n");
for (count=0; count < numdrivers; count++)
{
char name[256];
result = system->getRecordDriverInfo(count, name, 256, 0);
ERRCHECK(result);
printf("%d : %s\n", count + 1, name);
}
printf("---------------------------------------------------------\n");
printf("Press a corresponding number or ESC to quit\n");
recorddriver = 0;
do
{
key = getch();
if (key == 27)
{
return 0;
}
recorddriver = key - '1';
} while (recorddriver < 0 || recorddriver >= numdrivers);
printf("\n");
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels = 2;
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 44100;
exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2;
result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
printf("========================================================================\n");
printf("Record to disk example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("========================================================================\n");
printf("\n");
printf("Press a key to start recording to record.wav\n");
printf("\n");
getch();
result = system->recordStart(recorddriver, sound, true);
ERRCHECK(result);
printf("Press 'Esc' to quit\n");
printf("\n");
fp = fopen("record.wav", "wb");
if (!fp)
{
printf("ERROR : could not open record.wav for writing.\n");
return 1;
}
/*
Write out the wav header. As we don't know the length yet it will be 0.
*/
WriteWavHeader(fp, sound, datalength);
result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
/*
Main loop.
*/
do
{
static unsigned int lastrecordpos = 0;
unsigned int recordpos = 0;
if (kbhit())
{
key = getch();
}
system->getRecordPosition(recorddriver, &recordpos);
ERRCHECK(result);
if (recordpos != lastrecordpos)
{
void *ptr1, *ptr2;
int blocklength;
unsigned int len1, len2;
blocklength = (int)recordpos - (int)lastrecordpos;
if (blocklength < 0)
{
blocklength += soundlength;
}
/*
Lock the sound to get access to the raw data.
*/
sound->lock(lastrecordpos * 4, blocklength * 4, &ptr1, &ptr2, &len1, &len2); /* *4 = stereo 16bit. 1 sample = 4 bytes. */
/*
Write it to disk.
*/
if (ptr1 && len1)
{
datalength += fwrite(ptr1, 1, len1, fp);
}
if (ptr2 && len2)
{
datalength += fwrite(ptr2, 1, len2, fp);
}
/*
Unlock the sound to allow FMOD to use it again.
*/
sound->unlock(ptr1, ptr2, len1, len2);
}
lastrecordpos = recordpos;
printf("Record buffer pos = %6d : Record time = %02d:%02d\r", recordpos, datalength / exinfo.defaultfrequency / 4 / 60, (datalength / exinfo.defaultfrequency / 4) % 60);
fflush(stdout);
system->update();
Sleep(10);
} while (key != 27);
printf("\n");
/*
Write back the wav header now that we know its length.
*/
WriteWavHeader(fp, sound, datalength);
fclose(fp);
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
ripnetstream_cpp: main.cpp
g++ -O3 -o ripnetstream main.cpp ../../api/lib/libfmodex.so
ripnetstream_c: main.c
g++ -O3 -o ripnetstream main.c ../../api/lib/libfmodex.so
run:
./ripnetstream
clean:
rm -f ripnetstream

View File

@ -1,332 +0,0 @@
/*===============================================================================================
RipNetStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to rip streaming audio from the internet to local files, using
System::attachFileSystem.
This example also uses tags from the net stream to name the files as they are ripped.
Some internet radio station only broadcast new tag information on fixed intervals. This
means that the rip might not be exactly in line with the filenames that are produced.
For example if a radio station only broadcast the track name every 10 seconds, and the
music changed half way inbetween this period, then the first file would contain 5 seconds
of the new song, and the second song would be missing the first 5 seconds of the track.
Silence detection might help this problem, but most radio stations do not offer silence
between tracks.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
FMOD_SOUND_TYPE gSoundType = FMOD_SOUND_TYPE_MPEG;
int gFileBufferSize = 128*1024;
char gCurrentTrackArtist[256];
char gCurrentTrackTitle[256];
int gUpdateFileName = FALSE;
char gOutputFileName[1024];
FILE *gFileHandle = 0;
/*
File callbacks
*/
FMOD_RESULT F_CALLBACK myopen(const char *name, int unicode, unsigned int *filesize, void **handle, void **userdata)
{
gFileHandle = fopen(gOutputFileName, "wb");
if (!gFileHandle)
{
return FMOD_ERR_FILE_NOTFOUND;
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myclose(void *handle, void *userdata)
{
if (!gFileHandle)
{
return FMOD_ERR_INVALID_PARAM;
}
fclose(gFileHandle);
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myread(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata)
{
if (!gFileHandle)
{
return FMOD_ERR_INVALID_PARAM;
}
/*
If the main thread detected a new tag name for artist / title, close the file and open a new one with the new name.
*/
if (gUpdateFileName)
{
char *ext;
gUpdateFileName = FALSE;
fclose(gFileHandle);
switch (gSoundType)
{
case FMOD_SOUND_TYPE_MPEG: /* MP2/MP3 */
{
ext = ".mp3";
break;
}
case FMOD_SOUND_TYPE_OGGVORBIS: /* Ogg vorbis */
{
ext = ".ogg";
break;
}
default:
{
ext = ".unknown";
break;
}
}
/*
If it is the 'temp file name' then rename the file and append to it instead of starting a new file
*/
if (!strcmp(gOutputFileName, "output.mp3"))
{
sprintf(gOutputFileName, "%s%s%s%s", gCurrentTrackArtist, strlen(gCurrentTrackTitle) ? " - " : "", gCurrentTrackTitle, ext);
rename("output.mp3", gOutputFileName);
gFileHandle = fopen(gOutputFileName, "ab+");
}
else
{
sprintf(gOutputFileName, "%s%s%s%s", gCurrentTrackArtist, strlen(gCurrentTrackTitle) ? " - " : "", gCurrentTrackTitle, ext);
gFileHandle = fopen(gOutputFileName, "wb");
}
if (!gFileHandle)
{
return FMOD_ERR_FILE_NOTFOUND;
}
}
fwrite(buffer, 1, sizebytes, gFileHandle);
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
memset(gCurrentTrackArtist, 0, 256);
memset(gCurrentTrackTitle, 0, 256);
strcpy(gOutputFileName, "output.mp3"); /* Start off like this then rename if a title tag comes along */
printf("======================================================================\n");
printf("RipNetStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n\n");
if (argc < 2)
{
printf("Usage: ripnetstream <url>\n");
return -1;
}
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 100, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_SetStreamBufferSize(system, gFileBufferSize, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = FMOD_System_AttachFileSystem(system, myopen, myclose, myread, 0);
ERRCHECK(result);
printf("Buffering...\n\n");
result = FMOD_System_CreateSound(system, argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
/*
Main loop
*/
do
{
if (sound && !channel)
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
}
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
if (channel)
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
}
break;
}
case 'm' :
case 'M' :
{
if (channel)
{
int mute;
FMOD_Channel_GetMute(channel, &mute);
FMOD_Channel_SetMute(channel, !mute);
}
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
unsigned int ms = 0;
int playing = FALSE;
int paused = FALSE;
int tagsupdated = 0;
FMOD_Sound_GetNumTags(sound, 0, &tagsupdated);
if (tagsupdated)
{
printf("\n");
printf("\n");
for (;;)
{
FMOD_TAG tag;
if (FMOD_Sound_GetTag(sound, 0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("[%-11s] %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
FMOD_Sound_GetFormat(sound, &gSoundType, 0, 0, 0);
if (!strcmp(tag.name, "ARTIST"))
{
if(strncmp(gCurrentTrackArtist, (const char *)tag.data, 256))
{
strncpy(gCurrentTrackArtist, (const char *)tag.data, 256);
gUpdateFileName = TRUE;
}
}
if (!strcmp(tag.name, "TITLE"))
{
if (strncmp(gCurrentTrackTitle, (const char *)tag.data, 256))
{
strncpy(gCurrentTrackTitle, (const char *)tag.data, 256);
gUpdateFileName = TRUE;
}
}
}
}
printf("\n");
}
result = FMOD_Channel_IsPlaying(channel, &playing);
if (result != FMOD_OK || !playing)
{
FMOD_Sound_Release(sound);
sound = 0;
channel = 0;
}
else
{
result = FMOD_Channel_GetPaused(channel, &paused);
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
printf("Time %02d:%02d:%02d : %s : Press SPACE to pause. 'm' to mute. ESC to quit.\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
}
if (sound)
{
FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;
FMOD_Sound_GetOpenState(sound, &openstate, 0, 0, 0);
if (openstate == FMOD_OPENSTATE_ERROR)
{
FMOD_Sound_Release(sound);
sound = 0;
channel = 0;
}
}
if (!sound)
{
printf("\n");
printf("Error occurred or stream ended. Restarting stream..\n");
result = FMOD_System_CreateSound(system, argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
Sleep(1000);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,332 +0,0 @@
/*===============================================================================================
RipNetStream Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to rip streaming audio from the internet to local files, using
System::attachFileSystem.
This example also uses tags from the net stream to name the files as they are ripped.
Some internet radio station only broadcast new tag information on fixed intervals. This
means that the rip might not be exactly in line with the filenames that are produced.
For example if a radio station only broadcast the track name every 10 seconds, and the
music changed half way inbetween this period, then the first file would contain 5 seconds
of the new song, and the second song would be missing the first 5 seconds of the track.
Silence detection might help this problem, but most radio stations do not offer silence
between tracks.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
FMOD_SOUND_TYPE gSoundType = FMOD_SOUND_TYPE_MPEG;
int gFileBufferSize = 128*1024;
char gCurrentTrackArtist[256];
char gCurrentTrackTitle[256];
bool gUpdateFileName = false;
char gOutputFileName[1024];
FILE *gFileHandle = 0;
/*
File callbacks
*/
FMOD_RESULT F_CALLBACK myopen(const char *name, int unicode, unsigned int *filesize, void **handle, void **userdata)
{
gFileHandle = fopen(gOutputFileName, "wb");
if (!gFileHandle)
{
return FMOD_ERR_FILE_NOTFOUND;
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myclose(void *handle, void *userdata)
{
if (!gFileHandle)
{
return FMOD_ERR_INVALID_PARAM;
}
fclose(gFileHandle);
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK myread(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata)
{
if (!gFileHandle)
{
return FMOD_ERR_INVALID_PARAM;
}
/*
If the main thread detected a new tag name for artist / title, close the file and open a new one with the new name.
*/
if (gUpdateFileName)
{
char *ext;
gUpdateFileName = false;
fclose(gFileHandle);
switch (gSoundType)
{
case FMOD_SOUND_TYPE_MPEG: /* MP2/MP3 */
{
ext = ".mp3";
break;
}
case FMOD_SOUND_TYPE_OGGVORBIS: /* Ogg vorbis */
{
ext = ".ogg";
break;
}
default:
{
ext = ".unknown";
break;
}
}
/*
If it is the 'temp file name' then rename the file and append to it instead of starting a new file
*/
if (!strcmp(gOutputFileName, "output.mp3"))
{
sprintf(gOutputFileName, "%s%s%s%s", gCurrentTrackArtist, strlen(gCurrentTrackTitle) ? " - " : "", gCurrentTrackTitle, ext);
rename("output.mp3", gOutputFileName);
gFileHandle = fopen(gOutputFileName, "ab+");
}
else
{
sprintf(gOutputFileName, "%s%s%s%s", gCurrentTrackArtist, strlen(gCurrentTrackTitle) ? " - " : "", gCurrentTrackTitle, ext);
gFileHandle = fopen(gOutputFileName, "wb");
}
if (!gFileHandle)
{
return FMOD_ERR_FILE_NOTFOUND;
}
}
fwrite(buffer, 1, sizebytes, gFileHandle);
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
memset(gCurrentTrackArtist, 0, 256);
memset(gCurrentTrackTitle, 0, 256);
strcpy(gOutputFileName, "output.mp3"); /* Start off like this then rename if a title tag comes along */
printf("======================================================================\n");
printf("RipNetStream Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n\n");
if (argc < 2)
{
printf("Usage: ripnetstream <url>\n");
return -1;
}
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(100, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->setStreamBufferSize(gFileBufferSize, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = system->attachFileSystem(myopen, myclose, myread, 0);
ERRCHECK(result);
printf("Buffering...\n\n");
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
/*
Main loop
*/
do
{
if (sound && !channel)
{
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
}
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
if (channel)
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
}
break;
}
case 'm' :
case 'M' :
{
if (channel)
{
bool mute;
channel->getMute(&mute);
channel->setMute(!mute);
}
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms = 0;
bool playing = false;
bool paused = false;
int tagsupdated = 0;
sound->getNumTags(0, &tagsupdated);
if (tagsupdated)
{
printf("\n");
printf("\n");
for (;;)
{
FMOD_TAG tag;
if (sound->getTag(0, -1, &tag) != FMOD_OK)
{
break;
}
if (tag.datatype == FMOD_TAGDATATYPE_STRING)
{
printf("[%-11s] %s (%d bytes)\n", tag.name, tag.data, tag.datalen);
sound->getFormat(&gSoundType, 0, 0, 0);
if (!strcmp(tag.name, "ARTIST"))
{
if (strncmp(gCurrentTrackArtist, (const char *)tag.data, 256))
{
strncpy(gCurrentTrackArtist, (const char *)tag.data, 256);
gUpdateFileName = true;
}
}
if (!strcmp(tag.name, "TITLE"))
{
if (strncmp(gCurrentTrackTitle, (const char *)tag.data, 256))
{
strncpy(gCurrentTrackTitle, (const char *)tag.data, 256);
gUpdateFileName = true;
}
}
}
}
printf("\n");
}
result = channel->isPlaying(&playing);
if (result != FMOD_OK || !playing)
{
sound->release();
sound = 0;
channel = 0;
}
else
{
result = channel->getPaused(&paused);
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
printf("Time %02d:%02d:%02d : %s : Press SPACE to pause. 'm' to mute. ESC to quit.\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
fflush(stdout);
}
if (sound)
{
FMOD_OPENSTATE openstate = FMOD_OPENSTATE_READY;
sound->getOpenState(&openstate, 0, 0, 0);
if (openstate == FMOD_OPENSTATE_ERROR)
{
sound->release();
sound = 0;
channel = 0;
}
}
if (!sound)
{
printf("\n");
printf("Error occurred or stream ended. Restarting stream..\n");
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
Sleep(1000);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
submixing_cpp: main.cpp
g++ -O3 -o submixing main.cpp ../../api/lib/libfmodex.so -pthread
submixing_c: main.c
g++ -O3 -o submixing main.c ../../api/lib/libfmodex.so -pthread
run:
./submixing
clean:
rm -f submixing

View File

@ -1,269 +0,0 @@
/*===============================================================================================
Submixing Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to put channels into channel groups, so that you can affect a group
of channels at a time instead of just one channel at a time.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound[5];
FMOD_CHANNEL *channel[5];
FMOD_CHANNELGROUP *groupA, *groupB, *masterGroup;
FMOD_DSP *dspreverb, *dspflange, *dsplowpass;
FMOD_RESULT result;
int key, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[0]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/jaguar.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[1]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/c.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[2]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/d.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[3]);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/e.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[4]);
ERRCHECK(result);
result = FMOD_System_CreateChannelGroup(system, "Group A", &groupA);
ERRCHECK(result);
result = FMOD_System_CreateChannelGroup(system, "Group B", &groupB);
ERRCHECK(result);
result = FMOD_System_GetMasterChannelGroup(system, &masterGroup);
ERRCHECK(result);
result = FMOD_ChannelGroup_AddGroup(masterGroup, groupA);
ERRCHECK(result);
result = FMOD_ChannelGroup_AddGroup(masterGroup, groupB);
ERRCHECK(result);
printf("======================================================================\n");
printf("Sub-mixing example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n");
printf(" (drumloop.wav) \n");
printf(" / \n");
printf(" (groupA) \n");
printf(" (reverb)/ \\ \n");
printf(" / (jaguar.wav) \n");
printf("(soundcard)--(lowpass)--(mastergroup) \n");
printf(" \\ (c.ogg) \n");
printf(" (flange) / \n");
printf(" \\(groupB)--(d.ogg) \n");
printf(" \\ \n");
printf(" (e.ogg) \n");
printf("Press 'A' to mute/unmute group A\n");
printf("Press 'B' to mute/unmute group B\n");
printf("\n");
printf("Press 'R' to place reverb on group A\n");
printf("Press 'F' to place flange on group B\n");
printf("Press 'L' to place lowpass on master group (everything)\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Start all the sounds!
*/
for (count = 0; count < 5; count++)
{
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound[count], TRUE, &channel[count]);
ERRCHECK(result);
if (count < 2)
{
result = FMOD_Channel_SetChannelGroup(channel[count], groupA);
}
else
{
result = FMOD_Channel_SetChannelGroup(channel[count], groupB);
}
ERRCHECK(result);
result = FMOD_Channel_SetPaused(channel[count], FALSE);
ERRCHECK(result);
}
/*
Create the DSP effects we want to apply to our submixes.
*/
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_SFXREVERB, &dspreverb);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_FLANGE, &dspflange);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dspflange, FMOD_DSP_FLANGE_RATE, 1.0f);
ERRCHECK(result);
result = FMOD_System_CreateDSPByType(system, FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);
result = FMOD_DSP_SetParameter(dsplowpass, FMOD_DSP_LOWPASS_CUTOFF, 500.0f);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'a' :
case 'A' :
{
static int mute = TRUE;
FMOD_ChannelGroup_SetMute(groupA, mute);
mute = !mute;
break;
}
case 'b' :
case 'B' :
{
static int mute = TRUE;
FMOD_ChannelGroup_SetMute(groupB, mute);
mute = !mute;
break;
}
case 'r' :
case 'R' :
{
static int reverb = TRUE;
if (reverb)
{
FMOD_ChannelGroup_AddDSP(groupA, dspreverb, 0);
}
else
{
FMOD_DSP_Remove(dspreverb);
}
reverb = !reverb;
break;
}
case 'f' :
case 'F' :
{
static int flange = TRUE;
if (flange)
{
FMOD_ChannelGroup_AddDSP(groupB, dspflange, 0);
}
else
{
FMOD_DSP_Remove(dspflange);
}
flange = !flange;
break;
}
case 'l' :
case 'L' :
{
static int lowpass = TRUE;
if (lowpass)
{
FMOD_ChannelGroup_AddDSP(masterGroup, dsplowpass, 0);
}
else
{
FMOD_DSP_Remove(dsplowpass);
}
lowpass = !lowpass;
break;
}
}
}
FMOD_System_Update(system);
{
int channelsplaying = 0;
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
printf("Channels Playing %2d\r", channelsplaying);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
for (count = 0; count < 5; count++)
{
result = FMOD_Sound_Release(sound[count]);
ERRCHECK(result);
}
result = FMOD_DSP_Release(dspreverb);
ERRCHECK(result);
result = FMOD_DSP_Release(dspflange);
ERRCHECK(result);
result = FMOD_DSP_Release(dsplowpass);
ERRCHECK(result);
result = FMOD_ChannelGroup_Release(groupA);
ERRCHECK(result);
result = FMOD_ChannelGroup_Release(groupB);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,269 +0,0 @@
/*===============================================================================================
Submixing Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to put channels into channel groups, so that you can affect a group
of channels at a time instead of just one channel at a time.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <stdio.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound[5];
FMOD::Channel *channel[5];
FMOD::ChannelGroup *groupA, *groupB, *masterGroup;
FMOD::DSP *dspreverb, *dspflange, *dsplowpass;
FMOD_RESULT result;
int key, count;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createSound("../media/drumloop.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[0]);
ERRCHECK(result);
result = system->createSound("../media/jaguar.wav", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[1]);
ERRCHECK(result);
result = system->createSound("../media/c.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[2]);
ERRCHECK(result);
result = system->createSound("../media/d.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[3]);
ERRCHECK(result);
result = system->createSound("../media/e.ogg", FMOD_SOFTWARE | FMOD_LOOP_NORMAL, 0, &sound[4]);
ERRCHECK(result);
result = system->createChannelGroup("Group A", &groupA);
ERRCHECK(result);
result = system->createChannelGroup("Group B", &groupB);
ERRCHECK(result);
result = system->getMasterChannelGroup(&masterGroup);
ERRCHECK(result);
result = masterGroup->addGroup(groupA);
ERRCHECK(result);
result = masterGroup->addGroup(groupB);
ERRCHECK(result);
printf("======================================================================\n");
printf("Sub-mixing example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("======================================================================\n");
printf(" (drumloop.wav) \n");
printf(" / \n");
printf(" (groupA) \n");
printf(" (reverb)/ \\ \n");
printf(" / (jaguar.wav) \n");
printf("(soundcard)--(lowpass)--(mastergroup) \n");
printf(" \\ (c.ogg) \n");
printf(" (flange) / \n");
printf(" \\(groupB)--(d.ogg) \n");
printf(" \\ \n");
printf(" (e.ogg) \n");
printf("Press 'A' to mute/unmute group A\n");
printf("Press 'B' to mute/unmute group B\n");
printf("\n");
printf("Press 'R' to place reverb on group A\n");
printf("Press 'F' to place flange on group B\n");
printf("Press 'L' to place lowpass on master group (everything)\n");
printf("Press 'Esc' to quit\n");
printf("\n");
/*
Start all the sounds!
*/
for (count = 0; count < 5; count++)
{
result = system->playSound(FMOD_CHANNEL_FREE, sound[count], true, &channel[count]);
ERRCHECK(result);
if (count < 2)
{
result = channel[count]->setChannelGroup(groupA);
}
else
{
result = channel[count]->setChannelGroup(groupB);
}
ERRCHECK(result);
result = channel[count]->setPaused(false);
ERRCHECK(result);
}
/*
Create the DSP effects we want to apply to our submixes.
*/
result = system->createDSPByType(FMOD_DSP_TYPE_SFXREVERB, &dspreverb);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_FLANGE, &dspflange);
ERRCHECK(result);
result = dspflange->setParameter(FMOD_DSP_FLANGE_RATE, 1.0f);
ERRCHECK(result);
result = system->createDSPByType(FMOD_DSP_TYPE_LOWPASS, &dsplowpass);
ERRCHECK(result);
result = dsplowpass->setParameter(FMOD_DSP_LOWPASS_CUTOFF, 500.0f);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case 'a' :
case 'A' :
{
static bool mute = true;
groupA->setMute(mute);
mute = !mute;
break;
}
case 'b' :
case 'B' :
{
static bool mute = true;
groupB->setMute(mute);
mute = !mute;
break;
}
case 'r' :
case 'R' :
{
static bool reverb = true;
if (reverb)
{
groupA->addDSP(dspreverb, 0);
}
else
{
dspreverb->remove();
}
reverb = !reverb;
break;
}
case 'f' :
case 'F' :
{
static bool flange = true;
if (flange)
{
groupB->addDSP(dspflange, 0);
}
else
{
dspflange->remove();
}
flange = !flange;
break;
}
case 'l' :
case 'L' :
{
static bool lowpass = true;
if (lowpass)
{
masterGroup->addDSP(dsplowpass, 0);
}
else
{
dsplowpass->remove();
}
lowpass = !lowpass;
break;
}
}
}
system->update();
{
int channelsplaying = 0;
system->getChannelsPlaying(&channelsplaying);
printf("Channels Playing %2d\r", channelsplaying);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
for (count = 0; count < 5; count++)
{
result = sound[count]->release();
ERRCHECK(result);
}
result = dspreverb->release();
ERRCHECK(result);
result = dspflange->release();
ERRCHECK(result);
result = dsplowpass->release();
ERRCHECK(result);
result = groupA->release();
ERRCHECK(result);
result = groupB->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
useplugins_cpp: main.cpp
g++ -O3 -o useplugins main.cpp ../../api/lib/libfmodex.so -pthread
useplugins_c: main.c
g++ -O3 -o useplugins main.c ../../api/lib/libfmodex.so -pthread
run:
./useplugins
clean:
rm -f useplugins

View File

@ -1,249 +0,0 @@
/*===============================================================================================
Use Plugins Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to use FMODEXP.DLYLIB and its associated plugins.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system = 0;
FMOD_SOUND *sound = 0;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
int count;
int playing = FALSE;
int key;
unsigned int version;
int numoutputplugins = 0;
unsigned int handle = 0;
/*
Global Settings
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
/*
Set the source directory for all of the FMOD plugins.
*/
result = FMOD_System_SetPluginPath(system, "../../api/plugins");
ERRCHECK(result);
/*
Display plugins
*/
{
int num;
char name[256];
printf("Codec plugins\n");
printf("--------------\n");
result = FMOD_System_GetNumPlugins(system, FMOD_PLUGINTYPE_CODEC, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = FMOD_System_GetPluginHandle(system, FMOD_PLUGINTYPE_CODEC, count, &handle);
ERRCHECK(result);
result = FMOD_System_GetPluginInfo(system, handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
printf("\n");
if (count % 2)
{
printf("\n");
}
printf("DSP plugins\n");
printf("--------------\n");
result = FMOD_System_GetNumPlugins(system, FMOD_PLUGINTYPE_DSP, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = FMOD_System_GetPluginHandle(system, FMOD_PLUGINTYPE_DSP, count, &handle);
ERRCHECK(result);
result = FMOD_System_GetPluginInfo(system, handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
printf("\n");
if (count % 2)
{
printf("\n");
}
printf("Output plugins\n");
printf("--------------\n");
result = FMOD_System_GetNumPlugins(system, FMOD_PLUGINTYPE_OUTPUT, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = FMOD_System_GetPluginHandle(system, FMOD_PLUGINTYPE_OUTPUT, count, &handle);
ERRCHECK(result);
result = FMOD_System_GetPluginInfo(system, handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
if (count % 2)
{
printf("\n");
}
numoutputplugins = num;
}
/*
System initialization
*/
printf("-----------------------------------------------------------------------\n"); // print driver names
printf("Press a corresponding number for an OUTPUT PLUGIN to use or ESC to quit\n");
do
{
key = getch();
} while (!(key == 27 || (key >= '1' && key <= '0' + numoutputplugins)));
if (key == 27)
{
return 0;
}
result = FMOD_System_GetPluginHandle(system, FMOD_PLUGINTYPE_OUTPUT, key - '1', &handle);
ERRCHECK(result);
result = FMOD_System_SetOutputByPlugin(system, handle);
ERRCHECK(result);
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = FMOD_System_CreateSound(system, "../media/wave.mp3", FMOD_SOFTWARE | FMOD_CREATESTREAM, 0, &sound);
ERRCHECK(result);
printf("Press a key to play sound to output device.\n");
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
unsigned int ms = 0;
unsigned int lenms = 0;
int paused = FALSE;
int channelsplaying = 0;
FMOD_SOUND *currentsound = 0;
FMOD_System_Update(system);
playing = FALSE;
result = FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
FMOD_Channel_GetCurrentSound(channel, &currentsound);
if (currentsound)
{
result = FMOD_Sound_GetLength(currentsound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
FMOD_System_GetChannelsPlaying(system, &channelsplaying);
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);
fflush(stdout);
Sleep(5);
if (kbhit())
{
key = getch();
if (key == 27)
{
break;
}
}
} while (playing);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

View File

@ -1,249 +0,0 @@
/*===============================================================================================
Use Plugins Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how to use FMODEXP.DYLIB and its associated plugins.
===============================================================================================*/
#include "../../api/inc/fmod.hpp"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system = 0;
FMOD::Sound *sound = 0;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int count;
bool playing = false;
int key;
unsigned int version;
int numoutputplugins = 0;
unsigned int handle = 0;
/*
Global Settings
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
getch();
return 0;
}
/*
Set the source directory for all of the FMOD plugins.
*/
result = system->setPluginPath("../../api/plugins");
ERRCHECK(result);
/*
Display plugins
*/
{
int num;
char name[256];
printf("Codec plugins\n");
printf("--------------\n");
result = system->getNumPlugins(FMOD_PLUGINTYPE_CODEC, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = system->getPluginHandle(FMOD_PLUGINTYPE_CODEC, count, &handle);
ERRCHECK(result);
result = system->getPluginInfo(handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
printf("\n");
if (count % 2)
{
printf("\n");
}
printf("DSP plugins\n");
printf("--------------\n");
result = system->getNumPlugins(FMOD_PLUGINTYPE_DSP, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = system->getPluginHandle(FMOD_PLUGINTYPE_DSP, count, &handle);
ERRCHECK(result);
result = system->getPluginInfo(handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
printf("\n");
if (count % 2)
{
printf("\n");
}
printf("Output plugins\n");
printf("--------------\n");
result = system->getNumPlugins(FMOD_PLUGINTYPE_OUTPUT, &num);
ERRCHECK(result);
for (count = 0; count < num; count++)
{
result = system->getPluginHandle(FMOD_PLUGINTYPE_OUTPUT, count, &handle);
ERRCHECK(result);
result = system->getPluginInfo(handle, 0, name, 256, 0);
ERRCHECK(result);
printf("%2d - %-30s", count + 1, name);
if (count % 2)
{
printf("\n");
}
}
if (count % 2)
{
printf("\n");
}
numoutputplugins = num;
}
/*
System initialization
*/
printf("-----------------------------------------------------------------------\n"); // print driver names
printf("Press a corresponding number for an OUTPUT PLUGIN to use or ESC to quit\n");
do
{
key = getch();
} while (!(key == 27 || (key >= '1' && key <= '0' + numoutputplugins)));
if (key == 27)
{
return 0;
}
result = system->getPluginHandle(FMOD_PLUGINTYPE_OUTPUT, key - '1', &handle);
ERRCHECK(result);
result = system->setOutputByPlugin(handle);
ERRCHECK(result);
result = system->init(32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
result = system->createSound("../media/wave.mp3", FMOD_SOFTWARE | FMOD_CREATESTREAM, 0, &sound);
ERRCHECK(result);
printf("Press a key to play sound to output device.\n");
result = system->playSound(FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool paused = false;
int channelsplaying = 0;
FMOD::Sound *currentsound = 0;
system->update();
playing = false;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
channel->getCurrentSound(&currentsound);
if (currentsound)
{
result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
system->getChannelsPlaying(&channelsplaying);
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);
fflush(stdout);
Sleep(5);
if (kbhit())
{
key = getch();
if (key == 27)
{
break;
}
}
} while (playing);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}

View File

@ -1,11 +0,0 @@
usercreatedsound_cpp: main.cpp
g++ -O3 -o usercreatedsound main.cpp ../../api/lib/libfmodex.so
usercreatedsound_c: main.c
g++ -O3 -o usercreatedsound main.c ../../api/lib/libfmodex.so
run:
./usercreatedsound
clean:
rm -f usercreatedsound

View File

@ -1,215 +0,0 @@
/*===============================================================================================
User Created Sound Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
This example shows how create a sound with data filled by the user.
It shows a user created static sample, followed by a user created stream.
The former allocates all memory needed for the sound and is played back as a static sample,
while the latter streams the data in chunks as it plays, using far less memory.
===============================================================================================*/
#include "../../api/inc/fmod.h"
#include "../../api/inc/fmod_errors.h"
#include "../common/wincompat.h"
#include <math.h>
#include <string.h>
void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)
{
unsigned int count;
static float t1 = 0, t2 = 0; // time
static float v1 = 0, v2 = 0; // velocity
signed short *stereo16bitbuffer = (signed short *)data;
for (count=0; count<datalen>>2; count++) // >>2 = 16bit stereo (4 bytes per sample)
{
*stereo16bitbuffer++ = (signed short)(sin(t1) * 32767.0f); // left channel
*stereo16bitbuffer++ = (signed short)(sin(t2) * 32767.0f); // right channel
t1 += 0.01f + v1;
t2 += 0.0142f + v2;
v1 += (float)(sin(t1) * 0.002f);
v2 += (float)(sin(t2) * 0.002f);
}
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK pcmsetposcallback(FMOD_SOUND *sound, int subsound, unsigned int position, FMOD_TIMEUNIT postype)
{
/*
This is useful if the user calls FMOD_Sound_SetPosition and you want to seek your data accordingly.
*/
return FMOD_OK;
}
int main(int argc, char *argv[])
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
FMOD_MODE mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE;
int key;
int channels = 2;
FMOD_CREATESOUNDEXINFO createsoundexinfo;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD_System_Create(&system);
ERRCHECK(result);
result = FMOD_System_GetVersion(system, &version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);
printf("============================================================================\n");
printf("User Created Sound Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("============================================================================\n");
printf("Sound played here is generated in realtime. It will either play as a stream\n");
printf("which means it is continually filled as it is playing, or it will play as a \n");
printf("static sample, which means it is filled once as the sound is created, then \n");
printf("when played it will just play that short loop of data. \n");
printf("============================================================================\n");
printf("\n");
do
{
printf("Press 1 to play as a runtime decoded stream. (will carry on infinitely)\n");
printf("Press 2 to play as a static in memory sample. (loops a short block of data)\n");
printf("Press Esc to quit.\n\n");
key = getch();
} while (key != 27 && key != '1' && key != '2');
if (key == 27)
{
return 0;
}
else if (key == '1')
{
mode |= FMOD_CREATESTREAM;
}
memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* required. */
createsoundexinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */
createsoundexinfo.length = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
createsoundexinfo.numchannels = channels; /* Number of channels in the sound. */
createsoundexinfo.defaultfrequency = 44100; /* Default playback rate of sound. */
createsoundexinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */
createsoundexinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */
createsoundexinfo.pcmsetposcallback = pcmsetposcallback; /* User callback for seeking. */
result = FMOD_System_CreateSound(system, 0, mode, &createsoundexinfo, &sound);
ERRCHECK(result);
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
int paused;
FMOD_Channel_GetPaused(channel, &paused);
FMOD_Channel_SetPaused(channel, !paused);
break;
}
}
}
FMOD_System_Update(system);
if (channel)
{
unsigned int ms;
unsigned int lenms;
int playing;
int paused;
FMOD_Channel_IsPlaying(channel, &playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPaused(channel, &paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Channel_GetPosition(channel, &ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = FMOD_Sound_GetLength(sound, &lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = FMOD_Sound_Release(sound);
ERRCHECK(result);
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More