Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sound.cpp

Go to the documentation of this file.
00001 #include "audiere.h"
00002 #include "internal.h"
00003 #include "repeatable.h"
00004 #include "utility.h"
00005 
00006 
00007 namespace audiere {
00008 
00009   ADR_EXPORT(OutputStream*, AdrOpenSound)(
00010     AudioDevice* device,
00011     SampleSource* source,
00012     bool streaming)
00013   {
00014     if (!device || !source) {
00015       return 0;
00016     }
00017 
00018     // If the stream is not seekable, we cannot know how big of a buffer
00019     // to allocate, so try to stream it.  Also, if the user wants to stream
00020     // then let him.  ;)
00021     if (!source->isSeekable() || streaming) {
00022       return device->openStream(source);
00023     }
00024 
00025     int stream_length = source->getLength();
00026     int channel_count, sample_rate;
00027     SampleFormat sample_format;
00028     source->getFormat(channel_count, sample_rate, sample_format);
00029 
00030     int stream_length_bytes =
00031       stream_length * channel_count * GetSampleSize(sample_format);
00032     u8* buffer = new u8[stream_length_bytes];
00033     source->setPosition(0);  // in case the source has been read from already
00034     source->read(stream_length, buffer);
00035 
00036     OutputStream* stream = device->openBuffer(
00037       buffer, stream_length,
00038       channel_count, sample_rate, sample_format);
00039 
00040     delete[] buffer;
00041     return stream;
00042   }
00043 
00044 }

Generated on Sat Oct 12 01:43:04 2002 for audiere by doxygen1.2.17