[xiph-commits] r8029 - trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Sat Oct 16 08:34:57 PDT 2004


Author: illiminable
Date: 2004-10-16 08:34:56 -0700 (Sat, 16 Oct 2004)
New Revision: 8029

Added:
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.cpp
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.h
Modified:
   trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/libFLACHelper.vcproj
Log:
* Initial attempt at FLAC Push decoder.

Added: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.cpp
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.cpp	2004-10-16 14:18:17 UTC (rev 8028)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.cpp	2004-10-16 15:34:56 UTC (rev 8029)
@@ -0,0 +1,130 @@
+#include "StdAfx.h"
+#include ".\flacpushdecoder.h"
+
+FLACPushDecoder::FLACPushDecoder(void)
+	:	mInPacket(NULL)
+	,	mOutPacket(NULL)
+	,	mNumChannels(0)
+	,	mFrameSize(0)
+	,	mSampleRate(0)
+	,	mBegun(false)
+{
+
+}
+
+FLACPushDecoder::~FLACPushDecoder(void)
+{
+	delete mInPacket;
+	delete mOutPacket;
+}
+
+void FLACPushDecoder::initCodec() {
+	init();
+}
+void FLACPushDecoder::flushCodec() {
+	flush();
+}
+StampedOggPacket* FLACPushDecoder::decodeFLAC(OggPacket* inPacket) {
+	//Basically puts the incoming packet into the member variable.
+	//Calls process_single() and the read call back is fired.
+	//The read callback feeds in the packet we just saved.
+	//The write callback fires.
+	//The write callback sets the outpacket into a member variable.
+	//We return the member variable.
+	delete mInPacket;
+	mInPacket = inPacket;
+	if(process_single()) {
+		return mOutPacket;
+	} else {
+		delete mInPacket;
+		mInPacket = NULL;
+		delete mOutPacket;
+		mOutPacket = NULL;
+		return NULL;
+	}
+
+}
+//FLAC Callbacks
+::FLAC__StreamDecoderReadStatus FLACPushDecoder::read_callback(FLAC__byte outBuffer[], unsigned* outNumBytes) 
+{
+	//If we have a packet waiting...
+	if (mInPacket != NULL) {
+		//Copy it onto the buffer.
+		memcpy((void*)outBuffer, (const void*)mInPacket->packetData(), mInPacket->packetSize());
+
+		//Tell the decoder how big it is.
+		*outNumBytes = mInPacket->packetSize();
+		
+		//Delete the packet.
+		delete mInPacket;
+		mInPacket = NULL;
+	
+		return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+
+	} else {
+		return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+	}
+
+}
+::FLAC__StreamDecoderWriteStatus FLACPushDecoder::write_callback(const ::FLAC__Frame* inFrame, const FLAC__int32* const inBuffer[]) 
+{
+
+	if (! mBegun) {
+	
+		mBegun = true;
+		
+		mNumChannels = inFrame->header.channels;
+		mFrameSize = mNumChannels * SIZE_16_BITS;
+		mSampleRate = inFrame->header.sample_rate;
+		
+	}
+	unsigned long locNumFrames = inFrame->header.blocksize;
+	unsigned long locActualSize = locNumFrames * mFrameSize;
+	unsigned long locTotalFrameCount = locNumFrames * mNumChannels;
+
+	//BUG::: There's a bug here. Implicitly assumes 2 channels.
+	unsigned char* locBuff = new unsigned char[locActualSize];
+
+
+	signed short* locShortBuffer = (signed short*)locBuff;		//Don't delete this.
+	
+	signed short tempInt = 0;
+	int tempLong = 0;
+	float tempFloat = 0;
+	
+	//FIX:::Move the clipping to the abstract function
+	//Make sure our sample buffer is big enough
+
+	//Modified for FLAC int32 not float
+
+		
+	//Must interleave and convert sample size.
+	for(unsigned long i = 0; i < locNumFrames; i++) {
+		for (unsigned long j = 0; j < mNumChannels; j++) {
+			
+			
+				//No clipping required for ints
+				//FIX:::Take out the unnescessary variable.
+			tempLong = inBuffer[j][i];
+				//Convert 32 bit to 16 bit
+
+			//FIX::: Why on earth are you dividing by 2 ? It does not make sense !
+			tempInt = (signed short)(tempLong/2);
+		
+			*locShortBuffer = tempInt;
+			locShortBuffer++;
+		}
+	}
+	delete mOutPacket;
+	mOutPacket = new StampedOggPacket(locBuff, locActualSize, false, false, 0, locNumFrames, StampedOggPacket::OGG_END_ONLY);
+	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+
+}
+void FLACPushDecoder::metadata_callback(const ::FLAC__StreamMetadata* inMetadata) 
+{
+	int i = 0;
+}
+void FLACPushDecoder::error_callback(::FLAC__StreamDecoderErrorStatus inStatus) 
+{
+	int i = 0;
+}

Added: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.h
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.h	2004-10-16 14:18:17 UTC (rev 8028)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/FLACPushDecoder.h	2004-10-16 15:34:56 UTC (rev 8029)
@@ -0,0 +1,34 @@
+#pragma once
+#include "dllstuff.h"
+#include "StampedOggPacket.h"
+#include "OggPacket.h"
+#include "FLAC++/decoder.h"
+using namespace FLAC::Decoder;
+class FLACPushDecoder
+	:	protected Stream
+{
+public:
+	FLACPushDecoder(void);
+	virtual ~FLACPushDecoder(void);
+
+	StampedOggPacket* decodeFLAC(OggPacket* inPacket);
+
+	void initCodec();
+	void flushCodec();
+	//Probably shouldn't be public... but who cares for now.
+	unsigned long mNumChannels;
+	unsigned long mFrameSize;
+	unsigned long mSampleRate;
+protected:
+	static const int SIZE_16_BITS = 2;
+	//Virtuals frmo FLAC decoder
+	virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
+	virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
+	virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
+	virtual void error_callback(::FLAC__StreamDecoderErrorStatus status);
+
+	OggPacket* mInPacket;
+	StampedOggPacket* mOutPacket;
+	bool mBegun;
+	
+};

Modified: trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/libFLACHelper.vcproj
===================================================================
--- trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/libFLACHelper.vcproj	2004-10-16 14:18:17 UTC (rev 8028)
+++ trunk/oggdsf/src/lib/codecs/flac/libs/libFLACHelper/libFLACHelper.vcproj	2004-10-16 15:34:56 UTC (rev 8029)
@@ -19,7 +19,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\..\..\..\core\ogg\libOOOgg;..\..\..\..\helper\libilliCore"
+				AdditionalIncludeDirectories="..\..\..\..\core\ogg\libOOOgg;..\..\..\..\helper\libilliCore;..\libflac\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -108,6 +108,9 @@
 				RelativePath=".\FLACMetadataSplitter.cpp">
 			</File>
 			<File
+				RelativePath=".\FLACPushDecoder.cpp">
+			</File>
+			<File
 				RelativePath=".\stdafx.cpp">
 				<FileConfiguration
 					Name="Debug|Win32">
@@ -134,6 +137,9 @@
 				RelativePath=".\FLACMetadataSplitter.h">
 			</File>
 			<File
+				RelativePath=".\FLACPushDecoder.h">
+			</File>
+			<File
 				RelativePath=".\stdafx.h">
 			</File>
 		</Filter>



More information about the commits mailing list