void Sound::save(const QString& filename) const { qDebug() << filename << " - " << data.size() << endl; QFile file(filename); if(!file.open(IO_WriteOnly)) { qWarning() <<"unable to open file" ; return; } QDataStream stream(&file); stream.setByteOrder( QDataStream::LittleEndian ); QByteArray SoundData(data.size()*2, '\0'); for(long int f=0;f<data.size();f++) { Q_UINT16 val= (signed short int) ( (data.at(f) * ((double)(1<<13)/(signed)max) ) ); SoundData[ (uint)(2*f) ]= val & 0x00FF; SoundData[(uint)(2*f+1)]= (val & 0xFF00) >> 8; // qDebug() << data.at(f) << " / " << max << " = " << val << " | " << SoundData[ 2*f ] << " "<< SoundData[ 2*f+1 ] << endl; } Q_UINT16 NumberOfChannels=2; quint32 SampleRate=_fs; SMAGIC("RIFF"); //READ_FROM_STREAM(quint32,ChunkSize); stream << (quint32)(36+ SoundData.size()); SMAGIC("WAVE"); SMAGIC("fmt "); //READ_FROM_STREAM(quint32,ChunkSize2); stream << (quint32)(16); //READ_FROM_STREAM(Q_INT16,AudioFormat); stream << (Q_INT16)(1); //READ_FROM_STREAM(Q_UINT16,NumberOfChannels); stream << (Q_UINT16)(NumberOfChannels); //READ_FROM_STREAM(quint32,SampleRate); stream << (quint32)(SampleRate); //READ_FROM_STREAM(quint32,ByteRate); stream << (quint32)(NumberOfChannels*SampleRate*16/8); //READ_FROM_STREAM(Q_UINT16,BlockAlign); stream << (Q_UINT16)(16/8 *NumberOfChannels); //READ_FROM_STREAM(Q_UINT16,BitsPerSample); stream << (Q_UINT16)(16); SMAGIC("data"); //READ_FROM_STREAM(QByteArray,SoundData); stream << SoundData; file.close(); }
#include "SoundData.h" const SoundData soundDataArray[NUMBER_SOUNDDATA] = { SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_LEVEL_SCORPION, true, true), SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_SCORPION, false, false), SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_LEVEL_SUBZERO, true, true), SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_SUBZERO, false, false), SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_LEVEL_REPTILE, true, true), SoundData("../Ressources/Sounds/19 Triangle X2.wav", SOUND_REPTILE, false, false), }; SoundData::SoundData() { this->fileName = ""; this->soundID = 0; this->isMusic = false; this->isLoop = false; } SoundData::SoundData(string fileName, int soundID, bool isMusic, bool isLoop) { this->fileName = fileName; this->soundID = soundID; this->isMusic = isMusic; this->isLoop = isLoop; } SoundData::~SoundData(void) { }