Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lDEVinux
GitHub Repository: lDEVinux/eaglercraft
Path: blob/main/src/lwjgl/java/tritonus/TAudioInputStream.java
8642 views
1
/*
2
* TAudioInputStream.java
3
*
4
* This file is part of Tritonus: http://www.tritonus.org/
5
*/
6
7
/*
8
* Copyright (c) 2003 by Matthias Pfisterer
9
* Copyright (c) 2012 by fireandfuel from Cuina Team (http://www.cuina.byethost12.com/)
10
*
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU Library General Public License as published
13
* by the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* You should have received a copy of the GNU Library General Public
22
* License along with this program; if not, write to the Free Software
23
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
*/
25
26
package tritonus;
27
28
import java.io.InputStream;
29
30
import java.util.Collections;
31
import java.util.HashMap;
32
import java.util.Map;
33
34
import javax.sound.sampled.AudioFormat;
35
import javax.sound.sampled.AudioInputStream;
36
37
/**
38
* AudioInputStream base class. This class implements "dynamic" properties.
39
* "Dynamic" properties are properties that may change during the life time of
40
* the objects. This is typically used to pass information like the current
41
* frame number, volume of subbands and similar values. "Dynamic" properties are
42
* different from properties in AudioFormat and AudioFileFormat, which are
43
* considered "static", as they aren't allowed to change after creating of the
44
* object, thereby maintaining the immutable character of these classes.
45
*/
46
47
public class TAudioInputStream extends AudioInputStream
48
{
49
private Map<String, Object> m_properties;
50
private Map<String, Object> m_unmodifiableProperties;
51
52
/**
53
* Constructor without properties. Creates an empty properties map.
54
*/
55
public TAudioInputStream(InputStream inputStream, AudioFormat audioFormat, long lLengthInFrames)
56
{
57
super(inputStream, audioFormat, lLengthInFrames);
58
initMaps(new HashMap<String, Object>());
59
}
60
61
/**
62
* Constructor with properties. The passed properties map is not copied.
63
* This allows subclasses to change values in the map after creation, and
64
* the changes are reflected in the map the application program can obtain.
65
*/
66
public TAudioInputStream(InputStream inputStream, AudioFormat audioFormat,
67
long lLengthInFrames, Map<String, Object> properties)
68
{
69
super(inputStream, audioFormat, lLengthInFrames);
70
initMaps(properties);
71
}
72
73
private void initMaps(Map<String, Object> properties)
74
{
75
/*
76
* Here, we make a shallow copy of the map. It's unclear if this is
77
* sufficient (of if a deep copy should be made).
78
*/
79
m_properties = properties;
80
m_unmodifiableProperties = Collections.unmodifiableMap(m_properties);
81
}
82
83
/**
84
* Obtain a Map containing the properties. This method returns a Map that
85
* cannot be modified by the application program, but reflects changes to
86
* the map made by the implementation.
87
*
88
* @return a map containing the properties.
89
*/
90
public Map<String, Object> properties()
91
{
92
return m_unmodifiableProperties;
93
}
94
95
/**
96
* Set a property. Unlike in AudioFormat and AudioFileFormat, this method
97
* may be used anywhere by subclasses - it is not restricted to be used in
98
* the constructor.
99
*/
100
protected void setProperty(String key, Object value)
101
{
102
m_properties.put(key, value);
103
}
104
}
105
106
/*** TAudioInputStream.java ***/
107
108