Exemple #1
0
void Splicer::pull(AudioChunk &chunk)
{
	Uint32 left = chunk.length(), chans = chunk.format().channels;

	Sint32 *data[PG_MAX_CHANNELS];
	for (Uint32 i = 0; i < chans; ++i) data[i] = chunk.start(i);

	//Query exhausted each loop to refresh the value of "current".
	while (!exhausted())
	{
		//Pull data from next stream
		AudioChunk sub(chunk.scratch(), output, data, left, chunk.sync);
		current->pull(sub);

		//Partial advance
		if (current->exhausted())
		{
			Uint32 cut = sub.cutoff();
			for (Uint32 i = 0; i < chans; ++i) data[i] += cut;
			left -= cut;
			current = NULL;
			if (left) continue;
		}
		return;
	}

	//The Splicer is exhausted!
	chunk.cutoff(data[0] - chunk.start(0));
}
Exemple #2
0
			virtual void pull(AudioChunk &chunk)
			{
				if (!chunk.length())   return;
				if (!valid || finished) {chunk.silence(); return;}

				int samples, have = 0, need = chunk.length();

				//Create pointers to 16-bit data
				short *d16[PG_MAX_CHANNELS];
				for (Uint32 i = 0; i < chunk.format().channels; ++i)
					d16[i] = (short*) chunk.start(i);

				while (true)
				{
					samples = stb_vorbis_get_samples_short(ogg,
						chunk.format().channels, d16, (need-have));

					if (samples < 0)
					{
						finished = true;
						//cout << " VORBIS ERROR" << endl;
						break;
					}
					if (samples == 0)
					{
						//File's end
						if (loop)
						{
							stb_vorbis_seek_start(ogg);
							continue;
						}
						else
						{
							finished = true;
							break;
						}
					}

					for (Uint32 i=0; i < chunk.format().channels; ++i)
						d16[i] += samples;
					have += samples;
					//if (have > need) cout << "VORBIS OVERDRAW" << endl;

					//std::cout << "OGG pull: " << have << "/" << need << std::endl;

					if (have >= need) break;
				}

				//Cutoff marker if necessary
				if (have < need) chunk.cutoff(have);

				//Upsample data to 24-bit Sint32s
				for (Uint32 i=0; i < chunk.format().channels; ++i)
				{
					Sint32 *start = chunk.start(i), *op = start + have;
					short *ip = d16[i];
					while (op!=start) {*(--op) = 256 * Sint32(*(--ip));}
				}
			}