Code Search for Developers
 
 
  

stream.cpp from NeoEngineNG at Krugle


Show stream.cpp syntax highlighted

/***************************************************************************
                       stream.cpp  -  Ogg Vorbis stream
                             -------------------
    begin                : Wed Mar 17 2004
    copyright            : (C) 2004 by Reality Rift Studios
    email                : mattias@realityrift.com
 ***************************************************************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at 
 http://www.mozilla.org/MPL/

 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the
 License.

 The Original Code is the NeoEngine, NeoACVorbis, stream.cpp

 The Initial Developer of the Original Code is Mattias Jansson.
 Portions created by Mattias Jansson are Copyright (C) 2004
 Reality Rift Studios. All Rights Reserved.

 ***************************************************************************/

#include "stream.h"

using namespace std;
using namespace NeoEngine;


namespace NeoACVorbis
{


Stream::Stream( File *pkFile ) :
	SoundStream( pkFile )
{
	pkFile->SetBinary( true );
	pkFile->Seekg( 0, ios::beg );

	ov_callbacks cb;

	cb.read_func  = read_stream;
	cb.seek_func  = seek_stream;
	cb.close_func = close_stream;
	cb.tell_func  = tell_stream;

	ov_open_callbacks( pkFile, &m_kVorbis, 0, 0, cb );

	vorbis_info *pkInfo = ov_info( &m_kVorbis, -1 );

	m_uiSize             = (unsigned int)ov_pcm_total( &m_kVorbis, -1 ) * 2 * pkInfo->channels; // 2 == 16/8
	m_uiNumChannels      = pkInfo->channels;
	m_uiSamplesPerSecond = pkInfo->rate;
	m_uiBitsPerSample    = 16;
}


Stream::~Stream()
{
	ov_clear( &m_kVorbis );
}


void Stream::Reset()
{
	SoundStream::Reset();

	ov_pcm_seek( &m_kVorbis, 0 );
}



unsigned int Stream::Decode( unsigned char *pucBuffer, unsigned int uiBytes )
{
	char *pucCur = (char*)pucBuffer;
	unsigned int uiRead = 0;
	int iSection = 0;
	bool bEOF = false;

	while ( ( uiRead < uiBytes ) && !bEOF )
	{
		long ret = ov_read( &m_kVorbis, pucCur, uiBytes - uiRead, 0, 2, 1, &iSection );

		if( ret <= 0 )
			bEOF = true;
		else
		{
			uiRead += ret;
			pucCur += ret;
		}
	}

	m_uiCurPos += uiRead;

	return uiRead;
}


size_t read_stream( void* ptr, size_t size, size_t nmemb, void *datasource )
{
	File* pkFile = (File*)datasource;
	int iNumBytes = (int)( size * nmemb );
	int iNumAvail = 0;

	std::streampos curpos = pkFile->Tellg();
	pkFile->Seekg( 0, std::ios::end );
	
	std::streampos endpos = pkFile->Tellg();
	pkFile->Seekg( curpos, std::ios::beg );

	iNumAvail = (int)( endpos - curpos );

	if( iNumAvail < iNumBytes )
		iNumBytes = iNumAvail;

	pkFile->Read( ptr, iNumBytes );

	return iNumBytes;
}


int seek_stream( void *datasource, ogg_int64_t offset, int whence )
{
	File *pkFile = (File*)datasource;
	std::streamoff offs = (std::streamoff)offset;

	switch( whence )
	{
		case SEEK_SET:
			pkFile->Seekg( offs, std::ios::beg );
			break;
		case SEEK_CUR:
			pkFile->Seekg( offs, std::ios::cur );
			break;
		case SEEK_END:
			pkFile->Seekg( offs, std::ios::end );
			break;
	}

	return 0;
}


int close_stream(void *datasource )
{
	return 0;
}


long tell_stream( void *datasource )
{
	return long( ((File*)datasource)->Tellg() );
}


};





See more files for this project here

NeoEngineNG

NeoenEngine NG (Next Generation) is the evolution of neoengine one,it\'s a different development from NeoEngine2, it\'s a direct inherits from NeoEngine one.\n

Project homepage: http://sourceforge.net/projects/neoengineng
Programming language(s): C,C++
License: other

  ogg/
    bitwise.c
    config_types.h.in
    framing.c
    ogg.h
    os_types.h
  vorbis/
    books/
      coupled/
        res_books_stereo.h
      floor/
        floor_books.h
      uncoupled/
        res_books_uncoupled.h
    modes/
      floor_all.h
      psych_11.h
      psych_16.h
      psych_44.h
      psych_8.h
      residue_16.h
      residue_44.h
      residue_44u.h
      residue_8.h
      setup_11.h
      setup_16.h
      setup_22.h
      setup_32.h
      setup_44.h
      setup_44u.h
      setup_8.h
      setup_X.h
    analysis.c
    backends.h
    barkmel.c
    bitrate.c
    bitrate.h
    block.c
    codebook.c
    codebook.h
    codec.h
    codec_internal.h
    envelope.c
    envelope.h
    floor0.c
    floor1.c
    highlevel.h
    info.c
    lookup.c
    lookup.h
    lookup_data.h
    lookups.pl
    lpc.c
    lpc.h
    lsp.c
    lsp.h
    mapping0.c
    masking.h
    mdct.c
    mdct.h
    misc.h
    os.h
    psy.c
    psy.h
    psytune.c
    registry.c
    registry.h
    res0.c
    scales.h
    sharedbook.c
    smallft.c
    smallft.h
    synthesis.c
    tone.c
    vorbisenc.c
    vorbisenc.h
    vorbisfile.c
    vorbisfile.h
    window.c
    window.h
  Makefile.am
  SConscript
  codec.cpp
  codec.h
  link.h
  neoacvorbis-static.dev
  neoacvorbis.cbp
  neoacvorbis.depend
  neoacvorbis.dev
  neoacvorbis.dsp
  neoacvorbis.layout
  neoacvorbis.vcproj
  stream.cpp
  stream.h