[xiph-commits] r11218 - in branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs: . libOOVorbis

illiminable at svn.xiph.org illiminable at svn.xiph.org
Fri Apr 21 13:42:05 PDT 2006


Author: illiminable
Date: 2006-04-21 13:41:56 -0700 (Fri, 21 Apr 2006)
New Revision: 11218

Added:
   branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/
   branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.cpp
   branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.h
   branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.cpp
   branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.h
Log:
* Simple vorbis wrapper - to be abstracted to handle vorbis and tremor

Added: branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.cpp
===================================================================
--- branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.cpp	2006-04-21 19:18:23 UTC (rev 11217)
+++ branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.cpp	2006-04-21 20:41:56 UTC (rev 11218)
@@ -0,0 +1,134 @@
+#include "StdAfx.h"
+#include "VorbisDecoder.h"
+
+VorbisDecoder::VorbisDecoder(void)
+	:	mPacketCount(0)
+	,	mNumChannels(0)
+	,	mSampleRate(0)
+{
+	vorbis_info_init(&mVorbisInfo);
+	vorbis_comment_init(&mVorbisComment);
+
+}
+
+VorbisDecoder::~VorbisDecoder(void)
+{
+}
+
+VorbisDecoder::eVorbisResult VorbisDecoder::decodeHeader()
+{
+	int locRet = vorbis_synthesis_headerin(&mVorbisInfo, &mVorbisComment, &mWorkPacket);
+	if (locRet < 0) {
+		//Error
+		return VORBIS_HEADER_BAD;
+	}
+
+	return VORBIS_HEADER_OK;
+}
+
+VorbisDecoder::eVorbisResult VorbisDecoder::decodeComment()
+{
+	int locRet = vorbis_synthesis_headerin(&mVorbisInfo, &mVorbisComment, &mWorkPacket);
+	if (locRet < 0) {
+		//Error
+		return VORBIS_COMMENT_BAD;
+	}
+
+	return VORBIS_COMMENT_OK;
+}
+VorbisDecoder::eVorbisResult VorbisDecoder::decodeCodebook()
+{
+	int locRet = vorbis_synthesis_headerin(&mVorbisInfo, &mVorbisComment, &mWorkPacket);
+	if (locRet < 0) {
+		//Error
+		return VORBIS_CODEBOOK_BAD;
+	}
+
+	locRet = vorbis_synthesis_init(&mVorbisState, &mVorbisInfo);
+
+	//TODO::: What return codes?
+
+	locRet = vorbis_block_init(&mVorbisState, &mVorbisBlock);
+
+	mNumChannels = mVorbisInfo.channels;
+	mSampleRate = mVorbisInfo.rate;
+
+	return VORBIS_CODEBOOK_OK;
+}
+VorbisDecoder::eVorbisResult VorbisDecoder::decodePacket(		const unsigned char* inPacket
+											,	unsigned long inPacketSize
+											,	short* outSamples
+											,	unsigned long inOutputBufferSize)
+{
+	mWorkPacket.b_o_s = 0;
+	mWorkPacket.bytes = inPacketSize;
+	mWorkPacket.e_o_s = 0;
+	mWorkPacket.granulepos = 0;
+	mWorkPacket.packet = (unsigned char*)inPacket;		//Naughty!
+	mWorkPacket.packetno = mPacketCount;
+
+	if (mPacketCount == 0) {
+		mPacketCount++;
+		mWorkPacket.b_o_s = 1;
+		return decodeHeader();
+	} else if (mPacketCount == 1) {
+		//Comment
+		mPacketCount++;
+		return decodeComment();
+	} else if (mPacketCount == 2) {
+		//Codebooks
+		mPacketCount++;
+		return decodeCodebook();
+	} else {
+		mPacketCount++;
+
+		int locRet = vorbis_synthesis(&mVorbisBlock, &mWorkPacket);
+
+		if (locRet != 0) {
+			//Error
+			return VORBIS_SYNTH_FAILED;
+		}
+
+		locRet = vorbis_synthesis_blockin(&mVorbisState, &mVorbisBlock);
+
+		if (locRet != 0) {
+			//Error
+			return VORBIS_BLOCKIN_FAILED;
+		}
+
+		float** locPCM;
+		int locNumSamples;
+		int locTemp = 0;
+		short* locOutBuffer;
+		
+		while ((locNumSamples = vorbis_synthesis_pcmout(&mVorbisState, &locPCM)) > 0) {
+			if (locNumSamples * mNumChannels * sizeof(short) > inOutputBufferSize) {
+				//TODO::: Buffer overflow
+			} else {
+				
+				for (int chan= 0; chan < mNumChannels; chan++) {
+					//Interleave offset
+					locOutBuffer = outSamples + chan;
+					//Pointer into one channel of pcm
+					float* locOneChannel = locPCM[chan];
+					for (int i = 0; i < locNumSamples; i++) {
+						locTemp = (int)(locOneChannel[i] * 32767.0f);
+						*locOutBuffer = clip16(locTemp);
+
+						//Jump forward numChannels in the buffer
+						locOutBuffer += mNumChannels;
+					}
+				}
+
+				vorbis_synthesis_read(&mVorbisState, locNumSamples);
+			}
+
+		}
+
+		return VORBIS_DATA_OK;
+
+
+		
+	}
+
+}
\ No newline at end of file

Added: branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.h
===================================================================
--- branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.h	2006-04-21 19:18:23 UTC (rev 11217)
+++ branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/VorbisDecoder.h	2006-04-21 20:41:56 UTC (rev 11218)
@@ -0,0 +1,56 @@
+#pragma once
+
+#include <vorbis/codec.h>
+
+class VorbisDecoder
+{
+public:
+	VorbisDecoder(void);
+	~VorbisDecoder(void);
+
+
+
+	enum eVorbisResult {
+		VORBIS_DATA_OK = 0,
+		VORBIS_HEADER_OK,
+		VORBIS_COMMENT_OK,
+		VORBIS_CODEBOOK_OK,
+		VORBIS_ERROR_MIN = 64,
+		VORBIS_HEADER_BAD,
+		VORBIS_COMMENT_BAD,
+		VORBIS_CODEBOOK_BAD,
+		VORBIS_SYNTH_FAILED,
+		VORBIS_BLOCKIN_FAILED
+	};
+
+	//bool setDecodeParams(SpeexDecodeSettings inSettings);
+	eVorbisResult decodePacket(		const unsigned char* inPacket
+								,	unsigned long inPacketSize
+								,	short* outSamples
+								,	unsigned long inOutputBufferSize); 
+
+	int numChannels()	{	return mNumChannels;	}
+	int sampleRate()	{	return mSampleRate;		}
+protected:
+	eVorbisResult decodeHeader();
+	eVorbisResult decodeComment();
+	eVorbisResult decodeCodebook();
+
+	short clip16(int inVal)		{	return (short)((inVal > 32767) ? (32767) : ((inVal < -32768) ? (-32768) : (inVal)));	}
+	unsigned long mPacketCount;
+
+	int mNumChannels;
+	int mSampleRate;
+	//int mNumFrames;
+	//int mNumExtraHeaders;
+	//bool mIsVBR;
+
+	vorbis_info mVorbisInfo;
+	vorbis_comment mVorbisComment;
+	vorbis_dsp_state mVorbisState;
+	vorbis_block mVorbisBlock;
+
+	ogg_packet mWorkPacket;
+
+
+};

Added: branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.cpp
===================================================================
--- branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.cpp	2006-04-21 19:18:23 UTC (rev 11217)
+++ branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.cpp	2006-04-21 20:41:56 UTC (rev 11218)
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// libOOVorbis.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file

Added: branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.h
===================================================================
--- branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.h	2006-04-21 19:18:23 UTC (rev 11217)
+++ branches/oggdsf_ce_port/src/lib/codecs/vorbis/libs/libOOVorbis/stdafx.h	2006-04-21 20:41:56 UTC (rev 11218)
@@ -0,0 +1,13 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+
+#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
+
+
+
+// TODO: reference additional headers your program requires here



More information about the commits mailing list