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
00019
00020
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);
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 }