Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2793 in orxonox.OLD for orxonox


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

Location:
orxonox/branches/sound/src
Files:
2 added
2 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}
  • orxonox/branches/sound/src/sound_control.h

    r2777 r2793  
    1 
    2 #ifndef PROTO_CLASS_H
    3 #define PROTO_CLASS_H
     1#ifndef SOUNDCONTROL_CLASS_H
     2#define SOUNDCONTROL_CLASS_H
    43
    54#include "data_tank.h"
    65
    7 
    8 class ProtoClass {
     6class SoundControl {
    97
    108 public:
    11   ProtoClass ();
    12   ~ProtoClass ();
     9  SoundControl ();
     10  ~SoundControl ();
     11  void setNumberOfChannels(int number_of channels);
     12  int playMod(char* filename);
     13  int playWav(char* filename);
     14  int playOgg(char* filename);
     15  void volumeUp();
     16  void volumeDown();
     17  void trackRewind();
     18  void forwardMusic();
     19  void rewindMusic();
     20  void pauseMusic();
     21  void resumeMusic();
     22  void trackSelect();
    1323
    14 };
     24private:
     25  void postConstruction();
     26  SoundControl* singleton;
     27
     28}
    1529
    1630#endif
Note: See TracChangeset for help on using the changeset viewer.