Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2793 in orxonox.OLD for orxonox/branches/sound/src/sound_control.cc


Ignore:
Timestamp:
Nov 10, 2004, 10:37:57 PM (20 years ago)
Author:
simon
Message:

in branches/sound: made a tester, which is not finished yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/sound/src/sound_control.cc

    r2777 r2793  
    1414*/
    1515
    16 #include "Sound_control.h"
     16#include "sound_control.h"
    1717#include <string.h>
    1818#include "SDL_mixer.h"
     
    2929*/
    3030SoundControl::SoundControl () {
    31   
     31 
    3232  //setup parameters
    3333  int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0;
     
    3737  //initializing sound and calling Mix_OpenAudio
    3838  if(SDL_Init(SDL_INIT_AUDIO)<0){
    39     printf("SDL_Init:\n");
     39    printf("SDL_Init: \n");
    4040    exit(1);
    4141  }
    4242
    4343  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
    44     printf("Mix_OpenAudio:\n");
     44    printf("Mix_OpenAudio: \n");
    4545    exit(1);
    4646  }
     
    4949}
    5050
     51SoundControl::SoundControl (int audio_rate audiorate, Uint16 audio_format audioformat, int audio_channels audiochannels, int audio_buffers audiobuffers) {
     52 
     53  //setup parameters
     54  int audio_rate = audiorate, audio_channels = audiochannels, audio_buffers = audiobuffers, bits = 0;
     55  Uint16 audio_format = audioformat;
     56  Mix_Music* music = NULL;
     57 
     58  //initializing sound and calling Mix_OpenAudio
     59  if(SDL_Init(SDL_INIT_AUDIO)<0){
     60    printf("SDL_Init: \n");
     61    exit(1);
     62  }
     63
     64  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){
     65    printf("Mix_OpenAudio: \n");
     66    exit(1);
     67  }
     68
     69  postConstruction();
     70}
     71
    5172
    5273/**
     
    5475*/
    5576SoundControl::~SoundControl () {
    56 }
     77  SoundControl* SoundControl::singleton = NULL;
     78}
     79
     80SoundControl* SoundControl::singleton = NULL;
    5781
    5882
     
    6589  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
    6690  bits=audio_format&0xFF;
    67   printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
    68          bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers );
     91  printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels > 1 ? "stereo" : "mono", audio_buffers );
    6992 
    7093  int volume = SDL_MIX_MAXVOLUME;
     
    7295  int track_number = 1;
    7396  int done = 0;
    74   int free = 1;
    75 }
    76 
    77 
    78 /**
    79     \brief Returns false if a sound_control object has been made
    80 */
    81 void SoundControl::isFree () {
    82   return free;
    83 }
     97}
    8498
    8599
     
    96110    \param filename: self-explanatory
    97111*/
    98 void SoundControl::playMod (char* fileName) {
    99 
    100 }
    101 
    102 
    103 /**
    104     \brief May be called from any WorldEntity to play a .wav file
    105     \param filename: self-explanatory
    106 */
    107 void SoundControl::playWav (char* fileName) {
     112int SoundControl::playMod (char* fileName) {
    108113  Mix_Chunk* chunk = NULL;
    109114  chunk = Mix_LoadWAV(fileName);
     
    111116    printf("Mix_PlayChannel: %s\n", Mix_GetError());
    112117  }
     118}
     119
     120
     121/**
     122    \brief May be called from any WorldEntity to play a .wav file
     123    \param filename: self-explanatory
     124*/
     125int SoundControl::playWav (char* fileName) {
     126  Mix_Chunk* chunk = NULL;
     127  chunk = Mix_LoadWAV(fileName);
     128  if(Mix_PlayChannel(-1, chunk, 0) == -1) {
     129    printf("Mix_PlayChannel: %s\n", Mix_GetError());
     130  }
    113131}
    114132
     
    118136    \param filename: self-explanatory
    119137*/
    120 void SoundControl::playOgg (char* fileName) {
     138int SoundControl::playOgg (char* fileName) {
    121139  Mix_Music* music = NULL;
    122140  music = Mix_LoadMUS(fileName);
     
    212230
    213231/**
    214     \brief Called by playOgg
     232    \brief Hooked by playOgg at end of .ogg playback
    215233*/
    216234void SoundControl::musicDone () {
    217235  track_number++;
    218 }
    219 
     236  Mix_HaltMusic();
     237  Mix_FreeMusic(music);
     238  music = NULL;
     239}
Note: See TracChangeset for help on using the changeset viewer.