diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
commit | 9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch) | |
tree | 4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/org/tritonus/file/AuAudioOutputStream.java | |
parent | dfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff) | |
download | rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.tar.gz rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.zip |
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/org/tritonus/file/AuAudioOutputStream.java')
-rw-r--r-- | songdbj/org/tritonus/file/AuAudioOutputStream.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/songdbj/org/tritonus/file/AuAudioOutputStream.java b/songdbj/org/tritonus/file/AuAudioOutputStream.java new file mode 100644 index 0000000000..9f33e7a2aa --- /dev/null +++ b/songdbj/org/tritonus/file/AuAudioOutputStream.java | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | * AuAudioOutputStream.java | ||
3 | * | ||
4 | * This file is part of Tritonus: http://www.tritonus.org/ | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Copyright (c) 2000,2001 by Florian Bomers <http://www.bomers.de> | ||
9 | * Copyright (c) 1999 by Matthias Pfisterer | ||
10 | * | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU Library General Public License as published | ||
14 | * by the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU Library General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU Library General Public | ||
23 | * License along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | * | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | |<--- this code is formatted to fit into 80 columns --->| | ||
30 | */ | ||
31 | |||
32 | package org.tritonus.sampled.file; | ||
33 | |||
34 | import java.io.IOException; | ||
35 | import javax.sound.sampled.AudioFormat; | ||
36 | import javax.sound.sampled.AudioFileFormat; | ||
37 | import javax.sound.sampled.AudioSystem; | ||
38 | import org.tritonus.share.TDebug; | ||
39 | import org.tritonus.share.sampled.file.TAudioOutputStream; | ||
40 | import org.tritonus.share.sampled.file.TDataOutputStream; | ||
41 | |||
42 | |||
43 | |||
44 | /** | ||
45 | * AudioOutputStream for AU files. | ||
46 | * | ||
47 | * @author Florian Bomers | ||
48 | * @author Matthias Pfisterer | ||
49 | */ | ||
50 | |||
51 | public class AuAudioOutputStream extends TAudioOutputStream { | ||
52 | |||
53 | private static String description="Created by Tritonus"; | ||
54 | |||
55 | /** | ||
56 | * Writes a null-terminated ascii string s to f. | ||
57 | * The total number of bytes written is aligned on a 2byte boundary. | ||
58 | * @exception IOException Write error. | ||
59 | */ | ||
60 | protected static void writeText(TDataOutputStream dos, String s) throws IOException { | ||
61 | if (s.length()>0) { | ||
62 | dos.writeBytes(s); | ||
63 | dos.writeByte(0); // pour terminer le texte | ||
64 | if ((s.length() % 2)==0) { | ||
65 | // ajout d'un zero pour faire la longeur pair | ||
66 | dos.writeByte(0); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Returns number of bytes that have to written for string s (with alignment) | ||
73 | */ | ||
74 | protected static int getTextLength(String s) { | ||
75 | if (s.length()==0) { | ||
76 | return 0; | ||
77 | } else { | ||
78 | return (s.length()+2) & 0xFFFFFFFE; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public AuAudioOutputStream(AudioFormat audioFormat, | ||
83 | long lLength, | ||
84 | TDataOutputStream dataOutputStream) { | ||
85 | // if length exceeds 2GB, set the length field to NOT_SPECIFIED | ||
86 | super(audioFormat, | ||
87 | lLength>0x7FFFFFFFl?AudioSystem.NOT_SPECIFIED:lLength, | ||
88 | dataOutputStream, | ||
89 | lLength == AudioSystem.NOT_SPECIFIED && dataOutputStream.supportsSeek()); | ||
90 | } | ||
91 | |||
92 | protected void writeHeader() throws IOException { | ||
93 | if (TDebug.TraceAudioOutputStream) { | ||
94 | TDebug.out("AuAudioOutputStream.writeHeader(): called."); | ||
95 | } | ||
96 | AudioFormat format = getFormat(); | ||
97 | long lLength = getLength(); | ||
98 | TDataOutputStream dos = getDataOutputStream(); | ||
99 | if (TDebug.TraceAudioOutputStream) { | ||
100 | TDebug.out("AuAudioOutputStream.writeHeader(): AudioFormat: " + format); | ||
101 | TDebug.out("AuAudioOutputStream.writeHeader(): length: " + lLength); | ||
102 | } | ||
103 | |||
104 | dos.writeInt(AuTool.AU_HEADER_MAGIC); | ||
105 | dos.writeInt(AuTool.DATA_OFFSET+getTextLength(description)); | ||
106 | dos.writeInt((lLength!=AudioSystem.NOT_SPECIFIED)?((int) lLength):AuTool.AUDIO_UNKNOWN_SIZE); | ||
107 | dos.writeInt(AuTool.getFormatCode(format)); | ||
108 | dos.writeInt((int) format.getSampleRate()); | ||
109 | dos.writeInt(format.getChannels()); | ||
110 | writeText(dos, description); | ||
111 | } | ||
112 | |||
113 | protected void patchHeader() throws IOException { | ||
114 | TDataOutputStream tdos = getDataOutputStream(); | ||
115 | tdos.seek(0); | ||
116 | setLengthFromCalculatedLength(); | ||
117 | writeHeader(); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | /*** AuAudioOutputStream.java ***/ | ||