Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound/src/sound_control.cc @ 2780

Last change on this file since 2780 was 2777, checked in by simon, 20 years ago

/branches/sound: brought up sound_control.cc which doesn't do anything at the moment.

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3   
4   Copyright (C) 2004 orx
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10   
11   ### File Specific:
12   main-programmer: Simon Hofmann
13   co-programmer:
14*/
15
16#include "Sound_control.h"
17#include <string.h> 
18#include "SDL_mixer.h"
19
20using namespace std;
21
22
23/**
24    \brief standard constructor
25   
26    This constructor builds a SoundControl Object, which waits for callers
27    calling its functions to output sound. All sound output is handles by this 
28    object, which must only be constructed once.
29*/ 
30SoundControl::SoundControl () { 
31 
32  //setup parameters
33  int audio_rate = MIX_DEFAULT_FREQUENCY, audio_channels = MIX_DEFAULT_CHANNELS, audio_buffers = 8192, bits = 0; 
34  Uint16 audio_format = MIX_DEFAULT_FORMAT; 
35  Mix_Music* music = NULL; 
36 
37  //initializing sound and calling Mix_OpenAudio
38  if(SDL_Init(SDL_INIT_AUDIO)<0){ 
39    printf("SDL_Init:\n"); 
40    exit(1); 
41  } 
42
43  if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)){ 
44    printf("Mix_OpenAudio:\n"); 
45    exit(1); 
46  } 
47
48  postConstruction();
49}
50
51
52/**
53    \brief standard destructor
54*/ 
55SoundControl::~SoundControl () { 
56}
57
58
59/**
60    \brief Is called by SoundControl object to initiate all values
61*/ 
62void SoundControl::postConstruction () { 
63 
64  // Print some info
65  Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); 
66  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 ); 
69 
70  int volume = SDL_MIX_MAXVOLUME;
71  Mix_VolumeMusic(volume);
72  int track_number = 1;
73  int done = 0;
74  int free = 1;
75} 
76
77
78/**
79    \brief Returns false if a sound_control object has been made
80*/ 
81void SoundControl::isFree () { 
82  return free;
83}
84
85
86/**
87    \brief Sets the number of output Channels
88*/ 
89void SoundControl::setNumberOfChannels (int number_of_channels) { 
90  Mix_AllocateChannels(number_of_channels);
91} 
92
93
94/**
95    \brief May be called from any WorldEntity to play a .xm file
96    \param filename: self-explanatory
97*/ 
98void 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*/ 
107void SoundControl::playWav (char* fileName) {
108  Mix_Chunk* chunk = NULL; 
109  chunk = Mix_LoadWAV(fileName); 
110  if(Mix_PlayChannel(-1, chunk, 0) == -1) {
111    printf("Mix_PlayChannel: %s\n", Mix_GetError());
112  }
113} 
114
115
116/**
117    \brief May be called from any WorldEntity to play a .ogg file
118    \param filename: self-explanatory
119*/ 
120void SoundControl::playOgg (char* fileName) {
121  Mix_Music* music = NULL;
122  music = Mix_LoadMUS(fileName);
123  if(Mix_PlayMusic(music, 1) == -1){
124    printf("Mix_PlayMusic: %s\n",Mix_GetError());
125  }
126  Mix_HookMusicFinished(musicDone);
127} 
128
129
130/**
131    \brief Heightens the overall volume of output
132*/ 
133void SoundControl::volumeUp () { 
134  volume = (volume + 1) << 1; 
135  if(volume > SDL_MIX_MAXVOLUME) 
136    volume = SDL_MIX_MAXVOLUME; 
137  Mix_VolumeMusic(volume); 
138} 
139
140
141/**
142    \brief Lowers the overall volume of output
143*/ 
144void SoundControl::volumeDown () { 
145  volume >>= 1; 
146  Mix_VolumeMusic(volume); 
147} 
148
149
150/**
151    \brief Rewinds music to the beginning
152*/ 
153void SoundControl::trackRewind () { 
154  Mix_RewindMusic(); 
155} 
156
157
158/**
159    \brief Rewinds the music 5 seconds
160*/ 
161void SoundControl::forwardMusic () { 
162  Mix_SetMusicPosition(+5); 
163} 
164
165
166/**
167    \brief Forwards the music 5 seconds
168*/ 
169void SoundControl::rewindMusic () { 
170  Mix_SetMusicPosition(-5); 
171} 
172
173
174/**
175    \brief Pauses music output
176*/ 
177void SoundControl::pauseMusic () {
178  Mix_PauseMusic()
179} 
180
181
182/**
183    \brief this function pauses music output
184*/ 
185void SoundControl::resumeMusic () {
186  Mix_ResumeMusic()
187} 
188
189/**
190    \brief Selects the track of all orxonox tracks
191*/
192void SoundControl::trackSelect () { 
193  switch (track_number) { 
194  case 1: 
195    music = Mix_LoadMUS("luke_grey_orxonox1.ogg"); 
196    break; 
197  case 2: 
198    music = Mix_LoadMUS("luke_grey_orxonox2.ogg"); 
199    break; 
200  case 3: 
201    music = Mix_LoadMUS("luke_grey_orxonox3.ogg"); 
202    break; 
203  case 4: 
204    music = Mix_LoadMUS("luke_grey_and aquarius_orxonox.ogg"); 
205    break; 
206  case 5: 
207    music = Mix_LoadMUS("nomenes_orxonox.ogg"); 
208    break; 
209  } 
210}
211
212
213/**
214    \brief Called by playOgg
215*/ 
216void SoundControl::musicDone () {
217  track_number++; 
218} 
219
Note: See TracBrowser for help on using the repository browser.