sound.cpp

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

Generated on Mon Feb 13 23:07:47 2006 for audiere by  doxygen 1.4.6