BambooIsland: C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SoundManager.cpp Source File

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

# C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/SoundManager.cpp

    00001 #include "SoundManager.h"
    00002
    00003 #include <stdio.h>
    00004 #include <string.h>
    00005
    00006 SoundManager::SoundManager(void)
    00007 {
    00008         /*
    00009         Create a System object and initialize.
    00010         */
    00011         result = FMOD::System_Create(&system);
    00012         ERRCHECK(result);
    00013
    00014         result = system->getVersion(&version);
    00015         ERRCHECK(result);
    00016
    00017         if (version < FMOD_VERSION)
    00018         {
    00019                 printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n",
    00020                         version, FMOD_VERSION);
    00021                 //return 0;
    00022         }
    00023
    00024         result = system->getNumDrivers(&numdrivers);
    00025         ERRCHECK(result);
    00026
    00027         if (numdrivers == 0)
    00028         {
    00029                 result = system->setOutput(FMOD_OUTPUTTYPE_NOSOUND);
    00030                 ERRCHECK(result);
    00031         }
    00032         else
    00033         {
    00034                 result = system->getDriverCaps(0, &caps, 0, 0, &speakermode);
    00035                 ERRCHECK(result);
    00036
    00037                 /*
    00038                 Set the user selected speaker mode.
    00039                 */
    00040                 result = system->setSpeakerMode(speakermode);
    00041                 ERRCHECK(result);
    00042
    00043                 if (caps & FMOD_CAPS_HARDWARE_EMULATED)
    00044                 {
    00045                         /*
    00046                         The user has the 'Acceleration' slider set to off!  This is really bad
    00047                         for latency! You might want to warn the user about this.
    00048                         */
    00049                         result = system->setDSPBufferSize(1024, 10);
    00050                         ERRCHECK(result);
    00051                 }
    00052
    00053                 result = system->getDriverInfo(0, name, 256, 0);
    00054                 ERRCHECK(result);
    00055
    00056                 if (strstr(name, "SigmaTel"))
    00057                 {
    00058                         /*
    00059                         Sigmatel sound devices crackle for some reason if the format is PCM 16bit.
    00060                         PCM floating point output seems to solve it.
    00061                         */
    00062                         result = system->setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0,
    00063                                 FMOD_DSP_RESAMPLER_LINEAR);
    00064                         ERRCHECK(result);
    00065                 }
    00066         }
    00067
    00068         // init system with max 100 channels
    00069         result = system->init(100, FMOD_INIT_NORMAL, 0);
    00070         if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)
    00071         {
    00072                 /*
    00073                 Ok, the speaker mode selected isn't supported by this soundcard.  Switch it
    00074                 back to stereo...
    00075                 */
    00076                 result = system->setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
    00077                 ERRCHECK(result);
    00078
    00079                 /*
    00080                 ... and re-init.
    00081                 */
    00082                 result = system->init(100, FMOD_INIT_NORMAL, 0);
    00083                 ERRCHECK(result);
    00084         }
    00085 }
    00086
    00087 void SoundManager::ERRCHECK(FMOD_RESULT result)
    00088 {
    00089         if (result != FMOD_OK)
    00090         {
    00091                 printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
    00092         }
    00093 }
    00094
    00095 void SoundManager::playSound(char* filepath){
    00096         FMOD::Sound *sound;
    00097         result = system->createStream(filepath, FMOD_2D | FMOD_HARDWARE | FMOD_LOOP_NORMAL, 0, &sound);         // FMOD_DEFAULT uses the defaults.  These are the same as FMOD_LOOP_OFF | FMOD_2D | FMOD_HARDWARE.
    00098         ERRCHECK(result);
    00099         FMOD::Channel *channel;
    00100         sound->setLoopCount(10);
    00101         system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    00102
    00103 }
    00104
    00105 SoundManager::~SoundManager(void)
    00106 {
    00107         system->release(); // release sounds and close sound device
    00108 }

All Classes Functions Variables Enumerations Enumerator