diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp | 1 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.cpp | 38 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.h | 2 |
3 files changed, 22 insertions, 19 deletions
diff --git a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp index b980e1d98e0..1683a9a61c0 100644 --- a/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp +++ b/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp @@ -177,6 +177,7 @@ static const char* fileopen_error = "AUD_FFMPEGReader: File couldn't be " AUD_FFMPEGReader::AUD_FFMPEGReader(std::string filename) : m_pkgbuf(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1), + m_formatCtx(NULL), m_aviocontext(NULL), m_membuf(NULL) { diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index e5c966fdcae..85a053238d0 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -816,7 +816,7 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high, if(high < rate) sound = new AUD_LowpassFactory(sound, high); if(low > 0) - sound = new AUD_HighpassFactory(sound, low);; + sound = new AUD_HighpassFactory(sound, low); sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f); sound = new AUD_LinearResampleFactory(sound, specs); @@ -1055,7 +1055,7 @@ int AUD_doesPlayback() return -1; } -int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length) +int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_per_second) { AUD_DeviceSpecs specs; sample_t* buf; @@ -1067,38 +1067,40 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length) AUD_Reference<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, specs).createReader(); - int len = reader->getLength(); - float samplejump = (float)len / (float)length; - float min, max; + specs.specs = reader->getSpecs(); + int len; + float samplejump = specs.rate / samples_per_second; + float min, max, power; bool eos; for(int i = 0; i < length; i++) { len = floor(samplejump * (i+1)) - floor(samplejump * i); - if(aBuffer.getSize() < len * AUD_SAMPLE_SIZE(reader->getSpecs())) - { - aBuffer.resize(len * AUD_SAMPLE_SIZE(reader->getSpecs())); - buf = aBuffer.getBuffer(); - } + aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs)); + buf = aBuffer.getBuffer(); reader->read(len, eos, buf); - if(eos) - { - length = i; - break; - } - max = min = *buf; + power = *buf * *buf; for(int j = 1; j < len; j++) { if(buf[j] < min) min = buf[j]; if(buf[j] > max) max = buf[j]; - buffer[i * 2] = min; - buffer[i * 2 + 1] = max; + power += buf[j] * buf[j]; + } + + buffer[i * 3] = min; + buffer[i * 3 + 1] = max; + buffer[i * 3 + 2] = sqrt(power) / len; + + if(eos) + { + length = i; + break; } } diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index 7689d1b06b5..2cd24551dd9 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -502,7 +502,7 @@ extern void AUD_setSyncCallback(AUD_syncFunction function, void* data); extern int AUD_doesPlayback(void); -extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length); +extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_per_second); extern AUD_Sound* AUD_copy(AUD_Sound* sound); |