aboutsummaryrefslogtreecommitdiff
path: root/html/pattern.html
blob: 54e05d641624d9120f2f34a91cc0a657b7502505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
Pattern
<p>
Fill in the grid with a pattern of black and white squares, so that
the numbers in each row and column match the lengths of consecutive
runs of black squares.
<p>
Left-click in a square to mark it black; right-click (or hold Ctrl
while left-clicking) to mark it white. Click and drag along a row or
column to mark multiple squares black or white at once. Middle-click
(or hold Shift while left-clicking) to return a square to grey
(meaning undecided): dragging like that can erase a whole rectangle,
not just a row or column.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
/*
 *	VorbisAudioFileReader.java
 *
 *	This file is part of Tritonus: http://www.tritonus.org/
 */

/*
 *  Copyright (c) 2001 - 2004 by Matthias Pfisterer
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
|<---            this code is formatted to fit into 80 columns             --->|
*/

package org.tritonus.sampled.file.pvorbis;

import java.io.InputStream;
import java.io.IOException;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.tritonus.share.TDebug;
import org.tritonus.share.sampled.file.TAudioFileFormat;
import org.tritonus.share.sampled.file.TAudioFileReader;

import org.tritonus.lowlevel.pogg.Buffer;
import org.tritonus.lowlevel.pogg.Page;
import org.tritonus.lowlevel.pogg.Packet;
import org.tritonus.lowlevel.pogg.SyncState;
import org.tritonus.lowlevel.pogg.StreamState;



/**
 * @author Matthias Pfisterer
 */
public class VorbisAudioFileReader
extends TAudioFileReader
{
	private static final int	INITAL_READ_LENGTH = 4096;
	private static final int	MARK_LIMIT = INITAL_READ_LENGTH + 1;



	public VorbisAudioFileReader()
	{
		super(MARK_LIMIT, true);
	}



	protected AudioFileFormat getAudioFileFormat(InputStream inputStream,
						     long lFileSizeInBytes)
		throws UnsupportedAudioFileException, IOException
	{
		if (TDebug.TraceAudioFileReader) { TDebug.out(">VorbisAudioFileReader.getAudioFileFormat(): begin"); }
		SyncState	oggSyncState = new SyncState();
		StreamState	oggStreamState = new StreamState();
		Page		oggPage = new Page();
		Packet		oggPacket = new Packet();

		int		bytes = 0;

		// Decode setup

		oggSyncState.init(); // Now we can read pages

		// grab some data at the head of the stream.  We want the first page
		// (which is guaranteed to be small and only contain the Vorbis
		// stream initial header) We need the first page to get the stream
		// serialno.

		// submit a 4k block to libvorbis' Ogg layer
		byte[]	abBuffer = new byte[INITAL_READ_LENGTH];
		bytes = inputStream.read(abBuffer);
		if (TDebug.TraceAudioFileReader) { TDebug.out("read bytes from input stream: " + bytes); }
		int nResult = oggSyncState.write(abBuffer, bytes);
		if (TDebug.TraceAudioFileReader) { TDebug.out("SyncState.write() returned " + nResult); }
    
		// Get the first page.
		if (oggSyncState.pageOut(oggPage) != 1)
		{
			// have we simply run out of data?  If so, we're done.
			if (bytes < INITAL_READ_LENGTH)
			{
				if (TDebug.TraceAudioFileReader) { TDebug.out("stream ended prematurely"); }
				if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
				// IDEA: throw EOFException?
				oggSyncState.free();
				oggStreamState.free();
				oggPage.free();
				oggPacket.free();
				throw new UnsupportedAudioFileException("not a Vorbis stream: ended prematurely");
			}
			if (TDebug.TraceAudioFileReader) { TDebug.out("not in Ogg bitstream format"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
      			throw new UnsupportedAudioFileException("not a Vorbis stream: not in Ogg bitstream format");
		}

		// Get the serial number and set up the rest of decode.
		// serialno first; use it to set up a logical stream
		int nSerialNo = oggPage.getSerialNo();
		if (TDebug.TraceAudioFileReader) TDebug.out("serial no.: " + nSerialNo);
		oggStreamState.init(nSerialNo);

		// extract the initial header from the first page and verify that the
		// Ogg bitstream is in fact Vorbis data

		// I handle the initial header first instead of just having the code
		// read all three Vorbis headers at once because reading the initial
		// header is an easy way to identify a Vorbis bitstream and it's
		// useful to see that functionality seperated out.

		if (oggStreamState.pageIn(oggPage) < 0)
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("can't read first page of Ogg bitstream data"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			// error; stream version mismatch perhaps
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: can't read first page of Ogg bitstream data");
		}
    
		if (oggStreamState.packetOut(oggPacket) != 1)
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("can't read initial header packet"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			// no page? must not be vorbis
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: can't read initial header packet");
		}

		byte[]	abData = oggPacket.getData();
		if (TDebug.TraceAudioFileReader)
		{
			String	strData = "";
			for (int i = 0; i < abData.length; i++)
			{
				strData += " " + abData[i];
			}
			TDebug.out("packet data: " + strData);
		}

		int nPacketType = abData[0];
		if (TDebug.TraceAudioFileReader) { TDebug.out("packet type: " + nPacketType); }
		if (nPacketType != 1)
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("first packet is not the identification header"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: first packet is not the identification header");
		}
		if(abData[1] != 'v' ||
		   abData[2] != 'o' ||
		   abData[3] != 'r' ||
		   abData[4] != 'b' ||
		   abData[5] != 'i' ||
		   abData[6] != 's')
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("not a vorbis header packet"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: not a vorbis header packet");
		}
		if (! oggPacket.isBos())
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("initial packet not marked as beginning of stream"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: initial packet not marked as beginning of stream");
		}
		int	nVersion = (abData[7] & 0xFF) + 256 * (abData[8] & 0xFF) + 65536 * (abData[9] & 0xFF) + 16777216 * (abData[10] & 0xFF);
		if (TDebug.TraceAudioFileReader) { TDebug.out("version: " + nVersion); }
		if (nVersion != 0)
		{
			if (TDebug.TraceAudioFileReader) { TDebug.out("wrong vorbis version"); }
			if (TDebug.TraceAudioFileReader) { TDebug.out("<VorbisAudioFileReader.getAudioFileFormat(): throwing exception"); }
			oggSyncState.free();
			oggStreamState.free();
			oggPage.free();
			oggPacket.free();
			throw new UnsupportedAudioFileException("not a Vorbis stream: wrong vorbis version");
		}
		int	nChannels = (abData[11] & 0xFF);