runtime check for soundplay lossage

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6701 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty
2004-02-23 10:10:41 +00:00
parent f9e9fb76f0
commit 441fd5bdb4
2 changed files with 27 additions and 23 deletions
@@ -4,6 +4,7 @@
#include <Locker.h> #include <Locker.h>
#include <MediaFormats.h> #include <MediaFormats.h>
#include <MediaRoster.h> #include <MediaRoster.h>
#include <Roster.h>
#include <vector> #include <vector>
#include "vorbisCodecPlugin.h" #include "vorbisCodecPlugin.h"
#include "OggVorbisFormats.h" #include "OggVorbisFormats.h"
@@ -16,7 +17,6 @@
#endif #endif
#define DECODE_BUFFER_SIZE (32 * 1024) #define DECODE_BUFFER_SIZE (32 * 1024)
#define DECODE_AS_INT16 1
inline size_t inline size_t
AudioBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */) AudioBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
@@ -49,6 +49,9 @@ VorbisDecoder::VorbisDecoder()
fStartTime = 0; fStartTime = 0;
fFrameSize = 0; fFrameSize = 0;
fOutputBufferSize = 0; fOutputBufferSize = 0;
app_info info;
fSoundplayLossage = (be_roster->GetActiveAppInfo(&info) == B_OK) &&
(strcmp(info.signature, "application/x-vnd.marcone-soundplay") == 0);
} }
@@ -127,9 +130,9 @@ VorbisDecoder::NegotiateOutputFormat(media_format *ioDecodedFormat)
// Be R5 behavior seems to be that we can never fail. If we // Be R5 behavior seems to be that we can never fail. If we
// don't support the requested format, just return one we do. // don't support the requested format, just return one we do.
media_format format = vorbis_decoded_media_format(); media_format format = vorbis_decoded_media_format();
#if DECODE_AS_INT16 if (fSoundplayLossage) {
format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT; format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT;
#endif }
format.u.raw_audio.frame_rate = (float)fInfo.rate; format.u.raw_audio.frame_rate = (float)fInfo.rate;
format.u.raw_audio.channel_count = fInfo.channels; format.u.raw_audio.channel_count = fInfo.channels;
format.u.raw_audio.channel_mask = B_CHANNEL_LEFT | (fInfo.channels != 1 ? B_CHANNEL_RIGHT : 0); format.u.raw_audio.channel_mask = B_CHANNEL_LEFT | (fInfo.channels != 1 ? B_CHANNEL_RIGHT : 0);
@@ -207,27 +210,27 @@ VorbisDecoder::Decode(void *buffer, int64 *frameCount,
// reduce samples to the amount of samples we will actually consume // reduce samples to the amount of samples we will actually consume
samples = min_c(samples,out_bytes_needed/fFrameSize); samples = min_c(samples,out_bytes_needed/fFrameSize);
total_samples += samples; total_samples += samples;
#if DECODE_AS_INT16 if (fSoundplayLossage) {
for (int sample = 0; sample < samples ; sample++) { for (int sample = 0; sample < samples ; sample++) {
for (int channel = 0; channel < fInfo.channels; channel++) { for (int channel = 0; channel < fInfo.channels; channel++) {
int32 thesample = (int32)(pcm[channel][sample] * 32767.0f); int32 thesample = (int32)(pcm[channel][sample] * 32767.0f);
if (thesample > 32767) if (thesample > 32767)
*(int16*)out_buffer = 32767; *(int16*)out_buffer = 32767;
else if (thesample < -32767) else if (thesample < -32767)
*(int16*)out_buffer = -32767; *(int16*)out_buffer = -32767;
else else
*(int16*)out_buffer = thesample; *(int16*)out_buffer = thesample;
out_buffer += 2; out_buffer += 2;
}
}
} else {
for (int sample = 0; sample < samples ; sample++) {
for (int channel = 0; channel < fInfo.channels; channel++) {
*((float*)out_buffer) = pcm[channel][sample];
out_buffer += sizeof(float);
}
} }
} }
#else
for (int sample = 0; sample < samples ; sample++) {
for (int channel = 0; channel < fInfo.channels; channel++) {
*((float*)out_buffer) = pcm[channel][sample];
out_buffer += sizeof(float);
}
}
#endif
out_bytes_needed -= samples * fFrameSize; out_bytes_needed -= samples * fFrameSize;
// report back how many samples we consumed // report back how many samples we consumed
vorbis_synthesis_read(&fDspState,samples); vorbis_synthesis_read(&fDspState,samples);
@@ -33,6 +33,7 @@ private:
bigtime_t fStartTime; bigtime_t fStartTime;
int fFrameSize; int fFrameSize;
int fOutputBufferSize; int fOutputBufferSize;
bool fSoundplayLossage;
}; };