1 /*
2  * Copyright 2011-2012 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis 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 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 
44 #include "audio/AudioGlobal.h"
45 
46 #include "audio/Mixer.h"
47 #include "audio/Sample.h"
48 #include "audio/Ambiance.h"
49 #include "audio/AudioEnvironment.h"
50 
51 #include "io/resource/ResourcePath.h"
52 
53 namespace audio {
54 
55 // Audio device interface
56 Backend * backend = NULL;
57 
58 // Global settings
59 res::path sample_path;
60 res::path ambiance_path;
61 res::path environment_path;
62 size_t stream_limit_bytes = DEFAULT_STREAMLIMIT;
63 size_t session_time = 0;
64 
65 // Resources
66 ResourceList<Mixer> _mixer;
67 ResourceList<Sample> _sample;
68 ResourceList<Ambiance> _amb;
69 ResourceList<Environment> _env;
70 
unitsToBytes(size_t v,const PCMFormat & _format,TimeUnit unit)71 size_t unitsToBytes(size_t v, const PCMFormat & _format, TimeUnit unit) {
72 	switch(unit) {
73 		case UNIT_MS:
74 			return (size_t)(float(v) * 0.001f * _format.frequency * _format.channels * (_format.quality >> 3)) / 1000;
75 		case UNIT_SAMPLES:
76 			return v * _format.channels * (_format.quality >> 3);
77 		default:
78 			return v;
79 	}
80 }
81 
bytesToUnits(size_t v,const PCMFormat & _format,TimeUnit unit)82 size_t bytesToUnits(size_t v, const PCMFormat & _format, TimeUnit unit) {
83 	switch(unit) {
84 		case UNIT_MS      :
85 			return (size_t)(float(v) * 1000.f / (_format.frequency * _format.channels * (_format.quality >> 3)));
86 		case UNIT_SAMPLES :
87 			return v / (_format.frequency * _format.channels * (_format.quality >> 3));
88 
89 		default:
90 			return v;
91 	}
92 }
93 
94 } // namespace audio
95