1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| package particule_V3;
import java.nio.ByteBuffer;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import org.jouvieje.FmodEx.Channel;
import org.jouvieje.FmodEx.FmodEx;
import org.jouvieje.FmodEx.Init;
import org.jouvieje.FmodEx.Sound;
import org.jouvieje.FmodEx.System;
import org.jouvieje.FmodEx.Defines.INIT_MODES;
import org.jouvieje.FmodEx.Enumerations.FMOD_RESULT;
import org.jouvieje.FmodEx.Exceptions.InitException;
import org.jouvieje.FmodEx.Structures.FMOD_CREATESOUNDEXINFO;
import son.Medias;
import static org.jouvieje.FmodEx.Defines.FMOD_INITFLAGS.FMOD_INIT_NORMAL;
import static org.jouvieje.FmodEx.Defines.FMOD_MODE.FMOD_HARDWARE;
import static org.jouvieje.FmodEx.Defines.FMOD_MODE.FMOD_LOOP_OFF;
import static org.jouvieje.FmodEx.Defines.FMOD_MODE.FMOD_OPENMEMORY;
import static org.jouvieje.FmodEx.Defines.VERSIONS.FMOD_VERSION;
import static org.jouvieje.FmodEx.Defines.VERSIONS.NATIVEFMODEX_JAR_VERSION;
import static org.jouvieje.FmodEx.Defines.VERSIONS.NATIVEFMODEX_LIBRARY_VERSION;
import static org.jouvieje.FmodEx.Enumerations.FMOD_CHANNELINDEX.FMOD_CHANNEL_FREE;
import static org.jouvieje.FmodEx.Enumerations.FMOD_RESULT.FMOD_ERR_CHANNEL_STOLEN;
import static org.jouvieje.FmodEx.Enumerations.FMOD_RESULT.FMOD_ERR_INVALID_HANDLE;
import static org.jouvieje.FmodEx.Enumerations.FMOD_RESULT.FMOD_OK;
import static org.jouvieje.FmodEx.Misc.BufferUtils.newByteBuffer;
import static org.jouvieje.FmodEx.Misc.BufferUtils.SIZEOF_INT;
import static org.jouvieje.FmodEx.Enumerations.FMOD_RESULT.FMOD_OK;
public class Son extends JFrame {
JFrame frame;
JPanel info;
JTextArea info_erreur;
private System system = new System();
private Sound mon_son = new Sound();
private final static String newline = "\n";
private void ErrorCheck(FMOD_RESULT result, String text) {
if(result != FMOD_OK) {
String errstring = String.format("FMOD error! (%d)\n%s", result.asInt(), FmodEx.FMOD_ErrorString(result));
//printf("%s", errstring);
info_erreur.append(text + ": " + errstring + newline);
}
}
public static void main(String[] args) {
Son frame = new Son();
frame.setVisible(true);
}
public Son() {
super("Son");
initGUI();
initFMOD();
}
private void initFMOD() {
// TODO Auto-generated method stub
try
{
Init.loadLibraries(INIT_MODES.INIT_FMOD_EX_MINIMUM);
info_erreur.append("NativeFmodEx ok" + newline);
}
catch(InitException e)
{
info_erreur.append("NativeFmodEx error! %s\n" + newline);
// exit(1);
}
ByteBuffer soundBuffer;
FMOD_CREATESOUNDEXINFO exinfo;
Channel channel = new Channel();
FMOD_RESULT result;
int version;
/*
* Buffer used to store all datas received from FMOD.
*/
ByteBuffer buffer = newByteBuffer(SIZEOF_INT);
/*
* Create a System object and initialize.
*/
result = FmodEx.System_Create(system);
ErrorCheck(result, "SystemCreate");
result = system.getVersion(buffer.asIntBuffer());
ErrorCheck(result, "Version");
version = buffer.getInt(0);
if(version < FMOD_VERSION) {
info_erreur.append("Error! You are using an old version of FMOD %08x." + newline);
return;
}
result = system.init(32, FMOD_INIT_NORMAL, null);
ErrorCheck(result, "Initialisation");
// Erreur numero 1
soundBuffer = Medias.loadMediaIntoMemory("N:\\user_folder\\modules\\PR_PROJ_PROG\\code\\Projet\\bin\\son\\Media\\drumloop.wav");
// soundBuffer = Medias.loadMediaIntoMemory("/Media/drumloop.wav");
exinfo = FMOD_CREATESOUNDEXINFO.create();
exinfo.setLength(soundBuffer.capacity());
result = system.createSound(soundBuffer, FMOD_HARDWARE | FMOD_OPENMEMORY, exinfo, mon_son);
ErrorCheck(result, "CreateSound");
soundBuffer = null;
exinfo.release();
result = mon_son.setMode(FMOD_LOOP_OFF);// drumloop.wav has embedded loop points which automatically makes looping turn on,
ErrorCheck(result, "SetMode"); //so turn it off here. We could have also just put FMOD_LOOP_OFF in the above CreateSound call.
result = system.playSound(FMOD_CHANNEL_FREE, mon_son, false, channel);
ErrorCheck(result, "PlaySound");
}
private void initGUI() {
// TODO Auto-generated method stub
info = new JPanel();
info_erreur = new JTextArea(10,35);
info_erreur.setLineWrap(true);
info_erreur.setWrapStyleWord(true);
info.add(info_erreur);
getContentPane().add(info);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} |