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
00023
00024
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);
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 }