medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 72a7d078069926cd16cd2500be14cbb1e5d597c9
parent 4ea87b3494ef8f043189f5e6b0944e5c34b1a217
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Fri Feb 10 21:38:38 +0200

Add ReadStream::nocopy

Diffstat:
stream.h | 10++++++++++
wave.cc | 7+------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/stream.h b/stream.h @@ -45,6 +45,16 @@ struct ReadStream { cp->used = true; } + template< typename T > + T * nocopy( size_t num_bytes ) { + ASSERT( num_bytes % sizeof( T ) == 0 ); + ASSERT( is_aligned( ( T * ) cursor ) ); + + T * ret = ( T * ) cursor; + cursor += num_bytes; + return ret; + } + const char * cursor; const char * one_past_end; bool ok; diff --git a/wave.cc b/wave.cc @@ -86,13 +86,8 @@ bool wave_decode( MemoryArena * arena, u8 * data, size_t data_len, SoundData * s return false; } - // TODO: this should really copy data out, if - // only to make sure the samples are aligned - sound->samples = ( s16 * ) r.cursor; + sound->samples = r.nocopy< s16 >( chunk_length ); data_length = chunk_length; - for( u32 i = 0; i < align2( chunk_length ); i++ ) { - read_u8( &r ); - } } break; default: {