mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
commit
8d7e682a1f
2 changed files with 37 additions and 12 deletions
22
examples/playSoundWave.js
Normal file
22
examples/playSoundWave.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// playSoundWave.js
|
||||
// examples
|
||||
//
|
||||
// Created by Ryan Huffman on 05/27/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var soundClip = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail%20Party%20Snippets/Walken1.wav");
|
||||
|
||||
function playSound() {
|
||||
var options = new AudioInjectionOptions();
|
||||
var position = MyAvatar.position;
|
||||
options.position = position;
|
||||
options.volume = 0.5;
|
||||
Audio.playSound(soundClip, options);
|
||||
}
|
||||
|
||||
Script.setInterval(playSound, 10000);
|
|
@ -237,27 +237,30 @@ void Sound::interpretAsWav(const QByteArray& inputAudioByteArray, QByteArray& ou
|
|||
return;
|
||||
}
|
||||
|
||||
// Skip any extra data in the WAVE chunk
|
||||
waveStream.skipRawData(fileHeader.wave.descriptor.size - (sizeof(WAVEHeader) - sizeof(chunk)));
|
||||
|
||||
// Read off remaining header information
|
||||
DATAHeader dataHeader;
|
||||
if (waveStream.readRawData(reinterpret_cast<char *>(&dataHeader), sizeof(DATAHeader)) == sizeof(DATAHeader)) {
|
||||
if (strncmp(dataHeader.descriptor.id, "data", 4) != 0) {
|
||||
qDebug() << "Invalid wav audio data header.";
|
||||
while (true) {
|
||||
// Read chunks until the "data" chunk is found
|
||||
if (waveStream.readRawData(reinterpret_cast<char *>(&dataHeader), sizeof(DATAHeader)) == sizeof(DATAHeader)) {
|
||||
if (strncmp(dataHeader.descriptor.id, "data", 4) == 0) {
|
||||
break;
|
||||
}
|
||||
waveStream.skipRawData(dataHeader.descriptor.size);
|
||||
} else {
|
||||
qDebug() << "Could not read wav audio data header.";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Could not read wav audio data header.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (qFromLittleEndian<quint32>(fileHeader.riff.descriptor.size) != qFromLittleEndian<quint32>(dataHeader.descriptor.size) + 36) {
|
||||
qDebug() << "Did not read audio file chank headers correctly.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Now pull out the data
|
||||
quint32 outputAudioByteArraySize = qFromLittleEndian<quint32>(dataHeader.descriptor.size);
|
||||
outputAudioByteArray.resize(outputAudioByteArraySize);
|
||||
waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize);
|
||||
if (waveStream.readRawData(outputAudioByteArray.data(), outputAudioByteArraySize) != outputAudioByteArraySize) {
|
||||
qDebug() << "Error reading WAV file";
|
||||
}
|
||||
|
||||
} else {
|
||||
qDebug() << "Could not read wav audio file header.";
|
||||
|
|
Loading…
Reference in a new issue